diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 20864c657ffd7..772b81992c46b 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -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, @@ -1434,7 +1434,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { mut values: Option>, terr: &TypeError<'tcx>, swap_secondary_and_primary: bool, - force_label: bool, + prefer_label: bool, ) { let span = cause.span(); @@ -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); diff --git a/src/test/ui/argument-suggestions/two-mismatch-notes.rs b/src/test/ui/argument-suggestions/two-mismatch-notes.rs new file mode 100644 index 0000000000000..1309041ab9a59 --- /dev/null +++ b/src/test/ui/argument-suggestions/two-mismatch-notes.rs @@ -0,0 +1,11 @@ +#[derive(Copy, Clone)] +struct Wrapper(T); + +fn foo(_: fn(i32), _: Wrapper) {} + +fn f(_: u32) {} + +fn main() { + let w = Wrapper::(1isize); + foo(f, w); //~ ERROR arguments to this function are incorrect +} diff --git a/src/test/ui/argument-suggestions/two-mismatch-notes.stderr b/src/test/ui/argument-suggestions/two-mismatch-notes.stderr new file mode 100644 index 0000000000000..7873cf964cbbc --- /dev/null +++ b/src/test/ui/argument-suggestions/two-mismatch-notes.stderr @@ -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` + found struct `Wrapper` +note: function defined here + --> $DIR/two-mismatch-notes.rs:4:4 + | +LL | fn foo(_: fn(i32), _: Wrapper) {} + | ^^^ ---------- --------------- + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/issues/issue-18819.stderr b/src/test/ui/issues/issue-18819.stderr index 6499dd0d81b1c..e499d0572f607 100644 --- a/src/test/ui/issues/issue-18819.stderr +++ b/src/test/ui/issues/issue-18819.stderr @@ -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` found struct `X` note: function defined here diff --git a/src/test/ui/suggestions/args-instead-of-tuple-errors.stderr b/src/test/ui/suggestions/args-instead-of-tuple-errors.stderr index 805c75f464cd5..4c952669cfafd 100644 --- a/src/test/ui/suggestions/args-instead-of-tuple-errors.stderr +++ b/src/test/ui/suggestions/args-instead-of-tuple-errors.stderr @@ -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 @@ -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 diff --git a/src/test/ui/tuple/wrong_argument_ice-3.stderr b/src/test/ui/tuple/wrong_argument_ice-3.stderr index 2733fb3149b55..968cb75db7633 100644 --- a/src/test/ui/tuple/wrong_argument_ice-3.stderr +++ b/src/test/ui/tuple/wrong_argument_ice-3.stderr @@ -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, Vec)` found struct `Vec` note: associated function defined here