diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-09-02 18:22:01 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-02 18:22:01 +0200 |
| commit | 5a23efd31e0eaee3c8111a0018e541e672ca4a18 (patch) | |
| tree | 85b51cf27733999cc1c97ffaf3520f022e4d19d2 | |
| parent | c8749f045350ef6c729ff22d4069c2ff53ad7111 (diff) | |
| parent | 0c4ec5df58201a9215248d6cf68865431b4d3e35 (diff) | |
| download | rust-5a23efd31e0eaee3c8111a0018e541e672ca4a18.tar.gz rust-5a23efd31e0eaee3c8111a0018e541e672ca4a18.zip | |
Rollup merge of #101215 - est31:rustdoc_version_placeholder, r=Mark-Simulacrum
Also replace the version placeholder in rustc_attr Replace the version placeholder with the current version in the rustc_attr crate too so that users won't see the placeholder but instead the explicit version. This especially fixes the bug for rustdoc not showing it but instead the placeholder. Originally reported [here](https://rust-lang.zulipchat.com/#narrow/stream/241545-t-release/topic/libs.20stabilization.20placeholder/near/296057188). cc #100591 
| -rw-r--r-- | compiler/rustc_attr/src/builtin.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/lib_features.rs | 2 | ||||
| -rw-r--r-- | src/tools/replace-version-placeholder/src/main.rs | 2 |
3 files changed, 14 insertions, 2 deletions
diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index 65edab78ce7..a8ed510866d 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -15,6 +15,12 @@ use std::num::NonZeroU32; use crate::session_diagnostics::{self, IncorrectReprFormatGenericCause}; +/// The version placeholder that recently stabilized features contain inside the +/// `since` field of the `#[stable]` attribute. +/// +/// For more, see [this pull request](https://github.com/rust-lang/rust/pull/100591). +pub const VERSION_PLACEHOLDER: &str = "CURRENT_RUSTC_VERSION"; + pub fn is_builtin_attr(attr: &Attribute) -> bool { attr.is_doc_comment() || attr.ident().filter(|ident| is_builtin_attr_name(ident.name)).is_some() } @@ -483,6 +489,12 @@ where } } + if let Some(s) = since && s.as_str() == VERSION_PLACEHOLDER { + let version = option_env!("CFG_VERSION").unwrap_or("<current>"); + let version = version.split(' ').next().unwrap(); + since = Some(Symbol::intern(&version)); + } + match (feature, since) { (Some(feature), Some(since)) => { let level = Stable { since, allowed_through_unstable_modules: false }; diff --git a/compiler/rustc_passes/src/lib_features.rs b/compiler/rustc_passes/src/lib_features.rs index 70b6bfd1e58..5aac6943eef 100644 --- a/compiler/rustc_passes/src/lib_features.rs +++ b/compiler/rustc_passes/src/lib_features.rs @@ -5,6 +5,7 @@ //! collect them instead. use rustc_ast::{Attribute, MetaItemKind}; +use rustc_attr::VERSION_PLACEHOLDER; use rustc_errors::struct_span_err; use rustc_hir::intravisit::Visitor; use rustc_middle::hir::nested_filter; @@ -54,7 +55,6 @@ impl<'tcx> LibFeatureCollector<'tcx> { } } } - const VERSION_PLACEHOLDER: &str = "CURRENT_RUSTC_VERSION"; if let Some(s) = since && s.as_str() == VERSION_PLACEHOLDER { let version = option_env!("CFG_VERSION").unwrap_or("<current>"); diff --git a/src/tools/replace-version-placeholder/src/main.rs b/src/tools/replace-version-placeholder/src/main.rs index 146e53f2e9a..33b35d05415 100644 --- a/src/tools/replace-version-placeholder/src/main.rs +++ b/src/tools/replace-version-placeholder/src/main.rs @@ -14,7 +14,7 @@ fn main() { walk::filter_dirs(path) // We exempt these as they require the placeholder // for their operation - || path.ends_with("compiler/rustc_passes/src/lib_features.rs") + || path.ends_with("compiler/rustc_attr/src/builtin.rs") || path.ends_with("src/tools/tidy/src/features/version.rs") || path.ends_with("src/tools/replace-version-placeholder") }, |
