diff options
| author | Matthew Jasper <mjjasper1@gmail.com> | 2020-09-07 10:01:45 +0100 |
|---|---|---|
| committer | Matthew Jasper <mjjasper1@gmail.com> | 2020-10-06 11:19:33 +0100 |
| commit | 022c148fcd9e4339b4b59dfaee58ca5905d71b2d (patch) | |
| tree | 78e9598de2e80351e8f50abf57ca9f6c0b74e8c6 /compiler | |
| parent | 1db284ecb0039798a09e53a519219c5c556c9b38 (diff) | |
Fix tests from rebase
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_middle/src/ty/sty.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/select/confirmation.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/select/mod.rs | 18 | ||||
| -rw-r--r-- | compiler/rustc_traits/src/chalk/lowering.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/check/check.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/collect.rs | 1 |
6 files changed, 33 insertions, 22 deletions
diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 09895605dca..1af56972ad0 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1513,7 +1513,9 @@ impl<'tcx> ExistentialProjection<'tcx> { /// then this function would return a `exists T. T: Iterator` existential trait /// reference. pub fn trait_ref(&self, tcx: TyCtxt<'_>) -> ty::ExistentialTraitRef<'tcx> { - // FIXME(generic_associated_types): truncate substs to have the right length. + // FIXME(generic_associated_types): substs is the substs of the + // associated type, which should be truncated to get the correct substs + // for the trait. let def_id = tcx.associated_item(self.item_def_id).container.id(); ty::ExistentialTraitRef { def_id, substs: self.substs } } diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 905a2ab7057..96f0bedf6f1 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -125,29 +125,34 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { self.infcx.commit_unconditionally(|_| { let tcx = self.tcx(); - let bound_self_ty = self.infcx.shallow_resolve(obligation.self_ty()); - let (def_id, substs) = match *bound_self_ty.skip_binder().kind() { + let trait_predicate = self.infcx.shallow_resolve(obligation.predicate); + let placeholder_trait_predicate = + self.infcx().replace_bound_vars_with_placeholders(&trait_predicate); + let placeholder_self_ty = placeholder_trait_predicate.self_ty(); + let (def_id, substs) = match *placeholder_self_ty.kind() { ty::Projection(proj) => (proj.item_def_id, proj.substs), ty::Opaque(def_id, substs) => (def_id, substs), - _ => bug!("projection candidate for unexpected type: {:?}", bound_self_ty), + _ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty), }; let candidate_predicate = tcx.item_bounds(def_id)[idx].subst(tcx, substs); let candidate = candidate_predicate .to_opt_poly_trait_ref() .expect("projection candidate is not a trait predicate"); - let Normalized { value: candidate, mut obligations } = normalize_with_depth( + let mut obligations = Vec::new(); + let candidate = normalize_with_depth_to( self, obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, &candidate, + &mut obligations, ); obligations.extend( self.infcx .at(&obligation.cause, obligation.param_env) - .sup(obligation.predicate.to_poly_trait_ref(), candidate) + .sup(placeholder_trait_predicate.trait_ref.to_poly_trait_ref(), candidate) .map(|InferOk { obligations, .. }| obligations) .unwrap_or_else(|_| { bug!( @@ -158,7 +163,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { }), ); - if let ty::Projection(..) = bound_self_ty.skip_binder().kind() { + if let ty::Projection(..) = placeholder_self_ty.kind() { for predicate in tcx.predicates_of(def_id).instantiate_own(tcx, substs).predicates { let normalized = normalize_with_depth_to( self, diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 3b2cae0dbd5..a142ba58a69 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1204,22 +1204,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { if let ty::PredicateAtom::Trait(pred, _) = bound.skip_binders() { let bound = ty::Binder::bind(pred.trait_ref); if self.infcx.probe(|_| { - if let Ok(normalized_trait) = self.match_projection( + match self.match_projection( obligation, bound, placeholder_trait_predicate.trait_ref, ) { - match normalized_trait { - None => true, - Some(normalized_trait) - if distinct_normalized_bounds.insert(normalized_trait) => - { - true - } - _ => false, + Ok(None) => true, + Ok(Some(normalized_trait)) + if distinct_normalized_bounds.insert(normalized_trait) => + { + true } - } else { - false + _ => false, } }) { return Some(idx); diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index a59c81aa9b8..bdb2513cc46 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -767,7 +767,10 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<Ru | ty::PredicateAtom::ClosureKind(..) | ty::PredicateAtom::Subtype(..) | ty::PredicateAtom::ConstEvaluatable(..) - | ty::PredicateAtom::ConstEquate(..) => bug!("unexpected predicate {}", &self), + | ty::PredicateAtom::ConstEquate(..) + | ty::PredicateAtom::TypeWellFormedFromEnv(..) => { + bug!("unexpected predicate {}", &self) + } } } } diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index cfd75db61f7..d319ac2cba6 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -4,13 +4,13 @@ use super::compare_method::{compare_const_impl, compare_impl_method, compare_ty_ use super::*; use rustc_attr as attr; -use rustc_errors::Applicability; +use rustc_errors::{Applicability, ErrorReported}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE}; use rustc_hir::lang_items::LangItem; use rustc_hir::{ItemKind, Node}; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; -use rustc_infer::infer::RegionVariableOrigin; +use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt}; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::util::{Discr, IntTypeExt, Representability}; @@ -19,6 +19,8 @@ use rustc_session::config::EntryFnType; use rustc_span::symbol::sym; use rustc_span::{self, MultiSpan, Span}; use rustc_target::spec::abi::Abi; +use rustc_trait_selection::opaque_types::InferCtxtExt as _; +use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _; use rustc_trait_selection::traits::{self, ObligationCauseCode}; pub fn check_wf_new(tcx: TyCtxt<'_>) { @@ -386,7 +388,9 @@ pub(super) fn check_opaque<'tcx>( origin: &hir::OpaqueTyOrigin, ) { check_opaque_for_inheriting_lifetimes(tcx, def_id, span); - tcx.ensure().type_of(def_id); + if tcx.type_of(def_id).references_error() { + return; + } if check_opaque_for_cycles(tcx, def_id, substs, span, origin).is_err() { return; } diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 82d46b78178..092dae18192 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -704,6 +704,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) { hir::ItemKind::OpaqueTy(..) => { tcx.ensure().generics_of(def_id); tcx.ensure().predicates_of(def_id); + tcx.ensure().explicit_item_bounds(def_id); } hir::ItemKind::TyAlias(..) | hir::ItemKind::Static(..) |
