Run attributes check at crate level

This commit is contained in:
Guillaume Gomez 2020-09-21 16:37:37 +02:00
parent 0e18017fa3
commit 3950a6d8b6
7 changed files with 305 additions and 298 deletions

View File

@ -13,7 +13,9 @@ use rustc_errors::{pluralize, struct_span_err};
use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::{self, FnSig, ForeignItem, ForeignItemKind, HirId, Item, ItemKind, TraitItem, CRATE_HIR_ID};
use rustc_hir::{
self, FnSig, ForeignItem, ForeignItemKind, HirId, Item, ItemKind, TraitItem, CRATE_HIR_ID,
};
use rustc_hir::{MethodKind, Target};
use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
use rustc_session::parse::feature_err;
@ -823,9 +825,13 @@ fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
tcx.hir()
.visit_item_likes_in_module(module_def_id, &mut CheckAttrVisitor { tcx }.as_deep_visitor());
if module_def_id.is_top_level_module() {
for attr in tcx.hir().krate_attrs() {
CheckAttrVisitor { tcx }.check_doc_alias(attr, CRATE_HIR_ID, Target::Mod);
}
CheckAttrVisitor { tcx }.check_attributes(
CRATE_HIR_ID,
tcx.hir().krate_attrs(),
&tcx.hir().span(CRATE_HIR_ID),
Target::Mod,
None,
);
}
}

View File

@ -7,9 +7,6 @@
// ignore-tidy-linelength
// Crate-level is accepted, though it is almost certainly unused?
#![inline]
#[inline]
//~^ ERROR attribute should be applied to function or closure
mod inline {

View File

@ -1,5 +1,5 @@
error: attribute must be of the form `#[inline]` or `#[inline(always|never)]`
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:22:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:19:5
|
LL | #[inline = "2100"] fn f() { }
| ^^^^^^^^^^^^^^^^^^
@ -9,7 +9,7 @@ LL | #[inline = "2100"] fn f() { }
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
error[E0518]: attribute should be applied to function or closure
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:13:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:10:1
|
LL | #[inline]
| ^^^^^^^^^
@ -24,7 +24,7 @@ LL | | }
| |_- not a function or closure
error: attribute should be applied to an `extern crate` item
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:41:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:38:1
|
LL | #[no_link]
| ^^^^^^^^^^
@ -39,7 +39,7 @@ LL | | }
| |_- not an `extern crate` item
error: attribute should be applied to a function or static
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:67:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:64:1
|
LL | #[export_name = "2200"]
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -54,79 +54,79 @@ LL | | }
| |_- not a function or static
error[E0518]: attribute should be applied to function or closure
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:18:17
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:15:17
|
LL | mod inner { #![inline] }
| ------------^^^^^^^^^^-- not a function or closure
error[E0518]: attribute should be applied to function or closure
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:28:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:25:5
|
LL | #[inline] struct S;
| ^^^^^^^^^ --------- not a function or closure
error[E0518]: attribute should be applied to function or closure
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:32:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:29:5
|
LL | #[inline] type T = S;
| ^^^^^^^^^ ----------- not a function or closure
error[E0518]: attribute should be applied to function or closure
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:36:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:33:5
|
LL | #[inline] impl S { }
| ^^^^^^^^^ ---------- not a function or closure
error: attribute should be applied to an `extern crate` item
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:46:17
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:43:17
|
LL | mod inner { #![no_link] }
| ------------^^^^^^^^^^^-- not an `extern crate` item
error: attribute should be applied to an `extern crate` item
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:50:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:47:5
|
LL | #[no_link] fn f() { }
| ^^^^^^^^^^ ---------- not an `extern crate` item
error: attribute should be applied to an `extern crate` item
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:54:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:51:5
|
LL | #[no_link] struct S;
| ^^^^^^^^^^ --------- not an `extern crate` item
error: attribute should be applied to an `extern crate` item
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:58:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:55:5
|
LL | #[no_link]type T = S;
| ^^^^^^^^^^----------- not an `extern crate` item
error: attribute should be applied to an `extern crate` item
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:62:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:59:5
|
LL | #[no_link] impl S { }
| ^^^^^^^^^^ ---------- not an `extern crate` item
error: attribute should be applied to a function or static
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:72:17
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:69:17
|
LL | mod inner { #![export_name="2200"] }
| ------------^^^^^^^^^^^^^^^^^^^^^^-- not a function or static
error: attribute should be applied to a function or static
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:78:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:75:5
|
LL | #[export_name = "2200"] struct S;
| ^^^^^^^^^^^^^^^^^^^^^^^ --------- not a function or static
error: attribute should be applied to a function or static
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:82:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:79:5
|
LL | #[export_name = "2200"] type T = S;
| ^^^^^^^^^^^^^^^^^^^^^^^ ----------- not a function or static
error: attribute should be applied to a function or static
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:86:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:83:5
|
LL | #[export_name = "2200"] impl S { }
| ^^^^^^^^^^^^^^^^^^^^^^^ ---------- not a function or static

View File

@ -34,6 +34,9 @@
// ignore-tidy-linelength
#![feature(test, plugin_registrar)]
//~^ NOTE not a function
//~^^ NOTE not a foreign function or static
//~^^^ NOTE not a function or static
#![warn(unused_attributes, unknown_lints)]
//~^ NOTE the lint level is defined here
//~| NOTE the lint level is defined here
@ -52,20 +55,8 @@
#![forbid(x5200)] //~ WARN unknown lint: `x5200`
#![deny(x5100)] //~ WARN unknown lint: `x5100`
#![macro_use] // (allowed if no argument; see issue-43160-gating-of-macro_use.rs)
#![macro_export] //~ WARN unused attribute
// skipping testing of cfg
// skipping testing of cfg_attr
#![main] //~ WARN unused attribute
#![start] //~ WARN unused attribute
// see issue-43106-gating-of-test.rs for crate-level; but non crate-level is below at "4200"
// see issue-43106-gating-of-bench.rs for crate-level; but non crate-level is below at "4100"
#![repr()]
//~^ WARN unused attribute
#![path = "3800"] //~ WARN unused attribute
#![automatically_derived] //~ WARN unused attribute
#![no_mangle]
#![no_link] //~ WARN unused attribute
// see issue-43106-gating-of-derive.rs
#![should_panic] //~ WARN unused attribute
#![ignore] //~ WARN unused attribute
#![no_implicit_prelude]
@ -75,12 +66,16 @@
// (cannot easily test gating of crate-level #[no_std]; but non crate-level is below at "2600")
#![proc_macro_derive()] //~ WARN unused attribute
#![doc = "2400"]
#![cold]
#![export_name = "2200"]
#![cold] //~ WARN attribute should be applied to a function
//~^ WARN
// see issue-43106-gating-of-builtin-attrs-error.rs
#![link()]
#![link_name = "1900"]
//~^ WARN attribute should be applied to a foreign function
//~^^ WARN this was previously accepted by the compiler
#![link_section = "1800"]
//~^ WARN attribute should be applied to a function or static
//~^^ WARN this was previously accepted by the compiler
// see issue-43106-gating-of-rustc_deprecated.rs
#![must_use]
// see issue-43106-gating-of-stable.rs

View File

@ -2,7 +2,7 @@
#![feature(try_blocks)]
#![inline(never)]
#[inline(never)]
fn do_something_with<T>(_x: T) {}
// This test checks that borrows made and returned inside try blocks are properly constrained

View File

@ -2,7 +2,7 @@
#![feature(try_blocks)]
#![inline(never)]
#[inline(never)]
fn do_something_with<T>(_x: T) {}
// This test checks that borrows made and returned inside try blocks are properly constrained