-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Use the proper term when using non-existing variant #46024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,41 +164,63 @@ 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); | ||
let ty_string = self.ty_to_string(actual); | ||
let is_method = mode == Mode::MethodCall; | ||
let type_str = if is_method { | ||
"method" | ||
} else if actual.is_enum() { | ||
"variant" | ||
} else { | ||
match (item_name.as_str().chars().next(), actual.is_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", | ||
} | ||
}; | ||
let mut err = if !actual.references_error() { | ||
struct_span_err!(tcx.sess, span, E0599, | ||
"no {} named `{}` found for type `{}` in the \ | ||
current scope", | ||
if mode == Mode::MethodCall { | ||
"method" | ||
} else { | ||
match item_name.as_str().chars().next() { | ||
Some(name) => { | ||
if name.is_lowercase() { | ||
"function or associated item" | ||
} else { | ||
"associated item" | ||
} | ||
}, | ||
None => { | ||
"" | ||
}, | ||
} | ||
}, | ||
item_name, | ||
self.ty_to_string(actual)) | ||
struct_span_err!( | ||
tcx.sess, | ||
span, | ||
E0599, | ||
"no {} named `{}` found for type `{}` in the current scope", | ||
type_str, | ||
item_name, | ||
ty_string | ||
) | ||
} else { | ||
self.tcx.sess.diagnostic().struct_dummy() | ||
tcx.sess.diagnostic().struct_dummy() | ||
}; | ||
|
||
if let Some(def) = actual.ty_adt_def() { | ||
if let Some(full_sp) = tcx.hir.span_if_local(def.did) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @oli-obk I don't know if this will actually do what I want it to do. After the test suite runs I'll see. If the output is still suboptimal, I'll leave the PR with only the first commit for merging. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks on travis like it's doing the right thing now |
||
let def_sp = tcx.sess.codemap().def_span(full_sp); | ||
err.span_label(def_sp, format!("{} `{}` not found {}", | ||
type_str, | ||
item_name, | ||
if def.is_enum() && !is_method { | ||
"here" | ||
} else { | ||
"for this" | ||
})); | ||
} | ||
} | ||
|
||
// If the method name is the name of a field with a function or closure type, | ||
// give a helping note that it has to be called as (x.f)(...). | ||
if let Some(expr) = rcvr_expr { | ||
|
@@ -240,6 +262,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { | |
_ => {} | ||
} | ||
} | ||
} else { | ||
err.span_label(span, format!("{} not found in `{}`", type_str, ty_string)); | ||
} | ||
|
||
if self.is_fn_ty(&rcvr_ty, span) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this context nothing suggests for sure that (I'm basically adding a "rewrite this from scratch" item in my TODO list now.) |
||
let xe3 = XE::Empty3(); //~ ERROR no variant named `Empty3` found for type | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add tests for all these new variations of diagnostics?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done