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

Check no pointee attribute pos #128571

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
35 changes: 35 additions & 0 deletions tests/ui/attributes/pointee.rs
Original file line number Diff line number Diff line change
@@ -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() {}
54 changes: 54 additions & 0 deletions tests/ui/attributes/pointee.stderr
Original file line number Diff line number Diff line change
@@ -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
Loading