From 9281be94b56f1e894a2d82a5a8fc8a601163b232 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Thu, 2 Jan 2025 14:46:36 -0800 Subject: [PATCH] Remove unused fields from RepeatElementCopy obligation --- compiler/rustc_hir_typeck/src/expr.rs | 17 ++--------------- compiler/rustc_middle/src/traits/mod.rs | 8 ++++---- .../src/error_reporting/traits/suggestions.rs | 7 +------ 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 8ba9a4bab5783..2f7ed8dd2a877 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -1907,21 +1907,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; let lang_item = self.tcx.require_lang_item(LangItem::Copy, None); - let code = traits::ObligationCauseCode::RepeatElementCopy { - is_constable, - elt_type: element_ty, - elt_span: element.span, - elt_stmt_span: self - .tcx - .hir() - .parent_iter(element.hir_id) - .find_map(|(_, node)| match node { - hir::Node::Item(it) => Some(it.span), - hir::Node::Stmt(stmt) => Some(stmt.span), - _ => None, - }) - .expect("array repeat expressions must be inside an item or statement"), - }; + let code = + traits::ObligationCauseCode::RepeatElementCopy { is_constable, elt_span: element.span }; self.require_type_meets(element_ty, element.span, code, lang_item); } diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index b34a1782581e9..99211c1f92440 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -247,11 +247,11 @@ pub enum ObligationCauseCode<'tcx> { /// If element is a `const fn` or const ctor we display a help message suggesting /// to move it to a new `const` item while saying that `T` doesn't implement `Copy`. is_constable: IsConstable, - elt_type: Ty<'tcx>, + + /// Span of the repeat element. + /// + /// This is used to suggest wrapping it in a `const { ... }` block. elt_span: Span, - /// Span of the statement/item in which the repeat expression occurs. We can use this to - /// place a `const` declaration before it - elt_stmt_span: Span, }, /// Types of fields (other than the last, except for packed structs) in a struct must be sized. diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 1b8b35f18df84..6c0676270ece2 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -2966,12 +2966,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { "required for the cast from `{source}` to `{target}`", ))); } - ObligationCauseCode::RepeatElementCopy { - is_constable, - elt_type: _, - elt_span, - elt_stmt_span: _, - } => { + ObligationCauseCode::RepeatElementCopy { is_constable, elt_span } => { err.note( "the `Copy` trait is required because this value will be copied for each element of the array", );