Skip to content

Commit 8410df3

Browse files
committed
Also replace the version placeholder in rustc_attr
This fixes rustdoc not showing the current version as stabilization version for recently stabilized lang features.
1 parent 0631ea5 commit 8410df3

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

compiler/rustc_attr/src/builtin.rs

+12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ use std::num::NonZeroU32;
1515

1616
use crate::session_diagnostics::{self, IncorrectReprFormatGenericCause};
1717

18+
/// The version placeholder that recently stabilized features contain inside the
19+
/// `since` field of the `#[stable]` attribute.
20+
///
21+
/// For more, see https://github.com/rust-lang/rust/pull/100591
22+
pub const VERSION_PLACEHOLDER: &str = "CURRENT_RUSTC_VERSION";
23+
1824
pub fn is_builtin_attr(attr: &Attribute) -> bool {
1925
attr.is_doc_comment() || attr.ident().filter(|ident| is_builtin_attr_name(ident.name)).is_some()
2026
}
@@ -483,6 +489,12 @@ where
483489
}
484490
}
485491

492+
if let Some(s) = since && s.as_str() == VERSION_PLACEHOLDER {
493+
let version = option_env!("CFG_VERSION").unwrap_or("<current>");
494+
let version = version.split(' ').next().unwrap();
495+
since = Some(Symbol::intern(&version));
496+
}
497+
486498
match (feature, since) {
487499
(Some(feature), Some(since)) => {
488500
let level = Stable { since, allowed_through_unstable_modules: false };

compiler/rustc_passes/src/lib_features.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! collect them instead.
66
77
use rustc_ast::{Attribute, MetaItemKind};
8+
use rustc_attr::VERSION_PLACEHOLDER;
89
use rustc_errors::struct_span_err;
910
use rustc_hir::intravisit::Visitor;
1011
use rustc_middle::hir::nested_filter;
@@ -54,7 +55,6 @@ impl<'tcx> LibFeatureCollector<'tcx> {
5455
}
5556
}
5657
}
57-
const VERSION_PLACEHOLDER: &str = "CURRENT_RUSTC_VERSION";
5858

5959
if let Some(s) = since && s.as_str() == VERSION_PLACEHOLDER {
6060
let version = option_env!("CFG_VERSION").unwrap_or("<current>");

src/tools/replace-version-placeholder/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
walk::filter_dirs(path)
1515
// We exempt these as they require the placeholder
1616
// for their operation
17-
|| path.ends_with("compiler/rustc_passes/src/lib_features.rs")
17+
|| path.ends_with("compiler/rustc_attr/src/builtin.rs")
1818
|| path.ends_with("src/tools/tidy/src/features/version.rs")
1919
|| path.ends_with("src/tools/replace-version-placeholder")
2020
},

0 commit comments

Comments
 (0)