Skip to content

Commit a982471

Browse files
Uplift trait_ref_is_knowable and friends
1 parent b2e30bd commit a982471

File tree

13 files changed

+508
-458
lines changed

13 files changed

+508
-458
lines changed

compiler/rustc_hir_analysis/src/coherence/orphan.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ fn orphan_check<'tcx>(
286286
tcx: TyCtxt<'tcx>,
287287
impl_def_id: LocalDefId,
288288
mode: OrphanCheckMode,
289-
) -> Result<(), OrphanCheckErr<'tcx, FxIndexSet<DefId>>> {
289+
) -> Result<(), OrphanCheckErr<TyCtxt<'tcx>, FxIndexSet<DefId>>> {
290290
// We only accept this routine to be invoked on implementations
291291
// of a trait, not inherent implementations.
292292
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
@@ -326,17 +326,16 @@ fn orphan_check<'tcx>(
326326
ty
327327
};
328328

329-
Ok(ty)
329+
Ok::<_, !>(ty)
330330
};
331331

332-
let Ok(result) = traits::orphan_check_trait_ref::<!>(
332+
let result = traits::orphan_check_trait_ref(
333333
&infcx,
334334
trait_ref,
335335
traits::InCrate::Local { mode },
336336
lazily_normalize_ty,
337-
) else {
338-
unreachable!()
339-
};
337+
)
338+
.into_ok();
340339

341340
// (2) Try to map the remaining inference vars back to generic params.
342341
result.map_err(|err| match err {
@@ -369,7 +368,7 @@ fn emit_orphan_check_error<'tcx>(
369368
tcx: TyCtxt<'tcx>,
370369
trait_ref: ty::TraitRef<'tcx>,
371370
impl_def_id: LocalDefId,
372-
err: traits::OrphanCheckErr<'tcx, FxIndexSet<DefId>>,
371+
err: traits::OrphanCheckErr<TyCtxt<'tcx>, FxIndexSet<DefId>>,
373372
) -> ErrorGuaranteed {
374373
match err {
375374
traits::OrphanCheckErr::NonLocalInputType(tys) => {
@@ -482,7 +481,7 @@ fn emit_orphan_check_error<'tcx>(
482481

483482
fn lint_uncovered_ty_params<'tcx>(
484483
tcx: TyCtxt<'tcx>,
485-
UncoveredTyParams { uncovered, local_ty }: UncoveredTyParams<'tcx, FxIndexSet<DefId>>,
484+
UncoveredTyParams { uncovered, local_ty }: UncoveredTyParams<TyCtxt<'tcx>, FxIndexSet<DefId>>,
486485
impl_def_id: LocalDefId,
487486
) {
488487
let hir_id = tcx.local_def_id_to_hir_id(impl_def_id);

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ This API is completely unstable and subject to change.
7171
#![feature(rustdoc_internals)]
7272
#![feature(slice_partition_dedup)]
7373
#![feature(try_blocks)]
74+
#![feature(unwrap_infallible)]
7475
// tidy-alphabetical-end
7576

7677
#[macro_use]

compiler/rustc_infer/src/infer/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ impl<'tcx> InferCtxtLike for InferCtxt<'tcx> {
151151
.eq_structurally_relating_aliases_no_trace(lhs, rhs)
152152
}
153153

154+
fn shallow_resolve(&self, ty: Ty<'tcx>) -> Ty<'tcx> {
155+
self.shallow_resolve(ty)
156+
}
157+
154158
fn resolve_vars_if_possible<T>(&self, value: T) -> T
155159
where
156160
T: TypeFoldable<TyCtxt<'tcx>>,

compiler/rustc_middle/src/ty/adt.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> {
229229
fn sized_constraint(self, tcx: TyCtxt<'tcx>) -> Option<ty::EarlyBinder<'tcx, Ty<'tcx>>> {
230230
self.sized_constraint(tcx)
231231
}
232+
233+
fn is_fundamental(self) -> bool {
234+
self.is_fundamental()
235+
}
232236
}
233237

234238
#[derive(Copy, Clone, Debug, Eq, PartialEq, HashStable, TyEncodable, TyDecodable)]

compiler/rustc_middle/src/ty/context.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
524524
self.is_object_safe(trait_def_id)
525525
}
526526

527+
fn trait_is_fundamental(self, def_id: DefId) -> bool {
528+
self.trait_def(def_id).is_fundamental
529+
}
530+
527531
fn trait_may_be_implemented_via_object(self, trait_def_id: DefId) -> bool {
528532
self.trait_def(trait_def_id).implement_via_object
529533
}
@@ -635,6 +639,10 @@ bidirectional_lang_item_map! {
635639
}
636640

637641
impl<'tcx> rustc_type_ir::inherent::DefId<TyCtxt<'tcx>> for DefId {
642+
fn is_local(self) -> bool {
643+
self.is_local()
644+
}
645+
638646
fn as_local(self) -> Option<LocalDefId> {
639647
self.as_local()
640648
}

0 commit comments

Comments
 (0)