about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbohan <bohan-zhang@foxmail.com>2023-08-08 14:20:22 +0800
committerbohan <bohan-zhang@foxmail.com>2023-08-08 14:48:17 +0800
commit078b942fef1a8a699ae3a276d7d9695e46025f7e (patch)
tree1fda13312acbe004b93869adf04d87196a04c5c2
parent8e7fd551311d424e4e63fa45906a2a928fce96a7 (diff)
downloadrust-078b942fef1a8a699ae3a276d7d9695e46025f7e.tar.gz
rust-078b942fef1a8a699ae3a276d7d9695e46025f7e.zip
fix: not insert missing lifetime for `ConstParamTy`
-rw-r--r--compiler/rustc_resolve/src/late/diagnostics.rs6
-rw-r--r--tests/ui/const-generics/lifetime-in-const-param.rs9
-rw-r--r--tests/ui/const-generics/lifetime-in-const-param.stderr18
-rw-r--r--tests/ui/lifetimes/unusual-rib-combinations.stderr5
4 files changed, 31 insertions, 7 deletions
diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs
index ba9bbbb1463..c34b7df9b46 100644
--- a/compiler/rustc_resolve/src/late/diagnostics.rs
+++ b/compiler/rustc_resolve/src/late/diagnostics.rs
@@ -2404,7 +2404,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
                         should_continue = suggest(err, false, span, message, sugg);
                     }
                 }
-                LifetimeRibKind::Item => break,
+                LifetimeRibKind::Item | LifetimeRibKind::ConstParamTy => break,
                 _ => {}
             }
             if !should_continue {
@@ -2510,7 +2510,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
             .lifetime_ribs
             .iter()
             .rev()
-            .take_while(|rib| !matches!(rib.kind, LifetimeRibKind::Item))
+            .take_while(|rib| {
+                !matches!(rib.kind, LifetimeRibKind::Item | LifetimeRibKind::ConstParamTy)
+            })
             .flat_map(|rib| rib.bindings.iter())
             .map(|(&ident, &res)| (ident, res))
             .filter(|(ident, _)| ident.name != kw::UnderscoreLifetime)
diff --git a/tests/ui/const-generics/lifetime-in-const-param.rs b/tests/ui/const-generics/lifetime-in-const-param.rs
new file mode 100644
index 00000000000..be90dbb213e
--- /dev/null
+++ b/tests/ui/const-generics/lifetime-in-const-param.rs
@@ -0,0 +1,9 @@
+// https://github.com/rust-lang/rust/issues/113462
+
+struct S2<'b>(&'b ());
+
+struct S<'a, const N: S2>(&'a ());
+//~^ ERROR missing lifetime specifier [E0106]
+//~| ERROR `S2<'_>` is forbidden as the type of a const generic parameter
+
+fn main() {}
diff --git a/tests/ui/const-generics/lifetime-in-const-param.stderr b/tests/ui/const-generics/lifetime-in-const-param.stderr
new file mode 100644
index 00000000000..8fd9068e8ef
--- /dev/null
+++ b/tests/ui/const-generics/lifetime-in-const-param.stderr
@@ -0,0 +1,18 @@
+error[E0106]: missing lifetime specifier
+  --> $DIR/lifetime-in-const-param.rs:5:23
+   |
+LL | struct S<'a, const N: S2>(&'a ());
+   |                       ^^ expected named lifetime parameter
+
+error: `S2<'_>` is forbidden as the type of a const generic parameter
+  --> $DIR/lifetime-in-const-param.rs:5:23
+   |
+LL | struct S<'a, const N: S2>(&'a ());
+   |                       ^^
+   |
+   = note: the only supported types are integers, `bool` and `char`
+   = help: more complex types are supported with `#![feature(adt_const_params)]`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0106`.
diff --git a/tests/ui/lifetimes/unusual-rib-combinations.stderr b/tests/ui/lifetimes/unusual-rib-combinations.stderr
index 4994e4dc444..01ec69a6110 100644
--- a/tests/ui/lifetimes/unusual-rib-combinations.stderr
+++ b/tests/ui/lifetimes/unusual-rib-combinations.stderr
@@ -3,11 +3,6 @@ error[E0106]: missing lifetime specifier
    |
 LL | fn d<const C: S>() {}
    |               ^ expected named lifetime parameter
-   |
-help: consider introducing a named lifetime parameter
-   |
-LL | fn d<'a, const C: S<'a>>() {}
-   |      +++           ++++
 
 error[E0770]: the type of const parameters must not depend on other generic parameters
   --> $DIR/unusual-rib-combinations.rs:29:22