Skip to content

Commit

Permalink
Do not inline non-simple argument type errors into labels
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Aug 13, 2022
1 parent b0cd1e1 commit aa1a07f
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 16 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
/// E0271, like `src/test/ui/issues/issue-39970.stderr`.
#[tracing::instrument(
level = "debug",
skip(self, diag, secondary_span, swap_secondary_and_primary, force_label)
skip(self, diag, secondary_span, swap_secondary_and_primary, prefer_label)
)]
pub fn note_type_err(
&self,
Expand All @@ -1434,7 +1434,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
mut values: Option<ValuePairs<'tcx>>,
terr: &TypeError<'tcx>,
swap_secondary_and_primary: bool,
force_label: bool,
prefer_label: bool,
) {
let span = cause.span();

Expand Down Expand Up @@ -1612,7 +1612,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
TypeError::ObjectUnsafeCoercion(_) => {}
_ => {
let mut label_or_note = |span: Span, msg: &str| {
if force_label || &[span] == diag.span.primary_spans() {
if (prefer_label && is_simple_error) || &[span] == diag.span.primary_spans() {
diag.span_label(span, msg);
} else {
diag.span_note(span, msg);
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/argument-suggestions/two-mismatch-notes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[derive(Copy, Clone)]
struct Wrapper<T>(T);

fn foo(_: fn(i32), _: Wrapper<i32>) {}

fn f(_: u32) {}

fn main() {
let w = Wrapper::<isize>(1isize);
foo(f, w); //~ ERROR arguments to this function are incorrect
}
29 changes: 29 additions & 0 deletions src/test/ui/argument-suggestions/two-mismatch-notes.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
error[E0308]: arguments to this function are incorrect
--> $DIR/two-mismatch-notes.rs:10:5
|
LL | foo(f, w);
| ^^^
|
note: expected `i32`, found `u32`
--> $DIR/two-mismatch-notes.rs:10:9
|
LL | foo(f, w);
| ^
= note: expected fn pointer `fn(i32)`
found fn item `fn(u32) {f}`
note: expected `i32`, found `isize`
--> $DIR/two-mismatch-notes.rs:10:12
|
LL | foo(f, w);
| ^
= note: expected struct `Wrapper<i32>`
found struct `Wrapper<isize>`
note: function defined here
--> $DIR/two-mismatch-notes.rs:4:4
|
LL | fn foo(_: fn(i32), _: Wrapper<i32>) {}
| ^^^ ---------- ---------------

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
10 changes: 6 additions & 4 deletions src/test/ui/issues/issue-18819.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ error[E0061]: this function takes 2 arguments but 1 argument was supplied
--> $DIR/issue-18819.rs:16:5
|
LL | print_x(X);
| ^^^^^^^---
| ||
| |expected reference, found struct `X`
| an argument of type `&str` is missing
| ^^^^^^^--- an argument of type `&str` is missing
|
note: expected reference, found struct `X`
--> $DIR/issue-18819.rs:16:13
|
LL | print_x(X);
| ^
= note: expected reference `&dyn Foo<Item = bool>`
found struct `X`
note: function defined here
Expand Down
18 changes: 12 additions & 6 deletions src/test/ui/suggestions/args-instead-of-tuple-errors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ error[E0061]: this enum variant takes 1 argument but 2 arguments were supplied
--> $DIR/args-instead-of-tuple-errors.rs:6:34
|
LL | let _: Option<(i32, bool)> = Some(1, 2);
| ^^^^ - - argument of type `{integer}` unexpected
| |
| expected tuple, found integer
| ^^^^ - argument of type `{integer}` unexpected
|
note: expected tuple, found integer
--> $DIR/args-instead-of-tuple-errors.rs:6:39
|
LL | let _: Option<(i32, bool)> = Some(1, 2);
| ^
= note: expected tuple `(i32, bool)`
found type `{integer}`
note: tuple variant defined here
Expand All @@ -22,10 +25,13 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
--> $DIR/args-instead-of-tuple-errors.rs:8:5
|
LL | int_bool(1, 2);
| ^^^^^^^^ - - argument of type `{integer}` unexpected
| |
| expected tuple, found integer
| ^^^^^^^^ - argument of type `{integer}` unexpected
|
note: expected tuple, found integer
--> $DIR/args-instead-of-tuple-errors.rs:8:14
|
LL | int_bool(1, 2);
| ^
= note: expected tuple `(i32, bool)`
found type `{integer}`
note: function defined here
Expand Down
9 changes: 6 additions & 3 deletions src/test/ui/tuple/wrong_argument_ice-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
--> $DIR/wrong_argument_ice-3.rs:9:16
|
LL | groups.push(new_group, vec![process]);
| ^^^^ --------- ------------- argument of type `Vec<&Process>` unexpected
| |
| expected tuple, found struct `Vec`
| ^^^^ ------------- argument of type `Vec<&Process>` unexpected
|
note: expected tuple, found struct `Vec`
--> $DIR/wrong_argument_ice-3.rs:9:21
|
LL | groups.push(new_group, vec![process]);
| ^^^^^^^^^
= note: expected tuple `(Vec<String>, Vec<Process>)`
found struct `Vec<String>`
note: associated function defined here
Expand Down

0 comments on commit aa1a07f

Please sign in to comment.