Skip to content

Commit

Permalink
Rollup merge of rust-lang#35820 - knight42:update-error-msg, r=jonath…
Browse files Browse the repository at this point in the history
…andturner

Updated E0054, E0423 & E0432 to new error format

Fixes rust-lang#35791, rust-lang#35796 and rust-lang#35344, as part of rust-lang#35233

r? @jonathandturner
  • Loading branch information
Jonathan Turner committed Aug 22, 2016
2 parents 40f40e6 + 8fdc531 commit 5523db8
Show file tree
Hide file tree
Showing 26 changed files with 99 additions and 51 deletions.
14 changes: 10 additions & 4 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,14 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
err
}
ResolutionError::StructVariantUsedAsFunction(path_name) => {
struct_span_err!(resolver.session,
let mut err = struct_span_err!(resolver.session,
span,
E0423,
"`{}` is the name of a struct or struct variant, but this expression \
uses it like a function name",
path_name)
path_name);
err.span_label(span, &format!("struct called like a function"));
err
}
ResolutionError::SelfNotAvailableInStaticMethod => {
struct_span_err!(resolver.session,
Expand Down Expand Up @@ -418,10 +420,14 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
}
ResolutionError::UnresolvedImport(name) => {
let msg = match name {
Some((n, p)) => format!("unresolved import `{}`{}", n, p),
Some((n, _)) => format!("unresolved import `{}`", n),
None => "unresolved import".to_owned(),
};
struct_span_err!(resolver.session, span, E0432, "{}", msg)
let mut err = struct_span_err!(resolver.session, span, E0432, "{}", msg);
if let Some((_, p)) = name {
err.span_label(span, &p);
}
err
}
ResolutionError::FailedToResolve(msg) => {
let mut err = struct_span_err!(resolver.session, span, E0433,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
if let Failed(err) = self.finalize_import(import) {
errors = true;
let (span, help) = match err {
Some((span, msg)) => (span, format!(". {}", msg)),
Some((span, msg)) => (span, msg),
None => (import.span, String::new()),
};

Expand Down Expand Up @@ -596,9 +596,9 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
};
let module_str = module_to_string(module);
let msg = if &module_str == "???" {
format!("There is no `{}` in the crate root{}", name, lev_suggestion)
format!("no `{}` in the root{}", name, lev_suggestion)
} else {
format!("There is no `{}` in `{}`{}", name, module_str, lev_suggestion)
format!("no `{}` in `{}`{}", name, module_str, lev_suggestion)
};
Failed(Some((directive.span, msg)))
} else {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_typeck/check/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
}
CastError::CastToBool => {
struct_span_err!(fcx.tcx.sess, self.span, E0054, "cannot cast as `bool`")
.span_label(self.span, &format!("unsupported cast"))
.help("compare with zero instead")
.emit();
}
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/E0423.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ fn main () {
struct Foo { a: bool };

let f = Foo(); //~ ERROR E0423
//~^ struct called like a function
}
6 changes: 4 additions & 2 deletions src/test/compile-fail/cast-rfc0401.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ fn main()
//~^ ERROR casting
//~^^ HELP through a usize first
let _ = 3_i32 as bool;
//~^ ERROR cannot cast as `bool`
//~^ ERROR cannot cast as `bool` [E0054]
//~| unsupported cast
//~| HELP compare with zero
let _ = E::A as bool;
//~^ ERROR cannot cast as `bool`
//~^ ERROR cannot cast as `bool` [E0054]
//~| unsupported cast
//~| HELP compare with zero
let _ = 0x61u32 as char; //~ ERROR only `u8` can be cast

Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/import-from-missing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

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

mod spam {
pub fn ham() { }
Expand Down
7 changes: 4 additions & 3 deletions src/test/compile-fail/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
// except according to those terms.

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


mod zed {
pub fn bar() { println!("bar"); }
use foo; //~ ERROR unresolved import
use foo; //~ ERROR unresolved import `foo` [E0432]
//~^ no `foo` in the root
}

fn main() {
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/import2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

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

mod baz {}
mod zed {
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/issue-12612.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ extern crate issue_12612_1 as foo;
use foo::bar;

mod test {
use bar::foo;
//~^ ERROR unresolved import `bar::foo`. Maybe a missing `extern crate bar`?
use bar::foo; //~ ERROR unresolved import `bar::foo` [E0432]
//~^ Maybe a missing `extern crate bar`?
}

fn main() {}
4 changes: 2 additions & 2 deletions src/test/compile-fail/issue-13404.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// except according to those terms.

use a::f;
use b::f;
//~^ ERROR: unresolved import `b::f`. There is no `f` in `b`
use b::f; //~ ERROR: unresolved import `b::f` [E0432]
//~^ no `f` in `b`

mod a { pub fn f() {} }
mod b { }
Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail/issue-1697.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// Testing that we don't fail abnormally after hitting the errors

use unresolved::*; //~ ERROR unresolved import `unresolved::*`. Maybe a missing `extern crate unres
use unresolved::*; //~ ERROR unresolved import `unresolved::*` [E0432]
//~^ Maybe a missing `extern crate unresolved`?

fn main() {}
4 changes: 3 additions & 1 deletion src/test/compile-fail/issue-18252.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ enum Foo {
}

fn main() {
let f = Foo::Variant(42); //~ ERROR uses it like a function
let f = Foo::Variant(42);
//~^ ERROR uses it like a function
//~| struct called like a function
}
4 changes: 3 additions & 1 deletion src/test/compile-fail/issue-19452.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ enum Homura {
}

fn main() {
let homura = Homura::Madoka; //~ ERROR uses it like a function
let homura = Homura::Madoka;
//~^ ERROR uses it like a function
//~| struct called like a function
}
3 changes: 2 additions & 1 deletion src/test/compile-fail/issue-2937.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use m::f as x; //~ ERROR unresolved import `m::f`. There is no `f` in `m`
use m::f as x; //~ ERROR unresolved import `m::f` [E0432]
//~^ no `f` in `m`

mod m {}

Expand Down
8 changes: 6 additions & 2 deletions src/test/compile-fail/issue-30560.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
// except according to those terms.

type Alias = ();
use Alias::*; //~ ERROR Not a module
use std::io::Result::*; //~ ERROR Not a module
use Alias::*;
//~^ ERROR unresolved import `Alias::*` [E0432]
//~| Not a module `Alias`
use std::io::Result::*;
//~^ ERROR unresolved import `std::io::Result::*` [E0432]
//~| Not a module `Result`

trait T {}
use T::*; //~ ERROR items in traits are not importable
Expand Down
6 changes: 4 additions & 2 deletions src/test/compile-fail/issue-32833.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use bar::Foo; //~ ERROR There is no `Foo` in `bar` [E0432]
use bar::Foo; //~ ERROR unresolved import `bar::Foo` [E0432]
//~^ no `Foo` in `bar`
mod bar {
use Foo; //~ ERROR There is no `Foo` in the crate root [E0432]
use Foo; //~ ERROR unresolved import `Foo` [E0432]
//~^ no `Foo` in the root
}

fn main() {}
3 changes: 2 additions & 1 deletion src/test/compile-fail/issue-5035.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ impl K for isize {} //~ ERROR: `K` is not a trait
//~| NOTE: not a trait
//~| NOTE: aliases cannot be used for traits

use ImportError; //~ ERROR unresolved
use ImportError; //~ ERROR unresolved import `ImportError` [E0432]
//~^ no `ImportError` in the root
impl ImportError for () {} // check that this is not an additional error (c.f. #35142)

fn main() {}
9 changes: 6 additions & 3 deletions src/test/compile-fail/issue-8208.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use self::*; //~ ERROR: unresolved import `self::*`. Cannot glob-import a module into itself.
use self::*; //~ ERROR: unresolved import `self::*` [E0432]
//~^ Cannot glob-import a module into itself.

mod foo {
use foo::*; //~ ERROR: unresolved import `foo::*`. Cannot glob-import a module into itself.
use foo::*; //~ ERROR: unresolved import `foo::*` [E0432]
//~^ Cannot glob-import a module into itself.

mod bar {
use super::bar::*;
//~^ ERROR: unresolved import `super::bar::*`. Cannot glob-import a module into itself.
//~^ ERROR: unresolved import `super::bar::*` [E0432]
//~| Cannot glob-import a module into itself.
}

}
Expand Down
6 changes: 4 additions & 2 deletions src/test/compile-fail/privacy2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ pub fn foo() {}

fn test1() {
use bar::foo;
//~^ ERROR unresolved import `bar::foo`. There is no `foo` in `bar`
//~^ ERROR unresolved import `bar::foo` [E0432]
//~| no `foo` in `bar`
}

fn test2() {
use bar::glob::foo;
//~^ ERROR unresolved import `bar::glob::foo`. There is no `foo` in `bar::glob`
//~^ ERROR unresolved import `bar::glob::foo` [E0432]
//~| no `foo` in `bar::glob`
}

#[start] fn main(_: isize, _: *const *const u8) -> isize { 3 }
3 changes: 2 additions & 1 deletion src/test/compile-fail/privacy3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ pub fn foo() {}

fn test1() {
use bar::gpriv;
//~^ ERROR unresolved import `bar::gpriv`. There is no `gpriv` in `bar`
//~^ ERROR unresolved import `bar::gpriv` [E0432]
//~| no `gpriv` in `bar`

// This should pass because the compiler will insert a fake name binding
// for `gpriv`
Expand Down
12 changes: 8 additions & 4 deletions src/test/compile-fail/resolve_self_super_hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@
mod a {
extern crate collections;
use collections::HashMap;
//~^ ERROR unresolved import `collections::HashMap`. Did you mean `self::collections`?
//~^ ERROR unresolved import `collections::HashMap` [E0432]
//~| Did you mean `self::collections`?
mod b {
use collections::HashMap;
//~^ ERROR unresolved import `collections::HashMap`. Did you mean `a::collections`?
//~^ ERROR unresolved import `collections::HashMap` [E0432]
//~| Did you mean `a::collections`?
mod c {
use collections::HashMap;
//~^ ERROR unresolved import `collections::HashMap`. Did you mean `a::collections`?
//~^ ERROR unresolved import `collections::HashMap` [E0432]
//~| Did you mean `a::collections`?
mod d {
use collections::HashMap;
//~^ ERROR unresolved import `collections::HashMap`. Did you mean `a::collections`?
//~^ ERROR unresolved import `collections::HashMap` [E0432]
//~| Did you mean `a::collections`?
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail/super-at-top-level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use super::f; //~ ERROR unresolved import `super::f`. There are too many initial `super`s.
use super::f; //~ ERROR unresolved import `super::f` [E0432]
//~^ There are too many initial `super`s.

fn main() {
}
12 changes: 8 additions & 4 deletions src/test/compile-fail/unresolved-import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@

// ignore-tidy-linelength

use foo::bar; //~ ERROR unresolved import `foo::bar`. Maybe a missing `extern crate foo`?
use foo::bar; //~ ERROR unresolved import `foo::bar` [E0432]
//~^ Maybe a missing `extern crate foo`?

use bar::Baz as x; //~ ERROR unresolved import `bar::Baz`. There is no `Baz` in `bar`. Did you mean to use `Bar`?
use bar::Baz as x; //~ ERROR unresolved import `bar::Baz` [E0432]
//~^ no `Baz` in `bar`. Did you mean to use `Bar`?

use food::baz; //~ ERROR unresolved import `food::baz`. There is no `baz` in `food`. Did you mean to use `bag`?
use food::baz; //~ ERROR unresolved import `food::baz`
//~^ no `baz` in `food`. Did you mean to use `bag`?

use food::{beens as Foo}; //~ ERROR unresolved import `food::beens`. There is no `beens` in `food`. Did you mean to use `beans`?
use food::{beens as Foo}; //~ ERROR unresolved import `food::beens` [E0432]
//~^ no `beens` in `food`. Did you mean to use `beans`?

mod bar {
pub struct Bar;
Expand Down
6 changes: 4 additions & 2 deletions src/test/compile-fail/use-from-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ use Trait::C;
//~^ ERROR `C` is not directly importable

use Foo::new;
//~^ ERROR unresolved import `Foo::new`. Not a module `Foo`
//~^ ERROR unresolved import `Foo::new` [E0432]
//~| Not a module `Foo`

use Foo::C2;
//~^ ERROR unresolved import `Foo::C2`. Not a module `Foo`
//~^ ERROR unresolved import `Foo::C2` [E0432]
//~| Not a module `Foo`

pub trait Trait {
fn foo();
Expand Down
11 changes: 8 additions & 3 deletions src/test/compile-fail/use-keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@
mod a {
mod b {
use self as A; //~ ERROR `self` imports are only allowed within a { } list
//~^ ERROR unresolved import `self`. There is no `self` in the crate root
use super as B; //~ ERROR unresolved import `super`. There is no `super` in the crate root
use super::{self as C}; //~ERROR unresolved import `super`. There is no `super` in the crate
//~^ ERROR unresolved import `self` [E0432]
//~| no `self` in the root
use super as B;
//~^ ERROR unresolved import `super` [E0432]
//~| no `super` in the root
use super::{self as C};
//~^ ERROR unresolved import `super` [E0432]
//~| no `super` in the root
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/test/compile-fail/use-mod-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@

mod foo {
use self::{self};
//~^ ERROR unresolved import `self`. There is no `self` in the crate root
//~^ ERROR unresolved import `self` [E0432]
//~| no `self` in the root

use super::{self};
//~^ ERROR unresolved import `super`. There is no `super` in the crate root
//~^ ERROR unresolved import `super` [E0432]
//~| no `super` in the root
}

fn main() {}

0 comments on commit 5523db8

Please sign in to comment.