about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-12-06 08:08:05 +0000
committerbors <bors@rust-lang.org>2020-12-06 08:08:05 +0000
commita68864b68859e5848865bd392ce6d892b16f5cdd (patch)
treef1c402a267a47395f96161250da02124d1ebf4bf
parent5957f208a5def92a5ee85e71b01f75904c1ba4ff (diff)
parent6845e22bbabce5631c388c52eb367168ce9b14ce (diff)
downloadrust-a68864b68859e5848865bd392ce6d892b16f5cdd.tar.gz
rust-a68864b68859e5848865bd392ce6d892b16f5cdd.zip
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`
-rw-r--r--compiler/rustc_typeck/src/astconv/generics.rs7
-rw-r--r--src/test/ui/const-generics/issues/issue-62878.full.stderr2
-rw-r--r--src/test/ui/const-generics/min_const_generics/inferred_const.rs8
-rw-r--r--src/test/ui/const-generics/min_const_generics/inferred_const.stderr11
4 files changed, 28 insertions, 0 deletions
diff --git a/compiler/rustc_typeck/src/astconv/generics.rs b/compiler/rustc_typeck/src/astconv/generics.rs
index 0db5fda272a..b7e77f389f8 100644
--- a/compiler/rustc_typeck/src/astconv/generics.rs
+++ b/compiler/rustc_typeck/src/astconv/generics.rs
@@ -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,
diff --git a/src/test/ui/const-generics/issues/issue-62878.full.stderr b/src/test/ui/const-generics/issues/issue-62878.full.stderr
index fc70be40497..dce2e27c71a 100644
--- a/src/test/ui/const-generics/issues/issue-62878.full.stderr
+++ b/src/test/ui/const-generics/issues/issue-62878.full.stderr
@@ -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
diff --git a/src/test/ui/const-generics/min_const_generics/inferred_const.rs b/src/test/ui/const-generics/min_const_generics/inferred_const.rs
new file mode 100644
index 00000000000..dcd069ce3b0
--- /dev/null
+++ b/src/test/ui/const-generics/min_const_generics/inferred_const.rs
@@ -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
+}
diff --git a/src/test/ui/const-generics/min_const_generics/inferred_const.stderr b/src/test/ui/const-generics/min_const_generics/inferred_const.stderr
new file mode 100644
index 00000000000..e17105b2aa9
--- /dev/null
+++ b/src/test/ui/const-generics/min_const_generics/inferred_const.stderr
@@ -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`.