-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #11811 - y21:avoid_cx_struct_span_lint, r=Manishearth
disallow calls to `LintContext::struct_span_lint` and `TyCtxt::struct_span_lint_hir` `LintContext::struct_span_lint` and `TyCtxt::struct_span_lint_hir` don't show the link to the clippy documentation, see: #11805 In #11810, the last few calls to those methods were replaced with `span_lint_*`. It seems like we should just disallow them altogether so that no new code tries to use them. The existing `disallowed_methods` lint makes this easy. changelog: none
- Loading branch information
Showing
4 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
avoid-breaking-exported-api = false | ||
|
||
# use the various `span_lint_*` methods instead, which also add a link to the docs | ||
disallowed-methods = [ | ||
"rustc_lint::context::LintContext::struct_span_lint", | ||
"rustc_middle::ty::context::TyCtxt::struct_span_lint_hir" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#![feature(rustc_private)] | ||
|
||
extern crate rustc_errors; | ||
extern crate rustc_hir; | ||
extern crate rustc_lint; | ||
extern crate rustc_middle; | ||
|
||
use rustc_errors::{DiagnosticMessage, MultiSpan}; | ||
use rustc_hir::hir_id::HirId; | ||
use rustc_lint::{Lint, LintContext}; | ||
use rustc_middle::ty::TyCtxt; | ||
|
||
pub fn a(cx: impl LintContext, lint: &'static Lint, span: impl Into<MultiSpan>, msg: impl Into<DiagnosticMessage>) { | ||
cx.struct_span_lint(lint, span, msg, |b| b); | ||
} | ||
|
||
pub fn b( | ||
tcx: TyCtxt<'_>, | ||
lint: &'static Lint, | ||
hir_id: HirId, | ||
span: impl Into<MultiSpan>, | ||
msg: impl Into<DiagnosticMessage>, | ||
) { | ||
tcx.struct_span_lint_hir(lint, hir_id, span, msg, |b| b); | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error: use of a disallowed method `rustc_lint::context::LintContext::struct_span_lint` | ||
--> $DIR/disallow_struct_span_lint.rs:14:5 | ||
| | ||
LL | cx.struct_span_lint(lint, span, msg, |b| b); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::disallowed-methods` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::disallowed_methods)]` | ||
|
||
error: use of a disallowed method `rustc_middle::ty::context::TyCtxt::struct_span_lint_hir` | ||
--> $DIR/disallow_struct_span_lint.rs:24:5 | ||
| | ||
LL | tcx.struct_span_lint_hir(lint, hir_id, span, msg, |b| b); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|