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
Improve diagnostic output the non_local_definitions
lint
#125089
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
0c69265
to
2819950
Compare
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.
feel free to "nah actually" I am just trying to throw a couple wording ideas at the wall.
I pushed several more commits that tries to improve the clarity the message were are trying to pass, mainly by moving the "move help message" to a separate span with some labels.
|
9a5bb1f
to
a39cf37
Compare
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
I continued to improved the diagnostic output by adding labels that points to Self type and Trait to better put emphasis on the fact that they are non-local for the lint. With the example in #125068 (comment), it now gives:
|
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.
There's quite a bit of code that I need to continue reviewing, but I have some nitpicks based on the output.
LL | impl<T> Trait<InsideMain> for &Vec<below::Type<(InsideMain, T)>> | ||
| ^ ---------- ----------- ---------- may need to be moved as well |
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.
I see that you're hedging your bets that the type itself might also be in a weird scope that would otherwise not be accessible to the impl
in the new location. Ideally we would check that that is the case before saying anything.
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.
I don't understand your comment, it's not betting, we are checking in the code if the type is at the same nesting, and if it is we emit the note saying that it might (as in may not be something you might want to do) need to be moved, there is no guess here.
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.
Ah! I see. In that case I would make it a message explaining alternative ways of sealing traits and types?
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.
It doesn't make sense to recommend sealing the trait since if we warn that means it already not local so moving the impl
shouldn't change it's availability/visibility.
Regarding sealing the type, idk if that's a thing, but it also wouldn't change anything, since if it is not local it is already leaked.
In general it is very difficult to say how users should change their code to make a impl local (which from the type-system point-of-view doesn't exist anyway), so in general the lint "fallback" to proposing to make the impl def true to what it is, a global impl, and as such should be in a "global context" (module) and not inside a function, consts, array count, ...
abefe35
to
5044fb6
Compare
All the review comments have been addressed or have been replied to. @rustbot ready |
☔ The latest upstream changes (presumably #124417) made this pull request unmergeable. Please resolve the merge conflicts. |
5044fb6
to
7236f18
Compare
This PR improves (or at least tries to improve) the diagnostic output the
non_local_definitions
lint, by simplifying the wording, by adding a "sort of" explanation of bounds interaction that leak the impl...This PR is best reviewed commit by commit and is voluntarily made a bit vague as to have a starting point to improve on.
Related to https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/non_local_defs.20wording.20improvements
Fixes #125068
Fixes #124396
cc @workingjubilee
r? @estebank