Uh oh!
There was an error while loading. Please reload this page.
Detect duplicate implementations of assoc. types and constants. - #25993
Conversation
rust-highfive
commented
Jun 3, 2015
(rust_highfive has picked a reviewer for you, use r? to override) |
quantheory
commented
Jun 6, 2015
Hmm, one thing that seems to be missing here is that it should be an error for any pair of associated items to have the same name (e.g. a constant and a method). I believe I have a fix for this on a branch of mine, but that branch is temporarily stalled (and a long way from master now), so I will have to see if I can actually offer it as an alternative. |
arielb1
commented
Jun 8, 2015
That gives an error in the trait (trait declarations already check that you don't have multiple trait-items with the same name, and attempts to declare impl-items of the wrong kind are of course rejected). |
quantheory
commented
Jun 8, 2015
I don't have a recent rustc on hand right now, but what about inherent impls? #![feature(associated_consts)]structFoo;implFoo{const bar:bool = true;fnbar(){}} |
arielb1
commented
Jun 8, 2015
That does pose a problem :-). Seems like a job for resolve through. |
quantheory
commented
Jun 8, 2015
@arielb1 I'm not sure about that. If you refer to (All that said, code that follows the usual naming conventions will have uppercase names for constants and lowercase for methods, so this PR probably does cover the most important cases in practice.) |
arielb1
commented
Jun 11, 2015
Could you make the error for every 2 associated items, and add a test for the inherent impl case? I would change E201 for associated items in general (it was missed when associated types were added). |
nham
commented
Jun 12, 2015
@arielb1 I will take a look and see if I can figure out what to do. |
nikomatsakis
commented
Jun 15, 2015
If the problem is just the error code, it's easy enough to factor out the error reporting into a helper method (and indeed, you could just use one big set to detect duplicates between kinds of items). |
35fd79a to
ecaee08Comparenham
commented
Jun 16, 2015
I've changed it to correctly handle @quantheory 's example (and also added it as a test). Everything is under E0201 now as well. |
nikomatsakis
commented
Jul 8, 2015
@nham sorry for being slow here -- I'm way being on reviewing but aiming to be keeping up from now. However, I think there is a slight issue here. Normally in Rust there are two namespaces: types and values. If I am reading the code right, this is reporting an error for something like: traitFoo{typeBar;fnBar();}I don't think this is correct. We should report an error if there are two constants/fns with the same name or two types, but between those two groups aliasing is legal. |
nham
commented
Jul 8, 2015
@nikomatsakis Ahh, interesting. Your example actually fails to compile (seems to be erroring out in resolve, see below), but you're right that if it did compile, my approach wouldn't work. To address this I'm changing it to use separate HashSets for types and values. Do you see any issues with this approach? |
nikomatsakis
commented
Jul 8, 2015
Seems good. Niko -------- Original message -------- From: Nick Hamann notifications@github.com Date:07/08/2015 17:32 (GMT-05:00) To: rust-lang/rust rust@noreply.github.com Cc: Niko Matsakis niko@alum.mit.edu Subject: Re: [rust] Detect duplicate implementations of assoc. types and
constants. (#25993) @nikomatsakis Ahh, interesting. Your example actually fails to compile (seems to be erroring out in resolve, see below), but you're right that if it did compile, my approach wouldn't work.
$ cat 25993.rs — |
nikomatsakis
commented
Jul 10, 2015
@nham sorry, one nit, can you rename the tests to something like |
nham
commented
Jul 10, 2015
@nikomatsakis Done! Let me know if you'd like me to squash these commits. |
nikomatsakis
commented
Jul 15, 2015
@nham looks good, r+. Squashing would be good though, yeah. |
Expands E0201 to be used for any duplicate associated items, not just duplicate methods/functions. It also correctly detects when two different kinds of items (like a constant and a method) have the same name. Fixesrust-lang#23969.
nham
commented
Jul 15, 2015
Squashed. |
nikomatsakis
commented
Jul 15, 2015
@bors r+ thanks! |
bors
commented
Jul 15, 2015
📌 Commit 560bb0a has been approved by |
bors
commented
Jul 16, 2015
⌛ Testing commit 560bb0a with merge 8690536... |
bors
commented
Jul 17, 2015
⌛ Testing commit 560bb0a with merge 898e18d... |
Manishearth
commented
Jul 17, 2015
(closing just because bors is being stubborn) |
Manishearth
commented
Jul 17, 2015
@bors r+ |
bors
commented
Jul 17, 2015
📌 Commit 560bb0a has been approved by |
Manishearth
commented
Jul 17, 2015
@bors r- |
Manishearth
commented
Jul 17, 2015
@bors r=nikomatsakis |
bors
commented
Jul 17, 2015
📌 Commit 560bb0a has been approved by |
bors
commented
Jul 17, 2015
⌛ Testing commit 560bb0a with merge bab630e... |
Manishearth
commented
Jul 17, 2015
@bors force |
Manishearth
commented
Jul 17, 2015
@bors r=nikomatsakis |
bors
commented
Jul 17, 2015
📌 Commit 560bb0a has been approved by |
bors
commented
Jul 17, 2015
⌛ Testing commit 560bb0a with merge 5930c94... |
Adds two error codes, one for duplicate associated constants and one for types. I'm not certain these should each have their own code, but E0201 is already solely for duplicate associated functions so at least it kinda matches. This will lead to somewhat redundant error explanations, but that's nothing new! Fixesrust-lang#23969.
bors
commented
Jul 17, 2015
⛄ The build was interrupted to prioritize another pull request. |
bors
commented
Jul 17, 2015
⌛ Testing commit 560bb0a with merge d977c82... |
bors
commented
Jul 17, 2015
⛄ The build was interrupted to prioritize another pull request. |
bors
commented
Jul 17, 2015
⌛ Testing commit 560bb0a with merge 57dcda1... |
bors
commented
Jul 17, 2015
⛄ The build was interrupted to prioritize another pull request. |
Adds two error codes, one for duplicate associated constants and one for types. I'm not certain these should each have their own code, but E0201 is already solely for duplicate associated functions so at least it kinda matches. This will lead to somewhat redundant error explanations, but that's nothing new!
Fixes#23969.