Skip to content

Commit

Permalink
Rollup merge of rust-lang#127437 - compiler-errors:uplift-trait-ref-i…
Browse files Browse the repository at this point in the history
…s-knowable, r=lcnr

Uplift trait ref is knowable into `rustc_next_trait_solver`

Self-explanatory. Eliminates one more delegate method.

r? lcnr cc `@fmease`
  • Loading branch information
jieyouxu committed Jul 8, 2024
2 parents 4ece021 + ab27c2f commit 88eca34
Show file tree
Hide file tree
Showing 18 changed files with 520 additions and 480 deletions.
15 changes: 7 additions & 8 deletions compiler/rustc_hir_analysis/src/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ fn orphan_check<'tcx>(
tcx: TyCtxt<'tcx>,
impl_def_id: LocalDefId,
mode: OrphanCheckMode,
) -> Result<(), OrphanCheckErr<'tcx, FxIndexSet<DefId>>> {
) -> Result<(), OrphanCheckErr<TyCtxt<'tcx>, FxIndexSet<DefId>>> {
// We only accept this routine to be invoked on implementations
// of a trait, not inherent implementations.
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
Expand Down Expand Up @@ -326,17 +326,16 @@ fn orphan_check<'tcx>(
ty
};

Ok(ty)
Ok::<_, !>(ty)
};

let Ok(result) = traits::orphan_check_trait_ref::<!>(
let result = traits::orphan_check_trait_ref(
&infcx,
trait_ref,
traits::InCrate::Local { mode },
lazily_normalize_ty,
) else {
unreachable!()
};
)
.into_ok();

// (2) Try to map the remaining inference vars back to generic params.
result.map_err(|err| match err {
Expand Down Expand Up @@ -369,7 +368,7 @@ fn emit_orphan_check_error<'tcx>(
tcx: TyCtxt<'tcx>,
trait_ref: ty::TraitRef<'tcx>,
impl_def_id: LocalDefId,
err: traits::OrphanCheckErr<'tcx, FxIndexSet<DefId>>,
err: traits::OrphanCheckErr<TyCtxt<'tcx>, FxIndexSet<DefId>>,
) -> ErrorGuaranteed {
match err {
traits::OrphanCheckErr::NonLocalInputType(tys) => {
Expand Down Expand Up @@ -482,7 +481,7 @@ fn emit_orphan_check_error<'tcx>(

fn lint_uncovered_ty_params<'tcx>(
tcx: TyCtxt<'tcx>,
UncoveredTyParams { uncovered, local_ty }: UncoveredTyParams<'tcx, FxIndexSet<DefId>>,
UncoveredTyParams { uncovered, local_ty }: UncoveredTyParams<TyCtxt<'tcx>, FxIndexSet<DefId>>,
impl_def_id: LocalDefId,
) {
let hir_id = tcx.local_def_id_to_hir_id(impl_def_id);
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {

let is_marker = tcx.has_attr(def_id, sym::marker);
let rustc_coinductive = tcx.has_attr(def_id, sym::rustc_coinductive);
let is_fundamental = tcx.has_attr(def_id, sym::fundamental);

// FIXME: We could probably do way better attribute validation here.
let mut skip_array_during_method_dispatch = false;
Expand Down Expand Up @@ -1352,6 +1353,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
has_auto_impl: is_auto,
is_marker,
is_coinductive: rustc_coinductive || is_auto,
is_fundamental,
skip_array_during_method_dispatch,
skip_boxed_slice_during_method_dispatch,
specialization_kind,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ This API is completely unstable and subject to change.
#![feature(rustdoc_internals)]
#![feature(slice_partition_dedup)]
#![feature(try_blocks)]
#![feature(unwrap_infallible)]
// tidy-alphabetical-end

#[macro_use]
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_infer/src/infer/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ impl<'tcx> InferCtxtLike for InferCtxt<'tcx> {
.eq_structurally_relating_aliases_no_trace(lhs, rhs)
}

fn shallow_resolve(&self, ty: Ty<'tcx>) -> Ty<'tcx> {
self.shallow_resolve(ty)
}

fn resolve_vars_if_possible<T>(&self, value: T) -> T
where
T: TypeFoldable<TyCtxt<'tcx>>,
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> {
fn sized_constraint(self, tcx: TyCtxt<'tcx>) -> Option<ty::EarlyBinder<'tcx, Ty<'tcx>>> {
self.sized_constraint(tcx)
}

fn is_fundamental(self) -> bool {
self.is_fundamental()
}
}

#[derive(Copy, Clone, Debug, Eq, PartialEq, HashStable, TyEncodable, TyDecodable)]
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
self.is_object_safe(trait_def_id)
}

fn trait_is_fundamental(self, def_id: DefId) -> bool {
self.trait_def(def_id).is_fundamental
}

fn trait_may_be_implemented_via_object(self, trait_def_id: DefId) -> bool {
self.trait_def(trait_def_id).implement_via_object
}
Expand Down Expand Up @@ -635,6 +639,10 @@ bidirectional_lang_item_map! {
}

impl<'tcx> rustc_type_ir::inherent::DefId<TyCtxt<'tcx>> for DefId {
fn is_local(self) -> bool {
self.is_local()
}

fn as_local(self) -> Option<LocalDefId> {
self.as_local()
}
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_middle/src/ty/trait_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct TraitDef {
/// and thus `impl`s of it are allowed to overlap.
pub is_marker: bool,

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

/// If `true`, then this trait has the `#[fundamental]` attribute. This
/// affects how conherence computes whether a trait may have trait implementations
/// added in the future.
pub is_fundamental: bool,

/// If `true`, then this trait has the `#[rustc_skip_during_method_dispatch(array)]`
/// attribute, indicating that editions before 2021 should not consider this trait
/// during method dispatch if the receiver is an array.
Expand Down
Loading

0 comments on commit 88eca34

Please sign in to comment.