about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBastian Kauschke <bastian_kauschke@hotmail.de>2020-09-23 10:44:11 +0200
committerBastian Kauschke <bastian_kauschke@hotmail.de>2020-09-23 10:44:11 +0200
commit3dbfdb0182c7b8bbace4b5d8d4445aac4291351a (patch)
tree9918cdf89308773858344a3f77e9229b641bbcf7
parent0abb1abf04da1dd5a709614f443b57d973d438ba (diff)
downloadrust-3dbfdb0182c7b8bbace4b5d8d4445aac4291351a.tar.gz
rust-3dbfdb0182c7b8bbace4b5d8d4445aac4291351a.zip
use the correct span when dealing with inference variables
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs14
-rw-r--r--src/test/ui/const-generics/infer/cannot-infer-const-args.full.stderr2
-rw-r--r--src/test/ui/const-generics/infer/cannot-infer-const-args.min.stderr2
-rw-r--r--src/test/ui/const-generics/infer/issue-77092.rs16
-rw-r--r--src/test/ui/const-generics/infer/issue-77092.stderr9
-rw-r--r--src/test/ui/const-generics/infer/method-chain.full.stderr2
-rw-r--r--src/test/ui/const-generics/infer/method-chain.min.stderr2
-rw-r--r--src/test/ui/const-generics/infer/uninferred-consts.full.stderr2
-rw-r--r--src/test/ui/const-generics/infer/uninferred-consts.min.stderr2
9 files changed, 40 insertions, 11 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
index bea1ab519f1..b7debba68b5 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
@@ -275,7 +275,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
                 (s, None, ty.prefix_string(), None, None)
             }
             GenericArgKind::Const(ct) => {
-                if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.val {
+                let span = if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.val {
                     let origin =
                         self.inner.borrow_mut().const_unification_table().probe_value(vid).origin;
                     if let ConstVariableOriginKind::ConstParameterDefinition(name, def_id) =
@@ -308,15 +308,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
                             parent_descr,
                         );
                     }
-                }
+
+                    Some(origin.span).filter(|s| !s.is_dummy())
+                } else {
+                    bug!("unexpect const: {:?}", ct);
+                };
 
                 let mut s = String::new();
-                let mut printer = ty::print::FmtPrinter::new(self.tcx, &mut s, Namespace::TypeNS);
+                let mut printer = ty::print::FmtPrinter::new(self.tcx, &mut s, Namespace::ValueNS);
                 if let Some(highlight) = highlight {
                     printer.region_highlight_mode = highlight;
                 }
                 let _ = ct.print(printer);
-                (s, None, "value".into(), None, None)
+                (s, span, "the constant".into(), None, None)
             }
             GenericArgKind::Lifetime(_) => bug!("unexpected lifetime"),
         }
@@ -705,7 +709,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
                 "".to_string()
             };
 
-            let preposition = if "value" == kind_str { "of" } else { "for" };
+            let preposition = if "the value" == kind_str { "of" } else { "for" };
             // For example: "cannot infer type for type parameter `T`"
             format!(
                 "cannot infer {} {} {} `{}`{}",
diff --git a/src/test/ui/const-generics/infer/cannot-infer-const-args.full.stderr b/src/test/ui/const-generics/infer/cannot-infer-const-args.full.stderr
index a5f7705804e..b438ed3ad65 100644
--- a/src/test/ui/const-generics/infer/cannot-infer-const-args.full.stderr
+++ b/src/test/ui/const-generics/infer/cannot-infer-const-args.full.stderr
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
   --> $DIR/cannot-infer-const-args.rs:12:5
    |
 LL |     foo();
-   |     ^^^ cannot infer the value for const parameter `X` declared on the function `foo`
+   |     ^^^ cannot infer the value of const parameter `X` declared on the function `foo`
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/const-generics/infer/cannot-infer-const-args.min.stderr b/src/test/ui/const-generics/infer/cannot-infer-const-args.min.stderr
index a5f7705804e..b438ed3ad65 100644
--- a/src/test/ui/const-generics/infer/cannot-infer-const-args.min.stderr
+++ b/src/test/ui/const-generics/infer/cannot-infer-const-args.min.stderr
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
   --> $DIR/cannot-infer-const-args.rs:12:5
    |
 LL |     foo();
-   |     ^^^ cannot infer the value for const parameter `X` declared on the function `foo`
+   |     ^^^ cannot infer the value of const parameter `X` declared on the function `foo`
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/const-generics/infer/issue-77092.rs b/src/test/ui/const-generics/infer/issue-77092.rs
new file mode 100644
index 00000000000..9a1dd1a8258
--- /dev/null
+++ b/src/test/ui/const-generics/infer/issue-77092.rs
@@ -0,0 +1,16 @@
+#![feature(min_const_generics)]
+
+use std::convert::TryInto;
+
+fn take_array_from_mut<T, const N: usize>(data: &mut [T], start: usize) -> &mut [T; N] {
+    (&mut data[start .. start + N]).try_into().unwrap()
+}
+
+fn main() {
+    let mut arr = [0, 1, 2, 3, 4, 5, 6, 7, 8];
+
+    for i in 1 .. 4 {
+        println!("{:?}", take_array_from_mut(&mut arr, i));
+        //~^ ERROR type annotations needed
+    }
+}
diff --git a/src/test/ui/const-generics/infer/issue-77092.stderr b/src/test/ui/const-generics/infer/issue-77092.stderr
new file mode 100644
index 00000000000..e84ff8baeea
--- /dev/null
+++ b/src/test/ui/const-generics/infer/issue-77092.stderr
@@ -0,0 +1,9 @@
+error[E0282]: type annotations needed
+  --> $DIR/issue-77092.rs:13:26
+   |
+LL |         println!("{:?}", take_array_from_mut(&mut arr, i));
+   |                          ^^^^^^^^^^^^^^^^^^^ cannot infer the value of the constant `{_: usize}`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.
diff --git a/src/test/ui/const-generics/infer/method-chain.full.stderr b/src/test/ui/const-generics/infer/method-chain.full.stderr
index 0344b364166..1fb0b23cf11 100644
--- a/src/test/ui/const-generics/infer/method-chain.full.stderr
+++ b/src/test/ui/const-generics/infer/method-chain.full.stderr
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
   --> $DIR/method-chain.rs:21:33
    |
 LL |     Foo.bar().bar().bar().bar().baz();
-   |                                 ^^^ cannot infer the value for const parameter `N` declared on the associated function `baz`
+   |                                 ^^^ cannot infer the value of const parameter `N` declared on the associated function `baz`
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/const-generics/infer/method-chain.min.stderr b/src/test/ui/const-generics/infer/method-chain.min.stderr
index 0344b364166..1fb0b23cf11 100644
--- a/src/test/ui/const-generics/infer/method-chain.min.stderr
+++ b/src/test/ui/const-generics/infer/method-chain.min.stderr
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
   --> $DIR/method-chain.rs:21:33
    |
 LL |     Foo.bar().bar().bar().bar().baz();
-   |                                 ^^^ cannot infer the value for const parameter `N` declared on the associated function `baz`
+   |                                 ^^^ cannot infer the value of const parameter `N` declared on the associated function `baz`
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/const-generics/infer/uninferred-consts.full.stderr b/src/test/ui/const-generics/infer/uninferred-consts.full.stderr
index 47ffc7e7157..7a451903e96 100644
--- a/src/test/ui/const-generics/infer/uninferred-consts.full.stderr
+++ b/src/test/ui/const-generics/infer/uninferred-consts.full.stderr
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
   --> $DIR/uninferred-consts.rs:14:9
    |
 LL |     Foo.foo();
-   |         ^^^ cannot infer the value for const parameter `N` declared on the associated function `foo`
+   |         ^^^ cannot infer the value of const parameter `N` declared on the associated function `foo`
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/const-generics/infer/uninferred-consts.min.stderr b/src/test/ui/const-generics/infer/uninferred-consts.min.stderr
index 47ffc7e7157..7a451903e96 100644
--- a/src/test/ui/const-generics/infer/uninferred-consts.min.stderr
+++ b/src/test/ui/const-generics/infer/uninferred-consts.min.stderr
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
   --> $DIR/uninferred-consts.rs:14:9
    |
 LL |     Foo.foo();
-   |         ^^^ cannot infer the value for const parameter `N` declared on the associated function `foo`
+   |         ^^^ cannot infer the value of const parameter `N` declared on the associated function `foo`
 
 error: aborting due to previous error