Skip to content

Commit

Permalink
Auto merge of #126810 - estebank:resolve-error-wording, r=BoxyUwU
Browse files Browse the repository at this point in the history
Remove redundancy in resolve error between main message and primary label

```
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 will concatenate the main message and the primary labels, so they should be complementary.
  • Loading branch information
bors committed Jun 23, 2024
2 parents bcf94de + 1e450c7 commit 84e6a0c
Show file tree
Hide file tree
Showing 736 changed files with 1,572 additions and 1,572 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
4 changes: 2 additions & 2 deletions tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct InvalidLitNestedAttr {}

#[derive(Diagnostic)]
#[diag(nonsense, code = E0123)]
//~^ ERROR cannot find value `nonsense` in module `crate::fluent_generated`
//~^ ERROR cannot find value `nonsense`
struct InvalidNestedStructAttr {}

#[derive(Diagnostic)]
Expand Down Expand Up @@ -805,7 +805,7 @@ struct SuggestionsInvalidItem {
sub: Span,
}

#[derive(Diagnostic)] //~ ERROR cannot find value `__code_34` in this scope
#[derive(Diagnostic)] //~ ERROR cannot find value `__code_34`
#[diag(no_crate_example)]
struct SuggestionsInvalidLiteral {
#[suggestion(code = 3)]
Expand Down
6 changes: 3 additions & 3 deletions tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,13 @@ error: cannot find attribute `multipart_suggestion` in this scope
LL | #[multipart_suggestion(no_crate_suggestion)]
| ^^^^^^^^^^^^^^^^^^^^

error[E0425]: cannot find value `nonsense` in module `crate::fluent_generated`
error[E0425]: cannot find value `nonsense`
--> $DIR/diagnostic-derive.rs:75:8
|
LL | #[diag(nonsense, code = E0123)]
| ^^^^^^^^ not found in `crate::fluent_generated`
| ^^^^^^^^ not found in module `crate::fluent_generated`

error[E0425]: cannot find value `__code_34` in this scope
error[E0425]: cannot find value `__code_34`
--> $DIR/diagnostic-derive.rs:808:10
|
LL | #[derive(Diagnostic)]
Expand Down
8 changes: 4 additions & 4 deletions tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct D {
#[derive(Subdiagnostic)]
#[foo]
//~^ ERROR `#[foo]` is not a valid attribute
//~^^ ERROR cannot find attribute `foo` in this scope
//~^^ ERROR cannot find attribute `foo`
struct E {
#[primary_span]
span: Span,
Expand Down Expand Up @@ -124,8 +124,8 @@ struct K {

#[derive(Subdiagnostic)]
#[label(slug)]
//~^ ERROR cannot find value `slug` in module `crate::fluent_generated`
//~^^ NOTE not found in `crate::fluent_generated`
//~^ ERROR cannot find value `slug`
//~^^ NOTE not found in module `crate::fluent_generated`
struct L {
#[primary_span]
span: Span,
Expand Down Expand Up @@ -712,7 +712,7 @@ struct BP {
}

#[derive(Subdiagnostic)]
//~^ ERROR cannot find value `__code_29` in this scope
//~^ ERROR cannot find value `__code_29`
//~| NOTE in this expansion
//~| NOTE not found in this scope
#[multipart_suggestion(no_crate_example)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,13 +553,13 @@ error: cannot find attribute `bar` in this scope
LL | #[bar("...")]
| ^^^

error[E0425]: cannot find value `slug` in module `crate::fluent_generated`
error[E0425]: cannot find value `slug`
--> $DIR/subdiagnostic-derive.rs:126:9
|
LL | #[label(slug)]
| ^^^^ not found in `crate::fluent_generated`
| ^^^^ not found in module `crate::fluent_generated`

error[E0425]: cannot find value `__code_29` in this scope
error[E0425]: cannot find value `__code_29`
--> $DIR/subdiagnostic-derive.rs:714:10
|
LL | #[derive(Subdiagnostic)]
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
}
Loading

0 comments on commit 84e6a0c

Please sign in to comment.