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

Symbol::intern("cfg_if") changes to "//!" during rustfmt lifetime #73518

Closed
topecongiro opened this issue Jun 19, 2020 · 2 comments
Closed

Symbol::intern("cfg_if") changes to "//!" during rustfmt lifetime #73518

topecongiro opened this issue Jun 19, 2020 · 2 comments
Labels
T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@topecongiro
Copy link
Contributor

In rustfmt, we define rustc_span::Symbol like the following:

lazy_static! {
    static ref CFG_IF: Symbol = Symbol::intern("cfg_if");
}

Recently we found out that the value of CFG_IF may change to other value (cc rust-lang/rustfmt#4266 (comment)).

I was assuming that the value defined inside Symbol::intern is immutable within the same process. Is this assumption incorrect?

@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 19, 2020
@ehuss
Copy link
Contributor

ehuss commented Jun 20, 2020

I believe that the interned symbols are only scoped per thread for the duration of the Globals object. It looks like rustfmt re-initializes the globals for each input it processes. If the first input triggers the CFG_IF lazy static, it will initialize the Symbol in the first Globals. Then during the next input, there is a fresh Globals, but the CFG_IF lazy static still has a value from the first one.

@topecongiro
Copy link
Contributor Author

@ehuss Thank you for the reply! It seems like we are using the API in a way it wasn't intended.

I will be closing this as it is a rustfmt-side issue; sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants