about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBastian Kauschke <bastian_kauschke@hotmail.de>2020-09-21 23:25:52 +0200
committerBastian Kauschke <bastian_kauschke@hotmail.de>2020-09-21 23:25:52 +0200
commit2f893e458a20a159fcf93a9a5b0435ae3ed0a67e (patch)
tree0e4ac4a0a8f7c3fd078367315481a86022e7952c
parent9a493ced748e2e3e7390fc6f28640d23cb90e67b (diff)
downloadrust-2f893e458a20a159fcf93a9a5b0435ae3ed0a67e.tar.gz
rust-2f893e458a20a159fcf93a9a5b0435ae3ed0a67e.zip
review
-rw-r--r--compiler/rustc_middle/src/mir/interpret/error.rs6
-rw-r--r--compiler/rustc_trait_selection/src/traits/const_evaluatable.rs21
-rw-r--r--src/test/ui/const-generics/const_evaluatable_checked/closures.stderr9
-rw-r--r--src/test/ui/const-generics/const_evaluatable_checked/let-bindings.stderr18
4 files changed, 23 insertions, 31 deletions
diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs
index 059925088ce..97a13ee8e20 100644
--- a/compiler/rustc_middle/src/mir/interpret/error.rs
+++ b/compiler/rustc_middle/src/mir/interpret/error.rs
@@ -23,6 +23,12 @@ pub enum ErrorHandled {
     TooGeneric,
 }
 
+impl From<ErrorReported> for ErrorHandled {
+    fn from(err: ErrorReported) -> ErrorHandled {
+        ErrorHandled::Reported(err)
+    }
+}
+
 CloneTypeFoldableAndLiftImpls! {
     ErrorHandled,
 }
diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
index 12082475c85..0cfcaca9060 100644
--- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
+++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
@@ -32,9 +32,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
 ) -> Result<(), ErrorHandled> {
     debug!("is_const_evaluatable({:?}, {:?})", def, substs);
     if infcx.tcx.features().const_evaluatable_checked {
-        if let Some(ct) =
-            AbstractConst::new(infcx.tcx, def, substs).map_err(ErrorHandled::Reported)?
-        {
+        if let Some(ct) = AbstractConst::new(infcx.tcx, def, substs)? {
             for pred in param_env.caller_bounds() {
                 match pred.skip_binders() {
                     ty::PredicateAtom::ConstEvaluatable(b_def, b_substs) => {
@@ -42,8 +40,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
                         if b_def == def && b_substs == substs {
                             debug!("is_const_evaluatable: caller_bound ~~> ok");
                             return Ok(());
-                        } else if AbstractConst::new(infcx.tcx, b_def, b_substs)
-                            .map_err(ErrorHandled::Reported)?
+                        } else if AbstractConst::new(infcx.tcx, b_def, b_substs)?
                             .map_or(false, |b_ct| try_unify(infcx.tcx, ct, b_ct))
                         {
                             debug!("is_const_evaluatable: abstract_const ~~> ok");
@@ -153,14 +150,12 @@ struct AbstractConstBuilder<'a, 'tcx> {
 
 impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
     fn error(&mut self, span: Option<Span>, msg: &str) -> Result<!, ErrorReported> {
-        let mut err =
-            self.tcx.sess.struct_span_err(self.body.span, "overly complex generic constant");
-        if let Some(span) = span {
-            err.span_note(span, msg);
-        } else {
-            err.note(msg);
-        }
-        err.help("consider moving this anonymous constant into a `const` function").emit();
+        self.tcx
+            .sess
+            .struct_span_err(self.body.span, "overly complex generic constant")
+            .span_label(span.unwrap_or(self.body.span), msg)
+            .help("consider moving this anonymous constant into a `const` function")
+            .emit();
 
         Err(ErrorReported)
     }
diff --git a/src/test/ui/const-generics/const_evaluatable_checked/closures.stderr b/src/test/ui/const-generics/const_evaluatable_checked/closures.stderr
index 7bb23f1488d..9f0b7252e83 100644
--- a/src/test/ui/const-generics/const_evaluatable_checked/closures.stderr
+++ b/src/test/ui/const-generics/const_evaluatable_checked/closures.stderr
@@ -2,13 +2,10 @@ error: overly complex generic constant
   --> $DIR/closures.rs:3:35
    |
 LL | fn test<const N: usize>() -> [u8; N + (|| 42)()] {}
-   |                                   ^^^^^^^^^^^^^
+   |                                   ^^^^-------^^
+   |                                       |
+   |                                       unsupported rvalue
    |
-note: unsupported rvalue
-  --> $DIR/closures.rs:3:39
-   |
-LL | fn test<const N: usize>() -> [u8; N + (|| 42)()] {}
-   |                                       ^^^^^^^
    = help: consider moving this anonymous constant into a `const` function
 
 error: aborting due to previous error
diff --git a/src/test/ui/const-generics/const_evaluatable_checked/let-bindings.stderr b/src/test/ui/const-generics/const_evaluatable_checked/let-bindings.stderr
index 95fcde52af8..5749defb3e1 100644
--- a/src/test/ui/const-generics/const_evaluatable_checked/let-bindings.stderr
+++ b/src/test/ui/const-generics/const_evaluatable_checked/let-bindings.stderr
@@ -2,26 +2,20 @@ error: overly complex generic constant
   --> $DIR/let-bindings.rs:6:68
    |
 LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
-   |                                                                    ^^^^^^^^^^^^^^^^^^^^
+   |                                                                    ^^^^^^-^^^^^^^^^^^^^
+   |                                                                          |
+   |                                                                          unsupported statement
    |
-note: unsupported statement
-  --> $DIR/let-bindings.rs:6:74
-   |
-LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
-   |                                                                          ^
    = help: consider moving this anonymous constant into a `const` function
 
 error: overly complex generic constant
   --> $DIR/let-bindings.rs:6:35
    |
 LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
-   |                                   ^^^^^^^^^^^^^^^^^^^^
+   |                                   ^^^^^^-^^^^^^^^^^^^^
+   |                                         |
+   |                                         unsupported statement
    |
-note: unsupported statement
-  --> $DIR/let-bindings.rs:6:41
-   |
-LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
-   |                                         ^
    = help: consider moving this anonymous constant into a `const` function
 
 error: aborting due to 2 previous errors