-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Re-enable duplicate/unused diagnostic code detection #19624
Comments
My preferred approach would be to have each crate maintain its own set of diagnostics. All crates would continue to use the same universal naming scheme (EXXXX) and warn on unused codes. The main crate (rustc) would at compile-time cross-check all diagnostic sets from child crates for duplicate codes. |
The difficulty with the above approach is when adding a new diagnostic, you'll have to inspect all sets for the lowest available code. An alternative is to have a separate crate for the diagnostics that all other crates depend on. All crates would be able to do the "is this code registered?" sanity check but only rustc would warn on unused and duplicate codes. |
Some thoughts from IRC:
|
I was thinking more. I think that we should introduce an abstraction layer between the identifier that is present in the code and the error code that the user sees. I actually think this has the potential to solve all of these problems and then some more. Here is how I envision it working: In the main crate (probably driver), we compile a list of all the error codes. The list looks like this:
then in the code instead of writing Advantages of this scheme:
Now, we could arguably go one step further and just NOT USE NUMERIC CODES at all. It's not clear what advantage numeric codes offer over some distinct keyword like One thing I might like is that we do offer a mode for using the descriptive names rather than the numeric code in the output (perhaps a -Z flag). The reason for this is that I would like all the tests in |
I'm working on a quick patch that fixes registration according to the existing design. I agree it would probably be best to keep the metadata all in one crate. The biggest complication I see to that design is that it will be harder to statically determine whether error codes are being duplicated across crates. If we had to we could have a dynamic check when rustc starts up though. As to whether it would be best to get rid of numbers, the downside there is that arbitrary-length strings take up a lot of room in error messages. |
I guess english-language error codes could be a potential i18n issue as well, though I'm not sure if compiler errors are ever internationalized. |
If we used a tidy script to dig out all the error codes (if they had a more distinctive syntax) then we could get rid of the giant registration list. One of the purposes of the big gigantic list of error codes was to ensure that none ever get reused, so if we got rid of the list then it would be more tempting to go back and take one of the retired codes. I'm thinking there may be room in the design for a list of retired codes that perhaps the tidy script could check as well. |
Here's my revised proposal, which is substantially similar to niko's
|
This does the bare minimum to make registration of error codes work again. After this patch, every call to `span_err!` with an error code gets that error code validated against a list in that crate and a new tidy script `errorck.py` validates that no error codes are duplicated globally. There are further improvements to be made yet, detailed in rust-lang#19624. r? @nikomatsakis
fwiw I like the numbers in terms of presenting to end-users, I just would like to make dealing with merge conflicts easier when rebasing |
idea that was proposed: get a random unused number? |
Triage: @jonathandturner tells me this is back on now! |
It was disabled in #19362. It'd be good to have it back one way or another.
The text was updated successfully, but these errors were encountered: