Use the proper term when using non-existing variant
When using a non-existing variant, function or associated item, refer to the proper term, instead of defaulting to "associated item" in diagnostics.
This commit is contained in:
parent
783c6ec55d
commit
6a972cd855
8 changed files with 44 additions and 24 deletions
|
@ -1219,6 +1219,15 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_enum(&self) -> bool {
|
||||
match self.sty {
|
||||
TyAdt(adt_def, _) => {
|
||||
adt_def.is_enum()
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_closure(&self) -> bool {
|
||||
match self.sty {
|
||||
TyClosure(..) => true,
|
||||
|
@ -1233,6 +1242,13 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_fresh_ty(&self) -> bool {
|
||||
match self.sty {
|
||||
TyInfer(FreshTy(_)) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_fresh(&self) -> bool {
|
||||
match self.sty {
|
||||
TyInfer(FreshTy(_)) => true,
|
||||
|
|
|
@ -164,12 +164,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
};
|
||||
|
||||
match error {
|
||||
MethodError::NoMatch(NoMatchData { static_candidates: static_sources,
|
||||
unsatisfied_predicates,
|
||||
out_of_scope_traits,
|
||||
lev_candidate,
|
||||
mode,
|
||||
.. }) => {
|
||||
MethodError::NoMatch(NoMatchData {
|
||||
static_candidates: static_sources,
|
||||
unsatisfied_predicates,
|
||||
out_of_scope_traits,
|
||||
lev_candidate,
|
||||
mode,
|
||||
..
|
||||
}) => {
|
||||
let tcx = self.tcx;
|
||||
|
||||
let actual = self.resolve_type_vars_if_possible(&rcvr_ty);
|
||||
|
@ -179,18 +181,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
current scope",
|
||||
if mode == Mode::MethodCall {
|
||||
"method"
|
||||
} else if actual.is_enum() {
|
||||
"variant"
|
||||
} else {
|
||||
match item_name.as_str().chars().next() {
|
||||
Some(name) => {
|
||||
if name.is_lowercase() {
|
||||
"function or associated item"
|
||||
} else {
|
||||
"associated item"
|
||||
}
|
||||
},
|
||||
None => {
|
||||
""
|
||||
},
|
||||
let fresh_ty = actual.is_fresh_ty();
|
||||
match (item_name.as_str().chars().next(), fresh_ty) {
|
||||
(Some(name), false) if name.is_lowercase() => {
|
||||
"function or associated item"
|
||||
}
|
||||
(Some(_), false) => "associated item",
|
||||
(Some(_), true) | (None, false) => {
|
||||
"variant or associated item"
|
||||
}
|
||||
(None, true) => "variant",
|
||||
}
|
||||
},
|
||||
item_name,
|
||||
|
|
|
@ -15,6 +15,6 @@ fn main() {
|
|||
let red: color = color::rgb(255, 0, 0);
|
||||
match red {
|
||||
color::rgb(r, g, b) => { println!("rgb"); }
|
||||
color::hsl(h, s, l) => { println!("hsl"); } //~ ERROR no function
|
||||
color::hsl(h, s, l) => { println!("hsl"); } //~ ERROR no variant
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,6 @@ fn main() {
|
|||
|
||||
let xe1 = XEmpty1; //~ ERROR expected value, found struct `XEmpty1`
|
||||
let xe1 = XEmpty1(); //~ ERROR expected function, found struct `XEmpty1`
|
||||
let xe3 = XE::Empty3; //~ ERROR no associated item named `Empty3` found for type
|
||||
let xe3 = XE::Empty3(); //~ ERROR no associated item named `Empty3` found for type
|
||||
let xe3 = XE::Empty3; //~ ERROR no variant named `Empty3` found for type
|
||||
let xe3 = XE::Empty3(); //~ ERROR no variant named `Empty3` found for type
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ enum Delicious {
|
|||
Pie = 0x1,
|
||||
Apple = 0x2,
|
||||
ApplePie = Delicious::Apple as isize | Delicious::PIE as isize,
|
||||
//~^ ERROR no associated item named `PIE` found for type `Delicious`
|
||||
//~^ ERROR no variant named `PIE` found for type `Delicious`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -13,5 +13,5 @@ enum Token { LeftParen, RightParen, Plus, Minus, /* etc */ }
|
|||
fn use_token(token: &Token) { unimplemented!() }
|
||||
|
||||
fn main() {
|
||||
use_token(&Token::Homura); //~ ERROR no associated item named
|
||||
use_token(&Token::Homura); //~ ERROR no variant named `Homura`
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
pub enum SomeEnum {
|
||||
B = SomeEnum::A,
|
||||
//~^ ERROR no associated item named `A` found for type `SomeEnum`
|
||||
//~^ ERROR no variant named `A` found for type `SomeEnum`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -16,7 +16,8 @@ enum Foo {
|
|||
fn main(){
|
||||
foo(|| {
|
||||
match Foo::Bar(1) {
|
||||
Foo::Baz(..) => (), //~ ERROR no associated
|
||||
Foo::Baz(..) => (),
|
||||
//~^ ERROR no variant named `Baz` found for type `Foo`
|
||||
_ => (),
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue