From 9ebe2d0c9299a28d32fb22a88e56ddaaef20c8ff Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Wed, 29 Jun 2022 11:29:51 +0900 Subject: [PATCH 1/5] add regression test for #79494 use MCVE --- src/test/rustdoc-ui/issue-79494.rs | 5 +++++ src/test/rustdoc-ui/issue-79494.stderr | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/test/rustdoc-ui/issue-79494.rs create mode 100644 src/test/rustdoc-ui/issue-79494.stderr diff --git a/src/test/rustdoc-ui/issue-79494.rs b/src/test/rustdoc-ui/issue-79494.rs new file mode 100644 index 0000000000000..fc39424b793f6 --- /dev/null +++ b/src/test/rustdoc-ui/issue-79494.rs @@ -0,0 +1,5 @@ +// only-x86_64-unknown-linux-gnu + +#![feature(const_transmute)] + +const ZST: &[u8] = unsafe { std::mem::transmute(1usize) }; //~ ERROR cannot transmute between types of different sizes, or dependently-sized types diff --git a/src/test/rustdoc-ui/issue-79494.stderr b/src/test/rustdoc-ui/issue-79494.stderr new file mode 100644 index 0000000000000..7ed5ed3824716 --- /dev/null +++ b/src/test/rustdoc-ui/issue-79494.stderr @@ -0,0 +1,12 @@ +error[E0512]: cannot transmute between types of different sizes, or dependently-sized types + --> $DIR/issue-79494.rs:5:29 + | +LL | const ZST: &[u8] = unsafe { std::mem::transmute(1usize) }; + | ^^^^^^^^^^^^^^^^^^^ + | + = note: source type: `usize` (64 bits) + = note: target type: `&[u8]` (128 bits) + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0512`. From 5122bb5572ef2a784cfbd11864bc7a3942d9abe3 Mon Sep 17 00:00:00 2001 From: Andy Fiddaman Date: Fri, 1 Jul 2022 13:21:18 +0000 Subject: [PATCH 2/5] bootstrap: illumos platform flags for split-debuginfo Bootstrap currently provides `-Zunstable-options` for platforms when using split debuginfo - this commit adds it for the illumos target too. --- src/bootstrap/builder.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 62b5416cee8af..755c532ab3260 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1760,7 +1760,8 @@ impl<'a> Builder<'a> { let needs_unstable_opts = target.contains("linux") || target.contains("windows") || target.contains("bsd") - || target.contains("dragonfly"); + || target.contains("dragonfly") + || target.contains("illumos"); if needs_unstable_opts { rustflags.arg("-Zunstable-options"); From cf9c0a5935d833a52171cd3797616f2abc9e3b5a Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 1 Jul 2022 16:21:21 +0200 Subject: [PATCH 3/5] cleanup mir visitor for `rustc::pass_by_value` --- compiler/rustc_borrowck/src/borrow_set.rs | 8 +- .../src/diagnostics/find_all_local_uses.rs | 4 +- .../src/diagnostics/find_use.rs | 2 +- .../src/type_check/liveness/local_use_map.rs | 2 +- .../src/type_check/liveness/polonius.rs | 2 +- compiler/rustc_borrowck/src/type_check/mod.rs | 4 +- compiler/rustc_borrowck/src/used_muts.rs | 4 +- compiler/rustc_codegen_ssa/src/mir/analyze.rs | 6 +- .../src/transform/check_consts/check.rs | 4 +- .../src/transform/promote_consts.rs | 2 +- .../src/transform/validate.rs | 10 +- .../src/util/collect_writes.rs | 4 +- compiler/rustc_middle/src/mir/visit.rs | 255 ++++++++++-------- .../src/impls/init_locals.rs | 2 +- .../rustc_mir_dataflow/src/impls/liveness.rs | 2 +- .../src/impls/storage_liveness.rs | 6 +- .../src/const_debuginfo.rs | 6 +- .../rustc_mir_transform/src/const_prop.rs | 2 +- .../src/const_prop_lint.rs | 2 +- compiler/rustc_mir_transform/src/nrvo.rs | 2 +- compiler/rustc_mir_transform/src/simplify.rs | 8 +- .../rustc_mir_transform/src/simplify_try.rs | 4 +- compiler/rustc_monomorphize/src/collector.rs | 2 +- 23 files changed, 193 insertions(+), 150 deletions(-) diff --git a/compiler/rustc_borrowck/src/borrow_set.rs b/compiler/rustc_borrowck/src/borrow_set.rs index c7d0e3361331c..41279588e6334 100644 --- a/compiler/rustc_borrowck/src/borrow_set.rs +++ b/compiler/rustc_borrowck/src/borrow_set.rs @@ -92,9 +92,9 @@ impl LocalsStateAtExit { struct HasStorageDead(BitSet); impl<'tcx> Visitor<'tcx> for HasStorageDead { - fn visit_local(&mut self, local: &Local, ctx: PlaceContext, _: Location) { + fn visit_local(&mut self, local: Local, ctx: PlaceContext, _: Location) { if ctx == PlaceContext::NonUse(NonUseContext::StorageDead) { - self.0.insert(*local); + self.0.insert(local); } } } @@ -223,7 +223,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> { self.super_assign(assigned_place, rvalue, location) } - fn visit_local(&mut self, temp: &Local, context: PlaceContext, location: Location) { + fn visit_local(&mut self, temp: Local, context: PlaceContext, location: Location) { if !context.is_use() { return; } @@ -232,7 +232,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> { // check whether we (earlier) saw a 2-phase borrow like // // TMP = &mut place - if let Some(&borrow_index) = self.pending_activations.get(temp) { + if let Some(&borrow_index) = self.pending_activations.get(&temp) { let borrow_data = &mut self.location_map[borrow_index.as_usize()]; // Watch out: the use of TMP in the borrow itself diff --git a/compiler/rustc_borrowck/src/diagnostics/find_all_local_uses.rs b/compiler/rustc_borrowck/src/diagnostics/find_all_local_uses.rs index 49d9caae71144..b3edc35dc3642 100644 --- a/compiler/rustc_borrowck/src/diagnostics/find_all_local_uses.rs +++ b/compiler/rustc_borrowck/src/diagnostics/find_all_local_uses.rs @@ -18,8 +18,8 @@ struct AllLocalUsesVisitor { } impl<'tcx> Visitor<'tcx> for AllLocalUsesVisitor { - fn visit_local(&mut self, local: &Local, _context: PlaceContext, location: Location) { - if *local == self.for_local { + fn visit_local(&mut self, local: Local, _context: PlaceContext, location: Location) { + if local == self.for_local { self.uses.insert(location); } } diff --git a/compiler/rustc_borrowck/src/diagnostics/find_use.rs b/compiler/rustc_borrowck/src/diagnostics/find_use.rs index 06fca4db0cf1f..b5a3081e56a7a 100644 --- a/compiler/rustc_borrowck/src/diagnostics/find_use.rs +++ b/compiler/rustc_borrowck/src/diagnostics/find_use.rs @@ -106,7 +106,7 @@ enum DefUseResult { } impl<'cx, 'tcx> Visitor<'tcx> for DefUseVisitor<'cx, 'tcx> { - fn visit_local(&mut self, &local: &Local, context: PlaceContext, _: Location) { + fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) { let local_ty = self.body.local_decls[local].ty; let mut found_it = false; diff --git a/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs b/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs index b88f6e689cc80..fda2cee43fbf1 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs @@ -157,7 +157,7 @@ impl LocalUseMapBuild<'_> { } impl Visitor<'_> for LocalUseMapBuild<'_> { - fn visit_local(&mut self, &local: &Local, context: PlaceContext, location: Location) { + fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) { if self.locals_with_use_data[local] { match def_use::categorize(context) { Some(DefUse::Def) => self.insert_def(local, location), diff --git a/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs b/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs index 8070f3579194d..bc76a465e3c3a 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs @@ -54,7 +54,7 @@ impl UseFactsExtractor<'_, '_> { } impl<'a, 'tcx> Visitor<'tcx> for UseFactsExtractor<'a, 'tcx> { - fn visit_local(&mut self, &local: &Local, context: PlaceContext, location: Location) { + fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) { match def_use::categorize(context) { Some(DefUse::Def) => self.insert_def(local, location), Some(DefUse::Use) => self.insert_use(local, location), diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 5ee1f5a8e8e37..a21a8dd48be2b 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -333,9 +333,9 @@ struct TypeVerifier<'a, 'b, 'tcx> { } impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { - fn visit_span(&mut self, span: &Span) { + fn visit_span(&mut self, span: Span) { if !span.is_dummy() { - self.last_span = *span; + self.last_span = span; } } diff --git a/compiler/rustc_borrowck/src/used_muts.rs b/compiler/rustc_borrowck/src/used_muts.rs index 1093167fa8299..8833753b12c5d 100644 --- a/compiler/rustc_borrowck/src/used_muts.rs +++ b/compiler/rustc_borrowck/src/used_muts.rs @@ -91,8 +91,8 @@ impl<'visit, 'cx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'cx, 'tc self.super_statement(statement, location); } - fn visit_local(&mut self, local: &Local, place_context: PlaceContext, location: Location) { - if place_context.is_place_assignment() && self.temporary_used_locals.contains(local) { + fn visit_local(&mut self, local: Local, place_context: PlaceContext, location: Location) { + if place_context.is_place_assignment() && self.temporary_used_locals.contains(&local) { // Propagate the Local assigned at this Location as a used mutable local variable for moi in &self.mbcx.move_data.loc_map[location] { let mpi = &self.mbcx.move_data.moves[*moi].path; diff --git a/compiler/rustc_codegen_ssa/src/mir/analyze.rs b/compiler/rustc_codegen_ssa/src/mir/analyze.rs index 80dab115fac46..5c26168b50d65 100644 --- a/compiler/rustc_codegen_ssa/src/mir/analyze.rs +++ b/compiler/rustc_codegen_ssa/src/mir/analyze.rs @@ -143,13 +143,13 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, // now that we have moved to the "slice of projections" representation. if let mir::ProjectionElem::Index(local) = elem { self.visit_local( - &local, + local, PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy), location, ); } } else { - self.visit_local(&place_ref.local, context, location); + self.visit_local(place_ref.local, context, location); } } } @@ -185,7 +185,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx> self.process_place(&place.as_ref(), context, location); } - fn visit_local(&mut self, &local: &mir::Local, context: PlaceContext, location: Location) { + fn visit_local(&mut self, local: mir::Local, context: PlaceContext, location: Location) { match context { PlaceContext::MutatingUse(MutatingUseContext::Call) | PlaceContext::MutatingUse(MutatingUseContext::Yield) => { diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index 069fbed36ee3a..dc46583d5afbe 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -418,7 +418,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { PlaceContext::MutatingUse(MutatingUseContext::Borrow) } }; - self.visit_local(&reborrowed_place_ref.local, ctx, location); + self.visit_local(reborrowed_place_ref.local, ctx, location); self.visit_projection(reborrowed_place_ref, ctx, location); return; } @@ -431,7 +431,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { } Mutability::Mut => PlaceContext::MutatingUse(MutatingUseContext::AddressOf), }; - self.visit_local(&reborrowed_place_ref.local, ctx, location); + self.visit_local(reborrowed_place_ref.local, ctx, location); self.visit_projection(reborrowed_place_ref, ctx, location); return; } diff --git a/compiler/rustc_const_eval/src/transform/promote_consts.rs b/compiler/rustc_const_eval/src/transform/promote_consts.rs index 3595a488d0c5b..8eee13196fcb3 100644 --- a/compiler/rustc_const_eval/src/transform/promote_consts.rs +++ b/compiler/rustc_const_eval/src/transform/promote_consts.rs @@ -106,7 +106,7 @@ struct Collector<'a, 'tcx> { } impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> { - fn visit_local(&mut self, &index: &Local, context: PlaceContext, location: Location) { + fn visit_local(&mut self, index: Local, context: PlaceContext, location: Location) { debug!("visit_local: index={:?} context={:?} location={:?}", index, context, location); // We're only interested in temporaries and the return place match self.ccx.body.local_kind(index) { diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index 66d66ea951033..c9cb01701cfd2 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -196,8 +196,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { - fn visit_local(&mut self, local: &Local, context: PlaceContext, location: Location) { - if self.body.local_decls.get(*local).is_none() { + fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) { + if self.body.local_decls.get(local).is_none() { self.fail( location, format!("local {:?} has no corresponding declaration in `body.local_decls`", local), @@ -208,7 +208,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { // Uses of locals must occur while the local's storage is allocated. self.storage_liveness.seek_after_primary_effect(location); let locals_with_storage = self.storage_liveness.get(); - if !locals_with_storage.contains(*local) { + if !locals_with_storage.contains(local) { self.fail(location, format!("use of local {:?}, which has no storage here", local)); } } @@ -823,8 +823,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { self.super_terminator(terminator, location); } - fn visit_source_scope(&mut self, scope: &SourceScope) { - if self.body.source_scopes.get(*scope).is_none() { + fn visit_source_scope(&mut self, scope: SourceScope) { + if self.body.source_scopes.get(scope).is_none() { self.tcx.sess.diagnostic().delay_span_bug( self.body.span, &format!( diff --git a/compiler/rustc_const_eval/src/util/collect_writes.rs b/compiler/rustc_const_eval/src/util/collect_writes.rs index 9c56fd722bda6..8d92bb3593857 100644 --- a/compiler/rustc_const_eval/src/util/collect_writes.rs +++ b/compiler/rustc_const_eval/src/util/collect_writes.rs @@ -24,8 +24,8 @@ struct FindLocalAssignmentVisitor { } impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor { - fn visit_local(&mut self, local: &Local, place_context: PlaceContext, location: Location) { - if self.needle != *local { + fn visit_local(&mut self, local: Local, place_context: PlaceContext, location: Location) { + if self.needle != local { return; } diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 5ce92d127f3db..9285246eb797c 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -30,9 +30,11 @@ //! For example, the `super_basic_block_data` method begins like this: //! //! ```ignore (pseudo-rust) -//! fn super_basic_block_data(&mut self, -//! block: BasicBlock, -//! data: & $($mutability)? BasicBlockData<'tcx>) { +//! fn super_basic_block_data( +//! &mut self, +//! block: BasicBlock, +//! data: & $($mutability)? BasicBlockData<'tcx> +//! ) { //! let BasicBlockData { //! statements, //! terminator, @@ -78,106 +80,135 @@ macro_rules! make_mir_visitor { self.super_body(body); } - fn visit_basic_block_data(&mut self, - block: BasicBlock, - data: & $($mutability)? BasicBlockData<'tcx>) { + fn visit_basic_block_data( + &mut self, + block: BasicBlock, + data: & $($mutability)? BasicBlockData<'tcx>, + ) { self.super_basic_block_data(block, data); } - fn visit_source_scope_data(&mut self, - scope_data: & $($mutability)? SourceScopeData<'tcx>) { + fn visit_source_scope_data( + &mut self, + scope_data: & $($mutability)? SourceScopeData<'tcx>, + ) { self.super_source_scope_data(scope_data); } - fn visit_statement(&mut self, - statement: & $($mutability)? Statement<'tcx>, - location: Location) { + fn visit_statement( + &mut self, + statement: & $($mutability)? Statement<'tcx>, + location: Location, + ) { self.super_statement(statement, location); } - fn visit_assign(&mut self, - place: & $($mutability)? Place<'tcx>, - rvalue: & $($mutability)? Rvalue<'tcx>, - location: Location) { + fn visit_assign( + &mut self, + place: & $($mutability)? Place<'tcx>, + rvalue: & $($mutability)? Rvalue<'tcx>, + location: Location, + ) { self.super_assign(place, rvalue, location); } - fn visit_terminator(&mut self, - terminator: & $($mutability)? Terminator<'tcx>, - location: Location) { + fn visit_terminator( + &mut self, + terminator: & $($mutability)? Terminator<'tcx>, + location: Location, + ) { self.super_terminator(terminator, location); } - fn visit_assert_message(&mut self, - msg: & $($mutability)? AssertMessage<'tcx>, - location: Location) { + fn visit_assert_message( + &mut self, + msg: & $($mutability)? AssertMessage<'tcx>, + location: Location, + ) { self.super_assert_message(msg, location); } - fn visit_rvalue(&mut self, - rvalue: & $($mutability)? Rvalue<'tcx>, - location: Location) { + fn visit_rvalue( + &mut self, + rvalue: & $($mutability)? Rvalue<'tcx>, + location: Location, + ) { self.super_rvalue(rvalue, location); } - fn visit_operand(&mut self, - operand: & $($mutability)? Operand<'tcx>, - location: Location) { + fn visit_operand( + &mut self, + operand: & $($mutability)? Operand<'tcx>, + location: Location, + ) { self.super_operand(operand, location); } - fn visit_ascribe_user_ty(&mut self, - place: & $($mutability)? Place<'tcx>, - variance: & $($mutability)? ty::Variance, - user_ty: & $($mutability)? UserTypeProjection, - location: Location) { + fn visit_ascribe_user_ty( + &mut self, + place: & $($mutability)? Place<'tcx>, + variance: & $($mutability)? ty::Variance, + user_ty: & $($mutability)? UserTypeProjection, + location: Location, + ) { self.super_ascribe_user_ty(place, variance, user_ty, location); } - fn visit_coverage(&mut self, - coverage: & $($mutability)? Coverage, - location: Location) { + fn visit_coverage( + &mut self, + coverage: & $($mutability)? Coverage, + location: Location, + ) { self.super_coverage(coverage, location); } - fn visit_retag(&mut self, - kind: & $($mutability)? RetagKind, - place: & $($mutability)? Place<'tcx>, - location: Location) { + fn visit_retag( + &mut self, + kind: & $($mutability)? RetagKind, + place: & $($mutability)? Place<'tcx>, + location: Location, + ) { self.super_retag(kind, place, location); } - fn visit_place(&mut self, - place: & $($mutability)? Place<'tcx>, - context: PlaceContext, - location: Location) { + fn visit_place( + &mut self, + place: & $($mutability)? Place<'tcx>, + context: PlaceContext, + location: Location, + ) { self.super_place(place, context, location); } visit_place_fns!($($mutability)?); - fn visit_constant(&mut self, - constant: & $($mutability)? Constant<'tcx>, - location: Location) { + fn visit_constant( + &mut self, + constant: & $($mutability)? Constant<'tcx>, + location: Location, + ) { self.super_constant(constant, location); } - // The macro results in a false positive of sorts, where &mut Span - // is fine, but &Span is not; just allow the lint. - #[allow(rustc::pass_by_value)] - fn visit_span(&mut self, - span: & $($mutability)? Span) { + fn visit_span( + &mut self, + span: $(& $mutability)? Span, + ) { self.super_span(span); } - fn visit_source_info(&mut self, - source_info: & $($mutability)? SourceInfo) { + fn visit_source_info( + &mut self, + source_info: & $($mutability)? SourceInfo, + ) { self.super_source_info(source_info); } - fn visit_ty(&mut self, - ty: $(& $mutability)? Ty<'tcx>, - _: TyContext) { + fn visit_ty( + &mut self, + ty: $(& $mutability)? Ty<'tcx>, + _: TyContext, + ) { self.super_ty(ty); } @@ -196,45 +227,56 @@ macro_rules! make_mir_visitor { self.super_user_type_annotation(index, ty); } - fn visit_region(&mut self, - region: $(& $mutability)? ty::Region<'tcx>, - _: Location) { + fn visit_region( + &mut self, + region: $(& $mutability)? ty::Region<'tcx>, + _: Location, + ) { self.super_region(region); } - fn visit_const(&mut self, - constant: $(& $mutability)? ty::Const<'tcx>, - _: Location) { + fn visit_const( + &mut self, + constant: $(& $mutability)? ty::Const<'tcx>, + _: Location, + ) { self.super_const(constant); } - fn visit_substs(&mut self, - substs: & $($mutability)? SubstsRef<'tcx>, - _: Location) { + fn visit_substs( + &mut self, + substs: & $($mutability)? SubstsRef<'tcx>, + _: Location, + ) { self.super_substs(substs); } - fn visit_local_decl(&mut self, - local: Local, - local_decl: & $($mutability)? LocalDecl<'tcx>) { + fn visit_local_decl( + &mut self, + local: Local, + local_decl: & $($mutability)? LocalDecl<'tcx>, + ) { self.super_local_decl(local, local_decl); } - fn visit_var_debug_info(&mut self, - var_debug_info: & $($mutability)* VarDebugInfo<'tcx>) { + fn visit_var_debug_info( + &mut self, + var_debug_info: & $($mutability)* VarDebugInfo<'tcx>, + ) { self.super_var_debug_info(var_debug_info); } - #[allow(rustc::pass_by_value)] - fn visit_local(&mut self, - _local: & $($mutability)? Local, - _context: PlaceContext, - _location: Location) { - } + fn visit_local( + &mut self, + _local: $(& $mutability)? Local, + _context: PlaceContext, + _location: Location, + ) {} - #[allow(rustc::pass_by_value)] - fn visit_source_scope(&mut self, - scope: & $($mutability)? SourceScope) { + fn visit_source_scope( + &mut self, + scope: $(& $mutability)? SourceScope, + ) { self.super_source_scope(scope); } @@ -296,7 +338,7 @@ macro_rules! make_mir_visitor { self.visit_var_debug_info(var_debug_info); } - self.visit_span(&$($mutability)? body.span); + self.visit_span($(& $mutability)? body.span); for const_ in &$($mutability)? body.required_consts { let location = START_BLOCK.start_location(); @@ -338,14 +380,14 @@ macro_rules! make_mir_visitor { local_data: _, } = scope_data; - self.visit_span(span); + self.visit_span($(& $mutability)? *span); if let Some(parent_scope) = parent_scope { - self.visit_source_scope(parent_scope); + self.visit_source_scope($(& $mutability)? *parent_scope); } if let Some((callee, callsite_span)) = inlined { let location = START_BLOCK.start_location(); - self.visit_span(callsite_span); + self.visit_span($(& $mutability)? *callsite_span); let ty::Instance { def: callee_def, substs: callee_substs } = callee; match callee_def { @@ -368,7 +410,7 @@ macro_rules! make_mir_visitor { self.visit_substs(callee_substs, location); } if let Some(inlined_parent_scope) = inlined_parent_scope { - self.visit_source_scope(inlined_parent_scope); + self.visit_source_scope($(& $mutability)? *inlined_parent_scope); } } @@ -410,14 +452,14 @@ macro_rules! make_mir_visitor { } StatementKind::StorageLive(local) => { self.visit_local( - local, + $(& $mutability)? *local, PlaceContext::NonUse(NonUseContext::StorageLive), location ); } StatementKind::StorageDead(local) => { self.visit_local( - local, + $(& $mutability)? *local, PlaceContext::NonUse(NonUseContext::StorageDead), location ); @@ -483,7 +525,7 @@ macro_rules! make_mir_visitor { // cannot be changed by any visitor, though. let $($mutability)? local = RETURN_PLACE; self.visit_local( - & $($mutability)? local, + $(& $mutability)? local, PlaceContext::NonMutatingUse(NonMutatingUseContext::Move), location, ); @@ -840,8 +882,10 @@ macro_rules! make_mir_visitor { self.visit_source_info(source_info); } - fn super_var_debug_info(&mut self, - var_debug_info: & $($mutability)? VarDebugInfo<'tcx>) { + fn super_var_debug_info( + &mut self, + var_debug_info: & $($mutability)? VarDebugInfo<'tcx> + ) { let VarDebugInfo { name: _, source_info, @@ -861,21 +905,23 @@ macro_rules! make_mir_visitor { } } - #[allow(rustc::pass_by_value)] - fn super_source_scope(&mut self, - _scope: & $($mutability)? SourceScope) { - } + fn super_source_scope( + &mut self, + _scope: $(& $mutability)? SourceScope + ) {} - fn super_constant(&mut self, - constant: & $($mutability)? Constant<'tcx>, - location: Location) { + fn super_constant( + &mut self, + constant: & $($mutability)? Constant<'tcx>, + location: Location + ) { let Constant { span, user_ty, literal, } = constant; - self.visit_span(span); + self.visit_span($(& $mutability)? *span); drop(user_ty); // no visit method for this match literal { ConstantKind::Ty(ct) => self.visit_const($(& $mutability)? *ct, location), @@ -883,10 +929,7 @@ macro_rules! make_mir_visitor { } } - // The macro results in a false positive of sorts, where &mut Span - // is fine, but &Span is not; just allow the lint. - #[allow(rustc::pass_by_value)] - fn super_span(&mut self, _span: & $($mutability)? Span) { + fn super_span(&mut self, _span: $(& $mutability)? Span) { } fn super_source_info(&mut self, source_info: & $($mutability)? SourceInfo) { @@ -895,8 +938,8 @@ macro_rules! make_mir_visitor { scope, } = source_info; - self.visit_span(span); - self.visit_source_scope(scope); + self.visit_span($(& $mutability)? *span); + self.visit_source_scope($(& $mutability)? *scope); } fn super_user_type_projection( @@ -910,7 +953,7 @@ macro_rules! make_mir_visitor { _index: UserTypeAnnotationIndex, ty: & $($mutability)? CanonicalUserTypeAnnotation<'tcx>, ) { - self.visit_span(& $($mutability)? ty.span); + self.visit_span($(& $mutability)? ty.span); self.visit_ty($(& $mutability)? ty.inferred_ty, TyContext::UserTy(ty.span)); } @@ -1058,7 +1101,7 @@ macro_rules! visit_place_fns { } } - self.visit_local(&place.local, context, location); + self.visit_local(place.local, context, location); self.visit_projection(place.as_ref(), context, location); } @@ -1091,7 +1134,7 @@ macro_rules! visit_place_fns { } ProjectionElem::Index(local) => { self.visit_local( - &local, + local, PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy), location, ); diff --git a/compiler/rustc_mir_dataflow/src/impls/init_locals.rs b/compiler/rustc_mir_dataflow/src/impls/init_locals.rs index 584ab9718ed65..83ce4c44b7144 100644 --- a/compiler/rustc_mir_dataflow/src/impls/init_locals.rs +++ b/compiler/rustc_mir_dataflow/src/impls/init_locals.rs @@ -81,7 +81,7 @@ where // deinitialized, although clearly it is only partially deinitialized. This analysis is not // actually used anywhere at the moment, so this is not critical, but this does need to be fixed // before it starts being used again. - fn visit_local(&mut self, &local: &Local, context: PlaceContext, _: Location) { + fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) { use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, NonUseContext}; match context { // These are handled specially in `call_return_effect` and `yield_resume_effect`. diff --git a/compiler/rustc_mir_dataflow/src/impls/liveness.rs b/compiler/rustc_mir_dataflow/src/impls/liveness.rs index 35febb5d33060..e64136928cce8 100644 --- a/compiler/rustc_mir_dataflow/src/impls/liveness.rs +++ b/compiler/rustc_mir_dataflow/src/impls/liveness.rs @@ -111,7 +111,7 @@ where } } - fn visit_local(&mut self, &local: &Local, context: PlaceContext, _: Location) { + fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) { // Because we do not call `super_place` above, `visit_local` is only called for locals that // do not appear as part of a `Place` in the MIR. This handles cases like the implicit use // of the return place in a `Return` terminator or the index in an `Index` projection. diff --git a/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs index 33d2941814729..eae9313b77138 100644 --- a/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs +++ b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs @@ -288,12 +288,12 @@ impl<'a, 'mir, 'tcx, T> Visitor<'tcx> for MoveVisitor<'a, 'mir, 'tcx, T> where T: GenKill, { - fn visit_local(&mut self, local: &Local, context: PlaceContext, loc: Location) { + fn visit_local(&mut self, local: Local, context: PlaceContext, loc: Location) { if PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) == context { let mut borrowed_locals = self.borrowed_locals.borrow_mut(); borrowed_locals.seek_before_primary_effect(loc); - if !borrowed_locals.contains(*local) { - self.trans.kill(*local); + if !borrowed_locals.contains(local) { + self.trans.kill(local); } } } diff --git a/compiler/rustc_mir_transform/src/const_debuginfo.rs b/compiler/rustc_mir_transform/src/const_debuginfo.rs index 8944ebed9a704..48aea61b19186 100644 --- a/compiler/rustc_mir_transform/src/const_debuginfo.rs +++ b/compiler/rustc_mir_transform/src/const_debuginfo.rs @@ -88,12 +88,12 @@ fn find_optimization_oportunities<'tcx>(body: &Body<'tcx>) -> Vec<(Local, Consta } impl Visitor<'_> for LocalUseVisitor { - fn visit_local(&mut self, local: &Local, context: PlaceContext, location: Location) { + fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) { if context.is_mutating_use() { - self.local_mutating_uses[*local] = self.local_mutating_uses[*local].saturating_add(1); + self.local_mutating_uses[local] = self.local_mutating_uses[local].saturating_add(1); if context.is_place_assignment() { - self.local_assignment_locations[*local] = Some(location); + self.local_assignment_locations[local] = Some(location); } } } diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 412a5b4fc9104..36844d5f6cfae 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -882,7 +882,7 @@ impl CanConstProp { } impl Visitor<'_> for CanConstProp { - fn visit_local(&mut self, &local: &Local, context: PlaceContext, _: Location) { + fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) { use rustc_middle::mir::visit::PlaceContext::*; match context { // Projections are fine, because `&mut foo.x` will be caught by diff --git a/compiler/rustc_mir_transform/src/const_prop_lint.rs b/compiler/rustc_mir_transform/src/const_prop_lint.rs index 15ad13009e59a..dc3cb282c7328 100644 --- a/compiler/rustc_mir_transform/src/const_prop_lint.rs +++ b/compiler/rustc_mir_transform/src/const_prop_lint.rs @@ -773,7 +773,7 @@ impl CanConstProp { } impl Visitor<'_> for CanConstProp { - fn visit_local(&mut self, &local: &Local, context: PlaceContext, _: Location) { + fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) { use rustc_middle::mir::visit::PlaceContext::*; match context { // Projections are fine, because `&mut foo.x` will be caught by diff --git a/compiler/rustc_mir_transform/src/nrvo.rs b/compiler/rustc_mir_transform/src/nrvo.rs index 444b4126e88fc..d29d17399af3a 100644 --- a/compiler/rustc_mir_transform/src/nrvo.rs +++ b/compiler/rustc_mir_transform/src/nrvo.rs @@ -219,7 +219,7 @@ impl IsReturnPlaceRead { } impl<'tcx> Visitor<'tcx> for IsReturnPlaceRead { - fn visit_local(&mut self, &l: &Local, ctxt: PlaceContext, _: Location) { + fn visit_local(&mut self, l: Local, ctxt: PlaceContext, _: Location) { if l == mir::RETURN_PLACE && ctxt.is_use() && !ctxt.is_place_assignment() { self.0 = true; } diff --git a/compiler/rustc_mir_transform/src/simplify.rs b/compiler/rustc_mir_transform/src/simplify.rs index 8a78ea5c82bb1..980af98436281 100644 --- a/compiler/rustc_mir_transform/src/simplify.rs +++ b/compiler/rustc_mir_transform/src/simplify.rs @@ -509,12 +509,12 @@ impl<'tcx> Visitor<'tcx> for UsedLocals { } } - fn visit_local(&mut self, local: &Local, _ctx: PlaceContext, _location: Location) { + fn visit_local(&mut self, local: Local, _ctx: PlaceContext, _location: Location) { if self.increment { - self.use_count[*local] += 1; + self.use_count[local] += 1; } else { - assert_ne!(self.use_count[*local], 0); - self.use_count[*local] -= 1; + assert_ne!(self.use_count[local], 0); + self.use_count[local] -= 1; } } } diff --git a/compiler/rustc_mir_transform/src/simplify_try.rs b/compiler/rustc_mir_transform/src/simplify_try.rs index b3d45c7a22155..6902213ddad4f 100644 --- a/compiler/rustc_mir_transform/src/simplify_try.rs +++ b/compiler/rustc_mir_transform/src/simplify_try.rs @@ -462,14 +462,14 @@ impl LocalUseCounter { } impl Visitor<'_> for LocalUseCounter { - fn visit_local(&mut self, local: &Local, context: PlaceContext, _location: Location) { + fn visit_local(&mut self, local: Local, context: PlaceContext, _location: Location) { if context.is_storage_marker() || context == PlaceContext::NonUse(NonUseContext::VarDebugInfo) { return; } - self.local_uses[*local] += 1; + self.local_uses[local] += 1; } } diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 2af22e129a5f7..3f082896ccfd4 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -928,7 +928,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { fn visit_local( &mut self, - _place_local: &Local, + _place_local: Local, _context: mir::visit::PlaceContext, _location: Location, ) { From ec82bc199611e7f1cf3acd612a65eed81d22636b Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Tue, 28 Jun 2022 13:15:30 -0500 Subject: [PATCH 4/5] Factor out hir::Node::Binding --- compiler/rustc_ast_lowering/src/index.rs | 4 +--- .../src/diagnostics/mutability_errors.rs | 2 +- .../rustc_const_eval/src/interpret/validity.rs | 2 +- compiler/rustc_hir/src/hir.rs | 2 -- compiler/rustc_hir_pretty/src/lib.rs | 2 +- compiler/rustc_middle/src/hir/map/mod.rs | 5 +---- compiler/rustc_mir_build/src/build/mod.rs | 2 +- compiler/rustc_mir_build/src/thir/cx/mod.rs | 2 +- compiler/rustc_save_analysis/src/lib.rs | 6 +++--- compiler/rustc_typeck/src/check/demand.rs | 2 +- .../generator_interior/drop_ranges/cfg_build.rs | 1 - src/tools/clippy/clippy_lints/src/escape.rs | 16 +++++----------- .../clippy/clippy_lints/src/explicit_write.rs | 2 +- .../clippy_lints/src/loops/mut_range_bound.rs | 2 +- .../clippy_lints/src/loops/same_item_push.rs | 2 +- .../clippy/clippy_lints/src/manual_rem_euclid.rs | 3 +-- .../clippy_lints/src/methods/iter_skip_next.rs | 2 +- src/tools/clippy/clippy_utils/src/lib.rs | 2 +- 18 files changed, 22 insertions(+), 37 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/index.rs b/compiler/rustc_ast_lowering/src/index.rs index 4be22020ba153..ddd54f7c2089d 100644 --- a/compiler/rustc_ast_lowering/src/index.rs +++ b/compiler/rustc_ast_lowering/src/index.rs @@ -192,9 +192,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { } fn visit_pat(&mut self, pat: &'hir Pat<'hir>) { - let node = - if let PatKind::Binding(..) = pat.kind { Node::Binding(pat) } else { Node::Pat(pat) }; - self.insert(pat.span, pat.hir_id, node); + self.insert(pat.span, pat.hir_id, Node::Pat(pat)); self.with_parent(pat.hir_id, |this| { intravisit::walk_pat(this, pat); diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 49b24a05071b2..3c5dd32d2816e 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -362,7 +362,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let upvar_hir_id = captured_place.get_root_variable(); - if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find(upvar_hir_id) + if let Some(Node::Pat(pat)) = self.infcx.tcx.hir().find(upvar_hir_id) && let hir::PatKind::Binding( hir::BindingAnnotation::Unannotated, _, diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index 905ab6cb578fc..847694cbd10cb 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -244,7 +244,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' // for a generator). let var_hir_id = captured_place.get_root_variable(); let node = self.ecx.tcx.hir().get(var_hir_id); - if let hir::Node::Binding(pat) = node { + if let hir::Node::Pat(pat) = node { if let hir::PatKind::Binding(_, _, ident, _) = pat.kind { name = Some(ident.name); } diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index a7fc59255d79a..a2ef158ce8d32 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -3326,7 +3326,6 @@ pub enum Node<'hir> { Ty(&'hir Ty<'hir>), TypeBinding(&'hir TypeBinding<'hir>), TraitRef(&'hir TraitRef<'hir>), - Binding(&'hir Pat<'hir>), Pat(&'hir Pat<'hir>), Arm(&'hir Arm<'hir>), Block(&'hir Block<'hir>), @@ -3378,7 +3377,6 @@ impl<'hir> Node<'hir> { | Node::Block(..) | Node::Ctor(..) | Node::Pat(..) - | Node::Binding(..) | Node::Arm(..) | Node::Local(..) | Node::Crate(..) diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 7bf91df9f760b..fd843b0c403a6 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -87,7 +87,7 @@ impl<'a> State<'a> { Node::Ty(a) => self.print_type(&a), Node::TypeBinding(a) => self.print_type_binding(&a), Node::TraitRef(a) => self.print_trait_ref(&a), - Node::Binding(a) | Node::Pat(a) => self.print_pat(&a), + Node::Pat(a) => self.print_pat(&a), Node::Arm(a) => self.print_arm(&a), Node::Infer(_) => self.word("_"), Node::Block(a) => { diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index a27b8470e9573..72077e7301359 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -302,7 +302,6 @@ impl<'hir> Map<'hir> { | Node::Infer(_) | Node::TraitRef(_) | Node::Pat(_) - | Node::Binding(_) | Node::Local(_) | Node::Param(_) | Node::Arm(_) @@ -901,7 +900,7 @@ impl<'hir> Map<'hir> { #[inline] fn opt_ident(self, id: HirId) -> Option { match self.get(id) { - Node::Binding(&Pat { kind: PatKind::Binding(_, _, ident, _), .. }) => Some(ident), + Node::Pat(&Pat { kind: PatKind::Binding(_, _, ident, _), .. }) => Some(ident), // A `Ctor` doesn't have an identifier itself, but its parent // struct/variant does. Compare with `hir::Map::opt_span`. Node::Ctor(..) => match self.find(self.get_parent_node(id))? { @@ -969,7 +968,6 @@ impl<'hir> Map<'hir> { Node::Ty(ty) => ty.span, Node::TypeBinding(tb) => tb.span, Node::TraitRef(tr) => tr.path.span, - Node::Binding(pat) => pat.span, Node::Pat(pat) => pat.span, Node::Arm(arm) => arm.span, Node::Block(block) => block.span, @@ -1203,7 +1201,6 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String { Some(Node::Ty(_)) => node_str("type"), Some(Node::TypeBinding(_)) => node_str("type binding"), Some(Node::TraitRef(_)) => node_str("trait ref"), - Some(Node::Binding(_)) => node_str("local"), Some(Node::Pat(_)) => node_str("pat"), Some(Node::Param(_)) => node_str("param"), Some(Node::Arm(_)) => node_str("arm"), diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index cdacf3ad892e0..e27761381f633 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -997,7 +997,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { continue; }; let pat = match tcx.hir().get(arg.pat.hir_id) { - Node::Pat(pat) | Node::Binding(pat) => pat, + Node::Pat(pat) => pat, node => bug!("pattern became {:?}", node), }; let pattern = pat_from_hir(tcx, self.param_env, self.typeck_results, pat); diff --git a/compiler/rustc_mir_build/src/thir/cx/mod.rs b/compiler/rustc_mir_build/src/thir/cx/mod.rs index d853a5e9ee797..2645155adc67b 100644 --- a/compiler/rustc_mir_build/src/thir/cx/mod.rs +++ b/compiler/rustc_mir_build/src/thir/cx/mod.rs @@ -101,7 +101,7 @@ impl<'tcx> Cx<'tcx> { #[tracing::instrument(level = "debug", skip(self))] pub(crate) fn pattern_from_hir(&mut self, p: &hir::Pat<'_>) -> Pat<'tcx> { let p = match self.tcx.hir().get(p.hir_id) { - Node::Pat(p) | Node::Binding(p) => p, + Node::Pat(p) => p, node => bug!("pattern became {:?}", node), }; pat_from_hir(self.tcx, self.param_env, self.typeck_results(), p) diff --git a/compiler/rustc_save_analysis/src/lib.rs b/compiler/rustc_save_analysis/src/lib.rs index 99f38b3222dca..0a0c674d179e9 100644 --- a/compiler/rustc_save_analysis/src/lib.rs +++ b/compiler/rustc_save_analysis/src/lib.rs @@ -623,9 +623,9 @@ impl<'tcx> SaveContext<'tcx> { } }, - Node::Binding(&hir::Pat { - kind: hir::PatKind::Binding(_, canonical_id, ..), .. - }) => Res::Local(canonical_id), + Node::Pat(&hir::Pat { kind: hir::PatKind::Binding(_, canonical_id, ..), .. }) => { + Res::Local(canonical_id) + } _ => Res::Err, } diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs index 961bbc426613c..53ca027bb57f5 100644 --- a/compiler/rustc_typeck/src/check/demand.rs +++ b/compiler/rustc_typeck/src/check/demand.rs @@ -223,7 +223,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { None, hir::Path { res: hir::def::Res::Local(hir_id), .. }, )) => { - if let Some(hir::Node::Binding(pat)) = self.tcx.hir().find(*hir_id) { + if let Some(hir::Node::Pat(pat)) = self.tcx.hir().find(*hir_id) { let parent = self.tcx.hir().get_parent_node(pat.hir_id); primary_span = pat.span; secondary_span = pat.span; diff --git a/compiler/rustc_typeck/src/check/generator_interior/drop_ranges/cfg_build.rs b/compiler/rustc_typeck/src/check/generator_interior/drop_ranges/cfg_build.rs index dbc309b29ff11..365ff429243f1 100644 --- a/compiler/rustc_typeck/src/check/generator_interior/drop_ranges/cfg_build.rs +++ b/compiler/rustc_typeck/src/check/generator_interior/drop_ranges/cfg_build.rs @@ -251,7 +251,6 @@ impl<'a, 'tcx> DropRangeVisitor<'a, 'tcx> { | hir::Node::Ty(..) | hir::Node::TypeBinding(..) | hir::Node::TraitRef(..) - | hir::Node::Binding(..) | hir::Node::Pat(..) | hir::Node::Arm(..) | hir::Node::Local(..) diff --git a/src/tools/clippy/clippy_lints/src/escape.rs b/src/tools/clippy/clippy_lints/src/escape.rs index 7a65b849a6643..1ac7bfba06ba2 100644 --- a/src/tools/clippy/clippy_lints/src/escape.rs +++ b/src/tools/clippy/clippy_lints/src/escape.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_hir; use clippy_utils::ty::contains_ty; use rustc_hir::intravisit; -use rustc_hir::{self, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node}; +use rustc_hir::{self, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node, Pat, PatKind}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::FakeReadCause; @@ -132,7 +132,10 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { // TODO: Replace with Map::is_argument(..) when it's fixed fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool { match map.find(id) { - Some(Node::Binding(_)) => (), + Some(Node::Pat(Pat { + kind: PatKind::Binding(..), + .. + })) => (), _ => return false, } @@ -144,15 +147,6 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { if cmt.place.projections.is_empty() { if let PlaceBase::Local(lid) = cmt.place.base { self.set.remove(&lid); - let map = &self.cx.tcx.hir(); - if let Some(Node::Binding(_)) = map.find(cmt.hir_id) { - if self.set.contains(&lid) { - // let y = x where x is known - // remove x, insert y - self.set.insert(cmt.hir_id); - self.set.remove(&lid); - } - } } } } diff --git a/src/tools/clippy/clippy_lints/src/explicit_write.rs b/src/tools/clippy/clippy_lints/src/explicit_write.rs index 12d636cf41014..5bf4313b41a49 100644 --- a/src/tools/clippy/clippy_lints/src/explicit_write.rs +++ b/src/tools/clippy/clippy_lints/src/explicit_write.rs @@ -125,7 +125,7 @@ fn look_in_block<'tcx, 'hir>(cx: &LateContext<'tcx>, kind: &'tcx ExprKind<'hir>) // Find id of the local that expr_end_of_block resolves to if let ExprKind::Path(QPath::Resolved(None, expr_path)) = expr_end_of_block.kind; if let Res::Local(expr_res) = expr_path.res; - if let Some(Node::Binding(res_pat)) = cx.tcx.hir().find(expr_res); + if let Some(Node::Pat(res_pat)) = cx.tcx.hir().find(expr_res); // Find id of the local we found in the block if let PatKind::Binding(BindingAnnotation::Unannotated, local_hir_id, _ident, None) = local.pat.kind; diff --git a/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs b/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs index d20df83045589..aedf3810b23e9 100644 --- a/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs +++ b/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs @@ -43,7 +43,7 @@ fn mut_warn_with_span(cx: &LateContext<'_>, span: Option) { fn check_for_mutability(cx: &LateContext<'_>, bound: &Expr<'_>) -> Option { if_chain! { if let Some(hir_id) = path_to_local(bound); - if let Node::Binding(pat) = cx.tcx.hir().get(hir_id); + if let Node::Pat(pat) = cx.tcx.hir().get(hir_id); if let PatKind::Binding(BindingAnnotation::Mutable, ..) = pat.kind; then { return Some(hir_id); diff --git a/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs b/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs index e048d744fc3ba..1439f1f4c75d5 100644 --- a/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs +++ b/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs @@ -63,7 +63,7 @@ pub(super) fn check<'tcx>( Res::Local(hir_id) => { let node = cx.tcx.hir().get(hir_id); if_chain! { - if let Node::Binding(pat) = node; + if let Node::Pat(pat) = node; if let PatKind::Binding(bind_ann, ..) = pat.kind; if !matches!(bind_ann, BindingAnnotation::RefMut | BindingAnnotation::Mutable); let parent_node = cx.tcx.hir().get_parent_node(hir_id); diff --git a/src/tools/clippy/clippy_lints/src/manual_rem_euclid.rs b/src/tools/clippy/clippy_lints/src/manual_rem_euclid.rs index b5698965fc3dd..2ce9d0e77c1fd 100644 --- a/src/tools/clippy/clippy_lints/src/manual_rem_euclid.rs +++ b/src/tools/clippy/clippy_lints/src/manual_rem_euclid.rs @@ -71,8 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid { && let Some(const3) = check_for_unsigned_int_constant(cx, right) // Also ensures the const is nonzero since zero can't be a divisor && const1 == const2 && const2 == const3 - && let Some(hir_id) = path_to_local(expr3) - && let Some(Node::Binding(_)) = cx.tcx.hir().find(hir_id) { + && let Some(hir_id) = path_to_local(expr3) { // Apply only to params or locals with annotated types match cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) { Some(Node::Param(..)) => (), diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_skip_next.rs b/src/tools/clippy/clippy_lints/src/methods/iter_skip_next.rs index f5410c7fd7fc8..43e9451f7d37e 100644 --- a/src/tools/clippy/clippy_lints/src/methods/iter_skip_next.rs +++ b/src/tools/clippy/clippy_lints/src/methods/iter_skip_next.rs @@ -22,7 +22,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr |diag| { if_chain! { if let Some(id) = path_to_local(recv); - if let Node::Binding(pat) = cx.tcx.hir().get(id); + if let Node::Pat(pat) = cx.tcx.hir().get(id); if let PatKind::Binding(ann, _, _, _) = pat.kind; if ann != BindingAnnotation::Mutable; then { diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 9fa28e137f974..5cfd02232dec6 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -183,7 +183,7 @@ pub fn expr_or_init<'a, 'b, 'tcx: 'b>(cx: &LateContext<'tcx>, mut expr: &'a Expr pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<'tcx>> { let hir = cx.tcx.hir(); if_chain! { - if let Some(Node::Binding(pat)) = hir.find(hir_id); + if let Some(Node::Pat(pat)) = hir.find(hir_id); if matches!(pat.kind, PatKind::Binding(BindingAnnotation::Unannotated, ..)); let parent = hir.get_parent_node(hir_id); if let Some(Node::Local(local)) = hir.find(parent); From 65944ce5228c8c1d2038dddbfac23d4d872b5787 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 1 Jul 2022 17:57:32 -0400 Subject: [PATCH 5/5] interpret: make a comment less scary --- compiler/rustc_const_eval/src/interpret/cast.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs index 076415b2d1b2f..2e6c7f47ac1db 100644 --- a/compiler/rustc_const_eval/src/interpret/cast.rs +++ b/compiler/rustc_const_eval/src/interpret/cast.rs @@ -202,7 +202,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let ptr = self.scalar_to_ptr(scalar)?; match ptr.into_pointer_or_addr() { Ok(ptr) => M::expose_ptr(self, ptr)?, - Err(_) => {} // do nothing, exposing an invalid pointer has no meaning + Err(_) => {} // Do nothing, exposing an invalid pointer (`None` provenance) is a NOP. }; Ok(self.cast_from_int_like(scalar, src.layout, cast_ty)?.into()) }