Don't store defaultness for inherent impl items
This commit is contained in:
parent
9615ec7d10
commit
b995a55caf
6 changed files with 14 additions and 8 deletions
|
|
@ -1725,7 +1725,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
let tcx = self.tcx;
|
||||
let item = tcx.associated_item(def_id);
|
||||
|
||||
self.tables.defaultness.set_some(def_id.index, item.defaultness(tcx));
|
||||
if matches!(item.container, AssocContainer::Trait | AssocContainer::TraitImpl(_)) {
|
||||
self.tables.defaultness.set_some(def_id.index, item.defaultness(tcx));
|
||||
}
|
||||
|
||||
record!(self.tables.assoc_container[def_id] <- item.container);
|
||||
|
||||
if let AssocContainer::Trait = item.container
|
||||
|
|
|
|||
|
|
@ -1881,6 +1881,7 @@ rustc_queries! {
|
|||
}
|
||||
|
||||
/// Returns whether the impl or associated function has the `default` keyword.
|
||||
/// Note: This will ICE on inherent impl items. Consider using `AssocItem::defaultness`.
|
||||
query defaultness(def_id: DefId) -> hir::Defaultness {
|
||||
desc { |tcx| "looking up whether `{}` has `default`", tcx.def_path_str(def_id) }
|
||||
separate_provide_extern
|
||||
|
|
|
|||
|
|
@ -53,7 +53,10 @@ impl AssocItem {
|
|||
///
|
||||
/// [`type_of`]: crate::ty::TyCtxt::type_of
|
||||
pub fn defaultness(&self, tcx: TyCtxt<'_>) -> hir::Defaultness {
|
||||
tcx.defaultness(self.def_id)
|
||||
match self.container {
|
||||
AssocContainer::InherentImpl => hir::Defaultness::Final,
|
||||
AssocContainer::Trait | AssocContainer::TraitImpl(_) => tcx.defaultness(self.def_id),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_trait_impl(&self) -> Result<DefId, ErrorGuaranteed> {
|
||||
|
|
|
|||
|
|
@ -93,10 +93,6 @@ fn defaultness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Defaultness {
|
|||
..
|
||||
})
|
||||
| hir::Node::TraitItem(hir::TraitItem { defaultness, .. }) => *defaultness,
|
||||
hir::Node::ImplItem(hir::ImplItem {
|
||||
impl_kind: hir::ImplItemImplKind::Inherent { .. },
|
||||
..
|
||||
}) => hir::Defaultness::Final,
|
||||
node => {
|
||||
bug!("`defaultness` called on {:?}", node);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1256,7 +1256,10 @@ pub(crate) fn clean_impl_item<'tcx>(
|
|||
})),
|
||||
hir::ImplItemKind::Fn(ref sig, body) => {
|
||||
let m = clean_function(cx, sig, impl_.generics, ParamsSrc::Body(body));
|
||||
let defaultness = cx.tcx.defaultness(impl_.owner_id);
|
||||
let defaultness = match impl_.impl_kind {
|
||||
hir::ImplItemImplKind::Inherent { .. } => hir::Defaultness::Final,
|
||||
hir::ImplItemImplKind::Trait { defaultness, .. } => defaultness,
|
||||
};
|
||||
MethodItem(m, Some(defaultness))
|
||||
}
|
||||
hir::ImplItemKind::Type(hir_ty) => {
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ impl UrlFragment {
|
|||
&UrlFragment::Item(def_id) => {
|
||||
let kind = match tcx.def_kind(def_id) {
|
||||
DefKind::AssocFn => {
|
||||
if tcx.defaultness(def_id).has_value() {
|
||||
if tcx.associated_item(def_id).defaultness(tcx).has_value() {
|
||||
"method."
|
||||
} else {
|
||||
"tymethod."
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue