Skip to content

Commit

Permalink
Update E0425, E0446, E0449
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Turner committed Sep 26, 2016
1 parent 8ccfc69 commit 2fa91b2
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 35 deletions.
5 changes: 4 additions & 1 deletion src/librustc_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ impl<'a> AstValidator<'a> {
span,
E0449,
"unnecessary visibility qualifier");
if vis == &Visibility::Public {
err.span_label(span, &format!("`pub` not needed here"));
}
if let Some(note) = note {
err.span_note(span, note);
err.note(note);
}
err.emit();
}
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,8 +972,10 @@ impl<'a, 'tcx: 'a, 'v> Visitor<'v> for SearchInterfaceForPrivateItemsVisitor<'a,
if !vis.is_at_least(self.required_visibility, &self.tcx.map) {
if self.tcx.sess.features.borrow().pub_restricted ||
self.old_error_set.contains(&ty.id) {
span_err!(self.tcx.sess, ty.span, E0446,
let mut err = struct_span_err!(self.tcx.sess, ty.span, E0446,
"private type in public interface");
err.span_label(ty.span, &format!("private type can't be public"));
err.emit();
} else {
self.tcx.sess.add_lint(lint::builtin::PRIVATE_IN_PUBLIC,
node_id,
Expand Down
13 changes: 9 additions & 4 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,14 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
let mut err = struct_span_err!(resolver.session,
span,
E0425,
"unresolved name `{}`{}",
path,
msg);
"unresolved name `{}`",
path);
if msg != "" {
err.span_label(span, &msg);
} else {
err.span_label(span, &format!("unresolved name"));
}

match context {
UnresolvedNameContext::Other => {
if msg.is_empty() && is_static_method && is_field {
Expand Down Expand Up @@ -2941,7 +2946,7 @@ impl<'a> Resolver<'a> {
let mut context = UnresolvedNameContext::Other;
let mut def = Def::Err;
if !msg.is_empty() {
msg = format!(". Did you mean {}?", msg);
msg = format!("did you mean {}?", msg);
} else {
// we display a help message if this is a module
let name_path = path.segments.iter()
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/E0033.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ trait SomeTrait {
fn main() {
let trait_obj: &SomeTrait = SomeTrait;
//~^ ERROR E0425
//~| NOTE unresolved name
//~| ERROR E0038
//~| method `foo` has no receiver
//~| NOTE the trait `SomeTrait` cannot be made into an object
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/E0446.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod Foo {
struct Bar(u32);

pub fn bar() -> Bar { //~ ERROR E0446
//~| NOTE private type can't be public
Bar(0)
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/test/compile-fail/E0449.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ trait Foo {
}

pub impl Bar {} //~ ERROR E0449
//~| NOTE `pub` not needed here
//~| NOTE place qualifiers on individual impl items instead

pub impl Foo for Bar { //~ ERROR E0449
//~| NOTE `pub` not needed here
pub fn foo() {} //~ ERROR E0449
//~| NOTE `pub` not needed here
}

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

// error-pattern: unresolved name `m1::arguments`. Did you mean `arguments`?
// error-pattern: unresolved name `m1::arguments`

mod m1 {}

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/bad-expr-path2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern: unresolved name `m1::arguments`. Did you mean `arguments`?
// error-pattern: unresolved name `m1::arguments`

mod m1 {
pub mod arguments {}
Expand Down
62 changes: 43 additions & 19 deletions src/test/compile-fail/issue-14254.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,87 +27,111 @@ impl BarTy {
impl Foo for *const BarTy {
fn bar(&self) {
baz();
//~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`?
//~^ ERROR: unresolved name `baz`
//~| NOTE did you mean to call `self.baz`?
a;
//~^ ERROR: unresolved name `a`
//~| NOTE unresolved name
}
}

impl<'a> Foo for &'a BarTy {
fn bar(&self) {
baz();
//~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`?
//~^ ERROR: unresolved name `baz`
//~| NOTE did you mean to call `self.baz`?
x;
//~^ ERROR: unresolved name `x`. Did you mean `self.x`?
//~^ ERROR: unresolved name `x`
//~| NOTE did you mean `self.x`?
y;
//~^ ERROR: unresolved name `y`. Did you mean `self.y`?
//~^ ERROR: unresolved name `y`
//~| NOTE did you mean `self.y`?
a;
//~^ ERROR: unresolved name `a`
//~| NOTE unresolved name
bah;
//~^ ERROR: unresolved name `bah`. Did you mean to call `Foo::bah`?
//~^ ERROR: unresolved name `bah`
//~| NOTE did you mean to call `Foo::bah`?
b;
//~^ ERROR: unresolved name `b`
//~| NOTE unresolved name
}
}

impl<'a> Foo for &'a mut BarTy {
fn bar(&self) {
baz();
//~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`?
//~^ ERROR: unresolved name `baz`
//~| NOTE did you mean to call `self.baz`?
x;
//~^ ERROR: unresolved name `x`. Did you mean `self.x`?
//~^ ERROR: unresolved name `x`
//~| NOTE did you mean `self.x`?
y;
//~^ ERROR: unresolved name `y`. Did you mean `self.y`?
//~^ ERROR: unresolved name `y`
//~| NOTE did you mean `self.y`?
a;
//~^ ERROR: unresolved name `a`
//~| NOTE unresolved name
bah;
//~^ ERROR: unresolved name `bah`. Did you mean to call `Foo::bah`?
//~^ ERROR: unresolved name `bah`
//~| NOTE did you mean to call `Foo::bah`?
b;
//~^ ERROR: unresolved name `b`
//~| NOTE unresolved name
}
}

impl Foo for Box<BarTy> {
fn bar(&self) {
baz();
//~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`?
//~^ ERROR: unresolved name `baz`
//~| NOTE did you mean to call `self.baz`?
bah;
//~^ ERROR: unresolved name `bah`. Did you mean to call `Foo::bah`?
//~^ ERROR: unresolved name `bah`
//~| NOTE did you mean to call `Foo::bah`?
}
}

impl Foo for *const isize {
fn bar(&self) {
baz();
//~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`?
//~^ ERROR: unresolved name `baz`
//~| NOTE did you mean to call `self.baz`?
bah;
//~^ ERROR: unresolved name `bah`. Did you mean to call `Foo::bah`?
//~^ ERROR: unresolved name `bah`
//~| NOTE did you mean to call `Foo::bah`?
}
}

impl<'a> Foo for &'a isize {
fn bar(&self) {
baz();
//~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`?
//~^ ERROR: unresolved name `baz`
//~| NOTE did you mean to call `self.baz`?
bah;
//~^ ERROR: unresolved name `bah`. Did you mean to call `Foo::bah`?
//~^ ERROR: unresolved name `bah`
//~| NOTE did you mean to call `Foo::bah`?
}
}

impl<'a> Foo for &'a mut isize {
fn bar(&self) {
baz();
//~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`?
//~^ ERROR: unresolved name `baz`
//~| NOTE did you mean to call `self.baz`?
bah;
//~^ ERROR: unresolved name `bah`. Did you mean to call `Foo::bah`?
//~^ ERROR: unresolved name `bah`
//~| NOTE did you mean to call `Foo::bah`?
}
}

impl Foo for Box<isize> {
fn bar(&self) {
baz();
//~^ ERROR: unresolved name `baz`. Did you mean to call `self.baz`?
//~^ ERROR: unresolved name `baz`
//~| NOTE did you mean to call `self.baz`?
bah;
//~^ ERROR: unresolved name `bah`. Did you mean to call `Foo::bah`?
//~^ ERROR: unresolved name `bah`
//~| NOTE did you mean to call `Foo::bah`?
}
}
18 changes: 16 additions & 2 deletions src/test/compile-fail/issue-2356.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@ impl MaybeDog {
// If this provides a suggestion, it's a bug as MaybeDog doesn't impl Groom
shave();
//~^ ERROR: unresolved name `shave`
//~| NOTE unresolved name
}
}

impl Groom for cat {
fn shave(other: usize) {
whiskers -= other;
//~^ ERROR: unresolved name `whiskers`
//~| NOTE unresolved name
//~| HELP this is an associated function
shave(4);
//~^ ERROR: unresolved name `shave`. Did you mean to call `Groom::shave`?
//~^ ERROR: unresolved name `shave`
//~| NOTE did you mean to call `Groom::shave`?
purr();
//~^ ERROR: unresolved name `purr`
//~| NOTE unresolved name
}
}

Expand All @@ -47,12 +51,16 @@ impl cat {
fn purr_louder() {
static_method();
//~^ ERROR: unresolved name `static_method`
//~| NOTE unresolved name
purr();
//~^ ERROR: unresolved name `purr`
//~| NOTE unresolved name
purr();
//~^ ERROR: unresolved name `purr`
//~| NOTE unresolved name
purr();
//~^ ERROR: unresolved name `purr`
//~| NOTE unresolved name
}
}

Expand All @@ -69,27 +77,33 @@ impl cat {
fn purr(&self) {
grow_older();
//~^ ERROR: unresolved name `grow_older`
//~| NOTE unresolved name
shave();
//~^ ERROR: unresolved name `shave`
//~| NOTE unresolved name
}

fn burn_whiskers(&mut self) {
whiskers = 0;
//~^ ERROR: unresolved name `whiskers`. Did you mean `self.whiskers`?
//~^ ERROR: unresolved name `whiskers`
//~| NOTE did you mean `self.whiskers`?
}

pub fn grow_older(other:usize) {
whiskers = 4;
//~^ ERROR: unresolved name `whiskers`
//~| NOTE unresolved name
//~| HELP this is an associated function
purr_louder();
//~^ ERROR: unresolved name `purr_louder`
//~| NOTE unresolved name
}
}

fn main() {
self += 1;
//~^ ERROR: unresolved name `self`
//~| NOTE unresolved name
//~| HELP: module `self`
// it's a bug if this suggests a missing `self` as we're not in a method
}
4 changes: 3 additions & 1 deletion src/test/compile-fail/resolve-hint-macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
// except according to those terms.

fn main() {
assert(true); //~ERROR unresolved name `assert`. Did you mean the macro `assert!`?
assert(true);
//~^ ERROR unresolved name `assert`
//~| NOTE did you mean the macro `assert!`?
}
1 change: 1 addition & 0 deletions src/test/compile-fail/token-error-correct-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
fn main() {
if foo { //~ NOTE: unclosed delimiter
//~^ ERROR: unresolved name `foo`
//~| NOTE unresolved name
) //~ ERROR: incorrect close delimiter: `)`
}
1 change: 1 addition & 0 deletions src/test/compile-fail/token-error-correct-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod raw {
callback: F)
-> io::Result<bool> {
if !is_directory(path.as_ref()) { //~ ERROR: unresolved name `is_directory`
//~| NOTE unresolved name
callback(path.as_ref(); //~ NOTE: unclosed delimiter
//~^ ERROR: expected one of
fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/token-error-correct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ fn main() {
//~^^^ ERROR: unresolved name `bar`
//~^^^^ ERROR: unresolved name `foo`
//~^^^^^ ERROR: expected one of `)`, `,`, `.`, `<`, `?`
//~| NOTE unresolved name
//~| NOTE unresolved name
} //~ ERROR: incorrect close delimiter: `}`
//~^ ERROR: incorrect close delimiter: `}`
//~^^ ERROR: expected expression, found `)`
2 changes: 1 addition & 1 deletion src/test/ui/codemap_tests/tab.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0425]: unresolved name `bar`
--> $DIR/tab.rs:14:2
|
14 | \tbar;
| \t^^^
| \t^^^ unresolved name

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/macros/macro-backtrace-nested.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0425]: unresolved name `fake`
--> $DIR/macro-backtrace-nested.rs:15:12
|
15 | () => (fake)
| ^^^^
| ^^^^ unresolved name
...
27 | 1 + call_nested_expr!();
| ------------------- in this macro invocation
Expand All @@ -11,7 +11,7 @@ error[E0425]: unresolved name `fake`
--> $DIR/macro-backtrace-nested.rs:15:12
|
15 | () => (fake)
| ^^^^
| ^^^^ unresolved name
...
28 | call_nested_expr_sum!();
| ------------------------ in this macro invocation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ fn main() {

// `foo` shouldn't be suggested, it is too dissimilar from `bar`.
println!("Hello {}", bar);
//~^ ERROR: unresolved name `bar`

// But this is close enough.
println!("Hello {}", fob);
//~^ ERROR: unresolved name `fob`. Did you mean `foo`?
}
14 changes: 14 additions & 0 deletions src/test/ui/span/typo-suggestion.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0425]: unresolved name `bar`
--> $DIR/typo-suggestion.rs:15:26
|
15 | println!("Hello {}", bar);
| ^^^ unresolved name

error[E0425]: unresolved name `fob`
--> $DIR/typo-suggestion.rs:18:26
|
18 | println!("Hello {}", fob);
| ^^^ did you mean `foo`?

error: aborting due to 2 previous errors

0 comments on commit 2fa91b2

Please sign in to comment.