Add lint for multiple associated types#50682
Add lint for multiple associated types#50682bors merged 4 commits intorust-lang:masterfrom F001:issue-50589
Conversation
|
(rust_highfive has picked a reviewer for you, use r? to override) |
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
src/librustc_lint/builtin.rs
Outdated
There was a problem hiding this comment.
So the lint doesn't allocate for every path it checks, I think it'd be better just to do a nested loop search for any duplicates and push their spans to a Vec.
There was a problem hiding this comment.
Well, using a HashMap<Name, Vec> to collect all the spans with the same associate type name can avoid the inner loop.
What do you mean by "the lint doesn't allocate for every path it checks"?
There was a problem hiding this comment.
Your approach is fine, actually, I just think it shouldn't allocate until a duplicate is found, so use HashMap::new(). That way we're not allocating when we don't end up using it.
There was a problem hiding this comment.
Thanks. If we want to avoid allocation every time, how about keeping the HashMap as a member of struct struct DupAssocTypeBinding?
There was a problem hiding this comment.
I don't think that's quite necessary, I was just concerned about allocating every time this function is called.
There was a problem hiding this comment.
I think you are right. I have updated this function. Thanks.
|
r? @nikomatsakis for re-assignment |
|
Everybody forgets about hygiene :( |
|
@petrochenkov It's probably my mistake. This and #50763 were both started from my mentoring instructions and I was purely looking at the AST types since anything further in-depth would probably not be a good starting ticket. |
|
☔ The latest upstream changes (presumably #48557) made this pull request unmergeable. Please resolve the merge conflicts. |
|
I will fix this when I have time in the next two days. Thanks very much! |
|
@F001 do you think you know what to do from @petrochenkov's notes? |
|
r? @petrochenkov — since you seem to have a pretty specific idea for what you want, can you take on the review? (let me know if that's a problem) |
|
@petrochenkov This lint is re-implemented. Please help to review. Thanks! |
src/librustc/lint/builtin.rs
Outdated
There was a problem hiding this comment.
Could you add this lint to the list of deprecation lints?
(See e.g. PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES as an example.)
There was a problem hiding this comment.
Also duplicate_associated_type_binding -> duplicate_associated_type_bindings (see https://github.com/rust-lang/rfcs/blob/master/text/0344-conventions-galore.md#lints).
src/librustc_typeck/astconv.rs
Outdated
There was a problem hiding this comment.
Could we model this error after duplicated fields:
error[E0062]: field `a` specified more than once
--> src/main.rs:4:23
|
4 | let s = S { a: 0, a: 1 };
| ---- ^ used more than once
| |
| first use of `a`
We keep FxHashMap<DefId, Span> instead of FxHashMap<DefId, Vec<Span>> and if the inserted DefId was already in the table, report an error pointing to the first use right here.
I'd even reuse all the wording for fields (except for replacing "field a" with "associated type binding a", of course).
There was a problem hiding this comment.
(You can attach labels and notes to the object returned by struct_span_lint_node, there are plenty of examples in the codebase.)
There was a problem hiding this comment.
Hmm, the warning is reported twice.
I suspect it needs to be reported only when speculative is false.
There was a problem hiding this comment.
It seems the warning is reported twice when speculative is false. I don't know why.
|
☔ The latest upstream changes (presumably #50763) made this pull request unmergeable. Please resolve the merge conflicts. |
src/librustc_typeck/astconv.rs
Outdated
There was a problem hiding this comment.
if speculative -> if !speculative
|
r=me after inverting the |
|
✌️ @F001 can now approve this pull request |
|
@petrochenkov Thank you for your detailed mentoring. As I mentioned in the previous comment, when I use |
|
Weird. I'll look what happens. |
|
Ok, this may look logically impossible unless you know that fully identical diagnostics are merged! This happens because |
|
@bors: r=petrochenkov |
|
📌 Commit 88f810f has been approved by |
Add lint for multiple associated types Fix #50589. cc @abonander
|
☀️ Test successful - status-appveyor, status-travis |
Do not deduplicate diagnostics in UI tests Error reporting infrastructure deduplicates identical diagnostics with identical spans. While it's preferable to do this in "release"/"user-facing" mode, it sometimes brings [confusion](rust-lang#50682 (comment)) and hides details that may be important during development. Do we run some passes multiple times when we could do it once? How many times we run them exactly? Can this number be large? Can the multiplied error construction be expensive? Can speculative checks be made cheaper if they don't report errors? *Relying* on this mechanism to deduplicate some specific error never looks like a proper solution to me personally. In this PR I attempt to disable this deduplication by applying `-Z deduplicate-diagnostics=no` to UI tests.
Do not deduplicate diagnostics in UI tests Error reporting infrastructure deduplicates identical diagnostics with identical spans. While it's preferable to do this in "release"/"user-facing" mode, it sometimes brings [confusion](rust-lang#50682 (comment)) and hides details that may be important during development. Do we run some passes multiple times when we could do it once? How many times we run them exactly? Can this number be large? Can the multiplied error construction be expensive? Can speculative checks be made cheaper if they don't report errors? *Relying* on this mechanism to deduplicate some specific error never looks like a proper solution to me personally. In this PR I attempt to disable this deduplication by applying `-Z deduplicate-diagnostics=no` to UI tests.
Fix #50589. cc @abonander