Uh oh!
There was an error while loading. Please reload this page.
Fix span of visibility - #47799
Conversation
rust-highfive
commented
Jan 27, 2018
(rust_highfive has picked a reviewer for you, use r? to override) |
petrochenkov
commented
Jan 27, 2018
IIRC, the whole visibility span is used in couple of places, but it's retrieved from codemap when necessary rather than precomputed. r=me without the second commit. |
bors
commented
Jan 27, 2018
✌️ @topecongiro can now approve this pull request |
topecongiro
commented
Jan 28, 2018
@petrochenkov Thank you for your review! If adding a span filed to |
topecongiro
commented
Jan 28, 2018
Or, rather than adding a span field to pubtypeVisibility = Spanned<VisibilityKind>;#[derive(Clone,PartialEq,Eq,RustcEncodable,RustcDecodable,Hash,Debug)]pubenumVisibilityKind{Public,Crate(CrateSugar),Restricted{path:P<Path>,id:NodeId},Inherited,} |
petrochenkov
commented
Jan 28, 2018
@topecongiro |
There was a problem hiding this comment.
Dummy spans should not be used, unless completely unavoidable.
In most cases during expansion spans for generated code can be inherited from something. In this case item.span is used for the path and for the extern crate item, it can be used for visibility as well.
There was a problem hiding this comment.
Dummy spans should not be used, unless completely unavoidable.
It's probably not so dire for visibilities because they don't have hygiene, but it's still desirable to use some valid spans when possible.
There was a problem hiding this comment.
@petrochenkov Thank you for your advice!
Is it acceptable to use 'empty' span like the following, rather than item.span? I think it makes easier to handle comments in rustfmt and reflects the syntactic structure of source code more accurately (as Inherited visibility has no keyword).
Span{hi: item.span.lo(), ..item.span}There was a problem hiding this comment.
Yes, that would be even better.
(I was concerned about item.span.lo pointing to the location before item attributes, but it looks like this is not the case.)
8dcbba9 to
93e87c4Comparetopecongiro
commented
Feb 4, 2018
Updated and rebased against the master to resolve conflicts. |
petrochenkov
commented
Feb 4, 2018
r=me after removing unintended submodule updates and fixing tidy. |
bors
commented
Feb 4, 2018
✌️ @topecongiro can now approve this pull request |
93e87c4 to
7d51391Comparetopecongiro
commented
Feb 4, 2018
@bors r+ |
bors
commented
Feb 4, 2018
📌 Commit 7d51391 has been approved by |
7d51391 to
e4d4003Comparetopecongiro
commented
Feb 5, 2018
@bors r- Had to fix tidy. |
4bdf937 to
2e17f62Comparepetrochenkov
commented
Feb 5, 2018
Travis fails, unit tests in |
emilyalbini
commented
Feb 12, 2018
Hi @topecongiro, we haven't heard from you on this in a while! There are some broken tests (#47799 (comment)), could you update them so the PR can be merged? |
2e17f62 to
5ace5b6Comparetopecongiro
commented
Feb 14, 2018
Updated broken tests. I am sorry that this took a long time to get fixed. |
petrochenkov
commented
Feb 19, 2018
Timeout on i686-pc-windows-msvc again! Strange, but let's try again. |
bors
commented
Feb 19, 2018
⌛ Testing commit 8e9fa57 with merge b2642ba62d41570201a9d85e7f4df133590e5fed... |
… r=petrochenkov Fixesrust-lang#47311. r? @nrc
Manishearth
commented
Feb 20, 2018
@bors clean (included in the rollup) |
bors
commented
Feb 20, 2018
💥 Test timed out |
Manishearth
commented
Feb 20, 2018
@bors r=petrochenkov retry clean |
bors
commented
Feb 20, 2018
💡 This pull request was already approved, no need to approve it again. |
bors
commented
Feb 20, 2018
📌 Commit 8e9fa57 has been approved by |
bors
commented
Feb 23, 2018
…nkov Fix span of visibility This PR 1. adds a closing parenthesis to the span of `Visibility::Crate` (e.g. `pub(crate)`). The current span only covers `pub(crate`. 2. adds a `span` field to `Visibility::Restricted`. This span covers the entire visibility expression (e.g. `pub (in self)`). Currently all we can have is a span for `Path`. This PR is motivated by the bug found in rustfmt (rust-lang/rustfmt#2398). The first change is a strict improvement IMHO. The second change may not be desirable, as it adds a field which is currently not used by the compiler.
bors
commented
Feb 23, 2018
☀️ Test successful - status-appveyor, status-travis |
Tested on commit rust-lang/rust@063deba. 💔 clippy-driver on windows: test-pass → build-fail (cc @Manishearth@llogiq@mcarton@oli-obk). 💔 clippy-driver on linux: test-pass → build-fail (cc @Manishearth@llogiq@mcarton@oli-obk).
kennytm
commented
Feb 23, 2018
Clippy is broken by this PR, cc @Manishearth@llogiq@mcarton@oli-obk. Details |
Visibility spans were added to the AST in rust-lang#47799 (d6bdf29) as a `Spanned<_>`—which means that we need to choose a span even in the case of inherited visibility (what you get when there's no `pub` &c. keyword at all). That initial implementation's choice is pretty counterintuitive, which could matter if we want to use it as a site to suggest inserting a visibility modifier, &c. (The phrase "Schelling span" in the comment is meant in analogy to the game-theoretic concept of a "Schelling point", a value that is chosen simply because it's what one can expect to agree upon with other agents in the absence of explicit coördination.)
This PR
Visibility::Crate(e.g.pub(crate)). The current span only coverspub(crate.spanfield toVisibility::Restricted. This span covers the entire visibility expression (e.g.pub (in self)). Currently all we can have is a span forPath.This PR is motivated by the bug found in rustfmt (rust-lang/rustfmt#2398).
The first change is a strict improvement IMHO. The second change may not be desirable, as it adds a field which is currently not used by the compiler.