3
3
use crate :: infer:: error_reporting:: nice_region_error:: find_anon_type:: find_anon_type;
4
4
use crate :: infer:: error_reporting:: nice_region_error:: NiceRegionError ;
5
5
use rustc_errors:: { struct_span_err, Applicability , DiagnosticBuilder } ;
6
- use rustc_hir:: intravisit:: Visitor ;
7
- use rustc_hir:: FnRetTy ;
8
6
use rustc_middle:: ty;
9
7
10
8
impl < ' a , ' tcx > NiceRegionError < ' a , ' tcx > {
@@ -48,19 +46,24 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
48
46
return None ; // inapplicable
49
47
} ;
50
48
49
+ // Suggesting to add a `'static` lifetime to a parameter is nearly always incorrect,
50
+ // and can steer users down the wrong path.
51
+ if * named == ty:: ReStatic {
52
+ return None ;
53
+ }
54
+
51
55
debug ! ( "try_report_named_anon_conflict: named = {:?}" , named) ;
52
56
debug ! ( "try_report_named_anon_conflict: anon_param_info = {:?}" , anon_param_info) ;
53
57
debug ! ( "try_report_named_anon_conflict: region_info = {:?}" , region_info) ;
54
58
55
- let ( param, new_ty, new_ty_span, br, is_first, scope_def_id, is_impl_item) = (
56
- anon_param_info. param ,
57
- anon_param_info. param_ty ,
58
- anon_param_info. param_ty_span ,
59
- anon_param_info. bound_region ,
60
- anon_param_info. is_first ,
61
- region_info. def_id ,
62
- region_info. is_impl_item ,
63
- ) ;
59
+ let param = anon_param_info. param ;
60
+ let new_ty = anon_param_info. param_ty ;
61
+ let new_ty_span = anon_param_info. param_ty_span ;
62
+ let br = anon_param_info. bound_region ;
63
+ let is_first = anon_param_info. is_first ;
64
+ let scope_def_id = region_info. def_id ;
65
+ let is_impl_item = region_info. is_impl_item ;
66
+
64
67
match br {
65
68
ty:: BrAnon ( _) => { }
66
69
_ => {
@@ -75,26 +78,10 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
75
78
return None ;
76
79
}
77
80
78
- if let Some ( ( _, fndecl) ) = find_anon_type ( self . tcx ( ) , anon, & br) {
79
- if self . is_self_anon ( is_first, scope_def_id) {
80
- return None ;
81
- }
82
-
83
- if let FnRetTy :: Return ( ty) = & fndecl. output {
84
- let mut v = ty:: TraitObjectVisitor ( vec ! [ ] , self . tcx ( ) . hir ( ) ) ;
85
- v. visit_ty ( ty) ;
86
-
87
- debug ! ( "try_report_named_anon_conflict: ret ty {:?}" , ty) ;
88
- if sub == & ty:: ReStatic
89
- && v. 0 . into_iter ( ) . any ( |t| t. span . desugaring_kind ( ) . is_none ( ) )
90
- {
91
- // If the failure is due to a `'static` requirement coming from a `dyn` or
92
- // `impl` Trait that *isn't* caused by `async fn` desugaring, handle this case
93
- // better in `static_impl_trait`.
94
- debug ! ( "try_report_named_anon_conflict: impl Trait + 'static" ) ;
95
- return None ;
96
- }
97
- }
81
+ if find_anon_type ( self . tcx ( ) , anon, & br) . is_some ( )
82
+ && self . is_self_anon ( is_first, scope_def_id)
83
+ {
84
+ return None ;
98
85
}
99
86
100
87
let ( error_var, span_label_var) = match param. pat . simple_ident ( ) {
@@ -114,16 +101,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
114
101
) ;
115
102
116
103
diag. span_label ( span, format ! ( "lifetime `{}` required" , named) ) ;
117
- // Suggesting `'static` is nearly always incorrect, and can steer users
118
- // down the wrong path.
119
- if * named != ty:: ReStatic {
120
- diag. span_suggestion (
121
- new_ty_span,
122
- & format ! ( "add explicit lifetime `{}` to {}" , named, span_label_var) ,
123
- new_ty. to_string ( ) ,
124
- Applicability :: Unspecified ,
125
- ) ;
126
- }
104
+ diag. span_suggestion (
105
+ new_ty_span,
106
+ & format ! ( "add explicit lifetime `{}` to {}" , named, span_label_var) ,
107
+ new_ty. to_string ( ) ,
108
+ Applicability :: Unspecified ,
109
+ ) ;
127
110
128
111
Some ( diag)
129
112
}
0 commit comments