Repository: rust-lang/rust
File: compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs (Rust)

Code before:
                            )
                        }
                        // Already reported by rustc
                        rustc_transmute::Reason::TypeError => {
                            return GetSafeTransmuteErrorAndReason::Silent;
                        }
                        rustc_transmute::Reason::SrcLayoutUnknown => {
                            format!("`{src}` has an unknown layout")
                        }
                        rustc_transmute::Reason::DstLayoutUnknown => {
                            format!("`{dst}` has an unknown layout")
                        }
                    };
                    GetSafeTransmuteErrorAndReason::Error {
                        err_msg,
                        safe_transmute_explanation: Some(safe_transmute_explanation),
                    }
                }
                // The normalized types pass, but the original check failed.
                // This can happen when type aliases were normalized for diagnostics.
                // Retry with root_obligation's types to get the real error.
                Answer::Yes => {
                    if obligation.predicate != root_obligation.predicate {
                        if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(root_pred)) =
                            root_obligation.predicate.kind().skip_binder()
                            && root_pred.def_id() == trait_pred.trait_ref.def_id
                        {
                            return self.get_safe_transmute_error_and_reason(
                                root_obligation.clone(),
                                root_obligation.predicate.kind().rebind(root_pred),
                                root_obligation,
                                span,
                            );
                        }
                    }
                    span_bug!(
                        span,
                        "Inconsistent rustc_transmute::is_transmutable(...) result, got Yes",
                    )
                }
                // Reached when a different obligation (namely `Freeze`) causes the
                // transmutability analysis to fail. In this case, silence the
                // transmutability error message in favor of that more specific
                // error.
                Answer::If(_) => GetSafeTransmuteErrorAndReason::Error {
                    err_msg,
                    safe_transmute_explanation: None,
                },
            }
        })
    }

Review comment (suggestion):
```suggestion
                    if obligation.predicate != root_obligation.predicate
                        && let ty::PredicateKind::Clause(ty::ClauseKind::Trait(root_pred)) =
                            root_obligation.predicate.kind().skip_binder()
                        && root_pred.def_id() == trait_pred.trait_ref.def_id
```

Code after:
                        rustc_transmute::Reason::DstIsNotYetSupported => {
                            format!("analyzing the transmutability of `{dst}` is not yet supported")
                        }
                        rustc_transmute::Reason::DstIsBitIncompatible => {
                            format!(
                                "at least one value of `{src}` isn't a bit-valid value of `{dst}`"
                            )
                        }
                        rustc_transmute::Reason::DstUninhabited => {
                            format!("`{dst}` is uninhabited")
                        }
                        rustc_transmute::Reason::DstMayHaveSafetyInvariants => {
                            format!("`{dst}` may carry safety invariants")
                        }
                        rustc_transmute::Reason::DstIsTooBig => {
                            format!("the size of `{src}` is smaller than the size of `{dst}`")
                        }
                        rustc_transmute::Reason::DstRefIsTooBig {
                            src,
                            src_size,
                            dst,
                            dst_size,
                        } => {
                            format!(
                                "the size of `{src}` ({src_size} bytes) \
                        is smaller than that of `{dst}` ({dst_size} bytes)"
                            )
                        }
                        rustc_transmute::Reason::SrcSizeOverflow => {
                            format!(
                                "values of the type `{src}` are too big for the target architecture"
                            )
                        }
                        rustc_transmute::Reason::DstSizeOverflow => {
                            format!(
                                "values of the type `{dst}` are too big for the target architecture"
                            )
                        }
                        rustc_transmute::Reason::DstHasStricterAlignment {
                            src_min_align,
                            dst_min_align,
                        } => {
                            format!(
                                "the minimum alignment of `{src}` ({src_min_align}) should be \
                                 greater than that of `{dst}` ({dst_min_align})"
                            )
                        }
                        rustc_transmute::Reason::DstIsMoreUnique => {
                            format!(
                                "`{src}` is a shared reference, but `{dst}` is a unique reference"
                            )