Skip to content

Commit 88eca34

Browse files
authored
Rollup merge of #127437 - compiler-errors:uplift-trait-ref-is-knowable, r=lcnr
Uplift trait ref is knowable into `rustc_next_trait_solver` Self-explanatory. Eliminates one more delegate method. r? lcnr cc `@fmease`
2 parents 4ece021 + ab27c2f commit 88eca34

File tree

18 files changed

+520
-480
lines changed

18 files changed

+520
-480
lines changed

compiler/rustc_hir_analysis/src/coherence/orphan.rs

+7-8
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/collect.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
12011201

12021202
let is_marker = tcx.has_attr(def_id, sym::marker);
12031203
let rustc_coinductive = tcx.has_attr(def_id, sym::rustc_coinductive);
1204+
let is_fundamental = tcx.has_attr(def_id, sym::fundamental);
12041205

12051206
// FIXME: We could probably do way better attribute validation here.
12061207
let mut skip_array_during_method_dispatch = false;
@@ -1352,6 +1353,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
13521353
has_auto_impl: is_auto,
13531354
is_marker,
13541355
is_coinductive: rustc_coinductive || is_auto,
1356+
is_fundamental,
13551357
skip_array_during_method_dispatch,
13561358
skip_boxed_slice_during_method_dispatch,
13571359
specialization_kind,

compiler/rustc_hir_analysis/src/lib.rs

+1
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

+4
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

+4
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

+8
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
}

compiler/rustc_middle/src/ty/trait_def.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct TraitDef {
3131
/// and thus `impl`s of it are allowed to overlap.
3232
pub is_marker: bool,
3333

34-
/// If `true`, then this trait has to `#[rustc_coinductive]` attribute or
34+
/// If `true`, then this trait has the `#[rustc_coinductive]` attribute or
3535
/// is an auto trait. This indicates that trait solver cycles involving an
3636
/// `X: ThisTrait` goal are accepted.
3737
///
@@ -40,6 +40,11 @@ pub struct TraitDef {
4040
/// also have already switched to the new trait solver.
4141
pub is_coinductive: bool,
4242

43+
/// If `true`, then this trait has the `#[fundamental]` attribute. This
44+
/// affects how conherence computes whether a trait may have trait implementations
45+
/// added in the future.
46+
pub is_fundamental: bool,
47+
4348
/// If `true`, then this trait has the `#[rustc_skip_during_method_dispatch(array)]`
4449
/// attribute, indicating that editions before 2021 should not consider this trait
4550
/// during method dispatch if the receiver is an array.

0 commit comments

Comments
 (0)