Skip to content

Commit 101a0c6

Browse files
committed
Avoid span overlap in type mismatch
1 parent 7cd7bbc commit 101a0c6

File tree

6 files changed

+6
-34
lines changed

6 files changed

+6
-34
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
456456
span,
457457
format!("this is an iterator with items of type `{}`", args.type_at(0)),
458458
);
459-
} else {
459+
} else if !span.overlaps(cause.span) {
460460
err.span_label(span, format!("this expression has type `{expected_ty}`"));
461461
}
462462
}

tests/ui/codemap_tests/issue-28308.edition2024.stderr

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
//@revisions: edition2024 edition2021
2-
//@[edition2024] edition:2024
3-
//@[edition2024] compile-flags: -Z unstable-options
4-
//@[edition2021] edition:2021
51
fn main() {
62
assert!("foo");
7-
//[edition2024]~^ ERROR mismatched types
8-
//[edition2021]~^^ ERROR mismatched types
3+
//~^ ERROR mismatched types
94
}

tests/ui/codemap_tests/issue-28308.edition2021.stderr renamed to tests/ui/codemap_tests/issue-28308.stderr

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
error[E0308]: mismatched types
2-
--> $DIR/issue-28308.rs:6:13
2+
--> $DIR/issue-28308.rs:2:13
33
|
44
LL | assert!("foo");
5-
| ^^^^^
6-
| |
7-
| expected `str`, found `bool`
8-
| this expression has type `&str`
5+
| ^^^^^ expected `str`, found `bool`
96
|
107
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
118

tests/ui/issues/issue-14091-2.stderr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-14091-2.rs:15:13
33
|
44
LL | assert!(x, x);
5-
| ^
6-
| |
7-
| expected `BytePos`, found `bool`
8-
| this expression has type `BytePos`
5+
| ^ expected `BytePos`, found `bool`
96
|
107
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
118

tests/ui/issues/issue-14091.stderr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-14091.rs:2:13
33
|
44
LL | assert!(1,1);
5-
| ^
6-
| |
7-
| expected integer, found `bool`
8-
| this expression has type `{integer}`
5+
| ^ expected integer, found `bool`
96
|
107
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
118

0 commit comments

Comments
 (0)