Do not inline non-simple argument type errors into labels
This commit is contained in:
parent
b0cd1e192c
commit
aa1a07f114
6 changed files with 67 additions and 16 deletions
|
@ -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<ValuePairs<'tcx>>,
|
||||
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);
|
||||
|
|
11
src/test/ui/argument-suggestions/two-mismatch-notes.rs
Normal file
11
src/test/ui/argument-suggestions/two-mismatch-notes.rs
Normal file
|
@ -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
src/test/ui/argument-suggestions/two-mismatch-notes.stderr
Normal file
29
src/test/ui/argument-suggestions/two-mismatch-notes.stderr
Normal file
|
@ -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`.
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue