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

improve error message when global_asm! uses asm! options #128207

Merged
merged 5 commits into from
Jul 27, 2024

Conversation

folkertdev
Copy link
Contributor

specifically, what was

error: expected one of `)`, `att_syntax`, or `raw`, found `preserves_flags`
  --> $DIR/bad-options.rs:45:25
   |
LL | global_asm!("", options(preserves_flags));
   |                         ^^^^^^^^^^^^^^^ expected one of `)`, `att_syntax`, or `raw`

is now

error: the `preserves_flags` option cannot be used with `global_asm!`
  --> $DIR/bad-options.rs:45:25
   |
LL | global_asm!("", options(preserves_flags));
   |                         ^^^^^^^^^^^^^^^ the `preserves_flags` option is not meaningful for global-scoped inline assembly

mirroring the phrasing of the reference.

This is also a bit of a refactor for a future naked_asm! macro (for use in #[naked] functions). Currently this sort of error can come up when switching from inline to global asm, or when a user just isn't that experienced with assembly. With naked_asm! added to the mix hitting this error is more likely.

@rustbot
Copy link
Collaborator

rustbot commented Jul 25, 2024

r? @cjgillot

rustbot has assigned @cjgillot.
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 Jul 25, 2024
@workingjubilee
Copy link
Member

r? @Amanieu

@rustbot rustbot assigned Amanieu and unassigned cjgillot Jul 25, 2024
@Amanieu
Copy link
Member

Amanieu commented Jul 27, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Jul 27, 2024

📌 Commit 8859da0 has been approved by Amanieu

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 Jul 27, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 27, 2024
…r=Amanieu

improve error message when `global_asm!` uses `asm!` options

specifically, what was

    error: expected one of `)`, `att_syntax`, or `raw`, found `preserves_flags`
      --> $DIR/bad-options.rs:45:25
       |
    LL | global_asm!("", options(preserves_flags));
       |                         ^^^^^^^^^^^^^^^ expected one of `)`, `att_syntax`, or `raw`

is now

    error: the `preserves_flags` option cannot be used with `global_asm!`
      --> $DIR/bad-options.rs:45:25
       |
    LL | global_asm!("", options(preserves_flags));
       |                         ^^^^^^^^^^^^^^^ the `preserves_flags` option is not meaningful for global-scoped inline assembly

mirroring the phrasing of the [reference](https://doc.rust-lang.org/reference/inline-assembly.html#options).

This is also a bit of a refactor for a future `naked_asm!` macro (for use in `#[naked]` functions). Currently this sort of error can come up when switching from inline to global asm, or when a user just isn't that experienced with assembly. With  `naked_asm!` added to the mix hitting this error is more likely.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 27, 2024
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#128006 (Make `missing_fragment_specifier` an error in edition 2024)
 - rust-lang#128207 (improve error message when `global_asm!` uses `asm!` options)
 - rust-lang#128266 (update `rust.channel` default value documentation)

r? `@ghost`
`@rustbot` modify labels: rollup
@matthiaskrgr
Copy link
Member

@bors r-
#128268 (comment)

@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 Jul 27, 2024
@folkertdev
Copy link
Contributor Author

so CI fails on some of the aarch64 tests. I'm on x86, so how am I supposed to update those? for some using no_core works, but for tests/ui/asm/aarch64/parse-error.rs it doesn't because that actually used std (the format macro specifically)

@Amanieu
Copy link
Member

Amanieu commented Jul 27, 2024

You can run the UI tests with a cross-compiler by running ./x.py test tests/ui/asm --target aarch64-unknown-linux-gnu --bless

@@ -0,0 +1,10 @@
//@ run-rustfix
Copy link
Member

Choose a reason for hiding this comment

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

This probably needs //@ needs-asm-support otherwise it will fail on targets without asm support.

@Amanieu
Copy link
Member

Amanieu commented Jul 27, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Jul 27, 2024

📌 Commit 33b5ca9 has been approved by Amanieu

It is now in the queue for this repository.

@bors bors removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 27, 2024
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jul 27, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 27, 2024
Rollup of 8 pull requests

Successful merges:

 - rust-lang#125897 (from_ref, from_mut: clarify documentation)
 - rust-lang#128207 (improve error message when `global_asm!` uses `asm!` options)
 - rust-lang#128241 (Remove logic to suggest clone of function output)
 - rust-lang#128259 ([illumos/solaris] set MSG_NOSIGNAL while writing to sockets)
 - rust-lang#128262 (Delete `SimplifyArmIdentity` and `SimplifyBranchSame` tests)
 - rust-lang#128266 (update `rust.channel` default value documentation)
 - rust-lang#128267 (Add rustdoc GUI test to check title with and without search)
 - rust-lang#128271 (Disable jump threading of float equality)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9164dbd into rust-lang:master Jul 27, 2024
6 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Jul 27, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jul 27, 2024
Rollup merge of rust-lang#128207 - folkertdev:asm-parser-generalize, r=Amanieu

improve error message when `global_asm!` uses `asm!` options

specifically, what was

    error: expected one of `)`, `att_syntax`, or `raw`, found `preserves_flags`
      --> $DIR/bad-options.rs:45:25
       |
    LL | global_asm!("", options(preserves_flags));
       |                         ^^^^^^^^^^^^^^^ expected one of `)`, `att_syntax`, or `raw`

is now

    error: the `preserves_flags` option cannot be used with `global_asm!`
      --> $DIR/bad-options.rs:45:25
       |
    LL | global_asm!("", options(preserves_flags));
       |                         ^^^^^^^^^^^^^^^ the `preserves_flags` option is not meaningful for global-scoped inline assembly

mirroring the phrasing of the [reference](https://doc.rust-lang.org/reference/inline-assembly.html#options).

This is also a bit of a refactor for a future `naked_asm!` macro (for use in `#[naked]` functions). Currently this sort of error can come up when switching from inline to global asm, or when a user just isn't that experienced with assembly. With  `naked_asm!` added to the mix hitting this error is more likely.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 4, 2024
…operand, r=Amanieu

improve error message when `global_asm!` uses `asm!` operands

follow-up to rust-lang#128207

what was

```
error: expected expression, found keyword `in`
 --> src/lib.rs:1:31
  |
1 | core::arch::global_asm!("{}", in(reg));
  |                               ^^ expected expression
```

becomes

```
error: the `in` operand cannot be used with `global_asm!`
  --> $DIR/parse-error.rs:150:19
   |
LL | global_asm!("{}", in(reg));
   |                   ^^ the `in` operand is not meaningful for global-scoped inline assembly, remove it
```

the span of the error is just the keyword, which means that we can't create a machine-applicable suggestion here. The alternative would be to attempt to parse the full operand, but then if there are syntax errors in the operand those would  be presented to the user, even though the parser already knows that the output won't be valid. Also that would require more complexity in the parser.

So I think this is a nice improvement at very low cost.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 4, 2024
…operand, r=Amanieu

improve error message when `global_asm!` uses `asm!` operands

follow-up to rust-lang#128207

what was

```
error: expected expression, found keyword `in`
 --> src/lib.rs:1:31
  |
1 | core::arch::global_asm!("{}", in(reg));
  |                               ^^ expected expression
```

becomes

```
error: the `in` operand cannot be used with `global_asm!`
  --> $DIR/parse-error.rs:150:19
   |
LL | global_asm!("{}", in(reg));
   |                   ^^ the `in` operand is not meaningful for global-scoped inline assembly, remove it
```

the span of the error is just the keyword, which means that we can't create a machine-applicable suggestion here. The alternative would be to attempt to parse the full operand, but then if there are syntax errors in the operand those would  be presented to the user, even though the parser already knows that the output won't be valid. Also that would require more complexity in the parser.

So I think this is a nice improvement at very low cost.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 4, 2024
Rollup merge of rust-lang#128305 - folkertdev:asm-parser-unsupported-operand, r=Amanieu

improve error message when `global_asm!` uses `asm!` operands

follow-up to rust-lang#128207

what was

```
error: expected expression, found keyword `in`
 --> src/lib.rs:1:31
  |
1 | core::arch::global_asm!("{}", in(reg));
  |                               ^^ expected expression
```

becomes

```
error: the `in` operand cannot be used with `global_asm!`
  --> $DIR/parse-error.rs:150:19
   |
LL | global_asm!("{}", in(reg));
   |                   ^^ the `in` operand is not meaningful for global-scoped inline assembly, remove it
```

the span of the error is just the keyword, which means that we can't create a machine-applicable suggestion here. The alternative would be to attempt to parse the full operand, but then if there are syntax errors in the operand those would  be presented to the user, even though the parser already knows that the output won't be valid. Also that would require more complexity in the parser.

So I think this is a nice improvement at very low cost.
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Aug 5, 2024
…r=Amanieu

improve error message when `global_asm!` uses `asm!` operands

follow-up to rust-lang/rust#128207

what was

```
error: expected expression, found keyword `in`
 --> src/lib.rs:1:31
  |
1 | core::arch::global_asm!("{}", in(reg));
  |                               ^^ expected expression
```

becomes

```
error: the `in` operand cannot be used with `global_asm!`
  --> $DIR/parse-error.rs:150:19
   |
LL | global_asm!("{}", in(reg));
   |                   ^^ the `in` operand is not meaningful for global-scoped inline assembly, remove it
```

the span of the error is just the keyword, which means that we can't create a machine-applicable suggestion here. The alternative would be to attempt to parse the full operand, but then if there are syntax errors in the operand those would  be presented to the user, even though the parser already knows that the output won't be valid. Also that would require more complexity in the parser.

So I think this is a nice improvement at very low cost.
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.

8 participants