Skip to content

Commit 37c9a60

Browse files
committed
factor out helper method
1 parent 099bb1b commit 37c9a60

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/librustc/traits/coherence.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fn overlap<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
126126
}
127127

128128
pub fn trait_ref_is_knowable<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
129-
trait_ref: &ty::TraitRef<'tcx>) -> bool
129+
trait_ref: ty::TraitRef<'tcx>) -> bool
130130
{
131131
debug!("trait_ref_is_knowable(trait_ref={:?})", trait_ref);
132132

@@ -140,10 +140,7 @@ pub fn trait_ref_is_knowable<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
140140
// if the trait is not marked fundamental, then it's always possible that
141141
// an ancestor crate will impl this in the future, if they haven't
142142
// already
143-
if
144-
trait_ref.def_id.krate != LOCAL_CRATE &&
145-
!tcx.has_attr(trait_ref.def_id, "fundamental")
146-
{
143+
if !trait_ref_is_local_or_fundamental(tcx, trait_ref) {
147144
debug!("trait_ref_is_knowable: trait is neither local nor fundamental");
148145
return false;
149146
}
@@ -157,6 +154,12 @@ pub fn trait_ref_is_knowable<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
157154
orphan_check_trait_ref(tcx, trait_ref, InferIsLocal(true)).is_err()
158155
}
159156

157+
pub fn trait_ref_is_local_or_fundamental<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
158+
trait_ref: ty::TraitRef<'tcx>)
159+
-> bool {
160+
trait_ref.def_id.krate == LOCAL_CRATE || tcx.has_attr(trait_ref.def_id, "fundamental")
161+
}
162+
160163
pub enum OrphanCheckErr<'tcx> {
161164
NoLocalInputType,
162165
UncoveredTy(Ty<'tcx>),
@@ -186,11 +189,11 @@ pub fn orphan_check<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
186189
return Ok(());
187190
}
188191

189-
orphan_check_trait_ref(tcx, &trait_ref, InferIsLocal(false))
192+
orphan_check_trait_ref(tcx, trait_ref, InferIsLocal(false))
190193
}
191194

192195
fn orphan_check_trait_ref<'tcx>(tcx: TyCtxt,
193-
trait_ref: &ty::TraitRef<'tcx>,
196+
trait_ref: ty::TraitRef<'tcx>,
194197
infer_is_local: InferIsLocal)
195198
-> Result<(), OrphanCheckErr<'tcx>>
196199
{

src/librustc/traits/select.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use super::{VtableImplData, VtableObjectData, VtableBuiltinData, VtableGenerator
3131
use super::util;
3232

3333
use dep_graph::{DepNodeIndex, DepKind};
34-
use hir::def_id::{DefId, LOCAL_CRATE};
34+
use hir::def_id::DefId;
3535
use infer;
3636
use infer::{InferCtxt, InferOk, TypeFreshener};
3737
use ty::subst::{Kind, Subst, Substs};
@@ -1075,9 +1075,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
10751075
} else {
10761076
None
10771077
};
1078-
let cause = if
1079-
trait_ref.def_id.krate != LOCAL_CRATE &&
1080-
!self.tcx().has_attr(trait_ref.def_id, "fundamental") {
1078+
let cause = if !coherence::trait_ref_is_local_or_fundamental(self.tcx(),
1079+
trait_ref) {
10811080
IntercrateAmbiguityCause::UpstreamCrateUpdate { trait_desc, self_desc }
10821081
} else {
10831082
IntercrateAmbiguityCause::DownstreamCrate { trait_desc, self_desc }
@@ -1205,7 +1204,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
12051204
// ok to skip binder because of the nature of the
12061205
// trait-ref-is-knowable check, which does not care about
12071206
// bound regions
1208-
let trait_ref = &predicate.skip_binder().trait_ref;
1207+
let trait_ref = predicate.skip_binder().trait_ref;
12091208

12101209
coherence::trait_ref_is_knowable(self.tcx(), trait_ref)
12111210
}

0 commit comments

Comments
 (0)