1
1
//! Error Reporting for static impl Traits.
2
2
3
3
use rustc_data_structures:: fx:: FxIndexSet ;
4
- use rustc_errors:: { Applicability , Diag , ErrorGuaranteed , MultiSpan , Subdiagnostic } ;
4
+ use rustc_errors:: { Applicability , Diag , ErrorGuaranteed , MultiSpan } ;
5
5
use rustc_hir:: def_id:: DefId ;
6
6
use rustc_hir:: intravisit:: { Visitor , VisitorExt , walk_ty} ;
7
7
use rustc_hir:: {
@@ -14,9 +14,7 @@ use rustc_span::{Ident, Span};
14
14
use tracing:: debug;
15
15
16
16
use crate :: error_reporting:: infer:: nice_region_error:: NiceRegionError ;
17
- use crate :: errors:: {
18
- ButNeedsToSatisfy , DynTraitConstraintSuggestion , MoreTargeted , ReqIntroducedLocations ,
19
- } ;
17
+ use crate :: errors:: { ButNeedsToSatisfy , ReqIntroducedLocations } ;
20
18
use crate :: infer:: { RegionResolutionError , SubregionOrigin , TypeTrace } ;
21
19
use crate :: traits:: ObligationCauseCode ;
22
20
@@ -148,36 +146,6 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
148
146
149
147
let fn_returns = tcx. return_type_impl_or_dyn_traits ( anon_reg_sup. scope ) ;
150
148
151
- let mut override_error_code = None ;
152
-
153
- if let SubregionOrigin :: Subtype ( box TypeTrace { cause, .. } ) = & sub_origin
154
- && let code = match cause. code ( ) {
155
- ObligationCauseCode :: MatchImpl ( parent, ..) => parent. code ( ) ,
156
- _ => cause. code ( ) ,
157
- }
158
- && let & ObligationCauseCode :: WhereClause ( item_def_id, _)
159
- | & ObligationCauseCode :: WhereClauseInExpr ( item_def_id, ..) = code
160
- {
161
- // Same case of `impl Foo for dyn Bar { fn qux(&self) {} }` introducing a `'static`
162
- // lifetime as above, but called using a fully-qualified path to the method:
163
- // `Foo::qux(bar)`.
164
- let mut v = TraitObjectVisitor ( FxIndexSet :: default ( ) ) ;
165
- v. visit_ty ( param. param_ty ) ;
166
- if let Some ( ( ident, self_ty) ) =
167
- NiceRegionError :: get_impl_ident_and_self_ty_from_trait ( tcx, item_def_id, & v. 0 )
168
- && self . suggest_constrain_dyn_trait_in_impl ( & mut err, & v. 0 , ident, self_ty)
169
- {
170
- override_error_code = Some ( ident. name ) ;
171
- }
172
- }
173
- if let Some ( ident) = override_error_code
174
- && fn_returns. is_empty ( )
175
- {
176
- // Provide a more targeted error code and description.
177
- let retarget_subdiag = MoreTargeted { ident } ;
178
- retarget_subdiag. add_to_diag ( & mut err) ;
179
- }
180
-
181
149
let arg = match param. param . pat . simple_ident ( ) {
182
150
Some ( simple_ident) => format ! ( "argument `{simple_ident}`" ) ,
183
151
None => "the argument" . to_string ( ) ,
@@ -457,27 +425,6 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
457
425
_ => None ,
458
426
}
459
427
}
460
-
461
- fn suggest_constrain_dyn_trait_in_impl (
462
- & self ,
463
- err : & mut Diag < ' _ > ,
464
- found_dids : & FxIndexSet < DefId > ,
465
- ident : Ident ,
466
- self_ty : & hir:: Ty < ' _ > ,
467
- ) -> bool {
468
- let mut suggested = false ;
469
- for found_did in found_dids {
470
- let mut traits = vec ! [ ] ;
471
- let mut hir_v = HirTraitObjectVisitor ( & mut traits, * found_did) ;
472
- hir_v. visit_ty_unambig ( self_ty) ;
473
- for & span in & traits {
474
- let subdiag = DynTraitConstraintSuggestion { span, ident } ;
475
- subdiag. add_to_diag ( err) ;
476
- suggested = true ;
477
- }
478
- }
479
- suggested
480
- }
481
428
}
482
429
483
430
/// Collect all the trait objects in a type that could have received an implicit `'static` lifetime.
0 commit comments