Skip to content

Commit a30b28e

Browse files
committed
try referencing outer params
1 parent 19a3fe6 commit a30b28e

File tree

2 files changed

+247
-0
lines changed

2 files changed

+247
-0
lines changed
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
error: generic parameters may not be used in const operations
2+
--> $DIR/const-arg-in-const-arg.rs:14:23
3+
|
4+
LL | let _: [u8; foo::<T>()];
5+
| ^ cannot perform const operation using `T`
6+
|
7+
= note: type parameters may not be used in const expressions
8+
9+
error: generic parameters may not be used in const operations
10+
--> $DIR/const-arg-in-const-arg.rs:15:23
11+
|
12+
LL | let _: [u8; bar::<N>()];
13+
| ^ cannot perform const operation using `N`
14+
|
15+
= help: const parameters may only be used as standalone arguments, i.e. `N`
16+
17+
error: generic parameters may not be used in const operations
18+
--> $DIR/const-arg-in-const-arg.rs:25:23
19+
|
20+
LL | let _ = [0; bar::<N>()];
21+
| ^ cannot perform const operation using `N`
22+
|
23+
= help: const parameters may only be used as standalone arguments, i.e. `N`
24+
25+
error: generic parameters may not be used in const operations
26+
--> $DIR/const-arg-in-const-arg.rs:30:24
27+
|
28+
LL | let _: Foo<{ foo::<T>() }>;
29+
| ^ cannot perform const operation using `T`
30+
|
31+
= note: type parameters may not be used in const expressions
32+
33+
error: generic parameters may not be used in const operations
34+
--> $DIR/const-arg-in-const-arg.rs:31:24
35+
|
36+
LL | let _: Foo<{ bar::<N>() }>;
37+
| ^ cannot perform const operation using `N`
38+
|
39+
= help: const parameters may only be used as standalone arguments, i.e. `N`
40+
41+
error: generic parameters may not be used in const operations
42+
--> $DIR/const-arg-in-const-arg.rs:36:27
43+
|
44+
LL | let _ = Foo::<{ foo::<T>() }>;
45+
| ^ cannot perform const operation using `T`
46+
|
47+
= note: type parameters may not be used in const expressions
48+
49+
error: generic parameters may not be used in const operations
50+
--> $DIR/const-arg-in-const-arg.rs:37:27
51+
|
52+
LL | let _ = Foo::<{ bar::<N>() }>;
53+
| ^ cannot perform const operation using `N`
54+
|
55+
= help: const parameters may only be used as standalone arguments, i.e. `N`
56+
57+
error[E0658]: a non-static lifetime is not allowed in a `const`
58+
--> $DIR/const-arg-in-const-arg.rs:16:23
59+
|
60+
LL | let _: [u8; faz::<'a>(&())];
61+
| ^^
62+
|
63+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
64+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
65+
66+
error[E0658]: a non-static lifetime is not allowed in a `const`
67+
--> $DIR/const-arg-in-const-arg.rs:17:23
68+
|
69+
LL | let _: [u8; baz::<'a>(&())];
70+
| ^^
71+
|
72+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
73+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
74+
75+
error[E0658]: a non-static lifetime is not allowed in a `const`
76+
--> $DIR/const-arg-in-const-arg.rs:18:23
77+
|
78+
LL | let _: [u8; faz::<'b>(&())];
79+
| ^^
80+
|
81+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
82+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
83+
84+
error[E0658]: a non-static lifetime is not allowed in a `const`
85+
--> $DIR/const-arg-in-const-arg.rs:19:23
86+
|
87+
LL | let _: [u8; baz::<'b>(&())];
88+
| ^^
89+
|
90+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
91+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
92+
93+
error[E0658]: a non-static lifetime is not allowed in a `const`
94+
--> $DIR/const-arg-in-const-arg.rs:26:23
95+
|
96+
LL | let _ = [0; faz::<'a>(&())];
97+
| ^^
98+
|
99+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
100+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
101+
102+
error[E0658]: a non-static lifetime is not allowed in a `const`
103+
--> $DIR/const-arg-in-const-arg.rs:27:23
104+
|
105+
LL | let _ = [0; baz::<'a>(&())];
106+
| ^^
107+
|
108+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
109+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
110+
111+
error[E0658]: a non-static lifetime is not allowed in a `const`
112+
--> $DIR/const-arg-in-const-arg.rs:28:23
113+
|
114+
LL | let _ = [0; faz::<'b>(&())];
115+
| ^^
116+
|
117+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
118+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
119+
120+
error[E0658]: a non-static lifetime is not allowed in a `const`
121+
--> $DIR/const-arg-in-const-arg.rs:29:23
122+
|
123+
LL | let _ = [0; baz::<'b>(&())];
124+
| ^^
125+
|
126+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
127+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
128+
129+
error[E0658]: a non-static lifetime is not allowed in a `const`
130+
--> $DIR/const-arg-in-const-arg.rs:32:24
131+
|
132+
LL | let _: Foo<{ faz::<'a>(&()) }>;
133+
| ^^
134+
|
135+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
136+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
137+
138+
error[E0658]: a non-static lifetime is not allowed in a `const`
139+
--> $DIR/const-arg-in-const-arg.rs:33:24
140+
|
141+
LL | let _: Foo<{ baz::<'a>(&()) }>;
142+
| ^^
143+
|
144+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
145+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
146+
147+
error[E0658]: a non-static lifetime is not allowed in a `const`
148+
--> $DIR/const-arg-in-const-arg.rs:34:24
149+
|
150+
LL | let _: Foo<{ faz::<'b>(&()) }>;
151+
| ^^
152+
|
153+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
154+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
155+
156+
error[E0658]: a non-static lifetime is not allowed in a `const`
157+
--> $DIR/const-arg-in-const-arg.rs:35:24
158+
|
159+
LL | let _: Foo<{ baz::<'b>(&()) }>;
160+
| ^^
161+
|
162+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
163+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
164+
165+
error[E0658]: a non-static lifetime is not allowed in a `const`
166+
--> $DIR/const-arg-in-const-arg.rs:38:27
167+
|
168+
LL | let _ = Foo::<{ faz::<'a>(&()) }>;
169+
| ^^
170+
|
171+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
172+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
173+
174+
error[E0658]: a non-static lifetime is not allowed in a `const`
175+
--> $DIR/const-arg-in-const-arg.rs:39:27
176+
|
177+
LL | let _ = Foo::<{ baz::<'a>(&()) }>;
178+
| ^^
179+
|
180+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
181+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
182+
183+
error[E0658]: a non-static lifetime is not allowed in a `const`
184+
--> $DIR/const-arg-in-const-arg.rs:40:27
185+
|
186+
LL | let _ = Foo::<{ faz::<'b>(&()) }>;
187+
| ^^
188+
|
189+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
190+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
191+
192+
error[E0658]: a non-static lifetime is not allowed in a `const`
193+
--> $DIR/const-arg-in-const-arg.rs:41:27
194+
|
195+
LL | let _ = Foo::<{ baz::<'b>(&()) }>;
196+
| ^^
197+
|
198+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
199+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
200+
201+
error: aborting due to 23 previous errors
202+
203+
For more information about this error, try `rustc --explain E0658`.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// revisions: min
2+
// FIXME(const_generics): This test currently causes an ICE because
3+
// we don't yet correctly deal with lifetimes, reenable this test once
4+
// this is fixed.
5+
#![cfg_attr(min, feature(min_const_generics))]
6+
7+
const fn foo<T>() -> usize { std::mem::size_of::<T>() }
8+
const fn bar<const N: usize>() -> usize { N }
9+
const fn faz<'a>(_: &'a ()) -> usize { 13 }
10+
const fn baz<'a>(_: &'a ()) -> usize where &'a (): Sized { 13 }
11+
12+
struct Foo<const N: usize>;
13+
fn test<'a, 'b, T, const N: usize>() where &'b (): Sized {
14+
let _: [u8; foo::<T>()]; //~ ERROR generic parameters may not
15+
let _: [u8; bar::<N>()]; //~ ERROR generic parameters may not
16+
let _: [u8; faz::<'a>(&())]; //~ ERROR a non-static lifetime
17+
let _: [u8; baz::<'a>(&())]; //~ ERROR a non-static lifetime
18+
let _: [u8; faz::<'b>(&())]; //~ ERROR a non-static lifetime
19+
let _: [u8; baz::<'b>(&())]; //~ ERROR a non-static lifetime
20+
21+
// NOTE: This can be a future compat warning instead of an error,
22+
// so we stop compilation before emitting this error in this test.
23+
let _ = [0; foo::<T>()];
24+
25+
let _ = [0; bar::<N>()]; //~ ERROR generic parameters may not
26+
let _ = [0; faz::<'a>(&())]; //~ ERROR a non-static lifetime
27+
let _ = [0; baz::<'a>(&())]; //~ ERROR a non-static lifetime
28+
let _ = [0; faz::<'b>(&())]; //~ ERROR a non-static lifetime
29+
let _ = [0; baz::<'b>(&())]; //~ ERROR a non-static lifetime
30+
let _: Foo<{ foo::<T>() }>; //~ ERROR generic parameters may not
31+
let _: Foo<{ bar::<N>() }>; //~ ERROR generic parameters may not
32+
let _: Foo<{ faz::<'a>(&()) }>; //~ ERROR a non-static lifetime
33+
let _: Foo<{ baz::<'a>(&()) }>; //~ ERROR a non-static lifetime
34+
let _: Foo<{ faz::<'b>(&()) }>; //~ ERROR a non-static lifetime
35+
let _: Foo<{ baz::<'b>(&()) }>; //~ ERROR a non-static lifetime
36+
let _ = Foo::<{ foo::<T>() }>; //~ ERROR generic parameters may not
37+
let _ = Foo::<{ bar::<N>() }>; //~ ERROR generic parameters may not
38+
let _ = Foo::<{ faz::<'a>(&()) }>; //~ ERROR a non-static lifetime
39+
let _ = Foo::<{ baz::<'a>(&()) }>; //~ ERROR a non-static lifetime
40+
let _ = Foo::<{ faz::<'b>(&()) }>; //~ ERROR a non-static lifetime
41+
let _ = Foo::<{ baz::<'b>(&()) }>; //~ ERROR a non-static lifetime
42+
}
43+
44+
fn main() {}

0 commit comments

Comments
 (0)