forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
disallow non-static lifetimes in const generics
This has been put in place to patch over an ICE caused when we encounter a non-static lifetime in a const generic during borrow checking. This restriction may be relaxed in the future, but we need more discussion before then, and in the meantime we should still deal with this ICE. Fixes issue rust-lang#60814
- Loading branch information
1 parent
4803680
commit 69d5dd6
Showing
6 changed files
with
81 additions
and
0 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,23 @@ | ||
A non-`'static` lifetime was used in a const generic. This is currently not | ||
allowed. | ||
|
||
Erroneous code example: | ||
|
||
```compile_fail,E0771 | ||
#![feature(const_generics)] | ||
fn function_with_str<'a, const STRING: &'a str>() {} // error! | ||
``` | ||
|
||
To fix this issue, the lifetime in the const generic need to be changed to | ||
`'static`: | ||
|
||
``` | ||
#![feature(const_generics)] | ||
fn function_with_str<const STRING: &'static str>() {} // ok! | ||
``` | ||
|
||
For more information, see [GitHub issue #74052]. | ||
|
||
[GitHub issue #74052]: https://github.com/rust-lang/rust/issues/74052 |
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
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,8 @@ | ||
#![feature(const_generics)] | ||
//~^ WARN the feature `const_generics` is incomplete | ||
|
||
fn function_with_str<'a, const STRING: &'a str>() {} //~ ERROR E0771 | ||
|
||
fn main() { | ||
function_with_str::<"Hello, world!">() | ||
} |
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,20 @@ | ||
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/E0771.rs:1:12 | ||
| | ||
LL | #![feature(const_generics)] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
|
||
error[E0771]: use of non-static lifetime `'a` in const generic | ||
--> $DIR/E0771.rs:4:41 | ||
| | ||
LL | fn function_with_str<'a, const STRING: &'a str>() {} | ||
| ^^ | ||
| | ||
= note: for more information, see issue #74052 <https://github.com/rust-lang/rust/issues/74052> | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0771`. |