diff options
| author | Michael Goulet <michael@errs.io> | 2022-02-04 20:56:32 -0800 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2022-02-05 01:30:14 -0800 |
| commit | bcf98841d47b23dfc4cc85568fcd8dbb79748965 (patch) | |
| tree | b34122b9d04123892daf884b733c904067463b9a | |
| parent | b3800860e123443ffada615538926beed6bc4f85 (diff) | |
| download | rust-bcf98841d47b23dfc4cc85568fcd8dbb79748965.tar.gz rust-bcf98841d47b23dfc4cc85568fcd8dbb79748965.zip | |
resolve lifetimes for const generic defaults
5 files changed, 40 insertions, 1 deletions
diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index 6ef85c426be..f3d57139e08 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -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; } } diff --git a/src/test/ui/const-generics/issue-93647.rs b/src/test/ui/const-generics/issue-93647.rs new file mode 100644 index 00000000000..6a8fe64d187 --- /dev/null +++ b/src/test/ui/const-generics/issue-93647.rs @@ -0,0 +1,6 @@ +struct X<const N: usize = { + (||1usize)() + //~^ ERROR calls in constants are limited to +}>; + +fn main() {} diff --git a/src/test/ui/const-generics/issue-93647.stderr b/src/test/ui/const-generics/issue-93647.stderr new file mode 100644 index 00000000000..0fe54e7de41 --- /dev/null +++ b/src/test/ui/const-generics/issue-93647.stderr @@ -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`. diff --git a/src/test/ui/const-generics/outer-lifetime-in-const-generic-default.rs b/src/test/ui/const-generics/outer-lifetime-in-const-generic-default.rs new file mode 100644 index 00000000000..3018439afa7 --- /dev/null +++ b/src/test/ui/const-generics/outer-lifetime-in-const-generic-default.rs @@ -0,0 +1,10 @@ +struct Foo< + 'a, + const N: usize = { + let x: &'a (); + //~^ ERROR use of non-static lifetime `'a` in const generic + 3 + }, +>(&'a ()); + +fn main() {} diff --git a/src/test/ui/const-generics/outer-lifetime-in-const-generic-default.stderr b/src/test/ui/const-generics/outer-lifetime-in-const-generic-default.stderr new file mode 100644 index 00000000000..9d9555d3f64 --- /dev/null +++ b/src/test/ui/const-generics/outer-lifetime-in-const-generic-default.stderr @@ -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`. |
