1
Fork 0

ui-fulldeps: adopt to the new rustc lint API

This commit is contained in:
Maybe Waffle 2022-09-22 18:25:05 +04:00
parent b3071153c2
commit d028db9dbd
12 changed files with 44 additions and 40 deletions

View file

@ -917,7 +917,7 @@ pub trait LintContext: Sized {
fn lint( fn lint(
&self, &self,
lint: &'static Lint, lint: &'static Lint,
msg: DiagnosticMessage, msg: impl Into<DiagnosticMessage>,
decorate: impl for<'a, 'b> FnOnce( decorate: impl for<'a, 'b> FnOnce(
&'b mut DiagnosticBuilder<'a, ()>, &'b mut DiagnosticBuilder<'a, ()>,
) -> &'b mut DiagnosticBuilder<'a, ()>, ) -> &'b mut DiagnosticBuilder<'a, ()>,

View file

@ -49,9 +49,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingAllowedAttrPass {
let allowed = |attr| pprust::attribute_to_string(attr).contains("allowed_attr"); let allowed = |attr| pprust::attribute_to_string(attr).contains("allowed_attr");
if !cx.tcx.hir().attrs(item.hir_id()).iter().any(allowed) { if !cx.tcx.hir().attrs(item.hir_id()).iter().any(allowed) {
cx.lint(MISSING_ALLOWED_ATTR, |lint| { cx.lint(
lint.build("Missing 'allowed_attr' attribute").set_span(span).emit(); MISSING_ALLOWED_ATTR,
}); "Missing 'allowed_attr' attribute",
|lint| lint.set_span(span)
);
} }
} }
} }

View file

@ -29,9 +29,11 @@ impl<'tcx> LateLintPass<'tcx> for Pass {
let attrs = cx.tcx.hir().attrs(rustc_hir::CRATE_HIR_ID); let attrs = cx.tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
let span = cx.tcx.def_span(CRATE_DEF_ID); let span = cx.tcx.def_span(CRATE_DEF_ID);
if !cx.sess().contains_name(attrs, Symbol::intern("crate_okay")) { if !cx.sess().contains_name(attrs, Symbol::intern("crate_okay")) {
cx.lint(CRATE_NOT_OKAY, |lint| { cx.lint(
lint.build("crate is not marked with #![crate_okay]").set_span(span).emit(); CRATE_NOT_OKAY,
}); "crate is not marked with #![crate_okay]",
|lint| lint.set_span(span)
);
} }
} }
} }

View file

@ -22,12 +22,10 @@ declare_lint_pass!(Pass => [TEST_LINT, PLEASE_LINT]);
impl<'tcx> LateLintPass<'tcx> for Pass { impl<'tcx> LateLintPass<'tcx> for Pass {
fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) { fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) {
match it.ident.as_str() { match it.ident.as_str() {
"lintme" => cx.lint(TEST_LINT, |lint| { "lintme" => cx.lint(TEST_LINT, "item is named 'lintme'", |lint| lint.set_span(it.span)),
lint.build("item is named 'lintme'").set_span(it.span).emit(); "pleaselintme" => {
}), cx.lint(PLEASE_LINT, "item is named 'pleaselintme'", |lint| lint.set_span(it.span))
"pleaselintme" => cx.lint(PLEASE_LINT, |lint| { }
lint.build("item is named 'pleaselintme'").set_span(it.span).emit();
}),
_ => {} _ => {}
} }
} }

View file

@ -21,9 +21,7 @@ declare_lint_pass!(Pass => [TEST_LINT]);
impl EarlyLintPass for Pass { impl EarlyLintPass for Pass {
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) { fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
if it.ident.name.as_str() == "lintme" { if it.ident.name.as_str() == "lintme" {
cx.lint(TEST_LINT, |lint| { cx.lint(TEST_LINT, "item is named 'lintme'", |lint| lint.set_span(it.span));
lint.build("item is named 'lintme'").set_span(it.span).emit();
});
} }
} }
} }

View file

@ -31,14 +31,10 @@ declare_lint_pass!(Pass => [TEST_LINT, TEST_GROUP, TEST_RUSTC_TOOL_LINT]);
impl EarlyLintPass for Pass { impl EarlyLintPass for Pass {
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) { fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
if it.ident.name.as_str() == "lintme" { if it.ident.name.as_str() == "lintme" {
cx.lint(TEST_LINT, |lint| { cx.lint(TEST_LINT, "item is named 'lintme'", |lint| lint.set_span(it.span));
lint.build("item is named 'lintme'").set_span(it.span).emit();
});
} }
if it.ident.name.as_str() == "lintmetoo" { if it.ident.name.as_str() == "lintmetoo" {
cx.lint(TEST_GROUP, |lint| { cx.lint(TEST_GROUP, "item is named 'lintmetoo'", |lint| lint.set_span(it.span));
lint.build("item is named 'lintmetoo'").set_span(it.span).emit();
});
} }
} }
} }

View file

@ -4,12 +4,12 @@ error: prefer `FxHashMap` over `HashMap`, it has better performance
LL | let _map: HashMap<String, String> = HashMap::default(); LL | let _map: HashMap<String, String> = HashMap::default();
| ^^^^^^^ | ^^^^^^^
| |
= note: a `use rustc_data_structures::fx::FxHashMap` may be necessary
note: the lint level is defined here note: the lint level is defined here
--> $DIR/default_hash_types.rs:4:9 --> $DIR/default_hash_types.rs:4:9
| |
LL | #![deny(rustc::default_hash_types)] 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 error: prefer `FxHashMap` over `HashMap`, it has better performance
--> $DIR/default_hash_types.rs:16:15 --> $DIR/default_hash_types.rs:16:15

View file

@ -4,12 +4,12 @@ error: found non-existing keyword `tadam` used in `#[doc(keyword = \"...\")]`
LL | #[doc(keyword = "tadam")] LL | #[doc(keyword = "tadam")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= help: only existing keywords are allowed in core/std
note: the lint level is defined here note: the lint level is defined here
--> $DIR/existing_doc_keyword.rs:8:9 --> $DIR/existing_doc_keyword.rs:8:9
| |
LL | #![deny(rustc::existing_doc_keyword)] LL | #![deny(rustc::existing_doc_keyword)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: only existing keywords are allowed in core/std
error: aborting due to previous error error: aborting due to previous error

View file

@ -4,12 +4,12 @@ error: implementing `LintPass` by hand
LL | impl LintPass for Foo { LL | impl LintPass for Foo {
| ^^^^^^^^ | ^^^^^^^^
| |
= help: try using `declare_lint_pass!` or `impl_lint_pass!` instead
note: the lint level is defined here note: the lint level is defined here
--> $DIR/lint_pass_impl_without_macro.rs:4:9 --> $DIR/lint_pass_impl_without_macro.rs:4:9
| |
LL | #![deny(rustc::lint_pass_impl_without_macro)] LL | #![deny(rustc::lint_pass_impl_without_macro)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: try using `declare_lint_pass!` or `impl_lint_pass!` instead
error: implementing `LintPass` by hand error: implementing `LintPass` by hand
--> $DIR/lint_pass_impl_without_macro.rs:30:14 --> $DIR/lint_pass_impl_without_macro.rs:30:14

View file

@ -4,12 +4,12 @@ error: using `drain` can result in unstable query results
LL | for _ in x.drain() {} 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 note: the lint level is defined here
--> $DIR/query_stability.rs:4:9 --> $DIR/query_stability.rs:4:9
| |
LL | #![deny(rustc::potential_query_instability)] 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 error: using `iter` can result in unstable query results
--> $DIR/query_stability.rs:16:16 --> $DIR/query_stability.rs:16:16

View file

@ -585,6 +585,7 @@ struct LintAttributeOnSessionDiag {}
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")]
//~^ ERROR `#[lint(...)]` is not a valid attribute //~^ ERROR `#[lint(...)]` is not a valid attribute
//~| ERROR `#[lint(...)]` is not a valid attribute
//~| ERROR diagnostic slug not specified //~| ERROR diagnostic slug not specified
//~| ERROR cannot find attribute `lint` in this scope //~| ERROR cannot find attribute `lint` in this scope
struct LintAttributeOnLintDiag {} struct LintAttributeOnLintDiag {}

View file

@ -440,6 +440,12 @@ error: `#[lint(...)]` is not a valid attribute
LL | #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] 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 error: diagnostic slug not specified
--> $DIR/diagnostic-derive.rs:586:1 --> $DIR/diagnostic-derive.rs:586:1
| |
@ -447,25 +453,26 @@ LL | / #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")]
LL | | LL | |
LL | | LL | |
LL | | LL | |
LL | |
LL | | struct LintAttributeOnLintDiag {} LL | | struct LintAttributeOnLintDiag {}
| |_________________________________^ | |_________________________________^
| |
= help: specify the slug as the first argument to the attribute, such as `#[diag(typeck::example_error)]` = help: specify the slug as the first argument to the attribute, such as `#[diag(typeck::example_error)]`
error: specified multiple times error: specified multiple times
--> $DIR/diagnostic-derive.rs:595:52 --> $DIR/diagnostic-derive.rs:596:52
| |
LL | #[suggestion(typeck::suggestion, code = "...", code = ",,,")] LL | #[suggestion(typeck::suggestion, code = "...", code = ",,,")]
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
| |
note: previously specified here note: previously specified here
--> $DIR/diagnostic-derive.rs:595:38 --> $DIR/diagnostic-derive.rs:596:38
| |
LL | #[suggestion(typeck::suggestion, code = "...", code = ",,,")] LL | #[suggestion(typeck::suggestion, code = "...", code = ",,,")]
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
error: wrong types for suggestion error: wrong types for suggestion
--> $DIR/diagnostic-derive.rs:604:24 --> $DIR/diagnostic-derive.rs:605:24
| |
LL | suggestion: (Span, usize), 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)` = help: `#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)`
error: wrong types for suggestion error: wrong types for suggestion
--> $DIR/diagnostic-derive.rs:612:17 --> $DIR/diagnostic-derive.rs:613:17
| |
LL | suggestion: (Span,), 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)` = help: `#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)`
error: suggestion without `code = "..."` error: suggestion without `code = "..."`
--> $DIR/diagnostic-derive.rs:619:5 --> $DIR/diagnostic-derive.rs:620:5
| |
LL | #[suggestion(typeck::suggestion)] LL | #[suggestion(typeck::suggestion)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: `#[multipart_suggestion(...)]` is not a valid attribute 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)] LL | #[multipart_suggestion(typeck::suggestion)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -495,7 +502,7 @@ LL | #[multipart_suggestion(typeck::suggestion)]
= help: consider creating a `Subdiagnostic` instead = help: consider creating a `Subdiagnostic` instead
error: `#[multipart_suggestion(...)]` is not a valid attribute error: `#[multipart_suggestion(...)]` is not a valid attribute
--> $DIR/diagnostic-derive.rs:629:1 --> $DIR/diagnostic-derive.rs:630:1
| |
LL | #[multipart_suggestion()] LL | #[multipart_suggestion()]
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^
@ -503,7 +510,7 @@ LL | #[multipart_suggestion()]
= help: consider creating a `Subdiagnostic` instead = help: consider creating a `Subdiagnostic` instead
error: `#[multipart_suggestion(...)]` is not a valid attribute 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)] LL | #[multipart_suggestion(typeck::suggestion)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -511,7 +518,7 @@ LL | #[multipart_suggestion(typeck::suggestion)]
= help: consider creating a `Subdiagnostic` instead = help: consider creating a `Subdiagnostic` instead
error: `#[suggestion(...)]` is not a valid attribute error: `#[suggestion(...)]` is not a valid attribute
--> $DIR/diagnostic-derive.rs:641:1 --> $DIR/diagnostic-derive.rs:642:1
| |
LL | #[suggestion(typeck::suggestion, code = "...")] LL | #[suggestion(typeck::suggestion, code = "...")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -519,7 +526,7 @@ LL | #[suggestion(typeck::suggestion, code = "...")]
= help: `#[label]` and `#[suggestion]` can only be applied to fields = help: `#[label]` and `#[suggestion]` can only be applied to fields
error: `#[label]` is not a valid attribute error: `#[label]` is not a valid attribute
--> $DIR/diagnostic-derive.rs:650:1 --> $DIR/diagnostic-derive.rs:651:1
| |
LL | #[label] 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` | ^^^^ help: a built-in attribute with a similar name exists: `link`
error: cannot find attribute `multipart_suggestion` in this scope 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)] LL | #[multipart_suggestion(typeck::suggestion)]
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
error: cannot find attribute `multipart_suggestion` in this scope error: cannot find attribute `multipart_suggestion` in this scope
--> $DIR/diagnostic-derive.rs:629:3 --> $DIR/diagnostic-derive.rs:630:3
| |
LL | #[multipart_suggestion()] LL | #[multipart_suggestion()]
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
error: cannot find attribute `multipart_suggestion` in this scope 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)] LL | #[multipart_suggestion(typeck::suggestion)]
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -600,7 +607,7 @@ LL | arg: impl IntoDiagnosticArg,
| ^^^^^^^^^^^^^^^^^ required by this bound in `DiagnosticBuilder::<'a, G>::set_arg` | ^^^^^^^^^^^^^^^^^ 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) = 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. Some errors have detailed explanations: E0277, E0425.
For more information about an error, try `rustc --explain E0277`. For more information about an error, try `rustc --explain E0277`.