Auto merge of #36761 - jonathandturner:E0425_E0446_E0449, r=nrc
Update E0425, E0446, E0449 This addresses https://github.com/rust-lang/rust/issues/35343, https://github.com/rust-lang/rust/issues/35923, and https://github.com/rust-lang/rust/issues/35924. Part of https://github.com/rust-lang/rust/issues/35233 Specifically, this adds labels to these error messages following the suggestions in the attached bugs. r? @nrc
This commit is contained in:
commit
ea65ab6c7e
18 changed files with 107 additions and 35 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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!("can't leak private type"));
|
||||
err.emit();
|
||||
} else {
|
||||
self.tcx.sess.add_lint(lint::builtin::PRIVATE_IN_PUBLIC,
|
||||
node_id,
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ mod Foo {
|
|||
struct Bar(u32);
|
||||
|
||||
pub fn bar() -> Bar { //~ ERROR E0446
|
||||
//~| NOTE can't leak private type
|
||||
Bar(0)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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 {}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {}
|
||||
|
|
|
|||
|
|
@ -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`?
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ 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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -33,11 +34,14 @@ 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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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!`?
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,5 +13,6 @@
|
|||
fn main() {
|
||||
if foo { //~ NOTE: unclosed delimiter
|
||||
//~^ ERROR: unresolved name `foo`
|
||||
//~| NOTE unresolved name
|
||||
) //~ ERROR: incorrect close delimiter: `)`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
src/test/ui/span/typo-suggestion.stderr
Normal file
14
src/test/ui/span/typo-suggestion.stderr
Normal file
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue