Skip to content

Commit 5523db8

Browse files
author
Jonathan Turner
authored
Rollup merge of #35820 - knight42:update-error-msg, r=jonathandturner
Updated E0054, E0423 & E0432 to new error format Fixes #35791, #35796 and #35344, as part of #35233 r? @jonathandturner
2 parents 40f40e6 + 8fdc531 commit 5523db8

26 files changed

+99
-51
lines changed

src/librustc_resolve/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,14 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
336336
err
337337
}
338338
ResolutionError::StructVariantUsedAsFunction(path_name) => {
339-
struct_span_err!(resolver.session,
339+
let mut err = struct_span_err!(resolver.session,
340340
span,
341341
E0423,
342342
"`{}` is the name of a struct or struct variant, but this expression \
343343
uses it like a function name",
344-
path_name)
344+
path_name);
345+
err.span_label(span, &format!("struct called like a function"));
346+
err
345347
}
346348
ResolutionError::SelfNotAvailableInStaticMethod => {
347349
struct_span_err!(resolver.session,
@@ -418,10 +420,14 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
418420
}
419421
ResolutionError::UnresolvedImport(name) => {
420422
let msg = match name {
421-
Some((n, p)) => format!("unresolved import `{}`{}", n, p),
423+
Some((n, _)) => format!("unresolved import `{}`", n),
422424
None => "unresolved import".to_owned(),
423425
};
424-
struct_span_err!(resolver.session, span, E0432, "{}", msg)
426+
let mut err = struct_span_err!(resolver.session, span, E0432, "{}", msg);
427+
if let Some((_, p)) = name {
428+
err.span_label(span, &p);
429+
}
430+
err
425431
}
426432
ResolutionError::FailedToResolve(msg) => {
427433
let mut err = struct_span_err!(resolver.session, span, E0433,

src/librustc_resolve/resolve_imports.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
423423
if let Failed(err) = self.finalize_import(import) {
424424
errors = true;
425425
let (span, help) = match err {
426-
Some((span, msg)) => (span, format!(". {}", msg)),
426+
Some((span, msg)) => (span, msg),
427427
None => (import.span, String::new()),
428428
};
429429

@@ -596,9 +596,9 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
596596
};
597597
let module_str = module_to_string(module);
598598
let msg = if &module_str == "???" {
599-
format!("There is no `{}` in the crate root{}", name, lev_suggestion)
599+
format!("no `{}` in the root{}", name, lev_suggestion)
600600
} else {
601-
format!("There is no `{}` in `{}`{}", name, module_str, lev_suggestion)
601+
format!("no `{}` in `{}`{}", name, module_str, lev_suggestion)
602602
};
603603
Failed(Some((directive.span, msg)))
604604
} else {

src/librustc_typeck/check/cast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
161161
}
162162
CastError::CastToBool => {
163163
struct_span_err!(fcx.tcx.sess, self.span, E0054, "cannot cast as `bool`")
164+
.span_label(self.span, &format!("unsupported cast"))
164165
.help("compare with zero instead")
165166
.emit();
166167
}

src/test/compile-fail/E0423.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ fn main () {
1212
struct Foo { a: bool };
1313

1414
let f = Foo(); //~ ERROR E0423
15+
//~^ struct called like a function
1516
}

src/test/compile-fail/cast-rfc0401.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ fn main()
5959
//~^ ERROR casting
6060
//~^^ HELP through a usize first
6161
let _ = 3_i32 as bool;
62-
//~^ ERROR cannot cast as `bool`
62+
//~^ ERROR cannot cast as `bool` [E0054]
63+
//~| unsupported cast
6364
//~| HELP compare with zero
6465
let _ = E::A as bool;
65-
//~^ ERROR cannot cast as `bool`
66+
//~^ ERROR cannot cast as `bool` [E0054]
67+
//~| unsupported cast
6668
//~| HELP compare with zero
6769
let _ = 0x61u32 as char; //~ ERROR only `u8` can be cast
6870

src/test/compile-fail/import-from-missing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use spam::{ham, eggs};
12-
//~^ ERROR unresolved import `spam::eggs`. There is no `eggs` in `spam`
11+
use spam::{ham, eggs}; //~ ERROR unresolved import `spam::eggs` [E0432]
12+
//~^ no `eggs` in `spam`
1313

1414
mod spam {
1515
pub fn ham() { }

src/test/compile-fail/import.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
// except according to those terms.
1010

1111
use zed::bar;
12-
use zed::baz;
13-
//~^ ERROR unresolved import `zed::baz`. There is no `baz` in `zed`
12+
use zed::baz; //~ ERROR unresolved import `zed::baz` [E0432]
13+
//~^ no `baz` in `zed`. Did you mean to use `bar`?
1414

1515

1616
mod zed {
1717
pub fn bar() { println!("bar"); }
18-
use foo; //~ ERROR unresolved import
18+
use foo; //~ ERROR unresolved import `foo` [E0432]
19+
//~^ no `foo` in the root
1920
}
2021

2122
fn main() {

src/test/compile-fail/import2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use baz::zed::bar;
12-
//~^ ERROR unresolved import `baz::zed::bar`. Could not find `zed` in `baz`
11+
use baz::zed::bar; //~ ERROR unresolved import `baz::zed::bar` [E0432]
12+
//~^ Could not find `zed` in `baz`
1313

1414
mod baz {}
1515
mod zed {

src/test/compile-fail/issue-12612.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ extern crate issue_12612_1 as foo;
1515
use foo::bar;
1616

1717
mod test {
18-
use bar::foo;
19-
//~^ ERROR unresolved import `bar::foo`. Maybe a missing `extern crate bar`?
18+
use bar::foo; //~ ERROR unresolved import `bar::foo` [E0432]
19+
//~^ Maybe a missing `extern crate bar`?
2020
}
2121

2222
fn main() {}

src/test/compile-fail/issue-13404.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// except according to those terms.
1010

1111
use a::f;
12-
use b::f;
13-
//~^ ERROR: unresolved import `b::f`. There is no `f` in `b`
12+
use b::f; //~ ERROR: unresolved import `b::f` [E0432]
13+
//~^ no `f` in `b`
1414

1515
mod a { pub fn f() {} }
1616
mod b { }

0 commit comments

Comments
 (0)