rustc_error: make ErrorReported impossible to construct
There are a few places were we have to construct it, though, and a few places that are more invasive to change. To do this, we create a constructor with a long obvious name.
This commit is contained in:
parent
461e807801
commit
bb8d4307eb
104 changed files with 705 additions and 550 deletions
|
@ -157,7 +157,7 @@ impl BoxPointers {
|
|||
if let GenericArgKind::Type(leaf_ty) = leaf.unpack() {
|
||||
if leaf_ty.is_box() {
|
||||
cx.struct_span_lint(BOX_POINTERS, span, |lint| {
|
||||
lint.build(&format!("type uses owned (Box type) pointers: {}", ty)).emit()
|
||||
lint.build(&format!("type uses owned (Box type) pointers: {}", ty)).emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -318,7 +318,7 @@ impl UnsafeCode {
|
|||
&self,
|
||||
cx: &EarlyContext<'_>,
|
||||
span: Span,
|
||||
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>),
|
||||
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>),
|
||||
) {
|
||||
// This comes from a macro that has `#[allow_internal_unsafe]`.
|
||||
if span.allows_unsafe() {
|
||||
|
@ -350,7 +350,7 @@ impl EarlyLintPass for UnsafeCode {
|
|||
macros using unsafe without triggering \
|
||||
the `unsafe_code` lint at their call site",
|
||||
)
|
||||
.emit()
|
||||
.emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ impl EarlyLintPass for UnsafeCode {
|
|||
// Don't warn about generated blocks; that'll just pollute the output.
|
||||
if blk.rules == ast::BlockCheckMode::Unsafe(ast::UserProvided) {
|
||||
self.report_unsafe(cx, blk.span, |lint| {
|
||||
lint.build("usage of an `unsafe` block").emit()
|
||||
lint.build("usage of an `unsafe` block").emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -370,12 +370,12 @@ impl EarlyLintPass for UnsafeCode {
|
|||
match it.kind {
|
||||
ast::ItemKind::Trait(box ast::Trait { unsafety: ast::Unsafe::Yes(_), .. }) => self
|
||||
.report_unsafe(cx, it.span, |lint| {
|
||||
lint.build("declaration of an `unsafe` trait").emit()
|
||||
lint.build("declaration of an `unsafe` trait").emit();
|
||||
}),
|
||||
|
||||
ast::ItemKind::Impl(box ast::Impl { unsafety: ast::Unsafe::Yes(_), .. }) => self
|
||||
.report_unsafe(cx, it.span, |lint| {
|
||||
lint.build("implementation of an `unsafe` trait").emit()
|
||||
lint.build("implementation of an `unsafe` trait").emit();
|
||||
}),
|
||||
|
||||
ast::ItemKind::Fn(..) => {
|
||||
|
@ -450,7 +450,9 @@ impl EarlyLintPass for UnsafeCode {
|
|||
FnCtxt::Assoc(_) if body.is_none() => "declaration of an `unsafe` method",
|
||||
FnCtxt::Assoc(_) => "implementation of an `unsafe` method",
|
||||
};
|
||||
self.report_unsafe(cx, span, |lint| lint.build(msg).emit());
|
||||
self.report_unsafe(cx, span, |lint| {
|
||||
lint.build(msg).emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -559,7 +561,7 @@ impl MissingDoc {
|
|||
MISSING_DOCS,
|
||||
cx.tcx.sess.source_map().guess_head_span(sp),
|
||||
|lint| {
|
||||
lint.build(&format!("missing documentation for {} {}", article, desc)).emit()
|
||||
lint.build(&format!("missing documentation for {} {}", article, desc)).emit();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -777,7 +779,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
|
|||
"type could implement `Copy`; consider adding `impl \
|
||||
Copy`",
|
||||
)
|
||||
.emit()
|
||||
.emit();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -858,7 +860,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
|
|||
or a manual implementation",
|
||||
cx.tcx.def_path_str(debug)
|
||||
))
|
||||
.emit()
|
||||
.emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1278,7 +1280,9 @@ impl<'tcx> LateLintPass<'tcx> for MutableTransmutes {
|
|||
if to_mt == hir::Mutability::Mut && from_mt == hir::Mutability::Not {
|
||||
let msg = "transmuting &T to &mut T is undefined behavior, \
|
||||
even if the reference is unused, consider instead using an UnsafeCell";
|
||||
cx.struct_span_lint(MUTABLE_TRANSMUTES, expr.span, |lint| lint.build(msg).emit());
|
||||
cx.struct_span_lint(MUTABLE_TRANSMUTES, expr.span, |lint| {
|
||||
lint.build(msg).emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1328,7 +1332,7 @@ impl<'tcx> LateLintPass<'tcx> for UnstableFeatures {
|
|||
if let Some(items) = attr.meta_item_list() {
|
||||
for item in items {
|
||||
cx.struct_span_lint(UNSTABLE_FEATURES, item.span(), |lint| {
|
||||
lint.build("unstable feature").emit()
|
||||
lint.build("unstable feature").emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1680,7 +1684,7 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
|
|||
or lifetime parameters",
|
||||
predicate_kind_name, predicate
|
||||
))
|
||||
.emit()
|
||||
.emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1915,7 +1919,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnameableTestItems {
|
|||
let attrs = cx.tcx.hir().attrs(it.hir_id());
|
||||
if let Some(attr) = cx.sess().find_by_name(attrs, sym::rustc_test_marker) {
|
||||
cx.struct_span_lint(UNNAMEABLE_TEST_ITEMS, attr.span, |lint| {
|
||||
lint.build("cannot test inner items").emit()
|
||||
lint.build("cannot test inner items").emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2040,7 +2044,7 @@ impl KeywordIdents {
|
|||
format!("r#{}", ident),
|
||||
Applicability::MachineApplicable,
|
||||
)
|
||||
.emit()
|
||||
.emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -3055,7 +3059,7 @@ impl<'tcx> LateLintPass<'tcx> for ClashingExternDeclarations {
|
|||
"this signature doesn't match the previous declaration",
|
||||
)
|
||||
.note_expected_found(&"", expected_str, &"", found_str)
|
||||
.emit()
|
||||
.emit();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -593,7 +593,7 @@ pub trait LintContext: Sized {
|
|||
&self,
|
||||
lint: &'static Lint,
|
||||
span: Option<impl Into<MultiSpan>>,
|
||||
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>),
|
||||
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>),
|
||||
diagnostic: BuiltinLintDiagnostics,
|
||||
) {
|
||||
self.lookup(lint, span, |lint| {
|
||||
|
@ -840,19 +840,23 @@ pub trait LintContext: Sized {
|
|||
&self,
|
||||
lint: &'static Lint,
|
||||
span: Option<S>,
|
||||
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>),
|
||||
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>),
|
||||
);
|
||||
|
||||
fn struct_span_lint<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
lint: &'static Lint,
|
||||
span: S,
|
||||
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>),
|
||||
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>),
|
||||
) {
|
||||
self.lookup(lint, Some(span), decorate);
|
||||
}
|
||||
/// Emit a lint at the appropriate level, with no associated span.
|
||||
fn lint(&self, lint: &'static Lint, decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>)) {
|
||||
fn lint(
|
||||
&self,
|
||||
lint: &'static Lint,
|
||||
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>),
|
||||
) {
|
||||
self.lookup(lint, None as Option<Span>, decorate);
|
||||
}
|
||||
}
|
||||
|
@ -893,7 +897,7 @@ impl LintContext for LateContext<'_> {
|
|||
&self,
|
||||
lint: &'static Lint,
|
||||
span: Option<S>,
|
||||
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>),
|
||||
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>),
|
||||
) {
|
||||
let hir_id = self.last_node_with_lint_attrs;
|
||||
|
||||
|
@ -920,7 +924,7 @@ impl LintContext for EarlyContext<'_> {
|
|||
&self,
|
||||
lint: &'static Lint,
|
||||
span: Option<S>,
|
||||
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>),
|
||||
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>),
|
||||
) {
|
||||
self.builder.struct_lint(lint, span.map(|s| s.into()), decorate)
|
||||
}
|
||||
|
|
|
@ -45,7 +45,9 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
|
|||
self.context.lookup_with_diagnostics(
|
||||
lint_id.lint,
|
||||
Some(span),
|
||||
|lint| lint.build(&msg).emit(),
|
||||
|lint| {
|
||||
lint.build(&msg).emit();
|
||||
},
|
||||
diagnostic,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -652,7 +652,7 @@ impl<'s> LintLevelsBuilder<'s> {
|
|||
&self,
|
||||
lint: &'static Lint,
|
||||
span: Option<MultiSpan>,
|
||||
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>),
|
||||
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>),
|
||||
) {
|
||||
let (level, src) = self.lint_level(lint);
|
||||
struct_lint_level(self.sess, lint, level, src, span, decorate)
|
||||
|
|
|
@ -180,13 +180,13 @@ impl EarlyLintPass for NonAsciiIdents {
|
|||
}
|
||||
has_non_ascii_idents = true;
|
||||
cx.struct_span_lint(NON_ASCII_IDENTS, sp, |lint| {
|
||||
lint.build("identifier contains non-ASCII characters").emit()
|
||||
lint.build("identifier contains non-ASCII characters").emit();
|
||||
});
|
||||
if check_uncommon_codepoints
|
||||
&& !symbol_str.chars().all(GeneralSecurityProfile::identifier_allowed)
|
||||
{
|
||||
cx.struct_span_lint(UNCOMMON_CODEPOINTS, sp, |lint| {
|
||||
lint.build("identifier contains uncommon Unicode codepoints").emit()
|
||||
lint.build("identifier contains uncommon Unicode codepoints").emit();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -337,7 +337,7 @@ impl EarlyLintPass for NonAsciiIdents {
|
|||
let char_info = format!("'{}' (U+{:04X})", ch, ch as u32);
|
||||
note += &char_info;
|
||||
}
|
||||
lint.build(&message).note(¬e).note("please recheck to make sure their usages are indeed what you want").emit()
|
||||
lint.build(&message).note(¬e).note("please recheck to make sure their usages are indeed what you want").emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
|
|||
let method = &call.ident.name;
|
||||
let message =
|
||||
format!("call to `.{}()` on a reference in this situation does nothing", &method,);
|
||||
lint.build(&message).span_label(span, "unnecessary method call").note(¬e).emit()
|
||||
lint.build(&message).span_label(span, "unnecessary method call").note(¬e).emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
|
|||
predicate,
|
||||
cx.tcx.def_path_str(needs_drop)
|
||||
);
|
||||
lint.build(&msg).emit()
|
||||
lint.build(&msg).emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
|
|||
instead using `{}` to detect whether a type is trivially dropped",
|
||||
cx.tcx.def_path_str(needs_drop)
|
||||
);
|
||||
lint.build(&msg).emit()
|
||||
lint.build(&msg).emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -441,7 +441,7 @@ fn lint_uint_literal<'tcx>(
|
|||
min,
|
||||
max,
|
||||
))
|
||||
.emit()
|
||||
.emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -502,7 +502,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
|
|||
hir::ExprKind::Binary(binop, ref l, ref r) => {
|
||||
if is_comparison(binop) && !check_limits(cx, binop, &l, &r) {
|
||||
cx.struct_span_lint(UNUSED_COMPARISONS, e.span, |lint| {
|
||||
lint.build("comparison is useless due to type limits").emit()
|
||||
lint.build("comparison is useless due to type limits").emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1382,7 +1382,7 @@ impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences {
|
|||
larger ({} bytes) than the next largest",
|
||||
largest
|
||||
))
|
||||
.emit()
|
||||
.emit();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
|
|||
|
||||
if !(type_permits_lack_of_use || fn_warned || op_warned) {
|
||||
cx.struct_span_lint(UNUSED_RESULTS, s.span, |lint| {
|
||||
lint.build(&format!("unused result of type `{}`", ty)).emit()
|
||||
lint.build(&format!("unused result of type `{}`", ty)).emit();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -368,9 +368,9 @@ impl<'tcx> LateLintPass<'tcx> for PathStatements {
|
|||
} else {
|
||||
lint.span_help(s.span, "use `drop` to clarify the intent");
|
||||
}
|
||||
lint.emit()
|
||||
lint.emit();
|
||||
} else {
|
||||
lint.build("path statement with no effect").emit()
|
||||
lint.build("path statement with no effect").emit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1111,7 +1111,7 @@ impl UnusedImportBraces {
|
|||
};
|
||||
|
||||
cx.struct_span_lint(UNUSED_IMPORT_BRACES, item.span, |lint| {
|
||||
lint.build(&format!("braces around {} is unnecessary", node_name)).emit()
|
||||
lint.build(&format!("braces around {} is unnecessary", node_name)).emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1170,7 +1170,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAllocation {
|
|||
"unnecessary allocation, use `&mut` instead"
|
||||
}
|
||||
};
|
||||
lint.build(msg).emit()
|
||||
lint.build(msg).emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue