Skip to content

Commit d3f3004

Browse files
committed
Auto merge of rust-lang#92062 - matthiaskrgr:rollup-en3p4sb, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#91439 (Mark defaulted `PartialEq`/`PartialOrd` methods as const) - rust-lang#91516 (Improve suggestion to change struct field to &mut) - rust-lang#91896 (Remove `in_band_lifetimes` for `rustc_passes`) - rust-lang#91909 (:arrow_up: rust-analyzer) - rust-lang#91922 (Remove `in_band_lifetimes` from `rustc_mir_dataflow`) - rust-lang#92025 (Revert "socket ancillary data implementation for dragonflybsd.") - rust-lang#92030 (Update stdlib to the 2021 edition) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 208ced6 + efbefb6 commit d3f3004

Some content is hidden

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

41 files changed

+208
-239
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+12-27
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
229229
} => {
230230
err.span_label(span, format!("cannot {ACT}", ACT = act));
231231

232-
if let Some((span, message)) = annotate_struct_field(
232+
if let Some(span) = get_mut_span_in_struct_field(
233233
self.infcx.tcx,
234234
Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty,
235235
field,
236236
) {
237-
err.span_suggestion(
237+
err.span_suggestion_verbose(
238238
span,
239239
"consider changing this to be mutable",
240-
message,
240+
" mut ".into(),
241241
Applicability::MaybeIncorrect,
242242
);
243243
}
@@ -1059,18 +1059,18 @@ fn is_closure_or_generator(ty: Ty<'_>) -> bool {
10591059
ty.is_closure() || ty.is_generator()
10601060
}
10611061

1062-
/// Adds a suggestion to a struct definition given a field access to a local.
1063-
/// This function expects the local to be a reference to a struct in order to produce a suggestion.
1062+
/// Given a field that needs to be mutable, returns a span where the " mut " could go.
1063+
/// This function expects the local to be a reference to a struct in order to produce a span.
10641064
///
10651065
/// ```text
1066-
/// LL | s: &'a String
1067-
/// | ---------- use `&'a mut String` here to make mutable
1066+
/// LL | s: &'a String
1067+
/// | ^^^ returns a span taking up the space here
10681068
/// ```
1069-
fn annotate_struct_field<'tcx>(
1069+
fn get_mut_span_in_struct_field<'tcx>(
10701070
tcx: TyCtxt<'tcx>,
10711071
ty: Ty<'tcx>,
10721072
field: &mir::Field,
1073-
) -> Option<(Span, String)> {
1073+
) -> Option<Span> {
10741074
// Expect our local to be a reference to a struct of some kind.
10751075
if let ty::Ref(_, ty, _) = ty.kind() {
10761076
if let ty::Adt(def, _) = ty.kind() {
@@ -1081,25 +1081,10 @@ fn annotate_struct_field<'tcx>(
10811081
// Now we're dealing with the actual struct that we're going to suggest a change to,
10821082
// we can expect a field that is an immutable reference to a type.
10831083
if let hir::Node::Field(field) = node {
1084-
if let hir::TyKind::Rptr(
1085-
lifetime,
1086-
hir::MutTy { mutbl: hir::Mutability::Not, ref ty },
1087-
) = field.ty.kind
1084+
if let hir::TyKind::Rptr(lifetime, hir::MutTy { mutbl: hir::Mutability::Not, ty }) =
1085+
field.ty.kind
10881086
{
1089-
// Get the snippets in two parts - the named lifetime (if there is one) and
1090-
// type being referenced, that way we can reconstruct the snippet without loss
1091-
// of detail.
1092-
let type_snippet = tcx.sess.source_map().span_to_snippet(ty.span).ok()?;
1093-
let lifetime_snippet = if !lifetime.is_elided() {
1094-
format!("{} ", tcx.sess.source_map().span_to_snippet(lifetime.span).ok()?)
1095-
} else {
1096-
String::new()
1097-
};
1098-
1099-
return Some((
1100-
field.ty.span,
1101-
format!("&{}mut {}", lifetime_snippet, &*type_snippet,),
1102-
));
1087+
return Some(lifetime.span.between(ty.span));
11031088
}
11041089
}
11051090
}

compiler/rustc_mir_dataflow/src/framework/direction.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub trait Direction {
1818
/// Applies all effects between the given `EffectIndex`s.
1919
///
2020
/// `effects.start()` must precede or equal `effects.end()` in this direction.
21-
fn apply_effects_in_range<A>(
21+
fn apply_effects_in_range<'tcx, A>(
2222
analysis: &A,
2323
state: &mut A::Domain,
2424
block: BasicBlock,
@@ -27,23 +27,23 @@ pub trait Direction {
2727
) where
2828
A: Analysis<'tcx>;
2929

30-
fn apply_effects_in_block<A>(
30+
fn apply_effects_in_block<'tcx, A>(
3131
analysis: &A,
3232
state: &mut A::Domain,
3333
block: BasicBlock,
3434
block_data: &mir::BasicBlockData<'tcx>,
3535
) where
3636
A: Analysis<'tcx>;
3737

38-
fn gen_kill_effects_in_block<A>(
38+
fn gen_kill_effects_in_block<'tcx, A>(
3939
analysis: &A,
4040
trans: &mut GenKillSet<A::Idx>,
4141
block: BasicBlock,
4242
block_data: &mir::BasicBlockData<'tcx>,
4343
) where
4444
A: GenKillAnalysis<'tcx>;
4545

46-
fn visit_results_in_block<F, R>(
46+
fn visit_results_in_block<'mir, 'tcx, F, R>(
4747
state: &mut F,
4848
block: BasicBlock,
4949
block_data: &'mir mir::BasicBlockData<'tcx>,
@@ -52,7 +52,7 @@ pub trait Direction {
5252
) where
5353
R: ResultsVisitable<'tcx, FlowState = F>;
5454

55-
fn join_state_into_successors_of<A>(
55+
fn join_state_into_successors_of<'tcx, A>(
5656
analysis: &A,
5757
tcx: TyCtxt<'tcx>,
5858
body: &mir::Body<'tcx>,
@@ -72,7 +72,7 @@ impl Direction for Backward {
7272
false
7373
}
7474

75-
fn apply_effects_in_block<A>(
75+
fn apply_effects_in_block<'tcx, A>(
7676
analysis: &A,
7777
state: &mut A::Domain,
7878
block: BasicBlock,
@@ -92,7 +92,7 @@ impl Direction for Backward {
9292
}
9393
}
9494

95-
fn gen_kill_effects_in_block<A>(
95+
fn gen_kill_effects_in_block<'tcx, A>(
9696
analysis: &A,
9797
trans: &mut GenKillSet<A::Idx>,
9898
block: BasicBlock,
@@ -112,7 +112,7 @@ impl Direction for Backward {
112112
}
113113
}
114114

115-
fn apply_effects_in_range<A>(
115+
fn apply_effects_in_range<'tcx, A>(
116116
analysis: &A,
117117
state: &mut A::Domain,
118118
block: BasicBlock,
@@ -189,7 +189,7 @@ impl Direction for Backward {
189189
analysis.apply_statement_effect(state, statement, location);
190190
}
191191

192-
fn visit_results_in_block<F, R>(
192+
fn visit_results_in_block<'mir, 'tcx, F, R>(
193193
state: &mut F,
194194
block: BasicBlock,
195195
block_data: &'mir mir::BasicBlockData<'tcx>,
@@ -221,7 +221,7 @@ impl Direction for Backward {
221221
vis.visit_block_start(state, block_data, block);
222222
}
223223

224-
fn join_state_into_successors_of<A>(
224+
fn join_state_into_successors_of<'tcx, A>(
225225
analysis: &A,
226226
_tcx: TyCtxt<'tcx>,
227227
body: &mir::Body<'tcx>,
@@ -294,7 +294,7 @@ impl Direction for Forward {
294294
true
295295
}
296296

297-
fn apply_effects_in_block<A>(
297+
fn apply_effects_in_block<'tcx, A>(
298298
analysis: &A,
299299
state: &mut A::Domain,
300300
block: BasicBlock,
@@ -314,7 +314,7 @@ impl Direction for Forward {
314314
analysis.apply_terminator_effect(state, terminator, location);
315315
}
316316

317-
fn gen_kill_effects_in_block<A>(
317+
fn gen_kill_effects_in_block<'tcx, A>(
318318
analysis: &A,
319319
trans: &mut GenKillSet<A::Idx>,
320320
block: BasicBlock,
@@ -334,7 +334,7 @@ impl Direction for Forward {
334334
analysis.terminator_effect(trans, terminator, location);
335335
}
336336

337-
fn apply_effects_in_range<A>(
337+
fn apply_effects_in_range<'tcx, A>(
338338
analysis: &A,
339339
state: &mut A::Domain,
340340
block: BasicBlock,
@@ -407,7 +407,7 @@ impl Direction for Forward {
407407
}
408408
}
409409

410-
fn visit_results_in_block<F, R>(
410+
fn visit_results_in_block<'mir, 'tcx, F, R>(
411411
state: &mut F,
412412
block: BasicBlock,
413413
block_data: &'mir mir::BasicBlockData<'tcx>,
@@ -438,7 +438,7 @@ impl Direction for Forward {
438438
vis.visit_block_end(state, block_data, block);
439439
}
440440

441-
fn join_state_into_successors_of<A>(
441+
fn join_state_into_successors_of<'tcx, A>(
442442
analysis: &A,
443443
_tcx: TyCtxt<'tcx>,
444444
_body: &mir::Body<'tcx>,
@@ -591,7 +591,7 @@ where
591591
//
592592
// FIXME: Figure out how to express this using `Option::clone_from`, or maybe lift it into the
593593
// standard library?
594-
fn opt_clone_from_or_clone<T: Clone>(opt: &'a mut Option<T>, val: &T) -> &'a mut T {
594+
fn opt_clone_from_or_clone<'a, T: Clone>(opt: &'a mut Option<T>, val: &T) -> &'a mut T {
595595
if opt.is_some() {
596596
let ret = opt.as_mut().unwrap();
597597
ret.clone_from(val);

compiler/rustc_mir_dataflow/src/framework/engine.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ where
3131
pub(super) entry_sets: IndexVec<BasicBlock, A::Domain>,
3232
}
3333

34-
impl<A> Results<'tcx, A>
34+
impl<'tcx, A> Results<'tcx, A>
3535
where
3636
A: Analysis<'tcx>,
3737
{
3838
/// Creates a `ResultsCursor` that can inspect these `Results`.
39-
pub fn into_results_cursor(self, body: &'mir mir::Body<'tcx>) -> ResultsCursor<'mir, 'tcx, A> {
39+
pub fn into_results_cursor<'mir>(
40+
self,
41+
body: &'mir mir::Body<'tcx>,
42+
) -> ResultsCursor<'mir, 'tcx, A> {
4043
ResultsCursor::new(body, self)
4144
}
4245

@@ -45,7 +48,7 @@ where
4548
&self.entry_sets[block]
4649
}
4750

48-
pub fn visit_with(
51+
pub fn visit_with<'mir>(
4952
&self,
5053
body: &'mir mir::Body<'tcx>,
5154
blocks: impl IntoIterator<Item = BasicBlock>,
@@ -54,7 +57,7 @@ where
5457
visit_results(body, blocks, self, vis)
5558
}
5659

57-
pub fn visit_reachable_with(
60+
pub fn visit_reachable_with<'mir>(
5861
&self,
5962
body: &'mir mir::Body<'tcx>,
6063
vis: &mut impl ResultsVisitor<'mir, 'tcx, FlowState = A::Domain>,
@@ -85,7 +88,7 @@ where
8588
apply_trans_for_block: Option<Box<dyn Fn(BasicBlock, &mut A::Domain)>>,
8689
}
8790

88-
impl<A, D, T> Engine<'a, 'tcx, A>
91+
impl<'a, 'tcx, A, D, T> Engine<'a, 'tcx, A>
8992
where
9093
A: GenKillAnalysis<'tcx, Idx = T, Domain = D>,
9194
D: Clone + JoinSemiLattice + GenKill<T> + BorrowMut<BitSet<T>>,
@@ -119,7 +122,7 @@ where
119122
}
120123
}
121124

122-
impl<A, D> Engine<'a, 'tcx, A>
125+
impl<'a, 'tcx, A, D> Engine<'a, 'tcx, A>
123126
where
124127
A: Analysis<'tcx, Domain = D>,
125128
D: Clone + JoinSemiLattice,
@@ -257,7 +260,7 @@ where
257260

258261
/// Writes a DOT file containing the results of a dataflow analysis if the user requested it via
259262
/// `rustc_mir` attributes.
260-
fn write_graphviz_results<A>(
263+
fn write_graphviz_results<'tcx, A>(
261264
tcx: TyCtxt<'tcx>,
262265
body: &mir::Body<'tcx>,
263266
results: &Results<'tcx, A>,
@@ -330,7 +333,7 @@ struct RustcMirAttrs {
330333
}
331334

332335
impl RustcMirAttrs {
333-
fn parse(tcx: TyCtxt<'tcx>, def_id: DefId) -> Result<Self, ()> {
336+
fn parse(tcx: TyCtxt<'_>, def_id: DefId) -> Result<Self, ()> {
334337
let attrs = tcx.get_attrs(def_id);
335338

336339
let mut result = Ok(());
@@ -373,7 +376,7 @@ impl RustcMirAttrs {
373376

374377
fn set_field<T>(
375378
field: &mut Option<T>,
376-
tcx: TyCtxt<'tcx>,
379+
tcx: TyCtxt<'_>,
377380
attr: &ast::NestedMetaItem,
378381
mapper: impl FnOnce(Symbol) -> Result<T, ()>,
379382
) -> Result<(), ()> {

0 commit comments

Comments
 (0)