Skip to content

Commit dccc075

Browse files
committed
Check for rustc_has_incoherent_inherent_impls in incoherent_impls query.
1 parent bf644e9 commit dccc075

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -777,31 +777,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
777777

778778
self.assemble_inherent_candidates_from_object(generalized_self_ty);
779779
self.assemble_inherent_impl_candidates_for_type(p.def_id(), receiver_steps);
780-
if self.tcx.has_attr(p.def_id(), sym::rustc_has_incoherent_inherent_impls) {
781-
self.assemble_inherent_candidates_for_incoherent_ty(
782-
raw_self_ty,
783-
receiver_steps,
784-
);
785-
}
780+
self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
786781
}
787782
ty::Adt(def, _) => {
788783
let def_id = def.did();
789784
self.assemble_inherent_impl_candidates_for_type(def_id, receiver_steps);
790-
if self.tcx.has_attr(def_id, sym::rustc_has_incoherent_inherent_impls) {
791-
self.assemble_inherent_candidates_for_incoherent_ty(
792-
raw_self_ty,
793-
receiver_steps,
794-
);
795-
}
785+
self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
796786
}
797787
ty::Foreign(did) => {
798788
self.assemble_inherent_impl_candidates_for_type(did, receiver_steps);
799-
if self.tcx.has_attr(did, sym::rustc_has_incoherent_inherent_impls) {
800-
self.assemble_inherent_candidates_for_incoherent_ty(
801-
raw_self_ty,
802-
receiver_steps,
803-
);
804-
}
789+
self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
805790
}
806791
ty::Param(_) => {
807792
self.assemble_inherent_candidates_from_param(raw_self_ty);

compiler/rustc_middle/src/ty/trait_def.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_hir as hir;
66
use rustc_hir::def::DefKind;
77
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
88
use rustc_macros::{Decodable, Encodable, HashStable};
9+
use rustc_span::symbol::sym;
910
use tracing::debug;
1011

1112
use crate::query::LocalCrate;
@@ -239,6 +240,12 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
239240

240241
/// Query provider for `incoherent_impls`.
241242
pub(super) fn incoherent_impls_provider(tcx: TyCtxt<'_>, simp: SimplifiedType) -> &[DefId] {
243+
if let Some(def_id) = simp.def()
244+
&& !tcx.has_attr(def_id, sym::rustc_has_incoherent_inherent_impls)
245+
{
246+
return &[];
247+
}
248+
242249
let mut impls = Vec::new();
243250
for cnum in iter::once(LOCAL_CRATE).chain(tcx.crates(()).iter().copied()) {
244251
for &impl_def_id in tcx.crate_incoherent_impls((cnum, simp)) {

0 commit comments

Comments
 (0)