Skip to content

Tracing warning with invalid expansion #116203

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Noratrieb opened this issue Sep 27, 2023 · 0 comments · Fixed by #116420
Closed

Tracing warning with invalid expansion #116203

Noratrieb opened this issue Sep 27, 2023 · 0 comments · Fixed by #116420
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Noratrieb
Copy link
Member

extern "C" {
  thread_local! {
    static FOO: u32 = 0;
  }
}

This is of course invalid, thread_local expands to a static item with an initializer.

WARN rustc_errors::emitter Invalid span src/main.rs:4:12: 110:22 (#15), error=DistinctSources(DistinctSources { begin: (Real(LocalPath("src/main.rs")), BytePos(0)), end: (Real(Remapped { local_path: None, virtual_name: "/rustc/5ae769f06bbe2afc50cde219757a5915e61ba365/library/std/src/sys/common/thread_local/fast_local.rs" }), BytePos(415220)) })
error: extern items cannot be `const`
 --> src/main.rs:4:12
  |
4 |       static FOO: u32 = 0;
  |  ____________-^^
5 | |   }
6 | | }
7 | | }); }
... |
  |
  = note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html

error: incorrect `static` inside `extern` block
 --> src/main.rs:4:12
  |
2 |   extern "C" {
  |   ---------- `extern` blocks define existing foreign statics and statics inside of them cannot have a body
3 | /   thread_local! {
4 | |     static FOO: u32 = 0;
  | |            ^^^ cannot have a body
5 | |   }
  | |___- the invalid body
  |
  = note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html

something's having fun with the span there

@Noratrieb Noratrieb added A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Sep 27, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 27, 2023
@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 27, 2023
compiler-errors added a commit to compiler-errors/rust that referenced this issue Dec 7, 2023
discard invalid spans in external blocks

Fixes rust-lang#116203

This PR has discarded the invalid `const_span`, thereby making the format more neat.

r? `@Nilstrieb`
@bors bors closed this as completed in 71a8ca0 Dec 8, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 8, 2023
Rollup merge of rust-lang#116420 - bvanjoi:fix-116203, r=Nilstrieb

discard invalid spans in external blocks

Fixes rust-lang#116203

This PR has discarded the invalid `const_span`, thereby making the format more neat.

r? ``@Nilstrieb``
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants