diff options
| author | bors <bors@rust-lang.org> | 2025-07-09 19:38:39 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-07-09 19:38:39 +0000 |
| commit | e43d139a82620a268d3828a73e12a8679339e8f8 (patch) | |
| tree | d8d434caf51075a4bf43e995745162d007c26806 /compiler/rustc_trait_selection/src/traits/select/confirmation.rs | |
| parent | e3fccdd4a16bf3aa223749efef1fa981589e43ae (diff) | |
| parent | bbb409cc68e2588b72d95f77f2b551f5455a201d (diff) | |
| download | rust-e43d139a82620a268d3828a73e12a8679339e8f8.tar.gz rust-e43d139a82620a268d3828a73e12a8679339e8f8.zip | |
Auto merge of #143538 - compiler-errors:instantiate-auto-trait, r=lcnr
Instantiate auto trait/`Copy`/`Clone`/`Sized` before computing constituent types binder This makes the binder logic w.r.t. coroutines a bit simpler. r? lcnr
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits/select/confirmation.rs')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/select/confirmation.rs | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 545531f927a..ee8cef20279 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -21,7 +21,7 @@ use thin_vec::thin_vec; use tracing::{debug, instrument}; use super::SelectionCandidate::{self, *}; -use super::{BuiltinImplConditions, PredicateObligations, SelectionContext}; +use super::{PredicateObligations, SelectionContext}; use crate::traits::normalize::{normalize_with_depth, normalize_with_depth_to}; use crate::traits::util::{self, closure_trait_ref_and_return_type}; use crate::traits::{ @@ -257,16 +257,25 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { debug!(?obligation, "confirm_builtin_candidate"); let tcx = self.tcx(); let trait_def = obligation.predicate.def_id(); - let conditions = match tcx.as_lang_item(trait_def) { - Some(LangItem::Sized) => self.sizedness_conditions(obligation, SizedTraitKind::Sized), + let self_ty = self.infcx.shallow_resolve( + self.infcx.enter_forall_and_leak_universe(obligation.predicate.self_ty()), + ); + let types = match tcx.as_lang_item(trait_def) { + Some(LangItem::Sized) => self.sizedness_conditions(self_ty, SizedTraitKind::Sized), Some(LangItem::MetaSized) => { - self.sizedness_conditions(obligation, SizedTraitKind::MetaSized) + self.sizedness_conditions(self_ty, SizedTraitKind::MetaSized) } Some(LangItem::PointeeSized) => { bug!("`PointeeSized` is removing during lowering"); } - Some(LangItem::Copy | LangItem::Clone) => self.copy_clone_conditions(obligation), - Some(LangItem::FusedIterator) => self.fused_iterator_conditions(obligation), + Some(LangItem::Copy | LangItem::Clone) => self.copy_clone_conditions(self_ty), + Some(LangItem::FusedIterator) => { + if self.coroutine_is_gen(self_ty) { + ty::Binder::dummy(vec![]) + } else { + unreachable!("tried to assemble `FusedIterator` for non-gen coroutine"); + } + } Some( LangItem::Destruct | LangItem::DiscriminantKind @@ -274,12 +283,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | LangItem::PointeeTrait | LangItem::Tuple | LangItem::Unpin, - ) => BuiltinImplConditions::Where(ty::Binder::dummy(vec![])), + ) => ty::Binder::dummy(vec![]), other => bug!("unexpected builtin trait {trait_def:?} ({other:?})"), }; - let BuiltinImplConditions::Where(types) = conditions else { - bug!("obligation {:?} had matched a builtin impl but now doesn't", obligation); - }; let types = self.infcx.enter_forall_and_leak_universe(types); let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived); @@ -403,6 +409,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let self_ty = obligation.predicate.self_ty().map_bound(|ty| self.infcx.shallow_resolve(ty)); + let self_ty = self.infcx.enter_forall_and_leak_universe(self_ty); let types = self.constituent_types_for_ty(self_ty)?; let types = self.infcx.enter_forall_and_leak_universe(types); |
