1
Fork 0

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 as hir;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; 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_hir::{MethodKind, Target};
use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES}; use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
use rustc_session::parse::feature_err; use rustc_session::parse::feature_err;
@ -823,9 +825,13 @@ fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
tcx.hir() tcx.hir()
.visit_item_likes_in_module(module_def_id, &mut CheckAttrVisitor { tcx }.as_deep_visitor()); .visit_item_likes_in_module(module_def_id, &mut CheckAttrVisitor { tcx }.as_deep_visitor());
if module_def_id.is_top_level_module() { if module_def_id.is_top_level_module() {
for attr in tcx.hir().krate_attrs() { CheckAttrVisitor { tcx }.check_attributes(
CheckAttrVisitor { tcx }.check_doc_alias(attr, CRATE_HIR_ID, Target::Mod); 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 // ignore-tidy-linelength
// Crate-level is accepted, though it is almost certainly unused?
#![inline]
#[inline] #[inline]
//~^ ERROR attribute should be applied to function or closure //~^ ERROR attribute should be applied to function or closure
mod inline { mod inline {

View file

@ -1,5 +1,5 @@
error: attribute must be of the form `#[inline]` or `#[inline(always|never)]` 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() { } 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> = 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 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] LL | #[inline]
| ^^^^^^^^^ | ^^^^^^^^^
@ -24,7 +24,7 @@ LL | | }
| |_- not a function or closure | |_- not a function or closure
error: attribute should be applied to an `extern crate` item 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] LL | #[no_link]
| ^^^^^^^^^^ | ^^^^^^^^^^
@ -39,7 +39,7 @@ LL | | }
| |_- not an `extern crate` item | |_- not an `extern crate` item
error: attribute should be applied to a function or static 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"] LL | #[export_name = "2200"]
| ^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^
@ -54,79 +54,79 @@ LL | | }
| |_- not a function or static | |_- not a function or static
error[E0518]: attribute should be applied to function or closure 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] } LL | mod inner { #![inline] }
| ------------^^^^^^^^^^-- not a function or closure | ------------^^^^^^^^^^-- not a function or closure
error[E0518]: attribute should be applied to 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; LL | #[inline] struct S;
| ^^^^^^^^^ --------- not a function or closure | ^^^^^^^^^ --------- not a function or closure
error[E0518]: attribute should be applied to 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; LL | #[inline] type T = S;
| ^^^^^^^^^ ----------- not a function or closure | ^^^^^^^^^ ----------- not a function or closure
error[E0518]: attribute should be applied to 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 { } LL | #[inline] impl S { }
| ^^^^^^^^^ ---------- not a function or closure | ^^^^^^^^^ ---------- not a function or closure
error: attribute should be applied to an `extern crate` item 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] } LL | mod inner { #![no_link] }
| ------------^^^^^^^^^^^-- not an `extern crate` item | ------------^^^^^^^^^^^-- not an `extern crate` item
error: attribute should be applied to 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() { } LL | #[no_link] fn f() { }
| ^^^^^^^^^^ ---------- not an `extern crate` item | ^^^^^^^^^^ ---------- not an `extern crate` item
error: attribute should be applied to 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; LL | #[no_link] struct S;
| ^^^^^^^^^^ --------- not an `extern crate` item | ^^^^^^^^^^ --------- not an `extern crate` item
error: attribute should be applied to 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; LL | #[no_link]type T = S;
| ^^^^^^^^^^----------- not an `extern crate` item | ^^^^^^^^^^----------- not an `extern crate` item
error: attribute should be applied to 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 { } LL | #[no_link] impl S { }
| ^^^^^^^^^^ ---------- not an `extern crate` item | ^^^^^^^^^^ ---------- not an `extern crate` item
error: attribute should be applied to a function or static 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"] } LL | mod inner { #![export_name="2200"] }
| ------------^^^^^^^^^^^^^^^^^^^^^^-- not a function or static | ------------^^^^^^^^^^^^^^^^^^^^^^-- not a function or static
error: attribute should be applied to 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; LL | #[export_name = "2200"] struct S;
| ^^^^^^^^^^^^^^^^^^^^^^^ --------- not a function or static | ^^^^^^^^^^^^^^^^^^^^^^^ --------- not a function or static
error: attribute should be applied to 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; LL | #[export_name = "2200"] type T = S;
| ^^^^^^^^^^^^^^^^^^^^^^^ ----------- not a function or static | ^^^^^^^^^^^^^^^^^^^^^^^ ----------- not a function or static
error: attribute should be applied to 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 { } LL | #[export_name = "2200"] impl S { }
| ^^^^^^^^^^^^^^^^^^^^^^^ ---------- not a function or static | ^^^^^^^^^^^^^^^^^^^^^^^ ---------- not a function or static

View file

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

View file

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

View file

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