-
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
one-time diagnostics for private enum variants glob reëxport #46248
one-time diagnostics for private enum variants glob reëxport #46248
Conversation
f352fb5
to
42d744e
Compare
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.
Like the approach! Just a couple of nitpicks.
DiagnosticMessageId::ErrorId(0), | ||
enum_def_start_span, | ||
"consider making the enum public", | ||
"pub ".to_owned()); |
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.
Fix indentation.
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.
Instead of using enum_def_start_span
I'd use the codemap().def_span(enum_def_span)
in order to have the following output:
18 | enum Professor {
| -------------- help: consider making the enum public: `pub enum Professor`
I don't remember how the suggestion output looks when encountering multiline spans, like what would be caused by the following snippet of code:
enum
Professor {
Adjunct,
Assistant,
Associate,
Full
}
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 don't remember how the suggestion output looks when encountering multiline spans
It's the thing that goes like
/ struct MyStruct {
| ...
|
| }
|__^
Not recommended here.
let enum_def_span = directive.parent.resolutions.borrow() | ||
.get(&(enum_ident, TypeNS)) | ||
.expect("enum resolution should exist") | ||
.borrow().binding |
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.
align the binding.expect
in the same line (I personally like to make it visually easy to notice you can skip the expect
when skimming).
} | ||
} | ||
}, |
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.
This comma was not necessary.
@@ -891,7 +925,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { | |||
resolution.binding = Some(self.arenas.alloc_name_binding(NameBinding { | |||
kind: NameBindingKind::Ambiguity { b1: b1, b2: b2, legacy: true }, ..*b1 | |||
})); | |||
} | |||
}, |
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.
This comma was not necessary.
| ^^^^^^^^^^^^^^^^^^^ | ||
... | ||
18 | enum Professor { | ||
| - help: consider making the enum public: `pub ` |
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.
Love this! (With the above nitpick)
--> $DIR/issue-46209-private-enum-variant-reexport.rs:14:32 | ||
| | ||
14 | pub use self::Lieutenant::{JuniorGrade, Full}; | ||
| ^^^^^^^^^^^ |
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.
Ideally I would like these to follow the same output as #43447, but it could get hairy fairly quickly...
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.
motion to defer
Travis failure (of a revision that I'm about to force-push over) makes it look like we have some nondeterminism:
I'd rather actually fix the nondeterminism rather than going for the lazy "fix" of only including one of the non-glob erroneous re-exports, because I want the UI test to show that the suggestion doesn't appear the second time (thanks to |
42d744e
to
e6033b6
Compare
... wait, maybe I had to amend something the other night without updating the UI test (can't recall), and that's what threw off the hash ordering (but it would be stable with the same compiler/same code)? |
e6033b6
to
e32419d
Compare
force-updated to address review comments, plus a new commit for correct suggestions in the restricted-but-not-entirely-private case ( |
Travis failure is ordering-related again; I guess we do need to stabilize it? I'm not sure what the hash depends on such that same-compiler-code/same-program/different-machine (mine vs. Travis) gives different results. |
1bb63e3
to
155e852
Compare
@zackmdavis the way to make the ui output completely stable is to defer the emission of the diagnostic until all of them have been processed and then sorter right before output. I wouldn't bother with this case in particular and move the test to |
☔ The latest upstream changes (presumably #46288) made this pull request unmergeable. Please resolve the merge conflicts. |
155e852
to
f1c3c3a
Compare
(well, this also turns out to have a more serious failure ( |
d1f6dc1
to
b130d08
Compare
Travis is green now |
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.
Couple of nitpicks, but it looks great and almost ready to merge. r=me after addressing the comments.
ImportDirectiveSubclass::GlobImport { .. } => { | ||
let msg = "enum is private and its variants \ | ||
cannot be reexported".to_owned(); | ||
let error_id = (DiagnosticMessageId::ErrorId(0), // no 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 create a new code in https://github.com/rust-lang/rust/blob/master/src/librustc_resolve/diagnostics.rs (probably a good idea to do it as part of this PR)
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 there's a strong case to be made that this should just be E0364, rather than a new 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.
I'd rather defer this to some future PR. (I started coding, but the pieces don't quite fit together for the elegant thing that I wanted to do.)
} | ||
|
||
mod m2 { | ||
pub use ::E::{V}; //~ ERROR variant `V` is private, and cannot be reexported | ||
pub use ::E::{V}; //~ ERROR variant is private and cannot be reexported |
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.
What is the stderr output for this file? I want to make sure that it is pointing at the V
path segment exclusively (here and elsewhere in this file), otherwise change the msg
above to include the identifier as it was before to avoid confusion, as if the output points at the entire use
statement (which is my understanding from reading the code) it could be referring to E
or V
(and it gets worse the more path segments there are).
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.
It was
zmd@MaximumLikelihood:~/Code/rust$ ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc src/test/compile-fail/private-variant-reexport.rs
error: variant is private and cannot be reexported
--> src/test/compile-fail/private-variant-reexport.rs:12:13
|
12 | pub use ::E::V; //~ ERROR variant is private and cannot be reexported
| ^^^^^^
...
27 | enum E { V }
| ------ help: consider making the enum public: `pub enum E`
error: variant is private and cannot be reexported
--> src/test/compile-fail/private-variant-reexport.rs:16:19
|
16 | pub use ::E::{V}; //~ ERROR variant is private and cannot be reexported
| ^
error: variant is private and cannot be reexported
--> src/test/compile-fail/private-variant-reexport.rs:20:22
|
20 | pub use ::E::V::{self}; //~ ERROR variant is private and cannot be reexported
| ^^^^
error: enum is private and its variants cannot be reexported
--> src/test/compile-fail/private-variant-reexport.rs:24:13
|
24 | pub use ::E::*; //~ ERROR enum is private and its variants cannot be reexported
| ^^^^^^
error: aborting due to 4 previous errors
(Span is including the E::
for the non-brace case; can add variant name back into the message.)
304c8b1 made the Session's one-time-diagnostics set take a special-purpose `DiagnosticMessageId` enum rather than a LintID so that it could support more than just lints, but the `diag_span_note_once` and `diag_note_once` methods continued to take references to lints: for API consistency, we now make these methods take a `DiagnosticMessageId` while we add support for one-time span-suggestions.
We issue just one message for an erroneous glob private variant reëxport (using the Session's one-time-diagnostics capability), but individual (non-glob) such erroneous reëxports still get their own messages. The suggestion to make the enum public is also one-time. The enum variant reëxport error didn't have an associated error code (and remedying this here is deemed out of the scope of this commit), so we resort to the expediency of using 0 as the `DiagnosticMessageId` value. Adding Debug to NameResolution was helpful in development. This resolves rust-lang#46209.
b130d08
to
4fb57e0
Compare
(updated) |
@bors r+ |
📌 Commit 4fb57e0 has been approved by |
…ort_error, r=estebank one-time diagnostics for private enum variants glob reëxport ![private_enum_reexport](https://user-images.githubusercontent.com/1076988/33224719-4e5805f0-d121-11e7-8bc0-a708a277a5db.png) r? @estebank
☀️ Test successful - status-appveyor, status-travis |
r? @estebank