-
Notifications
You must be signed in to change notification settings - Fork 13.4k
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
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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()); |
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.
This fixes #137950
e6dad01
to
2a707bf
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #138302) made this pull request unmergeable. Please resolve the merge conflicts. |
b7dda57
to
88a713a
Compare
This comment has been minimized.
This comment has been minimized.
@rustbot review |
This comment has been minimized.
This comment has been minimized.
ah shit, broke clippy 😭 |
@@ -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 | |||
| |
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.
error message moved
| | ||
LL | fn barqux(#[rustc_force_inline] _x: u32) {} |
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.
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)] |
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.
@obi1kenobi is this one relevant for CSC? I'm going to upgrade more attributes like this I'm afraid
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.
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
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.
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
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.
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...
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.
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.
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! |
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #142299) made this pull request unmergeable. Please resolve the merge conflicts. |
3446ca2
to
dda1c4a
Compare
This comment has been minimized.
This comment has been minimized.
ugh, the rebase |
☔ The latest upstream changes (presumably #142381) made this pull request unmergeable. Please resolve the merge conflicts. |
lint on duplicates during attribute parsing To do this we stuff them in the diagnostic context to be emitted after hir is constructed
…ra, r=oli-obk Infrastructure for lints during attribute parsing, specifically duplicate usages of attributes r? `@oli-obk` This PR adds a new field to OwnerInfo to buffer lints which are generated during attribute parsing and ast lowering in general. They can't be emitted at this stage because at that point there's no HIR yet, and early lints are already emitted. This also adds the generic `S: Stage` to attribute parsers. Currently we don't emit any lints during early attribute parsing, but if we ever want to that logic will be different. That's because there we don't have hir ids yet, while at the same time still having access to node ids and early lints. Even though that logic isn't completely there in this PR (no worries, we don't use it), that's why the parameter is there. With this PR, we also add 2 associated consts to `SingleAttributeParser`. Those determine what logic should be applied when finding a duplicate attribute. This PR was getting pretty large, so the first code using this logic is in rust-lang#138165. This code is all new things that weren't possible before so it also doesn't break any behaviour. However, some of it will be dead code right now. I recommend reviewing both before merging, though in some sense that doubles the size of the review again, and the other PR might be more controversial. Let me know how you want to do this `@oli-obk`
Infrastructure for lints during attribute parsing, specifically duplicate usages of attributes r? `@oli-obk` This PR adds a new field to OwnerInfo to buffer lints which are generated during attribute parsing and ast lowering in general. They can't be emitted at this stage because at that point there's no HIR yet, and early lints are already emitted. This also adds the generic `S: Stage` to attribute parsers. Currently we don't emit any lints during early attribute parsing, but if we ever want to that logic will be different. That's because there we don't have hir ids yet, while at the same time still having access to node ids and early lints. Even though that logic isn't completely there in this PR (no worries, we don't use it), that's why the parameter is there. With this PR, we also add 2 associated consts to `SingleAttributeParser`. Those determine what logic should be applied when finding a duplicate attribute. This PR was getting pretty large, so the first code using this logic is in #138165. This code is all new things that weren't possible before so it also doesn't break any behaviour. However, some of it will be dead code right now. I recommend reviewing both before merging, though in some sense that doubles the size of the review again, and the other PR might be more controversial. Let me know how you want to do this `@oli-obk`
r? @oli-obk
This PR:
Builds on top of #138164
Closes #137950