Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c82dd3a

Browse files
dingxiangfei2009Niko Matsakis
authored andcommitted
reduce false positives of tail-expr-drop-order from consumed values
take 2 open up coroutines tweak the wordings the lint works up until 2021 We were missing one case, for ADTs, which was causing `Result` to yield incorrect results. only include field spans with significant types deduplicate and eliminate field spans switch to emit spans to impl Drops Co-authored-by: Niko Matsakis <nikomat@amazon.com>
1 parent 195bb57 commit c82dd3a

File tree

60 files changed

+1582
-534
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1582
-534
lines changed

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
563563
| mir::StatementKind::Coverage(..)
564564
| mir::StatementKind::Intrinsic(..)
565565
| mir::StatementKind::ConstEvalCounter
566+
| mir::StatementKind::BackwardIncompatibleDropHint { .. }
566567
| mir::StatementKind::Nop => {}
567568
}
568569
}

compiler/rustc_borrowck/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,8 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
646646
| StatementKind::Coverage(..)
647647
// These do not actually affect borrowck
648648
| StatementKind::ConstEvalCounter
649+
// This do not affect borrowck
650+
| StatementKind::BackwardIncompatibleDropHint { .. }
649651
| StatementKind::StorageLive(..) => {}
650652
StatementKind::StorageDead(local) => {
651653
self.access_place(

compiler/rustc_borrowck/src/polonius/loan_invalidations.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'a, 'tcx> {
8888
| StatementKind::Nop
8989
| StatementKind::Retag { .. }
9090
| StatementKind::Deinit(..)
91+
| StatementKind::BackwardIncompatibleDropHint { .. }
9192
| StatementKind::SetDiscriminant { .. } => {
9293
bug!("Statement not allowed in this MIR phase")
9394
}

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12651265
| StatementKind::Coverage(..)
12661266
| StatementKind::ConstEvalCounter
12671267
| StatementKind::PlaceMention(..)
1268+
| StatementKind::BackwardIncompatibleDropHint { .. }
12681269
| StatementKind::Nop => {}
12691270
StatementKind::Deinit(..) | StatementKind::SetDiscriminant { .. } => {
12701271
bug!("Statement not allowed in this MIR phase")

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@ fn codegen_stmt<'tcx>(
920920
| StatementKind::FakeRead(..)
921921
| StatementKind::Retag { .. }
922922
| StatementKind::PlaceMention(..)
923+
| StatementKind::BackwardIncompatibleDropHint { .. }
923924
| StatementKind::AscribeUserType(..) => {}
924925

925926
StatementKind::Coverage { .. } => unreachable!(),

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
578578
| StatementKind::PlaceMention(..)
579579
| StatementKind::Coverage(_)
580580
| StatementKind::ConstEvalCounter
581+
| StatementKind::BackwardIncompatibleDropHint { .. }
581582
| StatementKind::Nop => {}
582583
}
583584
}

compiler/rustc_codegen_ssa/src/mir/statement.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
9292
| mir::StatementKind::AscribeUserType(..)
9393
| mir::StatementKind::ConstEvalCounter
9494
| mir::StatementKind::PlaceMention(..)
95+
| mir::StatementKind::BackwardIncompatibleDropHint { .. }
9596
| mir::StatementKind::Nop => {}
9697
}
9798
}

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
610610
| StatementKind::Coverage(..)
611611
| StatementKind::Intrinsic(..)
612612
| StatementKind::ConstEvalCounter
613+
| StatementKind::BackwardIncompatibleDropHint { .. }
613614
| StatementKind::Nop => {}
614615
}
615616
}

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
143143
// Defined to do nothing. These are added by optimization passes, to avoid changing the
144144
// size of MIR constantly.
145145
Nop => {}
146+
147+
// Only used for temporary lifetime lints
148+
BackwardIncompatibleDropHint { .. } => {}
146149
}
147150

148151
interp_ok(())

compiler/rustc_hir_analysis/src/check/region.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_index::Idx;
1717
use rustc_middle::bug;
1818
use rustc_middle::middle::region::*;
1919
use rustc_middle::ty::TyCtxt;
20+
use rustc_session::lint;
2021
use rustc_span::source_map;
2122
use tracing::debug;
2223

@@ -167,8 +168,22 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
167168
}
168169
}
169170
if let Some(tail_expr) = blk.expr {
170-
if blk.span.edition().at_least_rust_2024() {
171-
visitor.terminating_scopes.insert(tail_expr.hir_id.local_id);
171+
let local_id = tail_expr.hir_id.local_id;
172+
let edition = blk.span.edition();
173+
if edition.at_least_rust_2024() {
174+
visitor.terminating_scopes.insert(local_id);
175+
} else if !matches!(
176+
visitor.tcx.lint_level_at_node(lint::builtin::TAIL_EXPR_DROP_ORDER, blk.hir_id),
177+
(lint::Level::Allow, _)
178+
) {
179+
// If this temporary scope will be changing once the codebase adopts Rust 2024,
180+
// and we are linting about possible semantic changes that would result,
181+
// then record this node-id in the field `backwards_incompatible_scope`
182+
// for future reference.
183+
visitor
184+
.scope_tree
185+
.backwards_incompatible_scope
186+
.insert(local_id, Scope { id: local_id, data: ScopeData::Node });
172187
}
173188
visitor.visit_expr(tail_expr);
174189
}

0 commit comments

Comments
 (0)