rustdoc: remove rust logo from non-Rust crates

This commit is contained in:
Michael Howell 2023-09-19 16:28:18 -07:00
parent 6d6fa792ff
commit c6e6ecb1af
46 changed files with 208 additions and 36 deletions

View File

@ -11,6 +11,8 @@
html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/", html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
test(no_crate_inject, attr(deny(warnings))) test(no_crate_inject, attr(deny(warnings)))
)] )]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![feature(core_intrinsics)] #![feature(core_intrinsics)]
#![feature(dropck_eyepatch)] #![feature(dropck_eyepatch)]
#![feature(new_uninit)] #![feature(new_uninit)]

View File

@ -8,6 +8,9 @@
html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/", html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
test(attr(deny(warnings))) test(attr(deny(warnings)))
)] )]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![feature(associated_type_bounds)] #![feature(associated_type_bounds)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(const_trait_impl)] #![feature(const_trait_impl)]

View File

@ -1,4 +1,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![feature(associated_type_bounds)] #![feature(associated_type_bounds)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(if_let_guard)] #![feature(if_let_guard)]

View File

@ -5,6 +5,9 @@
//! This API is completely unstable and subject to change. //! This API is completely unstable and subject to change.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![feature(lazy_cell)] #![feature(lazy_cell)]
#![feature(decl_macro)] #![feature(decl_macro)]
#![feature(panic_update_hook)] #![feature(panic_update_hook)]

View File

@ -3,6 +3,8 @@
//! This module contains the code for creating and emitting diagnostics. //! This module contains the code for creating and emitting diagnostics.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![feature(array_windows)] #![feature(array_windows)]
#![feature(extract_if)] #![feature(extract_if)]
#![feature(if_let_guard)] #![feature(if_let_guard)]

View File

@ -1,4 +1,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![feature(proc_macro_diagnostic)] #![feature(proc_macro_diagnostic)]
#![feature(proc_macro_span)] #![feature(proc_macro_span)]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]

View File

@ -273,6 +273,9 @@
html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/", html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
test(attr(allow(unused_variables), deny(warnings))) test(attr(allow(unused_variables), deny(warnings)))
)] )]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]

View File

@ -57,6 +57,9 @@ This API is completely unstable and subject to change.
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(control_flow_enum)] #![feature(control_flow_enum)]
#![feature(if_let_guard)] #![feature(if_let_guard)]

View File

@ -2,6 +2,9 @@
#![deny(missing_docs)] #![deny(missing_docs)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![feature(never_type)] #![feature(never_type)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]

View File

@ -13,6 +13,9 @@
//! This API is completely unstable and subject to change. //! This API is completely unstable and subject to change.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![feature(associated_type_bounds)] #![feature(associated_type_bounds)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(control_flow_enum)] #![feature(control_flow_enum)]

View File

@ -27,6 +27,8 @@
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![feature(array_windows)] #![feature(array_windows)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(control_flow_enum)] #![feature(control_flow_enum)]

View File

@ -1,6 +1,9 @@
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
// NOTE: This crate only exists to allow linking on mingw targets. // NOTE: This crate only exists to allow linking on mingw targets.

View File

@ -1,4 +1,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![feature(decl_macro)] #![feature(decl_macro)]
#![feature(extract_if)] #![feature(extract_if)]
#![feature(generators)] #![feature(generators)]

View File

@ -23,6 +23,8 @@
//! This API is completely unstable and subject to change. //! This API is completely unstable and subject to change.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![feature(allocator_api)] #![feature(allocator_api)]
#![feature(array_windows)] #![feature(array_windows)]
#![feature(assert_matches)] #![feature(assert_matches)]

View File

@ -9,6 +9,9 @@
html_playground_url = "https://play.rust-lang.org/", html_playground_url = "https://play.rust-lang.org/",
test(attr(deny(warnings))) test(attr(deny(warnings)))
)] )]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
// We want to be able to build this crate with a stable compiler, so no // We want to be able to build this crate with a stable compiler, so no

View File

@ -1108,6 +1108,7 @@ impl CheckAttrVisitor<'_> {
| sym::html_root_url | sym::html_root_url
| sym::html_no_source | sym::html_no_source
| sym::test | sym::test
| sym::rust_logo
if !self.check_attr_crate_level(attr, meta, hir_id) => if !self.check_attr_crate_level(attr, meta, hir_id) =>
{ {
is_valid = false; is_valid = false;
@ -1166,6 +1167,18 @@ impl CheckAttrVisitor<'_> {
| sym::plugins | sym::plugins
| sym::fake_variadic => {} | sym::fake_variadic => {}
sym::rust_logo => {
if !self.tcx.features().rustdoc_internals {
feature_err(
&self.tcx.sess.parse_sess,
sym::rustdoc_internals,
meta.span(),
"the `#[doc(rust_logo)]` attribute is used for Rust branding",
)
.emit();
}
}
sym::test => { sym::test => {
if !self.check_test_attr(meta, hir_id) { if !self.check_test_attr(meta, hir_id) {
is_valid = false; is_valid = false;

View File

@ -6,6 +6,9 @@
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![feature(iter_intersperse)] #![feature(iter_intersperse)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(map_try_insert)] #![feature(map_try_insert)]

View File

@ -7,6 +7,9 @@
//! of the Unstable Book for some examples. //! of the Unstable Book for some examples.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]

View File

@ -1,4 +1,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![feature(associated_type_defaults)] #![feature(associated_type_defaults)]
#![feature(rustc_private)] #![feature(rustc_private)]
#![feature(try_blocks)] #![feature(try_blocks)]

View File

@ -1,6 +1,8 @@
//! Support for serializing the dep-graph and reloading it. //! Support for serializing the dep-graph and reloading it.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
// this shouldn't be necessary, but the check for `&mut _` is too naive and denies returning a function pointer that takes a mut ref // this shouldn't be necessary, but the check for `&mut _` is too naive and denies returning a function pointer that takes a mut ref
#![feature(const_mut_refs)] #![feature(const_mut_refs)]
#![feature(const_refs_to_cell)] #![feature(const_refs_to_cell)]

View File

@ -7,6 +7,8 @@
//! Type-relative name resolution (methods, fields, associated items) happens in `rustc_hir_analysis`. //! Type-relative name resolution (methods, fields, associated items) happens in `rustc_hir_analysis`.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![feature(assert_matches)] #![feature(assert_matches)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(extract_if)] #![feature(extract_if)]

View File

@ -5,6 +5,9 @@
html_playground_url = "https://play.rust-lang.org/", html_playground_url = "https://play.rust-lang.org/",
test(attr(allow(unused_variables), deny(warnings))) test(attr(allow(unused_variables), deny(warnings)))
)] )]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![feature(allocator_api)] #![feature(allocator_api)]
#![feature(associated_type_bounds)] #![feature(associated_type_bounds)]
#![feature(const_option)] #![feature(const_option)]

View File

@ -10,6 +10,9 @@
html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/", html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
test(attr(allow(unused_variables), deny(warnings))) test(attr(allow(unused_variables), deny(warnings)))
)] )]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
pub mod rustc_internal; pub mod rustc_internal;

View File

@ -14,6 +14,8 @@
//! This API is completely unstable and subject to change. //! This API is completely unstable and subject to change.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![feature(array_windows)] #![feature(array_windows)]
#![feature(if_let_guard)] #![feature(if_let_guard)]
#![feature(negative_impls)] #![feature(negative_impls)]

View File

@ -1327,6 +1327,7 @@ symbols! {
rust_cold_cc, rust_cold_cc,
rust_eh_catch_typeinfo, rust_eh_catch_typeinfo,
rust_eh_personality, rust_eh_personality,
rust_logo,
rustc, rustc,
rustc_abi, rustc_abi,
rustc_allocator, rustc_allocator,

View File

@ -88,6 +88,9 @@
//! DefPaths which are much more robust in the face of changes to the code base. //! DefPaths which are much more robust in the face of changes to the code base.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![feature(never_type)] #![feature(never_type)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]

View File

@ -8,6 +8,8 @@
//! LLVM. //! LLVM.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![feature(assert_matches)] #![feature(assert_matches)]
#![feature(associated_type_bounds)] #![feature(associated_type_bounds)]
#![feature(exhaustive_patterns)] #![feature(exhaustive_patterns)]

View File

@ -11,6 +11,9 @@
//! This API is completely unstable and subject to change. //! This API is completely unstable and subject to change.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![feature(associated_type_bounds)] #![feature(associated_type_bounds)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(control_flow_enum)] #![feature(control_flow_enum)]

View File

@ -5,6 +5,9 @@
//! This API is completely unstable and subject to change. //! This API is completely unstable and subject to change.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![feature(assert_matches)] #![feature(assert_matches)]
#![feature(iterator_try_collect)] #![feature(iterator_try_collect)]
#![feature(let_chains)] #![feature(let_chains)]

View File

@ -78,6 +78,8 @@
not(no_sync), not(no_sync),
target_has_atomic = "ptr" target_has_atomic = "ptr"
))] ))]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![no_std] #![no_std]
#![needs_allocator] #![needs_allocator]
// Lints: // Lints:

View File

@ -68,6 +68,7 @@
test(no_crate_inject, attr(deny(warnings))), test(no_crate_inject, attr(deny(warnings))),
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))) test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
)] )]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![doc(cfg_hide( #![doc(cfg_hide(
not(test), not(test),
any(not(feature = "miri-test-libstd"), test, doctest), any(not(feature = "miri-test-libstd"), test, doctest),

View File

@ -17,6 +17,8 @@
test(no_crate_inject, attr(deny(warnings))), test(no_crate_inject, attr(deny(warnings))),
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))) test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
)] )]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
// This library is copied into rust-analyzer to allow loading rustc compiled proc macros. // This library is copied into rust-analyzer to allow loading rustc compiled proc macros.
// Please avoid unstable features where possible to minimize the amount of changes necessary // Please avoid unstable features where possible to minimize the amount of changes necessary
// to make it compile with rust-analyzer on stable. // to make it compile with rust-analyzer on stable.

View File

@ -227,6 +227,7 @@
test(no_crate_inject, attr(deny(warnings))), test(no_crate_inject, attr(deny(warnings))),
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))) test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
)] )]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![doc(cfg_hide( #![doc(cfg_hide(
not(test), not(test),
not(any(test, bootstrap)), not(any(test, bootstrap)),

View File

@ -16,6 +16,8 @@
#![unstable(feature = "test", issue = "50297")] #![unstable(feature = "test", issue = "50297")]
#![doc(test(attr(deny(warnings))))] #![doc(test(attr(deny(warnings))))]
#![cfg_attr(not(bootstrap), doc(rust_logo))]
#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
#![feature(internal_output_capture)] #![feature(internal_output_capture)]
#![feature(staged_api)] #![feature(staged_api)]
#![feature(process_exitcode_internals)] #![feature(process_exitcode_internals)]

View File

@ -207,6 +207,21 @@ To do so, the `#[doc(keyword = "...")]` attribute is used. Example:
mod empty_mod {} mod empty_mod {}
``` ```
### Use the Rust logo as the crate logo
This is for official Rust project use only.
Internal Rustdoc pages like settings.html and scrape-examples-help.html show the Rust logo.
This logo is tracked as a static resource. The attribute `#![doc(rust_logo)]` makes this same
built-in resource act as the main logo.
```rust
#![feature(rustdoc_internals)]
#![allow(internal_features)]
#![doc(rust_logo)]
//! This crate has the Rust(tm) branding on it.
```
## Effects of other nightly features ## Effects of other nightly features
These nightly-only features are not primarily related to Rustdoc, These nightly-only features are not primarily related to Rustdoc,

View File

@ -18,7 +18,6 @@ pub(crate) struct Layout {
pub(crate) default_settings: FxHashMap<String, String>, pub(crate) default_settings: FxHashMap<String, String>,
pub(crate) krate: String, pub(crate) krate: String,
pub(crate) krate_version: String, pub(crate) krate_version: String,
pub(crate) krate_version_extra: String,
/// The given user css file which allow to customize the generated /// The given user css file which allow to customize the generated
/// documentation theme. /// documentation theme.
pub(crate) css_file_extension: Option<PathBuf>, pub(crate) css_file_extension: Option<PathBuf>,
@ -33,6 +32,7 @@ pub(crate) struct Page<'a> {
pub(crate) static_root_path: Option<&'a str>, pub(crate) static_root_path: Option<&'a str>,
pub(crate) description: &'a str, pub(crate) description: &'a str,
pub(crate) resource_suffix: &'a str, pub(crate) resource_suffix: &'a str,
pub(crate) rust_logo: bool,
} }
impl<'a> Page<'a> { impl<'a> Page<'a> {
@ -56,9 +56,19 @@ struct PageLayout<'a> {
themes: Vec<String>, themes: Vec<String>,
sidebar: String, sidebar: String,
content: String, content: String,
krate_with_trailing_slash: String,
rust_channel: &'static str, rust_channel: &'static str,
pub(crate) rustdoc_version: &'a str, pub(crate) rustdoc_version: &'a str,
// same as layout.krate, except on top-level pages like
// Settings, Help, All Crates, and About Scraped Examples,
// where these things instead give Rustdoc name and version.
//
// These are separate from the variables used for the search
// engine, because "Rustdoc" isn't necessarily a crate in
// the current workspace.
display_krate: &'a str,
display_krate_with_trailing_slash: String,
display_krate_version_number: &'a str,
display_krate_version_extra: &'a str,
} }
pub(crate) fn render<T: Print, S: Print>( pub(crate) fn render<T: Print, S: Print>(
@ -68,12 +78,26 @@ pub(crate) fn render<T: Print, S: Print>(
t: T, t: T,
style_files: &[StylePath], style_files: &[StylePath],
) -> String { ) -> String {
let rustdoc_version = rustc_interface::util::version_str!().unwrap_or("unknown version");
let (display_krate, display_krate_version, display_krate_with_trailing_slash) =
if page.root_path == "./" {
// top level pages use Rust branding
("Rustdoc", rustdoc_version, String::new())
} else {
let display_krate_with_trailing_slash =
ensure_trailing_slash(&layout.krate).to_string();
(&layout.krate[..], &layout.krate_version[..], display_krate_with_trailing_slash)
};
let static_root_path = page.get_static_root_path(); let static_root_path = page.get_static_root_path();
let krate_with_trailing_slash = ensure_trailing_slash(&layout.krate).to_string();
// bootstrap passes in parts of the version separated by tabs, but other stuff might use spaces
let (display_krate_version_number, display_krate_version_extra) =
display_krate_version.split_once([' ', '\t']).unwrap_or((display_krate_version, ""));
let mut themes: Vec<String> = style_files.iter().map(|s| s.basename().unwrap()).collect(); let mut themes: Vec<String> = style_files.iter().map(|s| s.basename().unwrap()).collect();
themes.sort(); themes.sort();
let rustdoc_version = rustc_interface::util::version_str!().unwrap_or("unknown version");
let content = Buffer::html().to_display(t); // Note: This must happen before making the sidebar. let content = Buffer::html().to_display(t); // Note: This must happen before making the sidebar.
let sidebar = Buffer::html().to_display(sidebar); let sidebar = Buffer::html().to_display(sidebar);
PageLayout { PageLayout {
@ -84,7 +108,10 @@ pub(crate) fn render<T: Print, S: Print>(
themes, themes,
sidebar, sidebar,
content, content,
krate_with_trailing_slash, display_krate,
display_krate_with_trailing_slash,
display_krate_version_number,
display_krate_version_extra,
rust_channel: *crate::clean::utils::DOC_CHANNEL, rust_channel: *crate::clean::utils::DOC_CHANNEL,
rustdoc_version, rustdoc_version,
} }

View File

@ -24,6 +24,7 @@ use super::{
sidebar::{sidebar_module_like, Sidebar}, sidebar::{sidebar_module_like, Sidebar},
AllTypes, LinkFromSrc, StylePath, AllTypes, LinkFromSrc, StylePath,
}; };
use crate::clean::utils::has_doc_flag;
use crate::clean::{self, types::ExternalLocation, ExternalCrate, TypeAliasItem}; use crate::clean::{self, types::ExternalLocation, ExternalCrate, TypeAliasItem};
use crate::config::{ModuleSorting, RenderOptions}; use crate::config::{ModuleSorting, RenderOptions};
use crate::docfs::{DocFS, PathError}; use crate::docfs::{DocFS, PathError};
@ -277,6 +278,7 @@ impl<'tcx> Context<'tcx> {
title: &title, title: &title,
description: &desc, description: &desc,
resource_suffix: &clone_shared.resource_suffix, resource_suffix: &clone_shared.resource_suffix,
rust_logo: has_doc_flag(self.tcx(), LOCAL_CRATE.as_def_id(), sym::rust_logo),
}; };
let mut page_buffer = Buffer::html(); let mut page_buffer = Buffer::html();
print_item(self, it, &mut page_buffer, &page); print_item(self, it, &mut page_buffer, &page);
@ -529,8 +531,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
playground = Some(markdown::Playground { crate_name: Some(krate.name(tcx)), url }); playground = Some(markdown::Playground { crate_name: Some(krate.name(tcx)), url });
} }
let krate_version = cache.crate_version.as_deref().unwrap_or_default(); let krate_version = cache.crate_version.as_deref().unwrap_or_default();
let (krate_version, krate_version_extra) =
krate_version.split_once(" ").unwrap_or((krate_version, ""));
let mut layout = layout::Layout { let mut layout = layout::Layout {
logo: String::new(), logo: String::new(),
favicon: String::new(), favicon: String::new(),
@ -538,7 +538,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
default_settings, default_settings,
krate: krate.name(tcx).to_string(), krate: krate.name(tcx).to_string(),
krate_version: krate_version.to_string(), krate_version: krate_version.to_string(),
krate_version_extra: krate_version_extra.to_string(),
css_file_extension: extension_css, css_file_extension: extension_css,
scrape_examples_extension: !call_locations.is_empty(), scrape_examples_extension: !call_locations.is_empty(),
}; };
@ -668,6 +667,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
static_root_path: shared.static_root_path.as_deref(), static_root_path: shared.static_root_path.as_deref(),
description: "List of all items in this crate", description: "List of all items in this crate",
resource_suffix: &shared.resource_suffix, resource_suffix: &shared.resource_suffix,
rust_logo: has_doc_flag(self.tcx(), LOCAL_CRATE.as_def_id(), sym::rust_logo),
}; };
let all = shared.all.replace(AllTypes::new()); let all = shared.all.replace(AllTypes::new());
let mut sidebar = Buffer::html(); let mut sidebar = Buffer::html();
@ -693,9 +693,10 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
shared.fs.write(final_file, v)?; shared.fs.write(final_file, v)?;
// Generating settings page. // Generating settings page.
page.title = "Rustdoc settings"; page.title = "Settings";
page.description = "Settings of Rustdoc"; page.description = "Settings of Rustdoc";
page.root_path = "./"; page.root_path = "./";
page.rust_logo = true;
let sidebar = "<h2 class=\"location\">Settings</h2><div class=\"sidebar-elems\"></div>"; let sidebar = "<h2 class=\"location\">Settings</h2><div class=\"sidebar-elems\"></div>";
let v = layout::render( let v = layout::render(
@ -743,9 +744,10 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
shared.fs.write(settings_file, v)?; shared.fs.write(settings_file, v)?;
// Generating help page. // Generating help page.
page.title = "Rustdoc help"; page.title = "Help";
page.description = "Documentation for Rustdoc"; page.description = "Documentation for Rustdoc";
page.root_path = "./"; page.root_path = "./";
page.rust_logo = true;
let sidebar = "<h2 class=\"location\">Help</h2><div class=\"sidebar-elems\"></div>"; let sidebar = "<h2 class=\"location\">Help</h2><div class=\"sidebar-elems\"></div>";
let v = layout::render( let v = layout::render(

View File

@ -341,6 +341,7 @@ if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex};
static_root_path: shared.static_root_path.as_deref(), static_root_path: shared.static_root_path.as_deref(),
description: "List of crates", description: "List of crates",
resource_suffix: &shared.resource_suffix, resource_suffix: &shared.resource_suffix,
rust_logo: true,
}; };
let content = format!( let content = format!(

View File

@ -1,4 +1,5 @@
use crate::clean; use crate::clean;
use crate::clean::utils::has_doc_flag;
use crate::docfs::PathError; use crate::docfs::PathError;
use crate::error::Error; use crate::error::Error;
use crate::html::format; use crate::html::format;
@ -13,6 +14,7 @@ use rustc_hir::def_id::LOCAL_CRATE;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_session::Session; use rustc_session::Session;
use rustc_span::source_map::FileName; use rustc_span::source_map::FileName;
use rustc_span::sym;
use std::cell::RefCell; use std::cell::RefCell;
use std::ffi::OsStr; use std::ffi::OsStr;
@ -231,6 +233,7 @@ impl SourceCollector<'_, '_> {
static_root_path: shared.static_root_path.as_deref(), static_root_path: shared.static_root_path.as_deref(),
description: &desc, description: &desc,
resource_suffix: &shared.resource_suffix, resource_suffix: &shared.resource_suffix,
rust_logo: has_doc_flag(self.cx.tcx(), LOCAL_CRATE.as_def_id(), sym::rust_logo),
}; };
let v = layout::render( let v = layout::render(
&shared.layout, &shared.layout,

View File

@ -521,7 +521,8 @@ ul.block, .block li {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
margin: 0 32px; margin: 10px 32px 0;
row-gap: 10px;
column-gap: 32px; column-gap: 32px;
flex-wrap: wrap; flex-wrap: wrap;
} }
@ -540,7 +541,7 @@ ul.block, .block li {
} }
.sidebar-crate .logo-container { .sidebar-crate .logo-container {
margin: 10px -16px; margin: 0 -16px;
text-align: center; text-align: center;
} }

View File

@ -77,34 +77,38 @@
{% if page.css_class != "src" %} {% if page.css_class != "src" %}
<nav class="mobile-topbar"> {# #} <nav class="mobile-topbar"> {# #}
<button class="sidebar-menu-toggle">&#9776;</button> {# #} <button class="sidebar-menu-toggle">&#9776;</button> {# #}
<a class="logo-container" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {# #} {% if !layout.logo.is_empty() || page.rust_logo %}
{% if !layout.logo.is_empty() %} <a class="logo-container" href="{{page.root_path|safe}}{{display_krate_with_trailing_slash|safe}}index.html"> {# #}
<img src="{{layout.logo}}" alt="logo"> {# #} {% if page.rust_logo %}
{% else %} <img class="rust-logo" src="{{static_root_path|safe}}{{files.rust_logo_svg}}" alt=""> {# #}
<img class="rust-logo" src="{{static_root_path|safe}}{{files.rust_logo_svg}}" alt="logo"> {# #} {% else if !layout.logo.is_empty() %}
<img src="{{layout.logo}}" alt=""> {# #}
{% endif %} {% endif %}
</a> {# #} </a> {# #}
{% endif %}
</nav> </nav>
{% endif %} {% endif %}
<nav class="sidebar"> {# #} <nav class="sidebar"> {# #}
{% if page.css_class != "src" %} {% if page.css_class != "src" %}
<div class="sidebar-crate"> <div class="sidebar-crate">
<a class="logo-container" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {# #} {% if !layout.logo.is_empty() || page.rust_logo %}
{% if !layout.logo.is_empty() %} <a class="logo-container" href="{{page.root_path|safe}}{{display_krate_with_trailing_slash|safe}}index.html"> {# #}
<img src="{{layout.logo}}" alt="logo"> {# #} {% if page.rust_logo %}
{% else %}
<img class="rust-logo" src="{{static_root_path|safe}}{{files.rust_logo_svg}}" alt="logo"> {# #} <img class="rust-logo" src="{{static_root_path|safe}}{{files.rust_logo_svg}}" alt="logo"> {# #}
{% else if !layout.logo.is_empty() %}
<img src="{{layout.logo}}" alt="logo"> {# #}
{% endif %} {% endif %}
</a> {# #} </a> {# #}
{% endif %}
<h2> {# #} <h2> {# #}
<a href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html">{{layout.krate}}</a> {# #} <a href="{{page.root_path|safe}}{{display_krate_with_trailing_slash|safe}}index.html">{{display_krate}}</a> {# #}
{% if !layout.krate_version.is_empty() %} {% if !display_krate_version_number.is_empty() %}
<span class="version">{{+ layout.krate_version}}</span> <span class="version">{{+ display_krate_version_number}}</span>
{% endif %} {% endif %}
</h2> {# #} </h2> {# #}
</div> {# #} </div> {# #}
{% if !layout.krate_version_extra.is_empty() %} {% if !display_krate_version_extra.is_empty() %}
<div class="version">{{+ layout.krate_version_extra}}</div> {# #} <div class="version">{{+ display_krate_version_extra}}</div> {# #}
{% endif %} {% endif %}
{% endif %} {% endif %}
{{ sidebar|safe }} {{ sidebar|safe }}
@ -112,12 +116,12 @@
<main> {# #} <main> {# #}
{% if page.css_class != "src" %}<div class="width-limiter">{% endif %} {% if page.css_class != "src" %}<div class="width-limiter">{% endif %}
<nav class="sub"> {# #} <nav class="sub"> {# #}
{% if page.css_class == "src" %} {% if page.css_class == "src" && (!layout.logo.is_empty() || page.rust_logo) %}
<a class="sub-logo-container" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {# #} <a class="sub-logo-container" href="{{page.root_path|safe}}{{display_krate_with_trailing_slash|safe}}index.html"> {# #}
{% if !layout.logo.is_empty() %} {% if page.rust_logo %}
<img src="{{layout.logo}}" alt="logo"> {# #} <img class="rust-logo" src="{{static_root_path|safe}}{{files.rust_logo_svg}}" alt="{{display_krate}}"> {# #}
{% else %} {% else if !layout.logo.is_empty() %}
<img class="rust-logo" src="{{static_root_path|safe}}{{files.rust_logo_svg}}" alt="logo"> {# #} <img src="{{layout.logo}}" alt="{{display_krate}}"> {# #}
{% endif %} {% endif %}
</a> {# #} </a> {# #}
{% endif %} {% endif %}

View File

@ -1,4 +1,4 @@
// Note: this test is paired with logo-class.rs. // Note: this test is paired with logo-class.rs and logo-class-rust.rs.
// @has logo_class_default/struct.SomeStruct.html '//*[@class="logo-container"]/img[@class="rust-logo"]' '' // @!has logo_class_default/struct.SomeStruct.html '//*[@class="logo-container"]/img' ''
// @has src/logo_class_default/logo-class-default.rs.html '//*[@class="sub-logo-container"]/img[@class="rust-logo"]' '' // @!has src/logo_class_default/logo-class-default.rs.html '//*[@class="sub-logo-container"]/img' ''
pub struct SomeStruct; pub struct SomeStruct;

View File

@ -0,0 +1,7 @@
#![feature(rustdoc_internals)]
#![allow(internal_features)]
#![doc(rust_logo)]
// Note: this test is paired with logo-class.rs and logo-class-default.rs.
// @has logo_class_rust/struct.SomeStruct.html '//*[@class="logo-container"]/img[@class="rust-logo"]' ''
// @has src/logo_class_rust/logo-class-rust.rs.html '//*[@class="sub-logo-container"]/img[@class="rust-logo"]' ''
pub struct SomeStruct;

View File

@ -1,6 +1,6 @@
#![doc(html_logo_url = #![doc(html_logo_url =
"https://raw.githubusercontent.com/sagebind/isahc/master/media/isahc.svg.png")] "https://raw.githubusercontent.com/sagebind/isahc/master/media/isahc.svg.png")]
// Note: this test is paired with logo-class-default.rs. // Note: this test is paired with logo-class-default.rs and logo-class-rust.rs.
// @has logo_class/struct.SomeStruct.html '//*[@class="logo-container"]/img[@src="https://raw.githubusercontent.com/sagebind/isahc/master/media/isahc.svg.png"]' '' // @has logo_class/struct.SomeStruct.html '//*[@class="logo-container"]/img[@src="https://raw.githubusercontent.com/sagebind/isahc/master/media/isahc.svg.png"]' ''
// @!has logo_class/struct.SomeStruct.html '//*[@class="logo-container"]/img[@class="rust-logo"]' '' // @!has logo_class/struct.SomeStruct.html '//*[@class="logo-container"]/img[@class="rust-logo"]' ''

View File

@ -0,0 +1,5 @@
#![doc(rust_logo)]
//~^ ERROR the `#[doc(rust_logo)]` attribute is used for Rust branding
//! This is not an official rust crate
fn main() {}

View File

@ -0,0 +1,12 @@
error[E0658]: the `#[doc(rust_logo)]` attribute is used for Rust branding
--> $DIR/doc-rust-logo.rs:1:8
|
LL | #![doc(rust_logo)]
| ^^^^^^^^^
|
= note: see issue #90418 <https://github.com/rust-lang/rust/issues/90418> for more information
= help: add `#![feature(rustdoc_internals)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.