Skip to content

Commit aa1a07f

Browse files
Do not inline non-simple argument type errors into labels
1 parent b0cd1e1 commit aa1a07f

File tree

6 files changed

+67
-16
lines changed

6 files changed

+67
-16
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14241424
/// E0271, like `src/test/ui/issues/issue-39970.stderr`.
14251425
#[tracing::instrument(
14261426
level = "debug",
1427-
skip(self, diag, secondary_span, swap_secondary_and_primary, force_label)
1427+
skip(self, diag, secondary_span, swap_secondary_and_primary, prefer_label)
14281428
)]
14291429
pub fn note_type_err(
14301430
&self,
@@ -1434,7 +1434,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14341434
mut values: Option<ValuePairs<'tcx>>,
14351435
terr: &TypeError<'tcx>,
14361436
swap_secondary_and_primary: bool,
1437-
force_label: bool,
1437+
prefer_label: bool,
14381438
) {
14391439
let span = cause.span();
14401440

@@ -1612,7 +1612,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16121612
TypeError::ObjectUnsafeCoercion(_) => {}
16131613
_ => {
16141614
let mut label_or_note = |span: Span, msg: &str| {
1615-
if force_label || &[span] == diag.span.primary_spans() {
1615+
if (prefer_label && is_simple_error) || &[span] == diag.span.primary_spans() {
16161616
diag.span_label(span, msg);
16171617
} else {
16181618
diag.span_note(span, msg);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#[derive(Copy, Clone)]
2+
struct Wrapper<T>(T);
3+
4+
fn foo(_: fn(i32), _: Wrapper<i32>) {}
5+
6+
fn f(_: u32) {}
7+
8+
fn main() {
9+
let w = Wrapper::<isize>(1isize);
10+
foo(f, w); //~ ERROR arguments to this function are incorrect
11+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0308]: arguments to this function are incorrect
2+
--> $DIR/two-mismatch-notes.rs:10:5
3+
|
4+
LL | foo(f, w);
5+
| ^^^
6+
|
7+
note: expected `i32`, found `u32`
8+
--> $DIR/two-mismatch-notes.rs:10:9
9+
|
10+
LL | foo(f, w);
11+
| ^
12+
= note: expected fn pointer `fn(i32)`
13+
found fn item `fn(u32) {f}`
14+
note: expected `i32`, found `isize`
15+
--> $DIR/two-mismatch-notes.rs:10:12
16+
|
17+
LL | foo(f, w);
18+
| ^
19+
= note: expected struct `Wrapper<i32>`
20+
found struct `Wrapper<isize>`
21+
note: function defined here
22+
--> $DIR/two-mismatch-notes.rs:4:4
23+
|
24+
LL | fn foo(_: fn(i32), _: Wrapper<i32>) {}
25+
| ^^^ ---------- ---------------
26+
27+
error: aborting due to previous error
28+
29+
For more information about this error, try `rustc --explain E0308`.

src/test/ui/issues/issue-18819.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ error[E0061]: this function takes 2 arguments but 1 argument was supplied
22
--> $DIR/issue-18819.rs:16:5
33
|
44
LL | print_x(X);
5-
| ^^^^^^^---
6-
| ||
7-
| |expected reference, found struct `X`
8-
| an argument of type `&str` is missing
5+
| ^^^^^^^--- an argument of type `&str` is missing
96
|
7+
note: expected reference, found struct `X`
8+
--> $DIR/issue-18819.rs:16:13
9+
|
10+
LL | print_x(X);
11+
| ^
1012
= note: expected reference `&dyn Foo<Item = bool>`
1113
found struct `X`
1214
note: function defined here

src/test/ui/suggestions/args-instead-of-tuple-errors.stderr

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ error[E0061]: this enum variant takes 1 argument but 2 arguments were supplied
22
--> $DIR/args-instead-of-tuple-errors.rs:6:34
33
|
44
LL | let _: Option<(i32, bool)> = Some(1, 2);
5-
| ^^^^ - - argument of type `{integer}` unexpected
6-
| |
7-
| expected tuple, found integer
5+
| ^^^^ - argument of type `{integer}` unexpected
86
|
7+
note: expected tuple, found integer
8+
--> $DIR/args-instead-of-tuple-errors.rs:6:39
9+
|
10+
LL | let _: Option<(i32, bool)> = Some(1, 2);
11+
| ^
912
= note: expected tuple `(i32, bool)`
1013
found type `{integer}`
1114
note: tuple variant defined here
@@ -22,10 +25,13 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
2225
--> $DIR/args-instead-of-tuple-errors.rs:8:5
2326
|
2427
LL | int_bool(1, 2);
25-
| ^^^^^^^^ - - argument of type `{integer}` unexpected
26-
| |
27-
| expected tuple, found integer
28+
| ^^^^^^^^ - argument of type `{integer}` unexpected
2829
|
30+
note: expected tuple, found integer
31+
--> $DIR/args-instead-of-tuple-errors.rs:8:14
32+
|
33+
LL | int_bool(1, 2);
34+
| ^
2935
= note: expected tuple `(i32, bool)`
3036
found type `{integer}`
3137
note: function defined here

src/test/ui/tuple/wrong_argument_ice-3.stderr

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
22
--> $DIR/wrong_argument_ice-3.rs:9:16
33
|
44
LL | groups.push(new_group, vec![process]);
5-
| ^^^^ --------- ------------- argument of type `Vec<&Process>` unexpected
6-
| |
7-
| expected tuple, found struct `Vec`
5+
| ^^^^ ------------- argument of type `Vec<&Process>` unexpected
86
|
7+
note: expected tuple, found struct `Vec`
8+
--> $DIR/wrong_argument_ice-3.rs:9:21
9+
|
10+
LL | groups.push(new_group, vec![process]);
11+
| ^^^^^^^^^
912
= note: expected tuple `(Vec<String>, Vec<Process>)`
1013
found struct `Vec<String>`
1114
note: associated function defined here

0 commit comments

Comments
 (0)