-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
[WIP] Lint duplicate trait and lifetime bounds #57909
Conversation
This comment has been minimized.
This comment has been minimized.
r? @alexreg (not because there's anything to review, but just so it doesn't appear in someone else's queue) |
b7c700f
to
47a0dfe
Compare
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 |
// Lint duplicate bounds. | ||
let bounds = predicates.iter().filter_map(|(pred, sp)| { | ||
match pred { | ||
Predicate::Trait(ref pred) => |
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.
Use default match bindings?
let mut err = tcx.struct_span_lint_node( | ||
lint::builtin::DUPLICATE_BOUNDS, | ||
node_id, | ||
bounds[range.clone()].iter().map(|(_, _, sp)| *sp).collect::<Vec<_>>(), |
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.
bounds[range.clone()].iter().map(|(_, _, sp)| *sp).collect::<Vec<_>>(), | |
bounds[range.clone()].iter().map(|(.., sp)| *sp).collect::<Vec<_>>(), |
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 think it's clearer this way.
bound_name)); | ||
debug!("zzz: 1: {:?} / {:?}", bounds[range.start].0, bounds[range.start].1); | ||
err.span_label(bounds[range.start].2, "first use of bound"); | ||
for i in (range.start + 1)..range.end { |
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.
Why not get a subslice and iterate over that + pattern match out the parts of the tuple?
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.
Because it's important to have the indices, as you can see from the following code.
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.
You can use .enumerate()
to get the indices :)
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.
Yeah, but the thing is I'm keeping track of the start index of a "run"... this sort of made most sense to me. shrug
|
||
let mut seq_start = 0; | ||
for i in 1..bounds.len() { | ||
if (&bounds[i].0, &bounds[i].1) != (&bounds[i - 1].0, &bounds[i - 1].1) { |
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.
You can use tuple_windows
from itertools if available to express this more nicely.
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.
If only... introducing dependencies on itertools in the compiler is a big no no.
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.
Bummer... I would have expected it to already be used somewhere... :/
☔ The latest upstream changes (presumably #58254) made this pull request unmergeable. Please resolve the merge conflicts. |
ping from triage @alexreg you have conflicts to resolve |
@Dylan-DPC See my original comment. This is just a PR to say "here's my attempted solution, it didn't quite work out, but maybe someone can make something of it". Feel free to close if you think that's more appropriate though. |
Closing it for queue cleanup then. Ideally we'd track it as an issue and refer to this PR as a previous attempt to look at to see what problems can occur. |
@oli-obk Yeah, that sounds reasonable. |
For example,
T: Foo + Foo
,'a: 'b + 'b
, or in-bandT: Foo
together withwhere T: Foo
, etc.I ran into a brick wall with htis one, as it's a lot trickier than it first seems, though I should have a fair bit of boilerplate in place here. Leaving this for someone else to pick up hopefully (ideally before it bitrots into oblivion!).
CC @nikomatsakis