Files
rust/tests/ui/parser/attribute-on-empty.rs
León Orell Valerian Liehr 3d5b7aaa01 Simplify recovery from outer attributes on generic args
Use our new routine. Again, this means we can now also recover from
leading doc comments and inner attributes.

Moreover, we now actually store type & const arguments that have outer
attributes in the AST instead of using `{type error}` & `{const error}`
for them, respectively.
2026-09-07 21:43:51 +02:00

37 lines
871 B
Rust

// Exercise outer attributes being applied to "nothing" in invalid contexts.
struct Baz<const N: usize>(i32);
fn f() {
let _: Baz<#[cfg(false)]> = todo!();
//~^ ERROR attributes cannot be applied to generic arguments
}
fn g(_param: #[attr]) {}
//~^ ERROR attributes cannot be applied to types
//~| ERROR expected type, found `)`
fn barrier0() {
fn f() -> #[attr] { 0 }
//~^ ERROR attributes cannot be applied to types
//~| ERROR expected type, found `{`
}
struct S {
field: #[attr],
//~^ ERROR attributes cannot be applied to types
//~| ERROR expected type, found `,`
}
fn barrier1() {
type Tuple = (#[attr], String);
//~^ ERROR attributes cannot be applied to types
//~| ERROR expected type, found `,`
}
impl #[attr] {}
//~^ ERROR attributes cannot be applied to types
//~| ERROR expected type, found `{`
fn main() {}