Skip to content

Commit bcf9884

Browse files
resolve lifetimes for const generic defaults
1 parent b380086 commit bcf9884

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

compiler/rustc_resolve/src/late/lifetimes.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1339,11 +1339,14 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
13391339
this.visit_ty(&ty);
13401340
}
13411341
}
1342-
GenericParamKind::Const { ref ty, .. } => {
1342+
GenericParamKind::Const { ref ty, default } => {
13431343
let was_in_const_generic = this.is_in_const_generic;
13441344
this.is_in_const_generic = true;
13451345
walk_list!(this, visit_param_bound, param.bounds);
13461346
this.visit_ty(&ty);
1347+
if let Some(default) = default {
1348+
this.visit_body(this.tcx.hir().body(default.body));
1349+
}
13471350
this.is_in_const_generic = was_in_const_generic;
13481351
}
13491352
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
struct X<const N: usize = {
2+
(||1usize)()
3+
//~^ ERROR calls in constants are limited to
4+
}>;
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
2+
--> $DIR/issue-93647.rs:2:5
3+
|
4+
LL | (||1usize)()
5+
| ^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0015`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
struct Foo<
2+
'a,
3+
const N: usize = {
4+
let x: &'a ();
5+
//~^ ERROR use of non-static lifetime `'a` in const generic
6+
3
7+
},
8+
>(&'a ());
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0771]: use of non-static lifetime `'a` in const generic
2+
--> $DIR/outer-lifetime-in-const-generic-default.rs:4:17
3+
|
4+
LL | let x: &'a ();
5+
| ^^
6+
|
7+
= note: for more information, see issue #74052 <https://github.com/rust-lang/rust/issues/74052>
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0771`.

0 commit comments

Comments
 (0)