Skip to content
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

Avoid repetition on “use of unstable library feature 'rustc_private'” #45540

Merged
merged 4 commits into from
Oct 28, 2017

Conversation

virgil-palanciuc
Copy link
Contributor

@virgil-palanciuc virgil-palanciuc commented Oct 26, 2017

This PR fixes the error by only emitting it when the span contains a real file (is not inside a macro) - and making sure it's emitted only once per span.
The first check was needed because spans-within-macros seem to differ a lot and "fixing" them to the real location is not trivial (and the method that does this is private to another module). It also feels like there always will be an error on import, with the real file name, so not sure there's a point to re-emit the same error at macro use.

Fix #44953.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 26, 2017
@oli-obk
Copy link
Contributor

oli-obk commented Oct 26, 2017

compile-fail/internal-unstable-noallow.rs needs adjusting

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 26, 2017
@virgil-palanciuc
Copy link
Contributor Author

Yes, I've seen it now, sorry for that; I didn't have time to look at it/ fix it yet.

…s long as the same error message has not been used before (i.e. use the None as the span key, for errors that occur within macros)
Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great to me! Please fix the formatting nitpicks and I'll merge.


let msp: MultiSpan = span.into();
let cm = &self.sess.parse_sess.codemap();
let span_key =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably fit the following line on this one.

let cm = &self.sess.parse_sess.codemap();
let span_key =
msp.primary_span().and_then(|sp:Span|
if sp != DUMMY_SP {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean up the formatting for this entire block to avoid as having as much left padding.

}
);

let tuple = (None, span_key, msg.clone());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to give tuple a more descriptive name. You can also get around that by just inserting the tuple inline ;)

msp.primary_span().and_then(|sp:Span|
if sp != DUMMY_SP {
let fname = cm.lookup_char_pos(sp.lo()).file.as_ref().name.clone();
if fname.starts_with("<") && fname.ends_with(" macros>") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This piece of code could be better as a method of cm.lookup_char_pos(sp.lo()).file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you meant. Hopefully the way it's written now is better (well, it is better, I don't exactly know why I felt I needed to make it so complicated... )

@@ -78,7 +78,7 @@ pub struct Session {
/// Set of (LintId, Option<Span>, message) tuples tracking lint
/// (sub)diagnostics that have been set once, but should not be set again,
/// in order to avoid redundantly verbose output (Issue #24690).
pub one_time_diagnostics: RefCell<FxHashSet<(lint::LintId, Option<Span>, String)>>,
pub one_time_diagnostics: RefCell<FxHashSet<(Option<lint::LintId>, Option<Span>, String)>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally, instead of making the first tuple field an option, I would suggest making the FxHashSet accept a new struct with three fields diagnostic_id, span and message, with diagnostic_id being a new enum that takes either a LintId or a GateIssue. This way we can keep expanding one_time_diagnostics without the risk of having multiple different diagnostics with the same span message and no lint_id, but being different errors, from being incorrectly stopped, but because of the message being there, what you're doing is correct and unlikely to be made incorrect with a subsequent change.

@estebank estebank changed the title fix #44953 - The “use of unstable library feature 'rustc_private'” error is very repetitive Avoid repetition on “use of unstable library feature 'rustc_private'” Oct 27, 2017
@@ -361,7 +368,7 @@ impl Session {
},
_ => {
let lint_id = lint::LintId::of(lint);
let id_span_message = (lint_id, span, message.to_owned());
let id_span_message = (DiagnosticMessageId::LintId(lint_id), span, message.to_owned());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please shorten this line to ≤100 chars.

[00:02:54] tidy error: /checkout/src/librustc/session/mod.rs:371: line longer than 100 chars

@kennytm
Copy link
Member

kennytm commented Oct 28, 2017

@bors r=estebank

@bors
Copy link
Contributor

bors commented Oct 28, 2017

📌 Commit bb0049b has been approved by estebank

@bors
Copy link
Contributor

bors commented Oct 28, 2017

⌛ Testing commit bb0049b with merge 269cf50...

bors added a commit that referenced this pull request Oct 28, 2017
Avoid repetition on “use of unstable library feature 'rustc_private'”

This PR fixes the error by only emitting it when the span contains a real file (is not inside a macro) - and making sure it's emitted only once per span.
The first check was needed because spans-within-macros seem to differ a lot and "fixing" them to the real location is not trivial (and the method that does this is private to another module). It also feels like there always will be an error on import, with the real file name, so not sure there's a point to re-emit the same error at macro use.

Fix #44953.
@kennytm kennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 28, 2017
@bors
Copy link
Contributor

bors commented Oct 28, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: estebank
Pushing 269cf50 to master...

@bors bors merged commit bb0049b into rust-lang:master Oct 28, 2017
@jakubadamw
Copy link
Contributor

jakubadamw commented Oct 29, 2017

@virgil-palanciuc, may be worth adding a test?

MaloJaffre added a commit to MaloJaffre/rust that referenced this pull request Jan 1, 2018
It tested rust-lang#44953.
`log` macros in newer versions are no longer recursive, so these duplicated
error messages (about unstable feature uses) previously occurring at each
level of recursion are no longer possible, even with the fix by rust-lang#45540.
Furthermore this test breaks when multiple versions of `log` are in the
sysroot (`log 0.3.9` depends on`log 0.4.1`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The “use of unstable library feature 'rustc_private'” error is very repetitive
8 participants