-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #68143 - skinny121:const-param-type-elided-lifetime, …
…r=petrochenkov Forbid elided lifetimes within const generic parameter types Disallows `fn foo<const T: &u32>()`, the lifetime must be explicitly given, i.e. `fn foo<const T: &'static u32>()`. Fixes #67883
- Loading branch information
Showing
3 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Elided lifetimes within the type of a const generic parameters is disallowed. This matches the | ||
// behaviour of trait bounds where `fn foo<T: Ord<&u8>>() {}` is illegal. Though we could change | ||
// elided lifetimes within the type of a const generic parameters to be 'static, like elided | ||
// lifetimes within const/static items. | ||
|
||
#![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() {} |
40 changes: 40 additions & 0 deletions
40
src/test/ui/const-generics/const-param-elided-lifetime.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
error[E0637]: `&` without an explicit lifetime name cannot be used here | ||
--> $DIR/const-param-elided-lifetime.rs:9: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:13: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:14: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:18: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:21: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:6:12 | ||
| | ||
LL | #![feature(const_generics)] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error: aborting due to 5 previous errors | ||
|