diff options
| author | mark <markm@cs.wisc.edu> | 2022-01-22 18:49:12 -0600 |
|---|---|---|
| committer | mark <markm@cs.wisc.edu> | 2022-03-16 10:35:24 -0500 |
| commit | bb8d4307eb723850e98bcb52d71d860a4aba220a (patch) | |
| tree | f3215627c474542776bdbcb03f634651a89b70f8 /compiler/rustc_lint/src | |
| parent | 461e8078010433ff7de2db2aaae8a3cfb0847215 (diff) | |
| download | rust-bb8d4307eb723850e98bcb52d71d860a4aba220a.tar.gz rust-bb8d4307eb723850e98bcb52d71d860a4aba220a.zip | |
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.
Diffstat (limited to 'compiler/rustc_lint/src')
| -rw-r--r-- | compiler/rustc_lint/src/builtin.rs | 36 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/context.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/early.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/levels.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/non_ascii_idents.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/noop_method_call.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/traits.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/types.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/unused.rs | 10 |
9 files changed, 48 insertions, 38 deletions
diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 47de4c9be26..50a3df21a3b 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -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(); }, ); } diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index d3c019ad70e..882fa4496ca 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -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) } diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs index e9b7620bf1d..7447f9f64b7 100644 --- a/compiler/rustc_lint/src/early.rs +++ b/compiler/rustc_lint/src/early.rs @@ -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, ); } diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 0d790e38206..99a5720832e 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -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) diff --git a/compiler/rustc_lint/src/non_ascii_idents.rs b/compiler/rustc_lint/src/non_ascii_idents.rs index 264a80339cc..6182d2b10ed 100644 --- a/compiler/rustc_lint/src/non_ascii_idents.rs +++ b/compiler/rustc_lint/src/non_ascii_idents.rs @@ -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(); }); } } diff --git a/compiler/rustc_lint/src/noop_method_call.rs b/compiler/rustc_lint/src/noop_method_call.rs index 39b5b7afdae..5d734fd2ba7 100644 --- a/compiler/rustc_lint/src/noop_method_call.rs +++ b/compiler/rustc_lint/src/noop_method_call.rs @@ -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(); }); } } diff --git a/compiler/rustc_lint/src/traits.rs b/compiler/rustc_lint/src/traits.rs index 4c7f3482776..5b6997bf0ee 100644 --- a/compiler/rustc_lint/src/traits.rs +++ b/compiler/rustc_lint/src/traits.rs @@ -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(); }); } } diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index ed5578c754d..c95905b9b18 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -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(); }, ); } diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index abe34a8a39f..91b72f1d2b1 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -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(); }); } } |
