@@ -69,7 +69,9 @@ pub struct ImplCandidate<'tcx> {
69
69
}
70
70
71
71
enum GetSafeTransmuteErrorAndReason {
72
- Silent ,
72
+ ErrorGuaranteed ( ErrorGuaranteed ) ,
73
+ // Unable to compute Safe Transmute result because of ambiguity
74
+ Ambiguous ,
73
75
Error { err_msg : String , safe_transmute_explanation : String } ,
74
76
}
75
77
@@ -756,7 +758,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
756
758
trait_ref,
757
759
span,
758
760
) {
759
- GetSafeTransmuteErrorAndReason :: Silent => return ,
761
+ GetSafeTransmuteErrorAndReason :: ErrorGuaranteed ( _guar) => return ,
762
+ // Unable to compute whether Safe Transmute is possible (for example, due to an unevaluated const).
763
+ // The same thing occurred during trait selection/confirmation, so there is no error to report here.
764
+ GetSafeTransmuteErrorAndReason :: Ambiguous => return ,
760
765
GetSafeTransmuteErrorAndReason :: Error {
761
766
err_msg,
762
767
safe_transmute_explanation,
@@ -2884,15 +2889,17 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2884
2889
src : trait_ref. args . type_at ( 1 ) ,
2885
2890
} ;
2886
2891
let scope = trait_ref. args . type_at ( 2 ) ;
2887
- let Some ( assume) = rustc_transmute:: Assume :: from_const (
2892
+
2893
+ let maybe_assume = rustc_transmute:: Assume :: from_const (
2888
2894
self . infcx . tcx ,
2889
2895
obligation. param_env ,
2890
2896
trait_ref. args . const_at ( 3 ) ,
2891
- ) else {
2892
- span_bug ! (
2893
- span,
2894
- "Unable to construct rustc_transmute::Assume where it was previously possible"
2895
- ) ;
2897
+ ) ;
2898
+
2899
+ let assume = match maybe_assume {
2900
+ Some ( Ok ( assume) ) => assume,
2901
+ Some ( Err ( guar) ) => return GetSafeTransmuteErrorAndReason :: ErrorGuaranteed ( guar) ,
2902
+ None => return GetSafeTransmuteErrorAndReason :: Ambiguous ,
2896
2903
} ;
2897
2904
2898
2905
match rustc_transmute:: TransmuteTypeEnv :: new ( self . infcx ) . is_transmutable (
@@ -2938,8 +2945,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2938
2945
format ! ( "`{src}` is a shared reference, but `{dst}` is a unique reference" )
2939
2946
}
2940
2947
// Already reported by rustc
2941
- rustc_transmute:: Reason :: TypeError => {
2942
- return GetSafeTransmuteErrorAndReason :: Silent ;
2948
+ rustc_transmute:: Reason :: TypeError ( guar ) => {
2949
+ return GetSafeTransmuteErrorAndReason :: ErrorGuaranteed ( guar ) ;
2943
2950
}
2944
2951
rustc_transmute:: Reason :: SrcLayoutUnknown => {
2945
2952
format ! ( "`{src}` has an unknown layout" )
0 commit comments