Skip to content
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

Const parameters can not be inferred with _ help note #79734

Merged
merged 1 commit into from
Dec 6, 2020
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
7 changes: 7 additions & 0 deletions compiler/rustc_typeck/src/astconv/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// the match is non-exhaustive.
_ => bug!("invalid generic parameter kind {}", kind),
};

if let ParamKindOrd::Const { .. } = kind_ord {
if let GenericArg::Type(hir::Ty { kind: hir::TyKind::Infer, .. }) = arg {
err.help("const arguments cannot yet be inferred with `_`");
}
}

let arg_ord = match arg {
GenericArg::Lifetime(_) => ParamKindOrd::Lifetime,
GenericArg::Type(_) => ParamKindOrd::Type,
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/const-generics/issues/issue-62878.full.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ error[E0747]: type provided when a constant was expected
|
LL | foo::<_, {[1]}>();
| ^
|
= help: const arguments cannot yet be inferred with `_`

error[E0308]: mismatched types
--> $DIR/issue-62878.rs:11:15
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![feature(min_const_generics)]
fn foo<const N: usize, const K: usize>(data: [u32; N]) -> [u32; K] {
[0; K]
}
fn main() {
let a = foo::<_, 2>([0, 1, 2]);
//~^ ERROR type provided when a constant was expected
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0747]: type provided when a constant was expected
--> $DIR/inferred_const.rs:6:19
|
LL | let a = foo::<_, 2>([0, 1, 2]);
| ^
|
= help: const arguments cannot yet be inferred with `_`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0747`.