Skip to content

Rewrite on_unimplemented format string parser. #139091

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

Merged
merged 8 commits into from
Apr 20, 2025
Merged

Conversation

mejrs
Copy link
Contributor

@mejrs mejrs commented Mar 29, 2025

This PR rewrites the format string parser for rustc_on_unimplemented and diagnostic::on_unimplemented. I plan on moving this code (and more) into the new attribute parsing system soon and wanted to PR it separately.

This PR introduces some minor differences though:

  • rustc_on_unimplemented on trait implementations is no longer checked/used - this is actually never used (outside of some tests) so I plan on removing it in the future.
  • for rustc_on_unimplemented, it introduces the {This} argument in favor of {ThisTraitname} (to be removed later). It'll be easier to parse.
  • for rustc_on_unimplemented, Self can now consistently be used as a filter, rather than just _Self. It used to not match correctly on for example Self = "[{integer}]"
  • Some error messages now have better spans.

Fixes #130627

@rustbot
Copy link
Collaborator

rustbot commented Mar 29, 2025

r? @jackh726

rustbot has assigned @jackh726.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Mar 29, 2025
@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Mar 29, 2025

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@mejrs mejrs force-pushed the format branch 2 times, most recently from 8f91772 to 232c722 Compare April 1, 2025 00:47
@bors
Copy link
Collaborator

bors commented Apr 9, 2025

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

@mejrs
Copy link
Contributor Author

mejrs commented Apr 9, 2025

r? @compiler-errors (or reroll)

@rustbot rustbot assigned compiler-errors and unassigned jackh726 Apr 9, 2025
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

ill actually look at this tomorrow, just a few actionable things until then

@@ -63,9 +60,8 @@ error[E0277]: the trait bound `[i32]: Index<Bar<u32>>` is not satisfied
--> $DIR/multiple-impls.rs:39:5
|
LL | Index::index(&[] as &[i32], Bar(2u32));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ on impl for Bar
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove the rustc_on_unimplemented from impls in these test files?

Copy link
Member

Choose a reason for hiding this comment

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

ideally we'd make it a validation error or something to put this on an impl

Copy link
Member

Choose a reason for hiding this comment

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

so I plan on removing it in the future.

why not now? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for a couple reasons:

  • in b1bc725 I deleted its only use in std, but it's still present in the beta std. I'm unsure whether raising an error would cause problems.
  • rather than adding that check to this PR I'd rather do it in a future hir attributes related PR
  • I'm not intimately familiar with this code so didn't feel like raising new errors.

I'm happy to start raising errors now if you'd prefer.

Copy link
Member

Choose a reason for hiding this comment

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

Well, I'd at least prefer for us to clean up the UI tests so they don't look like they're buggy (i.e. have annotations on impls, but don't use them).

I feel like the easiest way of doing that is just making rustc_on_unimplemented an error then clean up the new errors in the UI tests, but it's up to you I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the "now the ui tests look buggy" argument is compelling to me, i'll experiment with a hard error tomorrow

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've deleted the tests for attribute on impls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ideally we'd make it a validation error or something to put this on an impl

it's not a validation error to put it anywhere, you can put it on structs, functions, etc. I would like to start erroring on all of that after migrating the attribute itself.

@rustbot rustbot added A-tidy Area: The tidy tool T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Apr 10, 2025
@mejrs
Copy link
Contributor Author

mejrs commented Apr 10, 2025

the Tidy/bootstrap labels are just because it deletes a issue-###.rs test

@compiler-errors
Copy link
Member

One nit, though I didn't review this for perfect parity with the previous behavior, it looks fine to me.

@compiler-errors
Copy link
Member

@rustbot author

@rustbot rustbot 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 13, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 13, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@mejrs
Copy link
Contributor Author

mejrs commented Apr 13, 2025

I've fixed the doc comment. Thanks for the review :)

@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 Apr 13, 2025
@mejrs
Copy link
Contributor Author

mejrs commented Apr 18, 2025

@compiler-errors ping 🙏

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 18, 2025

📌 Commit 4a5369b has been approved by compiler-errors

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 Apr 18, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 19, 2025
…enton

Rollup of 8 pull requests

Successful merges:

 - rust-lang#138934 (support config extensions)
 - rust-lang#139091 (Rewrite on_unimplemented format string parser.)
 - rust-lang#139753 (Make `#[naked]` an unsafe attribute)
 - rust-lang#139762 (Don't assemble non-env/bound candidates if projection is rigid)
 - rust-lang#139834 (Don't canonicalize crate paths)
 - rust-lang#139868 (Move `pal::env` to `std::sys::env_consts`)
 - rust-lang#139978 (Add citool command for generating a test dashboard)
 - rust-lang#139995 (Clean UI tests 4 of n)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 20, 2025
…enton

Rollup of 8 pull requests

Successful merges:

 - rust-lang#138934 (support config extensions)
 - rust-lang#139091 (Rewrite on_unimplemented format string parser.)
 - rust-lang#139753 (Make `#[naked]` an unsafe attribute)
 - rust-lang#139762 (Don't assemble non-env/bound candidates if projection is rigid)
 - rust-lang#139834 (Don't canonicalize crate paths)
 - rust-lang#139868 (Move `pal::env` to `std::sys::env_consts`)
 - rust-lang#139978 (Add citool command for generating a test dashboard)
 - rust-lang#139995 (Clean UI tests 4 of n)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 20, 2025
…enton

Rollup of 8 pull requests

Successful merges:

 - rust-lang#138934 (support config extensions)
 - rust-lang#139091 (Rewrite on_unimplemented format string parser.)
 - rust-lang#139753 (Make `#[naked]` an unsafe attribute)
 - rust-lang#139762 (Don't assemble non-env/bound candidates if projection is rigid)
 - rust-lang#139834 (Don't canonicalize crate paths)
 - rust-lang#139868 (Move `pal::env` to `std::sys::env_consts`)
 - rust-lang#139978 (Add citool command for generating a test dashboard)
 - rust-lang#139995 (Clean UI tests 4 of n)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit aad59a3 into rust-lang:master Apr 20, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 20, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 20, 2025
Rollup merge of rust-lang#139091 - mejrs:format, r=compiler-errors

Rewrite on_unimplemented format string parser.

This PR rewrites the format string parser for `rustc_on_unimplemented` and `diagnostic::on_unimplemented`. I plan on moving this code (and more) into the new attribute parsing system soon and wanted to PR it separately.

This PR introduces some minor differences though:
- `rustc_on_unimplemented` on trait *implementations* is no longer checked/used - this is actually never used (outside of some tests) so I plan on removing it in the future.
- for `rustc_on_unimplemented`, it introduces the `{This}` argument in favor of `{ThisTraitname}` (to be removed later). It'll be easier to parse.
- for `rustc_on_unimplemented`, `Self` can now consistently be used as a filter, rather than just `_Self`. It used to not match correctly on for example `Self = "[{integer}]"`
- Some error messages now have better spans.

Fixes rust-lang#130627
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Apr 22, 2025
…enton

Rollup of 8 pull requests

Successful merges:

 - rust-lang#138934 (support config extensions)
 - rust-lang#139091 (Rewrite on_unimplemented format string parser.)
 - rust-lang#139753 (Make `#[naked]` an unsafe attribute)
 - rust-lang#139762 (Don't assemble non-env/bound candidates if projection is rigid)
 - rust-lang#139834 (Don't canonicalize crate paths)
 - rust-lang#139868 (Move `pal::env` to `std::sys::env_consts`)
 - rust-lang#139978 (Add citool command for generating a test dashboard)
 - rust-lang#139995 (Clean UI tests 4 of n)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tidy Area: The tidy tool S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

RFC #1733 (Trait Aliases): compilation crash when putting "diagnostic::on_unimplemented" on alias
6 participants