@@ -30,7 +30,7 @@ use rustc_infer::infer::error_reporting::TypeErrCtxt;
3030use rustc_infer:: infer:: { InferOk , TypeTrace } ;
3131use rustc_middle:: traits:: select:: OverflowError ;
3232use rustc_middle:: traits:: solve:: Goal ;
33- use rustc_middle:: traits:: SelectionOutputTypeParameterMismatch ;
33+ use rustc_middle:: traits:: { DefiningAnchor , SelectionOutputTypeParameterMismatch } ;
3434use rustc_middle:: ty:: abstract_const:: NotConstEvaluatable ;
3535use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
3636use rustc_middle:: ty:: fold:: { TypeFolder , TypeSuperFoldable } ;
@@ -1152,6 +1152,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
11521152 }
11531153 }
11541154
1155+ SelectionError :: OpaqueTypeAutoTraitLeakageUnknown ( def_id) => self . report_opaque_type_auto_trait_leakage (
1156+ & obligation,
1157+ def_id,
1158+ ) ,
1159+
11551160 TraitNotObjectSafe ( did) => {
11561161 let violations = self . tcx . object_safety_violations ( did) ;
11571162 report_object_safety_error ( self . tcx , span, did, violations)
@@ -1170,16 +1175,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
11701175 }
11711176
11721177 // Already reported in the query.
1173- SelectionError :: NotConstEvaluatable ( NotConstEvaluatable :: Error ( _) ) => {
1174- // FIXME(eddyb) remove this once `ErrorGuaranteed` becomes a proof token.
1175- self . tcx . sess . delay_span_bug ( span, "`ErrorGuaranteed` without an error" ) ;
1176- return ;
1177- }
1178+ SelectionError :: NotConstEvaluatable ( NotConstEvaluatable :: Error ( _) ) |
11781179 // Already reported.
1179- Overflow ( OverflowError :: Error ( _) ) => {
1180- self . tcx . sess . delay_span_bug ( span, "`OverflowError` has been reported" ) ;
1181- return ;
1182- }
1180+ Overflow ( OverflowError :: Error ( _) ) => return ,
1181+
11831182 Overflow ( _) => {
11841183 bug ! ( "overflow should be handled before the `report_selection_error` path" ) ;
11851184 }
@@ -1471,6 +1470,12 @@ trait InferCtxtPrivExt<'tcx> {
14711470 terr : TypeError < ' tcx > ,
14721471 ) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > ;
14731472
1473+ fn report_opaque_type_auto_trait_leakage (
1474+ & self ,
1475+ obligation : & PredicateObligation < ' tcx > ,
1476+ def_id : DefId ,
1477+ ) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > ;
1478+
14741479 fn report_type_parameter_mismatch_error (
14751480 & self ,
14761481 obligation : & PredicateObligation < ' tcx > ,
@@ -3192,6 +3197,39 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
31923197 )
31933198 }
31943199
3200+ fn report_opaque_type_auto_trait_leakage (
3201+ & self ,
3202+ obligation : & PredicateObligation < ' tcx > ,
3203+ def_id : DefId ,
3204+ ) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
3205+ let name = match self . tcx . opaque_type_origin ( def_id. expect_local ( ) ) {
3206+ hir:: OpaqueTyOrigin :: FnReturn ( _) | hir:: OpaqueTyOrigin :: AsyncFn ( _) => {
3207+ format ! ( "opaque type" )
3208+ }
3209+ hir:: OpaqueTyOrigin :: TyAlias { .. } => {
3210+ format ! ( "`{}`" , self . tcx. def_path_debug_str( def_id) )
3211+ }
3212+ } ;
3213+ let mut err = self . tcx . sess . struct_span_err (
3214+ obligation. cause . span ,
3215+ format ! ( "cannot check whether the hidden type of {name} satisfies auto traits" ) ,
3216+ ) ;
3217+ err. span_note ( self . tcx . def_span ( def_id) , "opaque type is declared here" ) ;
3218+ match self . defining_use_anchor {
3219+ DefiningAnchor :: Bubble | DefiningAnchor :: Error => { }
3220+ DefiningAnchor :: Bind ( bind) => {
3221+ err. span_note (
3222+ self . tcx . def_ident_span ( bind) . unwrap_or_else ( || self . tcx . def_span ( bind) ) ,
3223+ "this item depends on auto traits of the hidden type, \
3224+ but may also be registering the hidden type. \
3225+ This is not supported right now. \
3226+ You can try moving the opaque type and the item that actually registers a hidden type into a new submodule". to_string ( ) ,
3227+ ) ;
3228+ }
3229+ } ;
3230+ err
3231+ }
3232+
31953233 fn report_type_parameter_mismatch_error (
31963234 & self ,
31973235 obligation : & PredicateObligation < ' tcx > ,
0 commit comments