about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-03-09 22:08:48 +0000
committerMichael Goulet <michael@errs.io>2023-03-23 19:09:34 +0000
commit6c6bd014210aa4a5cd4a2bb5ab4cc7174e82d74b (patch)
treef936c5c8d0f168cccdaa8713ef81ad4a3acc40d6
parente55f73ae47dd3b508edaf8403ca26ca9dbb1097e (diff)
downloadrust-6c6bd014210aa4a5cd4a2bb5ab4cc7174e82d74b.tar.gz
rust-6c6bd014210aa4a5cd4a2bb5ab4cc7174e82d74b.zip
Note type mismatch on ConstArgHasType
-rw-r--r--compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs14
-rw-r--r--tests/ui/const-generics/type_mismatch.stderr2
-rw-r--r--tests/ui/specialization/min_specialization/bad-const-wf-doesnt-specialize.stderr2
-rw-r--r--tests/ui/transmutability/issue-101739-1.stderr2
4 files changed, 15 insertions, 5 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
index 617d53b609d..296fd1ed524 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
@@ -1282,10 +1282,20 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
                     ),
 
                     ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(ct, ty)) => {
-                        self.tcx.sess.struct_span_err(
+                        let mut diag = self.tcx.sess.struct_span_err(
                             span,
                             &format!("the constant `{}` is not of type `{}`", ct, ty),
-                        )
+                        );
+                        self.note_type_err(
+                            &mut diag,
+                            &obligation.cause,
+                            None,
+                            None,
+                            TypeError::Sorts(ty::error::ExpectedFound::new(true, ty, ct.ty())),
+                            false,
+                            false,
+                        );
+                        diag
                     }
                 }
             }
diff --git a/tests/ui/const-generics/type_mismatch.stderr b/tests/ui/const-generics/type_mismatch.stderr
index 2831577b132..394dd44d40d 100644
--- a/tests/ui/const-generics/type_mismatch.stderr
+++ b/tests/ui/const-generics/type_mismatch.stderr
@@ -2,7 +2,7 @@ error: the constant `N` is not of type `u8`
   --> $DIR/type_mismatch.rs:2:11
    |
 LL |     bar::<N>()
-   |           ^
+   |           ^ expected `u8`, found `usize`
    |
 note: required by a bound in `bar`
   --> $DIR/type_mismatch.rs:6:8
diff --git a/tests/ui/specialization/min_specialization/bad-const-wf-doesnt-specialize.stderr b/tests/ui/specialization/min_specialization/bad-const-wf-doesnt-specialize.stderr
index 6d7028c5e70..83f311efd39 100644
--- a/tests/ui/specialization/min_specialization/bad-const-wf-doesnt-specialize.stderr
+++ b/tests/ui/specialization/min_specialization/bad-const-wf-doesnt-specialize.stderr
@@ -2,7 +2,7 @@ error: the constant `N` is not of type `usize`
   --> $DIR/bad-const-wf-doesnt-specialize.rs:8:29
    |
 LL | impl<const N: i32> Copy for S<N> {}
-   |                             ^^^^
+   |                             ^^^^ expected `usize`, found `i32`
    |
 note: required by a bound in `S`
   --> $DIR/bad-const-wf-doesnt-specialize.rs:6:10
diff --git a/tests/ui/transmutability/issue-101739-1.stderr b/tests/ui/transmutability/issue-101739-1.stderr
index f0fa93722b8..bf947d0ea4a 100644
--- a/tests/ui/transmutability/issue-101739-1.stderr
+++ b/tests/ui/transmutability/issue-101739-1.stderr
@@ -8,7 +8,7 @@ error: the constant `ASSUME_ALIGNMENT` is not of type `Assume`
   --> $DIR/issue-101739-1.rs:8:14
    |
 LL |         Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME_ALIGNMENT>,
-   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Assume`, found `bool`
    |
 note: required by a bound in `BikeshedIntrinsicFrom`
   --> $SRC_DIR/core/src/mem/transmutability.rs:LL:COL