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 {
|
pub fn is_closure(&self) -> bool {
|
||||||
match self.sty {
|
match self.sty {
|
||||||
TyClosure(..) => true,
|
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 {
|
pub fn is_fresh(&self) -> bool {
|
||||||
match self.sty {
|
match self.sty {
|
||||||
TyInfer(FreshTy(_)) => true,
|
TyInfer(FreshTy(_)) => true,
|
||||||
|
|
|
@ -164,12 +164,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
match error {
|
match error {
|
||||||
MethodError::NoMatch(NoMatchData { static_candidates: static_sources,
|
MethodError::NoMatch(NoMatchData {
|
||||||
unsatisfied_predicates,
|
static_candidates: static_sources,
|
||||||
out_of_scope_traits,
|
unsatisfied_predicates,
|
||||||
lev_candidate,
|
out_of_scope_traits,
|
||||||
mode,
|
lev_candidate,
|
||||||
.. }) => {
|
mode,
|
||||||
|
..
|
||||||
|
}) => {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
|
|
||||||
let actual = self.resolve_type_vars_if_possible(&rcvr_ty);
|
let actual = self.resolve_type_vars_if_possible(&rcvr_ty);
|
||||||
|
@ -179,18 +181,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
current scope",
|
current scope",
|
||||||
if mode == Mode::MethodCall {
|
if mode == Mode::MethodCall {
|
||||||
"method"
|
"method"
|
||||||
|
} else if actual.is_enum() {
|
||||||
|
"variant"
|
||||||
} else {
|
} else {
|
||||||
match item_name.as_str().chars().next() {
|
let fresh_ty = actual.is_fresh_ty();
|
||||||
Some(name) => {
|
match (item_name.as_str().chars().next(), fresh_ty) {
|
||||||
if name.is_lowercase() {
|
(Some(name), false) if name.is_lowercase() => {
|
||||||
"function or associated item"
|
"function or associated item"
|
||||||
} else {
|
}
|
||||||
"associated item"
|
(Some(_), false) => "associated item",
|
||||||
}
|
(Some(_), true) | (None, false) => {
|
||||||
},
|
"variant or associated item"
|
||||||
None => {
|
}
|
||||||
""
|
(None, true) => "variant",
|
||||||
},
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
item_name,
|
item_name,
|
||||||
|
|
|
@ -15,6 +15,6 @@ fn main() {
|
||||||
let red: color = color::rgb(255, 0, 0);
|
let red: color = color::rgb(255, 0, 0);
|
||||||
match red {
|
match red {
|
||||||
color::rgb(r, g, b) => { println!("rgb"); }
|
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 value, found struct `XEmpty1`
|
||||||
let xe1 = XEmpty1(); //~ ERROR expected function, 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 variant 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
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ enum Delicious {
|
||||||
Pie = 0x1,
|
Pie = 0x1,
|
||||||
Apple = 0x2,
|
Apple = 0x2,
|
||||||
ApplePie = Delicious::Apple as isize | Delicious::PIE as isize,
|
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() {}
|
fn main() {}
|
||||||
|
|
|
@ -13,5 +13,5 @@ enum Token { LeftParen, RightParen, Plus, Minus, /* etc */ }
|
||||||
fn use_token(token: &Token) { unimplemented!() }
|
fn use_token(token: &Token) { unimplemented!() }
|
||||||
|
|
||||||
fn main() {
|
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 {
|
pub enum SomeEnum {
|
||||||
B = SomeEnum::A,
|
B = SomeEnum::A,
|
||||||
//~^ ERROR no associated item named `A` found for type `SomeEnum`
|
//~^ ERROR no variant named `A` found for type `SomeEnum`
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -16,7 +16,8 @@ enum Foo {
|
||||||
fn main(){
|
fn main(){
|
||||||
foo(|| {
|
foo(|| {
|
||||||
match Foo::Bar(1) {
|
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