Files
rust/tests/ui/loop-match/invalid-attribute.rs
Nicholas Nethercote 35b1187a65 Improve consistency of InvalidTarget attribute error messages
Mostly in a fashion similar to the previous commit.

There is one exceptional case: for errors involving `repr` the argument
is significant. For these, the argument is included in the error line
and the caret highlighting, e.g.
```
error: the `repr(C)` attribute cannot be used on functions
  --> $DIR/naked-with-invalid-repr-attr.rs:10:3
   |
LL | #[repr(C)]
   |   ^^^^^^^
   |
   = help: the `repr(C)` attribute can only be applied to data types
```

Contrast this with a more typical argument-excluding case used
everywhere else:
```
error: the `rustc_abi` attribute cannot be used on associated consts
  --> $DIR/debug.rs:46:7
   |
LL |     #[rustc_abi(debug)]
   |       ^^^^^^^^^
   |
   = help: the `rustc_abi` attribute can be applied to functions and type aliases
```
2026-07-24 12:58:31 +10:00

45 lines
1.2 KiB
Rust

// Test that the `#[loop_match]` and `#[const_continue]` attributes can only be
// placed on expressions.
#![allow(incomplete_features)]
#![feature(loop_match)]
#![loop_match] //~ ERROR attribute cannot be used on
#![const_continue] //~ ERROR attribute cannot be used on
extern "C" {
#[loop_match] //~ ERROR attribute cannot be used on
#[const_continue] //~ ERROR attribute cannot be used on
fn f();
}
#[loop_match] //~ ERROR attribute cannot be used on
#[const_continue] //~ ERROR attribute cannot be used on
#[repr(C)]
struct S {
a: u32,
b: u32,
}
trait Invoke {
#[loop_match] //~ ERROR attribute cannot be used on
#[const_continue] //~ ERROR attribute cannot be used on
extern "C" fn invoke(&self);
}
#[loop_match] //~ ERROR attribute cannot be used on
#[const_continue] //~ ERROR attribute cannot be used on
extern "C" fn ok() {}
fn main() {
#[loop_match] //~ ERROR attribute cannot be used on
#[const_continue] //~ ERROR attribute cannot be used on
|| {};
{
#[loop_match] //~ ERROR attribute cannot be used on
#[const_continue]
//~^ ERROR the `const_continue` attribute cannot be used on expressions
5
};
}