Skip to content
/ rust Public
forked from rust-lang/rust

Commit

Permalink
Rollup merge of rust-lang#134418 - jieyouxu:ui-cleanup-3, r=compiler-…
Browse files Browse the repository at this point in the history
…errors

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

Part of rust-lang#133895.

Misc improvements to some ui tests immediately under `tests/ui/`.

Best reviewed commit-by-commit. Each commit's commit message contains further elaboration and rationale for changes.

r? compiler
  • Loading branch information
jhpratt authored Dec 19, 2024
2 parents fa75b4d + 47ad3b2 commit 871c2d8
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 20 deletions.
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.
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
File renamed without changes.
File renamed without changes.

0 comments on commit 871c2d8

Please sign in to comment.