Skip to content

Commit 2e7472f

Browse files
Note type mismatch on ConstArgHasType
1 parent 7c2ee33 commit 2e7472f

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1282,10 +1282,20 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
12821282
),
12831283

12841284
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(ct, ty)) => {
1285-
self.tcx.sess.struct_span_err(
1285+
let mut diag = self.tcx.sess.struct_span_err(
12861286
span,
12871287
&format!("the constant `{}` is not of type `{}`", ct, ty),
1288-
)
1288+
);
1289+
self.note_type_err(
1290+
&mut diag,
1291+
&obligation.cause,
1292+
None,
1293+
None,
1294+
TypeError::Sorts(ty::error::ExpectedFound::new(true, ty, ct.ty())),
1295+
false,
1296+
false,
1297+
);
1298+
diag
12891299
}
12901300
}
12911301
}

tests/ui/const-generics/type_mismatch.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: the constant `N` is not of type `u8`
22
--> $DIR/type_mismatch.rs:2:11
33
|
44
LL | bar::<N>()
5-
| ^
5+
| ^ expected `u8`, found `usize`
66
|
77
note: required by a bound in `bar`
88
--> $DIR/type_mismatch.rs:6:8

tests/ui/transmutability/issue-101739-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ error: the constant `ASSUME_ALIGNMENT` is not of type `Assume`
88
--> $DIR/issue-101739-1.rs:8:14
99
|
1010
LL | Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME_ALIGNMENT>,
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Assume`, found `bool`
1212
|
1313
note: required by a bound in `BikeshedIntrinsicFrom`
1414
--> $SRC_DIR/core/src/mem/transmutability.rs:LL:COL

0 commit comments

Comments
 (0)