Skip to content

Commit 679ab9e

Browse files
authored
Rollup merge of #149400 - Skgland:tracked_mod, r=Amanieu
unstable proc_macro tracked::* rename/restructure Picking up what should be the uncontroversial part of #87173 (closed due to inactivity over two years ago). Part of #99515. - move `proc_macro::tracked_env::var` to `proc_macro::tracked::env_var` - move `proc_macro::tracked_path::path` to `proc_macro::tracked::path` - change the argument of `proc_macro::tracked::path` from `AsRef<str>` to `AsRef<Path>`.
2 parents 90dc2b6 + 3f67246 commit 679ab9e

File tree

8 files changed

+37
-22
lines changed

8 files changed

+37
-22
lines changed

compiler/rustc_fluent_macro/src/fluent.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ use fluent_syntax::ast::{
88
Attribute, Entry, Expression, Identifier, InlineExpression, Message, Pattern, PatternElement,
99
};
1010
use fluent_syntax::parser::ParserError;
11+
#[cfg(not(bootstrap))]
12+
use proc_macro::tracked::path;
13+
#[cfg(bootstrap)]
1114
use proc_macro::tracked_path::path;
1215
use proc_macro::{Diagnostic, Level, Span};
1316
use proc_macro2::TokenStream;

compiler/rustc_fluent_macro/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// tidy-alphabetical-start
22
#![allow(rustc::default_hash_types)]
3+
#![cfg_attr(bootstrap, feature(track_path))]
4+
#![cfg_attr(not(bootstrap), feature(proc_macro_tracked_path))]
35
#![feature(proc_macro_diagnostic)]
4-
#![feature(track_path)]
56
// tidy-alphabetical-end
67

78
use proc_macro::TokenStream;

compiler/rustc_macros/src/current_version.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ struct RustcVersion {
2222

2323
impl RustcVersion {
2424
fn parse_cfg_release(env_var: &str) -> Result<Self, Box<dyn std::error::Error>> {
25+
#[cfg(not(bootstrap))]
26+
let value = proc_macro::tracked::env_var(env_var)?;
27+
#[cfg(bootstrap)]
2528
let value = proc_macro::tracked_env::var(env_var)?;
29+
2630
Self::parse_str(&value)
2731
.ok_or_else(|| format!("failed to parse rustc version: {:?}", value).into())
2832
}

compiler/rustc_macros/src/symbols.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,13 @@ fn symbols_with_errors(input: TokenStream) -> (TokenStream, Vec<syn::Error>) {
259259
break;
260260
}
261261

262-
let value = match proc_macro::tracked_env::var(env_var.value()) {
262+
#[cfg(bootstrap)]
263+
let tracked_env = proc_macro::tracked_env::var(env_var.value());
264+
265+
#[cfg(not(bootstrap))]
266+
let tracked_env = proc_macro::tracked::env_var(env_var.value());
267+
268+
let value = match tracked_env {
263269
Ok(value) => value,
264270
Err(err) => {
265271
errors.list.push(syn::Error::new_spanned(expr, err));

library/proc_macro/src/lib.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,37 +1594,38 @@ impl fmt::Debug for Literal {
15941594
}
15951595
}
15961596

1597-
/// Tracked access to environment variables.
1598-
#[unstable(feature = "proc_macro_tracked_env", issue = "99515")]
1599-
pub mod tracked_env {
1597+
#[unstable(
1598+
feature = "proc_macro_tracked_path",
1599+
issue = "99515",
1600+
implied_by = "proc_macro_tracked_env"
1601+
)]
1602+
/// Functionality for adding environment state to the build dependency info.
1603+
pub mod tracked {
1604+
16001605
use std::env::{self, VarError};
16011606
use std::ffi::OsStr;
1607+
use std::path::Path;
16021608

16031609
/// Retrieve an environment variable and add it to build dependency info.
16041610
/// The build system executing the compiler will know that the variable was accessed during
16051611
/// compilation, and will be able to rerun the build when the value of that variable changes.
16061612
/// Besides the dependency tracking this function should be equivalent to `env::var` from the
16071613
/// standard library, except that the argument must be UTF-8.
16081614
#[unstable(feature = "proc_macro_tracked_env", issue = "99515")]
1609-
pub fn var<K: AsRef<OsStr> + AsRef<str>>(key: K) -> Result<String, VarError> {
1615+
pub fn env_var<K: AsRef<OsStr> + AsRef<str>>(key: K) -> Result<String, VarError> {
16101616
let key: &str = key.as_ref();
16111617
let value = crate::bridge::client::FreeFunctions::injected_env_var(key)
16121618
.map_or_else(|| env::var(key), Ok);
16131619
crate::bridge::client::FreeFunctions::track_env_var(key, value.as_deref().ok());
16141620
value
16151621
}
1616-
}
1617-
1618-
/// Tracked access to additional files.
1619-
#[unstable(feature = "track_path", issue = "99515")]
1620-
pub mod tracked_path {
16211622

1622-
/// Track a file explicitly.
1623+
/// Track a file or directory explicitly.
16231624
///
16241625
/// Commonly used for tracking asset preprocessing.
1625-
#[unstable(feature = "track_path", issue = "99515")]
1626-
pub fn path<P: AsRef<str>>(path: P) {
1627-
let path: &str = path.as_ref();
1626+
#[unstable(feature = "proc_macro_tracked_path", issue = "99515")]
1627+
pub fn path<P: AsRef<Path>>(path: P) {
1628+
let path: &str = path.as_ref().to_str().unwrap();
16281629
crate::bridge::client::FreeFunctions::track_path(path);
16291630
}
16301631
}

tests/run-make/env-dep-info/macro_def.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use proc_macro::*;
66

77
#[proc_macro]
88
pub fn access_env_vars(_: TokenStream) -> TokenStream {
9-
let _ = tracked_env::var("EXISTING_PROC_MACRO_ENV");
10-
let _ = tracked_env::var("NONEXISTENT_PROC_MACEO_ENV");
9+
let _ = tracked::env_var("EXISTING_PROC_MACRO_ENV");
10+
let _ = tracked::env_var("NONEXISTENT_PROC_MACEO_ENV");
1111
TokenStream::new()
1212
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#![feature(track_path)]
1+
#![feature(proc_macro_tracked_path)]
22
#![crate_type = "proc-macro"]
33

44
extern crate proc_macro;
55
use proc_macro::*;
66

77
#[proc_macro]
88
pub fn access_tracked_paths(_: TokenStream) -> TokenStream {
9-
tracked_path::path("emojis.txt");
9+
tracked::path("emojis.txt");
1010
TokenStream::new()
1111
}

tests/ui/proc-macro/auxiliary/env.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
extern crate proc_macro;
44

55
use proc_macro::TokenStream;
6-
use proc_macro::tracked_env::var;
6+
use proc_macro::tracked::env_var;
77

88
#[proc_macro]
99
pub fn generate_const(input: TokenStream) -> TokenStream {
10-
let the_const = match var("THE_CONST") {
10+
let the_const = match env_var("THE_CONST") {
1111
Ok(x) if x == "12" => {
1212
"const THE_CONST: u32 = 12;"
1313
}
1414
_ => {
1515
"const THE_CONST: u32 = 0;"
1616
}
1717
};
18-
let another = if var("ANOTHER").is_ok() {
18+
let another = if env_var("ANOTHER").is_ok() {
1919
"const ANOTHER: u32 = 1;"
2020
} else {
2121
"const ANOTHER: u32 = 2;"

0 commit comments

Comments
 (0)