@@ -50,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
50
50
}
51
51
52
52
let ty = cx. tables . expr_ty ( & expr) ;
53
- let type_permits_lack_of_use = check_must_use_ty ( cx, ty, & expr, s. span , "" , "" , 1 ) ;
53
+ let type_permits_lack_of_use = check_must_use_ty ( cx, ty, & expr, s. span , "" , "" , 1 , false ) ;
54
54
55
55
let mut fn_warned = false ;
56
56
let mut op_warned = false ;
@@ -75,7 +75,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
75
75
_ => None
76
76
} ;
77
77
if let Some ( def_id) = maybe_def_id {
78
- fn_warned = check_must_use_def ( cx, def_id, s. span , "return value of " , "" ) ;
78
+ fn_warned = check_must_use_def ( cx, def_id, s. span , "return value of " , "" , false ) ;
79
79
} else if type_permits_lack_of_use {
80
80
// We don't warn about unused unit or uninhabited types.
81
81
// (See https://github.com/rust-lang/rust/issues/43806 for details.)
@@ -137,26 +137,27 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
137
137
span : Span ,
138
138
descr_pre : & str ,
139
139
descr_post : & str ,
140
- plural_len : usize ,
140
+ len : usize ,
141
+ err : bool , // HACK: Report an error rather than a lint, for crater testing.
141
142
) -> bool {
142
143
if ty. is_unit ( ) || cx. tcx . is_ty_uninhabited_from (
143
144
cx. tcx . hir ( ) . get_module_parent ( expr. hir_id ) , ty)
144
145
{
145
146
return true ;
146
147
}
147
148
148
- let plural_suffix = pluralise ! ( plural_len ) ;
149
+ let plural_suffix = pluralise ! ( len ) ;
149
150
150
151
match ty. kind {
151
152
ty:: Adt ( ..) if ty. is_box ( ) => {
152
153
let boxed_ty = ty. boxed_ty ( ) ;
153
154
let descr_pre = & format ! ( "{}boxed " , descr_pre) ;
154
- check_must_use_ty ( cx, boxed_ty, expr, span, descr_pre, descr_post, plural_len )
155
+ check_must_use_ty ( cx, boxed_ty, expr, span, descr_pre, descr_post, len , err )
155
156
}
156
157
ty:: Adt ( def, subst) => {
157
158
// Check the type itself for `#[must_use]` annotations.
158
159
let mut has_emitted = check_must_use_def (
159
- cx, def. did , span, descr_pre, descr_post) ;
160
+ cx, def. did , span, descr_pre, descr_post, err ) ;
160
161
// Check any fields of the type for `#[must_use]` annotations.
161
162
// We ignore ADTs with more than one variant for simplicity and to avoid
162
163
// false positives.
@@ -182,7 +183,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
182
183
( expr, span)
183
184
} ;
184
185
has_emitted |= check_must_use_ty (
185
- cx, ty, expr, span, descr_pre, descr_post, plural_len ) ;
186
+ cx, ty, expr, span, descr_pre, descr_post, len , true ) ;
186
187
}
187
188
}
188
189
}
@@ -199,7 +200,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
199
200
descr_pre,
200
201
plural_suffix,
201
202
) ;
202
- if check_must_use_def ( cx, def_id, span, descr_pre, descr_post) {
203
+ if check_must_use_def ( cx, def_id, span, descr_pre, descr_post, err ) {
203
204
has_emitted = true ;
204
205
break ;
205
206
}
@@ -217,7 +218,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
217
218
plural_suffix,
218
219
descr_post,
219
220
) ;
220
- if check_must_use_def ( cx, def_id, span, descr_pre, descr_post) {
221
+ if check_must_use_def ( cx, def_id, span, descr_pre, descr_post, err ) {
221
222
has_emitted = true ;
222
223
break ;
223
224
}
@@ -237,7 +238,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
237
238
let descr_post = & format ! ( " in tuple element {}" , i) ;
238
239
let span = * spans. get ( i) . unwrap_or ( & span) ;
239
240
has_emitted |= check_must_use_ty (
240
- cx, ty, expr, span, descr_pre, descr_post, plural_len ) ;
241
+ cx, ty, expr, span, descr_pre, descr_post, len , err ) ;
241
242
}
242
243
has_emitted
243
244
}
@@ -253,7 +254,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
253
254
) ;
254
255
// `2` is just a stand-in for a number greater than 1, for correct plurals
255
256
// in diagnostics.
256
- check_must_use_ty ( cx, ty, expr, span, descr_pre, descr_post, 2 )
257
+ check_must_use_ty ( cx, ty, expr, span, descr_pre, descr_post, 2 , err )
257
258
}
258
259
}
259
260
_ => false ,
@@ -267,12 +268,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
267
268
span : Span ,
268
269
descr_pre_path : & str ,
269
270
descr_post_path : & str ,
271
+ force_err : bool , // HACK: Report an error rather than a lint, for crater testing.
270
272
) -> bool {
271
273
for attr in cx. tcx . get_attrs ( def_id) . iter ( ) {
272
274
if attr. check_name ( sym:: must_use) {
273
275
let msg = format ! ( "unused {}`{}`{} that must be used" ,
274
276
descr_pre_path, cx. tcx. def_path_str( def_id) , descr_post_path) ;
275
- let mut err = cx. struct_span_lint ( UNUSED_MUST_USE , span, & msg) ;
277
+ let mut err = if !force_err {
278
+ cx. struct_span_lint ( UNUSED_MUST_USE , span, & msg)
279
+ } else {
280
+ cx. sess ( ) . struct_span_err ( span, & msg)
281
+ } ;
276
282
// check for #[must_use = "..."]
277
283
if let Some ( note) = attr. value_str ( ) {
278
284
err. note ( & note. as_str ( ) ) ;
0 commit comments