-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add ability to attach custom #[on_unimplemented] error messages for unimplemented traits #20889
Conversation
👯 |
6665642
to
6f0419f
Compare
Awesome :] This should be very useful. |
6f0419f
to
6cde8cf
Compare
Cool! |
looks better now, I think we should have an @nikomatsakis your call now :) |
let mut report = None; | ||
ty::each_attr(infcx.tcx, def_id, |item| { | ||
if item.check_name("on_unimplemented") { | ||
match item.meta().node { |
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.
This pair of nested match
s can be if let Some(ref i) = item.value_str() { ... }
.
Yay! I wonder if we need to have a definition-site verification as well as the use-site behaviour, as it stands one will only get validation that the E.g. AFAICT, this will compile fine in isolation #[on_unimplemented = "foo {X}, {Y}, {unclosed"]
pub trait Foo {} |
6cde8cf
to
c671926
Compare
@huonw fixed the other issues |
c671926
to
de683c4
Compare
It's great to see this! But I think the error message should still mention the specific trait ( |
@P1start It is done manually, a |
Oh, wait, I see, you want a placeholder for the trait name. I guess that can be done manually (or I can add a |
…nimplemented traits (fixes rust-lang#20783)
82295a3
to
dc0de42
Compare
@huon I made it a note, and added a lint/test. |
@@ -88,12 +154,20 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>, | |||
infcx.resolve_type_vars_if_possible(trait_predicate); | |||
if !trait_predicate.references_error() { | |||
let trait_ref = trait_predicate.to_poly_trait_ref(); | |||
// Check if it has a custom "#[on_unimplemented]" error message, | |||
// report with that message if it does | |||
let custom_note = report_on_unimplemented(infcx, &*trait_ref.0); |
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.
This is probably best run after the main error message, just in case the span_err
s inside it are triggered, so that the output has a slightly more sensible order.
let custom_note = report_on_unimplemented(infcx, &*trait_ref.0, | ||
obligation.cause.span); | ||
if let Some(s) = custom_note { | ||
infcx.tcx.sess.span_note( |
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.
Indentation
f0e6e8d
to
ad7e33e
Compare
|
||
#[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{C}>`"] | ||
//~^ ERROR there is no type parameter C on trait BadAnnotation2 | ||
trait BadAnnotation2<A,B> {} |
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.
Maybe add a test with an illegal thing, like {}
?
2f5767f
to
02d0a8b
Compare
fixes #20783
r? @nikomatsakis