mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Forbid elided lifetimes within const generic parameter types.
This commit is contained in:
parent
1389494ac1
commit
b4fddf0f08
@ -2121,12 +2121,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
|
||||
(hir::ParamName::Plain(param.ident), kind)
|
||||
}
|
||||
GenericParamKind::Const { ref ty } => (
|
||||
hir::ParamName::Plain(param.ident),
|
||||
hir::GenericParamKind::Const {
|
||||
ty: self.lower_ty(&ty, ImplTraitContext::disallowed()),
|
||||
},
|
||||
),
|
||||
GenericParamKind::Const { ref ty } => {
|
||||
let ty = self
|
||||
.with_anonymous_lifetime_mode(AnonymousLifetimeMode::ReportError, |this| {
|
||||
this.lower_ty(&ty, ImplTraitContext::disallowed())
|
||||
});
|
||||
|
||||
(hir::ParamName::Plain(param.ident), hir::GenericParamKind::Const { ty })
|
||||
}
|
||||
};
|
||||
|
||||
hir::GenericParam {
|
||||
|
19
src/test/ui/const-generics/const-param-elided-lifetime.rs
Normal file
19
src/test/ui/const-generics/const-param-elided-lifetime.rs
Normal file
@ -0,0 +1,19 @@
|
||||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||
|
||||
struct A<const N: &u8>;
|
||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||
trait B {}
|
||||
|
||||
impl<const N: &u8> A<N> { //~ ERROR `&` without an explicit lifetime name cannot be used here
|
||||
fn foo<const M: &u8>(&self) {}
|
||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||
}
|
||||
|
||||
impl<const N: &u8> B for A<N> {}
|
||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||
|
||||
fn bar<const N: &u8>() {}
|
||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,40 @@
|
||||
error[E0637]: `&` without an explicit lifetime name cannot be used here
|
||||
--> $DIR/const-param-elided-lifetime.rs:4:19
|
||||
|
|
||||
LL | struct A<const N: &u8>;
|
||||
| ^ explicit lifetime name needed here
|
||||
|
||||
error[E0637]: `&` without an explicit lifetime name cannot be used here
|
||||
--> $DIR/const-param-elided-lifetime.rs:8:15
|
||||
|
|
||||
LL | impl<const N: &u8> A<N> {
|
||||
| ^ explicit lifetime name needed here
|
||||
|
||||
error[E0637]: `&` without an explicit lifetime name cannot be used here
|
||||
--> $DIR/const-param-elided-lifetime.rs:9:21
|
||||
|
|
||||
LL | fn foo<const M: &u8>(&self) {}
|
||||
| ^ explicit lifetime name needed here
|
||||
|
||||
error[E0637]: `&` without an explicit lifetime name cannot be used here
|
||||
--> $DIR/const-param-elided-lifetime.rs:13:15
|
||||
|
|
||||
LL | impl<const N: &u8> B for A<N> {}
|
||||
| ^ explicit lifetime name needed here
|
||||
|
||||
error[E0637]: `&` without an explicit lifetime name cannot be used here
|
||||
--> $DIR/const-param-elided-lifetime.rs:16:17
|
||||
|
|
||||
LL | fn bar<const N: &u8>() {}
|
||||
| ^ explicit lifetime name needed here
|
||||
|
||||
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||
--> $DIR/const-param-elided-lifetime.rs:1:12
|
||||
|
|
||||
LL | #![feature(const_generics)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user