Skip to content

Commit

Permalink
Fix stage2 test failures from call to span_lint.
Browse files Browse the repository at this point in the history
span_lint was removed. Callers should use the `lint` method now, and
call `set_span` within the closure passed to this method.
  • Loading branch information
jumbatm committed Feb 11, 2020
1 parent e450996 commit b959da2
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 43 deletions.
34 changes: 19 additions & 15 deletions src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
extern crate rustc_ast_pretty;
extern crate rustc_driver;
extern crate rustc_hir;
#[macro_use] extern crate rustc_lint;
#[macro_use] extern crate rustc_session;
#[macro_use]
extern crate rustc_lint;
#[macro_use]
extern crate rustc_session;
extern crate rustc_span;
extern crate syntax;

use rustc_ast_pretty::pprust;
use rustc_hir::intravisit;
use rustc_driver::plugin::Registry;
use rustc_hir as hir;
use rustc_hir::intravisit;
use rustc_hir::Node;
use rustc_lint::{LateContext, LintPass, LintArray, LateLintPass, LintContext};
use rustc_driver::plugin::Registry;
use rustc_lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc_span::source_map;

#[plugin_registrar]
Expand All @@ -32,23 +34,25 @@ declare_lint! {
declare_lint_pass!(MissingWhitelistedAttrPass => [MISSING_WHITELISTED_ATTR]);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingWhitelistedAttrPass {
fn check_fn(&mut self,
cx: &LateContext<'a, 'tcx>,
_: intravisit::FnKind<'tcx>,
_: &'tcx hir::FnDecl,
_: &'tcx hir::Body,
span: source_map::Span,
id: hir::HirId) {

fn check_fn(
&mut self,
cx: &LateContext<'a, 'tcx>,
_: intravisit::FnKind<'tcx>,
_: &'tcx hir::FnDecl,
_: &'tcx hir::Body,
span: source_map::Span,
id: hir::HirId,
) {
let item = match cx.tcx.hir().get(id) {
Node::Item(item) => item,
_ => cx.tcx.hir().expect_item(cx.tcx.hir().get_parent_item(id)),
};

let whitelisted = |attr| pprust::attribute_to_string(attr).contains("whitelisted_attr");
if !item.attrs.iter().any(whitelisted) {
cx.span_lint(MISSING_WHITELISTED_ATTR, span,
"Missing 'whitelisted_attr' attribute");
cx.lint(MISSING_WHITELISTED_ATTR, |lint| {
lint.build("Missing 'whitelisted_attr' attribute").set_span(span).emit()
});
}
}
}
14 changes: 9 additions & 5 deletions src/test/ui-fulldeps/auxiliary/lint-for-crate-rpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
extern crate rustc_driver;
extern crate rustc_hir;
extern crate rustc_span;
#[macro_use] extern crate rustc_lint;
#[macro_use] extern crate rustc_session;
#[macro_use]
extern crate rustc_lint;
#[macro_use]
extern crate rustc_session;
extern crate syntax;

use rustc_lint::{LateContext, LintContext, LintPass, LateLintPass};
use rustc_driver::plugin::Registry;
use rustc_lint::{LateContext, LateLintPass, LintContext, LintPass};
use rustc_span::symbol::Symbol;
use syntax::attr;

Expand All @@ -28,8 +30,10 @@ macro_rules! fake_lint_pass {
fn check_crate(&mut self, cx: &LateContext, krate: &rustc_hir::Crate) {
$(
if !attr::contains_name(&krate.attrs, $attr) {
cx.span_lint(CRATE_NOT_OKAY, krate.span,
&format!("crate is not marked with #![{}]", $attr));
cx.lint(CRATE_NOT_OKAY, |lint| {
let msg = format!("crate is not marked with #![{}]", $attr);
lint.build(&msg).set_span(krate.span).emit()
});
}
)*
}
Expand Down
15 changes: 10 additions & 5 deletions src/test/ui-fulldeps/auxiliary/lint-for-crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

extern crate rustc_driver;
extern crate rustc_hir;
#[macro_use] extern crate rustc_lint;
#[macro_use] extern crate rustc_session;
#[macro_use]
extern crate rustc_lint;
#[macro_use]
extern crate rustc_session;
extern crate rustc_span;
extern crate syntax;

use rustc_lint::{LateContext, LintContext, LintPass, LateLintPass, LintArray};
use rustc_driver::plugin::Registry;
use rustc_lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc_span::symbol::Symbol;
use syntax::attr;

Expand All @@ -26,8 +28,11 @@ declare_lint_pass!(Pass => [CRATE_NOT_OKAY]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_crate(&mut self, cx: &LateContext, krate: &rustc_hir::Crate) {
if !attr::contains_name(&krate.attrs, Symbol::intern("crate_okay")) {
cx.span_lint(CRATE_NOT_OKAY, krate.span,
"crate is not marked with #![crate_okay]");
cx.lint(CRATE_NOT_OKAY, |lint| {
lint.build("crate is not marked with #![crate_okay]")
.set_span(krate.span)
.emit()
});
}
}
}
Expand Down
24 changes: 17 additions & 7 deletions src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
// Load rustc as a plugin to get macros.
extern crate rustc_driver;
extern crate rustc_hir;
#[macro_use] extern crate rustc_lint;
#[macro_use] extern crate rustc_session;
#[macro_use]
extern crate rustc_lint;
#[macro_use]
extern crate rustc_session;

use rustc_lint::{LateContext, LintContext, LintPass, LateLintPass, LintArray, LintId};
use rustc_driver::plugin::Registry;
use rustc_lint::{LateContext, LateLintPass, LintArray, LintContext, LintId, LintPass};

declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");

Expand All @@ -21,8 +23,12 @@ declare_lint_pass!(Pass => [TEST_LINT, PLEASE_LINT]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) {
match &*it.ident.as_str() {
"lintme" => cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"),
"pleaselintme" => cx.span_lint(PLEASE_LINT, it.span, "item is named 'pleaselintme'"),
"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()
}),
_ => {}
}
}
Expand All @@ -32,6 +38,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
pub fn plugin_registrar(reg: &mut Registry) {
reg.lint_store.register_lints(&[&TEST_LINT, &PLEASE_LINT]);
reg.lint_store.register_late_pass(|| box Pass);
reg.lint_store.register_group(true, "lint_me", None,
vec![LintId::of(&TEST_LINT), LintId::of(&PLEASE_LINT)]);
reg.lint_store.register_group(
true,
"lint_me",
None,
vec![LintId::of(&TEST_LINT), LintId::of(&PLEASE_LINT)],
);
}
12 changes: 8 additions & 4 deletions src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ extern crate syntax;

// Load rustc as a plugin to get macros
extern crate rustc_driver;
#[macro_use] extern crate rustc_lint;
#[macro_use] extern crate rustc_session;
#[macro_use]
extern crate rustc_lint;
#[macro_use]
extern crate rustc_session;

use rustc_lint::{EarlyContext, LintContext, LintPass, EarlyLintPass, LintArray};
use rustc_driver::plugin::Registry;
use rustc_lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
use syntax::ast;
declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");

Expand All @@ -20,7 +22,9 @@ 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.span_lint(TEST_LINT, it.span, "item is named 'lintme'");
cx.lint(TEST_LINT, |lint| {
lint.build("item is named 'lintme'").set_span(it.span).emit()
});
}
}
}
Expand Down
24 changes: 17 additions & 7 deletions src/test/ui-fulldeps/auxiliary/lint-tool-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ extern crate syntax;

// Load rustc as a plugin to get macros
extern crate rustc_driver;
#[macro_use] extern crate rustc_lint;
#[macro_use] extern crate rustc_session;
#[macro_use]
extern crate rustc_lint;
#[macro_use]
extern crate rustc_session;

use rustc_lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass, LintId};
use rustc_driver::plugin::Registry;
use rustc_lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintId, LintPass};
use syntax::ast;
declare_tool_lint!(pub clippy::TEST_LINT, Warn, "Warn about stuff");
declare_tool_lint!(
Expand All @@ -30,10 +32,14 @@ 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.span_lint(TEST_LINT, it.span, "item is named 'lintme'");
cx.lint(TEST_LINT, |lint| {
lint.build("item is named 'lintme'").set_span(it.span).emit()
});
}
if it.ident.name.as_str() == "lintmetoo" {
cx.span_lint(TEST_GROUP, it.span, "item is named 'lintmetoo'");
cx.lint(TEST_GROUP, |lint| {
lint.build("item is named 'lintmetoo'").set_span(it.span).emit()
});
}
}
}
Expand All @@ -42,6 +48,10 @@ impl EarlyLintPass for Pass {
pub fn plugin_registrar(reg: &mut Registry) {
reg.lint_store.register_lints(&[&TEST_RUSTC_TOOL_LINT, &TEST_LINT, &TEST_GROUP]);
reg.lint_store.register_early_pass(|| box Pass);
reg.lint_store.register_group(true, "clippy::group", Some("clippy_group"),
vec![LintId::of(&TEST_LINT), LintId::of(&TEST_GROUP)]);
reg.lint_store.register_group(
true,
"clippy::group",
Some("clippy_group"),
vec![LintId::of(&TEST_LINT), LintId::of(&TEST_GROUP)],
);
}

0 comments on commit b959da2

Please sign in to comment.