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

Advent of tests/ui (misc cleanups and improvements) [3/N] #134418

Merged
merged 7 commits into from
Dec 19, 2024
Merged
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
4 changes: 0 additions & 4 deletions tests/ui/attr-bad-crate-attr.rs

This file was deleted.

5 changes: 0 additions & 5 deletions tests/ui/attr-shebang.rs

This file was deleted.

9 changes: 9 additions & 0 deletions tests/ui/attributes/attr-bad-crate-attr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! Check that we permit a crate-level inner attribute but reject a dangling outer attribute which
//! does not have a following thing that it can target.
//!
//! See <https://doc.rust-lang.org/reference/attributes.html>.

//@ error-pattern: expected item

#![attr = "val"]
#[attr = "val"] // Unterminated
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: expected item after attributes
--> $DIR/attr-bad-crate-attr.rs:4:1
--> $DIR/attr-bad-crate-attr.rs:9:1
|
LL | #[attr = "val"] // Unterminated
| ^^^^^^^^^^^^^^^
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/attributes/attr-shebang.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Check that we accept crate-level inner attributes with the `#![..]` shebang syntax.

//@ check-pass

#![allow(stable_features)]
#![feature(rust1)]
pub fn main() { }
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(dead_code)]
//! Check that `#[inline]` attribute can only be applied to fn-like targets (e.g. function or
//! closure), and when misapplied to other targets an error is emitted.

#[inline]
fn f() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error[E0518]: attribute should be applied to function or closure
--> $DIR/attr-usage-inline.rs:6:1
--> $DIR/attr-usage-inline.rs:7:1
|
LL | #[inline]
| ^^^^^^^^^
LL | struct S;
| --------- not a function or closure

error[E0518]: attribute should be applied to function or closure
--> $DIR/attr-usage-inline.rs:20:1
--> $DIR/attr-usage-inline.rs:21:1
|
LL | #[inline]
| ^^^^^^^^^ not a function or closure
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
//! Check that certain positions (listed below) only permit *non-macro* attributes and reject
//! attribute macros:
//!
//! - Enum variants
//! - Struct fields
//! - Field in a struct pattern
//! - Match arm
//! - Field in struct initialization expression

enum FooEnum {
#[test]
//~^ ERROR expected non-macro attribute, found attribute macro
Expand Down Expand Up @@ -32,7 +41,7 @@ fn main() {
_ => {}
}

let _another_foo_strunct = FooStruct {
let _another_foo_struct = FooStruct {
#[test]
//~^ ERROR expected non-macro attribute, found attribute macro
bar: 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
error: expected non-macro attribute, found attribute macro `test`
--> $DIR/attrs-resolution-errors.rs:2:7
--> $DIR/attr-macros-positional-rejection.rs:11:7
|
LL | #[test]
| ^^^^ not a non-macro attribute

error: expected non-macro attribute, found attribute macro `test`
--> $DIR/attrs-resolution-errors.rs:8:7
--> $DIR/attr-macros-positional-rejection.rs:17:7
|
LL | #[test]
| ^^^^ not a non-macro attribute

error: expected non-macro attribute, found attribute macro `test`
--> $DIR/attrs-resolution-errors.rs:23:15
--> $DIR/attr-macros-positional-rejection.rs:32:15
|
LL | #[test] bar
| ^^^^ not a non-macro attribute

error: expected non-macro attribute, found attribute macro `test`
--> $DIR/attrs-resolution-errors.rs:30:11
--> $DIR/attr-macros-positional-rejection.rs:39:11
|
LL | #[test]
| ^^^^ not a non-macro attribute

error: expected non-macro attribute, found attribute macro `test`
--> $DIR/attrs-resolution-errors.rs:36:11
--> $DIR/attr-macros-positional-rejection.rs:45:11
|
LL | #[test]
| ^^^^ not a non-macro attribute
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
//! Check that certain positions (listed below) permit *non-macro* attributes.
//!
//! - Enum variants
//! - Struct fields
//! - Field in a struct pattern
//! - Match arm
//! - Field in struct initialization expression

//@ check-pass

enum FooEnum {
Expand Down Expand Up @@ -30,7 +38,7 @@ fn main() {
_ => {}
}

let _another_foo_strunct = FooStruct {
let _another_foo_struct = FooStruct {
#[rustfmt::skip]
bar: 1,
};
Expand Down
Loading