From d028db9dbd57da78fec667343571459c41562874 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 22 Sep 2022 18:25:05 +0400 Subject: [PATCH] `ui-fulldeps`: adopt to the new rustc lint API --- compiler/rustc_lint/src/context.rs | 2 +- .../auxiliary/issue-40001-plugin.rs | 8 +++-- .../ui-fulldeps/auxiliary/lint-for-crate.rs | 8 +++-- .../auxiliary/lint-group-plugin-test.rs | 10 +++--- .../ui-fulldeps/auxiliary/lint-plugin-test.rs | 4 +-- .../ui-fulldeps/auxiliary/lint-tool-test.rs | 8 ++--- .../internal-lints/default_hash_types.stderr | 2 +- .../existing_doc_keyword.stderr | 2 +- .../lint_pass_impl_without_macro.stderr | 2 +- .../internal-lints/query_stability.stderr | 2 +- .../session-diagnostic/diagnostic-derive.rs | 1 + .../diagnostic-derive.stderr | 35 +++++++++++-------- 12 files changed, 44 insertions(+), 40 deletions(-) diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 9df6e0f534e..87007728e9d 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -917,7 +917,7 @@ pub trait LintContext: Sized { fn lint( &self, lint: &'static Lint, - msg: DiagnosticMessage, + msg: impl Into, decorate: impl for<'a, 'b> FnOnce( &'b mut DiagnosticBuilder<'a, ()>, ) -> &'b mut DiagnosticBuilder<'a, ()>, diff --git a/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs b/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs index 03da804bd1c..c05443488c3 100644 --- a/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs +++ b/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs @@ -49,9 +49,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingAllowedAttrPass { let allowed = |attr| pprust::attribute_to_string(attr).contains("allowed_attr"); if !cx.tcx.hir().attrs(item.hir_id()).iter().any(allowed) { - cx.lint(MISSING_ALLOWED_ATTR, |lint| { - lint.build("Missing 'allowed_attr' attribute").set_span(span).emit(); - }); + cx.lint( + MISSING_ALLOWED_ATTR, + "Missing 'allowed_attr' attribute", + |lint| lint.set_span(span) + ); } } } diff --git a/src/test/ui-fulldeps/auxiliary/lint-for-crate.rs b/src/test/ui-fulldeps/auxiliary/lint-for-crate.rs index 0b1534939b7..073da688c7c 100644 --- a/src/test/ui-fulldeps/auxiliary/lint-for-crate.rs +++ b/src/test/ui-fulldeps/auxiliary/lint-for-crate.rs @@ -29,9 +29,11 @@ impl<'tcx> LateLintPass<'tcx> for Pass { let attrs = cx.tcx.hir().attrs(rustc_hir::CRATE_HIR_ID); let span = cx.tcx.def_span(CRATE_DEF_ID); if !cx.sess().contains_name(attrs, Symbol::intern("crate_okay")) { - cx.lint(CRATE_NOT_OKAY, |lint| { - lint.build("crate is not marked with #![crate_okay]").set_span(span).emit(); - }); + cx.lint( + CRATE_NOT_OKAY, + "crate is not marked with #![crate_okay]", + |lint| lint.set_span(span) + ); } } } diff --git a/src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs b/src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs index 2d41b5f30e9..4a41e7fbb72 100644 --- a/src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs +++ b/src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs @@ -22,12 +22,10 @@ declare_lint_pass!(Pass => [TEST_LINT, PLEASE_LINT]); impl<'tcx> LateLintPass<'tcx> for Pass { fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) { match it.ident.as_str() { - "lintme" => cx.lint(TEST_LINT, |lint| { - lint.build("item is named 'lintme'").set_span(it.span).emit(); - }), - "pleaselintme" => cx.lint(PLEASE_LINT, |lint| { - lint.build("item is named 'pleaselintme'").set_span(it.span).emit(); - }), + "lintme" => cx.lint(TEST_LINT, "item is named 'lintme'", |lint| lint.set_span(it.span)), + "pleaselintme" => { + cx.lint(PLEASE_LINT, "item is named 'pleaselintme'", |lint| lint.set_span(it.span)) + } _ => {} } } diff --git a/src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs b/src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs index 285754928c2..30956deb799 100644 --- a/src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs +++ b/src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs @@ -21,9 +21,7 @@ declare_lint_pass!(Pass => [TEST_LINT]); impl EarlyLintPass for Pass { fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) { if it.ident.name.as_str() == "lintme" { - cx.lint(TEST_LINT, |lint| { - lint.build("item is named 'lintme'").set_span(it.span).emit(); - }); + cx.lint(TEST_LINT, "item is named 'lintme'", |lint| lint.set_span(it.span)); } } } diff --git a/src/test/ui-fulldeps/auxiliary/lint-tool-test.rs b/src/test/ui-fulldeps/auxiliary/lint-tool-test.rs index 3d5dba42b5f..c2c024865e8 100644 --- a/src/test/ui-fulldeps/auxiliary/lint-tool-test.rs +++ b/src/test/ui-fulldeps/auxiliary/lint-tool-test.rs @@ -31,14 +31,10 @@ declare_lint_pass!(Pass => [TEST_LINT, TEST_GROUP, TEST_RUSTC_TOOL_LINT]); impl EarlyLintPass for Pass { fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) { if it.ident.name.as_str() == "lintme" { - cx.lint(TEST_LINT, |lint| { - lint.build("item is named 'lintme'").set_span(it.span).emit(); - }); + cx.lint(TEST_LINT, "item is named 'lintme'", |lint| lint.set_span(it.span)); } if it.ident.name.as_str() == "lintmetoo" { - cx.lint(TEST_GROUP, |lint| { - lint.build("item is named 'lintmetoo'").set_span(it.span).emit(); - }); + cx.lint(TEST_GROUP, "item is named 'lintmetoo'", |lint| lint.set_span(it.span)); } } } diff --git a/src/test/ui-fulldeps/internal-lints/default_hash_types.stderr b/src/test/ui-fulldeps/internal-lints/default_hash_types.stderr index 9d13ee89bca..3cb13082f25 100644 --- a/src/test/ui-fulldeps/internal-lints/default_hash_types.stderr +++ b/src/test/ui-fulldeps/internal-lints/default_hash_types.stderr @@ -4,12 +4,12 @@ error: prefer `FxHashMap` over `HashMap`, it has better performance LL | let _map: HashMap = HashMap::default(); | ^^^^^^^ | + = note: a `use rustc_data_structures::fx::FxHashMap` may be necessary note: the lint level is defined here --> $DIR/default_hash_types.rs:4:9 | LL | #![deny(rustc::default_hash_types)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: a `use rustc_data_structures::fx::FxHashMap` may be necessary error: prefer `FxHashMap` over `HashMap`, it has better performance --> $DIR/default_hash_types.rs:16:15 diff --git a/src/test/ui-fulldeps/internal-lints/existing_doc_keyword.stderr b/src/test/ui-fulldeps/internal-lints/existing_doc_keyword.stderr index bc9fcdd7bc7..4e296fff6d0 100644 --- a/src/test/ui-fulldeps/internal-lints/existing_doc_keyword.stderr +++ b/src/test/ui-fulldeps/internal-lints/existing_doc_keyword.stderr @@ -4,12 +4,12 @@ error: found non-existing keyword `tadam` used in `#[doc(keyword = \"...\")]` LL | #[doc(keyword = "tadam")] | ^^^^^^^^^^^^^^^^^^^^^^^^^ | + = help: only existing keywords are allowed in core/std note: the lint level is defined here --> $DIR/existing_doc_keyword.rs:8:9 | LL | #![deny(rustc::existing_doc_keyword)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: only existing keywords are allowed in core/std error: aborting due to previous error diff --git a/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr index 9df6be65eb3..ad6e93334cd 100644 --- a/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr +++ b/src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr @@ -4,12 +4,12 @@ error: implementing `LintPass` by hand LL | impl LintPass for Foo { | ^^^^^^^^ | + = help: try using `declare_lint_pass!` or `impl_lint_pass!` instead note: the lint level is defined here --> $DIR/lint_pass_impl_without_macro.rs:4:9 | LL | #![deny(rustc::lint_pass_impl_without_macro)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = help: try using `declare_lint_pass!` or `impl_lint_pass!` instead error: implementing `LintPass` by hand --> $DIR/lint_pass_impl_without_macro.rs:30:14 diff --git a/src/test/ui-fulldeps/internal-lints/query_stability.stderr b/src/test/ui-fulldeps/internal-lints/query_stability.stderr index 7e8b448f41a..ee4ef998237 100644 --- a/src/test/ui-fulldeps/internal-lints/query_stability.stderr +++ b/src/test/ui-fulldeps/internal-lints/query_stability.stderr @@ -4,12 +4,12 @@ error: using `drain` can result in unstable query results LL | for _ in x.drain() {} | ^^^^^ | + = note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale note: the lint level is defined here --> $DIR/query_stability.rs:4:9 | LL | #![deny(rustc::potential_query_instability)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale error: using `iter` can result in unstable query results --> $DIR/query_stability.rs:16:16 diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs index 3d363cae473..d425f6f34e9 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs @@ -585,6 +585,7 @@ struct LintAttributeOnSessionDiag {} #[derive(LintDiagnostic)] #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] //~^ ERROR `#[lint(...)]` is not a valid attribute +//~| ERROR `#[lint(...)]` is not a valid attribute //~| ERROR diagnostic slug not specified //~| ERROR cannot find attribute `lint` in this scope struct LintAttributeOnLintDiag {} diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr index 21a402c7b9d..17bab3a1d65 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr @@ -440,6 +440,12 @@ error: `#[lint(...)]` is not a valid attribute LL | #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +error: `#[lint(...)]` is not a valid attribute + --> $DIR/diagnostic-derive.rs:586:1 + | +LL | #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: diagnostic slug not specified --> $DIR/diagnostic-derive.rs:586:1 | @@ -447,25 +453,26 @@ LL | / #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] LL | | LL | | LL | | +LL | | LL | | struct LintAttributeOnLintDiag {} | |_________________________________^ | = help: specify the slug as the first argument to the attribute, such as `#[diag(typeck::example_error)]` error: specified multiple times - --> $DIR/diagnostic-derive.rs:595:52 + --> $DIR/diagnostic-derive.rs:596:52 | LL | #[suggestion(typeck::suggestion, code = "...", code = ",,,")] | ^^^^^^^^^^^^ | note: previously specified here - --> $DIR/diagnostic-derive.rs:595:38 + --> $DIR/diagnostic-derive.rs:596:38 | LL | #[suggestion(typeck::suggestion, code = "...", code = ",,,")] | ^^^^^^^^^^^^ error: wrong types for suggestion - --> $DIR/diagnostic-derive.rs:604:24 + --> $DIR/diagnostic-derive.rs:605:24 | LL | suggestion: (Span, usize), | ^^^^^ @@ -473,7 +480,7 @@ LL | suggestion: (Span, usize), = help: `#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)` error: wrong types for suggestion - --> $DIR/diagnostic-derive.rs:612:17 + --> $DIR/diagnostic-derive.rs:613:17 | LL | suggestion: (Span,), | ^^^^^^^ @@ -481,13 +488,13 @@ LL | suggestion: (Span,), = help: `#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)` error: suggestion without `code = "..."` - --> $DIR/diagnostic-derive.rs:619:5 + --> $DIR/diagnostic-derive.rs:620:5 | LL | #[suggestion(typeck::suggestion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `#[multipart_suggestion(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:626:1 + --> $DIR/diagnostic-derive.rs:627:1 | LL | #[multipart_suggestion(typeck::suggestion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -495,7 +502,7 @@ LL | #[multipart_suggestion(typeck::suggestion)] = help: consider creating a `Subdiagnostic` instead error: `#[multipart_suggestion(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:629:1 + --> $DIR/diagnostic-derive.rs:630:1 | LL | #[multipart_suggestion()] | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -503,7 +510,7 @@ LL | #[multipart_suggestion()] = help: consider creating a `Subdiagnostic` instead error: `#[multipart_suggestion(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:633:5 + --> $DIR/diagnostic-derive.rs:634:5 | LL | #[multipart_suggestion(typeck::suggestion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -511,7 +518,7 @@ LL | #[multipart_suggestion(typeck::suggestion)] = help: consider creating a `Subdiagnostic` instead error: `#[suggestion(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:641:1 + --> $DIR/diagnostic-derive.rs:642:1 | LL | #[suggestion(typeck::suggestion, code = "...")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -519,7 +526,7 @@ LL | #[suggestion(typeck::suggestion, code = "...")] = help: `#[label]` and `#[suggestion]` can only be applied to fields error: `#[label]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:650:1 + --> $DIR/diagnostic-derive.rs:651:1 | LL | #[label] | ^^^^^^^^ @@ -563,19 +570,19 @@ LL | #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] | ^^^^ help: a built-in attribute with a similar name exists: `link` error: cannot find attribute `multipart_suggestion` in this scope - --> $DIR/diagnostic-derive.rs:626:3 + --> $DIR/diagnostic-derive.rs:627:3 | LL | #[multipart_suggestion(typeck::suggestion)] | ^^^^^^^^^^^^^^^^^^^^ error: cannot find attribute `multipart_suggestion` in this scope - --> $DIR/diagnostic-derive.rs:629:3 + --> $DIR/diagnostic-derive.rs:630:3 | LL | #[multipart_suggestion()] | ^^^^^^^^^^^^^^^^^^^^ error: cannot find attribute `multipart_suggestion` in this scope - --> $DIR/diagnostic-derive.rs:633:7 + --> $DIR/diagnostic-derive.rs:634:7 | LL | #[multipart_suggestion(typeck::suggestion)] | ^^^^^^^^^^^^^^^^^^^^ @@ -600,7 +607,7 @@ LL | arg: impl IntoDiagnosticArg, | ^^^^^^^^^^^^^^^^^ required by this bound in `DiagnosticBuilder::<'a, G>::set_arg` = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 74 previous errors +error: aborting due to 75 previous errors Some errors have detailed explanations: E0277, E0425. For more information about an error, try `rustc --explain E0277`.