Introduce #[diagnostic::on_type_error(message)]#155200
Introduce #[diagnostic::on_type_error(message)]#155200Unique-Usman wants to merge 1 commit intorust-lang:mainfrom
Conversation
|
Some changes occurred in compiler/rustc_passes/src/check_attr.rs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_attr_parsing cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_hir/src/attrs |
|
r? @davidtwco rustbot has assigned @davidtwco. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
r? estebank |
|
Before you sink more time and effort into this you should explain what you want One expectation I have is that it can specialize for different types. For example if you put this attribute on struct A but the typeerror finds a B or C instead you'll want to emit different messages for them, similar to how the filtering in I'm not convinced this attribute can be implemented in a satisfying way at this time. I'm open to being convinced otherwise though, and am happy to hear your thoughts. |
|
@mejrs two things: I agree that we want filtering in the same way as #[diagnostic::on_type_error(
note = "text",
)]
struct S<T>(T);with an eye for something along the lines of #[diagnostic::on_type_error(
on(expected="Self", found="crate::K", T = "i32", note = "a"),
on(expected="crate::K", found="Self", note = "b"),
note = "c",
)]
struct S<T>(T);some time later. I believe that having the minimal functionality at least lets crate authors include the "filtering information" in the text itself ("if this is the found type, then..." or "if type parameter T is blah, ..."), and that there are already several cases in the std of unconditional addition of notes during error reporting for given types, so I think the minimal functionality is already adding value. For the filtering I would like to share the same parser between on_type_error and on_unimplemented, as it is effectively the same functionality. |
| if let ty::Adt(_, _) = parent_ty.kind() { Some(parent_ty) } else { None } | ||
| } else { | ||
| None | ||
| }; |
There was a problem hiding this comment.
as discussed we shouldn't do this now, only deal with the simple case that can be gleaned from only the expected/found mismatch.
|
Did you two have a discussion about this beforehand? I'd like to read it.
I presume you are talking about this? rust/compiler/rustc_hir_typeck/src/method/suggest.rs Lines 3156 to 3345 in e8e4541 The bit about unwrapping Option/Result is actually really impactful for learners and the way you propose the attribute it should be able to do that sort of thing (minus the inline code suggestions, obviously). So 💯 from me. Let's go for a minimal version for now, like estebank said: #[diagnostic::on_type_error(
note = "text",
)]
struct S<T>(T);I'm a bit worried about this thing being too powerful and showing up in places where authors didn't quite expect or intend. There are after all quite a few ways and places to get type errors. I think the following semantics would be reasonably useful but also restrictive enough to not spook me or the lang people.
Then in the future, when we evolve the attribute forwards, we can specify something like "if you dont supply any filter then this wrapper kind of thing is all it can do". |
There was a discussion initally, it was through video meet though, but, nothing much more than whatever is here actually.
Agreed. |
Suggested-by: Esteban Küber <[email protected]> Signed-off-by: Usman Akinyemi <[email protected]>
c6cbaa7 to
5b090d2
Compare
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
☔ The latest upstream changes (presumably #155380) made this pull request unmergeable. Please resolve the merge conflicts. |
No description provided.