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

TyCtxt::get_attr should check that no duplicates are allowed #100658

Merged
merged 1 commit into from
Sep 6, 2022

Conversation

chenyukang
Copy link
Member

Fixes #100631

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 17, 2022
@rust-highfive
Copy link
Collaborator

r? @compiler-errors

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 17, 2022
@compiler-errors
Copy link
Member

r? @lcnr

@chenyukang
Copy link
Member Author

r? @lcnr
Not sure we need to check any other parts.
I tested with UI, not assertion crash will be triggered.

Comment on lines 2284 to 2289
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
Copy link
Contributor

@lcnr lcnr Aug 17, 2022

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.

Copy link
Member Author

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.

Copy link
Member Author

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?

Copy link
Member Author

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,

ErrorFollowing | ErrorPreceding => match seen.entry(attr.name_or_empty()) {

Copy link
Contributor

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, or WarnFollowingWordOnly, 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.

Copy link
Member Author

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.

Copy link
Contributor

@lcnr lcnr left a 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 👍

compiler/rustc_feature/src/builtin_attrs.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/ty/mod.rs Outdated Show resolved Hide resolved
src/test/ui/issues/issue-100631.rs Outdated Show resolved Hide resolved
@chenyukang
Copy link
Member Author

r=@lcnr

@compiler-errors
Copy link
Member

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Aug 21, 2022

📌 Commit 5e8b356775549c66eec8cd31dcde60576268d766 has been approved by lcnr

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 Aug 21, 2022
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Aug 30, 2022

@chenyukang: 🔑 Insufficient privileges: Not in reviewers

@chenyukang
Copy link
Member Author

r? @lcnr

@lcnr
Copy link
Contributor

lcnr commented Sep 5, 2022

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Sep 5, 2022

📌 Commit 7d45a75 has been approved by lcnr

It is now in the queue for this repository.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 5, 2022
…r=lcnr

TyCtxt::get_attr should check that no duplicates are allowed

Fixes rust-lang#100631
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Sep 5, 2022
…r=lcnr

TyCtxt::get_attr should check that no duplicates are allowed

Fixes rust-lang#100631
@JohnTitor
Copy link
Member

Failed on rollup: #101463 (comment)
This needs a rebase and to move the test outside of src/test/ui/issues.

@bors r-

@bors bors removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Sep 5, 2022
@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 5, 2022
@chenyukang
Copy link
Member Author

Failed on rollup: #101463 (comment) This needs a rebase and to move the test outside of src/test/ui/issues.

@bors r-

Rebase and updated.
Out of curious, why we would want to limit the file number in src/test/ui/issues?

@lcnr
Copy link
Contributor

lcnr commented Sep 6, 2022

Out of curious, why we would want to limit the file number in src/test/ui/issues?

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 @bors r=lcnr)

@bors
Copy link
Contributor

bors commented Sep 6, 2022

✌️ @chenyukang can now approve this pull request

@bors
Copy link
Contributor

bors commented Sep 6, 2022

📌 Commit 575e9b6414f9986f5dcdfbfc06356d554636aa86 has been approved by lcnr)`

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 6, 2022
@lcnr
Copy link
Contributor

lcnr commented Sep 6, 2022

woops
@bors r-

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 6, 2022
@chenyukang
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Sep 6, 2022

📌 Commit 00b10a5 has been approved by lcnr

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 6, 2022
@compiler-errors
Copy link
Member

(side-note @chenyukang it's usually best to wait until CI is green until approving a PR, just in case it fails!)

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 6, 2022
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
@bors bors merged commit 3f22020 into rust-lang:master Sep 6, 2022
@rustbot rustbot added this to the 1.65.0 milestone Sep 6, 2022
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.

TyCtxt::get_attr should check that no duplicates are allowed
8 participants