-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
TyCtxt::get_attr should check that no duplicates are allowed #100658
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
r? @lcnr |
r? @lcnr |
compiler/rustc_middle/src/ty/mod.rs
Outdated
let mut attrs = self.get_attrs(did, attr); | ||
let first = attrs.next(); | ||
if attrs.next().is_some() { | ||
bug!("get_attr: multiple attributes with same attr symbol"); | ||
} | ||
first |
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.
we can't check whether there are multiple attributes, but instead have to check that we only use get_attr
in cases where the compiler can reasonably deal with multiple attributes.
e.g. the following would ICE with your change (please add that as a test)
#[repr(C)]
#[repr(C)]
enum Foo {}
fn main() {}
instead check - similar to is_builtin_only_local
- whether the feature definition in rustc_feature
either warns or errors on duplicate attributes. This might not be enough as there could be some attributes where duplicates are allowed, but useless, but that's a bridge we can burn when we get to it.
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.
got it, I will dig more and ping you if I need help.
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.
We should check:
pub enum AttributeDuplicates {
#[default]
DuplicatesOk
...
}
pub enum AttributeDuplicates { |
If the attribute is marked as DuplicatesOk
WarnFollowing
, or WarnFollowingWordOnly
, then we allow multiple attributes, otherwise raise an error?
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.
We have a check for proper diagnostics,
rust/compiler/rustc_passes/src/check_attr.rs
Line 2223 in e1b28cd
ErrorFollowing | ErrorPreceding => match seen.entry(attr.name_or_empty()) { |
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.
If the attribute is marked as
DuplicatesOk
WarnFollowing
, orWarnFollowingWordOnly
, then we allow multiple attributes, otherwise raise an error?
The other way around. We should only use get_attr
for attributes which are either WarnFollowing
, ErrorFollowing
, ErrorPreceding
, FutureWarnFollowing
and FutureWarnPreceding
. For all other attributes using get_attr
is a compiler bug so we should ICE there. We should not emit errors for users in get_attr
.
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.
@lcnr Code updated and added a testcase.
1364dcb
to
7ec7edd
Compare
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.
some nits, then r=me
thanks 👍
7ec7edd
to
5e8b356
Compare
r=@lcnr |
@bors r=lcnr |
📌 Commit 5e8b356775549c66eec8cd31dcde60576268d766 has been approved by It is now in the queue for this repository. |
This comment has been minimized.
This comment has been minimized.
5e8b356
to
7d45a75
Compare
@chenyukang: 🔑 Insufficient privileges: Not in reviewers |
r? @lcnr |
@bors r+ rollup |
…r=lcnr TyCtxt::get_attr should check that no duplicates are allowed Fixes rust-lang#100631
…r=lcnr TyCtxt::get_attr should check that no duplicates are allowed Fixes rust-lang#100631
Failed on rollup: #101463 (comment) @bors r- |
7d45a75
to
575e9b6
Compare
Rebase and updated. |
because large directories are difficult to navigate, both in editors and in the github view. E.g. https://github.com/rust-lang/rust/tree/master/src/test/ui/issues currently does not show 1146 entries, which is a annoying for people manually searching for a file @bors delegate+ (after fixing the nit you can run |
✌️ @chenyukang can now approve this pull request |
📌 Commit 575e9b6414f9986f5dcdfbfc06356d554636aa86 has been approved by It is now in the queue for this repository. |
woops |
575e9b6
to
00b10a5
Compare
@bors r=lcnr |
(side-note @chenyukang it's usually best to wait until CI is green until approving a PR, just in case it fails!) |
Rollup of 5 pull requests Successful merges: - rust-lang#100658 (TyCtxt::get_attr should check that no duplicates are allowed) - rust-lang#101021 (Migrate ``rustc_middle`` diagnostic) - rust-lang#101287 (Document eager evaluation of `bool::then_some` argument) - rust-lang#101412 (Some more cleanup in `core`) - rust-lang#101427 (Fix ICE, generalize 'move generics to trait' suggestion for >0 non-rcvr arguments) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fixes #100631