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

discard invalid spans in external blocks #116420

Merged
merged 1 commit into from
Dec 8, 2023
Merged

Conversation

bvanjoi
Copy link
Contributor

@bvanjoi bvanjoi commented Oct 4, 2023

Fixes #116203

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

r? @Nilstrieb

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 4, 2023
@Noratrieb
Copy link
Member

Sorry for the late review, I forgot about this PR.
I don't like this fix, because it papers over the problem of assuming that the const keyword and the name will be adjacent.
For example, with

macro_rules! hello {
    ($name:ident) => {
        const $name: () = ();
    };
}

extern "C" {
    hello! { yes }
}
fn main() {}

the span is valid and accessible, but still very bad:

error: extern items cannot be `const`
 --> uwu.rs:8:14
  |
3 | /         const $name: () = ();
4 | |     };
5 | | }
6 | |
7 | | extern "C" {
8 | |     hello! { yes }
  | |             -^^^
  | |_____________|
  |               help: try using a static value: `static`
  |

The suggestion suggests replacing all the code between the macro definition and macro invocation with static, which is not good at all :D.
We just want the span of the const keyword, and nothing more. Maybe there's a helper somewhere for this, I'm not sure.

@Noratrieb Noratrieb 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-review Status: Awaiting review from the assignee but also interested parties. labels Oct 15, 2023
@Dylan-DPC
Copy link
Member

@bvanjoi any updates on this?

@bvanjoi
Copy link
Contributor Author

bvanjoi commented Nov 15, 2023

Apologies for the late response.

I have utilized can_be_used_for_suggestions to filter out invalid spans, which I think could help to clean up the output.

@bvanjoi
Copy link
Contributor Author

bvanjoi commented Nov 15, 2023

Another solution to this issue could involve setting const_span = span.with_hi(span.lo + len(kw::Const)). However, I'm uncertain which approach would be more suitable for this situation.

@bvanjoi
Copy link
Contributor Author

bvanjoi commented Nov 15, 2023

ci is green.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 15, 2023
Copy link
Member

@Noratrieb Noratrieb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will approve this if CI is happy with my style improvement. Thank you for the patience of waiting for 3 weeks while I kept forgetting that this PR existed. Next time, feel free to ping me after 2 weeks :)

compiler/rustc_parse/src/parser/item.rs Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

@Noratrieb Noratrieb force-pushed the fix-116203 branch 2 times, most recently from acabed7 to 4138702 Compare December 7, 2023 18:43
@Noratrieb
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Dec 7, 2023

📌 Commit 4138702 has been approved by Nilstrieb

It is now in the queue for this repository.

@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 Dec 7, 2023
compiler-errors added a commit to compiler-errors/rust that referenced this pull request 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 added a commit to rust-lang-ci/rust that referenced this pull request Dec 7, 2023
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#116420 (discard invalid spans in external blocks)
 - rust-lang#118686 (Only check principal trait ref for object safety)
 - rust-lang#118688 (Add method to get type of an Rvalue in StableMIR)
 - rust-lang#118707 (Ping GuillaumeGomez for changes in rustc_codegen_gcc)
 - rust-lang#118712 (targets: remove not-added {i386,i486}-unknown-linux-gnu)
 - rust-lang#118719 (CFI: Add char to CFI integer normalization)

Failed merges:

 - rust-lang#117586 (Uplift the (new solver) canonicalizer into `rustc_next_trait_solver`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 71a8ca0 into rust-lang:master Dec 8, 2023
22 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Dec 8, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request 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``
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracing warning with invalid expansion
6 participants