@@ -65,13 +65,25 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
65
65
true
66
66
} else {
67
67
match t. sty {
68
- ty:: Adt ( def, _) => check_must_use ( cx, def. did , s. span , "" ) ,
68
+ ty:: Adt ( def, _) => check_must_use ( cx, def. did , s. span , "" , "" ) ,
69
69
ty:: Opaque ( def, _) => {
70
70
let mut must_use = false ;
71
71
for ( predicate, _) in cx. tcx . predicates_of ( def) . predicates {
72
72
if let ty:: Predicate :: Trait ( ref poly_trait_predicate) = predicate {
73
73
let trait_ref = poly_trait_predicate. skip_binder ( ) . trait_ref ;
74
- if check_must_use ( cx, trait_ref. def_id , s. span , "implementer of " ) {
74
+ if check_must_use ( cx, trait_ref. def_id , s. span , "implementer of " , "" ) {
75
+ must_use = true ;
76
+ break ;
77
+ }
78
+ }
79
+ }
80
+ must_use
81
+ }
82
+ ty:: Dynamic ( binder, _) => {
83
+ let mut must_use = false ;
84
+ for predicate in binder. skip_binder ( ) . iter ( ) {
85
+ if let ty:: ExistentialPredicate :: Trait ( ref trait_ref) = predicate {
86
+ if check_must_use ( cx, trait_ref. def_id , s. span , "" , " trait object" ) {
75
87
must_use = true ;
76
88
break ;
77
89
}
@@ -107,7 +119,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
107
119
} ;
108
120
if let Some ( def) = maybe_def {
109
121
let def_id = def. def_id ( ) ;
110
- fn_warned = check_must_use ( cx, def_id, s. span , "return value of " ) ;
122
+ fn_warned = check_must_use ( cx, def_id, s. span , "return value of " , "" ) ;
111
123
} else if type_permits_lack_of_use {
112
124
// We don't warn about unused unit or uninhabited types.
113
125
// (See https://github.com/rust-lang/rust/issues/43806 for details.)
@@ -161,11 +173,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
161
173
cx. span_lint ( UNUSED_RESULTS , s. span , "unused result" ) ;
162
174
}
163
175
164
- fn check_must_use ( cx : & LateContext , def_id : DefId , sp : Span , describe_path : & str ) -> bool {
176
+ fn check_must_use (
177
+ cx : & LateContext ,
178
+ def_id : DefId ,
179
+ sp : Span ,
180
+ descr_pre_path : & str ,
181
+ descr_post_path : & str ,
182
+ ) -> bool {
165
183
for attr in cx. tcx . get_attrs ( def_id) . iter ( ) {
166
184
if attr. check_name ( "must_use" ) {
167
- let msg = format ! ( "unused {}`{}` that must be used" ,
168
- describe_path , cx. tcx. item_path_str( def_id) ) ;
185
+ let msg = format ! ( "unused {}`{}`{} that must be used" ,
186
+ descr_pre_path , descr_post_path , cx. tcx. item_path_str( def_id) ) ;
169
187
let mut err = cx. struct_span_lint ( UNUSED_MUST_USE , sp, & msg) ;
170
188
// check for #[must_use = "..."]
171
189
if let Some ( note) = attr. value_str ( ) {
0 commit comments