diff --git a/Cargo.lock b/Cargo.lock index f15f9519cb34f..8bfdf23a30bf4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4133,6 +4133,7 @@ dependencies = [ "rustc_middle", "rustc_session", "rustc_span", + "rustc_trait_selection", "rustc_typeck", "tracing", ] diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 8f2e49e299c8b..ac76b42c57d12 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -506,7 +506,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let count = generics .params .iter() - .filter(|param| matches!(param.kind, ast::GenericParamKind::Lifetime { .. })) + .filter(|param| { + matches!(param.kind, ast::GenericParamKind::Lifetime { .. }) + }) .count(); self.lctx.type_def_lifetime_params.insert(def_id.to_def_id(), count); } diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index e78d1368b357e..fa3c958c9fe78 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -598,7 +598,7 @@ impl<'a> TraitDef<'a> { let mut ty_params = params .iter() - .filter(|param| matches!(param.kind, ast::GenericParamKind::Type{..})) + .filter(|param| matches!(param.kind, ast::GenericParamKind::Type { .. })) .peekable(); if ty_params.peek().is_some() { diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index 37902dddff46d..c09cce21bf24c 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -36,7 +36,7 @@ macro_rules! forward_inner_docs { ($e:expr => $i:item) => { #[doc = $e] $i - } + }; } /// In general, the `DiagnosticBuilder` uses deref to allow access to diff --git a/compiler/rustc_errors/src/snippet.rs b/compiler/rustc_errors/src/snippet.rs index dbb2523f28691..acb88e57db5ee 100644 --- a/compiler/rustc_errors/src/snippet.rs +++ b/compiler/rustc_errors/src/snippet.rs @@ -122,11 +122,13 @@ impl Annotation { } pub fn is_multiline(&self) -> bool { - matches!(self.annotation_type, + matches!( + self.annotation_type, AnnotationType::Multiline(_) - | AnnotationType::MultilineStart(_) - | AnnotationType::MultilineLine(_) - | AnnotationType::MultilineEnd(_)) + | AnnotationType::MultilineStart(_) + | AnnotationType::MultilineLine(_) + | AnnotationType::MultilineEnd(_) + ) } pub fn len(&self) -> usize { @@ -158,7 +160,10 @@ impl Annotation { pub fn takes_space(&self) -> bool { // Multiline annotations always have to keep vertical space. - matches!(self.annotation_type, AnnotationType::MultilineStart(_) | AnnotationType::MultilineEnd(_)) + matches!( + self.annotation_type, + AnnotationType::MultilineStart(_) | AnnotationType::MultilineEnd(_) + ) } } diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 35170fa7c1d02..1c16dc026670b 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1543,10 +1543,10 @@ pub fn is_range_literal(expr: &Expr<'_>) -> bool { **qpath, QPath::LangItem( LangItem::Range - | LangItem::RangeTo - | LangItem::RangeFrom - | LangItem::RangeFull - | LangItem::RangeToInclusive, + | LangItem::RangeTo + | LangItem::RangeFrom + | LangItem::RangeFull + | LangItem::RangeToInclusive, _, ) ), diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index 4357eb34add23..1546c1e559f57 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -14,7 +14,7 @@ use crate::infer::canonical::{ }; use crate::infer::nll_relate::{NormalizationStrategy, TypeRelating, TypeRelatingDelegate}; use crate::infer::region_constraints::{Constraint, RegionConstraintData}; -use crate::infer::{InferCtxt, InferOk, InferResult, NLLRegionVariableOrigin}; +use crate::infer::{InferCtxt, InferOk, InferResult, NllRegionVariableOrigin}; use crate::traits::query::{Fallible, NoSolution}; use crate::traits::TraitEngine; use crate::traits::{Obligation, ObligationCause, PredicateObligation}; @@ -644,7 +644,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> { } fn next_existential_region_var(&mut self, from_forall: bool) -> ty::Region<'tcx> { - let origin = NLLRegionVariableOrigin::Existential { from_forall }; + let origin = NllRegionVariableOrigin::Existential { from_forall }; self.infcx.next_nll_region_var(origin) } @@ -654,7 +654,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> { fn generalize_existential(&mut self, universe: ty::UniverseIndex) -> ty::Region<'tcx> { self.infcx.next_nll_region_var_in_universe( - NLLRegionVariableOrigin::Existential { from_forall: false }, + NllRegionVariableOrigin::Existential { from_forall: false }, universe, ) } diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index c39daea0811e0..a5f1f878e1931 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -2342,7 +2342,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id); format!(" for capture of `{}` by closure", var_name) } - infer::NLL(..) => bug!("NLL variable found in lexical phase"), + infer::Nll(..) => bug!("NLL variable found in lexical phase"), }; struct_span_err!( diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs index 0958afa03082a..61c8113d05287 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs @@ -132,7 +132,12 @@ impl Visitor<'tcx> for TypeParamSpanVisitor<'tcx> { [segment] if segment .res - .map(|res| matches!(res, Res::SelfTy(_, _) | Res::Def(hir::def::DefKind::TyParam, _))) + .map(|res| { + matches!( + res, + Res::SelfTy(_, _) | Res::Def(hir::def::DefKind::TyParam, _) + ) + }) .unwrap_or(false) => { self.types.push(path.span); diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 27545c126857b..09eecd715f03b 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -458,11 +458,11 @@ pub enum RegionVariableOrigin { /// This origin is used for the inference variables that we create /// during NLL region processing. - NLL(NLLRegionVariableOrigin), + Nll(NllRegionVariableOrigin), } #[derive(Copy, Clone, Debug)] -pub enum NLLRegionVariableOrigin { +pub enum NllRegionVariableOrigin { /// During NLL region processing, we create variables for free /// regions that we encounter in the function signature and /// elsewhere. This origin indices we've got one of those. @@ -1078,17 +1078,17 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } /// Just a convenient wrapper of `next_region_var` for using during NLL. - pub fn next_nll_region_var(&self, origin: NLLRegionVariableOrigin) -> ty::Region<'tcx> { - self.next_region_var(RegionVariableOrigin::NLL(origin)) + pub fn next_nll_region_var(&self, origin: NllRegionVariableOrigin) -> ty::Region<'tcx> { + self.next_region_var(RegionVariableOrigin::Nll(origin)) } /// Just a convenient wrapper of `next_region_var` for using during NLL. pub fn next_nll_region_var_in_universe( &self, - origin: NLLRegionVariableOrigin, + origin: NllRegionVariableOrigin, universe: ty::UniverseIndex, ) -> ty::Region<'tcx> { - self.next_region_var_in_universe(RegionVariableOrigin::NLL(origin), universe) + self.next_region_var_in_universe(RegionVariableOrigin::Nll(origin), universe) } pub fn var_for_def(&self, span: Span, param: &ty::GenericParamDef) -> GenericArg<'tcx> { @@ -1770,7 +1770,7 @@ impl RegionVariableOrigin { | LateBoundRegion(a, ..) | UpvarRegion(_, a) => a, BoundRegionInCoherence(_) => rustc_span::DUMMY_SP, - NLL(..) => bug!("NLL variable used with `span`"), + Nll(..) => bug!("NLL variable used with `span`"), } } } diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index ebd6190dc74cc..121dde325f74b 100644 --- a/compiler/rustc_lint/src/nonstandard_style.rs +++ b/compiler/rustc_lint/src/nonstandard_style.rs @@ -56,8 +56,19 @@ declare_lint! { declare_lint_pass!(NonCamelCaseTypes => [NON_CAMEL_CASE_TYPES]); +/// Some unicode characters *have* case, are considered upper case or lower case, but they *can't* +/// be upper cased or lower cased. For the purposes of the lint suggestion, we care about being able +/// to change the char's case. fn char_has_case(c: char) -> bool { - c.is_lowercase() || c.is_uppercase() + let mut l = c.to_lowercase(); + let mut u = c.to_uppercase(); + while let Some(l) = l.next() { + match u.next() { + Some(u) if l != u => return true, + _ => {} + } + } + u.next().is_some() } fn is_camel_case(name: &str) -> bool { @@ -138,6 +149,8 @@ impl NonCamelCaseTypes { to_camel_case(name), Applicability::MaybeIncorrect, ); + } else { + err.span_label(ident.span, "should have an UpperCamelCase name"); } err.emit(); @@ -299,6 +312,8 @@ impl NonSnakeCase { } else { err.help(&format!("convert the identifier to snake case: `{}`", sc)); } + } else { + err.span_label(ident.span, "should have a snake_case name"); } err.emit(); @@ -477,6 +492,8 @@ impl NonUpperCaseGlobals { uc, Applicability::MaybeIncorrect, ); + } else { + err.span_label(ident.span, "should have an UPPER_CASE name"); } err.emit(); diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 26b35e87ac491..2ae4b7c021a8c 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -559,9 +559,9 @@ impl<'hir> Map<'hir> { self.find(self.get_parent_node(id)), Some( Node::Item(_) - | Node::TraitItem(_) - | Node::ImplItem(_) - | Node::Expr(Expr { kind: ExprKind::Closure(..), .. }), + | Node::TraitItem(_) + | Node::ImplItem(_) + | Node::Expr(Expr { kind: ExprKind::Closure(..), .. }), ) ) } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index cd2bea86ea1a7..718e81c84eddd 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -962,8 +962,7 @@ impl<'tcx> LocalDecl<'tcx> { opt_ty_info: _, opt_match_place: _, pat_span: _, - }) - | BindingForm::ImplicitSelf(ImplicitSelfKind::Imm), + }) | BindingForm::ImplicitSelf(ImplicitSelfKind::Imm), ))) ) } @@ -980,8 +979,7 @@ impl<'tcx> LocalDecl<'tcx> { opt_ty_info: _, opt_match_place: _, pat_span: _, - }) - | BindingForm::ImplicitSelf(_), + }) | BindingForm::ImplicitSelf(_), ))) ) } diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index e386d973ee447..4a131a4ec0581 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -12,13 +12,17 @@ impl<'tcx> TyS<'tcx> { pub fn is_primitive_ty(&self) -> bool { matches!( self.kind(), - Bool | Char | Str | Int(_) | Uint(_) | Float(_) - | Infer( - InferTy::IntVar(_) - | InferTy::FloatVar(_) - | InferTy::FreshIntTy(_) - | InferTy::FreshFloatTy(_) - ) + Bool | Char + | Str + | Int(_) + | Uint(_) + | Float(_) + | Infer( + InferTy::IntVar(_) + | InferTy::FloatVar(_) + | InferTy::FreshIntTy(_) + | InferTy::FreshFloatTy(_) + ) ) } diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index c211f07bed8c2..1669c59d7f1b9 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -646,11 +646,14 @@ impl Trait for X { let current_method_ident = body_owner.and_then(|n| n.ident()).map(|i| i.name); // We don't want to suggest calling an assoc fn in a scope where that isn't feasible. - let callable_scope = matches!(body_owner, Some( + let callable_scope = matches!( + body_owner, + Some( hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(..), .. }) - | hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(..), .. }) - | hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }), - )); + | hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(..), .. }) + | hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }), + ) + ); let impl_comparison = matches!( cause_code, ObligationCauseCode::CompareImplMethodObligation { .. } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 9cec0eb5be3c5..6b4f08d9f9335 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1871,8 +1871,14 @@ impl<'tcx> TyS<'tcx> { pub fn is_scalar(&self) -> bool { matches!( self.kind(), - Bool | Char | Int(_) | Float(_) | Uint(_) | FnDef(..) | FnPtr(_) | RawPtr(_) - | Infer(IntVar(_) | FloatVar(_)) + Bool | Char + | Int(_) + | Float(_) + | Uint(_) + | FnDef(..) + | FnPtr(_) + | RawPtr(_) + | Infer(IntVar(_) | FloatVar(_)) ) } diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rs index a3d09c3a8d4c1..06e3f4b91f61f 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rs @@ -5,7 +5,7 @@ use std::collections::VecDeque; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_index::vec::IndexVec; -use rustc_infer::infer::NLLRegionVariableOrigin; +use rustc_infer::infer::NllRegionVariableOrigin; use rustc_middle::mir::{ Body, CastKind, ConstraintCategory, FakeReadCause, Local, Location, Operand, Place, Rvalue, Statement, StatementKind, TerminatorKind, @@ -258,7 +258,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let (category, from_closure, span) = self.regioncx.best_blame_constraint( &self.body, borrow_region, - NLLRegionVariableOrigin::FreeRegion, + NllRegionVariableOrigin::FreeRegion, |r| self.regioncx.provides_universal_region(r, borrow_region, outlived_region), ); diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs index ab83fc8dfaf75..058986593a41b 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs @@ -3,7 +3,7 @@ use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_infer::infer::{ error_reporting::nice_region_error::NiceRegionError, - error_reporting::unexpected_hidden_region_diagnostic, NLLRegionVariableOrigin, + error_reporting::unexpected_hidden_region_diagnostic, NllRegionVariableOrigin, }; use rustc_middle::mir::{ConstraintCategory, ReturnConstraint}; use rustc_middle::ty::subst::Subst; @@ -75,13 +75,13 @@ crate enum RegionErrorKind<'tcx> { /// The region element that erroneously must be outlived by `longer_fr`. error_element: RegionElement, /// The origin of the placeholder region. - fr_origin: NLLRegionVariableOrigin, + fr_origin: NllRegionVariableOrigin, }, /// Any other lifetime error. RegionError { /// The origin of the region. - fr_origin: NLLRegionVariableOrigin, + fr_origin: NllRegionVariableOrigin, /// The region that should outlive `shorter_fr`. longer_fr: RegionVid, /// The region that should be shorter, but we can't prove it. @@ -269,7 +269,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { pub(in crate::borrow_check) fn report_region_error( &mut self, fr: RegionVid, - fr_origin: NLLRegionVariableOrigin, + fr_origin: NllRegionVariableOrigin, outlived_fr: RegionVid, outlives_suggestion: &mut OutlivesSuggestionBuilder, ) { diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/dump_mir.rs b/compiler/rustc_mir/src/borrow_check/region_infer/dump_mir.rs index d6e48deb031ac..86d9db294bf71 100644 --- a/compiler/rustc_mir/src/borrow_check/region_infer/dump_mir.rs +++ b/compiler/rustc_mir/src/borrow_check/region_infer/dump_mir.rs @@ -5,7 +5,7 @@ use super::{OutlivesConstraint, RegionInferenceContext}; use crate::borrow_check::type_check::Locations; -use rustc_infer::infer::NLLRegionVariableOrigin; +use rustc_infer::infer::NllRegionVariableOrigin; use rustc_middle::ty::TyCtxt; use std::io::{self, Write}; @@ -20,7 +20,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { writeln!(out, "| Free Region Mapping")?; for region in self.regions() { - if let NLLRegionVariableOrigin::FreeRegion = self.definitions[region].origin { + if let NllRegionVariableOrigin::FreeRegion = self.definitions[region].origin { let classification = self.universal_regions.region_classification(region).unwrap(); let outlived_by = self.universal_region_relations.regions_outlived_by(region); writeln!( diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/mod.rs b/compiler/rustc_mir/src/borrow_check/region_infer/mod.rs index 9d45f6fd0d348..bbd512fd36050 100644 --- a/compiler/rustc_mir/src/borrow_check/region_infer/mod.rs +++ b/compiler/rustc_mir/src/borrow_check/region_infer/mod.rs @@ -9,7 +9,7 @@ use rustc_hir::def_id::DefId; use rustc_index::vec::IndexVec; use rustc_infer::infer::canonical::QueryOutlivesConstraint; use rustc_infer::infer::region_constraints::{GenericKind, VarInfos, VerifyBound}; -use rustc_infer::infer::{InferCtxt, NLLRegionVariableOrigin, RegionVariableOrigin}; +use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin}; use rustc_middle::mir::{ Body, ClosureOutlivesRequirement, ClosureOutlivesSubject, ClosureRegionRequirements, ConstraintCategory, Local, Location, ReturnConstraint, @@ -143,9 +143,9 @@ pub(crate) struct AppliedMemberConstraint { pub(crate) struct RegionDefinition<'tcx> { /// What kind of variable is this -- a free region? existential - /// variable? etc. (See the `NLLRegionVariableOrigin` for more + /// variable? etc. (See the `NllRegionVariableOrigin` for more /// info.) - pub(in crate::borrow_check) origin: NLLRegionVariableOrigin, + pub(in crate::borrow_check) origin: NllRegionVariableOrigin, /// Which universe is this region variable defined in? This is /// most often `ty::UniverseIndex::ROOT`, but when we encounter @@ -451,7 +451,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { let scc = self.constraint_sccs.scc(variable); match self.definitions[variable].origin { - NLLRegionVariableOrigin::FreeRegion => { + NllRegionVariableOrigin::FreeRegion => { // For each free, universally quantified region X: // Add all nodes in the CFG to liveness constraints @@ -462,7 +462,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { self.scc_values.add_element(scc, variable); } - NLLRegionVariableOrigin::Placeholder(placeholder) => { + NllRegionVariableOrigin::Placeholder(placeholder) => { // Each placeholder region is only visible from // its universe `ui` and its extensions. So we // can't just add it into `scc` unless the @@ -480,8 +480,8 @@ impl<'tcx> RegionInferenceContext<'tcx> { } } - NLLRegionVariableOrigin::RootEmptyRegion - | NLLRegionVariableOrigin::Existential { .. } => { + NllRegionVariableOrigin::RootEmptyRegion + | NllRegionVariableOrigin::Existential { .. } => { // For existential, regions, nothing to do. } } @@ -1348,7 +1348,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { ) { for (fr, fr_definition) in self.definitions.iter_enumerated() { match fr_definition.origin { - NLLRegionVariableOrigin::FreeRegion => { + NllRegionVariableOrigin::FreeRegion => { // Go through each of the universal regions `fr` and check that // they did not grow too large, accumulating any requirements // for our caller into the `outlives_requirements` vector. @@ -1360,12 +1360,12 @@ impl<'tcx> RegionInferenceContext<'tcx> { ); } - NLLRegionVariableOrigin::Placeholder(placeholder) => { + NllRegionVariableOrigin::Placeholder(placeholder) => { self.check_bound_universal_region(fr, placeholder, errors_buffer); } - NLLRegionVariableOrigin::RootEmptyRegion - | NLLRegionVariableOrigin::Existential { .. } => { + NllRegionVariableOrigin::RootEmptyRegion + | NllRegionVariableOrigin::Existential { .. } => { // nothing to check here } } @@ -1449,7 +1449,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { errors_buffer.push(RegionErrorKind::RegionError { longer_fr: *longer_fr, shorter_fr: *shorter_fr, - fr_origin: NLLRegionVariableOrigin::FreeRegion, + fr_origin: NllRegionVariableOrigin::FreeRegion, is_reported: true, }); } @@ -1459,16 +1459,16 @@ impl<'tcx> RegionInferenceContext<'tcx> { // a more complete picture on how to separate this responsibility. for (fr, fr_definition) in self.definitions.iter_enumerated() { match fr_definition.origin { - NLLRegionVariableOrigin::FreeRegion => { + NllRegionVariableOrigin::FreeRegion => { // handled by polonius above } - NLLRegionVariableOrigin::Placeholder(placeholder) => { + NllRegionVariableOrigin::Placeholder(placeholder) => { self.check_bound_universal_region(fr, placeholder, errors_buffer); } - NLLRegionVariableOrigin::RootEmptyRegion - | NLLRegionVariableOrigin::Existential { .. } => { + NllRegionVariableOrigin::RootEmptyRegion + | NllRegionVariableOrigin::Existential { .. } => { // nothing to check here } } @@ -1516,7 +1516,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { errors_buffer.push(RegionErrorKind::RegionError { longer_fr, shorter_fr: representative, - fr_origin: NLLRegionVariableOrigin::FreeRegion, + fr_origin: NllRegionVariableOrigin::FreeRegion, is_reported: true, }); } @@ -1539,7 +1539,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { errors_buffer.push(RegionErrorKind::RegionError { longer_fr, shorter_fr, - fr_origin: NLLRegionVariableOrigin::FreeRegion, + fr_origin: NllRegionVariableOrigin::FreeRegion, is_reported: !error_reported, }); @@ -1597,7 +1597,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { let blame_span_category = self.find_outlives_blame_span( body, longer_fr, - NLLRegionVariableOrigin::FreeRegion, + NllRegionVariableOrigin::FreeRegion, shorter_fr, ); @@ -1656,7 +1656,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { errors_buffer.push(RegionErrorKind::BoundUniversalRegionError { longer_fr, error_element, - fr_origin: NLLRegionVariableOrigin::Placeholder(placeholder), + fr_origin: NllRegionVariableOrigin::Placeholder(placeholder), }); } @@ -1732,7 +1732,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { debug!("cannot_name_value_of(r1={:?}, r2={:?})", r1, r2); match self.definitions[r2].origin { - NLLRegionVariableOrigin::Placeholder(placeholder) => { + NllRegionVariableOrigin::Placeholder(placeholder) => { let universe1 = self.definitions[r1].universe; debug!( "cannot_name_value_of: universe1={:?} placeholder={:?}", @@ -1741,9 +1741,9 @@ impl<'tcx> RegionInferenceContext<'tcx> { universe1.cannot_name(placeholder.universe) } - NLLRegionVariableOrigin::RootEmptyRegion - | NLLRegionVariableOrigin::FreeRegion - | NLLRegionVariableOrigin::Existential { .. } => false, + NllRegionVariableOrigin::RootEmptyRegion + | NllRegionVariableOrigin::FreeRegion + | NllRegionVariableOrigin::Existential { .. } => false, } } @@ -1771,7 +1771,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { &self, body: &Body<'tcx>, fr1: RegionVid, - fr1_origin: NLLRegionVariableOrigin, + fr1_origin: NllRegionVariableOrigin, fr2: RegionVid, ) -> (ConstraintCategory, Span) { let (category, _, span) = self.best_blame_constraint(body, fr1, fr1_origin, |r| { @@ -1933,7 +1933,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { .definitions .iter_enumerated() .find_map(|(r, definition)| match definition.origin { - NLLRegionVariableOrigin::Placeholder(p) if p == error_placeholder => Some(r), + NllRegionVariableOrigin::Placeholder(p) if p == error_placeholder => Some(r), _ => None, }) .unwrap(), @@ -1965,7 +1965,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { &self, body: &Body<'tcx>, from_region: RegionVid, - from_region_origin: NLLRegionVariableOrigin, + from_region_origin: NllRegionVariableOrigin, target_test: impl Fn(RegionVid) -> bool, ) -> (ConstraintCategory, bool, Span) { debug!( @@ -2059,11 +2059,11 @@ impl<'tcx> RegionInferenceContext<'tcx> { // // and here we prefer to blame the source (the y = x statement). let blame_source = match from_region_origin { - NLLRegionVariableOrigin::FreeRegion - | NLLRegionVariableOrigin::Existential { from_forall: false } => true, - NLLRegionVariableOrigin::RootEmptyRegion - | NLLRegionVariableOrigin::Placeholder(_) - | NLLRegionVariableOrigin::Existential { from_forall: true } => false, + NllRegionVariableOrigin::FreeRegion + | NllRegionVariableOrigin::Existential { from_forall: false } => true, + NllRegionVariableOrigin::RootEmptyRegion + | NllRegionVariableOrigin::Placeholder(_) + | NllRegionVariableOrigin::Existential { from_forall: true } => false, }; let find_region = |i: &usize| { @@ -2144,8 +2144,8 @@ impl<'tcx> RegionDefinition<'tcx> { // `init_universal_regions`. let origin = match rv_origin { - RegionVariableOrigin::NLL(origin) => origin, - _ => NLLRegionVariableOrigin::Existential { from_forall: false }, + RegionVariableOrigin::Nll(origin) => origin, + _ => NllRegionVariableOrigin::Existential { from_forall: false }, }; Self { origin, universe, external_name: None } diff --git a/compiler/rustc_mir/src/borrow_check/renumber.rs b/compiler/rustc_mir/src/borrow_check/renumber.rs index e563e37adc22b..9377473befe32 100644 --- a/compiler/rustc_mir/src/borrow_check/renumber.rs +++ b/compiler/rustc_mir/src/borrow_check/renumber.rs @@ -1,5 +1,5 @@ use rustc_index::vec::IndexVec; -use rustc_infer::infer::{InferCtxt, NLLRegionVariableOrigin}; +use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin}; use rustc_middle::mir::visit::{MutVisitor, TyContext}; use rustc_middle::mir::{Body, Location, PlaceElem, Promoted}; use rustc_middle::ty::subst::SubstsRef; @@ -15,7 +15,7 @@ pub fn renumber_mir<'tcx>( debug!("renumber_mir()"); debug!("renumber_mir: body.arg_count={:?}", body.arg_count); - let mut visitor = NLLVisitor { infcx }; + let mut visitor = NllVisitor { infcx }; for body in promoted.iter_mut() { visitor.visit_body(body); @@ -33,16 +33,16 @@ where debug!("renumber_regions(value={:?})", value); infcx.tcx.fold_regions(value, &mut false, |_region, _depth| { - let origin = NLLRegionVariableOrigin::Existential { from_forall: false }; + let origin = NllRegionVariableOrigin::Existential { from_forall: false }; infcx.next_nll_region_var(origin) }) } -struct NLLVisitor<'a, 'tcx> { +struct NllVisitor<'a, 'tcx> { infcx: &'a InferCtxt<'a, 'tcx>, } -impl<'a, 'tcx> NLLVisitor<'a, 'tcx> { +impl<'a, 'tcx> NllVisitor<'a, 'tcx> { fn renumber_regions(&mut self, value: T) -> T where T: TypeFoldable<'tcx>, @@ -51,7 +51,7 @@ impl<'a, 'tcx> NLLVisitor<'a, 'tcx> { } } -impl<'a, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'tcx> { +impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> { fn tcx(&self) -> TyCtxt<'tcx> { self.infcx.tcx } diff --git a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs index e689964b99858..3ba06bdd6e05f 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs @@ -16,7 +16,7 @@ use rustc_infer::infer::canonical::QueryRegionConstraints; use rustc_infer::infer::outlives::env::RegionBoundPairs; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::{ - InferCtxt, InferOk, LateBoundRegionConversionTime, NLLRegionVariableOrigin, + InferCtxt, InferOk, LateBoundRegionConversionTime, NllRegionVariableOrigin, }; use rustc_middle::mir::tcx::PlaceTy; use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor}; @@ -872,7 +872,7 @@ impl MirTypeckRegionConstraints<'tcx> { match self.placeholder_index_to_region.get(placeholder_index) { Some(&v) => v, None => { - let origin = NLLRegionVariableOrigin::Placeholder(placeholder); + let origin = NllRegionVariableOrigin::Placeholder(placeholder); let region = infcx.next_nll_region_var_in_universe(origin, placeholder.universe); self.placeholder_index_to_region.push(region); region diff --git a/compiler/rustc_mir/src/borrow_check/type_check/relate_tys.rs b/compiler/rustc_mir/src/borrow_check/type_check/relate_tys.rs index 91b1a1fbd9705..6665eb5ad5fff 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/relate_tys.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/relate_tys.rs @@ -1,5 +1,5 @@ use rustc_infer::infer::nll_relate::{NormalizationStrategy, TypeRelating, TypeRelatingDelegate}; -use rustc_infer::infer::{InferCtxt, NLLRegionVariableOrigin}; +use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin}; use rustc_middle::mir::ConstraintCategory; use rustc_middle::ty::relate::TypeRelation; use rustc_middle::ty::{self, Const, Ty}; @@ -64,7 +64,7 @@ impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> { fn next_existential_region_var(&mut self, from_forall: bool) -> ty::Region<'tcx> { if self.borrowck_context.is_some() { - let origin = NLLRegionVariableOrigin::Existential { from_forall }; + let origin = NllRegionVariableOrigin::Existential { from_forall }; self.infcx.next_nll_region_var(origin) } else { self.infcx.tcx.lifetimes.re_erased @@ -81,7 +81,7 @@ impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> { fn generalize_existential(&mut self, universe: ty::UniverseIndex) -> ty::Region<'tcx> { self.infcx.next_nll_region_var_in_universe( - NLLRegionVariableOrigin::Existential { from_forall: false }, + NllRegionVariableOrigin::Existential { from_forall: false }, universe, ) } diff --git a/compiler/rustc_mir/src/borrow_check/universal_regions.rs b/compiler/rustc_mir/src/borrow_check/universal_regions.rs index 02d951b70e28d..4b1acc1cd105e 100644 --- a/compiler/rustc_mir/src/borrow_check/universal_regions.rs +++ b/compiler/rustc_mir/src/borrow_check/universal_regions.rs @@ -20,7 +20,7 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::lang_items::LangItem; use rustc_hir::{BodyOwnerKind, HirId}; use rustc_index::vec::{Idx, IndexVec}; -use rustc_infer::infer::{InferCtxt, NLLRegionVariableOrigin}; +use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin}; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef}; use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt}; @@ -393,7 +393,7 @@ struct UniversalRegionsBuilder<'cx, 'tcx> { param_env: ty::ParamEnv<'tcx>, } -const FR: NLLRegionVariableOrigin = NLLRegionVariableOrigin::FreeRegion; +const FR: NllRegionVariableOrigin = NllRegionVariableOrigin::FreeRegion; impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { fn build(self) -> UniversalRegions<'tcx> { @@ -486,7 +486,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { let root_empty = self .infcx - .next_nll_region_var(NLLRegionVariableOrigin::RootEmptyRegion) + .next_nll_region_var(NllRegionVariableOrigin::RootEmptyRegion) .to_region_vid(); UniversalRegions { @@ -647,7 +647,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { trait InferCtxtExt<'tcx> { fn replace_free_regions_with_nll_infer_vars( &self, - origin: NLLRegionVariableOrigin, + origin: NllRegionVariableOrigin, value: T, ) -> T where @@ -655,7 +655,7 @@ trait InferCtxtExt<'tcx> { fn replace_bound_regions_with_nll_infer_vars( &self, - origin: NLLRegionVariableOrigin, + origin: NllRegionVariableOrigin, all_outlive_scope: LocalDefId, value: ty::Binder, indices: &mut UniversalRegionIndices<'tcx>, @@ -673,7 +673,7 @@ trait InferCtxtExt<'tcx> { impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> { fn replace_free_regions_with_nll_infer_vars( &self, - origin: NLLRegionVariableOrigin, + origin: NllRegionVariableOrigin, value: T, ) -> T where @@ -684,7 +684,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> { fn replace_bound_regions_with_nll_infer_vars( &self, - origin: NLLRegionVariableOrigin, + origin: NllRegionVariableOrigin, all_outlive_scope: LocalDefId, value: ty::Binder, indices: &mut UniversalRegionIndices<'tcx>, diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs index 2503360b1e4d0..3308a243a3afb 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs @@ -6,8 +6,8 @@ use crate::build::{BlockAnd, BlockAndExtension, Builder}; use crate::thir::*; use rustc_hir::def_id::DefId; use rustc_hir::HirId; -use rustc_middle::middle::region; use rustc_middle::hir::place::ProjectionKind as HirProjectionKind; +use rustc_middle::middle::region; use rustc_middle::mir::AssertKind::BoundsCheck; use rustc_middle::mir::*; use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty, TyCtxt, Variance}; @@ -57,7 +57,8 @@ crate enum PlaceBase { /// DefId of the closure closure_def_id: DefId, /// The trait closure implements, `Fn`, `FnMut`, `FnOnce` - closure_kind: ty::ClosureKind }, + closure_kind: ty::ClosureKind, + }, } /// `PlaceBuilder` is used to create places during MIR construction. It allows you to "build up" a @@ -81,8 +82,7 @@ crate struct PlaceBuilder<'tcx> { fn convert_to_hir_projections_and_truncate_for_capture<'tcx>( mir_projections: &[PlaceElem<'tcx>], ) -> Vec { - - let mut hir_projections = Vec::new(); + let mut hir_projections = Vec::new(); for mir_projection in mir_projections { let hir_projection = match mir_projection { @@ -91,20 +91,20 @@ fn convert_to_hir_projections_and_truncate_for_capture<'tcx>( // We will never encouter this for multivariant enums, // read the comment for `Downcast`. HirProjectionKind::Field(field.index() as u32, VariantIdx::new(0)) - }, + } ProjectionElem::Downcast(..) => { // This projections exist only for enums that have // multiple variants. Since such enums that are captured // completely, we can stop here. - break - }, + break; + } ProjectionElem::Index(..) | ProjectionElem::ConstantIndex { .. } | ProjectionElem::Subslice { .. } => { // We don't capture array-access projections. // We can stop here as arrays are captured completely. - break - }, + break; + } }; hir_projections.push(hir_projection); @@ -181,9 +181,9 @@ fn find_capture_matching_projections<'a, 'tcx>( // If an ancestor is found, `idx` is the index within the list of captured places // for root variable `var_hir_id` and `capture` is the `ty::CapturedPlace` itself. let (idx, capture) = root_variable_min_captures.iter().enumerate().find(|(_, capture)| { - let possible_ancestor_proj_kinds = - capture.place.projections.iter().map(|proj| proj.kind).collect(); - is_ancestor_or_same_capture(&possible_ancestor_proj_kinds, &hir_projections) + let possible_ancestor_proj_kinds = + capture.place.projections.iter().map(|proj| proj.kind).collect(); + is_ancestor_or_same_capture(&possible_ancestor_proj_kinds, &hir_projections) })?; // Convert index to be from the presepective of the entire closure_min_captures map @@ -213,35 +213,34 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>( ty::ClosureKind::FnOnce => {} } - let (capture_index, capture) = - if let Some(capture_details) = find_capture_matching_projections( + let (capture_index, capture) = if let Some(capture_details) = + find_capture_matching_projections( typeck_results, var_hir_id, closure_def_id, &from_builder.projection, ) { - capture_details - } else { - if !tcx.features().capture_disjoint_fields { - bug!( - "No associated capture found for {:?}[{:#?}] even though \ + capture_details + } else { + if !tcx.features().capture_disjoint_fields { + bug!( + "No associated capture found for {:?}[{:#?}] even though \ capture_disjoint_fields isn't enabled", - var_hir_id, - from_builder.projection - ) - } else { - // FIXME(project-rfc-2229#24): Handle this case properly - debug!( - "No associated capture found for {:?}[{:#?}]", - var_hir_id, - from_builder.projection, - ); - } - return Err(var_hir_id); - }; + var_hir_id, + from_builder.projection + ) + } else { + // FIXME(project-rfc-2229#24): Handle this case properly + debug!( + "No associated capture found for {:?}[{:#?}]", + var_hir_id, from_builder.projection, + ); + } + return Err(var_hir_id); + }; - let closure_ty = - typeck_results.node_type(tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local())); + let closure_ty = typeck_results + .node_type(tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local())); let substs = match closure_ty.kind() { ty::Closure(_, substs) => ty::UpvarSubsts::Closure(substs), @@ -256,7 +255,8 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>( // we know that the capture exists and is the `capture_index`-th capture. let var_ty = substs.tupled_upvars_ty().tuple_element_ty(capture_index).unwrap(); - upvar_resolved_place_builder = upvar_resolved_place_builder.field(Field::new(capture_index), var_ty); + upvar_resolved_place_builder = + upvar_resolved_place_builder.field(Field::new(capture_index), var_ty); // If the variable is captured via ByRef(Immutable/Mutable) Borrow, // we need to deref it @@ -270,8 +270,9 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>( // We used some of the projections to build the capture itself, // now we apply the remaining to the upvar resolved place. - upvar_resolved_place_builder.projection.extend( - curr_projections.drain(next_projection..)); + upvar_resolved_place_builder + .projection + .extend(curr_projections.drain(next_projection..)); Ok(upvar_resolved_place_builder) } @@ -356,7 +357,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// This is used when constructing a compound `Place`, so that we can avoid creating /// intermediate `Place` values until we know the full set of projections. - crate fn as_place_builder(&mut self, block: BasicBlock, expr: M) -> BlockAnd> + crate fn as_place_builder( + &mut self, + block: BasicBlock, + expr: M, + ) -> BlockAnd> where M: Mirror<'tcx, Output = Expr<'tcx>>, { @@ -627,7 +632,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { if is_outermost_index { self.read_fake_borrows(block, fake_borrow_temps, source_info) } else { - base_place = base_place.expect_upvars_resolved(self.hir.tcx(), self.hir.typeck_results()); + base_place = + base_place.expect_upvars_resolved(self.hir.tcx(), self.hir.typeck_results()); self.add_fake_borrows_of_base( &base_place, block, @@ -679,7 +685,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let tcx = self.hir.tcx(); let local = match base_place.base { PlaceBase::Local(local) => local, - PlaceBase::Upvar { .. } => bug!("Expected PlacseBase::Local found Upvar") + PlaceBase::Upvar { .. } => bug!("Expected PlacseBase::Local found Upvar"), }; let place_ty = Place::ty_from(local, &base_place.projection, &self.local_decls, tcx); diff --git a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs index 55bdbcfc5b916..c95fc969797b4 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs @@ -2,9 +2,9 @@ use rustc_index::vec::Idx; +use crate::build::expr::as_place::PlaceBase; use crate::build::expr::category::{Category, RvalueFunc}; use crate::build::{BlockAnd, BlockAndExtension, Builder}; -use crate::build::expr::as_place::PlaceBase; use crate::thir::*; use rustc_middle::middle::region; use rustc_middle::mir::AssertKind; @@ -274,7 +274,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | ExprKind::ValueTypeAscription { .. } => { // these do not have corresponding `Rvalue` variants, // so make an operand and then return that - debug_assert!(!matches!(Category::of(&expr.kind), Some(Category::Rvalue(RvalueFunc::AsRvalue)))); + debug_assert!(!matches!( + Category::of(&expr.kind), + Some(Category::Rvalue(RvalueFunc::AsRvalue)) + )); let operand = unpack!(block = this.as_operand(block, scope, expr)); block.and(Rvalue::Use(operand)) } @@ -401,34 +404,39 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // We are capturing a path that starts off a local variable in the parent. // The mutability of the current capture is same as the mutability // of the local declaration in the parent. - PlaceBase::Local(local) => this.local_decls[local].mutability, + PlaceBase::Local(local) => this.local_decls[local].mutability, // Parent is a closure and we are capturing a path that is captured // by the parent itself. The mutability of the current capture // is same as that of the capture in the parent closure. PlaceBase::Upvar { .. } => { - let enclosing_upvars_resolved = arg_place_builder.clone().into_place( - this.hir.tcx(), - this.hir.typeck_results()); + let enclosing_upvars_resolved = + arg_place_builder.clone().into_place(this.hir.tcx(), this.hir.typeck_results()); match enclosing_upvars_resolved.as_ref() { - PlaceRef { local, projection: &[ProjectionElem::Field(upvar_index, _), ..] } + PlaceRef { + local, + projection: &[ProjectionElem::Field(upvar_index, _), ..], + } | PlaceRef { local, - projection: &[ProjectionElem::Deref, ProjectionElem::Field(upvar_index, _), ..] } => { - // Not in a closure - debug_assert!( - local == Local::new(1), - "Expected local to be Local(1), found {:?}", - local - ); - // Not in a closure - debug_assert!( - this.upvar_mutbls.len() > upvar_index.index(), - "Unexpected capture place, upvar_mutbls={:#?}, upvar_index={:?}", - this.upvar_mutbls, upvar_index - ); - this.upvar_mutbls[upvar_index.index()] - } + projection: + &[ProjectionElem::Deref, ProjectionElem::Field(upvar_index, _), ..], + } => { + // Not in a closure + debug_assert!( + local == Local::new(1), + "Expected local to be Local(1), found {:?}", + local + ); + // Not in a closure + debug_assert!( + this.upvar_mutbls.len() > upvar_index.index(), + "Unexpected capture place, upvar_mutbls={:#?}, upvar_index={:?}", + this.upvar_mutbls, + upvar_index + ); + this.upvar_mutbls[upvar_index.index()] + } _ => bug!("Unexpected capture place"), } } @@ -439,9 +447,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { Mutability::Mut => BorrowKind::Mut { allow_two_phase_borrow: false }, }; - let arg_place = arg_place_builder.into_place( - this.hir.tcx(), - this.hir.typeck_results()); + let arg_place = arg_place_builder.into_place(this.hir.tcx(), this.hir.typeck_results()); this.cfg.push_assign( block, diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs index 32c01f2c73326..54e7bb248eb61 100644 --- a/compiler/rustc_mir_build/src/build/expr/into.rs +++ b/compiler/rustc_mir_build/src/build/expr/into.rs @@ -10,7 +10,7 @@ use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_hir as hir; use rustc_middle::middle::region; use rustc_middle::mir::*; -use rustc_middle::ty::{CanonicalUserTypeAnnotation}; +use rustc_middle::ty::CanonicalUserTypeAnnotation; use std::slice; @@ -38,7 +38,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let expr_span = expr.span; let source_info = this.source_info(expr_span); - let expr_is_block_or_scope = matches!(expr.kind, ExprKind::Block { .. } | ExprKind::Scope { .. }); + let expr_is_block_or_scope = + matches!(expr.kind, ExprKind::Block { .. } | ExprKind::Scope { .. }); let schedule_drop = move |this: &mut Self| { if let Some(drop_scope) = scope { @@ -68,7 +69,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { this.match_expr(destination, scope, expr_span, block, scrutinee, arms) } ExprKind::If { cond, then, else_opt } => { - let place = unpack!(block = this.as_temp(block, Some(this.local_scope()), cond, Mutability::Mut)); + let place = unpack!( + block = this.as_temp(block, Some(this.local_scope()), cond, Mutability::Mut) + ); let operand = Operand::Move(Place::from(place)); let mut then_block = this.cfg.start_new_block(); @@ -100,14 +103,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ); join_block.unit() - }, + } ExprKind::NeverToAny { source } => { let source = this.hir.mirror(source); - let is_call = matches!(source.kind, ExprKind::Call { .. } | ExprKind::InlineAsm { .. }); + let is_call = + matches!(source.kind, ExprKind::Call { .. } | ExprKind::InlineAsm { .. }); // (#66975) Source could be a const of type `!`, so has to // exist in the generated MIR. - unpack!(block = this.as_temp(block, Some(this.local_scope()), source, Mutability::Mut,)); + unpack!( + block = this.as_temp(block, Some(this.local_scope()), source, Mutability::Mut,) + ); // This is an optimization. If the expression was a call then we already have an // unreachable block. Don't bother to terminate it and create a new one. diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index 2e108d480932a..205ba0d2579f6 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -82,8 +82,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// visible through borrow checking. False edges ensure that the CFG as /// seen by borrow checking doesn't encode this. False edges are added: /// - /// * From each prebinding block to the next prebinding block. - /// * From each otherwise block to the next prebinding block. + /// * From each pre-binding block to the next pre-binding block. + /// * From each otherwise block to the next pre-binding block. crate fn match_expr( &mut self, destination: Place<'tcx>, @@ -630,10 +630,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { #[derive(Debug)] pub(super) struct Candidate<'pat, 'tcx> { - /// `Span` of the original pattern that gave rise to this candidate + /// [`Span`] of the original pattern that gave rise to this candidate. span: Span, - /// This `Candidate` has a guard. + /// Whether this `Candidate` has a guard. has_guard: bool, /// All of these must be satisfied... @@ -645,14 +645,15 @@ pub(super) struct Candidate<'pat, 'tcx> { /// ...and these types asserted... ascriptions: Vec>, - /// ... and if this is non-empty, one of these subcandidates also has to match ... + /// ...and if this is non-empty, one of these subcandidates also has to match... subcandidates: Vec>, - /// ...and the guard must be evaluated, if false branch to Block... + /// ...and the guard must be evaluated; if it's `false` then branch to `otherwise_block`. otherwise_block: Option, - /// ...and the blocks for add false edges between candidates + /// The block before the `bindings` have been established. pre_binding_block: Option, + /// The pre-binding block of the next candidate. next_candidate_pre_binding_block: Option, } @@ -737,18 +738,19 @@ crate struct MatchPair<'pat, 'tcx> { pattern: &'pat Pat<'tcx>, } +/// See [`Test`] for more. #[derive(Clone, Debug, PartialEq)] enum TestKind<'tcx> { - /// Test the branches of enum. + /// Test what enum variant a value is. Switch { - /// The enum being tested + /// The enum type being tested. adt_def: &'tcx ty::AdtDef, /// The set of variants that we should create a branch for. We also /// create an additional "otherwise" case. variants: BitSet, }, - /// Test what value an `integer`, `bool` or `char` has. + /// Test what value an integer, `bool`, or `char` has. SwitchInt { /// The type of the value that we're testing. switch_ty: Ty<'tcx>, @@ -756,7 +758,7 @@ enum TestKind<'tcx> { /// /// For integers and `char`s we create a branch to each of the values in /// `options`, as well as an "otherwise" branch for all other values, even - /// in the (rare) case that options is exhaustive. + /// in the (rare) case that `options` is exhaustive. /// /// For `bool` we always generate two edges, one for `true` and one for /// `false`. @@ -776,17 +778,21 @@ enum TestKind<'tcx> { /// Test whether the value falls within an inclusive or exclusive range Range(PatRange<'tcx>), - /// Test length of the slice is equal to len + /// Test that the length of the slice is equal to `len`. Len { len: u64, op: BinOp }, } +/// A test to perform to determine which [`Candidate`] matches a value. +/// +/// [`Test`] is just the test to perform; it does not include the value +/// to be tested. #[derive(Debug)] crate struct Test<'tcx> { span: Span, kind: TestKind<'tcx>, } -/// ArmHasGuard is isomorphic to a boolean flag. It indicates whether +/// `ArmHasGuard` is a wrapper around a boolean flag. It indicates whether /// a match arm has a guard expression attached to it. #[derive(Copy, Clone, Debug)] crate struct ArmHasGuard(crate bool); @@ -801,27 +807,27 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// candidates are sorted such that the first item in the list /// has the highest priority. When a candidate is found to match /// the value, we will set and generate a branch to the appropriate - /// prebinding block. + /// pre-binding block. /// /// If we find that *NONE* of the candidates apply, we branch to the /// `otherwise_block`, setting it to `Some` if required. In principle, this /// means that the input list was not exhaustive, though at present we /// sometimes are not smart enough to recognize all exhaustive inputs. /// - /// It might be surprising that the input can be inexhaustive. + /// It might be surprising that the input can be non-exhaustive. /// Indeed, initially, it is not, because all matches are /// exhaustive in Rust. But during processing we sometimes divide /// up the list of candidates and recurse with a non-exhaustive /// list. This is important to keep the size of the generated code - /// under control. See `test_candidates` for more details. + /// under control. See [`Builder::test_candidates`] for more details. /// - /// If `fake_borrows` is Some, then places which need fake borrows + /// If `fake_borrows` is `Some`, then places which need fake borrows /// will be added to it. /// /// For an example of a case where we set `otherwise_block`, even for an - /// exhaustive match consider: + /// exhaustive match, consider: /// - /// ```rust + /// ``` /// match x { /// (true, true) => (), /// (_, false) => (), @@ -830,8 +836,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// ``` /// /// For this match, we check if `x.0` matches `true` (for the first - /// arm). If that's false, we check `x.1`. If it's `true` we check if - /// `x.0` matches `false` (for the third arm). In the (impossible at + /// arm). If it doesn't match, we check `x.1`. If `x.1` is `true` we check + /// if `x.0` matches `false` (for the third arm). In the (impossible at /// runtime) case when `x.0` is now `true`, we branch to /// `otherwise_block`. fn match_candidates<'pat>( @@ -938,26 +944,31 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ); } - /// Link up matched candidates. For example, if we have something like - /// this: + /// Link up matched candidates. + /// + /// For example, if we have something like this: /// /// ```rust /// ... - /// Some(x) if cond => ... + /// Some(x) if cond1 => ... /// Some(x) => ... - /// Some(x) if cond => ... + /// Some(x) if cond2 => ... /// ... /// ``` /// /// We generate real edges from: - /// * `start_block` to the `prebinding_block` of the first pattern, - /// * the otherwise block of the first pattern to the second pattern, - /// * the otherwise block of the third pattern to the a block with an - /// Unreachable terminator. /// - /// As well as that we add fake edges from the otherwise blocks to the - /// prebinding block of the next candidate in the original set of + /// * `start_block` to the [pre-binding block] of the first pattern, + /// * the [otherwise block] of the first pattern to the second pattern, + /// * the [otherwise block] of the third pattern to a block with an + /// [`Unreachable` terminator](TerminatorKind::Unreachable). + /// + /// In addition, we add fake edges from the otherwise blocks to the + /// pre-binding block of the next candidate in the original set of /// candidates. + /// + /// [pre-binding block]: Candidate::pre_binding_block + /// [otherwise block]: Candidate::otherwise_block fn select_matched_candidates( &mut self, matched_candidates: &mut [&mut Candidate<'_, 'tcx>], @@ -1044,7 +1055,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// forwards to [Builder::test_candidates]. /// /// Given a pattern `(P | Q, R | S)` we (in principle) generate a CFG like - /// so + /// so: /// /// ```text /// [ start ] @@ -1214,10 +1225,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// This is the most subtle part of the matching algorithm. At /// this point, the input candidates have been fully simplified, /// and so we know that all remaining match-pairs require some - /// sort of test. To decide what test to do, we take the highest - /// priority candidate (last one in the list) and extract the - /// first match-pair from the list. From this we decide what kind - /// of test is needed using `test`, defined in the `test` module. + /// sort of test. To decide what test to perform, we take the highest + /// priority candidate (the first one in the list, as of January 2021) + /// and extract the first match-pair from the list. From this we decide + /// what kind of test is needed using [`Builder::test`], defined in the + /// [`test` module](mod@test). /// /// *Note:* taking the first match pair is somewhat arbitrary, and /// we might do better here by choosing more carefully what to @@ -1225,20 +1237,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// /// For example, consider the following possible match-pairs: /// - /// 1. `x @ Some(P)` -- we will do a `Switch` to decide what variant `x` has - /// 2. `x @ 22` -- we will do a `SwitchInt` - /// 3. `x @ 3..5` -- we will do a range test + /// 1. `x @ Some(P)` -- we will do a [`Switch`] to decide what variant `x` has + /// 2. `x @ 22` -- we will do a [`SwitchInt`] to decide what value `x` has + /// 3. `x @ 3..5` -- we will do a [`Range`] test to decide what range `x` falls in /// 4. etc. /// + /// [`Switch`]: TestKind::Switch + /// [`SwitchInt`]: TestKind::SwitchInt + /// [`Range`]: TestKind::Range + /// /// Once we know what sort of test we are going to perform, this - /// Tests may also help us with other candidates. So we walk over + /// test may also help us winnow down our candidates. So we walk over /// the candidates (from high to low priority) and check. This /// gives us, for each outcome of the test, a transformed list of - /// candidates. For example, if we are testing the current - /// variant of `x.0`, and we have a candidate `{x.0 @ Some(v), x.1 - /// @ 22}`, then we would have a resulting candidate of `{(x.0 as - /// Some).0 @ v, x.1 @ 22}`. Note that the first match-pair is now - /// simpler (and, in fact, irrefutable). + /// candidates. For example, if we are testing `x.0`'s variant, + /// and we have a candidate `(x.0 @ Some(v), x.1 @ 22)`, + /// then we would have a resulting candidate of `((x.0 as Some).0 @ v, x.1 @ 22)`. + /// Note that the first match-pair is now simpler (and, in fact, irrefutable). /// /// But there may also be candidates that the test just doesn't /// apply to. The classical example involves wildcards: @@ -1268,7 +1283,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// is trivially NP-complete: /// /// ```rust - /// match (var0, var1, var2, var3, ..) { + /// match (var0, var1, var2, var3, ...) { /// (true, _, _, false, true, ...) => false, /// (_, true, true, false, _, ...) => false, /// (false, _, false, false, _, ...) => false, @@ -1283,7 +1298,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// /// That kind of exponential worst-case might not occur in practice, but /// our simplistic treatment of constants and guards would make it occur - /// in very common situations - for example #29740: + /// in very common situations - for example [#29740]: /// /// ```rust /// match x { @@ -1294,13 +1309,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// } /// ``` /// - /// Here we first test the match-pair `x @ "foo"`, which is an `Eq` test. + /// [#29740]: https://github.com/rust-lang/rust/issues/29740 + /// + /// Here we first test the match-pair `x @ "foo"`, which is an [`Eq` test]. + /// + /// [`Eq` test]: TestKind::Eq /// /// It might seem that we would end up with 2 disjoint candidate - /// sets, consisting of the first candidate or the other 3, but our - /// algorithm doesn't reason about "foo" being distinct from the other + /// sets, consisting of the first candidate or the other two, but our + /// algorithm doesn't reason about `"foo"` being distinct from the other /// constants; it considers the latter arms to potentially match after - /// both outcomes, which obviously leads to an exponential amount + /// both outcomes, which obviously leads to an exponential number /// of tests. /// /// To avoid these kinds of problems, our algorithm tries to ensure @@ -1312,16 +1331,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// /// After we perform our test, we branch into the appropriate candidate /// set and recurse with `match_candidates`. These sub-matches are - /// obviously inexhaustive - as we discarded our otherwise set - so + /// obviously non-exhaustive - as we discarded our otherwise set - so /// we set their continuation to do `match_candidates` on the - /// "unmatched" set (which is again inexhaustive). + /// "unmatched" set (which is again non-exhaustive). /// /// If you apply this to the above test, you basically wind up /// with an if-else-if chain, testing each candidate in turn, /// which is precisely what we want. /// /// In addition to avoiding exponential-time blowups, this algorithm - /// also has nice property that each guard and arm is only generated + /// also has the nice property that each guard and arm is only generated /// once. fn test_candidates<'pat, 'b, 'c>( &mut self, @@ -1673,15 +1692,21 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let e = self.hir.mirror(e.clone()); let source_info = self.source_info(e.span); (e.span, self.test_bool(block, e, source_info)) - }, + } Guard::IfLet(pat, scrutinee) => { let scrutinee_span = scrutinee.span(); - let scrutinee_place = unpack!(block = self.lower_scrutinee(block, scrutinee.clone(), scrutinee_span)); + let scrutinee_place = unpack!( + block = self.lower_scrutinee(block, scrutinee.clone(), scrutinee_span) + ); let mut guard_candidate = Candidate::new(scrutinee_place, &pat, false); let wildcard = Pat::wildcard_from_ty(pat.ty); let mut otherwise_candidate = Candidate::new(scrutinee_place, &wildcard, false); - let fake_borrow_temps = - self.lower_match_tree(block, pat.span, false, &mut [&mut guard_candidate, &mut otherwise_candidate]); + let fake_borrow_temps = self.lower_match_tree( + block, + pat.span, + false, + &mut [&mut guard_candidate, &mut otherwise_candidate], + ); self.declare_bindings( None, pat.span.to(arm_span.unwrap()), diff --git a/compiler/rustc_mir_build/src/build/matches/test.rs b/compiler/rustc_mir_build/src/build/matches/test.rs index 07173f41cd6db..126fb957a6a99 100644 --- a/compiler/rustc_mir_build/src/build/matches/test.rs +++ b/compiler/rustc_mir_build/src/build/matches/test.rs @@ -23,7 +23,7 @@ use std::cmp::Ordering; impl<'a, 'tcx> Builder<'a, 'tcx> { /// Identifies what test is needed to decide if `match_pair` is applicable. /// - /// It is a bug to call this with a simplifiable pattern. + /// It is a bug to call this with a not-fully-simplified pattern. pub(super) fn test<'pat>(&mut self, match_pair: &MatchPair<'pat, 'tcx>) -> Test<'tcx> { match *match_pair.pattern.kind { PatKind::Variant { ref adt_def, substs: _, variant_index: _, subpatterns: _ } => Test { diff --git a/compiler/rustc_mir_build/src/build/matches/util.rs b/compiler/rustc_mir_build/src/build/matches/util.rs index 4ef88c25cadf3..db1f678a5c68d 100644 --- a/compiler/rustc_mir_build/src/build/matches/util.rs +++ b/compiler/rustc_mir_build/src/build/matches/util.rs @@ -32,9 +32,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ) { let tcx = self.hir.tcx(); let (min_length, exact_size) = match place.ty(&self.local_decls, tcx).ty.kind() { - ty::Array(_, length) => { - (length.eval_usize(tcx, self.hir.param_env), true) - } + ty::Array(_, length) => (length.eval_usize(tcx, self.hir.param_env), true), _ => ((prefix.len() + suffix.len()).try_into().unwrap(), false), }; diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index e4891eb5a3c0c..8c1f73f4235c0 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -838,9 +838,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { _ => span_bug!(self.fn_span, "upvars with non-closure env ty {:?}", closure_ty), }; let capture_tys = upvar_substs.upvar_tys(); - let captures_with_tys = hir_typeck_results - .closure_min_captures_flattened(fn_def_id) - .zip(capture_tys); + let captures_with_tys = + hir_typeck_results.closure_min_captures_flattened(fn_def_id).zip(capture_tys); self.upvar_mutbls = captures_with_tys .enumerate() @@ -848,7 +847,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let capture = captured_place.info.capture_kind; let var_id = match captured_place.place.base { HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id, - _ => bug!("Expected an upvar") + _ => bug!("Expected an upvar"), }; let mutability = captured_place.mutability; diff --git a/compiler/rustc_mir_build/src/build/scope.rs b/compiler/rustc_mir_build/src/build/scope.rs index 62d2212d10962..cbc20c6153a56 100644 --- a/compiler/rustc_mir_build/src/build/scope.rs +++ b/compiler/rustc_mir_build/src/build/scope.rs @@ -931,10 +931,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let local_scope = self.local_scope(); let scope = self.scopes.scopes.last_mut().unwrap(); - assert_eq!( - scope.region_scope, local_scope, - "local scope is not the topmost scope!", - ); + assert_eq!(scope.region_scope, local_scope, "local scope is not the topmost scope!",); // look for moves of a local variable, like `MOVE(_X)` let locals_moved = operands @@ -1046,9 +1043,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { matches!( self.cfg.block_data(start).terminator().kind, TerminatorKind::Assert { .. } - | TerminatorKind::Call {..} - | TerminatorKind::DropAndReplace { .. } - | TerminatorKind::FalseUnwind { .. } + | TerminatorKind::Call { .. } + | TerminatorKind::DropAndReplace { .. } + | TerminatorKind::FalseUnwind { .. } ), "diverge_from called on block with terminator that cannot unwind." ); diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index 012b76d3d1887..6e25209f0905e 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -41,13 +41,16 @@ impl<'a> Parser<'a> { }, NonterminalKind::Block => match token.kind { token::OpenDelim(token::Brace) => true, - token::Interpolated(ref nt) => !matches!(**nt, token::NtItem(_) - | token::NtPat(_) - | token::NtTy(_) - | token::NtIdent(..) - | token::NtMeta(_) - | token::NtPath(_) - | token::NtVis(_)), + token::Interpolated(ref nt) => !matches!( + **nt, + token::NtItem(_) + | token::NtPat(_) + | token::NtTy(_) + | token::NtIdent(..) + | token::NtMeta(_) + | token::NtPath(_) + | token::NtVis(_) + ), _ => false, }, NonterminalKind::Path | NonterminalKind::Meta => match token.kind { diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index b70cec25dfb5a..e1d03e3504800 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -553,7 +553,8 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> { // optional. They inherit stability from their parents when unannotated. if !matches!( i.kind, - hir::ItemKind::Impl(hir::Impl { of_trait: None, .. }) | hir::ItemKind::ForeignMod { .. } + hir::ItemKind::Impl(hir::Impl { of_trait: None, .. }) + | hir::ItemKind::ForeignMod { .. } ) { self.check_missing_stability(i.hir_id, i.span); } diff --git a/compiler/rustc_privacy/Cargo.toml b/compiler/rustc_privacy/Cargo.toml index ce83dc1de78c7..85e584d543507 100644 --- a/compiler/rustc_privacy/Cargo.toml +++ b/compiler/rustc_privacy/Cargo.toml @@ -13,4 +13,5 @@ rustc_typeck = { path = "../rustc_typeck" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } rustc_data_structures = { path = "../rustc_data_structures" } +rustc_trait_selection = { path = "../rustc_trait_selection" } tracing = "0.1" diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 66206ca46c3a7..3fade2c443726 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -18,15 +18,17 @@ use rustc_hir::{AssocItemKind, HirIdSet, Node, PatKind}; use rustc_middle::bug; use rustc_middle::hir::map::Map; use rustc_middle::middle::privacy::{AccessLevel, AccessLevels}; +use rustc_middle::mir::abstract_const::Node as ACNode; use rustc_middle::span_bug; use rustc_middle::ty::fold::TypeVisitor; use rustc_middle::ty::query::Providers; -use rustc_middle::ty::subst::InternalSubsts; -use rustc_middle::ty::{self, GenericParamDefKind, TraitRef, Ty, TyCtxt, TypeFoldable}; +use rustc_middle::ty::subst::{InternalSubsts, Subst}; +use rustc_middle::ty::{self, Const, GenericParamDefKind, TraitRef, Ty, TyCtxt, TypeFoldable}; use rustc_session::lint; use rustc_span::hygiene::Transparency; use rustc_span::symbol::{kw, Ident}; use rustc_span::Span; +use rustc_trait_selection::traits::const_evaluatable::{self, AbstractConst}; use std::marker::PhantomData; use std::ops::ControlFlow; @@ -112,19 +114,35 @@ where ty.visit_with(self) } ty::PredicateKind::RegionOutlives(..) => ControlFlow::CONTINUE, - ty::PredicateKind::ConstEvaluatable(..) + ty::PredicateKind::ConstEvaluatable(defs, substs) if self.def_id_visitor.tcx().features().const_evaluatable_checked => { - // FIXME(const_evaluatable_checked): If the constant used here depends on a - // private function we may have to do something here... - // - // For now, let's just pretend that everything is fine. + let tcx = self.def_id_visitor.tcx(); + if let Ok(Some(ct)) = AbstractConst::new(tcx, defs, substs) { + self.visit_abstract_const_expr(tcx, ct)?; + } ControlFlow::CONTINUE } _ => bug!("unexpected predicate: {:?}", predicate), } } + fn visit_abstract_const_expr( + &mut self, + tcx: TyCtxt<'tcx>, + ct: AbstractConst<'tcx>, + ) -> ControlFlow { + const_evaluatable::walk_abstract_const(tcx, ct, |node| match node { + ACNode::Leaf(leaf) => { + let leaf = leaf.subst(tcx, ct.substs); + self.visit_const(leaf) + } + ACNode::Binop(..) | ACNode::UnaryOp(..) | ACNode::FunctionCall(_, _) => { + ControlFlow::CONTINUE + } + }) + } + fn visit_predicates( &mut self, predicates: ty::GenericPredicates<'tcx>, @@ -241,6 +259,15 @@ where ty.super_visit_with(self) } } + + fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow { + self.visit_ty(c.ty)?; + let tcx = self.def_id_visitor.tcx(); + if let Ok(Some(ct)) = AbstractConst::from_const(tcx, c) { + self.visit_abstract_const_expr(tcx, ct)?; + } + ControlFlow::CONTINUE + } } fn min(vis1: ty::Visibility, vis2: ty::Visibility, tcx: TyCtxt<'_>) -> ty::Visibility { diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index bed7a350ea86d..9c90388d24aaa 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1659,12 +1659,15 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { match missing { MissingLifetimeSpot::Generics(generics) => { let (span, sugg) = if let Some(param) = generics.params.iter().find(|p| { - !matches!(p.kind, hir::GenericParamKind::Type { - synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), - .. - } | hir::GenericParamKind::Lifetime { - kind: hir::LifetimeParamKind::Elided, - }) + !matches!( + p.kind, + hir::GenericParamKind::Type { + synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), + .. + } | hir::GenericParamKind::Lifetime { + kind: hir::LifetimeParamKind::Elided, + } + ) }) { (param.span.shrink_to_lo(), format!("{}, ", lifetime_ref)) } else { @@ -1844,10 +1847,13 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { msg = "consider introducing a named lifetime parameter".to_string(); should_break = true; if let Some(param) = generics.params.iter().find(|p| { - !matches!(p.kind, hir::GenericParamKind::Type { - synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), - .. - }) + !matches!( + p.kind, + hir::GenericParamKind::Type { + synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), + .. + } + ) }) { (param.span.shrink_to_lo(), "'a, ".to_string()) } else { diff --git a/compiler/rustc_target/src/abi/call/mod.rs b/compiler/rustc_target/src/abi/call/mod.rs index ce8e56b194980..cb37a4b231b40 100644 --- a/compiler/rustc_target/src/abi/call/mod.rs +++ b/compiler/rustc_target/src/abi/call/mod.rs @@ -526,7 +526,7 @@ impl<'a, Ty> ArgAbi<'a, Ty> { } pub fn is_indirect(&self) -> bool { - matches!(self.mode, PassMode::Indirect {..}) + matches!(self.mode, PassMode::Indirect { .. }) } pub fn is_sized_indirect(&self) -> bool { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index a42a05c5f0284..d3b3403ac3e73 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1190,9 +1190,12 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> { normalized_ty, data.ty ); - let is_normalized_ty_expected = !matches!(obligation.cause.code, ObligationCauseCode::ItemObligation(_) - | ObligationCauseCode::BindingObligation(_, _) - | ObligationCauseCode::ObjectCastObligation(_)); + let is_normalized_ty_expected = !matches!( + obligation.cause.code, + ObligationCauseCode::ItemObligation(_) + | ObligationCauseCode::BindingObligation(_, _) + | ObligationCauseCode::ObjectCastObligation(_) + ); if let Err(error) = self.at(&obligation.cause, obligation.param_env).eq_exp( is_normalized_ty_expected, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 690591930deb9..218280061643c 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -290,9 +290,9 @@ fn suggest_restriction( generics .params .iter() - .filter( - |p| !matches!(p.kind, hir::GenericParamKind::Type { synthetic: Some(_), ..}), - ) + .filter(|p| { + !matches!(p.kind, hir::GenericParamKind::Type { synthetic: Some(_), .. }) + }) .next(), super_traits, ) { diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index dbc40a2eb9662..f7c0bafff05b4 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -6,7 +6,7 @@ pub mod auto_trait; mod chalk_fulfill; pub mod codegen; mod coherence; -mod const_evaluatable; +pub mod const_evaluatable; mod engine; pub mod error_reporting; mod fulfill; diff --git a/compiler/rustc_typeck/src/astconv/generics.rs b/compiler/rustc_typeck/src/astconv/generics.rs index 0797c95636260..67e37ca8d8e49 100644 --- a/compiler/rustc_typeck/src/astconv/generics.rs +++ b/compiler/rustc_typeck/src/astconv/generics.rs @@ -496,14 +496,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { ) -> bool { let explicit = !seg.infer_args; let impl_trait = generics.params.iter().any(|param| { - matches!(param.kind, ty::GenericParamDefKind::Type { - synthetic: - Some( - hir::SyntheticTyParamKind::ImplTrait - | hir::SyntheticTyParamKind::FromAttr, + matches!( + param.kind, + ty::GenericParamDefKind::Type { + synthetic: Some( + hir::SyntheticTyParamKind::ImplTrait | hir::SyntheticTyParamKind::FromAttr, ), - .. - }) + .. + } + ) }); if explicit && impl_trait { diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index ed48a0bc801cf..bc1a07801ae87 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -274,10 +274,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } let autoborrow_mut = adj.iter().any(|adj| { - matches!(adj, &Adjustment { - kind: Adjust::Borrow(AutoBorrow::Ref(_, AutoBorrowMutability::Mut { .. })), - .. - }) + matches!( + adj, + &Adjustment { + kind: Adjust::Borrow(AutoBorrow::Ref(_, AutoBorrowMutability::Mut { .. })), + .. + } + ) }); match self.typeck_results.borrow_mut().adjustments_mut().entry(expr.hir_id) { diff --git a/library/core/src/default.rs b/library/core/src/default.rs index 9a8d65cd4e06b..28ec3279459ab 100644 --- a/library/core/src/default.rs +++ b/library/core/src/default.rs @@ -173,9 +173,11 @@ macro_rules! default_impl { impl Default for $t { #[inline] #[doc = $doc] - fn default() -> $t { $v } + fn default() -> $t { + $v + } } - } + }; } default_impl! { (), (), "Returns the default value of `()`" } diff --git a/library/std/src/io/buffered/bufwriter.rs b/library/std/src/io/buffered/bufwriter.rs index fa7bd0d72d157..65bc2fcf00ae0 100644 --- a/library/std/src/io/buffered/bufwriter.rs +++ b/library/std/src/io/buffered/bufwriter.rs @@ -117,7 +117,7 @@ impl BufWriter { /// "successfully written" (by returning nonzero success values from /// `write`), any 0-length writes from `inner` must be reported as i/o /// errors from this method. - pub(super) fn flush_buf(&mut self) -> io::Result<()> { + pub(in crate::io) fn flush_buf(&mut self) -> io::Result<()> { /// Helper struct to ensure the buffer is updated after all the writes /// are complete. It tracks the number of written bytes and drains them /// all from the front of the buffer when dropped. @@ -243,6 +243,18 @@ impl BufWriter { &self.buf } + /// Returns a mutable reference to the internal buffer. + /// + /// This can be used to write data directly into the buffer without triggering writers + /// to the underlying writer. + /// + /// That the buffer is a `Vec` is an implementation detail. + /// Callers should not modify the capacity as there currently is no public API to do so + /// and thus any capacity changes would be unexpected by the user. + pub(in crate::io) fn buffer_mut(&mut self) -> &mut Vec { + &mut self.buf + } + /// Returns the number of bytes the internal buffer can hold without flushing. /// /// # Examples diff --git a/library/std/src/io/copy.rs b/library/std/src/io/copy.rs index b88bca2f2b4ff..3780f2044cb90 100644 --- a/library/std/src/io/copy.rs +++ b/library/std/src/io/copy.rs @@ -1,4 +1,4 @@ -use crate::io::{self, ErrorKind, Read, Write}; +use super::{BufWriter, ErrorKind, Read, Result, Write, DEFAULT_BUF_SIZE}; use crate::mem::MaybeUninit; /// Copies the entire contents of a reader into a writer. @@ -40,7 +40,7 @@ use crate::mem::MaybeUninit; /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn copy(reader: &mut R, writer: &mut W) -> io::Result +pub fn copy(reader: &mut R, writer: &mut W) -> Result where R: Read, W: Write, @@ -54,14 +54,82 @@ where } } -/// The general read-write-loop implementation of -/// `io::copy` that is used when specializations are not available or not applicable. -pub(crate) fn generic_copy(reader: &mut R, writer: &mut W) -> io::Result +/// The userspace read-write-loop implementation of `io::copy` that is used when +/// OS-specific specializations for copy offloading are not available or not applicable. +pub(crate) fn generic_copy(reader: &mut R, writer: &mut W) -> Result where R: Read, W: Write, { - let mut buf = MaybeUninit::<[u8; super::DEFAULT_BUF_SIZE]>::uninit(); + BufferedCopySpec::copy_to(reader, writer) +} + +/// Specialization of the read-write loop that either uses a stack buffer +/// or reuses the internal buffer of a BufWriter +trait BufferedCopySpec: Write { + fn copy_to(reader: &mut R, writer: &mut Self) -> Result; +} + +impl BufferedCopySpec for W { + default fn copy_to(reader: &mut R, writer: &mut Self) -> Result { + stack_buffer_copy(reader, writer) + } +} + +impl BufferedCopySpec for BufWriter { + fn copy_to(reader: &mut R, writer: &mut Self) -> Result { + if writer.capacity() < DEFAULT_BUF_SIZE { + return stack_buffer_copy(reader, writer); + } + + // FIXME: #42788 + // + // - This creates a (mut) reference to a slice of + // _uninitialized_ integers, which is **undefined behavior** + // + // - Only the standard library gets to soundly "ignore" this, + // based on its privileged knowledge of unstable rustc + // internals; + unsafe { + let spare_cap = writer.buffer_mut().spare_capacity_mut(); + reader.initializer().initialize(MaybeUninit::slice_assume_init_mut(spare_cap)); + } + + let mut len = 0; + + loop { + let buf = writer.buffer_mut(); + let spare_cap = buf.spare_capacity_mut(); + + if spare_cap.len() >= DEFAULT_BUF_SIZE { + match reader.read(unsafe { MaybeUninit::slice_assume_init_mut(spare_cap) }) { + Ok(0) => return Ok(len), // EOF reached + Ok(bytes_read) => { + assert!(bytes_read <= spare_cap.len()); + // Safety: The initializer contract guarantees that either it or `read` + // will have initialized these bytes. And we just checked that the number + // of bytes is within the buffer capacity. + unsafe { buf.set_len(buf.len() + bytes_read) }; + len += bytes_read as u64; + // Read again if the buffer still has enough capacity, as BufWriter itself would do + // This will occur if the reader returns short reads + continue; + } + Err(ref e) if e.kind() == ErrorKind::Interrupted => continue, + Err(e) => return Err(e), + } + } + + writer.flush_buf()?; + } + } +} + +fn stack_buffer_copy( + reader: &mut R, + writer: &mut W, +) -> Result { + let mut buf = MaybeUninit::<[u8; DEFAULT_BUF_SIZE]>::uninit(); // FIXME: #42788 // // - This creates a (mut) reference to a slice of diff --git a/library/std/src/io/util/tests.rs b/library/std/src/io/util/tests.rs index df34e27d1361b..7632eaf872a5b 100644 --- a/library/std/src/io/util/tests.rs +++ b/library/std/src/io/util/tests.rs @@ -1,5 +1,8 @@ +use crate::cmp::{max, min}; use crate::io::prelude::*; -use crate::io::{copy, empty, repeat, sink, Empty, Repeat, SeekFrom, Sink}; +use crate::io::{ + copy, empty, repeat, sink, BufWriter, Empty, Repeat, Result, SeekFrom, Sink, DEFAULT_BUF_SIZE, +}; #[test] fn copy_copies() { @@ -11,6 +14,51 @@ fn copy_copies() { assert_eq!(copy(&mut r as &mut dyn Read, &mut w as &mut dyn Write).unwrap(), 1 << 17); } +struct ShortReader { + cap: usize, + read_size: usize, + observed_buffer: usize, +} + +impl Read for ShortReader { + fn read(&mut self, buf: &mut [u8]) -> Result { + let bytes = min(self.cap, self.read_size); + self.cap -= bytes; + self.observed_buffer = max(self.observed_buffer, buf.len()); + Ok(bytes) + } +} + +struct WriteObserver { + observed_buffer: usize, +} + +impl Write for WriteObserver { + fn write(&mut self, buf: &[u8]) -> Result { + self.observed_buffer = max(self.observed_buffer, buf.len()); + Ok(buf.len()) + } + + fn flush(&mut self) -> Result<()> { + Ok(()) + } +} + +#[test] +fn copy_specializes_bufwriter() { + let cap = 117 * 1024; + let buf_sz = 16 * 1024; + let mut r = ShortReader { cap, observed_buffer: 0, read_size: 1337 }; + let mut w = BufWriter::with_capacity(buf_sz, WriteObserver { observed_buffer: 0 }); + assert_eq!( + copy(&mut r, &mut w).unwrap(), + cap as u64, + "expected the whole capacity to be copied" + ); + assert_eq!(r.observed_buffer, buf_sz, "expected a large buffer to be provided to the reader"); + assert!(w.get_mut().observed_buffer > DEFAULT_BUF_SIZE, "expected coalesced writes"); +} + #[test] fn sink_sinks() { let mut s = sink(); diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index c1b79ff716c72..f16fb3d04db45 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -283,6 +283,7 @@ #![feature(maybe_uninit_extra)] #![feature(maybe_uninit_ref)] #![feature(maybe_uninit_slice)] +#![feature(maybe_uninit_uninit_array)] #![feature(min_specialization)] #![feature(needs_panic_runtime)] #![feature(negative_impls)] @@ -326,6 +327,7 @@ #![feature(unsafe_cell_raw_get)] #![feature(unwind_attributes)] #![feature(vec_into_raw_parts)] +#![feature(vec_spare_capacity)] #![feature(wake_trait)] // NB: the above list is sorted to minimize merge conflicts. #![default_lib_allocator] diff --git a/rustfmt.toml b/rustfmt.toml index 45cce186c0996..af807aa6f739e 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -6,7 +6,7 @@ merge_derives = false # by default we ignore everything in the repository # tidy only checks files which are not ignored, each entry follows gitignore style ignore = [ - "build", + "/build/", "/vendor/", # tests for now are not formatted, as they are sometimes pretty-printing constrained diff --git a/src/bootstrap/bin/main.rs b/src/bootstrap/bin/main.rs index 07e582d4d2941..a32a4a7fe56c2 100644 --- a/src/bootstrap/bin/main.rs +++ b/src/bootstrap/bin/main.rs @@ -15,7 +15,7 @@ fn main() { // check_version warnings are not printed during setup let changelog_suggestion = - if matches!(config.cmd, Subcommand::Setup {..}) { None } else { check_version(&config) }; + if matches!(config.cmd, Subcommand::Setup { .. }) { None } else { check_version(&config) }; // NOTE: Since `./configure` generates a `config.toml`, distro maintainers will see the // changelog warning, not the `x.py setup` message. diff --git a/src/stage0.txt b/src/stage0.txt index e853b9b4e4191..d3c76eb282a7e 100644 --- a/src/stage0.txt +++ b/src/stage0.txt @@ -19,7 +19,7 @@ rustc: beta # bootstrapping issues with use of new syntax in this repo. If you're looking at # the beta/stable branch, this key should be omitted, as we don't want to depend # on rustfmt from nightly there. -rustfmt: nightly-2020-11-19 +rustfmt: nightly-2021-01-28 # When making a stable release the process currently looks like: # diff --git a/src/test/ui/issues/issue-18425.rs b/src/test/ui/array-slice-vec/issue-18425.rs similarity index 100% rename from src/test/ui/issues/issue-18425.rs rename to src/test/ui/array-slice-vec/issue-18425.rs diff --git a/src/test/ui/issues/issue-18655.rs b/src/test/ui/associated-types/issue-18655.rs similarity index 100% rename from src/test/ui/issues/issue-18655.rs rename to src/test/ui/associated-types/issue-18655.rs diff --git a/src/test/ui/issues/issue-22037.rs b/src/test/ui/associated-types/issue-22037.rs similarity index 100% rename from src/test/ui/issues/issue-22037.rs rename to src/test/ui/associated-types/issue-22037.rs diff --git a/src/test/ui/issues/issue-22037.stderr b/src/test/ui/associated-types/issue-22037.stderr similarity index 100% rename from src/test/ui/issues/issue-22037.stderr rename to src/test/ui/associated-types/issue-22037.stderr diff --git a/src/test/ui/issues/issue-73541-2.rs b/src/test/ui/async-await/issue-73541-2.rs similarity index 100% rename from src/test/ui/issues/issue-73541-2.rs rename to src/test/ui/async-await/issue-73541-2.rs diff --git a/src/test/ui/issues/issue-73541-2.stderr b/src/test/ui/async-await/issue-73541-2.stderr similarity index 100% rename from src/test/ui/issues/issue-73541-2.stderr rename to src/test/ui/async-await/issue-73541-2.stderr diff --git a/src/test/ui/issues/issue-33819.rs b/src/test/ui/borrowck/issue-33819.rs similarity index 100% rename from src/test/ui/issues/issue-33819.rs rename to src/test/ui/borrowck/issue-33819.rs diff --git a/src/test/ui/issues/issue-33819.stderr b/src/test/ui/borrowck/issue-33819.stderr similarity index 100% rename from src/test/ui/issues/issue-33819.stderr rename to src/test/ui/borrowck/issue-33819.stderr diff --git a/src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.rs b/src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.rs new file mode 100644 index 0000000000000..9f457fbd346cd --- /dev/null +++ b/src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.rs @@ -0,0 +1,31 @@ +#![crate_type = "lib"] +#![feature(const_generics, const_evaluatable_checked)] +#![allow(incomplete_features)] + +pub struct Const; + +pub trait Trait { + type AssocTy; + fn assoc_fn() -> Self::AssocTy; +} + +impl Trait for Const +//~^ WARN private type +//~| WARN this was previously +//~| WARN private type +//~| WARN this was previously + +where + Const<{ my_const_fn(U) }>: , +{ + type AssocTy = Const<{ my_const_fn(U) }>; + //~^ ERROR private type + fn assoc_fn() -> Self::AssocTy { + Const + } +} + +const fn my_const_fn(val: u8) -> u8 { + // body of this function doesn't matter + val +} diff --git a/src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.stderr b/src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.stderr new file mode 100644 index 0000000000000..842c22c5c6775 --- /dev/null +++ b/src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.stderr @@ -0,0 +1,43 @@ +warning: private type `fn(u8) -> u8 {my_const_fn}` in public interface (error E0446) + --> $DIR/eval-privacy.rs:12:1 + | +LL | / impl Trait for Const +LL | | +LL | | +LL | | +... | +LL | | } +LL | | } + | |_^ + | + = note: `#[warn(private_in_public)]` on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #34537 + +warning: private type `fn(u8) -> u8 {my_const_fn}` in public interface (error E0446) + --> $DIR/eval-privacy.rs:12:1 + | +LL | / impl Trait for Const +LL | | +LL | | +LL | | +... | +LL | | } +LL | | } + | |_^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #34537 + +error[E0446]: private type `fn(u8) -> u8 {my_const_fn}` in public interface + --> $DIR/eval-privacy.rs:21:5 + | +LL | type AssocTy = Const<{ my_const_fn(U) }>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type +... +LL | const fn my_const_fn(val: u8) -> u8 { + | ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private + +error: aborting due to previous error; 2 warnings emitted + +For more information about this error, try `rustc --explain E0446`. diff --git a/src/test/ui/issues/issue-17458.rs b/src/test/ui/consts/issue-17458.rs similarity index 100% rename from src/test/ui/issues/issue-17458.rs rename to src/test/ui/consts/issue-17458.rs diff --git a/src/test/ui/issues/issue-17458.stderr b/src/test/ui/consts/issue-17458.stderr similarity index 100% rename from src/test/ui/issues/issue-17458.stderr rename to src/test/ui/consts/issue-17458.stderr diff --git a/src/test/ui/issues/issue-25826.rs b/src/test/ui/consts/issue-25826.rs similarity index 100% rename from src/test/ui/issues/issue-25826.rs rename to src/test/ui/consts/issue-25826.rs diff --git a/src/test/ui/issues/issue-25826.stderr b/src/test/ui/consts/issue-25826.stderr similarity index 100% rename from src/test/ui/issues/issue-25826.stderr rename to src/test/ui/consts/issue-25826.stderr diff --git a/src/test/ui/issues/issue-46553.rs b/src/test/ui/consts/issue-46553.rs similarity index 100% rename from src/test/ui/issues/issue-46553.rs rename to src/test/ui/consts/issue-46553.rs diff --git a/src/test/ui/issues/issue-54348.rs b/src/test/ui/consts/issue-54348.rs similarity index 100% rename from src/test/ui/issues/issue-54348.rs rename to src/test/ui/consts/issue-54348.rs diff --git a/src/test/ui/issues/issue-54348.stderr b/src/test/ui/consts/issue-54348.stderr similarity index 100% rename from src/test/ui/issues/issue-54348.stderr rename to src/test/ui/consts/issue-54348.stderr diff --git a/src/test/ui/issues/issue-56762.rs b/src/test/ui/consts/issue-56762.rs similarity index 100% rename from src/test/ui/issues/issue-56762.rs rename to src/test/ui/consts/issue-56762.rs diff --git a/src/test/ui/issues/issue-56762.stderr b/src/test/ui/consts/issue-56762.stderr similarity index 100% rename from src/test/ui/issues/issue-56762.stderr rename to src/test/ui/consts/issue-56762.stderr diff --git a/src/test/ui/issues/issue-10763.rs b/src/test/ui/extern/issue-10763.rs similarity index 100% rename from src/test/ui/issues/issue-10763.rs rename to src/test/ui/extern/issue-10763.rs diff --git a/src/test/ui/issues/issue-10764-rpass.rs b/src/test/ui/extern/issue-10764-rpass.rs similarity index 100% rename from src/test/ui/issues/issue-10764-rpass.rs rename to src/test/ui/extern/issue-10764-rpass.rs diff --git a/src/test/ui/issues/issue-2216.rs b/src/test/ui/for-loop-while/issue-2216.rs similarity index 100% rename from src/test/ui/issues/issue-2216.rs rename to src/test/ui/for-loop-while/issue-2216.rs diff --git a/src/test/ui/issues/issue-69841.rs b/src/test/ui/for-loop-while/issue-69841.rs similarity index 100% rename from src/test/ui/issues/issue-69841.rs rename to src/test/ui/for-loop-while/issue-69841.rs diff --git a/src/test/ui/issues/issue-14309.rs b/src/test/ui/lint/issue-14309.rs similarity index 100% rename from src/test/ui/issues/issue-14309.rs rename to src/test/ui/lint/issue-14309.rs diff --git a/src/test/ui/issues/issue-14309.stderr b/src/test/ui/lint/issue-14309.stderr similarity index 100% rename from src/test/ui/issues/issue-14309.stderr rename to src/test/ui/lint/issue-14309.stderr diff --git a/src/test/ui/lint/special-upper-lower-cases.stderr b/src/test/ui/lint/special-upper-lower-cases.stderr index f32193a2e4a47..e3b451a15a2cc 100644 --- a/src/test/ui/lint/special-upper-lower-cases.stderr +++ b/src/test/ui/lint/special-upper-lower-cases.stderr @@ -2,7 +2,7 @@ warning: type `𝕟𝕠𝕥𝕒𝕔𝕒𝕞𝕖𝕝` should have an upper camel --> $DIR/special-upper-lower-cases.rs:11:8 | LL | struct 𝕟𝕠𝕥𝕒𝕔𝕒𝕞𝕖𝕝; - | ^^^^^^^^^ + | ^^^^^^^^^ should have an UpperCamelCase name | = note: `#[warn(non_camel_case_types)]` on by default @@ -10,13 +10,13 @@ warning: type `𝕟𝕠𝕥_𝕒_𝕔𝕒𝕞𝕖𝕝` should have an upper came --> $DIR/special-upper-lower-cases.rs:15:8 | LL | struct 𝕟𝕠𝕥_𝕒_𝕔𝕒𝕞𝕖𝕝; - | ^^^^^^^^^^^ help: convert the identifier to upper camel case: `𝕟𝕠𝕥𝕒𝕔𝕒𝕞𝕖𝕝` + | ^^^^^^^^^^^ should have an UpperCamelCase name warning: static variable `𝗻𝗼𝗻𝘂𝗽𝗽𝗲𝗿𝗰𝗮𝘀𝗲` should have an upper case name --> $DIR/special-upper-lower-cases.rs:18:8 | LL | static 𝗻𝗼𝗻𝘂𝗽𝗽𝗲𝗿𝗰𝗮𝘀𝗲: i32 = 1; - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^^ should have an UPPER_CASE name | = note: `#[warn(non_upper_case_globals)]` on by default @@ -24,7 +24,7 @@ warning: variable `𝓢𝓝𝓐𝓐𝓐𝓐𝓚𝓔𝓢` should have a snake cas --> $DIR/special-upper-lower-cases.rs:22:9 | LL | let 𝓢𝓝𝓐𝓐𝓐𝓐𝓚𝓔𝓢 = 1; - | ^^^^^^^^^ + | ^^^^^^^^^ should have a snake_case name | = note: `#[warn(non_snake_case)]` on by default diff --git a/src/test/ui/issues/issue-33264.rs b/src/test/ui/llvm-asm/issue-33264.rs similarity index 100% rename from src/test/ui/issues/issue-33264.rs rename to src/test/ui/llvm-asm/issue-33264.rs diff --git a/src/test/ui/issues/issue-8709.rs b/src/test/ui/macros/issue-8709.rs similarity index 100% rename from src/test/ui/issues/issue-8709.rs rename to src/test/ui/macros/issue-8709.rs diff --git a/src/test/ui/issues/issue-45696-scribble-on-boxed-borrow.rs b/src/test/ui/nll/issue-45696-scribble-on-boxed-borrow.rs similarity index 100% rename from src/test/ui/issues/issue-45696-scribble-on-boxed-borrow.rs rename to src/test/ui/nll/issue-45696-scribble-on-boxed-borrow.rs diff --git a/src/test/ui/issues/issue-45696-scribble-on-boxed-borrow.stderr b/src/test/ui/nll/issue-45696-scribble-on-boxed-borrow.stderr similarity index 100% rename from src/test/ui/issues/issue-45696-scribble-on-boxed-borrow.stderr rename to src/test/ui/nll/issue-45696-scribble-on-boxed-borrow.stderr diff --git a/src/test/ui/issues/issue-46036.rs b/src/test/ui/nll/issue-46036.rs similarity index 100% rename from src/test/ui/issues/issue-46036.rs rename to src/test/ui/nll/issue-46036.rs diff --git a/src/test/ui/issues/issue-46036.stderr b/src/test/ui/nll/issue-46036.stderr similarity index 100% rename from src/test/ui/issues/issue-46036.stderr rename to src/test/ui/nll/issue-46036.stderr diff --git a/src/test/ui/issues/issue-20616-8.rs b/src/test/ui/parser/issue-20616-8.rs similarity index 100% rename from src/test/ui/issues/issue-20616-8.rs rename to src/test/ui/parser/issue-20616-8.rs diff --git a/src/test/ui/issues/issue-20616-8.stderr b/src/test/ui/parser/issue-20616-8.stderr similarity index 100% rename from src/test/ui/issues/issue-20616-8.stderr rename to src/test/ui/parser/issue-20616-8.stderr diff --git a/src/test/ui/issues/issue-20616-9.rs b/src/test/ui/parser/issue-20616-9.rs similarity index 100% rename from src/test/ui/issues/issue-20616-9.rs rename to src/test/ui/parser/issue-20616-9.rs diff --git a/src/test/ui/issues/issue-20616-9.stderr b/src/test/ui/parser/issue-20616-9.stderr similarity index 100% rename from src/test/ui/issues/issue-20616-9.stderr rename to src/test/ui/parser/issue-20616-9.stderr diff --git a/src/test/ui/issues/issue-57198.rs b/src/test/ui/parser/issue-57198.rs similarity index 100% rename from src/test/ui/issues/issue-57198.rs rename to src/test/ui/parser/issue-57198.rs diff --git a/src/test/ui/issues/issue-57198.stderr b/src/test/ui/parser/issue-57198.stderr similarity index 100% rename from src/test/ui/issues/issue-57198.stderr rename to src/test/ui/parser/issue-57198.stderr diff --git a/src/test/ui/issues/issue-57684.fixed b/src/test/ui/parser/issue-57684.fixed similarity index 100% rename from src/test/ui/issues/issue-57684.fixed rename to src/test/ui/parser/issue-57684.fixed diff --git a/src/test/ui/issues/issue-57684.rs b/src/test/ui/parser/issue-57684.rs similarity index 100% rename from src/test/ui/issues/issue-57684.rs rename to src/test/ui/parser/issue-57684.rs diff --git a/src/test/ui/issues/issue-57684.stderr b/src/test/ui/parser/issue-57684.stderr similarity index 100% rename from src/test/ui/issues/issue-57684.stderr rename to src/test/ui/parser/issue-57684.stderr diff --git a/src/test/ui/issues/issue-57819.fixed b/src/test/ui/parser/issue-57819.fixed similarity index 100% rename from src/test/ui/issues/issue-57819.fixed rename to src/test/ui/parser/issue-57819.fixed diff --git a/src/test/ui/issues/issue-57819.rs b/src/test/ui/parser/issue-57819.rs similarity index 100% rename from src/test/ui/issues/issue-57819.rs rename to src/test/ui/parser/issue-57819.rs diff --git a/src/test/ui/issues/issue-57819.stderr b/src/test/ui/parser/issue-57819.stderr similarity index 100% rename from src/test/ui/issues/issue-57819.stderr rename to src/test/ui/parser/issue-57819.stderr diff --git a/src/test/ui/issues/issue-58856-1.rs b/src/test/ui/parser/issue-58856-1.rs similarity index 100% rename from src/test/ui/issues/issue-58856-1.rs rename to src/test/ui/parser/issue-58856-1.rs diff --git a/src/test/ui/issues/issue-58856-1.stderr b/src/test/ui/parser/issue-58856-1.stderr similarity index 100% rename from src/test/ui/issues/issue-58856-1.stderr rename to src/test/ui/parser/issue-58856-1.stderr diff --git a/src/test/ui/issues/issue-64732.rs b/src/test/ui/parser/issue-64732.rs similarity index 100% rename from src/test/ui/issues/issue-64732.rs rename to src/test/ui/parser/issue-64732.rs diff --git a/src/test/ui/issues/issue-64732.stderr b/src/test/ui/parser/issue-64732.stderr similarity index 100% rename from src/test/ui/issues/issue-64732.stderr rename to src/test/ui/parser/issue-64732.stderr diff --git a/src/test/ui/issues/issue-7970b.rs b/src/test/ui/parser/issue-7970b.rs similarity index 100% rename from src/test/ui/issues/issue-7970b.rs rename to src/test/ui/parser/issue-7970b.rs diff --git a/src/test/ui/issues/issue-7970b.stderr b/src/test/ui/parser/issue-7970b.stderr similarity index 100% rename from src/test/ui/issues/issue-7970b.stderr rename to src/test/ui/parser/issue-7970b.stderr diff --git a/src/test/ui/issues/issue-50599.rs b/src/test/ui/resolve/issue-50599.rs similarity index 100% rename from src/test/ui/issues/issue-50599.rs rename to src/test/ui/resolve/issue-50599.rs diff --git a/src/test/ui/issues/issue-50599.stderr b/src/test/ui/resolve/issue-50599.stderr similarity index 100% rename from src/test/ui/issues/issue-50599.stderr rename to src/test/ui/resolve/issue-50599.stderr diff --git a/src/test/ui/issues/issue-32947.rs b/src/test/ui/simd/issue-32947.rs similarity index 100% rename from src/test/ui/issues/issue-32947.rs rename to src/test/ui/simd/issue-32947.rs diff --git a/src/test/ui/issues/issue-53675-a-test-called-panic.rs b/src/test/ui/test-attrs/issue-53675-a-test-called-panic.rs similarity index 100% rename from src/test/ui/issues/issue-53675-a-test-called-panic.rs rename to src/test/ui/test-attrs/issue-53675-a-test-called-panic.rs diff --git a/src/test/ui/issues/issue-4446.rs b/src/test/ui/threads-sendsync/issue-4446.rs similarity index 100% rename from src/test/ui/issues/issue-4446.rs rename to src/test/ui/threads-sendsync/issue-4446.rs diff --git a/src/test/ui/issues/issue-33140-hack-boundaries.rs b/src/test/ui/traits/issue-33140-hack-boundaries.rs similarity index 100% rename from src/test/ui/issues/issue-33140-hack-boundaries.rs rename to src/test/ui/traits/issue-33140-hack-boundaries.rs diff --git a/src/test/ui/issues/issue-33140-hack-boundaries.stderr b/src/test/ui/traits/issue-33140-hack-boundaries.stderr similarity index 100% rename from src/test/ui/issues/issue-33140-hack-boundaries.stderr rename to src/test/ui/traits/issue-33140-hack-boundaries.stderr diff --git a/src/test/ui/issues/issue-3683.rs b/src/test/ui/traits/issue-3683.rs similarity index 100% rename from src/test/ui/issues/issue-3683.rs rename to src/test/ui/traits/issue-3683.rs diff --git a/src/test/ui/issues/issue-56202.rs b/src/test/ui/traits/issue-56202.rs similarity index 100% rename from src/test/ui/issues/issue-56202.rs rename to src/test/ui/traits/issue-56202.rs diff --git a/src/test/ui/issues/issue-56488.rs b/src/test/ui/traits/issue-56488.rs similarity index 100% rename from src/test/ui/issues/issue-56488.rs rename to src/test/ui/traits/issue-56488.rs diff --git a/src/test/ui/issues/issue-59029-2.rs b/src/test/ui/traits/issue-59029-2.rs similarity index 100% rename from src/test/ui/issues/issue-59029-2.rs rename to src/test/ui/traits/issue-59029-2.rs diff --git a/src/test/ui/issues/issue-6128.rs b/src/test/ui/traits/issue-6128.rs similarity index 100% rename from src/test/ui/issues/issue-6128.rs rename to src/test/ui/traits/issue-6128.rs diff --git a/src/test/ui/issues/issue-65284-suggest-generic-trait-bound.rs b/src/test/ui/traits/issue-65284-suggest-generic-trait-bound.rs similarity index 100% rename from src/test/ui/issues/issue-65284-suggest-generic-trait-bound.rs rename to src/test/ui/traits/issue-65284-suggest-generic-trait-bound.rs diff --git a/src/test/ui/issues/issue-65284-suggest-generic-trait-bound.stderr b/src/test/ui/traits/issue-65284-suggest-generic-trait-bound.stderr similarity index 100% rename from src/test/ui/issues/issue-65284-suggest-generic-trait-bound.stderr rename to src/test/ui/traits/issue-65284-suggest-generic-trait-bound.stderr diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index 21d05226fb42c..74ed236675208 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -8,7 +8,7 @@ use std::path::Path; const ENTRY_LIMIT: usize = 1000; // FIXME: The following limits should be reduced eventually. const ROOT_ENTRY_LIMIT: usize = 1459; -const ISSUES_ENTRY_LIMIT: usize = 2669; +const ISSUES_ENTRY_LIMIT: usize = 2615; fn check_entries(path: &Path, bad: &mut bool) { let dirs = walkdir::WalkDir::new(&path.join("test/ui"))