Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve lifetimes for const generic defaults #93669

Merged
merged 1 commit into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/rustc_resolve/src/late/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1339,11 +1339,14 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
this.visit_ty(&ty);
}
}
GenericParamKind::Const { ref ty, .. } => {
GenericParamKind::Const { ref ty, default } => {
let was_in_const_generic = this.is_in_const_generic;
this.is_in_const_generic = true;
walk_list!(this, visit_param_bound, param.bounds);
this.visit_ty(&ty);
if let Some(default) = default {
this.visit_body(this.tcx.hir().body(default.body));
}
this.is_in_const_generic = was_in_const_generic;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/const-generics/issue-93647.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
struct X<const N: usize = {
(||1usize)()
//~^ ERROR calls in constants are limited to
}>;

fn main() {}
9 changes: 9 additions & 0 deletions src/test/ui/const-generics/issue-93647.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> $DIR/issue-93647.rs:2:5
|
LL | (||1usize)()
| ^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0015`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
struct Foo<
'a,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha rustfmt is so weird, i swear i didn't do this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^

const N: usize = {
let x: &'a ();
//~^ ERROR use of non-static lifetime `'a` in const generic
3
},
>(&'a ());

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0771]: use of non-static lifetime `'a` in const generic
--> $DIR/outer-lifetime-in-const-generic-default.rs:4:17
|
LL | let x: &'a ();
| ^^
|
= note: for more information, see issue #74052 <https://github.com/rust-lang/rust/issues/74052>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0771`.