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

Allow multiple suggestions for malformed crate_type attribute #130923

Conversation

Blindspot22
Copy link

Solves these #61288

@rustbot
Copy link
Collaborator

rustbot commented Sep 27, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nnethercote (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@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 Sep 27, 2024
@rustbot
Copy link
Collaborator

rustbot commented Sep 27, 2024

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

@lnicola
Copy link
Member

lnicola commented Sep 27, 2024

I think you got the wrong file, #61288 points to rust/src/libsyntax/feature_gate.rs.

@rust-log-analyzer

This comment has been minimized.

@Dylan-DPC Dylan-DPC 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 Sep 27, 2024
@Blindspot22
Copy link
Author

I think you got the wrong file, #61288 points to rust/src/libsyntax/feature_gate.rs.

I think since the last time this issue was made, refactors have been made and the libsyntax folder doesn't exist or if isn't found under the src directory and

I think you got the wrong file, #61288 points to rust/src/libsyntax/feature_gate.rs.

Hello @lnicola to begin with, I think that the path isn't valid again cause a lot of changes have been made since the creation of these issue.

The must have been some refactor cause the libsyntax directory doesn't seem to exit again and the feature_gate.rs file is now found in this path rust/compiler/rustc_ast_passes/src/feature_gate.rs rather.

Moreover if you look into that feature_gate.rs file you will see that the pub struct AttributeTemplate implementation was removed from it.

@Blindspot22
Copy link
Author

Blindspot22 commented Sep 27, 2024

After a couple of diggings i found the pub struct AttributeTemplate implementation in the inert_attr_macro.rs file

Screenshot from 2024-09-27 11-23-01

And if you look carefully as from line 21 to 28 you will see it was done by Lukas Wirth 3 years ago same as done here src/libsyntax/feature_gate.rs from line 870 to 877.

@lnicola
Copy link
Member

lnicola commented Sep 27, 2024

@Blindspot22 rust-analyzer is in most part a reimplementation of the compiler, so you should never need to modify r-a to fix a compiler issue.

@Blindspot22
Copy link
Author

@Blindspot22 rust-analyzer is in most part a reimplementation of the compiler, so you should never need to modify r-a to fix a compiler issue.

Okay thanks for that info 👍

@jieyouxu
Copy link
Member

@Blindspot22 you can find where this diagnostic is emitted in rustc with [-Ztreat-err-as-bug=1]

gh-jieyouxu@dev-desktop-eu-1:~$ rustc +stage1 test.rs -Ztreat-err-as-bug=1
error: internal compiler error: malformed `crate_type` attribute input
 --> test.rs:1:1
  |
1 | #![crate_type]
  | ^^^^^^^^^^^^^^ help: must be of the form: `#![crate_type = "bin|lib|..."]`

thread 'rustc' panicked at compiler/rustc_errors/src/lib.rs:1763:17:
aborting due to `-Z treat-err-as-bug=1`
stack backtrace:
[irrelevant lines trimmed]
  30:     0xf95c0a21e72c - rustc_parse[4ae35f3312fdabf2]::validate_attr::emit_malformed_attribute
                               at /home/gh-jieyouxu/rust/compiler/rustc_parse/src/validate_attr.rs:272:9

@jieyouxu
Copy link
Member

Might be able to massage

fn emit_malformed_attribute(

to produce extra help by matching on rustc_session::CrateType if the attribute under check is sym::crate_type.

@Dylan-DPC

This comment was marked as resolved.

@bors

This comment was marked as off-topic.

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 27, 2024
…-in-template-for-bad-attribute-use-rust-lang#61288, r=<try>

Allow multiple suggestions for malformed crate_type attribute

Solves these rust-lang#61288
@bors

This comment was marked as off-topic.

@rust-log-analyzer

This comment has been minimized.

@alex-semenyuk
Copy link
Member

@Blindspot22
From wg-triage. Any updates on this PR?

@Blindspot22
Copy link
Author

Blindspot22 commented Dec 16, 2024

@Blindspot22 From wg-triage. Any updates on this PR?

Hello @alex-semenyuk. Sorry I have been kind of busy lately and forgot about this, working on it right away 👍

@rust-log-analyzer

This comment has been minimized.

@Blindspot22
Copy link
Author

Hey @jieyouxu I'm having this issue. Meanwhile we're intentionally testing a malformed attribute.
Screenshot from 2024-12-16 11-51-35

We actually want that each time someone uses #![crate_type]. The person should specify if its either "bin" or "lib" they wanna attribute to it with.

@Blindspot22
Copy link
Author

Blindspot22 commented Dec 16, 2024

It obviously needs to be a failing test with a .stderr
Screenshot from 2024-12-16 12-03-33
Which i further enhanced for easy understanding and clearer for users to correct their code. But the below CI 👀 keeps failing

@rust-log-analyzer

This comment has been minimized.

@nnethercote
Copy link
Contributor

@Blindspot22: You have modified the AttributeTemplate type, which is a good start. You also need to change all the places that use AttributeTemplate type. That's what the compile errors in the most recent CI run are about. Once that's working it makes sense to update the .stderr file with the expected test output.

Also, you should squash the commits into a single commit, because they don't make sense individually.

And the tests/ui/no_crate_type.stderr has somehow had its final newline removed. Might be a text editor issue?

@Blindspot22
Copy link
Author

Blindspot22 commented Dec 17, 2024

@Blindspot22: You have modified the AttributeTemplate type, which is a good start. You also need to change all the places that use AttributeTemplate type. That's what the compile errors in the most recent CI run are about. Once that's working it makes sense to update the .stderr file with the expected test output.

Also, you should squash the commits into a single commit, because they don't make sense individually.

And the tests/ui/no_crate_type.stderr has somehow had its final newline removed. Might be a text editor issue?

Okay thanks @nnethercote on that 👍

@Blindspot22 Blindspot22 reopened this Dec 17, 2024
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Jan 24, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jan 24, 2025

There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged.

You can start a rebase with the following commands:

$ # rebase
$ git pull --rebase https://github.com/rust-lang/rust.git master
$ git push --force-with-lease

The following commits are merge commits:

@rust-log-analyzer

This comment has been minimized.

@Blindspot22
Copy link
Author

Blindspot22 commented Jan 24, 2025

Hey @nnethercote, a small look in on this might help :)

@bors
Copy link
Contributor

bors commented Jan 25, 2025

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

Copy link
Contributor

@nnethercote nnethercote left a comment

Choose a reason for hiding this comment

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

This is getting closer, but there are still some problems.

  • There is a merge commit, which isn't acceptable, as explained here.
  • Something weird has happened with the merge commit, which is causing the compile errors.
  • The change to rust/src/test/ui/no_crate_type.stderr present in an earlier commit has been reverted in a later commit. This change is the motivation for this whole PR.
  • The multiple commits still need to be squashed.
  • Plus the various comments I have made below.

Please make sure these are fixed. If any of them are unclear, feel free to ask for clarification here or on Zulip.

@Blindspot22
Copy link
Author

This is getting closer, but there are still some problems.

* There is a merge commit, which isn't acceptable, as explained [here](https://github.com/rust-lang/rust/pull/130923#issuecomment-2612132083).

* Something weird has happened with the merge commit, which is causing the compile errors.

* The change to `rust/src/test/ui/no_crate_type.stderr` present in an earlier commit has been reverted in a later commit. This change is the motivation for this whole PR.

* The multiple commits still need to be squashed.

* Plus the various comments I have made below.

Please make sure these are fixed. If any of them are unclear, feel free to ask for clarification here or on Zulip.

Hello @nnethercote thanks. I'm presently working on the changes, almost done. As for the squash i was thinking of doing that after all the changes are good and ready for merge, such that i have just 1 squash

@Blindspot22
Copy link
Author

Blindspot22 commented Jan 27, 2025

There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged.

You can start a rebase with the following commands:

$ # rebase
$ git pull --rebase https://github.com/rust-lang/rust.git master
$ git push --force-with-lease

The following commits are merge commits:

* [9fae9f4](https://github.com/rust-lang/rust/commit/9fae9f4ed9de6b2a31b675b72bf5ab694892b052)

Hello @nnethercote to solve the no merge policy and squash issue i created a new branch/PR with reference to this one here below
New PR

@nnethercote
Copy link
Contributor

It would have been possible to remove the merge commit in this PR, but given that #136125 has been opened I will close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

9 participants