Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,23 @@ fn get_substructure_equality_expr(
EnumMatching(.., fields) | Struct(.., fields) => {
let combine = move |acc, field| {
let rhs = get_field_equality_expr(cx, field);
if let Some(lhs) = acc {
match acc {
// Combine the previous comparison with the current field
// using logical AND.
return Some(cx.expr_binary(field.span, BinOpKind::And, lhs, rhs));
Some(lhs) => Some(cx.expr_binary(field.span, BinOpKind::And, lhs, rhs)),
// Start the chain with the first field's comparison.
None => Some(rhs),
}
// Start the chain with the first field's comparison.
Some(rhs)
};

// First compare scalar fields, then compound fields, combining all
// with logical AND.
return fields
fields
.iter()
.filter(|field| !field.maybe_scalar)
.fold(fields.iter().filter(|field| field.maybe_scalar).fold(None, combine), combine)
// If there are no fields, treat as always equal.
.unwrap_or_else(|| cx.expr_bool(span, true));
.unwrap_or_else(|| cx.expr_bool(span, true))
}
EnumDiscr(disc, match_expr) => {
let lhs = get_field_equality_expr(cx, disc);
Expand All @@ -154,7 +154,7 @@ fn get_substructure_equality_expr(
};
// Compare the discriminant first (cheaper), then the rest of the
// fields.
return cx.expr_binary(disc.span, BinOpKind::And, lhs, match_expr.clone());
cx.expr_binary(disc.span, BinOpKind::And, lhs, match_expr.clone())
}
StaticEnum(..) => cx.dcx().span_bug(
span,
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => {}
}

// Don't emit the lint if we are in an impl marked as `#[automatically_derive]`.
// This is relevant for deriving `Clone` and `PartialEq` on types containing `!`.
if self.tcx.is_automatically_derived(self.tcx.parent(id.owner.def_id.into())) {
return;
}

// Don't warn twice.
self.diverges.set(Diverges::WarnedAlways);

Expand Down
20 changes: 20 additions & 0 deletions tests/ui/never_type/regress/builtin_derives_on_adts_with_never.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Regression test for <https://github.com/rust-lang/rust/issues/154900>.
//
//@ check-pass
#![feature(never_type)]
#![crate_type = "lib"]
#![warn(unreachable_code)]

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct S(!);

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct S2 {
f: !,
}

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub enum E {
E2(!),
E3 { f: ! },
}
Loading