]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/traits/select.rs
Rollup merge of #65073 - ecstatic-morse:issue-65071, r=petrochenkov
[rust.git] / src / librustc / traits / select.rs
index c91ee1b9caa938e5e51632ffb7ed791070a8725d..1fae2a2fe8dbffc783595f05aacbf58e5f2541a7 100644 (file)
@@ -40,7 +40,7 @@
 use crate::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable};
 
 use crate::hir;
-use rustc_data_structures::bit_set::GrowableBitSet;
+use rustc_index::bit_set::GrowableBitSet;
 use rustc_data_structures::sync::Lock;
 use rustc_target::spec::abi::Abi;
 use syntax::attr;
@@ -224,7 +224,7 @@ pub struct SelectionCache<'tcx> {
 /// of type variables - it just means the obligation isn't sufficiently
 /// elaborated. In that case we report an ambiguity, and the caller can
 /// try again after more type information has been gathered or report a
-/// "type annotations required" error.
+/// "type annotations needed" error.
 ///
 /// However, with type parameters, this can be a real problem - type
 /// parameters don't unify with regular types, but they *can* unify
@@ -1816,7 +1816,7 @@ fn assemble_candidates_from_projected_tys(
 
         // before we go into the whole placeholder thing, just
         // quickly check if the self-type is a projection at all.
-        match obligation.predicate.skip_binder().trait_ref.self_ty().sty {
+        match obligation.predicate.skip_binder().trait_ref.self_ty().kind {
             ty::Projection(_) | ty::Opaque(..) => {}
             ty::Infer(ty::TyVar(_)) => {
                 span_bug!(
@@ -1854,7 +1854,7 @@ fn match_projection_obligation_against_definition_bounds(
             placeholder_trait_predicate,
         );
 
-        let (def_id, substs) = match placeholder_trait_predicate.trait_ref.self_ty().sty {
+        let (def_id, substs) = match placeholder_trait_predicate.trait_ref.self_ty().kind {
             ty::Projection(ref data) => (data.trait_ref(self.tcx()).def_id, data.substs),
             ty::Opaque(def_id, substs) => (def_id, substs),
             _ => {
@@ -2002,7 +2002,7 @@ fn assemble_generator_candidates(
         // touch bound regions, they just capture the in-scope
         // type/region parameters.
         let self_ty = *obligation.self_ty().skip_binder();
-        match self_ty.sty {
+        match self_ty.kind {
             ty::Generator(..) => {
                 debug!(
                     "assemble_generator_candidates: self_ty={:?} obligation={:?}",
@@ -2045,13 +2045,16 @@ fn assemble_closure_candidates(
         // Okay to skip binder because the substs on closure types never
         // touch bound regions, they just capture the in-scope
         // type/region parameters
-        match obligation.self_ty().skip_binder().sty {
+        match obligation.self_ty().skip_binder().kind {
             ty::Closure(closure_def_id, closure_substs) => {
                 debug!(
                     "assemble_unboxed_candidates: kind={:?} obligation={:?}",
                     kind, obligation
                 );
-                match self.infcx.closure_kind(closure_def_id, closure_substs) {
+                match self.infcx.closure_kind(
+                    closure_def_id,
+                    closure_substs
+                ) {
                     Some(closure_kind) => {
                         debug!(
                             "assemble_unboxed_candidates: closure_kind = {:?}",
@@ -2094,7 +2097,7 @@ fn assemble_fn_pointer_candidates(
 
         // Okay to skip binder because what we are inspecting doesn't involve bound regions
         let self_ty = *obligation.self_ty().skip_binder();
-        match self_ty.sty {
+        match self_ty.kind {
             ty::Infer(ty::TyVar(_)) => {
                 debug!("assemble_fn_pointer_candidates: ambiguous self-type");
                 candidates.ambiguous = true; // could wind up being a fn() type
@@ -2156,7 +2159,7 @@ fn assemble_candidates_from_auto_impls(
         let def_id = obligation.predicate.def_id();
 
         if self.tcx().trait_is_auto(def_id) {
-            match self_ty.sty {
+            match self_ty.kind {
                 ty::Dynamic(..) => {
                     // For object types, we don't know what the closed
                     // over types are. This means we conservatively
@@ -2229,7 +2232,7 @@ fn assemble_candidates_from_object_ty(
             // self-ty here doesn't escape this probe, so just erase
             // any LBR.
             let self_ty = self.tcx().erase_late_bound_regions(&obligation.self_ty());
-            let poly_trait_ref = match self_ty.sty {
+            let poly_trait_ref = match self_ty.kind {
                 ty::Dynamic(ref data, ..) => {
                     if data.auto_traits()
                         .any(|did| did == obligation.predicate.def_id())
@@ -2325,7 +2328,7 @@ fn assemble_candidates_for_unsizing(
             source, target
         );
 
-        let may_apply = match (&source.sty, &target.sty) {
+        let may_apply = match (&source.kind, &target.kind) {
             // Trait+Kx+'a -> Trait+Ky+'b (upcasts).
             (&ty::Dynamic(ref data_a, ..), &ty::Dynamic(ref data_b, ..)) => {
                 // Upcasts permit two things:
@@ -2491,7 +2494,7 @@ fn candidate_should_be_dropped_in_favor_of(
                 if other.evaluation.must_apply_modulo_regions() {
                     match victim.candidate {
                         ImplCandidate(victim_def) => {
-                            let tcx = self.tcx().global_tcx();
+                            let tcx = self.tcx();
                             return tcx.specializes((other_def, victim_def))
                                 || tcx.impls_are_allowed_to_overlap(
                                     other_def, victim_def).is_some();
@@ -2563,7 +2566,7 @@ fn sized_conditions(
         let self_ty = self.infcx
             .shallow_resolve(obligation.predicate.skip_binder().self_ty());
 
-        match self_ty.sty {
+        match self_ty.kind {
             ty::Infer(ty::IntVar(_))
             | ty::Infer(ty::FloatVar(_))
             | ty::Uint(_)
@@ -2629,7 +2632,7 @@ fn copy_clone_conditions(
 
         use self::BuiltinImplConditions::{Ambiguous, None, Where};
 
-        match self_ty.sty {
+        match self_ty.kind {
             ty::Infer(ty::IntVar(_))
             | ty::Infer(ty::FloatVar(_))
             | ty::FnDef(..)
@@ -2669,7 +2672,7 @@ fn copy_clone_conditions(
             ty::Closure(def_id, substs) => {
                 // (*) binder moved here
                 Where(ty::Binder::bind(
-                    substs.upvar_tys(def_id, self.tcx()).collect(),
+                    substs.as_closure().upvar_tys(def_id, self.tcx()).collect(),
                 ))
             }
 
@@ -2711,7 +2714,7 @@ fn copy_clone_conditions(
     /// Zed<i32> where enum Zed { A(T), B(u32) } -> [i32, u32]
     /// ```
     fn constituent_types_for_ty(&self, t: Ty<'tcx>) -> Vec<Ty<'tcx>> {
-        match t.sty {
+        match t.kind {
             ty::Uint(_)
             | ty::Int(_)
             | ty::Bool
@@ -2753,7 +2756,9 @@ fn constituent_types_for_ty(&self, t: Ty<'tcx>) -> Vec<Ty<'tcx>> {
                 tys.iter().map(|k| k.expect_ty()).collect()
             }
 
-            ty::Closure(def_id, ref substs) => substs.upvar_tys(def_id, self.tcx()).collect(),
+            ty::Closure(def_id, ref substs) => substs.as_closure()
+                .upvar_tys(def_id, self.tcx())
+                .collect(),
 
             ty::Generator(def_id, ref substs, _) => {
                 let witness = substs.witness(def_id, self.tcx());
@@ -3149,7 +3154,7 @@ fn confirm_object_candidate(
         // results.
         let self_ty = self.infcx
             .shallow_resolve(*obligation.self_ty().skip_binder());
-        let poly_trait_ref = match self_ty.sty {
+        let poly_trait_ref = match self_ty.kind {
             ty::Dynamic(ref data, ..) =>
                 data.principal().unwrap_or_else(|| {
                     span_bug!(obligation.cause.span, "object candidate with no principal")
@@ -3283,7 +3288,7 @@ fn confirm_generator_candidate(
         // touch bound regions, they just capture the in-scope
         // type/region parameters.
         let self_ty = self.infcx.shallow_resolve(*obligation.self_ty().skip_binder());
-        let (generator_def_id, substs) = match self_ty.sty {
+        let (generator_def_id, substs) = match self_ty.kind {
             ty::Generator(id, substs, _) => (id, substs),
             _ => bug!("closure candidate for non-closure {:?}", obligation),
         };
@@ -3340,7 +3345,7 @@ fn confirm_closure_candidate(
         // touch bound regions, they just capture the in-scope
         // type/region parameters.
         let self_ty = self.infcx.shallow_resolve(*obligation.self_ty().skip_binder());
-        let (closure_def_id, substs) = match self_ty.sty {
+        let (closure_def_id, substs) = match self_ty.kind {
             ty::Closure(id, substs) => (id, substs),
             _ => bug!("closure candidate for non-closure {:?}", obligation),
         };
@@ -3370,17 +3375,22 @@ fn confirm_closure_candidate(
         )?);
 
         // FIXME: chalk
+
         if !self.tcx().sess.opts.debugging_opts.chalk {
             obligations.push(Obligation::new(
                 obligation.cause.clone(),
                 obligation.param_env,
-                ty::Predicate::ClosureKind(closure_def_id, substs, kind),
+                ty::Predicate::ClosureKind(
+                    closure_def_id,
+                    substs,
+                    kind
+                ),
             ));
         }
 
         Ok(VtableClosureData {
             closure_def_id,
-            substs: substs.clone(),
+            substs: substs,
             nested: obligations,
         })
     }
@@ -3449,7 +3459,7 @@ fn confirm_builtin_unsize_candidate(
         );
 
         let mut nested = vec![];
-        match (&source.sty, &target.sty) {
+        match (&source.kind, &target.kind) {
             // Trait+Kx+'a -> Trait+Ky+'b (upcasts).
             (&ty::Dynamic(ref data_a, r_a), &ty::Dynamic(ref data_b, r_b)) => {
                 // See assemble_candidates_for_unsizing for more info.
@@ -3581,7 +3591,7 @@ fn confirm_builtin_unsize_candidate(
                 let mut ty_params = GrowableBitSet::new_empty();
                 let mut found = false;
                 for ty in field.walk() {
-                    if let ty::Param(p) = ty.sty {
+                    if let ty::Param(p) = ty.kind {
                         ty_params.insert(p.index as usize);
                         found = true;
                     }
@@ -3869,7 +3879,7 @@ fn closure_trait_ref_unnormalized(
         &mut self,
         obligation: &TraitObligation<'tcx>,
         closure_def_id: DefId,
-        substs: ty::ClosureSubsts<'tcx>,
+        substs: SubstsRef<'tcx>,
     ) -> ty::PolyTraitRef<'tcx> {
         debug!(
             "closure_trait_ref_unnormalized(obligation={:?}, closure_def_id={:?}, substs={:?})",