Bless tests.

This commit is contained in:
Camille GILLOT 2021-09-12 13:19:04 +02:00
parent faa7d4221b
commit 659b0a2fd9
5 changed files with 25 additions and 15 deletions

View File

@ -48,7 +48,6 @@ fn main() {
pub struct CompilerCalls; pub struct CompilerCalls;
impl rustc_driver::Callbacks for CompilerCalls { impl rustc_driver::Callbacks for CompilerCalls {
// In this callback we override the mir_borrowck query. // In this callback we override the mir_borrowck query.
fn config(&mut self, config: &mut Config) { fn config(&mut self, config: &mut Config) {
assert!(config.override_queries.is_none()); assert!(config.override_queries.is_none());
@ -64,12 +63,10 @@ fn after_analysis<'tcx>(
) -> Compilation { ) -> Compilation {
compiler.session().abort_if_errors(); compiler.session().abort_if_errors();
queries.global_ctxt().unwrap().peek_mut().enter(|tcx| { queries.global_ctxt().unwrap().peek_mut().enter(|tcx| {
// Collect definition ids of MIR bodies. // Collect definition ids of MIR bodies.
let hir = tcx.hir(); let hir = tcx.hir();
let krate = hir.krate();
let mut visitor = HirVisitor { bodies: Vec::new() }; let mut visitor = HirVisitor { bodies: Vec::new() };
krate.visit_all_item_likes(&mut visitor); hir.visit_all_item_likes(&mut visitor);
// Trigger borrow checking of all bodies. // Trigger borrow checking of all bodies.
for def_id in visitor.bodies { for def_id in visitor.bodies {

View File

@ -13,6 +13,7 @@
use rustc_ast::attr; use rustc_ast::attr;
use rustc_driver::plugin::Registry; use rustc_driver::plugin::Registry;
use rustc_lint::{LateContext, LateLintPass, LintContext, LintPass}; use rustc_lint::{LateContext, LateLintPass, LintContext, LintPass};
use rustc_span::def_id::CRATE_DEF_ID;
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
macro_rules! fake_lint_pass { macro_rules! fake_lint_pass {
@ -26,13 +27,14 @@ fn name(&self) -> &'static str {
} }
impl LateLintPass<'_> for $struct { impl LateLintPass<'_> for $struct {
fn check_crate(&mut self, cx: &LateContext, krate: &rustc_hir::Crate) { fn check_crate(&mut self, cx: &LateContext) {
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);
$( $(
if !cx.sess().contains_name(attrs, $attr) { if !cx.sess().contains_name(attrs, $attr) {
cx.lint(CRATE_NOT_OKAY, |lint| { cx.lint(CRATE_NOT_OKAY, |lint| {
let msg = format!("crate is not marked with #![{}]", $attr); let msg = format!("crate is not marked with #![{}]", $attr);
lint.build(&msg).set_span(krate.module().inner).emit() lint.build(&msg).set_span(span).emit()
}); });
} }
)* )*

View File

@ -8,13 +8,13 @@
extern crate rustc_lint; extern crate rustc_lint;
#[macro_use] #[macro_use]
extern crate rustc_session; extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_ast; extern crate rustc_ast;
extern crate rustc_span;
use rustc_driver::plugin::Registry; use rustc_driver::plugin::Registry;
use rustc_lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_span::def_id::CRATE_DEF_ID;
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
use rustc_ast::attr;
declare_lint! { declare_lint! {
CRATE_NOT_OKAY, CRATE_NOT_OKAY,
@ -25,13 +25,12 @@
declare_lint_pass!(Pass => [CRATE_NOT_OKAY]); declare_lint_pass!(Pass => [CRATE_NOT_OKAY]);
impl<'tcx> LateLintPass<'tcx> for Pass { impl<'tcx> LateLintPass<'tcx> for Pass {
fn check_crate(&mut self, cx: &LateContext, krate: &rustc_hir::Crate) { fn check_crate(&mut self, cx: &LateContext) {
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);
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(CRATE_NOT_OKAY, |lint| {
lint.build("crate is not marked with #![crate_okay]") lint.build("crate is not marked with #![crate_okay]").set_span(span).emit()
.set_span(krate.module().inner)
.emit()
}); });
} }
} }

View File

@ -23,7 +23,13 @@ LL | pub fn foo() {}
error: requires `sized` lang_item error: requires `sized` lang_item
error: aborting due to 3 previous errors error: requires `sized` lang_item
error: requires `sized` lang_item
error: requires `sized` lang_item
error: aborting due to 6 previous errors
Some errors have detailed explanations: E0432, E0603. Some errors have detailed explanations: E0432, E0603.
For more information about an error, try `rustc --explain E0432`. For more information about an error, try `rustc --explain E0432`.

View File

@ -6,6 +6,12 @@ LL | use bar::gpriv;
error: requires `sized` lang_item error: requires `sized` lang_item
error: aborting due to 2 previous errors error: requires `sized` lang_item
error: requires `sized` lang_item
error: requires `sized` lang_item
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0432`. For more information about this error, try `rustc --explain E0432`.