Skip to content

Commit

Permalink
Remove redundancy in resolve error between main message and primary l…
Browse files Browse the repository at this point in the history
…abel

```
error[E0576]: cannot find method or associated constant `BAR`
  --> $DIR/issue-87638.rs:20:27
   |
LL |     let _ = <S as Trait>::BAR;
   |                           ^^^ not found in trait `Trait`
```

instead of

```
error[E0576]: cannot find method or associated constant `BAR` in trait `Trait`
  --> $DIR/issue-87638.rs:20:27
   |
LL |     let _ = <S as Trait>::BAR;
   |                           ^^^ not found in `Trait`
```

The general rule is that the primary span label should work well on its own
(suitable to be shown in editors), while the main message provides
additional context of the general case. When using `--error-format=short`,
we concatenate the main message and the primary labels, so they should be
complementary.
  • Loading branch information
estebank committed Jun 21, 2024
1 parent c1b336c commit b4c34b6
Show file tree
Hide file tree
Showing 731 changed files with 1,559 additions and 1,559 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,11 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
} else {
suggestion
};
(format!("not found in {mod_str}"), override_suggestion)
(format!("not found in {mod_prefix}{mod_str}"), override_suggestion)
};

BaseError {
msg: format!("cannot find {expected} `{item_str}` in {mod_prefix}{mod_str}"),
msg: format!("cannot find {expected} `{item_str}`"),
fallback_label,
span: item_span,
span_label,
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/tests/ui/crashes/ice-6252.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0412]: cannot find type `PhantomData` in this scope
error[E0412]: cannot find type `PhantomData`
--> tests/ui/crashes/ice-6252.rs:9:9
|
LL | _n: PhantomData,
Expand All @@ -9,7 +9,7 @@ help: consider importing this struct
LL + use std::marker::PhantomData;
|

error[E0412]: cannot find type `VAL` in this scope
error[E0412]: cannot find type `VAL`
--> tests/ui/crashes/ice-6252.rs:11:63
|
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
Expand Down
8 changes: 4 additions & 4 deletions src/tools/clippy/tests/ui/option_map_unit_fn_unfixable.stderr
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
error[E0425]: cannot find value `x` in this scope
error[E0425]: cannot find value `x`
--> tests/ui/option_map_unit_fn_unfixable.rs:17:5
|
LL | x.field.map(|value| { do_nothing(value); do_nothing(value) });
| ^ not found in this scope

error[E0425]: cannot find value `x` in this scope
error[E0425]: cannot find value `x`
--> tests/ui/option_map_unit_fn_unfixable.rs:19:5
|
LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) });
| ^ not found in this scope

error[E0425]: cannot find value `x` in this scope
error[E0425]: cannot find value `x`
--> tests/ui/option_map_unit_fn_unfixable.rs:23:5
|
LL | x.field.map(|value| {
| ^ not found in this scope

error[E0425]: cannot find value `x` in this scope
error[E0425]: cannot find value `x`
--> tests/ui/option_map_unit_fn_unfixable.rs:27:5
|
LL | x.field.map(|value| { do_nothing(value); do_nothing(value); });
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc-ui/doctest/failed-doctest-output.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test $DIR/failed-doctest-output.rs - SomeStruct (line 15) ... FAILED
failures:

---- $DIR/failed-doctest-output.rs - OtherStruct (line 25) stdout ----
error[E0425]: cannot find value `no` in this scope
error[E0425]: cannot find value `no`
--> $DIR/failed-doctest-output.rs:26:1
|
LL | no
Expand Down
18 changes: 9 additions & 9 deletions tests/rustdoc-ui/impl-fn-nesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ pub trait NeedsBody {

/// This function has docs
pub fn f<B: UnknownBound>(a: UnknownType, b: B) {
//~^ ERROR cannot find trait `UnknownBound` in this scope
//~| ERROR cannot find type `UnknownType` in this scope
//~^ ERROR cannot find trait `UnknownBound`
//~| ERROR cannot find type `UnknownType`
impl UnknownTrait for ValidType {} //~ ERROR cannot find trait `UnknownTrait`
impl<T: UnknownBound> UnknownTrait for T {}
//~^ ERROR cannot find trait `UnknownBound` in this scope
//~| ERROR cannot find trait `UnknownTrait` in this scope
//~^ ERROR cannot find trait `UnknownBound`
//~| ERROR cannot find trait `UnknownTrait`
impl ValidTrait for UnknownType {}
//~^ ERROR cannot find type `UnknownType` in this scope
//~^ ERROR cannot find type `UnknownType`
impl ValidTrait for ValidType where ValidTrait: UnknownBound {}
//~^ ERROR cannot find trait `UnknownBound` in this scope
//~^ ERROR cannot find trait `UnknownBound`

/// This impl has documentation
impl NeedsBody for ValidType {
type Item = UnknownType;
//~^ ERROR cannot find type `UnknownType` in this scope
//~^ ERROR cannot find type `UnknownType`

/// This function has documentation
fn f() {
<UnknownTypeShouldBeIgnored>::a();
content::shouldnt::matter();
unknown_macro!();
//~^ ERROR cannot find macro `unknown_macro` in this scope
//~^ ERROR cannot find macro `unknown_macro`

/// This is documentation for a macro
macro_rules! can_define_macros_here_too {
Expand All @@ -42,7 +42,7 @@ pub fn f<B: UnknownBound>(a: UnknownType, b: B) {

/// This also is documented.
pub fn doubly_nested(c: UnknownType) {
//~^ ERROR cannot find type `UnknownType` in this scope
//~^ ERROR cannot find type `UnknownType`
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions tests/rustdoc-ui/impl-fn-nesting.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,55 @@ error: cannot find macro `unknown_macro` in this scope
LL | unknown_macro!();
| ^^^^^^^^^^^^^

error[E0405]: cannot find trait `UnknownBound` in this scope
error[E0405]: cannot find trait `UnknownBound`
--> $DIR/impl-fn-nesting.rs:11:13
|
LL | pub fn f<B: UnknownBound>(a: UnknownType, b: B) {
| ^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `UnknownType` in this scope
error[E0412]: cannot find type `UnknownType`
--> $DIR/impl-fn-nesting.rs:11:30
|
LL | pub fn f<B: UnknownBound>(a: UnknownType, b: B) {
| ^^^^^^^^^^^ not found in this scope

error[E0405]: cannot find trait `UnknownTrait` in this scope
error[E0405]: cannot find trait `UnknownTrait`
--> $DIR/impl-fn-nesting.rs:14:10
|
LL | impl UnknownTrait for ValidType {}
| ^^^^^^^^^^^^ not found in this scope

error[E0405]: cannot find trait `UnknownTrait` in this scope
error[E0405]: cannot find trait `UnknownTrait`
--> $DIR/impl-fn-nesting.rs:15:27
|
LL | impl<T: UnknownBound> UnknownTrait for T {}
| ^^^^^^^^^^^^ not found in this scope

error[E0405]: cannot find trait `UnknownBound` in this scope
error[E0405]: cannot find trait `UnknownBound`
--> $DIR/impl-fn-nesting.rs:15:13
|
LL | impl<T: UnknownBound> UnknownTrait for T {}
| ^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `UnknownType` in this scope
error[E0412]: cannot find type `UnknownType`
--> $DIR/impl-fn-nesting.rs:18:25
|
LL | impl ValidTrait for UnknownType {}
| ^^^^^^^^^^^ not found in this scope

error[E0405]: cannot find trait `UnknownBound` in this scope
error[E0405]: cannot find trait `UnknownBound`
--> $DIR/impl-fn-nesting.rs:20:53
|
LL | impl ValidTrait for ValidType where ValidTrait: UnknownBound {}
| ^^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `UnknownType` in this scope
error[E0412]: cannot find type `UnknownType`
--> $DIR/impl-fn-nesting.rs:25:21
|
LL | type Item = UnknownType;
| ^^^^^^^^^^^ not found in this scope

error[E0412]: cannot find type `UnknownType` in this scope
error[E0412]: cannot find type `UnknownType`
--> $DIR/impl-fn-nesting.rs:44:37
|
LL | pub fn doubly_nested(c: UnknownType) {
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc-ui/issues/issue-81662-shortness.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ compile-flags:--test --error-format=short
//@ check-stdout
//@ error-pattern:cannot find function `foo` in this scope
//@ error-pattern:cannot find function `foo`
//@ normalize-stdout-test: "tests/rustdoc-ui/issues" -> "$$DIR"
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
//@ failure-status: 101
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc-ui/issues/issue-81662-shortness.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test $DIR/issue-81662-shortness.rs - foo (line 8) ... FAILED
failures:

---- $DIR/issue-81662-shortness.rs - foo (line 8) stdout ----
$DIR/issue-81662-shortness.rs:9:1: error[E0425]: cannot find function `foo` in this scope
$DIR/issue-81662-shortness.rs:9:1: error[E0425]: cannot find function `foo`
error: aborting due to 1 previous error
Couldn't compile the test.

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/annotate-snippet/missing-type.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ compile-flags: --error-format human-annotate-rs -Z unstable-options
//@ error-pattern:cannot find type `Iter` in this scope
//@ error-pattern:cannot find type `Iter`

pub fn main() {
let x: Iter;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/annotate-snippet/missing-type.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0412]: cannot find type `Iter` in this scope
error[E0412]: cannot find type `Iter`
--> $DIR/missing-type.rs:5:12
|
LL | let x: Iter;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/argument-suggestions/extern-fn-arg-names.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern "Rust" {
fn dstfn(src: i32, dst: err);
//~^ ERROR cannot find type `err` in this scope
//~^ ERROR cannot find type `err`
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/argument-suggestions/extern-fn-arg-names.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0412]: cannot find type `err` in this scope
error[E0412]: cannot find type `err`
--> $DIR/extern-fn-arg-names.rs:2:29
|
LL | fn dstfn(src: i32, dst: err);
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/argument-suggestions/issue-109831.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0412]: cannot find type `C` in this scope
error[E0412]: cannot find type `C`
--> $DIR/issue-109831.rs:4:24
|
LL | struct A;
Expand All @@ -16,7 +16,7 @@ help: you might be missing a type parameter
LL | fn f<C>(b1: B, b2: B, a2: C) {}
| +++

error[E0425]: cannot find value `C` in this scope
error[E0425]: cannot find value `C`
--> $DIR/issue-109831.rs:7:16
|
LL | struct A;
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/array-slice-vec/slice-pat-type-mismatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ fn main() {
};

match does_not_exist {
//~^ ERROR cannot find value `does_not_exist` in this scope
[] => {} // ERROR cannot find value `does_not_exist` in this scope
//~^ ERROR cannot find value `does_not_exist`
[] => {} // ERROR cannot find value `does_not_exist`
};
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/array-slice-vec/slice-pat-type-mismatches.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0425]: cannot find value `does_not_exist` in this scope
error[E0425]: cannot find value `does_not_exist`
--> $DIR/slice-pat-type-mismatches.rs:26:11
|
LL | match does_not_exist {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/asm/issue-113788.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
//@ needs-asm-support
//@ only-x86_64
fn main() {
let peb: *const PEB; //~ ERROR cannot find type `PEB` in this scope [E0412]
let peb: *const PEB; //~ ERROR cannot find type `PEB` [E0412]
unsafe { std::arch::asm!("mov {0}, fs:[0x30]", out(reg) peb); }
}
2 changes: 1 addition & 1 deletion tests/ui/asm/issue-113788.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0412]: cannot find type `PEB` in this scope
error[E0412]: cannot find type `PEB`
--> $DIR/issue-113788.rs:5:21
|
LL | let peb: *const PEB;
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/associated-consts/issue-93835.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

fn e() {
type_ascribe!(p, a<p:p<e=6>>);
//~^ ERROR cannot find type `a` in this scope
//~^ ERROR cannot find type `a`
//~| ERROR cannot find value
//~| ERROR associated const equality
//~| ERROR cannot find trait `p` in this scope
//~| ERROR cannot find trait `p`
}

fn main() {}
6 changes: 3 additions & 3 deletions tests/ui/associated-consts/issue-93835.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
error[E0425]: cannot find value `p` in this scope
error[E0425]: cannot find value `p`
--> $DIR/issue-93835.rs:4:19
|
LL | type_ascribe!(p, a<p:p<e=6>>);
| ^ not found in this scope

error[E0412]: cannot find type `a` in this scope
error[E0412]: cannot find type `a`
--> $DIR/issue-93835.rs:4:22
|
LL | type_ascribe!(p, a<p:p<e=6>>);
| ^ not found in this scope

error[E0405]: cannot find trait `p` in this scope
error[E0405]: cannot find trait `p`
--> $DIR/issue-93835.rs:4:26
|
LL | type_ascribe!(p, a<p:p<e=6>>);
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/associated-item/issue-87638.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ impl Trait for S {
}

fn main() {
let _: <S as Trait>::Target; //~ ERROR cannot find associated type `Output` in trait `Trait`
let _: <S as Trait>::Target; //~ ERROR cannot find associated type `Output`
//~^ HELP maybe you meant this associated type

let _ = <S as Trait>::FOO; //~ ERROR cannot find method or associated constant `BAR` in trait `Trait`
let _ = <S as Trait>::FOO; //~ ERROR cannot find method or associated constant `BAR`
//~^ HELP maybe you meant this associated constant
}
4 changes: 2 additions & 2 deletions tests/ui/associated-item/issue-87638.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ impl Trait for S {
}

fn main() {
let _: <S as Trait>::Output; //~ ERROR cannot find associated type `Output` in trait `Trait`
let _: <S as Trait>::Output; //~ ERROR cannot find associated type `Output`
//~^ HELP maybe you meant this associated type

let _ = <S as Trait>::BAR; //~ ERROR cannot find method or associated constant `BAR` in trait `Trait`
let _ = <S as Trait>::BAR; //~ ERROR cannot find method or associated constant `BAR`
//~^ HELP maybe you meant this associated constant
}
8 changes: 4 additions & 4 deletions tests/ui/associated-item/issue-87638.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0576]: cannot find associated type `Output` in trait `Trait`
error[E0576]: cannot find associated type `Output`
--> $DIR/issue-87638.rs:17:26
|
LL | type Target;
Expand All @@ -7,10 +7,10 @@ LL | type Target;
LL | let _: <S as Trait>::Output;
| ^^^^^^
| |
| not found in `Trait`
| not found in trait `Trait`
| help: maybe you meant this associated type: `Target`

error[E0576]: cannot find method or associated constant `BAR` in trait `Trait`
error[E0576]: cannot find method or associated constant `BAR`
--> $DIR/issue-87638.rs:20:27
|
LL | const FOO: usize;
Expand All @@ -19,7 +19,7 @@ LL | const FOO: usize;
LL | let _ = <S as Trait>::BAR;
| ^^^
| |
| not found in `Trait`
| not found in trait `Trait`
| help: maybe you meant this associated constant: `FOO`

error: aborting due to 2 previous errors
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/associated-path-shl.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Check that associated paths starting with `<<` are successfully parsed.

fn main() {
let _: <<A>::B>::C; //~ ERROR cannot find type `A` in this scope
let _ = <<A>::B>::C; //~ ERROR cannot find type `A` in this scope
let <<A>::B>::C; //~ ERROR cannot find type `A` in this scope
let 0 ..= <<A>::B>::C; //~ ERROR cannot find type `A` in this scope
<<A>::B>::C; //~ ERROR cannot find type `A` in this scope
let _: <<A>::B>::C; //~ ERROR cannot find type `A`
let _ = <<A>::B>::C; //~ ERROR cannot find type `A`
let <<A>::B>::C; //~ ERROR cannot find type `A`
let 0 ..= <<A>::B>::C; //~ ERROR cannot find type `A`
<<A>::B>::C; //~ ERROR cannot find type `A`
}
10 changes: 5 additions & 5 deletions tests/ui/associated-path-shl.stderr
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
error[E0412]: cannot find type `A` in this scope
error[E0412]: cannot find type `A`
--> $DIR/associated-path-shl.rs:4:14
|
LL | let _: <<A>::B>::C;
| ^ not found in this scope

error[E0412]: cannot find type `A` in this scope
error[E0412]: cannot find type `A`
--> $DIR/associated-path-shl.rs:5:15
|
LL | let _ = <<A>::B>::C;
| ^ not found in this scope

error[E0412]: cannot find type `A` in this scope
error[E0412]: cannot find type `A`
--> $DIR/associated-path-shl.rs:6:11
|
LL | let <<A>::B>::C;
| ^ not found in this scope

error[E0412]: cannot find type `A` in this scope
error[E0412]: cannot find type `A`
--> $DIR/associated-path-shl.rs:7:17
|
LL | let 0 ..= <<A>::B>::C;
| ^ not found in this scope

error[E0412]: cannot find type `A` in this scope
error[E0412]: cannot find type `A`
--> $DIR/associated-path-shl.rs:8:7
|
LL | <<A>::B>::C;
Expand Down
Loading

0 comments on commit b4c34b6

Please sign in to comment.