-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
trait bounds lint - repeated types #3766
Conversation
Correct, the ID is the id of the AST entry and has nothing to do with identity of the element at hand. This makes comparing the types significantly harder, because there are also ids inside the I suggest you create a newtype wrapper around |
So I followed the Tested it on a simple example and it seems to work fine so I'm hoping anything else is just fine-tuning and tweaking. |
All of them are relevant. You can actually have bounds like So instead of collecting the idents, you need to hash all the relevant information. For this you can create a wrapper type struct HashTy<'ast>(&'ast Ty); and then implement What I'm imagining is an impl like impl Hash for HashTy {
fn hash<H: Hasher>(&self, h: &mut H) {
// make sure we hash the kind of type, so we can distinguish between
// `Slice` and `Array`
std::mem::discrimiant(&self.0.node).hash(h);
match &self.0.node {
Slice(p) => HashTy(p).hash(h),
Tuple(ps) => for p in ps {
HashTy(p).hash(h);
},
... and so on
}
}
} Something similar for the |
So I've started the Hash implementation, I wasn't 100% sure on the I'll start adding some |
Sorry for the long time no reply @xd009642. The Hash implementation LGTM so far. I would like to have more telling variable names in the hash implementation, but that's just a NIT. Do you want to continue working on this? Any specific questions or cases you want help with? |
Yeah I'd like to continue working on this. Just one question so far. When I've encountered an |
There's
Does this help you with the |
This looks like it solves my |
Below in this file there is also Note, that this is based on HIR items, not on AST items. So in order to use these functions you have to make this lint either a |
What's the difference between the late and early pass? If there's reason why I can't make it a late pass I'll do that and reuse those functions. |
Late pass lints are run on the HIR (High-level Intermediate Representation), while Early pass lints are run on the AST (Abstract Syntax Tree). Early pass lints have better performance, than Late pass lints. Also they're run earlier (well 😄). Also Late pass lints have full type information. So you can just make this a Late pass lint. |
Me again! Sorry for the length of time between tackling this again and again but I think I've got it mostly cracked now. I had to add
|
The impl LGTM now. Could you add some tests? |
I've added a UI test, let me know if there are any issues 👍 |
There's currently a bunch of compiler errors in compiletest post rebase i.e.
I'm just updating things like rust version etc to see if that resolves it |
Yeah, this thing goes a little bit deeper. See #3897. I'll ping you when this is fixed. |
☔ The latest upstream changes (presumably #3848) made this pull request unmergeable. Please resolve the merge conflicts. |
ping @xd009642. Clippy master builds again! Do you want to pick this up? |
Sweet I'll rebase tonight and try to finish it off 👍 |
So I've still got some build errors and from files I haven't touched? I'm going to update various things and see if I can resolve it, but any thoughts are appreciated if it can speed things along 😄
|
I think you just need to update your compiler to the latest nightly |
Yeah I realised just now my rustup default was stable not nightly! It's all good now, bar the |
Great! Thanks for all the work, let's wait if travis still has something to say and after that, this should be ready to merge. |
Travis reported some dogfood errors. Please fix them. |
Dogfood errors are now fixed |
@bors r+ |
📌 Commit 78ebcaa has been approved by |
trait bounds lint - repeated types This PR is to tackle #3764 it's still a WIP and doesn't work but this is an initial stab. It builds though I haven't added any tests as I'm not sure where lint tests should go? Unfortunately, it seems id isn't tied to the type itself but I guess where it is in the AST? Looking at https://manishearth.github.io/rust-internals-docs/syntax/ast/struct.Ty.html I can't see any members that would let me tell if a type was repeated in multiple trait bounds. There may be other issues with how I've implemented this so any assistance is appreciated!
💔 Test failed - checks-travis |
@bors retry |
trait bounds lint - repeated types This PR is to tackle #3764 it's still a WIP and doesn't work but this is an initial stab. It builds though I haven't added any tests as I'm not sure where lint tests should go? Unfortunately, it seems id isn't tied to the type itself but I guess where it is in the AST? Looking at https://manishearth.github.io/rust-internals-docs/syntax/ast/struct.Ty.html I can't see any members that would let me tell if a type was repeated in multiple trait bounds. There may be other issues with how I've implemented this so any assistance is appreciated! changelog: Add new lint: `type_repetition_in_bounds`
💔 Test failed - status-appveyor |
@flip1995 anything I need to do for these failures? |
No that's unrelated, I just wait until those are fixed (in another PR) and then merge this. |
@bors retry |
trait bounds lint - repeated types This PR is to tackle #3764 it's still a WIP and doesn't work but this is an initial stab. It builds though I haven't added any tests as I'm not sure where lint tests should go? Unfortunately, it seems id isn't tied to the type itself but I guess where it is in the AST? Looking at https://manishearth.github.io/rust-internals-docs/syntax/ast/struct.Ty.html I can't see any members that would let me tell if a type was repeated in multiple trait bounds. There may be other issues with how I've implemented this so any assistance is appreciated! changelog: Add new lint: `type_repetition_in_bounds`
☀️ Test successful - checks-travis, status-appveyor |
This PR is to tackle #3764 it's still a WIP and doesn't work but this is an initial stab. It builds though I haven't added any tests as I'm not sure where lint tests should go?
Unfortunately, it seems id isn't tied to the type itself but I guess where it is in the AST? Looking at https://manishearth.github.io/rust-internals-docs/syntax/ast/struct.Ty.html I can't see any members that would let me tell if a type was repeated in multiple trait bounds.
There may be other issues with how I've implemented this so any assistance is appreciated!
changelog: Add new lint:
type_repetition_in_bounds