Skip to content

Commit 1b9e575

Browse files
dingxiangfei2009compiler-errors
authored andcommitted
reduce false positives of tail-expr-drop-order from consumed values
1 parent 24290ef commit 1b9e575

File tree

34 files changed

+728
-373
lines changed

34 files changed

+728
-373
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4112,6 +4112,7 @@ dependencies = [
41124112
"rustc_hir",
41134113
"rustc_index",
41144114
"rustc_infer",
4115+
"rustc_lint",
41154116
"rustc_macros",
41164117
"rustc_middle",
41174118
"rustc_mir_build",

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ impl<'a, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'a, 'tcx, R>
691691
TerminatorKind::SwitchInt { discr, targets: _ } => {
692692
self.consume_operand(loc, (discr, span), state);
693693
}
694-
TerminatorKind::Drop { place, target: _, unwind: _, replace } => {
694+
TerminatorKind::Drop { place, target: _, scope: _, unwind: _, replace } => {
695695
debug!(
696696
"visit_terminator_drop \
697697
loc: {:?} term: {:?} place: {:?} span: {:?}",

compiler/rustc_borrowck/src/polonius/loan_invalidations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'a, 'tcx> {
103103
TerminatorKind::SwitchInt { discr, targets: _ } => {
104104
self.consume_operand(location, discr);
105105
}
106-
TerminatorKind::Drop { place: drop_place, target: _, unwind: _, replace } => {
106+
TerminatorKind::Drop { place: drop_place, target: _, scope: _, unwind: _, replace } => {
107107
let write_kind =
108108
if *replace { WriteKind::Replace } else { WriteKind::StorageDeadOrDrop };
109109
self.access_place(

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
549549
| TerminatorKind::CoroutineDrop => {
550550
bug!("shouldn't exist at codegen {:?}", bb_data.terminator());
551551
}
552-
TerminatorKind::Drop { place, target, unwind: _, replace: _ } => {
552+
TerminatorKind::Drop { place, target, unwind: _, scope: _, replace: _ } => {
553553
let drop_place = codegen_place(fx, *place);
554554
crate::abi::codegen_drop(fx, source_info, drop_place, *target);
555555
}

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
13221322
MergingSucc::False
13231323
}
13241324

1325-
mir::TerminatorKind::Drop { place, target, unwind, replace: _ } => self
1325+
mir::TerminatorKind::Drop { place, target, unwind, scope: _, replace: _ } => self
13261326
.codegen_drop_terminator(
13271327
helper,
13281328
bx,

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
528528
}
529529
}
530530

531-
Drop { place, target, unwind, replace: _ } => {
531+
Drop { place, target, unwind, scope: _, replace: _ } => {
532532
let place = self.eval_place(place)?;
533533
let instance = Instance::resolve_drop_in_place(*self.tcx, place.layout.ty);
534534
if let ty::InstanceKind::DropGlue(_, None) = instance.def {

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,50 @@ pub trait TypeInformationCtxt<'tcx> {
150150
fn tcx(&self) -> TyCtxt<'tcx>;
151151
}
152152

153+
impl<'tcx> TypeInformationCtxt<'tcx> for (TyCtxt<'tcx>, LocalDefId) {
154+
type TypeckResults<'a> = &'tcx ty::TypeckResults<'tcx>
155+
where
156+
Self: 'a;
157+
158+
type Error = !;
159+
160+
fn typeck_results(&self) -> Self::TypeckResults<'_> {
161+
self.0.typeck(self.1)
162+
}
163+
164+
fn resolve_vars_if_possible<T: TypeFoldable<TyCtxt<'tcx>>>(&self, t: T) -> T {
165+
t
166+
}
167+
168+
fn try_structurally_resolve_type(&self, _span: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
169+
ty
170+
}
171+
172+
fn report_error(&self, span: Span, msg: impl ToString) -> Self::Error {
173+
span_bug!(span, "{}", msg.to_string())
174+
}
175+
176+
fn error_reported_in_ty(&self, _ty: Ty<'tcx>) -> Result<(), Self::Error> {
177+
Ok(())
178+
}
179+
180+
fn tainted_by_errors(&self) -> Result<(), Self::Error> {
181+
Ok(())
182+
}
183+
184+
fn type_is_copy_modulo_regions(&self, ty: Ty<'tcx>) -> bool {
185+
ty.is_copy_modulo_regions(self.0, self.0.param_env(self.1))
186+
}
187+
188+
fn body_owner_def_id(&self) -> LocalDefId {
189+
self.1
190+
}
191+
192+
fn tcx(&self) -> TyCtxt<'tcx> {
193+
self.0
194+
}
195+
}
196+
153197
impl<'tcx> TypeInformationCtxt<'tcx> for &FnCtxt<'_, 'tcx> {
154198
type TypeckResults<'a>
155199
= Ref<'a, ty::TypeckResults<'tcx>>

compiler/rustc_lint/messages.ftl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -778,9 +778,6 @@ lint_suspicious_double_ref_clone =
778778
lint_suspicious_double_ref_deref =
779779
using `.deref()` on a double reference, which returns `{$ty}` instead of dereferencing the inner type
780780
781-
lint_tail_expr_drop_order = these values and local bindings have significant drop implementation that will have a different drop order from that of Edition 2021
782-
.label = these values have significant drop implementation and will observe changes in drop order under Edition 2024
783-
784781
lint_trailing_semi_macro = trailing semicolon in macro used in expression position
785782
.note1 = macro invocations at the end of a block are treated as expressions
786783
.note2 = to ignore the value produced by the macro, add a semicolon after the invocation of `{$name}`

compiler/rustc_lint/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ mod redundant_semicolon;
8282
mod reference_casting;
8383
mod shadowed_into_iter;
8484
mod static_mut_refs;
85-
mod tail_expr_drop_order;
8685
mod traits;
8786
mod types;
8887
mod unit_bindings;
@@ -123,7 +122,6 @@ use rustc_middle::ty::TyCtxt;
123122
use shadowed_into_iter::ShadowedIntoIter;
124123
pub use shadowed_into_iter::{ARRAY_INTO_ITER, BOXED_SLICE_INTO_ITER};
125124
use static_mut_refs::*;
126-
use tail_expr_drop_order::TailExprDropOrder;
127125
use traits::*;
128126
use types::*;
129127
use unit_bindings::*;
@@ -248,7 +246,6 @@ late_lint_methods!(
248246
AsyncFnInTrait: AsyncFnInTrait,
249247
NonLocalDefinitions: NonLocalDefinitions::default(),
250248
ImplTraitOvercaptures: ImplTraitOvercaptures,
251-
TailExprDropOrder: TailExprDropOrder,
252249
IfLetRescope: IfLetRescope::default(),
253250
StaticMutRefs: StaticMutRefs,
254251
UnqualifiedLocalImports: UnqualifiedLocalImports,

0 commit comments

Comments
 (0)