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

don't make crazy suggestion for unreachable braced pub-use #50476

Merged
merged 1 commit into from
May 12, 2018

Conversation

zackmdavis
Copy link
Member

The Higher Intermediate Representation doesn't have spans for visibility
keywords, so we were assuming that the first whitespace-delimited token
in the item span was the pub to be weakened. This doesn't work for
brace-grouped uses, which get lowered as if they were several
individual use statements, but with spans that only cover the braced
path-segments. Constructing a correct suggestion here presents some
challenges—until someone works those out, we can at least protect the
dignity of our compiler by not offering any suggestion at all for use items.

This resolves #50455 (but again, it would be desirable in the future to
make a correct suggestion instead of copping out like this).

r? @Manishearth

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 6, 2018
@Manishearth
Copy link
Member

Could you instead still output the suggestion, but using _with_applicability and marking it PossiblyIncorrect? See baa7b32 for how this works.

We still need to figure out a way to suggest in this case; edition lints should be automatable as much as possible.

@zackmdavis zackmdavis force-pushed the tame_unreachable_pub_suggestion branch from 9561b45 to 0fd6c30 Compare May 7, 2018 04:14
@zackmdavis
Copy link
Member Author

@Manishearth (updated)

still output the suggestion

I see; humans who see the bad consider restricting its visibility: 'pub(crate)' label will read the English and probably understand what we meant; only tools need to be dissuaded from doing a blind text substitution.

using _with_applicability

.span_suggestion_with_applicability is kind of a long name. If our goal is for all suggestions to have a meaningful applicability value, would it make sense to put an Applicability argument in the signature of .span_suggestion (at the cost of someone having a compose an enormous pull request editing all ~200 uses of span_suggestion)?

@zackmdavis zackmdavis force-pushed the tame_unreachable_pub_suggestion branch from 0fd6c30 to 891fc7a Compare May 7, 2018 14:45
@zackmdavis
Copy link
Member Author

(force-pushed again, had forgotten to update the commit message)

@Manishearth
Copy link
Member

@zackmdavis that is the eventual plan, for now we're going to use _with_applicability, and when everything is updated we rename the methods.

@Manishearth
Copy link
Member

@bors r+

I'd prefer something using span_to_snippet but I don't think there's a way to make that work better here.

@bors
Copy link
Contributor

bors commented May 7, 2018

📌 Commit 891fc7a has been approved by Manishearth

@bors bors 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-review Status: Awaiting review from the assignee but also interested parties. labels May 7, 2018
@bors
Copy link
Contributor

bors commented May 7, 2018

☔ The latest upstream changes (presumably #50454) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 7, 2018
@zackmdavis zackmdavis force-pushed the tame_unreachable_pub_suggestion branch from 891fc7a to d74636d Compare May 11, 2018 02:01
@zackmdavis
Copy link
Member Author

(updated)

@Manishearth Rebase conflict was with the macro-context check you added in #50454—is there a specifically known case where macros mess up the suggestion, or was that generalized skepticism of the I-agree-very-regrettable span-chopping being OK in the presence of macros? (The revision I just pushed just takes my branch's side of the conflict, only doing MaybeIncorrect for use items.)

@Manishearth
Copy link
Member

Manishearth commented May 11, 2018 via email

The Higher Intermediate Representation doesn't have spans for visibility
keywords, so we were assuming that the first whitespace-delimited token
in the item span was the `pub` to be weakened. This doesn't work for
brace-grouped `use`s, which get lowered as if they were several
individual `use` statements, but with spans that only cover the braced
path-segments. Constructing a correct suggestion here presents some
challenges—until someone works those out, we can at least protect the
dignity of our compiler marking the suggestion for `use` items as
potentially incorrect.

This resolves rust-lang#50455 (but again, it would be desirable in the future to
make a correct suggestion instead of copping out like this).
@zackmdavis zackmdavis force-pushed the tame_unreachable_pub_suggestion branch from d74636d to 7006018 Compare May 11, 2018 03:48
@alexcrichton
Copy link
Member

@bors: p=1

We'll want to land this pretty quickly for the edition preview, so raising priority

@Manishearth
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented May 11, 2018

📌 Commit 7006018 has been approved by Manishearth

@bors bors 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 May 11, 2018
alexcrichton added a commit to alexcrichton/rust that referenced this pull request May 11, 2018
…gestion, r=Manishearth

don't make crazy suggestion for unreachable braced pub-use

The Higher Intermediate Representation doesn't have spans for visibility
keywords, so we were assuming that the first whitespace-delimited token
in the item span was the `pub` to be weakened. This doesn't work for
brace-grouped `use`s, which get lowered as if they were several
individual `use` statements, but with spans that only cover the braced
path-segments. Constructing a correct suggestion here presents some
challenges—until someone works those out, we can at least protect the
dignity of our compiler by not offering any suggestion at all for `use` items.

This resolves rust-lang#50455 (but again, it would be desirable in the future to
make a correct suggestion instead of copping out like this).

r? @Manishearth
@bors
Copy link
Contributor

bors commented May 11, 2018

⌛ Testing commit 7006018 with merge 3b946e637fb5d314379cbc620ddc3000994520fb...

@alexcrichton
Copy link
Member

@bors: retry

prioritizing rollup which includes this

@alexcrichton
Copy link
Member

@bors: p=0

Moving back to a normal priority

@alexcrichton
Copy link
Member

@zackmdavis I noticed that the fixes here were centered around the UnreachablePub but I've noticed that the ABSOLUTE_PATH_NOT_STARTING_WITH_CRATE lint also runs into this same issue. Would it be easy to include a similar fix here to avoid warning about those statements for the time being? Or would delaying for a future PR be best?

@bors
Copy link
Contributor

bors commented May 12, 2018

⌛ Testing commit 7006018 with merge 5f98fe7...

bors added a commit that referenced this pull request May 12, 2018
…Manishearth

don't make crazy suggestion for unreachable braced pub-use

The Higher Intermediate Representation doesn't have spans for visibility
keywords, so we were assuming that the first whitespace-delimited token
in the item span was the `pub` to be weakened. This doesn't work for
brace-grouped `use`s, which get lowered as if they were several
individual `use` statements, but with spans that only cover the braced
path-segments. Constructing a correct suggestion here presents some
challenges—until someone works those out, we can at least protect the
dignity of our compiler by not offering any suggestion at all for `use` items.

This resolves #50455 (but again, it would be desirable in the future to
make a correct suggestion instead of copping out like this).

r? @Manishearth
@bors
Copy link
Contributor

bors commented May 12, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: Manishearth
Pushing 5f98fe7 to master...

@bors bors merged commit 7006018 into rust-lang:master May 12, 2018
@zackmdavis zackmdavis deleted the tame_unreachable_pub_suggestion branch May 12, 2018 16:31
@zackmdavis
Copy link
Member Author

(um, probably a future PR)

zackmdavis added a commit to zackmdavis/rust that referenced this pull request Jul 1, 2018
This is a true fix for rust-lang#50455, superior to the mere bandage offered
in rust-lang#50476.
bors added a commit that referenced this pull request Jul 2, 2018
…petrochenkov

add modifier keyword spans to hir::Visibility; improve unreachable-pub, private-no-mangle lint suggestions

#50455 pointed out that the unreachable-pub suggestion for brace-grouped `use`s was bogus; #50476 partially ameliorated this by marking the suggestion as `Applicability::MaybeIncorrect`, but this is the actual fix.

Meanwhile, another application of having spans available in `hir::Visibility` is found in the private-no-mangle lints, where we can now issue a suggestion to use `pub` if the item has a more restricted visibility marker (this seems much less likely to come up in practice than not having any visibility keyword at all, but thoroughness is a virtue). While we're there, we can also add a helpful note if the item does have a `pub` (but triggered the lint presumably because enclosing modules were private).

![hir_vis](https://user-images.githubusercontent.com/1076988/42018064-ca830290-7a65-11e8-9c4c-48bc846f861f.png)

r? @nrc
cc @Manishearth
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.

Suggestion for pub(crate) not always valid on multiple imports
5 participants