From 820c8101077c430e6fc10481782f5df0862c279c Mon Sep 17 00:00:00 2001 From: Knight Date: Mon, 22 Aug 2016 13:51:21 +0800 Subject: [PATCH 1/3] Updated E0054 to new format --- src/librustc_typeck/check/cast.rs | 1 + src/test/compile-fail/cast-rfc0401.rs | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index fb78d3a37ca23..54e63497e6202 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -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(); } diff --git a/src/test/compile-fail/cast-rfc0401.rs b/src/test/compile-fail/cast-rfc0401.rs index 05c531e91f128..7839fb45d1c34 100644 --- a/src/test/compile-fail/cast-rfc0401.rs +++ b/src/test/compile-fail/cast-rfc0401.rs @@ -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 From a4c6307a157eaf8f9292f2456d7b5055a0b69ea4 Mon Sep 17 00:00:00 2001 From: Knight Date: Mon, 22 Aug 2016 13:57:10 +0800 Subject: [PATCH 2/3] Updated E0432 to new format --- src/librustc_resolve/lib.rs | 8 ++++++-- src/librustc_resolve/resolve_imports.rs | 6 +++--- src/test/compile-fail/import-from-missing.rs | 4 ++-- src/test/compile-fail/import.rs | 7 ++++--- src/test/compile-fail/import2.rs | 4 ++-- src/test/compile-fail/issue-12612.rs | 4 ++-- src/test/compile-fail/issue-13404.rs | 4 ++-- src/test/compile-fail/issue-1697.rs | 3 ++- src/test/compile-fail/issue-2937.rs | 3 ++- src/test/compile-fail/issue-30560.rs | 8 ++++++-- src/test/compile-fail/issue-32833.rs | 6 ++++-- src/test/compile-fail/issue-5035.rs | 3 ++- src/test/compile-fail/issue-8208.rs | 9 ++++++--- src/test/compile-fail/privacy2.rs | 6 ++++-- src/test/compile-fail/privacy3.rs | 3 ++- src/test/compile-fail/resolve_self_super_hint.rs | 12 ++++++++---- src/test/compile-fail/super-at-top-level.rs | 3 ++- src/test/compile-fail/unresolved-import.rs | 12 ++++++++---- src/test/compile-fail/use-from-trait.rs | 6 ++++-- src/test/compile-fail/use-keyword.rs | 11 ++++++++--- src/test/compile-fail/use-mod-2.rs | 6 ++++-- 21 files changed, 83 insertions(+), 45 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 0c0582edcc051..e2c9e4aca57dc 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -418,10 +418,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, diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index c0a9ee1c48380..8c6d89c29bde1 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -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()), }; @@ -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 { diff --git a/src/test/compile-fail/import-from-missing.rs b/src/test/compile-fail/import-from-missing.rs index bcd2cd816ed45..220b255bde419 100644 --- a/src/test/compile-fail/import-from-missing.rs +++ b/src/test/compile-fail/import-from-missing.rs @@ -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() { } diff --git a/src/test/compile-fail/import.rs b/src/test/compile-fail/import.rs index ff93cd0f06624..1ca1c060410ad 100644 --- a/src/test/compile-fail/import.rs +++ b/src/test/compile-fail/import.rs @@ -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() { diff --git a/src/test/compile-fail/import2.rs b/src/test/compile-fail/import2.rs index 1f25bce209314..f5b03f9b2e971 100644 --- a/src/test/compile-fail/import2.rs +++ b/src/test/compile-fail/import2.rs @@ -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 { diff --git a/src/test/compile-fail/issue-12612.rs b/src/test/compile-fail/issue-12612.rs index f76d12d93fdf6..20943bd0ea077 100644 --- a/src/test/compile-fail/issue-12612.rs +++ b/src/test/compile-fail/issue-12612.rs @@ -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() {} diff --git a/src/test/compile-fail/issue-13404.rs b/src/test/compile-fail/issue-13404.rs index 355be1562df2b..0059e92e07f07 100644 --- a/src/test/compile-fail/issue-13404.rs +++ b/src/test/compile-fail/issue-13404.rs @@ -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 { } diff --git a/src/test/compile-fail/issue-1697.rs b/src/test/compile-fail/issue-1697.rs index f2d858391cea2..dc09af0ada66f 100644 --- a/src/test/compile-fail/issue-1697.rs +++ b/src/test/compile-fail/issue-1697.rs @@ -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() {} diff --git a/src/test/compile-fail/issue-2937.rs b/src/test/compile-fail/issue-2937.rs index e4fae73b18991..0d684ec5ae19b 100644 --- a/src/test/compile-fail/issue-2937.rs +++ b/src/test/compile-fail/issue-2937.rs @@ -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 {} diff --git a/src/test/compile-fail/issue-30560.rs b/src/test/compile-fail/issue-30560.rs index 71c7e6009655b..b0cfd8714fc02 100644 --- a/src/test/compile-fail/issue-30560.rs +++ b/src/test/compile-fail/issue-30560.rs @@ -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 diff --git a/src/test/compile-fail/issue-32833.rs b/src/test/compile-fail/issue-32833.rs index 22261d98a128c..d610e8b483798 100644 --- a/src/test/compile-fail/issue-32833.rs +++ b/src/test/compile-fail/issue-32833.rs @@ -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() {} diff --git a/src/test/compile-fail/issue-5035.rs b/src/test/compile-fail/issue-5035.rs index c2154e8a6c0b6..7a36012925eed 100644 --- a/src/test/compile-fail/issue-5035.rs +++ b/src/test/compile-fail/issue-5035.rs @@ -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() {} diff --git a/src/test/compile-fail/issue-8208.rs b/src/test/compile-fail/issue-8208.rs index 318089b3030f6..670b6bd46e7d8 100644 --- a/src/test/compile-fail/issue-8208.rs +++ b/src/test/compile-fail/issue-8208.rs @@ -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. } } diff --git a/src/test/compile-fail/privacy2.rs b/src/test/compile-fail/privacy2.rs index abf702204d16b..376e95312b8fb 100644 --- a/src/test/compile-fail/privacy2.rs +++ b/src/test/compile-fail/privacy2.rs @@ -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 } diff --git a/src/test/compile-fail/privacy3.rs b/src/test/compile-fail/privacy3.rs index 89f38fa143445..b841717bd11d8 100644 --- a/src/test/compile-fail/privacy3.rs +++ b/src/test/compile-fail/privacy3.rs @@ -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` diff --git a/src/test/compile-fail/resolve_self_super_hint.rs b/src/test/compile-fail/resolve_self_super_hint.rs index ed143fdff687f..a23ac80fca620 100644 --- a/src/test/compile-fail/resolve_self_super_hint.rs +++ b/src/test/compile-fail/resolve_self_super_hint.rs @@ -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`? } } } diff --git a/src/test/compile-fail/super-at-top-level.rs b/src/test/compile-fail/super-at-top-level.rs index f59caef463136..7d11ff6c9b54d 100644 --- a/src/test/compile-fail/super-at-top-level.rs +++ b/src/test/compile-fail/super-at-top-level.rs @@ -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() { } diff --git a/src/test/compile-fail/unresolved-import.rs b/src/test/compile-fail/unresolved-import.rs index b60d19fcab4aa..d1254f3f5241b 100644 --- a/src/test/compile-fail/unresolved-import.rs +++ b/src/test/compile-fail/unresolved-import.rs @@ -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; diff --git a/src/test/compile-fail/use-from-trait.rs b/src/test/compile-fail/use-from-trait.rs index 28e933bc7aa0a..58e37bbfa3ea7 100644 --- a/src/test/compile-fail/use-from-trait.rs +++ b/src/test/compile-fail/use-from-trait.rs @@ -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(); diff --git a/src/test/compile-fail/use-keyword.rs b/src/test/compile-fail/use-keyword.rs index 040db0255678d..6df20d414a788 100644 --- a/src/test/compile-fail/use-keyword.rs +++ b/src/test/compile-fail/use-keyword.rs @@ -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 } } diff --git a/src/test/compile-fail/use-mod-2.rs b/src/test/compile-fail/use-mod-2.rs index f2384912cdba3..5f8842a521abd 100644 --- a/src/test/compile-fail/use-mod-2.rs +++ b/src/test/compile-fail/use-mod-2.rs @@ -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() {} From 8fdc53144615760a6c6f532a20d487e5b948167a Mon Sep 17 00:00:00 2001 From: Knight Date: Mon, 22 Aug 2016 13:57:37 +0800 Subject: [PATCH 3/3] Updated E0423 to new format --- src/librustc_resolve/lib.rs | 6 ++++-- src/test/compile-fail/E0423.rs | 1 + src/test/compile-fail/issue-18252.rs | 4 +++- src/test/compile-fail/issue-19452.rs | 4 +++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index e2c9e4aca57dc..6bf4da438dd20 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -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, diff --git a/src/test/compile-fail/E0423.rs b/src/test/compile-fail/E0423.rs index f5fea77cf9639..98b700984a707 100644 --- a/src/test/compile-fail/E0423.rs +++ b/src/test/compile-fail/E0423.rs @@ -12,4 +12,5 @@ fn main () { struct Foo { a: bool }; let f = Foo(); //~ ERROR E0423 + //~^ struct called like a function } diff --git a/src/test/compile-fail/issue-18252.rs b/src/test/compile-fail/issue-18252.rs index e3e56c7f97ad5..8e3faca02b7d1 100644 --- a/src/test/compile-fail/issue-18252.rs +++ b/src/test/compile-fail/issue-18252.rs @@ -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 } diff --git a/src/test/compile-fail/issue-19452.rs b/src/test/compile-fail/issue-19452.rs index 2270ba594ad2b..15d5d2b80c31d 100644 --- a/src/test/compile-fail/issue-19452.rs +++ b/src/test/compile-fail/issue-19452.rs @@ -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 }