Skip to content

Commit

Permalink
Rollup merge of rust-lang#135049 - cramertj:rmunused, r=compiler-errors
Browse files Browse the repository at this point in the history
Remove unused fields from RepeatElementCopy obligation
  • Loading branch information
matthiaskrgr authored Jan 3, 2025
2 parents e0f4dc9 + 9281be9 commit 0053aa4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 25 deletions.
17 changes: 2 additions & 15 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
Expand Down

0 comments on commit 0053aa4

Please sign in to comment.