Skip to content

Commit a68864b

Browse files
committed
Auto merge of #79734 - ethanboxx:inferred_const_note, r=varkor
Const parameters can not be inferred with `_` help note This should close: #79557 # Example output ``` error[E0747]: type provided when a constant was expected --> inferred_const_note.rs:6:19 | 6 | let a = foo::<_, 2>([0, 1, 2]); | ^ | = help: Const parameters can not be inferred with `_` error: aborting due to previous error For more information about this error, try `rustc --explain E0747`. ``` r? `@lcnr`
2 parents 5957f20 + 6845e22 commit a68864b

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

compiler/rustc_typeck/src/astconv/generics.rs

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
4444
// the match is non-exhaustive.
4545
_ => bug!("invalid generic parameter kind {}", kind),
4646
};
47+
48+
if let ParamKindOrd::Const { .. } = kind_ord {
49+
if let GenericArg::Type(hir::Ty { kind: hir::TyKind::Infer, .. }) = arg {
50+
err.help("const arguments cannot yet be inferred with `_`");
51+
}
52+
}
53+
4754
let arg_ord = match arg {
4855
GenericArg::Lifetime(_) => ParamKindOrd::Lifetime,
4956
GenericArg::Type(_) => ParamKindOrd::Type,

src/test/ui/const-generics/issues/issue-62878.full.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ error[E0747]: type provided when a constant was expected
99
|
1010
LL | foo::<_, {[1]}>();
1111
| ^
12+
|
13+
= help: const arguments cannot yet be inferred with `_`
1214

1315
error[E0308]: mismatched types
1416
--> $DIR/issue-62878.rs:11:15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(min_const_generics)]
2+
fn foo<const N: usize, const K: usize>(data: [u32; N]) -> [u32; K] {
3+
[0; K]
4+
}
5+
fn main() {
6+
let a = foo::<_, 2>([0, 1, 2]);
7+
//~^ ERROR type provided when a constant was expected
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0747]: type provided when a constant was expected
2+
--> $DIR/inferred_const.rs:6:19
3+
|
4+
LL | let a = foo::<_, 2>([0, 1, 2]);
5+
| ^
6+
|
7+
= help: const arguments cannot yet be inferred with `_`
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0747`.

0 commit comments

Comments
 (0)