-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Replace def_id_no_primitives with def_id #92342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use std::cell::RefCell; | ||
use std::default::Default; | ||
use std::hash::Hash; | ||
use std::hash::{Hash, Hasher}; | ||
use std::lazy::SyncOnceCell as OnceCell; | ||
use std::path::PathBuf; | ||
use std::rc::Rc; | ||
|
@@ -904,7 +904,7 @@ impl<I: Iterator<Item = ast::NestedMetaItem> + IntoIterator<Item = ast::NestedMe | |
/// Included files are kept separate from inline doc comments so that proper line-number | ||
/// information can be given when a doctest fails. Sugared doc comments and "raw" doc comments are | ||
/// kept separate because of issue #42760. | ||
#[derive(Clone, PartialEq, Eq, Debug)] | ||
#[derive(Clone, PartialEq, Eq, Debug, Hash)] | ||
crate struct DocFragment { | ||
crate span: rustc_span::Span, | ||
/// The module this doc-comment came from. | ||
|
@@ -1140,6 +1140,15 @@ impl PartialEq for Attributes { | |
|
||
impl Eq for Attributes {} | ||
|
||
impl Hash for Attributes { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? |
||
fn hash<H: Hasher>(&self, hasher: &mut H) { | ||
self.doc_strings.hash(hasher); | ||
for attr in &self.other_attrs { | ||
attr.id.hash(hasher); | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, PartialEq, Eq, Debug, Hash)] | ||
crate enum GenericBound { | ||
TraitBound(PolyTrait, hir::TraitBoundModifier), | ||
|
@@ -1554,23 +1563,12 @@ impl Type { | |
|
||
/// Use this method to get the [DefId] of a [clean] AST node, including [PrimitiveType]s. | ||
/// | ||
/// See [`Self::def_id_no_primitives`] for more. | ||
/// See [`Self::def_id`] for more. | ||
/// | ||
/// [clean]: crate::clean | ||
crate fn def_id(&self, cache: &Cache) -> Option<DefId> { | ||
self.inner_def_id(Some(cache)) | ||
} | ||
|
||
/// Use this method to get the [`DefId`] of a [`clean`] AST node. | ||
/// This will return [`None`] when called on a primitive [`clean::Type`]. | ||
/// Use [`Self::def_id`] if you want to include primitives. | ||
/// | ||
/// [`clean`]: crate::clean | ||
/// [`clean::Type`]: crate::clean::Type | ||
// FIXME: get rid of this function and always use `def_id` | ||
crate fn def_id_no_primitives(&self) -> Option<DefId> { | ||
self.inner_def_id(None) | ||
} | ||
} | ||
|
||
/// A primitive (aka, builtin) type. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ use crate::clean::*; | |
use crate::core::DocContext; | ||
use crate::visit::DocVisitor; | ||
|
||
use crate::formats::cache::Cache; | ||
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; | ||
use rustc_hir::def_id::DefId; | ||
use rustc_middle::ty::DefIdTree; | ||
|
@@ -47,7 +48,7 @@ crate fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate | |
inline::build_impl(cx, None, def_id, None, &mut new_items); | ||
|
||
// FIXME(eddyb) is this `doc(hidden)` check needed? | ||
if !cx.tcx.is_doc_hidden(def_id) { | ||
if !cx.tcx.get_attrs(def_id).lists(sym::doc).has_word(sym::hidden) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't have changed. |
||
let impls = get_auto_trait_and_blanket_impls(cx, def_id); | ||
new_items.extend(impls.filter(|i| cx.inlined.insert(i.def_id))); | ||
} | ||
|
@@ -64,6 +65,7 @@ crate fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate | |
map: &FxHashMap<DefId, &Type>, | ||
cleaner: &mut BadImplStripper, | ||
type_did: DefId, | ||
c: &Cache, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) { | ||
if let Some(target) = map.get(&type_did) { | ||
debug!("add_deref_target: type {:?}, target {:?}", type_did, target); | ||
|
@@ -76,7 +78,7 @@ crate fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate | |
return; | ||
} | ||
cleaner.items.insert(target_did.into()); | ||
add_deref_target(cx, map, cleaner, target_did); | ||
add_deref_target(cx, map, cleaner, target_did, c); | ||
} | ||
} | ||
} | ||
|
@@ -85,7 +87,7 @@ crate fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate | |
for it in &new_items { | ||
if let ImplItem(Impl { ref for_, ref trait_, ref items, .. }) = *it.kind { | ||
if trait_.as_ref().map(|t| t.def_id()) == cx.tcx.lang_items().deref_trait() | ||
&& cleaner.keep_impl(for_, true) | ||
&& cleaner.keep_impl(for_, true, &cx.cache) | ||
{ | ||
let target = items | ||
.iter() | ||
|
@@ -100,13 +102,19 @@ crate fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate | |
} else if let Some(did) = target.def_id(&cx.cache) { | ||
cleaner.items.insert(did.into()); | ||
} | ||
if let Some(for_did) = for_.def_id_no_primitives() { | ||
if let Some(for_did) = for_.def_id(&cx.cache) { | ||
if type_did_to_deref_target.insert(for_did, target).is_none() { | ||
// Since only the `DefId` portion of the `Type` instances is known to be same for both the | ||
// `Deref` target type and the impl for type positions, this map of types is keyed by | ||
// `DefId` and for convenience uses a special cleaner that accepts `DefId`s directly. | ||
if cleaner.keep_impl_with_def_id(for_did.into()) { | ||
add_deref_target(cx, &type_did_to_deref_target, &mut cleaner, for_did); | ||
add_deref_target( | ||
cx, | ||
&type_did_to_deref_target, | ||
&mut cleaner, | ||
for_did, | ||
&cx.cache, | ||
); | ||
} | ||
} | ||
} | ||
|
@@ -119,6 +127,7 @@ crate fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate | |
cleaner.keep_impl( | ||
for_, | ||
trait_.as_ref().map(|t| t.def_id()) == cx.tcx.lang_items().deref_trait(), | ||
&cx.cache, | ||
) || trait_.as_ref().map_or(false, |t| cleaner.keep_impl_with_def_id(t.def_id().into())) | ||
|| kind.is_blanket() | ||
} else { | ||
|
@@ -176,7 +185,13 @@ impl<'a, 'tcx> DocVisitor for SyntheticImplCollector<'a, 'tcx> { | |
fn visit_item(&mut self, i: &Item) { | ||
if i.is_struct() || i.is_enum() || i.is_union() { | ||
// FIXME(eddyb) is this `doc(hidden)` check needed? | ||
if !self.cx.tcx.is_doc_hidden(i.def_id.expect_def_id()) { | ||
if !self | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't have changed. |
||
.cx | ||
.tcx | ||
.get_attrs(i.def_id.expect_def_id()) | ||
.lists(sym::doc) | ||
.has_word(sym::hidden) | ||
{ | ||
self.impls | ||
.extend(get_auto_trait_and_blanket_impls(self.cx, i.def_id.expect_def_id())); | ||
} | ||
|
@@ -211,13 +226,13 @@ struct BadImplStripper { | |
} | ||
|
||
impl BadImplStripper { | ||
fn keep_impl(&self, ty: &Type, is_deref: bool) -> bool { | ||
fn keep_impl(&self, ty: &Type, is_deref: bool, c: &Cache) -> bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please name it |
||
if let Generic(_) = ty { | ||
// keep impls made on generics | ||
true | ||
} else if let Some(prim) = ty.primitive_type() { | ||
self.prims.contains(&prim) | ||
} else if let Some(did) = ty.def_id_no_primitives() { | ||
} else if let Some(did) = ty.def_id(c) { | ||
is_deref || self.keep_impl_with_def_id(did.into()) | ||
} else { | ||
false | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?