Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2a7ad95
Fix test hangs on AIX
mustartt Mar 3, 2025
506c304
Clarify iterator by_ref docs
hkBst Jan 24, 2025
6a38322
Rename print_something to should_render
compiler-errors Mar 5, 2025
279377f
Fix pretty printing of parsed attrs in hir_pretty
compiler-errors Mar 5, 2025
b827087
add tracking issue for unqualified_local_imports
RalfJung Mar 10, 2025
7ca7675
Make all keys explicit in citool
Kobzol Feb 27, 2025
0412507
Move job handling to a separate module
Kobzol Mar 10, 2025
3326a9f
Allow using glob aliases for custom try jobs
Kobzol Mar 10, 2025
06d86cd
Modify try-job documentation
Kobzol Mar 10, 2025
dfef1a7
Handle backticks in try job patterns
Kobzol Mar 10, 2025
16c08f6
Ignore job duplicates
Kobzol Mar 10, 2025
dcf6137
use next_back() instead of last() on DoubleEndedIterator
matthiaskrgr Mar 10, 2025
e337d87
Add powerpc64le maintainers
daltenty Mar 7, 2025
32afef4
Remove unnecessary `[lints.rust]` sections.
nnethercote Mar 11, 2025
c00a5c0
Fix post-merge workflow
jieyouxu Mar 11, 2025
6e83ebe
Document -Z crate-attr
jyn514 Mar 9, 2025
512ebed
add more -Z crate-attr tests
jyn514 Mar 11, 2025
bb2324a
Rollup merge of #135987 - hkBst:patch-20, r=joboet
Kobzol Mar 11, 2025
95d9ade
Rollup merge of #137967 - mustartt:fix-aix-test-hangs, r=workingjubilee
Kobzol Mar 11, 2025
c054bac
Rollup merge of #138063 - compiler-errors:improve-attr-unpretty, r=jd…
Kobzol Mar 11, 2025
09cc57e
Rollup merge of #138147 - daltenty:patch-1, r=jieyouxu
Kobzol Mar 11, 2025
79fa56a
Rollup merge of #138288 - jyn514:crate-attr, r=Noratrieb
Kobzol Mar 11, 2025
07f33e2
Rollup merge of #138300 - RalfJung:unqualified-local-imports, r=jieyouxu
Kobzol Mar 11, 2025
3e67637
Rollup merge of #138307 - Kobzol:citool-alias, r=marcoieni
Kobzol Mar 11, 2025
03a79a7
Rollup merge of #138315 - matthiaskrgr:nextback, r=fmease
Kobzol Mar 11, 2025
7e4c08b
Rollup merge of #138330 - nnethercote:rm-lints-rust-sections, r=jieyouxu
Kobzol Mar 11, 2025
64c6ec5
Rollup merge of #138335 - jieyouxu:fix-citool, r=marcoieni
Kobzol Mar 11, 2025
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
16 changes: 16 additions & 0 deletions src/doc/unstable-book/src/compiler-flags/crate-attr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# `crate-attr`

The tracking issue for this feature is: [#138287](https://github.com/rust-lang/rust/issues/138287).

------------------------

The `-Z crate-attr` flag allows you to inject attributes into the crate root.
For example, `-Z crate-attr=crate_name="test"` acts as if `#![crate_name="test"]` were present before the first source line of the crate root.

To inject multiple attributes, pass `-Z crate-attr` multiple times.

Formally, the expansion behaves as follows:
1. The crate is parsed as if `-Z crate-attr` were not present.
2. The attributes in `-Z crate-attr` are parsed.
3. The attributes are injected at the top of the crate root.
4. Macro expansion is performed.
7 changes: 7 additions & 0 deletions tests/ui/attributes/z-crate-attr/cfg-false.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Ensure that `-Z crate-attr=cfg(FALSE)` can comment out the whole crate
//@ compile-flags: --crate-type=lib -Zcrate-attr=cfg(FALSE)
//@ check-pass

// NOTE: duplicate items are load-bearing
fn foo() {}
fn foo() {}
5 changes: 5 additions & 0 deletions tests/ui/attributes/z-crate-attr/comments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@ check-pass
//@ compile-flags: -Zcrate-attr=/*hi-there*/feature(rustc_attrs)

#[rustc_dummy]
fn main() {}
6 changes: 6 additions & 0 deletions tests/ui/attributes/z-crate-attr/crate-name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Ensure that `crate_name` and `crate_type` can be set through `-Z crate-attr`.
//@ check-pass
//@ compile-flags: -Zcrate-attr=crate_name="override"
fn main() {
assert_eq!(module_path!(), "r#override");
}
3 changes: 3 additions & 0 deletions tests/ui/attributes/z-crate-attr/crate-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//@ check-pass
//@ compile-flags: -Zcrate-attr=crate_type="lib"
// notice the lack of `main` is load-bearing
4 changes: 4 additions & 0 deletions tests/ui/attributes/z-crate-attr/garbage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Show diagnostics for invalid tokens
//@ compile-flags: -Zcrate-attr=`%~@$#
//@ error-pattern:unknown start of token
fn main() {}
20 changes: 20 additions & 0 deletions tests/ui/attributes/z-crate-attr/garbage.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: unknown start of token: `
--> <crate attribute>:1:1
|
LL | `%~@$#
| ^
|
help: Unicode character '`' (Grave Accent) looks like ''' (Single Quote), but it is not
|
LL - `%~@$#
LL + '%~@$#
|

error: expected identifier, found `%`
--> <crate attribute>:1:2
|
LL | `%~@$#
| ^ expected identifier

error: aborting due to 2 previous errors

3 changes: 3 additions & 0 deletions tests/ui/attributes/z-crate-attr/injection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//@ compile-flags: '-Zcrate-attr=feature(yeet_expr)]fn main(){}#[inline'
//@ error-pattern:unexpected closing delimiter
fn foo() {}
8 changes: 8 additions & 0 deletions tests/ui/attributes/z-crate-attr/injection.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: unexpected closing delimiter: `]`
--> <crate attribute>:1:19
|
LL | feature(yeet_expr)]fn main(){}#[inline
| ^ unexpected closing delimiter

error: aborting due to 1 previous error

4 changes: 4 additions & 0 deletions tests/ui/attributes/z-crate-attr/inner-attr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//@ compile-flags: -Zcrate-attr=#![feature(foo)]
//@ error-pattern:expected identifier

fn main() {}
8 changes: 8 additions & 0 deletions tests/ui/attributes/z-crate-attr/inner-attr.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: expected identifier, found `#`
--> <crate attribute>:1:1
|
LL | #![feature(foo)]
| ^ expected identifier

error: aborting due to 1 previous error

3 changes: 3 additions & 0 deletions tests/ui/attributes/z-crate-attr/multiple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//@ compile-flags: -Zcrate-attr=feature(foo),feature(bar)
//@ error-pattern:invalid crate attr
fn main() {}
8 changes: 8 additions & 0 deletions tests/ui/attributes/z-crate-attr/multiple.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: invalid crate attribute
--> <crate attribute>:1:1
|
LL | feature(foo),feature(bar)
| ^^^^^^^^^^^^^

error: aborting due to 1 previous error

9 changes: 9 additions & 0 deletions tests/ui/attributes/z-crate-attr/respect-existing-attrs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Make sure that existing root attributes are still respected even when `-Zcrate-attr` is present.
//@ run-pass
//@ compile-flags: -Zcrate-attr=feature(rustc_attrs)
#![crate_name = "override"]

#[rustc_dummy]
fn main() {
assert_eq!(module_path!(), "r#override");
}
6 changes: 6 additions & 0 deletions tests/ui/attributes/z-crate-attr/shebang.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env -S cargo +nightly -Zscript
// Make sure that shebangs are still allowed even when `-Zcrate-attr` is present.
//@ check-pass
//@ compile-flags: -Zcrate-attr=feature(rustc_attrs)
#[rustc_dummy]
fn main() {}
4 changes: 4 additions & 0 deletions tests/ui/attributes/z-crate-attr/unbalanced-paren.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Show diagnostics for unbalanced parens.
//@ compile-flags: -Zcrate-attr=(
//@ error-pattern:unclosed delimiter
fn main() {}
10 changes: 10 additions & 0 deletions tests/ui/attributes/z-crate-attr/unbalanced-paren.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: this file contains an unclosed delimiter
--> <crate attribute>:1:2
|
LL | (
| -^
| |
| unclosed delimiter

error: aborting due to 1 previous error