Skip to content

Commit 512ebed

Browse files
committed
add more -Z crate-attr tests
1 parent 6e83ebe commit 512ebed

17 files changed

+108
-0
lines changed
File renamed without changes.

Diff for: tests/ui/attributes/z-crate-attr/cfg-false.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Ensure that `-Z crate-attr=cfg(FALSE)` can comment out the whole crate
2+
//@ compile-flags: --crate-type=lib -Zcrate-attr=cfg(FALSE)
3+
//@ check-pass
4+
5+
// NOTE: duplicate items are load-bearing
6+
fn foo() {}
7+
fn foo() {}

Diff for: tests/ui/attributes/z-crate-attr/comments.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//@ check-pass
2+
//@ compile-flags: -Zcrate-attr=/*hi-there*/feature(rustc_attrs)
3+
4+
#[rustc_dummy]
5+
fn main() {}

Diff for: tests/ui/attributes/z-crate-attr/crate-name.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Ensure that `crate_name` and `crate_type` can be set through `-Z crate-attr`.
2+
//@ check-pass
3+
//@ compile-flags: -Zcrate-attr=crate_name="override"
4+
fn main() {
5+
assert_eq!(module_path!(), "r#override");
6+
}

Diff for: tests/ui/attributes/z-crate-attr/crate-type.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//@ check-pass
2+
//@ compile-flags: -Zcrate-attr=crate_type="lib"
3+
// notice the lack of `main` is load-bearing

Diff for: tests/ui/attributes/z-crate-attr/garbage.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Show diagnostics for invalid tokens
2+
//@ compile-flags: -Zcrate-attr=`%~@$#
3+
//@ error-pattern:unknown start of token
4+
fn main() {}

Diff for: tests/ui/attributes/z-crate-attr/garbage.stderr

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: unknown start of token: `
2+
--> <crate attribute>:1:1
3+
|
4+
LL | `%~@$#
5+
| ^
6+
|
7+
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
8+
|
9+
LL - `%~@$#
10+
LL + '%~@$#
11+
|
12+
13+
error: expected identifier, found `%`
14+
--> <crate attribute>:1:2
15+
|
16+
LL | `%~@$#
17+
| ^ expected identifier
18+
19+
error: aborting due to 2 previous errors
20+

Diff for: tests/ui/attributes/z-crate-attr/injection.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//@ compile-flags: '-Zcrate-attr=feature(yeet_expr)]fn main(){}#[inline'
2+
//@ error-pattern:unexpected closing delimiter
3+
fn foo() {}

Diff for: tests/ui/attributes/z-crate-attr/injection.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: unexpected closing delimiter: `]`
2+
--> <crate attribute>:1:19
3+
|
4+
LL | feature(yeet_expr)]fn main(){}#[inline
5+
| ^ unexpected closing delimiter
6+
7+
error: aborting due to 1 previous error
8+

Diff for: tests/ui/attributes/z-crate-attr/inner-attr.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//@ compile-flags: -Zcrate-attr=#![feature(foo)]
2+
//@ error-pattern:expected identifier
3+
4+
fn main() {}

Diff for: tests/ui/attributes/z-crate-attr/inner-attr.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected identifier, found `#`
2+
--> <crate attribute>:1:1
3+
|
4+
LL | #![feature(foo)]
5+
| ^ expected identifier
6+
7+
error: aborting due to 1 previous error
8+

Diff for: tests/ui/attributes/z-crate-attr/multiple.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//@ compile-flags: -Zcrate-attr=feature(foo),feature(bar)
2+
//@ error-pattern:invalid crate attr
3+
fn main() {}

Diff for: tests/ui/attributes/z-crate-attr/multiple.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: invalid crate attribute
2+
--> <crate attribute>:1:1
3+
|
4+
LL | feature(foo),feature(bar)
5+
| ^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Make sure that existing root attributes are still respected even when `-Zcrate-attr` is present.
2+
//@ run-pass
3+
//@ compile-flags: -Zcrate-attr=feature(rustc_attrs)
4+
#![crate_name = "override"]
5+
6+
#[rustc_dummy]
7+
fn main() {
8+
assert_eq!(module_path!(), "r#override");
9+
}

Diff for: tests/ui/attributes/z-crate-attr/shebang.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env -S cargo +nightly -Zscript
2+
// Make sure that shebangs are still allowed even when `-Zcrate-attr` is present.
3+
//@ check-pass
4+
//@ compile-flags: -Zcrate-attr=feature(rustc_attrs)
5+
#[rustc_dummy]
6+
fn main() {}

Diff for: tests/ui/attributes/z-crate-attr/unbalanced-paren.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Show diagnostics for unbalanced parens.
2+
//@ compile-flags: -Zcrate-attr=(
3+
//@ error-pattern:unclosed delimiter
4+
fn main() {}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: this file contains an unclosed delimiter
2+
--> <crate attribute>:1:2
3+
|
4+
LL | (
5+
| -^
6+
| |
7+
| unclosed delimiter
8+
9+
error: aborting due to 1 previous error
10+

0 commit comments

Comments
 (0)