Skip to content

Commit e9426ca

Browse files
authored
Unrolled build for rust-lang#129388
Rollup merge of rust-lang#129388 - cjgillot:region-def-id, r=compiler-errors Do not rely on names to find lifetimes. For some reason, we were trying to find the lifetime parameter from its name, instead of using the def_id we have. This PR uses it instead. This changes some ui tests, I think to be more sensible.
2 parents 739b1fd + ca7c55f commit e9426ca

File tree

7 files changed

+19
-39
lines changed

7 files changed

+19
-39
lines changed

compiler/rustc_trait_selection/src/error_reporting/infer/region.rs

+4-20
Original file line numberDiff line numberDiff line change
@@ -1099,16 +1099,8 @@ fn msg_span_from_named_region<'tcx>(
10991099
) -> (String, Option<Span>) {
11001100
match *region {
11011101
ty::ReEarlyParam(br) => {
1102-
let scope = tcx
1103-
.parent(tcx.generics_of(generic_param_scope).region_param(br, tcx).def_id)
1104-
.expect_local();
1105-
let span = if let Some(param) =
1106-
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name))
1107-
{
1108-
param.span
1109-
} else {
1110-
tcx.def_span(scope)
1111-
};
1102+
let param_def_id = tcx.generics_of(generic_param_scope).region_param(br, tcx).def_id;
1103+
let span = tcx.def_span(param_def_id);
11121104
let text = if br.has_name() {
11131105
format!("the lifetime `{}` as defined here", br.name)
11141106
} else {
@@ -1124,16 +1116,8 @@ fn msg_span_from_named_region<'tcx>(
11241116
("the anonymous lifetime defined here".to_string(), Some(ty.span))
11251117
} else {
11261118
match fr.bound_region {
1127-
ty::BoundRegionKind::BrNamed(_, name) => {
1128-
let span = if let Some(param) = tcx
1129-
.hir()
1130-
.get_generics(generic_param_scope)
1131-
.and_then(|generics| generics.get_named(name))
1132-
{
1133-
param.span
1134-
} else {
1135-
tcx.def_span(generic_param_scope)
1136-
};
1119+
ty::BoundRegionKind::BrNamed(param_def_id, name) => {
1120+
let span = tcx.def_span(param_def_id);
11371121
let text = if name == kw::UnderscoreLifetime {
11381122
"the anonymous lifetime as defined here".to_string()
11391123
} else {

tests/ui/borrowck/regions-bound-missing-bound-in-impl.stderr

+4-5
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ note: the lifetime `'c` as defined here...
3030
LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
3131
| ^^
3232
note: ...does not necessarily outlive the lifetime `'c` as defined here
33-
--> $DIR/regions-bound-missing-bound-in-impl.rs:27:24
33+
--> $DIR/regions-bound-missing-bound-in-impl.rs:12:24
3434
|
35-
LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
35+
LL | fn wrong_bound1<'b,'c,'d:'a+'b>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>);
3636
| ^^
3737

3838
error[E0308]: method not compatible with trait
@@ -44,16 +44,15 @@ LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d
4444
= note: expected signature `fn(&'a _, Inv<'c>, Inv<'c>, Inv<'_>)`
4545
found signature `fn(&'a _, Inv<'_>, Inv<'c>, Inv<'_>)`
4646
note: the lifetime `'c` as defined here...
47-
--> $DIR/regions-bound-missing-bound-in-impl.rs:27:24
47+
--> $DIR/regions-bound-missing-bound-in-impl.rs:12:24
4848
|
49-
LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
49+
LL | fn wrong_bound1<'b,'c,'d:'a+'b>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>);
5050
| ^^
5151
note: ...does not necessarily outlive the lifetime `'c` as defined here
5252
--> $DIR/regions-bound-missing-bound-in-impl.rs:27:24
5353
|
5454
LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
5555
| ^^
56-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
5756

5857
error[E0195]: lifetime parameters or bounds on method `wrong_bound2` do not match the trait declaration
5958
--> $DIR/regions-bound-missing-bound-in-impl.rs:42:20

tests/ui/consts/static-default-lifetime/elided-lifetime.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ LL | const STATIC: &str = "";
4848
= note: expected reference `&'static _`
4949
found reference `&_`
5050
note: the anonymous lifetime as defined here...
51-
--> $DIR/elided-lifetime.rs:15:18
51+
--> $DIR/elided-lifetime.rs:16:19
5252
|
53-
LL | impl Bar for Foo<'_> {
54-
| ^^
53+
LL | const STATIC: &str = "";
54+
| ^
5555
= note: ...does not necessarily outlive the static lifetime
5656

5757
error: aborting due to 3 previous errors

tests/ui/consts/static-default-lifetime/static-trait-impl.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ LL | const STATIC: &str = "";
3030
= note: expected reference `&_`
3131
found reference `&_`
3232
note: the anonymous lifetime as defined here...
33-
--> $DIR/static-trait-impl.rs:8:10
33+
--> $DIR/static-trait-impl.rs:9:19
3434
|
35-
LL | impl Bar<'_> for A {
36-
| ^^
35+
LL | const STATIC: &str = "";
36+
| ^
3737
note: ...does not necessarily outlive the anonymous lifetime as defined here
3838
--> $DIR/static-trait-impl.rs:8:10
3939
|

tests/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ LL | fn get<'s>(s: &'s str, _: <&'static &'s () as Project>::Ty) -> &'static
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
note: first, the lifetime cannot outlive the lifetime `'s` as defined here...
8-
--> $DIR/impl-implied-bounds-compatibility-unnormalized.rs:11:12
8+
--> $DIR/impl-implied-bounds-compatibility-unnormalized.rs:8:12
99
|
10-
LL | fn get<'s>(s: &'s str, _: <&'static &'s () as Project>::Ty) -> &'static str {
10+
LL | fn get<'s>(s: &'s str, _: ()) -> &'static str;
1111
| ^^
1212
note: ...so that the method type is compatible with trait
1313
--> $DIR/impl-implied-bounds-compatibility-unnormalized.rs:11:5

tests/ui/issues/issue-20831-debruijn.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | fn subscribe(&mut self, t : Box<dyn Subscriber<Input=<Self as Publisher
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
note: first, the lifetime cannot outlive the anonymous lifetime as defined here...
8-
--> $DIR/issue-20831-debruijn.rs:28:18
8+
--> $DIR/issue-20831-debruijn.rs:28:67
99
|
1010
LL | fn subscribe(&mut self, t : Box<dyn Subscriber<Input=<Self as Publisher>::Output> + 'a>) {
11-
| ^
11+
| ^^^^^^^^^
1212
note: ...but the lifetime must also be valid for the lifetime `'a` as defined here...
1313
--> $DIR/issue-20831-debruijn.rs:26:6
1414
|

tests/ui/issues/issue-37884.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ LL | fn next(&'a mut self) -> Option<Self::Item>
77
= note: expected signature `fn(&mut RepeatMut<'_, _>) -> Option<_>`
88
found signature `fn(&'a mut RepeatMut<'_, _>) -> Option<_>`
99
note: the anonymous lifetime as defined here...
10-
--> $DIR/issue-37884.rs:6:5
11-
|
12-
LL | fn next(&'a mut self) -> Option<Self::Item>
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
1411
note: ...does not necessarily outlive the lifetime `'a` as defined here
1512
--> $DIR/issue-37884.rs:3:6
1613
|

0 commit comments

Comments
 (0)