@@ -30,7 +30,7 @@ use rustc_infer::infer::error_reporting::TypeErrCtxt;
30
30
use rustc_infer:: infer:: { InferOk , TypeTrace } ;
31
31
use rustc_middle:: traits:: select:: OverflowError ;
32
32
use rustc_middle:: traits:: solve:: Goal ;
33
- use rustc_middle:: traits:: SelectionOutputTypeParameterMismatch ;
33
+ use rustc_middle:: traits:: { DefiningAnchor , SelectionOutputTypeParameterMismatch } ;
34
34
use rustc_middle:: ty:: abstract_const:: NotConstEvaluatable ;
35
35
use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
36
36
use rustc_middle:: ty:: fold:: { TypeFolder , TypeSuperFoldable } ;
@@ -1152,6 +1152,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1152
1152
}
1153
1153
}
1154
1154
1155
+ SelectionError :: OpaqueTypeAutoTraitLeakageUnknown ( def_id) => self . report_opaque_type_auto_trait_leakage (
1156
+ & obligation,
1157
+ def_id,
1158
+ ) ,
1159
+
1155
1160
TraitNotObjectSafe ( did) => {
1156
1161
let violations = self . tcx . object_safety_violations ( did) ;
1157
1162
report_object_safety_error ( self . tcx , span, did, violations)
@@ -1170,16 +1175,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1170
1175
}
1171
1176
1172
1177
// 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 ( _) ) |
1178
1179
// 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
+
1183
1182
Overflow ( _) => {
1184
1183
bug ! ( "overflow should be handled before the `report_selection_error` path" ) ;
1185
1184
}
@@ -1471,6 +1470,12 @@ trait InferCtxtPrivExt<'tcx> {
1471
1470
terr : TypeError < ' tcx > ,
1472
1471
) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > ;
1473
1472
1473
+ fn report_opaque_type_auto_trait_leakage (
1474
+ & self ,
1475
+ obligation : & PredicateObligation < ' tcx > ,
1476
+ def_id : DefId ,
1477
+ ) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > ;
1478
+
1474
1479
fn report_type_parameter_mismatch_error (
1475
1480
& self ,
1476
1481
obligation : & PredicateObligation < ' tcx > ,
@@ -3192,6 +3197,39 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
3192
3197
)
3193
3198
}
3194
3199
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
+
3195
3233
fn report_type_parameter_mismatch_error (
3196
3234
& self ,
3197
3235
obligation : & PredicateObligation < ' tcx > ,
0 commit comments