Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,9 +1269,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
GenericArg::Type(self.lower_ty_alloc(ty, itctx).try_as_ambig_ty().unwrap())
}
ast::GenericArg::Const(ct) => GenericArg::Const(
self.lower_anon_const_to_const_arg_and_alloc(ct).try_as_ambig_ct().unwrap(),
),
ast::GenericArg::Const(ct) => {
let ct = self.lower_anon_const_to_const_arg_and_alloc(ct);
match ct.try_as_ambig_ct() {
Some(ct) => GenericArg::Const(ct),
None => GenericArg::Infer(hir::InferArg { hir_id: ct.hir_id, span: ct.span }),
}
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions tests/ui/const-generics/mgca/braced-const-infer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! Regression test for https://github.com/rust-lang/rust/issues/153198
#![feature(min_generic_const_args)]
#![allow(incomplete_features, rust_2021_compatibility)]

trait Trait<T> {}

impl dyn Trait<{_}> {} //~ ERROR: the placeholder `_` is not allowed within types on item signatures

fn main() {}
9 changes: 9 additions & 0 deletions tests/ui/const-generics/mgca/braced-const-infer.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0121]: the placeholder `_` is not allowed within types on item signatures for implementations
--> $DIR/braced-const-infer.rs:7:17
|
LL | impl dyn Trait<{_}> {}
| ^ not allowed in type signatures

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0121`.
20 changes: 20 additions & 0 deletions tests/ui/const-generics/mgca/macro-const-arg-infer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Regression test for https://github.com/rust-lang/rust/issues/153198
#![feature(min_generic_const_args)]
#![allow(incomplete_features)]
macro_rules! y {
( $($matcher:tt)*) => {
_ //~ ERROR: the placeholder `_` is not allowed within types on item signatures
};
}

struct A<T>; //~ ERROR: type parameter `T` is never used

const y: A<
{
y! {
x
}
},
> = 1; //~ ERROR: mismatched types

fn main() {}
44 changes: 44 additions & 0 deletions tests/ui/const-generics/mgca/macro-const-arg-infer.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
error[E0392]: type parameter `T` is never used
--> $DIR/macro-const-arg-infer.rs:10:10
|
LL | struct A<T>;
| ^ unused type parameter
|
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
= help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead

error[E0308]: mismatched types
--> $DIR/macro-const-arg-infer.rs:18:5
|
LL | const y: A<
| __________-
LL | | {
LL | | y! {
LL | | x
LL | | }
LL | | },
LL | | > = 1;
| | - ^ expected `A<_>`, found integer
| |_|
| expected because of the type of the constant
|
= note: expected struct `A<_>`
found type `{integer}`

error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
--> $DIR/macro-const-arg-infer.rs:6:9
|
LL | _
| ^ not allowed in type signatures
...
LL | / y! {
LL | | x
LL | | }
| |_________- in this macro invocation
|
= note: this error originates in the macro `y` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0121, E0308, E0392.
For more information about an error, try `rustc --explain E0121`.
Loading