From d7cada17670c03c7029441e17381845bbe8fa3cc Mon Sep 17 00:00:00 2001 From: lcnr Date: Thu, 31 Mar 2022 12:50:53 +0200 Subject: [PATCH 1/2] obligation cause: `RepeatVec` -> `RepeatValueCopy` --- compiler/rustc_borrowck/src/type_check/mod.rs | 4 +++- compiler/rustc_middle/src/traits/mod.rs | 11 ++++++----- compiler/rustc_mir_build/src/thir/pattern/mod.rs | 2 +- .../src/traits/error_reporting/suggestions.rs | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 7dc292ffb6579..e9fa33f656f31 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -1899,7 +1899,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { ObligationCause::new( span, self.tcx().hir().local_def_id_to_hir_id(def_id), - traits::ObligationCauseCode::RepeatVec(is_const_fn), + traits::ObligationCauseCode::RepeatElementCopy { + is_const_fn, + }, ), self.param_env, ty::Binder::dummy(ty::TraitRef::new( diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 3d0a0d2a58e1f..1f18260d9154f 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -236,11 +236,12 @@ pub enum ObligationCauseCode<'tcx> { SizedBoxType, /// Inline asm operand type must be `Sized`. InlineAsmSized, - /// `[T, ..n]` implies that `T` must be `Copy`. - /// If the function in the array repeat expression is a `const fn`, - /// display a help message suggesting to move the function call to a - /// new `const` item while saying that `T` doesn't implement `Copy`. - RepeatVec(bool), + /// `[expr; N]` requires `type_of(expr): Copy`. + RepeatElementCopy { + /// If element is a `const fn` we display a help message suggesting to move the + /// function call to a new `const` item while saying that `T` doesn't implement `Copy`. + is_const_fn: bool, + }, /// Types of fields (other than the last, except for packed structs) in a struct must be sized. FieldSized { diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index 57aec86785657..72b597bb13d29 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -198,7 +198,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { let kind = match pat.kind { hir::PatKind::Wild => PatKind::Wild, - hir::PatKind::Lit(ref value) => self.lower_lit(value), + hir::PatKind::Lit(value) => self.lower_lit(value), hir::PatKind::Range(ref lo_expr, ref hi_expr, end) => { let (lo_expr, hi_expr) = (lo_expr.as_deref(), hi_expr.as_deref()); 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 505d78d800a3a..58e002b336081 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1988,7 +1988,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ObligationCauseCode::Coercion { source: _, target } => { err.note(&format!("required by cast to type `{}`", self.ty_to_string(target))); } - ObligationCauseCode::RepeatVec(is_const_fn) => { + ObligationCauseCode::RepeatElementCopy { is_const_fn } => { err.note( "the `Copy` trait is required because the repeated element will be copied", ); From 89c66eb42d385975c91d79de139b50c298414d71 Mon Sep 17 00:00:00 2001 From: lcnr Date: Thu, 31 Mar 2022 15:41:52 +0200 Subject: [PATCH 2/2] update comment --- .../rustc_borrowck/src/type_check/free_region_relations.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs index 0b9d0a0e9220b..f8439d2e16355 100644 --- a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs +++ b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs @@ -253,8 +253,10 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> { let constraint_sets: Vec<_> = unnormalized_input_output_tys .flat_map(|ty| { debug!("build: input_or_output={:?}", ty); - // We add implied bounds from both the unnormalized and normalized ty - // See issue #87748 + // We only add implied bounds for the normalized type as the unnormalized + // type may not actually get checked by the caller. + // + // Can otherwise be unsound, see #91068. let TypeOpOutput { output: norm_ty, constraints: constraints1, .. } = self .param_env .and(type_op::normalize::Normalize::new(ty))