Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a19ad5e

Browse files
authoredDec 18, 2024
Rollup merge of rust-lang#134418 - jieyouxu:ui-cleanup-3, r=compiler-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
2 parents 844e435 + 47ad3b2 commit a19ad5e

14 files changed

+45
-20
lines changed
 

‎tests/ui/attr-bad-crate-attr.rs

-4
This file was deleted.

‎tests/ui/attr-shebang.rs

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//! Check that we permit a crate-level inner attribute but reject a dangling outer attribute which
2+
//! does not have a following thing that it can target.
3+
//!
4+
//! See <https://doc.rust-lang.org/reference/attributes.html>.
5+
6+
//@ error-pattern: expected item
7+
8+
#![attr = "val"]
9+
#[attr = "val"] // Unterminated

‎tests/ui/attr-bad-crate-attr.stderr ‎tests/ui/attributes/attr-bad-crate-attr.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: expected item after attributes
2-
--> $DIR/attr-bad-crate-attr.rs:4:1
2+
--> $DIR/attr-bad-crate-attr.rs:9:1
33
|
44
LL | #[attr = "val"] // Unterminated
55
| ^^^^^^^^^^^^^^^

‎tests/ui/attributes/attr-shebang.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//! Check that we accept crate-level inner attributes with the `#![..]` shebang syntax.
2+
3+
//@ check-pass
4+
5+
#![allow(stable_features)]
6+
#![feature(rust1)]
7+
pub fn main() { }

‎tests/ui/attr-usage-inline.rs ‎tests/ui/attributes/inline/attr-usage-inline.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#![allow(dead_code)]
1+
//! Check that `#[inline]` attribute can only be applied to fn-like targets (e.g. function or
2+
//! closure), and when misapplied to other targets an error is emitted.
23
34
#[inline]
45
fn f() {}

‎tests/ui/attr-usage-inline.stderr ‎tests/ui/attributes/inline/attr-usage-inline.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0518]: attribute should be applied to function or closure
2-
--> $DIR/attr-usage-inline.rs:6:1
2+
--> $DIR/attr-usage-inline.rs:7:1
33
|
44
LL | #[inline]
55
| ^^^^^^^^^
66
LL | struct S;
77
| --------- not a function or closure
88

99
error[E0518]: attribute should be applied to function or closure
10-
--> $DIR/attr-usage-inline.rs:20:1
10+
--> $DIR/attr-usage-inline.rs:21:1
1111
|
1212
LL | #[inline]
1313
| ^^^^^^^^^ not a function or closure
File renamed without changes.
File renamed without changes.

‎tests/ui/attrs-resolution-errors.rs ‎tests/ui/resolve/attr-macros-positional-rejection.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
//! Check that certain positions (listed below) only permit *non-macro* attributes and reject
2+
//! attribute macros:
3+
//!
4+
//! - Enum variants
5+
//! - Struct fields
6+
//! - Field in a struct pattern
7+
//! - Match arm
8+
//! - Field in struct initialization expression
9+
110
enum FooEnum {
211
#[test]
312
//~^ ERROR expected non-macro attribute, found attribute macro
@@ -32,7 +41,7 @@ fn main() {
3241
_ => {}
3342
}
3443

35-
let _another_foo_strunct = FooStruct {
44+
let _another_foo_struct = FooStruct {
3645
#[test]
3746
//~^ ERROR expected non-macro attribute, found attribute macro
3847
bar: 1,

‎tests/ui/attrs-resolution-errors.stderr ‎tests/ui/resolve/attr-macros-positional-rejection.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
error: expected non-macro attribute, found attribute macro `test`
2-
--> $DIR/attrs-resolution-errors.rs:2:7
2+
--> $DIR/attr-macros-positional-rejection.rs:11:7
33
|
44
LL | #[test]
55
| ^^^^ not a non-macro attribute
66

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

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

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

2525
error: expected non-macro attribute, found attribute macro `test`
26-
--> $DIR/attrs-resolution-errors.rs:36:11
26+
--> $DIR/attr-macros-positional-rejection.rs:45:11
2727
|
2828
LL | #[test]
2929
| ^^^^ not a non-macro attribute

‎tests/ui/attrs-resolution.rs ‎tests/ui/resolve/non-macro-attrs-accepted.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//! Check that certain positions (listed below) permit *non-macro* attributes.
2+
//!
3+
//! - Enum variants
4+
//! - Struct fields
5+
//! - Field in a struct pattern
6+
//! - Match arm
7+
//! - Field in struct initialization expression
8+
19
//@ check-pass
210

311
enum FooEnum {
@@ -30,7 +38,7 @@ fn main() {
3038
_ => {}
3139
}
3240

33-
let _another_foo_strunct = FooStruct {
41+
let _another_foo_struct = FooStruct {
3442
#[rustfmt::skip]
3543
bar: 1,
3644
};

0 commit comments

Comments
 (0)
Failed to load comments.