Skip to content

Commit

Permalink
Rollup merge of #101215 - est31:rustdoc_version_placeholder, r=Mark-S…
Browse files Browse the repository at this point in the history
…imulacrum

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

![Screenshot_20220830_233727](https://user-images.githubusercontent.com/8872119/187548079-6207776b-4481-4351-afff-607f5b3fe03a.png)
  • Loading branch information
matthiaskrgr authored Sep 2, 2022
2 parents c8749f0 + 0c4ec5d commit 5a23efd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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 };
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/lib_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>");
Expand Down
2 changes: 1 addition & 1 deletion src/tools/replace-version-placeholder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
},
Expand Down

0 comments on commit 5a23efd

Please sign in to comment.