Skip to content

Rewrite inline attribute parser to use new infrastructure and improve diagnostics for all parsed attributes #138165

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

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

jdonszelmann
Copy link
Contributor

@jdonszelmann jdonszelmann commented Mar 7, 2025

r? @oli-obk

This PR:

Builds on top of #138164

Closes #137950

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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 Mar 7, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@@ -584,7 +546,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
return OptimizeAttr::Default;
};

inline_span = Some(attr.span());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fixes #137950

@jdonszelmann jdonszelmann force-pushed the inline branch 2 times, most recently from e6dad01 to 2a707bf Compare March 9, 2025 15:34
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Mar 11, 2025

☔ The latest upstream changes (presumably #138302) made this pull request unmergeable. Please resolve the merge conflicts.

@oli-obk oli-obk 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 Apr 28, 2025
@jdonszelmann jdonszelmann force-pushed the inline branch 2 times, most recently from b7dda57 to 88a713a Compare June 9, 2025 22:40
@rust-log-analyzer

This comment has been minimized.

@jdonszelmann
Copy link
Contributor Author

@rustbot review

@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 Jun 9, 2025
@rust-log-analyzer

This comment has been minimized.

@jdonszelmann
Copy link
Contributor Author

ah shit, broke clippy 😭

|
LL | #[rustc_confusables("invalid_meta_item")]
| + +
LL | #[rustc_confusables(invalid_meta_item)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rewording, arguably worse but consistent with other error messages with a consistent error code (as opposed to a dedicated diagnostic for this attribute only)

The `inline` attribute was malformed.

Erroneous code example:

```compile_fail,E0534
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no longer emitted because it's specific to inline. I kind of want to avoid those in favor of generic attribute related error codes

@@ -49,3 +48,29 @@ struct Stable;
#[rustc_const_stable(feature = "stable_fn", since = "1.39.0")] // ok!
const fn stable_fn() {}
```
Copy link
Contributor Author

Choose a reason for hiding this comment

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

error code upgraded to represent the more generic issue of the structure of an attribute not matching the expected structure

Erroneous code example:

```compile_fail,E0540
#[inline()] // error! should either have a single argument, or no parentheses
Copy link
Contributor Author

Choose a reason for hiding this comment

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

new generic error code for argument mismatch. 540 was not used.

|
LL | #[deprecated(since = "a", note)]
| ^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^----^^
Copy link
Contributor Author

@jdonszelmann jdonszelmann Jun 10, 2025

Choose a reason for hiding this comment

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

much more detailed error messages

@@ -313,6 +303,16 @@ error[E0517]: attribute should be applied to a struct, enum, or union
LL | #[repr(Rust)] impl S { }
| ^^^^ ---------- not a struct, enum, or union

error: valid forms for the attribute are `#[inline(always|never)]` and `#[inline]`
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:44:5
|
Copy link
Contributor Author

Choose a reason for hiding this comment

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

error message moved

|
LL | fn barqux(#[rustc_force_inline] _x: u32) {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is a genuine regression, I think because check_attr now has to see this as a parsed attribute, let me fix that

@@ -8,7 +8,7 @@ extern crate std;
// issue#97006

macro_rules! m { ($attr_path: path) => { #[$attr_path] fn f() {} } }
#[inline]
#[attr = Inline(Hint)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@obi1kenobi is this one relevant for CSC? I'm going to upgrade more attributes like this I'm afraid

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the ping! I think we don't SemVer-check based on it, but we do parse it so it'd be great to go back to emitting it as #[inline] in rustdoc JSON in a separate PR if possible. cc @aDotInTheVoid

Copy link
Contributor Author

@jdonszelmann jdonszelmann Jun 10, 2025

Choose a reason for hiding this comment

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

mhm, I messaged Alona today as well, since it's technically also a breaking change in rustdoc json. However, it's really annoying since I'll be making about a 100 separate breaking changes like this in the coming months.... and practically few people will care

Copy link
Contributor Author

Choose a reason for hiding this comment

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

at the very least the debug representation is much more consistent nowadays. However, I think the solution is not to see this as a breaking change in the format, but just an unspecified part of the format you can't rely on at the moment until we stabilize it in a more structured way...

Copy link
Member

Choose a reason for hiding this comment

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

I think the solution is not to see this as a breaking change in the format, but just an unspecified part of the format you can't rely on at the moment

I think this is a fine mental model but I think it'll be frustrating to many users regardless, because we've given plenty of time to Hyrum's Law to kick in here.

Telling broken users "we're technically right, it was your assumptions that were wrong" will not make them any happier about it. So I think we should approach this situation with empathy for those users, and attempt to do what we can to minimize the negative impact as best as circumstances allow.

@jdonszelmann
Copy link
Contributor Author

note, there are tests that tests the newly emitted lints during attr parsing. However, it works so well, none of them changed! They are emitted though, but exactly the same as they already were so it doesn't show up in the diff. Hard to check, but great!

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the A-rustdoc-json Area: Rustdoc JSON backend label Jun 10, 2025
@bors
Copy link
Collaborator

bors commented Jun 10, 2025

☔ The latest upstream changes (presumably #142299) made this pull request unmergeable. Please resolve the merge conflicts.

jdonszelmann and others added 4 commits June 11, 2025 00:23
 lint on duplicates during attribute parsing
To do this we stuff them in the diagnostic context to be emitted after
hir is constructed
@rust-log-analyzer

This comment has been minimized.

@jdonszelmann
Copy link
Contributor Author

ugh, the rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-json Area: Rustdoc JSON backend 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Diagnostics error in interaction between #[optimize(..)] and #[no_sanitize(..)]
6 participants