diff options
Diffstat (limited to 'compiler/rustc_trait_selection/src')
11 files changed, 37 insertions, 31 deletions
diff --git a/compiler/rustc_trait_selection/src/solve/normalize.rs b/compiler/rustc_trait_selection/src/solve/normalize.rs index 94b44571d3b..65ef4659907 100644 --- a/compiler/rustc_trait_selection/src/solve/normalize.rs +++ b/compiler/rustc_trait_selection/src/solve/normalize.rs @@ -198,7 +198,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for NormalizationFolder<'_, 'tcx> { #[instrument(level = "debug", skip(self), ret)] fn try_fold_const(&mut self, ct: ty::Const<'tcx>) -> Result<ty::Const<'tcx>, Self::Error> { let infcx = self.at.infcx; - debug_assert_eq!(ct, infcx.shallow_resolve(ct)); + debug_assert_eq!(ct, infcx.shallow_resolve_const(ct)); if !ct.has_aliases() { return Ok(ct); } diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 77eaa4fd03e..36028b51659 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -501,7 +501,7 @@ fn plug_infer_with_placeholders<'tcx>( } fn visit_const(&mut self, ct: ty::Const<'tcx>) { - let ct = self.infcx.shallow_resolve(ct); + let ct = self.infcx.shallow_resolve_const(ct); if ct.is_ct_infer() { let Ok(InferOk { value: (), obligations }) = self.infcx.at(&ObligationCause::dummy(), ty::ParamEnv::empty()).eq( diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 9ca1dd4557d..a8be5627fed 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -8,15 +8,14 @@ //! In this case we try to build an abstract representation of this constant using //! `thir_abstract_const` which can then be checked for structural equality with other //! generic constants mentioned in the `caller_bounds` of the current environment. + use rustc_hir::def::DefKind; use rustc_infer::infer::InferCtxt; use rustc_middle::mir::interpret::ErrorHandled; - use rustc_middle::traits::ObligationCause; use rustc_middle::ty::abstract_const::NotConstEvaluatable; use rustc_middle::ty::{self, TyCtxt, TypeVisitable, TypeVisitableExt, TypeVisitor}; - -use rustc_span::Span; +use rustc_span::{Span, DUMMY_SP}; use crate::traits::ObligationCtxt; @@ -116,12 +115,12 @@ pub fn is_const_evaluatable<'tcx>( tcx.dcx() .struct_span_fatal( // Slightly better span than just using `span` alone - if span == rustc_span::DUMMY_SP { tcx.def_span(uv.def) } else { span }, + if span == DUMMY_SP { tcx.def_span(uv.def) } else { span }, "failed to evaluate generic const expression", ) .with_note("the crate this constant originates from uses `#![feature(generic_const_exprs)]`") .with_span_suggestion_verbose( - rustc_span::DUMMY_SP, + DUMMY_SP, "consider enabling this feature", "#![feature(generic_const_exprs)]\n", rustc_errors::Applicability::MaybeIncorrect, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index bbb634dacdf..db3794c1c40 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -751,9 +751,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { // Get the local name of this closure. This can be inaccurate because // of the possibility of reassignment, but this should be good enough. match &kind { - hir::PatKind::Binding(hir::BindingAnnotation::NONE, _, ident, None) => { - Some(ident.name) - } + hir::PatKind::Binding(hir::BindingMode::NONE, _, ident, None) => Some(ident.name), _ => { err.note(msg); None @@ -4251,7 +4249,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { type_diffs: &[TypeError<'tcx>], span: Span, prev_ty: Ty<'tcx>, - body_id: hir::HirId, + body_id: HirId, param_env: ty::ParamEnv<'tcx>, ) -> Vec<Option<(Span, (DefId, Ty<'tcx>))>> { let ocx = ObligationCtxt::new(self.infcx); @@ -4545,7 +4543,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { self.type_implements_trait(default_trait, [ty], param_env).must_apply_modulo_regions() }; - Some(match ty.kind() { + Some(match *ty.kind() { ty::Never | ty::Error(_) => return None, ty::Bool => "false".to_string(), ty::Char => "\'x\'".to_string(), @@ -4572,12 +4570,19 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { if let (ty::Str, hir::Mutability::Not) = (ty.kind(), mutability) { "\"\"".to_string() } else { - let ty = self.ty_kind_suggestion(param_env, *ty)?; + let ty = self.ty_kind_suggestion(param_env, ty)?; format!("&{}{ty}", mutability.prefix_str()) } } ty::Array(ty, len) if let Some(len) = len.try_eval_target_usize(tcx, param_env) => { - format!("[{}; {}]", self.ty_kind_suggestion(param_env, *ty)?, len) + if len == 0 { + "[]".to_string() + } else if self.type_is_copy_modulo_regions(param_env, ty) || len == 1 { + // Can only suggest `[ty; 0]` if sz == 1 or copy + format!("[{}; {}]", self.ty_kind_suggestion(param_env, ty)?, len) + } else { + "/* value */".to_string() + } } ty::Tuple(tys) => format!( "({}{})", @@ -4587,7 +4592,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { .join(", "), if tys.len() == 1 { "," } else { "" } ), - _ => "value".to_string(), + _ => "/* value */".to_string(), }) } } @@ -4757,7 +4762,7 @@ impl<'v> Visitor<'v> for ReturnsVisitor<'v> { /// Collect all the awaited expressions within the input expression. #[derive(Default)] struct AwaitsVisitor { - awaits: Vec<hir::HirId>, + awaits: Vec<HirId>, } impl<'v> Visitor<'v> for AwaitsVisitor { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index 925fe98d293..96596de32aa 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -1977,6 +1977,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { for (obligation_arg, impl_arg) in std::iter::zip(obligation_trait_ref.args, impl_trait_ref.args) { + if (obligation_arg, impl_arg).references_error() { + return false; + } if let Err(terr) = ocx.eq(&ObligationCause::dummy(), param_env, impl_arg, obligation_arg) { diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 98d5b466cd0..8f5a30c436d 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -162,7 +162,7 @@ fn pred_known_to_hold_modulo_regions<'tcx>( let errors = ocx.select_all_or_error(); match errors.as_slice() { // Only known to hold if we did no inference. - [] => infcx.shallow_resolve(goal) == goal, + [] => infcx.resolve_vars_if_possible(goal) == goal, errors => { debug!(?errors); diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 3ef7cc01f90..c415d288b8f 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -1173,8 +1173,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { return; } - let self_ty = self.infcx.shallow_resolve(obligation.self_ty()); - match self_ty.skip_binder().kind() { + let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder()); + match self_ty.kind() { ty::Alias(..) | ty::Dynamic(..) | ty::Error(_) @@ -1325,7 +1325,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligation: &PolyTraitObligation<'tcx>, candidates: &mut SelectionCandidateSet<'tcx>, ) { - let self_ty = self.infcx.shallow_resolve(obligation.self_ty()); + let self_ty = self.infcx.resolve_vars_if_possible(obligation.self_ty()); match self_ty.skip_binder().kind() { ty::FnPtr(_) => candidates.vec.push(BuiltinCandidate { has_nested: false }), diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 716b9a49ab5..4fa2455c42d 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -157,10 +157,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> { let tcx = self.tcx(); - let trait_predicate = self.infcx.shallow_resolve(obligation.predicate); let placeholder_trait_predicate = - self.infcx.enter_forall_and_leak_universe(trait_predicate).trait_ref; - let placeholder_self_ty = placeholder_trait_predicate.self_ty(); + self.infcx.enter_forall_and_leak_universe(obligation.predicate).trait_ref; + let placeholder_self_ty = self.infcx.shallow_resolve(placeholder_trait_predicate.self_ty()); let candidate_predicate = self .for_each_item_bound( placeholder_self_ty, @@ -422,7 +421,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> { debug!(?obligation, "confirm_auto_impl_candidate"); - let self_ty = self.infcx.shallow_resolve(obligation.predicate.self_ty()); + let self_ty = obligation.predicate.self_ty().map_bound(|ty| self.infcx.shallow_resolve(ty)); let types = self.constituent_types_for_ty(self_ty)?; Ok(self.vtable_auto_impl(obligation, obligation.predicate.def_id(), types)) } @@ -1378,7 +1377,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let drop_trait = self.tcx().require_lang_item(LangItem::Drop, None); let tcx = self.tcx(); - let self_ty = self.infcx.shallow_resolve(obligation.self_ty()); + let self_ty = obligation.self_ty().map_bound(|ty| self.infcx.shallow_resolve(ty)); let mut nested = vec![]; let cause = obligation.derived_cause(BuiltinDerivedObligation); diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index e363119393a..10370c7898b 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -571,7 +571,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { )?; // If the predicate has done any inference, then downgrade the // result to ambiguous. - if this.infcx.shallow_resolve(goal) != goal { + if this.infcx.resolve_vars_if_possible(goal) != goal { result = result.max(EvaluatedToAmbig); } Ok(result) @@ -1774,9 +1774,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // that means that we must have newly inferred something about the GAT. // We should give up in that case. if !generics.params.is_empty() - && obligation.predicate.args[generics.parent_count..] - .iter() - .any(|&p| p.has_non_region_infer() && self.infcx.shallow_resolve(p) != p) + && obligation.predicate.args[generics.parent_count..].iter().any(|&p| { + p.has_non_region_infer() && self.infcx.resolve_vars_if_possible(p) != p + }) { ProjectionMatchesProjection::Ambiguous } else { diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index d29fc7921bc..a8ca7d164a0 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -649,7 +649,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for PlaceholderReplacer<'_, 'tcx> { } fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> { - let ct = self.infcx.shallow_resolve(ct); + let ct = self.infcx.shallow_resolve_const(ct); if let ty::ConstKind::Placeholder(p) = ct.kind() { let replace_var = self.mapped_consts.get(&p); match replace_var { diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 5553490542b..f1c24b6adc1 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -44,7 +44,7 @@ pub fn obligations<'tcx>( GenericArgKind::Const(ct) => { match ct.kind() { ty::ConstKind::Infer(_) => { - let resolved = infcx.shallow_resolve(ct); + let resolved = infcx.shallow_resolve_const(ct); if resolved == ct { // No progress. return None; |
