Skip to content

Commit 82b311b

Browse files
committed
Auto merge of rust-lang#112016 - GuillaumeGomez:rollup-fhqn4i6, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - rust-lang#111936 (Include test suite metadata in the build metrics) - rust-lang#111952 (Remove DesugaringKind::Replace.) - rust-lang#111966 (Add #[inline] to array TryFrom impls) - rust-lang#111983 (Perform MIR type ops locally in new solver) - rust-lang#111997 (Fix re-export of doc hidden macro not showing up) - rust-lang#112014 (rustdoc: get unnormalized link destination for suggestions) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 786178b + 3089653 commit 82b311b

Some content is hidden

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

54 files changed

+1610
-749
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

-28
Original file line numberDiff line numberDiff line change
@@ -1635,34 +1635,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16351635
})
16361636
}
16371637

1638-
/// Reports StorageDeadOrDrop of `place` conflicts with `borrow`.
1639-
///
1640-
/// Depending on the origin of the StorageDeadOrDrop, this may be
1641-
/// reported as either a drop or an illegal mutation of a borrowed value.
1642-
/// The latter is preferred when the this is a drop triggered by a
1643-
/// reassignment, as it's more user friendly to report a problem with the
1644-
/// explicit assignment than the implicit drop.
1645-
#[instrument(level = "debug", skip(self))]
1646-
pub(crate) fn report_storage_dead_or_drop_of_borrowed(
1647-
&mut self,
1648-
location: Location,
1649-
place_span: (Place<'tcx>, Span),
1650-
borrow: &BorrowData<'tcx>,
1651-
) {
1652-
// It's sufficient to check the last desugaring as Replace is the last
1653-
// one to be applied.
1654-
if let Some(DesugaringKind::Replace) = place_span.1.desugaring_kind() {
1655-
self.report_illegal_mutation_of_borrowed(location, place_span, borrow)
1656-
} else {
1657-
self.report_borrowed_value_does_not_live_long_enough(
1658-
location,
1659-
borrow,
1660-
place_span,
1661-
Some(WriteKind::StorageDeadOrDrop),
1662-
)
1663-
}
1664-
}
1665-
16661638
/// This means that some data referenced by `borrow` needs to live
16671639
/// past the point where the StorageDeadOrDrop of `place` occurs.
16681640
/// This is usually interpreted as meaning that `place` has too

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
641641
let Some(hir::Node::Item(item)) = node else { return; };
642642
let hir::ItemKind::Fn(.., body_id) = item.kind else { return; };
643643
let body = self.infcx.tcx.hir().body(body_id);
644-
let mut assign_span = span;
645-
// Drop desugaring is done at MIR build so it's not in the HIR
646-
if let Some(DesugaringKind::Replace) = span.desugaring_kind() {
647-
assign_span.remove_mark();
648-
}
649644

650-
let mut v = V { assign_span, err, ty, suggested: false };
645+
let mut v = V { assign_span: span, err, ty, suggested: false };
651646
v.visit_body(body);
652647
if !v.suggested {
653648
err.help(format!(

compiler/rustc_borrowck/src/invalidation.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,13 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
112112
TerminatorKind::SwitchInt { discr, targets: _ } => {
113113
self.consume_operand(location, discr);
114114
}
115-
TerminatorKind::Drop { place: drop_place, target: _, unwind: _ } => {
115+
TerminatorKind::Drop { place: drop_place, target: _, unwind: _, replace } => {
116+
let write_kind =
117+
if *replace { WriteKind::Replace } else { WriteKind::StorageDeadOrDrop };
116118
self.access_place(
117119
location,
118120
*drop_place,
119-
(AccessDepth::Drop, Write(WriteKind::StorageDeadOrDrop)),
121+
(AccessDepth::Drop, Write(write_kind)),
120122
LocalMutationIsAllowed::Yes,
121123
);
122124
}

compiler/rustc_borrowck/src/lib.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -685,17 +685,19 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
685685
TerminatorKind::SwitchInt { discr, targets: _ } => {
686686
self.consume_operand(loc, (discr, span), flow_state);
687687
}
688-
TerminatorKind::Drop { place, target: _, unwind: _ } => {
688+
TerminatorKind::Drop { place, target: _, unwind: _, replace } => {
689689
debug!(
690690
"visit_terminator_drop \
691691
loc: {:?} term: {:?} place: {:?} span: {:?}",
692692
loc, term, place, span
693693
);
694694

695+
let write_kind =
696+
if *replace { WriteKind::Replace } else { WriteKind::StorageDeadOrDrop };
695697
self.access_place(
696698
loc,
697699
(*place, span),
698-
(AccessDepth::Drop, Write(WriteKind::StorageDeadOrDrop)),
700+
(AccessDepth::Drop, Write(write_kind)),
699701
LocalMutationIsAllowed::Yes,
700702
flow_state,
701703
);
@@ -885,6 +887,7 @@ enum ReadKind {
885887
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
886888
enum WriteKind {
887889
StorageDeadOrDrop,
890+
Replace,
888891
MutableBorrow(BorrowKind),
889892
Mutate,
890893
Move,
@@ -1132,13 +1135,21 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11321135
this.buffer_error(err);
11331136
}
11341137
WriteKind::StorageDeadOrDrop => this
1135-
.report_storage_dead_or_drop_of_borrowed(location, place_span, borrow),
1138+
.report_borrowed_value_does_not_live_long_enough(
1139+
location,
1140+
borrow,
1141+
place_span,
1142+
Some(WriteKind::StorageDeadOrDrop),
1143+
),
11361144
WriteKind::Mutate => {
11371145
this.report_illegal_mutation_of_borrowed(location, place_span, borrow)
11381146
}
11391147
WriteKind::Move => {
11401148
this.report_move_out_while_borrowed(location, place_span, borrow)
11411149
}
1150+
WriteKind::Replace => {
1151+
this.report_illegal_mutation_of_borrowed(location, place_span, borrow)
1152+
}
11421153
}
11431154
Control::Break
11441155
}
@@ -1982,12 +1993,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19821993

19831994
Reservation(
19841995
WriteKind::Move
1996+
| WriteKind::Replace
19851997
| WriteKind::StorageDeadOrDrop
19861998
| WriteKind::MutableBorrow(BorrowKind::Shared)
19871999
| WriteKind::MutableBorrow(BorrowKind::Shallow),
19882000
)
19892001
| Write(
19902002
WriteKind::Move
2003+
| WriteKind::Replace
19912004
| WriteKind::StorageDeadOrDrop
19922005
| WriteKind::MutableBorrow(BorrowKind::Shared)
19932006
| WriteKind::MutableBorrow(BorrowKind::Shallow),

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use rustc_index::bit_set::HybridBitSet;
33
use rustc_index::interval::IntervalSet;
44
use rustc_infer::infer::canonical::QueryRegionConstraints;
55
use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, Local, Location};
6+
use rustc_middle::traits::query::DropckOutlivesResult;
67
use rustc_middle::ty::{Ty, TyCtxt, TypeVisitable, TypeVisitableExt};
78
use rustc_span::DUMMY_SP;
8-
use rustc_trait_selection::traits::query::dropck_outlives::DropckOutlivesResult;
99
use rustc_trait_selection::traits::query::type_op::outlives::DropckOutlives;
1010
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
1111
use std::rc::Rc;

compiler/rustc_codegen_cranelift/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
473473
| TerminatorKind::GeneratorDrop => {
474474
bug!("shouldn't exist at codegen {:?}", bb_data.terminator());
475475
}
476-
TerminatorKind::Drop { place, target, unwind: _ } => {
476+
TerminatorKind::Drop { place, target, unwind: _, replace: _ } => {
477477
let drop_place = codegen_place(fx, *place);
478478
crate::abi::codegen_drop(fx, source_info, drop_place);
479479

compiler/rustc_codegen_ssa/src/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12561256
MergingSucc::False
12571257
}
12581258

1259-
mir::TerminatorKind::Drop { place, target, unwind } => {
1259+
mir::TerminatorKind::Drop { place, target, unwind, replace: _ } => {
12601260
self.codegen_drop_terminator(helper, bx, place, target, unwind, mergeable_succ())
12611261
}
12621262

compiler/rustc_const_eval/src/interpret/terminator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
114114
}
115115
}
116116

117-
Drop { place, target, unwind } => {
117+
Drop { place, target, unwind, replace: _ } => {
118118
let frame = self.frame();
119119
let ty = place.ty(&frame.body.local_decls, *self.tcx).ty;
120120
let ty = self.subst_from_frame_and_normalize_erasing_regions(frame, ty)?;

compiler/rustc_middle/src/mir/syntax.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,11 @@ pub enum TerminatorKind<'tcx> {
603603
/// > The drop glue is executed if, among all statements executed within this `Body`, an assignment to
604604
/// > the place or one of its "parents" occurred more recently than a move out of it. This does not
605605
/// > consider indirect assignments.
606-
Drop { place: Place<'tcx>, target: BasicBlock, unwind: UnwindAction },
606+
///
607+
/// The `replace` flag indicates whether this terminator was created as part of an assignment.
608+
/// This should only be used for diagnostic purposes, and does not have any operational
609+
/// meaning.
610+
Drop { place: Place<'tcx>, target: BasicBlock, unwind: UnwindAction, replace: bool },
607611

608612
/// Roughly speaking, evaluates the `func` operand and the arguments, and starts execution of
609613
/// the referred to function. The operand types must match the argument types of the function.

compiler/rustc_middle/src/mir/visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ macro_rules! make_mir_visitor {
504504
place,
505505
target: _,
506506
unwind: _,
507+
replace: _,
507508
} => {
508509
self.visit_place(
509510
place,

compiler/rustc_mir_build/src/build/custom/parse/instruction.rs

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
5757
place: self.parse_place(args[0])?,
5858
target: self.parse_block(args[1])?,
5959
unwind: UnwindAction::Continue,
60+
replace: false,
6061
})
6162
},
6263
@call("mir_call", args) => {

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+1
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
725725
place: to_drop,
726726
target: success,
727727
unwind: UnwindAction::Continue,
728+
replace: false,
728729
},
729730
);
730731
this.diverge_from(block);

compiler/rustc_mir_build/src/build/scope.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ use rustc_middle::middle::region;
9191
use rustc_middle::mir::*;
9292
use rustc_middle::thir::{Expr, LintLevel};
9393

94-
use rustc_span::{DesugaringKind, Span, DUMMY_SP};
94+
use rustc_span::{Span, DUMMY_SP};
9595

9696
#[derive(Debug)]
9797
pub struct Scopes<'tcx> {
@@ -371,6 +371,7 @@ impl DropTree {
371371
// The caller will handle this if needed.
372372
unwind: UnwindAction::Terminate,
373373
place: drop_data.0.local.into(),
374+
replace: false,
374375
};
375376
cfg.terminate(block, drop_data.0.source_info, terminator);
376377
}
@@ -1128,9 +1129,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11281129
place: Place<'tcx>,
11291130
value: Rvalue<'tcx>,
11301131
) -> BlockAnd<()> {
1131-
let span = self.tcx.with_stable_hashing_context(|hcx| {
1132-
span.mark_with_reason(None, DesugaringKind::Replace, self.tcx.sess.edition(), hcx)
1133-
});
11341132
let source_info = self.source_info(span);
11351133

11361134
// create the new block for the assignment
@@ -1148,6 +1146,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11481146
place,
11491147
target: assign,
11501148
unwind: UnwindAction::Cleanup(assign_unwind),
1149+
replace: true,
11511150
},
11521151
);
11531152
self.diverge_from(block);
@@ -1261,6 +1260,7 @@ fn build_scope_drops<'tcx>(
12611260
place: local.into(),
12621261
target: next,
12631262
unwind: UnwindAction::Continue,
1263+
replace: false,
12641264
},
12651265
);
12661266
block = next;

compiler/rustc_mir_dataflow/src/elaborate_drops.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ where
237237
place: self.place,
238238
target: self.succ,
239239
unwind: self.unwind.into_action(),
240+
replace: false,
240241
},
241242
);
242243
}
@@ -719,6 +720,7 @@ where
719720
place: tcx.mk_place_deref(ptr),
720721
target: loop_block,
721722
unwind: unwind.into_action(),
723+
replace: false,
722724
},
723725
);
724726

@@ -963,8 +965,12 @@ where
963965
}
964966

965967
fn drop_block(&mut self, target: BasicBlock, unwind: Unwind) -> BasicBlock {
966-
let block =
967-
TerminatorKind::Drop { place: self.place, target, unwind: unwind.into_action() };
968+
let block = TerminatorKind::Drop {
969+
place: self.place,
970+
target,
971+
unwind: unwind.into_action(),
972+
replace: false,
973+
};
968974
self.new_block(unwind, block)
969975
}
970976

compiler/rustc_mir_dataflow/src/framework/direction.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ impl Direction for Forward {
479479
Goto { target } => propagate(target, exit_state),
480480

481481
Assert { target, unwind, expected: _, msg: _, cond: _ }
482-
| Drop { target, unwind, place: _ }
482+
| Drop { target, unwind, place: _, replace: _ }
483483
| FalseUnwind { real_target: target, unwind } => {
484484
if let UnwindAction::Cleanup(unwind) = unwind {
485485
propagate(unwind, exit_state);

compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn add_move_for_packed_drop<'tcx>(
8080
is_cleanup: bool,
8181
) {
8282
debug!("add_move_for_packed_drop({:?} @ {:?})", terminator, loc);
83-
let TerminatorKind::Drop { ref place, target, unwind } = terminator.kind else {
83+
let TerminatorKind::Drop { ref place, target, unwind, replace } = terminator.kind else {
8484
unreachable!();
8585
};
8686

@@ -98,6 +98,11 @@ fn add_move_for_packed_drop<'tcx>(
9898
patch.add_assign(loc, Place::from(temp), Rvalue::Use(Operand::Move(*place)));
9999
patch.patch_terminator(
100100
loc.block,
101-
TerminatorKind::Drop { place: Place::from(temp), target: storage_dead_block, unwind },
101+
TerminatorKind::Drop {
102+
place: Place::from(temp),
103+
target: storage_dead_block,
104+
unwind,
105+
replace,
106+
},
102107
);
103108
}

compiler/rustc_mir_transform/src/elaborate_drops.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_mir_dataflow::un_derefer::UnDerefer;
1414
use rustc_mir_dataflow::MoveDataParamEnv;
1515
use rustc_mir_dataflow::{on_all_children_bits, on_all_drop_children_bits};
1616
use rustc_mir_dataflow::{Analysis, ResultsCursor};
17-
use rustc_span::{DesugaringKind, Span};
17+
use rustc_span::Span;
1818
use rustc_target::abi::{FieldIdx, VariantIdx};
1919
use std::fmt;
2020

@@ -401,7 +401,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
401401
let terminator = data.terminator();
402402

403403
match terminator.kind {
404-
TerminatorKind::Drop { mut place, target, unwind } => {
404+
TerminatorKind::Drop { mut place, target, unwind, replace } => {
405405
if let Some(new_place) = self.un_derefer.derefer(place.as_ref(), self.body) {
406406
place = new_place;
407407
}
@@ -434,10 +434,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
434434
)
435435
}
436436
LookupResult::Parent(..) => {
437-
if !matches!(
438-
terminator.source_info.span.desugaring_kind(),
439-
Some(DesugaringKind::Replace),
440-
) {
437+
if !replace {
441438
self.tcx.sess.delay_span_bug(
442439
terminator.source_info.span,
443440
format!("drop of untracked value {:?}", bb),

compiler/rustc_mir_transform/src/generator.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,10 @@ fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
10451045

10461046
for (block, block_data) in body.basic_blocks.iter_enumerated() {
10471047
let (target, unwind, source_info) = match block_data.terminator() {
1048-
Terminator { source_info, kind: TerminatorKind::Drop { place, target, unwind } } => {
1048+
Terminator {
1049+
source_info,
1050+
kind: TerminatorKind::Drop { place, target, unwind, replace: _ },
1051+
} => {
10491052
if let Some(local) = place.as_local() {
10501053
if local == SELF_ARG {
10511054
(target, unwind, source_info)
@@ -1304,6 +1307,7 @@ fn insert_clean_drop(body: &mut Body<'_>) -> BasicBlock {
13041307
place: Place::from(SELF_ARG),
13051308
target: return_block,
13061309
unwind: UnwindAction::Continue,
1310+
replace: false,
13071311
};
13081312
let source_info = SourceInfo::outermost(body.span);
13091313

compiler/rustc_mir_transform/src/inline.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -449,16 +449,16 @@ impl<'tcx> Inliner<'tcx> {
449449
checker.visit_basic_block_data(bb, blk);
450450

451451
let term = blk.terminator();
452-
if let TerminatorKind::Drop { ref place, target, unwind } = term.kind {
452+
if let TerminatorKind::Drop { ref place, target, unwind, replace: _ } = term.kind {
453453
work_list.push(target);
454454

455455
// If the place doesn't actually need dropping, treat it like a regular goto.
456456
let ty = callsite
457457
.callee
458458
.subst_mir(self.tcx, ty::EarlyBinder(&place.ty(callee_body, tcx).ty));
459459
if ty.needs_drop(tcx, self.param_env) && let UnwindAction::Cleanup(unwind) = unwind {
460-
work_list.push(unwind);
461-
}
460+
work_list.push(unwind);
461+
}
462462
} else if callee_attrs.instruction_set != self.codegen_fn_attrs.instruction_set
463463
&& matches!(term.kind, TerminatorKind::InlineAsm { .. })
464464
{

0 commit comments

Comments
 (0)