Skip to content

Commit e1c28e0

Browse files
committed
Auto merge of #102068 - cjgillot:erased-lifetime-print, r=eholk
Always print '_, even for erased lifetimes. Explicit lifetime arguments are now the recommended syntax in rust 2018 and rust 2021. This PR applies this discipline to rustc itself.
2 parents 4a14677 + eb1ddd2 commit e1c28e0

22 files changed

+72
-91
lines changed

compiler/rustc_middle/src/ty/print/pretty.rs

+3-22
Original file line numberDiff line numberDiff line change
@@ -1088,17 +1088,9 @@ pub trait PrettyPrinter<'tcx>:
10881088
.generics_of(principal.def_id)
10891089
.own_substs_no_defaults(cx.tcx(), principal.substs);
10901090

1091-
// Don't print `'_` if there's no unerased regions.
1092-
let print_regions = args.iter().any(|arg| match arg.unpack() {
1093-
GenericArgKind::Lifetime(r) => !r.is_erased(),
1094-
_ => false,
1095-
});
1096-
let mut args = args.iter().cloned().filter(|arg| match arg.unpack() {
1097-
GenericArgKind::Lifetime(_) => print_regions,
1098-
_ => true,
1099-
});
11001091
let mut projections = predicates.projection_bounds();
11011092

1093+
let mut args = args.iter().cloned();
11021094
let arg0 = args.next();
11031095
let projection0 = projections.next();
11041096
if arg0.is_some() || projection0.is_some() {
@@ -1845,22 +1837,11 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
18451837
) -> Result<Self::Path, Self::Error> {
18461838
self = print_prefix(self)?;
18471839

1848-
// Don't print `'_` if there's no unerased regions.
1849-
let print_regions = self.tcx.sess.verbose()
1850-
|| args.iter().any(|arg| match arg.unpack() {
1851-
GenericArgKind::Lifetime(r) => !r.is_erased(),
1852-
_ => false,
1853-
});
1854-
let args = args.iter().cloned().filter(|arg| match arg.unpack() {
1855-
GenericArgKind::Lifetime(_) => print_regions,
1856-
_ => true,
1857-
});
1858-
1859-
if args.clone().next().is_some() {
1840+
if args.first().is_some() {
18601841
if self.in_value {
18611842
write!(self, "::")?;
18621843
}
1863-
self.generic_delimiters(|cx| cx.comma_sep(args))
1844+
self.generic_delimiters(|cx| cx.comma_sep(args.iter().cloned()))
18641845
} else {
18651846
Ok(self)
18661847
}

src/test/codegen-units/item-collection/generic-impl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ pub struct LifeTimeOnly<'a> {
3030

3131
impl<'a> LifeTimeOnly<'a> {
3232

33-
//~ MONO_ITEM fn LifeTimeOnly::foo
33+
//~ MONO_ITEM fn LifeTimeOnly::<'_>::foo
3434
pub fn foo(&self) {}
35-
//~ MONO_ITEM fn LifeTimeOnly::bar
35+
//~ MONO_ITEM fn LifeTimeOnly::<'_>::bar
3636
pub fn bar(&'a self) {}
37-
//~ MONO_ITEM fn LifeTimeOnly::baz
37+
//~ MONO_ITEM fn LifeTimeOnly::<'_>::baz
3838
pub fn baz<'b>(&'b self) {}
3939

4040
pub fn non_instantiated<T>(&self) {}

src/test/mir-opt/derefer_complex_case.main.Derefer.diff

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
fn main() -> () {
55
let mut _0: (); // return place in scope 0 at $DIR/derefer_complex_case.rs:+0:11: +0:11
6-
let mut _1: std::slice::Iter<i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
6+
let mut _1: std::slice::Iter<'_, i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
77
let mut _2: &[i32; 2]; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
88
let _3: [i32; 2]; // in scope 0 at $DIR/derefer_complex_case.rs:+1:18: +1:26
9-
let mut _4: std::slice::Iter<i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
9+
let mut _4: std::slice::Iter<'_, i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
1010
let mut _5: (); // in scope 0 at $DIR/derefer_complex_case.rs:+0:1: +2:2
1111
let _6: (); // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
1212
let mut _7: std::option::Option<&i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
13-
let mut _8: &mut std::slice::Iter<i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
14-
let mut _9: &mut std::slice::Iter<i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
13+
let mut _8: &mut std::slice::Iter<'_, i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
14+
let mut _9: &mut std::slice::Iter<'_, i32>; // in scope 0 at $DIR/derefer_complex_case.rs:+1:17: +1:26
1515
let mut _10: isize; // in scope 0 at $DIR/derefer_complex_case.rs:+1:5: +1:40
1616
let mut _11: !; // in scope 0 at $DIR/derefer_complex_case.rs:+1:5: +1:40
1717
let mut _13: i32; // in scope 0 at $DIR/derefer_complex_case.rs:+1:34: +1:37
@@ -53,10 +53,10 @@
5353
StorageLive(_9); // scope 1 at $DIR/derefer_complex_case.rs:+1:17: +1:26
5454
_9 = &mut _4; // scope 1 at $DIR/derefer_complex_case.rs:+1:17: +1:26
5555
_8 = &mut (*_9); // scope 1 at $DIR/derefer_complex_case.rs:+1:17: +1:26
56-
_7 = <std::slice::Iter<i32> as Iterator>::next(move _8) -> bb3; // scope 1 at $DIR/derefer_complex_case.rs:+1:17: +1:26
56+
_7 = <std::slice::Iter<'_, i32> as Iterator>::next(move _8) -> bb3; // scope 1 at $DIR/derefer_complex_case.rs:+1:17: +1:26
5757
// mir::Constant
5858
// + span: $DIR/derefer_complex_case.rs:6:17: 6:26
59-
// + literal: Const { ty: for<'r> fn(&'r mut std::slice::Iter<i32>) -> Option<<std::slice::Iter<i32> as Iterator>::Item> {<std::slice::Iter<i32> as Iterator>::next}, val: Value(<ZST>) }
59+
// + literal: Const { ty: for<'r> fn(&'r mut std::slice::Iter<'_, i32>) -> Option<<std::slice::Iter<'_, i32> as Iterator>::Item> {<std::slice::Iter<'_, i32> as Iterator>::next}, val: Value(<ZST>) }
6060
}
6161

6262
bb3: {

src/test/mir-opt/early_otherwise_branch_soundness.no_downcast.EarlyOtherwiseBranch.diff

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
- // MIR for `no_downcast` before EarlyOtherwiseBranch
22
+ // MIR for `no_downcast` after EarlyOtherwiseBranch
33

4-
fn no_downcast(_1: &E) -> u32 {
4+
fn no_downcast(_1: &E<'_>) -> u32 {
55
debug e => _1; // in scope 0 at $DIR/early_otherwise_branch_soundness.rs:+0:16: +0:17
66
let mut _0: u32; // return place in scope 0 at $DIR/early_otherwise_branch_soundness.rs:+0:26: +0:29
77
let mut _2: isize; // in scope 0 at $DIR/early_otherwise_branch_soundness.rs:+1:20: +1:30
88
let mut _3: isize; // in scope 0 at $DIR/early_otherwise_branch_soundness.rs:+1:12: +1:31
9-
let mut _4: &E; // in scope 0 at $DIR/early_otherwise_branch_soundness.rs:+0:16: +0:17
9+
let mut _4: &E<'_>; // in scope 0 at $DIR/early_otherwise_branch_soundness.rs:+0:16: +0:17
1010
scope 1 {
1111
}
1212

@@ -16,7 +16,7 @@
1616
}
1717

1818
bb1: {
19-
_4 = deref_copy (((*_1) as Some).0: &E); // scope 1 at $DIR/early_otherwise_branch_soundness.rs:+1:12: +1:31
19+
_4 = deref_copy (((*_1) as Some).0: &E<'_>); // scope 1 at $DIR/early_otherwise_branch_soundness.rs:+1:12: +1:31
2020
_2 = discriminant((*_4)); // scope 1 at $DIR/early_otherwise_branch_soundness.rs:+1:12: +1:31
2121
switchInt(move _2) -> [1_isize: bb2, otherwise: bb3]; // scope 1 at $DIR/early_otherwise_branch_soundness.rs:+1:12: +1:31
2222
}

src/test/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
- // MIR for `float_to_exponential_common` before ConstProp
22
+ // MIR for `float_to_exponential_common` after ConstProp
33

4-
fn float_to_exponential_common(_1: &mut Formatter, _2: &T, _3: bool) -> Result<(), std::fmt::Error> {
4+
fn float_to_exponential_common(_1: &mut Formatter<'_>, _2: &T, _3: bool) -> Result<(), std::fmt::Error> {
55
debug fmt => _1; // in scope 0 at $DIR/funky_arms.rs:+0:35: +0:38
66
debug num => _2; // in scope 0 at $DIR/funky_arms.rs:+0:60: +0:63
77
debug upper => _3; // in scope 0 at $DIR/funky_arms.rs:+0:69: +0:74
88
let mut _0: std::result::Result<(), std::fmt::Error>; // return place in scope 0 at $DIR/funky_arms.rs:+0:85: +0:91
99
let _4: bool; // in scope 0 at $DIR/funky_arms.rs:+4:9: +4:19
10-
let mut _5: &std::fmt::Formatter; // in scope 0 at $DIR/funky_arms.rs:+4:22: +4:37
10+
let mut _5: &std::fmt::Formatter<'_>; // in scope 0 at $DIR/funky_arms.rs:+4:22: +4:37
1111
let mut _7: std::option::Option<usize>; // in scope 0 at $DIR/funky_arms.rs:+13:30: +13:45
12-
let mut _8: &std::fmt::Formatter; // in scope 0 at $DIR/funky_arms.rs:+13:30: +13:45
12+
let mut _8: &std::fmt::Formatter<'_>; // in scope 0 at $DIR/funky_arms.rs:+13:30: +13:45
1313
let mut _9: isize; // in scope 0 at $DIR/funky_arms.rs:+13:12: +13:27
14-
let mut _11: &mut std::fmt::Formatter; // in scope 0 at $DIR/funky_arms.rs:+15:43: +15:46
14+
let mut _11: &mut std::fmt::Formatter<'_>; // in scope 0 at $DIR/funky_arms.rs:+15:43: +15:46
1515
let mut _12: &T; // in scope 0 at $DIR/funky_arms.rs:+15:48: +15:51
1616
let mut _13: core::num::flt2dec::Sign; // in scope 0 at $DIR/funky_arms.rs:+15:53: +15:57
1717
let mut _14: u32; // in scope 0 at $DIR/funky_arms.rs:+15:59: +15:79
1818
let mut _15: u32; // in scope 0 at $DIR/funky_arms.rs:+15:59: +15:75
1919
let mut _16: usize; // in scope 0 at $DIR/funky_arms.rs:+15:59: +15:68
2020
let mut _17: bool; // in scope 0 at $DIR/funky_arms.rs:+15:81: +15:86
21-
let mut _18: &mut std::fmt::Formatter; // in scope 0 at $DIR/funky_arms.rs:+17:46: +17:49
21+
let mut _18: &mut std::fmt::Formatter<'_>; // in scope 0 at $DIR/funky_arms.rs:+17:46: +17:49
2222
let mut _19: &T; // in scope 0 at $DIR/funky_arms.rs:+17:51: +17:54
2323
let mut _20: core::num::flt2dec::Sign; // in scope 0 at $DIR/funky_arms.rs:+17:56: +17:60
2424
let mut _21: bool; // in scope 0 at $DIR/funky_arms.rs:+17:62: +17:67
@@ -38,10 +38,10 @@
3838
StorageLive(_4); // scope 0 at $DIR/funky_arms.rs:+4:9: +4:19
3939
StorageLive(_5); // scope 0 at $DIR/funky_arms.rs:+4:22: +4:37
4040
_5 = &(*_1); // scope 0 at $DIR/funky_arms.rs:+4:22: +4:37
41-
_4 = Formatter::sign_plus(move _5) -> bb1; // scope 0 at $DIR/funky_arms.rs:+4:22: +4:37
41+
_4 = Formatter::<'_>::sign_plus(move _5) -> bb1; // scope 0 at $DIR/funky_arms.rs:+4:22: +4:37
4242
// mir::Constant
4343
// + span: $DIR/funky_arms.rs:15:26: 15:35
44-
// + literal: Const { ty: for<'r> fn(&'r Formatter) -> bool {Formatter::sign_plus}, val: Value(<ZST>) }
44+
// + literal: Const { ty: for<'r> fn(&'r Formatter<'_>) -> bool {Formatter::<'_>::sign_plus}, val: Value(<ZST>) }
4545
}
4646

4747
bb1: {
@@ -66,10 +66,10 @@
6666
StorageLive(_7); // scope 3 at $DIR/funky_arms.rs:+13:30: +13:45
6767
StorageLive(_8); // scope 3 at $DIR/funky_arms.rs:+13:30: +13:45
6868
_8 = &(*_1); // scope 3 at $DIR/funky_arms.rs:+13:30: +13:45
69-
_7 = Formatter::precision(move _8) -> bb5; // scope 3 at $DIR/funky_arms.rs:+13:30: +13:45
69+
_7 = Formatter::<'_>::precision(move _8) -> bb5; // scope 3 at $DIR/funky_arms.rs:+13:30: +13:45
7070
// mir::Constant
7171
// + span: $DIR/funky_arms.rs:24:34: 24:43
72-
// + literal: Const { ty: for<'r> fn(&'r Formatter) -> Option<usize> {Formatter::precision}, val: Value(<ZST>) }
72+
// + literal: Const { ty: for<'r> fn(&'r Formatter<'_>) -> Option<usize> {Formatter::<'_>::precision}, val: Value(<ZST>) }
7373
}
7474

7575
bb5: {

src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
let _24: &i32; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
2626
let mut _25: &i32; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
2727
let _26: &i32; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
28-
let mut _27: std::option::Option<std::fmt::Arguments>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
28+
let mut _27: std::option::Option<std::fmt::Arguments<'_>>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
2929
scope 1 {
3030
debug split => _1; // in scope 1 at $DIR/issue-73223.rs:+1:9: +1:14
3131
let _6: std::option::Option<i32>; // in scope 1 at $DIR/issue-73223.rs:+6:9: +6:14

src/test/mir-opt/issue_99325.main.mir_map.0.mir

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() -> () {
2626
let _19: &&[u8]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
2727
let mut _20: &&[u8; 4]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
2828
let _21: &&[u8; 4]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
29-
let mut _22: std::option::Option<std::fmt::Arguments>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
29+
let mut _22: std::option::Option<std::fmt::Arguments<'_>>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
3030
let _23: (); // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
3131
let mut _24: (&&[u8], &&[u8; 4]); // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
3232
let mut _25: &&[u8]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
@@ -46,7 +46,7 @@ fn main() -> () {
4646
let _40: &&[u8]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
4747
let mut _41: &&[u8; 4]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
4848
let _42: &&[u8; 4]; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
49-
let mut _43: std::option::Option<std::fmt::Arguments>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
49+
let mut _43: std::option::Option<std::fmt::Arguments<'_>>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
5050
scope 1 {
5151
debug left_val => _8; // in scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
5252
debug right_val => _9; // in scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
@@ -128,7 +128,7 @@ fn main() -> () {
128128
_21 = &(*_9); // scope 2 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
129129
_20 = &(*_21); // scope 2 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
130130
StorageLive(_22); // scope 2 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
131-
_22 = Option::<Arguments>::None; // scope 2 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
131+
_22 = Option::<Arguments<'_>>::None; // scope 2 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
132132
_16 = core::panicking::assert_failed::<&[u8], &[u8; 4]>(move _17, move _18, move _20, move _22) -> bb19; // scope 2 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
133133
// mir::Constant
134134
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
@@ -237,7 +237,7 @@ fn main() -> () {
237237
_42 = &(*_30); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
238238
_41 = &(*_42); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
239239
StorageLive(_43); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
240-
_43 = Option::<Arguments>::None; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
240+
_43 = Option::<Arguments<'_>>::None; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
241241
_37 = core::panicking::assert_failed::<&[u8], &[u8; 4]>(move _38, move _39, move _41, move _43) -> bb19; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
242242
// mir::Constant
243243
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL

src/test/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn array_casts() -> () {
2929
let _31: &usize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
3030
let mut _32: &usize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
3131
let _33: &usize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
32-
let mut _34: std::option::Option<std::fmt::Arguments>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
32+
let mut _34: std::option::Option<std::fmt::Arguments<'_>>; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
3333
scope 1 {
3434
debug x => _1; // in scope 1 at $DIR/retag.rs:+1:9: +1:14
3535
let _2: *mut usize; // in scope 1 at $DIR/retag.rs:+2:9: +2:10

src/test/pretty/issue-4264.pp

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
((::alloc::fmt::format as
3535
for<'r> fn(Arguments<'r>) -> String {format})(((::core::fmt::Arguments::new_v1
3636
as
37-
fn(&[&'static str], &[ArgumentV1]) -> Arguments {Arguments::new_v1})((&([("test"
37+
fn(&[&'static str], &[ArgumentV1<'_>]) -> Arguments<'_> {Arguments::<'_>::new_v1})((&([("test"
3838
as &str)] as [&str; 1]) as &[&str; 1]),
39-
(&([] as [ArgumentV1; 0]) as &[ArgumentV1; 0])) as
40-
Arguments)) as String);
39+
(&([] as [ArgumentV1<'_>; 0]) as &[ArgumentV1<'_>; 0])) as
40+
Arguments<'_>)) as String);
4141
(res as String)
4242
} as String);
4343
} as ())

src/test/ui/const-generics/issues/issue-83765.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
error[E0391]: cycle detected when resolving instance `<LazyUpdim<T, { T::DIM }, DIM> as TensorDimension>::DIM`
1+
error[E0391]: cycle detected when resolving instance `<LazyUpdim<'_, T, { T::DIM }, DIM> as TensorDimension>::DIM`
22
--> $DIR/issue-83765.rs:5:5
33
|
44
LL | const DIM: usize;
55
| ^^^^^^^^^^^^^^^^
66
|
7-
note: ...which requires computing candidate for `<LazyUpdim<T, { T::DIM }, DIM> as TensorDimension>`...
7+
note: ...which requires computing candidate for `<LazyUpdim<'_, T, { T::DIM }, DIM> as TensorDimension>`...
88
--> $DIR/issue-83765.rs:4:1
99
|
1010
LL | trait TensorDimension {
1111
| ^^^^^^^^^^^^^^^^^^^^^
12-
= note: ...which again requires resolving instance `<LazyUpdim<T, { T::DIM }, DIM> as TensorDimension>::DIM`, completing the cycle
13-
note: cycle used when computing candidate for `<LazyUpdim<T, { T::DIM }, DIM> as TensorDimension>`
12+
= note: ...which again requires resolving instance `<LazyUpdim<'_, T, { T::DIM }, DIM> as TensorDimension>::DIM`, completing the cycle
13+
note: cycle used when computing candidate for `<LazyUpdim<'_, T, { T::DIM }, DIM> as TensorDimension>`
1414
--> $DIR/issue-83765.rs:4:1
1515
|
1616
LL | trait TensorDimension {

0 commit comments

Comments
 (0)