summaryrefslogtreecommitdiffstats
path: root/src/librustdoc/html/render/context.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /src/librustdoc/html/render/context.rs
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/librustdoc/html/render/context.rs')
-rw-r--r--src/librustdoc/html/render/context.rs74
1 files changed, 56 insertions, 18 deletions
diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs
index d7ff248a9..97714afaa 100644
--- a/src/librustdoc/html/render/context.rs
+++ b/src/librustdoc/html/render/context.rs
@@ -7,8 +7,10 @@ use std::sync::mpsc::{channel, Receiver};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def_id::{DefIdMap, LOCAL_CRATE};
+use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
+use rustc_span::def_id::DefId;
use rustc_span::edition::Edition;
use rustc_span::source_map::FileName;
use rustc_span::{sym, Symbol};
@@ -22,13 +24,13 @@ use super::{
sidebar::{sidebar_module_like, Sidebar},
AllTypes, LinkFromSrc, StylePath,
};
-use crate::clean::{self, types::ExternalLocation, ExternalCrate};
+use crate::clean::{self, types::ExternalLocation, ExternalCrate, TypeAliasItem};
use crate::config::{ModuleSorting, RenderOptions};
use crate::docfs::{DocFS, PathError};
use crate::error::Error;
use crate::formats::cache::Cache;
use crate::formats::item_type::ItemType;
-use crate::formats::FormatRenderer;
+use crate::formats::{self, FormatRenderer};
use crate::html::escape::Escape;
use crate::html::format::{join_with_double_colon, Buffer};
use crate::html::markdown::{self, plain_text_summary, ErrorCodes, IdMap};
@@ -105,8 +107,8 @@ pub(crate) struct SharedContext<'tcx> {
pub(super) module_sorting: ModuleSorting,
/// Additional CSS files to be added to the generated docs.
pub(crate) style_files: Vec<StylePath>,
- /// Suffix to be added on resource files (if suffix is "-v2" then "light.css" becomes
- /// "light-v2.css").
+ /// Suffix to add on resource files (if suffix is "-v2" then "search-index.js" becomes
+ /// "search-index-v2.js").
pub(crate) resource_suffix: String,
/// Optional path string to be used to load static files on output pages. If not set, uses
/// combinations of `../` to reach the documentation root.
@@ -147,6 +149,53 @@ impl SharedContext<'_> {
pub(crate) fn edition(&self) -> Edition {
self.tcx.sess.edition()
}
+
+ /// Returns a list of impls on the given type, and, if it's a type alias,
+ /// other types that it aliases.
+ pub(crate) fn all_impls_for_item<'a>(
+ &'a self,
+ it: &clean::Item,
+ did: DefId,
+ ) -> Vec<&'a formats::Impl> {
+ let tcx = self.tcx;
+ let cache = &self.cache;
+ let mut saw_impls = FxHashSet::default();
+ let mut v: Vec<&formats::Impl> = cache
+ .impls
+ .get(&did)
+ .map(Vec::as_slice)
+ .unwrap_or(&[])
+ .iter()
+ .filter(|i| saw_impls.insert(i.def_id()))
+ .collect();
+ if let TypeAliasItem(ait) = &*it.kind &&
+ let aliased_clean_type = ait.item_type.as_ref().unwrap_or(&ait.type_) &&
+ let Some(aliased_type_defid) = aliased_clean_type.def_id(cache) &&
+ let Some(av) = cache.impls.get(&aliased_type_defid) &&
+ let Some(alias_def_id) = it.item_id.as_def_id()
+ {
+ // This branch of the compiler compares types structually, but does
+ // not check trait bounds. That's probably fine, since type aliases
+ // don't normally constrain on them anyway.
+ // https://github.com/rust-lang/rust/issues/21903
+ //
+ // FIXME(lazy_type_alias): Once the feature is complete or stable, rewrite this to use type unification.
+ // Be aware of `tests/rustdoc/issue-112515-impl-ty-alias.rs` which might regress.
+ let aliased_ty = tcx.type_of(alias_def_id).skip_binder();
+ let reject_cx = DeepRejectCtxt {
+ treat_obligation_params: TreatParams::AsCandidateKey,
+ };
+ v.extend(av.iter().filter(|impl_| {
+ if let Some(impl_def_id) = impl_.impl_item.item_id.as_def_id() {
+ reject_cx.types_may_unify(aliased_ty, tcx.type_of(impl_def_id).skip_binder())
+ && saw_impls.insert(impl_def_id)
+ } else {
+ false
+ }
+ }));
+ }
+ v
+ }
}
impl<'tcx> Context<'tcx> {
@@ -463,6 +512,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
generate_link_to_definition,
call_locations,
no_emit_shared,
+ html_no_source,
..
} = options;
@@ -488,7 +538,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
scrape_examples_extension: !call_locations.is_empty(),
};
let mut issue_tracker_base_url = None;
- let mut include_sources = true;
+ let mut include_sources = !html_no_source;
// Crawl the crate attributes looking for attributes which control how we're
// going to emit HTML
@@ -664,21 +714,9 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
You need to enable JavaScript be able to update your settings.\
</section>\
</noscript>\
- <link rel=\"stylesheet\" \
- href=\"{static_root_path}{settings_css}\">\
- <script defer src=\"{static_root_path}{settings_js}\"></script>\
- <link rel=\"preload\" href=\"{static_root_path}{theme_light_css}\" \
- as=\"style\">\
- <link rel=\"preload\" href=\"{static_root_path}{theme_dark_css}\" \
- as=\"style\">\
- <link rel=\"preload\" href=\"{static_root_path}{theme_ayu_css}\" \
- as=\"style\">",
+ <script defer src=\"{static_root_path}{settings_js}\"></script>",
static_root_path = page.get_static_root_path(),
- settings_css = static_files::STATIC_FILES.settings_css,
settings_js = static_files::STATIC_FILES.settings_js,
- theme_light_css = static_files::STATIC_FILES.theme_light_css,
- theme_dark_css = static_files::STATIC_FILES.theme_dark_css,
- theme_ayu_css = static_files::STATIC_FILES.theme_ayu_css,
);
// Pre-load all theme CSS files, so that switching feels seamless.
//