Skip to content

Commit 57a0449

Browse files
committed
Make recursive lint into an error for crater
1 parent 5c1ee17 commit 57a0449

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/librustc_lint/unused.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
5050
}
5151

5252
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);
5454

5555
let mut fn_warned = false;
5656
let mut op_warned = false;
@@ -75,7 +75,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
7575
_ => None
7676
};
7777
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);
7979
} else if type_permits_lack_of_use {
8080
// We don't warn about unused unit or uninhabited types.
8181
// (See https://github.com/rust-lang/rust/issues/43806 for details.)
@@ -137,26 +137,27 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
137137
span: Span,
138138
descr_pre: &str,
139139
descr_post: &str,
140-
plural_len: usize,
140+
len: usize,
141+
err: bool, // HACK: Report an error rather than a lint, for crater testing.
141142
) -> bool {
142143
if ty.is_unit() || cx.tcx.is_ty_uninhabited_from(
143144
cx.tcx.hir().get_module_parent(expr.hir_id), ty)
144145
{
145146
return true;
146147
}
147148

148-
let plural_suffix = pluralise!(plural_len);
149+
let plural_suffix = pluralise!(len);
149150

150151
match ty.kind {
151152
ty::Adt(..) if ty.is_box() => {
152153
let boxed_ty = ty.boxed_ty();
153154
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)
155156
}
156157
ty::Adt(def, subst) => {
157158
// Check the type itself for `#[must_use]` annotations.
158159
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);
160161
// Check any fields of the type for `#[must_use]` annotations.
161162
// We ignore ADTs with more than one variant for simplicity and to avoid
162163
// false positives.
@@ -182,7 +183,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
182183
(expr, span)
183184
};
184185
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);
186187
}
187188
}
188189
}
@@ -199,7 +200,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
199200
descr_pre,
200201
plural_suffix,
201202
);
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) {
203204
has_emitted = true;
204205
break;
205206
}
@@ -217,7 +218,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
217218
plural_suffix,
218219
descr_post,
219220
);
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) {
221222
has_emitted = true;
222223
break;
223224
}
@@ -237,7 +238,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
237238
let descr_post = &format!(" in tuple element {}", i);
238239
let span = *spans.get(i).unwrap_or(&span);
239240
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);
241242
}
242243
has_emitted
243244
}
@@ -253,7 +254,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
253254
);
254255
// `2` is just a stand-in for a number greater than 1, for correct plurals
255256
// 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)
257258
}
258259
}
259260
_ => false,
@@ -267,12 +268,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
267268
span: Span,
268269
descr_pre_path: &str,
269270
descr_post_path: &str,
271+
force_err: bool, // HACK: Report an error rather than a lint, for crater testing.
270272
) -> bool {
271273
for attr in cx.tcx.get_attrs(def_id).iter() {
272274
if attr.check_name(sym::must_use) {
273275
let msg = format!("unused {}`{}`{} that must be used",
274276
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+
};
276282
// check for #[must_use = "..."]
277283
if let Some(note) = attr.value_str() {
278284
err.note(&note.as_str());

0 commit comments

Comments
 (0)