diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 86b18570f376b..af8e24c990606 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -158,6 +158,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { self.check_rustc_std_internal_symbol(attr, span, target) } [sym::naked] => self.check_naked(hir_id, attr, span, target, attrs), + [sym::pointee] => self.check_applied_to_fn_or_method(hir_id, attr, span, target), [sym::rustc_never_returns_null_ptr] => { self.check_applied_to_fn_or_method(hir_id, attr, span, target) } diff --git a/tests/ui/attributes/pointee.rs b/tests/ui/attributes/pointee.rs new file mode 100644 index 0000000000000..fffa55fe7e1c8 --- /dev/null +++ b/tests/ui/attributes/pointee.rs @@ -0,0 +1,35 @@ +#![feature(pointee)] +#![feature(stmt_expr_attributes)] +#![feature(derive_smart_pointer)] +#![deny(unused_attributes)] +#![allow(dead_code)] + +fn invalid() { + #[pointee] //~ ERROR attribute should be applied to a function definition + { + 1 + }; +} + +#[pointee] //~ ERROR attribute should be applied to a function definition +type InvalidTy = (); + +#[pointee] //~ ERROR attribute should be applied to a function definition +mod invalid_module {} + +fn main() { + let _ = #[pointee] //~ ERROR attribute should be applied to a function definition + (|| 1); +} + +#[pointee] //~ ERROR attribute should be applied to a function definition +struct F; + +#[pointee] //~ ERROR attribute should be applied to a function definition +impl F { + #[pointee] + fn valid(&self) {} +} + +#[pointee] +fn valid() {} diff --git a/tests/ui/attributes/pointee.stderr b/tests/ui/attributes/pointee.stderr new file mode 100644 index 0000000000000..54ac19ca25abb --- /dev/null +++ b/tests/ui/attributes/pointee.stderr @@ -0,0 +1,54 @@ +error: attribute should be applied to a function definition + --> $DIR/pointee.rs:8:5 + | +LL | #[pointee] + | ^^^^^^^^^^ +LL | / { +LL | | 1 +LL | | }; + | |_____- not a function definition + +error: attribute should be applied to a function definition + --> $DIR/pointee.rs:14:1 + | +LL | #[pointee] + | ^^^^^^^^^^ +LL | type InvalidTy = (); + | -------------------- not a function definition + +error: attribute should be applied to a function definition + --> $DIR/pointee.rs:17:1 + | +LL | #[pointee] + | ^^^^^^^^^^ +LL | mod invalid_module {} + | --------------------- not a function definition + +error: attribute should be applied to a function definition + --> $DIR/pointee.rs:21:13 + | +LL | let _ = #[pointee] + | ^^^^^^^^^^ +LL | (|| 1); + | ------ not a function definition + +error: attribute should be applied to a function definition + --> $DIR/pointee.rs:25:1 + | +LL | #[pointee] + | ^^^^^^^^^^ +LL | struct F; + | --------- not a function definition + +error: attribute should be applied to a function definition + --> $DIR/pointee.rs:28:1 + | +LL | #[pointee] + | ^^^^^^^^^^ +LL | / impl F { +LL | | #[pointee] +LL | | fn valid(&self) {} +LL | | } + | |_- not a function definition + +error: aborting due to 6 previous errors