Skip to content

Commit 130e5e3

Browse files
committed
Fix early param lifetimes in generic_const_exprs
1 parent 61d3b26 commit 130e5e3

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
258258
.or_else(|| self.give_name_if_anonymous_region_appears_in_output(fr))
259259
.or_else(|| self.give_name_if_anonymous_region_appears_in_yield_ty(fr))
260260
.or_else(|| self.give_name_if_anonymous_region_appears_in_impl_signature(fr))
261-
.or_else(|| self.give_name_if_anonymous_region_appears_in_arg_position_impl_trait(fr));
262-
261+
.or_else(|| self.give_name_if_anonymous_region_appears_in_arg_position_impl_trait(fr))
262+
.or_else(|| self.give_name_if_anonymous_region_appears_in_early_param(fr));
263263
if let Some(value) = &value {
264264
self.region_names.try_borrow_mut().unwrap().insert(fr, value.clone());
265265
}
@@ -966,4 +966,23 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
966966
}
967967
})
968968
}
969+
970+
fn give_name_if_anonymous_region_appears_in_early_param(
971+
&self,
972+
fr: RegionVid,
973+
) -> Option<RegionName> {
974+
let error_region = self.to_error_region(fr)?;
975+
let tcx = self.infcx.tcx;
976+
977+
match *error_region {
978+
ty::ReEarlyParam(ebr) => {
979+
let span = tcx.hir().span_if_local(ebr.def_id).unwrap_or(DUMMY_SP);
980+
Some(RegionName {
981+
name: ebr.name,
982+
source: RegionNameSource::NamedEarlyParamRegion(span),
983+
})
984+
}
985+
_ => None,
986+
}
987+
}
969988
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(generic_const_exprs)]
2+
//~^ WARN the feature `generic_const_exprs` is incomplete
3+
4+
struct DataWrapper<'static> {
5+
//~^ ERROR invalid lifetime parameter name: `'static`
6+
data: &'a [u8; Self::SIZE],
7+
//~^ ERROR use of undeclared lifetime name `'a`
8+
//~^^ ERROR lifetime may not live long enough
9+
}
10+
11+
impl DataWrapper<'a> {
12+
//~^ ERROR undeclared lifetime
13+
const SIZE: usize = 14;
14+
}
15+
16+
fn main(){}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
error[E0262]: invalid lifetime parameter name: `'static`
2+
--> $DIR/generic_const_early_param.rs:4:20
3+
|
4+
LL | struct DataWrapper<'static> {
5+
| ^^^^^^^ 'static is a reserved lifetime name
6+
7+
error[E0261]: use of undeclared lifetime name `'a`
8+
--> $DIR/generic_const_early_param.rs:6:12
9+
|
10+
LL | struct DataWrapper<'static> {
11+
| - help: consider introducing lifetime `'a` here: `'a,`
12+
LL |
13+
LL | data: &'a [u8; Self::SIZE],
14+
| ^^ undeclared lifetime
15+
16+
error[E0261]: use of undeclared lifetime name `'a`
17+
--> $DIR/generic_const_early_param.rs:11:18
18+
|
19+
LL | impl DataWrapper<'a> {
20+
| - ^^ undeclared lifetime
21+
| |
22+
| help: consider introducing lifetime `'a` here: `<'a>`
23+
24+
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
25+
--> $DIR/generic_const_early_param.rs:1:12
26+
|
27+
LL | #![feature(generic_const_exprs)]
28+
| ^^^^^^^^^^^^^^^^^^^
29+
|
30+
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
31+
= note: `#[warn(incomplete_features)]` on by default
32+
33+
error: lifetime may not live long enough
34+
--> $DIR/generic_const_early_param.rs:6:20
35+
|
36+
LL | struct DataWrapper<'static> {
37+
| ------- lifetime `'_` defined here
38+
LL |
39+
LL | data: &'a [u8; Self::SIZE],
40+
| ^^^^^^^^^^ requires that `'_` must outlive `'static`
41+
42+
error: aborting due to 4 previous errors; 1 warning emitted
43+
44+
Some errors have detailed explanations: E0261, E0262.
45+
For more information about an error, try `rustc --explain E0261`.

0 commit comments

Comments
 (0)