Skip to content

Commit dfba606

Browse files
Rollup merge of rust-lang#153987 - reddevilmidzy:mgca-ast, r=BoxyUwU
mGCA: Lower const generic args to infer when needed close: rust-lang#153198 r? BoxyUwU
2 parents db7db62 + 924374c commit dfba606

File tree

5 files changed

+89
-3
lines changed

5 files changed

+89
-3
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,9 +1310,13 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
13101310
}
13111311
GenericArg::Type(self.lower_ty_alloc(ty, itctx).try_as_ambig_ty().unwrap())
13121312
}
1313-
ast::GenericArg::Const(ct) => GenericArg::Const(
1314-
self.lower_anon_const_to_const_arg_and_alloc(ct).try_as_ambig_ct().unwrap(),
1315-
),
1313+
ast::GenericArg::Const(ct) => {
1314+
let ct = self.lower_anon_const_to_const_arg_and_alloc(ct);
1315+
match ct.try_as_ambig_ct() {
1316+
Some(ct) => GenericArg::Const(ct),
1317+
None => GenericArg::Infer(hir::InferArg { hir_id: ct.hir_id, span: ct.span }),
1318+
}
1319+
}
13161320
}
13171321
}
13181322

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//! Regression test for https://github.com/rust-lang/rust/issues/153198
2+
#![feature(min_generic_const_args)]
3+
#![allow(incomplete_features, rust_2021_compatibility)]
4+
5+
trait Trait<T> {}
6+
7+
impl dyn Trait<{_}> {} //~ ERROR: the placeholder `_` is not allowed within types on item signatures
8+
9+
fn main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for implementations
2+
--> $DIR/braced-const-infer.rs:7:17
3+
|
4+
LL | impl dyn Trait<{_}> {}
5+
| ^ not allowed in type signatures
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0121`.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Regression test for https://github.com/rust-lang/rust/issues/153198
2+
#![feature(min_generic_const_args)]
3+
#![allow(incomplete_features)]
4+
macro_rules! y {
5+
( $($matcher:tt)*) => {
6+
_ //~ ERROR: the placeholder `_` is not allowed within types on item signatures
7+
};
8+
}
9+
10+
struct A<T>; //~ ERROR: type parameter `T` is never used
11+
12+
const y: A<
13+
{
14+
y! {
15+
x
16+
}
17+
},
18+
> = 1; //~ ERROR: mismatched types
19+
20+
fn main() {}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
error[E0392]: type parameter `T` is never used
2+
--> $DIR/macro-const-arg-infer.rs:10:10
3+
|
4+
LL | struct A<T>;
5+
| ^ unused type parameter
6+
|
7+
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
8+
= help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead
9+
10+
error[E0308]: mismatched types
11+
--> $DIR/macro-const-arg-infer.rs:18:5
12+
|
13+
LL | const y: A<
14+
| __________-
15+
LL | | {
16+
LL | | y! {
17+
LL | | x
18+
LL | | }
19+
LL | | },
20+
LL | | > = 1;
21+
| | - ^ expected `A<_>`, found integer
22+
| |_|
23+
| expected because of the type of the constant
24+
|
25+
= note: expected struct `A<_>`
26+
found type `{integer}`
27+
28+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
29+
--> $DIR/macro-const-arg-infer.rs:6:9
30+
|
31+
LL | _
32+
| ^ not allowed in type signatures
33+
...
34+
LL | / y! {
35+
LL | | x
36+
LL | | }
37+
| |_________- in this macro invocation
38+
|
39+
= note: this error originates in the macro `y` (in Nightly builds, run with -Z macro-backtrace for more info)
40+
41+
error: aborting due to 3 previous errors
42+
43+
Some errors have detailed explanations: E0121, E0308, E0392.
44+
For more information about an error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)