-
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
Fix span of visibility #47799
Fix span of visibility #47799
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
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. |
✌️ @topecongiro can now approve this pull request |
@petrochenkov Thank you for your review! If adding a span filed to |
Or, rather than adding a span field to pub type Visibility = Spanned<VisibilityKind>;
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum VisibilityKind {
Public,
Crate(CrateSugar),
Restricted { path: P<Path>, id: NodeId },
Inherited,
} |
@topecongiro |
src/librustc_allocator/expand.rs
Outdated
@@ -97,7 +97,7 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> { | |||
]); | |||
let mut items = vec![ | |||
f.cx.item_extern_crate(f.span, f.alloc), | |||
f.cx.item_use_simple(f.span, Visibility::Inherited, super_path), | |||
f.cx.item_use_simple(f.span, dummy_spanned(VisibilityKind::Inherited), super_path), |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
93e87c4
Compare
Updated and rebased against the master to resolve conflicts. |
r=me after removing unintended submodule updates and fixing tidy. |
✌️ @topecongiro can now approve this pull request |
93e87c4
to
7d51391
Compare
@bors r+ |
📌 Commit 7d51391 has been approved by |
7d51391
to
e4d4003
Compare
@bors r- Had to fix tidy. |
4bdf937
to
2e17f62
Compare
Travis fails, unit tests in |
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
5ace5b6
Compare
Updated broken tests. I am sorry that this took a long time to get fixed. |
Timeout on i686-pc-windows-msvc again! Strange, but let's try again. |
⌛ Testing commit 8e9fa57 with merge b2642ba62d41570201a9d85e7f4df133590e5fed... |
… r=petrochenkov Fixes rust-lang#47311. r? @nrc
@bors clean (included in the rollup) |
💥 Test timed out |
@bors r=petrochenkov retry clean |
💡 This pull request was already approved, no need to approve it again. |
📌 Commit 8e9fa57 has been approved by |
…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.
☀️ 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).
Clippy is broken by this PR, cc @Manishearth @llogiq @mcarton @oli-obk.
|
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
.span
field 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.