-
Notifications
You must be signed in to change notification settings - Fork 13.3k
extend const generics test suite #78916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,126
−0
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d76cdb0
const param macro test
lcnr 359031e
add generic param mismatch test
lcnr dd78188
add macro_rules test regarding braces
lcnr a8310e2
add associated type bounds test
lcnr 19a3fe6
exhaustively enumerate all values of a const param
lcnr a30b28e
try referencing outer params
lcnr de1ebbb
const param in async
lcnr 4b5cd04
add test for where clauses mentioning const params
lcnr f4790ec
add cross crate test
lcnr 7d9f815
add rustdoc test
lcnr a9eacf3
add error-in-impl-trait const generics test
lcnr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
try referencing outer params
- Loading branch information
commit a30b28e8932f8eb2931d1a41bc9271961e90f1cb
There are no files selected for viewing
203 changes: 203 additions & 0 deletions
203
src/test/ui/const-generics/const-arg-in-const-arg.min.stderr
This file contains hidden or 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,203 @@ | ||
error: generic parameters may not be used in const operations | ||
--> $DIR/const-arg-in-const-arg.rs:14:23 | ||
| | ||
LL | let _: [u8; foo::<T>()]; | ||
| ^ cannot perform const operation using `T` | ||
| | ||
= note: type parameters may not be used in const expressions | ||
|
||
error: generic parameters may not be used in const operations | ||
--> $DIR/const-arg-in-const-arg.rs:15:23 | ||
| | ||
LL | let _: [u8; bar::<N>()]; | ||
| ^ cannot perform const operation using `N` | ||
| | ||
= help: const parameters may only be used as standalone arguments, i.e. `N` | ||
|
||
error: generic parameters may not be used in const operations | ||
--> $DIR/const-arg-in-const-arg.rs:25:23 | ||
| | ||
LL | let _ = [0; bar::<N>()]; | ||
| ^ cannot perform const operation using `N` | ||
| | ||
= help: const parameters may only be used as standalone arguments, i.e. `N` | ||
|
||
error: generic parameters may not be used in const operations | ||
--> $DIR/const-arg-in-const-arg.rs:30:24 | ||
| | ||
LL | let _: Foo<{ foo::<T>() }>; | ||
| ^ cannot perform const operation using `T` | ||
| | ||
= note: type parameters may not be used in const expressions | ||
|
||
error: generic parameters may not be used in const operations | ||
--> $DIR/const-arg-in-const-arg.rs:31:24 | ||
| | ||
LL | let _: Foo<{ bar::<N>() }>; | ||
| ^ cannot perform const operation using `N` | ||
| | ||
= help: const parameters may only be used as standalone arguments, i.e. `N` | ||
|
||
error: generic parameters may not be used in const operations | ||
--> $DIR/const-arg-in-const-arg.rs:36:27 | ||
| | ||
LL | let _ = Foo::<{ foo::<T>() }>; | ||
| ^ cannot perform const operation using `T` | ||
| | ||
= note: type parameters may not be used in const expressions | ||
|
||
error: generic parameters may not be used in const operations | ||
--> $DIR/const-arg-in-const-arg.rs:37:27 | ||
| | ||
LL | let _ = Foo::<{ bar::<N>() }>; | ||
| ^ cannot perform const operation using `N` | ||
| | ||
= help: const parameters may only be used as standalone arguments, i.e. `N` | ||
|
||
error[E0658]: a non-static lifetime is not allowed in a `const` | ||
--> $DIR/const-arg-in-const-arg.rs:16:23 | ||
| | ||
LL | let _: [u8; faz::<'a>(&())]; | ||
| ^^ | ||
| | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
= help: add `#![feature(const_generics)]` to the crate attributes to enable | ||
|
||
error[E0658]: a non-static lifetime is not allowed in a `const` | ||
--> $DIR/const-arg-in-const-arg.rs:17:23 | ||
| | ||
LL | let _: [u8; baz::<'a>(&())]; | ||
| ^^ | ||
| | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
= help: add `#![feature(const_generics)]` to the crate attributes to enable | ||
|
||
error[E0658]: a non-static lifetime is not allowed in a `const` | ||
--> $DIR/const-arg-in-const-arg.rs:18:23 | ||
| | ||
LL | let _: [u8; faz::<'b>(&())]; | ||
| ^^ | ||
| | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
= help: add `#![feature(const_generics)]` to the crate attributes to enable | ||
|
||
error[E0658]: a non-static lifetime is not allowed in a `const` | ||
--> $DIR/const-arg-in-const-arg.rs:19:23 | ||
| | ||
LL | let _: [u8; baz::<'b>(&())]; | ||
| ^^ | ||
| | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
= help: add `#![feature(const_generics)]` to the crate attributes to enable | ||
|
||
error[E0658]: a non-static lifetime is not allowed in a `const` | ||
--> $DIR/const-arg-in-const-arg.rs:26:23 | ||
| | ||
LL | let _ = [0; faz::<'a>(&())]; | ||
| ^^ | ||
| | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
= help: add `#![feature(const_generics)]` to the crate attributes to enable | ||
|
||
error[E0658]: a non-static lifetime is not allowed in a `const` | ||
--> $DIR/const-arg-in-const-arg.rs:27:23 | ||
| | ||
LL | let _ = [0; baz::<'a>(&())]; | ||
| ^^ | ||
| | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
= help: add `#![feature(const_generics)]` to the crate attributes to enable | ||
|
||
error[E0658]: a non-static lifetime is not allowed in a `const` | ||
--> $DIR/const-arg-in-const-arg.rs:28:23 | ||
| | ||
LL | let _ = [0; faz::<'b>(&())]; | ||
| ^^ | ||
| | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
= help: add `#![feature(const_generics)]` to the crate attributes to enable | ||
|
||
error[E0658]: a non-static lifetime is not allowed in a `const` | ||
--> $DIR/const-arg-in-const-arg.rs:29:23 | ||
| | ||
LL | let _ = [0; baz::<'b>(&())]; | ||
| ^^ | ||
| | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
= help: add `#![feature(const_generics)]` to the crate attributes to enable | ||
|
||
error[E0658]: a non-static lifetime is not allowed in a `const` | ||
--> $DIR/const-arg-in-const-arg.rs:32:24 | ||
| | ||
LL | let _: Foo<{ faz::<'a>(&()) }>; | ||
| ^^ | ||
| | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
= help: add `#![feature(const_generics)]` to the crate attributes to enable | ||
|
||
error[E0658]: a non-static lifetime is not allowed in a `const` | ||
--> $DIR/const-arg-in-const-arg.rs:33:24 | ||
| | ||
LL | let _: Foo<{ baz::<'a>(&()) }>; | ||
| ^^ | ||
| | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
= help: add `#![feature(const_generics)]` to the crate attributes to enable | ||
|
||
error[E0658]: a non-static lifetime is not allowed in a `const` | ||
--> $DIR/const-arg-in-const-arg.rs:34:24 | ||
| | ||
LL | let _: Foo<{ faz::<'b>(&()) }>; | ||
| ^^ | ||
| | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
= help: add `#![feature(const_generics)]` to the crate attributes to enable | ||
|
||
error[E0658]: a non-static lifetime is not allowed in a `const` | ||
--> $DIR/const-arg-in-const-arg.rs:35:24 | ||
| | ||
LL | let _: Foo<{ baz::<'b>(&()) }>; | ||
| ^^ | ||
| | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
= help: add `#![feature(const_generics)]` to the crate attributes to enable | ||
|
||
error[E0658]: a non-static lifetime is not allowed in a `const` | ||
--> $DIR/const-arg-in-const-arg.rs:38:27 | ||
| | ||
LL | let _ = Foo::<{ faz::<'a>(&()) }>; | ||
| ^^ | ||
| | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
= help: add `#![feature(const_generics)]` to the crate attributes to enable | ||
|
||
error[E0658]: a non-static lifetime is not allowed in a `const` | ||
--> $DIR/const-arg-in-const-arg.rs:39:27 | ||
| | ||
LL | let _ = Foo::<{ baz::<'a>(&()) }>; | ||
| ^^ | ||
| | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
= help: add `#![feature(const_generics)]` to the crate attributes to enable | ||
|
||
error[E0658]: a non-static lifetime is not allowed in a `const` | ||
--> $DIR/const-arg-in-const-arg.rs:40:27 | ||
| | ||
LL | let _ = Foo::<{ faz::<'b>(&()) }>; | ||
| ^^ | ||
| | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
= help: add `#![feature(const_generics)]` to the crate attributes to enable | ||
|
||
error[E0658]: a non-static lifetime is not allowed in a `const` | ||
--> $DIR/const-arg-in-const-arg.rs:41:27 | ||
| | ||
LL | let _ = Foo::<{ baz::<'b>(&()) }>; | ||
| ^^ | ||
| | ||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information | ||
= help: add `#![feature(const_generics)]` to the crate attributes to enable | ||
|
||
error: aborting due to 23 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
This file contains hidden or 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,44 @@ | ||
// revisions: min | ||
// FIXME(const_generics): This test currently causes an ICE because | ||
// we don't yet correctly deal with lifetimes, reenable this test once | ||
// this is fixed. | ||
#![cfg_attr(min, feature(min_const_generics))] | ||
|
||
const fn foo<T>() -> usize { std::mem::size_of::<T>() } | ||
const fn bar<const N: usize>() -> usize { N } | ||
const fn faz<'a>(_: &'a ()) -> usize { 13 } | ||
const fn baz<'a>(_: &'a ()) -> usize where &'a (): Sized { 13 } | ||
|
||
struct Foo<const N: usize>; | ||
fn test<'a, 'b, T, const N: usize>() where &'b (): Sized { | ||
let _: [u8; foo::<T>()]; //~ ERROR generic parameters may not | ||
let _: [u8; bar::<N>()]; //~ ERROR generic parameters may not | ||
let _: [u8; faz::<'a>(&())]; //~ ERROR a non-static lifetime | ||
let _: [u8; baz::<'a>(&())]; //~ ERROR a non-static lifetime | ||
let _: [u8; faz::<'b>(&())]; //~ ERROR a non-static lifetime | ||
let _: [u8; baz::<'b>(&())]; //~ ERROR a non-static lifetime | ||
|
||
// NOTE: This can be a future compat warning instead of an error, | ||
// so we stop compilation before emitting this error in this test. | ||
let _ = [0; foo::<T>()]; | ||
|
||
let _ = [0; bar::<N>()]; //~ ERROR generic parameters may not | ||
let _ = [0; faz::<'a>(&())]; //~ ERROR a non-static lifetime | ||
let _ = [0; baz::<'a>(&())]; //~ ERROR a non-static lifetime | ||
let _ = [0; faz::<'b>(&())]; //~ ERROR a non-static lifetime | ||
let _ = [0; baz::<'b>(&())]; //~ ERROR a non-static lifetime | ||
let _: Foo<{ foo::<T>() }>; //~ ERROR generic parameters may not | ||
let _: Foo<{ bar::<N>() }>; //~ ERROR generic parameters may not | ||
let _: Foo<{ faz::<'a>(&()) }>; //~ ERROR a non-static lifetime | ||
let _: Foo<{ baz::<'a>(&()) }>; //~ ERROR a non-static lifetime | ||
let _: Foo<{ faz::<'b>(&()) }>; //~ ERROR a non-static lifetime | ||
let _: Foo<{ baz::<'b>(&()) }>; //~ ERROR a non-static lifetime | ||
let _ = Foo::<{ foo::<T>() }>; //~ ERROR generic parameters may not | ||
let _ = Foo::<{ bar::<N>() }>; //~ ERROR generic parameters may not | ||
let _ = Foo::<{ faz::<'a>(&()) }>; //~ ERROR a non-static lifetime | ||
let _ = Foo::<{ baz::<'a>(&()) }>; //~ ERROR a non-static lifetime | ||
let _ = Foo::<{ faz::<'b>(&()) }>; //~ ERROR a non-static lifetime | ||
let _ = Foo::<{ baz::<'b>(&()) }>; //~ ERROR a non-static lifetime | ||
} | ||
|
||
fn main() {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this causes both the github and the vs code code highligher to break, what would be a good way to notify the relevant people here?
I personally don't think that this is blocking though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub and Atom use https://github.com/zargony/atom-language-rust. VS Code's Rust syntax is here It would be good to also check how it looks in CodeMirror.