提交 88e2c396 编写于 作者: B bors

Auto merge of #43168 - pnkfelix:check-attr-gating, r=aturon

Slew of builtin-attribute gating tests

Slew of builtin-attribute "gating" tests for issue #43106.

Some stray observations:

 * I don't know if its a good thing that so many attributes allow inputs which are silently discarded. (I  made heavy use of that in writing my tests, but that was more out of curiosity than necessity.)
 * The difference between crate-level and non-crate-level behavior is quite significant in some cases. Definitely worth making sure one has tests for both cases. (Not as clear whether it was worthwhile trying the various other AST forms like `fn f()` vs `struct S;`)
 * `#[no_builtins]` and `#[no_mangle]` occur twice on the `BUILTIN_ATTRIBUTES` list. Thats almost certainly a bug. (Filed as #43148)
 * We are maximally liberal in what we allow for `#[test]` and `#[bench]` when one compiles without `--test`.
 * We allow `#[no_mangle]` on arbitrary AST nodes, but only warn about potential misuse on `fn`
 * We allow `#[cold]`, `#[must_use]`, `#[windows_subsystem]`, and `#[no_builtins]` on arbitrary AST nodes. I don't know off-hand what the semantics are for e.g. a `#[cold] type T = ...;`
 * We allow crate-level `#![inline]`. That's probably a bug since its otherwise restricted to `fn` items
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: main function not found
// At time of authorship, a crate-level #![bench] with no `--test`
// will cause compilation to error unconditionally with "main function
// not found" (despite having one), similar to #[bench].
//
// (The non-crate level cases are in
// issue-43106-gating-of-builtin-attrs.rs.)
// See issue-12997-1.rs and issue-12997-2.rs to see how `#[bench]` is
// handled in "weird places" when `--test` is passed.
#![bench = "4100"]
fn main() { }
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// This test just shows that a crate-level `#![deprecated]` does not
// signal a warning or error. (This file sits on its own because a
// crate-level `#![deprecated]` causes all that crate's item
// definitions to be deprecated, which is a pain to work with.)
//
// (For non-crate-level cases, see issue-43106-gating-of-builtin-attrs.rs)
#![feature(rustc_attrs)] // For `rustc_error`; see note below.
#![allow(dead_code)]
#![deprecated = "1100"]
// Since we expect for the mix of attributes used here to compile
// successfully, and we are just testing for the expected warnings of
// various (mis)uses of attributes, we use the `rustc_error` attribute
// on the `fn main()`.
#[rustc_error]
fn main() { //~ ERROR compilation successful
println!("Hello World");
}
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// `#![derive]` is interpreted (and raises errors) when it occurs at
// contexts other than ADT definitions. This test checks cases where
// the derive-macro does not exist.
#![derive(x3300)]
//~^ ERROR cannot find derive macro `x3300` in this scope
#[derive(x3300)]
//~^ ERROR cannot find derive macro `x3300` in this scope
mod derive {
mod inner { #![derive(x3300)] }
//~^ ERROR cannot find derive macro `x3300` in this scope
#[derive(x3300)]
//~^ ERROR cannot find derive macro `x3300` in this scope
fn derive() { }
#[derive(x3300)]
//~^ ERROR cannot find derive macro `x3300` in this scope
union U { f: i32 }
#[derive(x3300)]
//~^ ERROR cannot find derive macro `x3300` in this scope
enum E { }
#[derive(x3300)]
//~^ ERROR cannot find derive macro `x3300` in this scope
struct S;
#[derive(x3300)]
//~^ ERROR cannot find derive macro `x3300` in this scope
type T = S;
#[derive(x3300)]
//~^ ERROR cannot find derive macro `x3300` in this scope
impl S { }
}
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// `#![derive]` is interpreted (and raises errors) when it occurs at
// contexts other than ADT definitions. This test checks cases where
// the derive-macro exists.
#![derive(Debug)]
//~^ ERROR `derive` may only be applied to structs, enums and unions
#[derive(Debug)]
//~^ ERROR `derive` may only be applied to structs, enums and unions
mod derive {
mod inner { #![derive(Debug)] }
//~^ ERROR `derive` may only be applied to structs, enums and unions
#[derive(Debug)]
//~^ ERROR `derive` may only be applied to structs, enums and unions
fn derive() { }
#[derive(Copy, Clone)] // (can't derive Debug for unions)
union U { f: i32 }
#[derive(Debug)]
struct S;
#[derive(Debug)]
enum E { }
#[derive(Debug)]
//~^ ERROR `derive` may only be applied to structs, enums and unions
type T = S;
#[derive(Debug)]
//~^ ERROR `derive` may only be applied to structs, enums and unions
impl S { }
}
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// This is testing whether `#[inline]` signals an error or warning
// when put in "weird" places.
//
// (This file sits on its own because it actually signals an error,
// which would mess up the treatment of other cases in
// issue-43106-gating-of-builtin-attrs.rs)
// Crate-level is accepted, though it is almost certainly unused?
#![inline = "2100"]
#[inline = "2100"]
//~^ ERROR attribute should be applied to function
mod inline {
mod inner { #![inline="2100"] }
//~^ ERROR attribute should be applied to function
#[inline = "2100"] fn f() { }
#[inline = "2100"] struct S;
//~^ ERROR attribute should be applied to function
#[inline = "2100"] type T = S;
//~^ ERROR attribute should be applied to function
#[inline = "2100"] impl S { }
//~^ ERROR attribute should be applied to function
}
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Testing that crate-level `#![macro_escape]` is not gated beyond a
// depecation warning. This file sits on its own, because crate-level
// `#![macro_escape]` is incompatible with crate-level `#![macro_use]`
// already present in issue-43106-gating-of-builtin-attrs.
#![macro_escape]
//~^ WARN macro_escape is a deprecated synonym for macro_use
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// This is just a check-list of the cases where feeding arguments to
// `#[macro_use]` is rejected. (The cases where no error is emitted
// corresponds to cases where the attribute is currently unused, so we
// get that warning; see issue-43106-gating-of-builtin-attrs.rs
#![macro_use = "4900"] //~ ERROR arguments to macro_use are not allowed here
#[macro_use = "2700"]
//~^ ERROR arguments to macro_use are not allowed here
mod macro_escape {
mod inner { #![macro_use="2700"] }
//~^ ERROR arguments to macro_use are not allowed here
#[macro_use = "2700"] fn f() { }
#[macro_use = "2700"] struct S;
#[macro_use = "2700"] type T = S;
#[macro_use = "2700"] impl S { }
}
fn main() { }
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// At time of authorship, #[proc_macro_derive = "2500"] will emit an
// error when it occurs on a mod (apart from crate-level), but will
// not descend further into the mod for other occurrences of the same
// error.
//
// This file sits on its own because the the "weird" occurrences here
// signal errors, making it incompatible with the "warnings only"
// nature of issue-43106-gating-of-builtin-attrs.rs
#[proc_macro_derive = "2500"]
//~^ ERROR the `#[proc_macro_derive]` attribute may only be used on bare functions
mod proc_macro_derive1 {
mod inner { #![proc_macro_derive="2500"] }
// (no error issued here if there was one on outer module)
}
mod proc_macro_derive2 {
mod inner { #![proc_macro_derive="2500"] }
//~^ ERROR the `#[proc_macro_derive]` attribute may only be used on bare functions
#[proc_macro_derive = "2500"] fn f() { }
//~^ ERROR the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro`
#[proc_macro_derive = "2500"] struct S;
//~^ ERROR the `#[proc_macro_derive]` attribute may only be used on bare functions
#[proc_macro_derive = "2500"] type T = S;
//~^ ERROR the `#[proc_macro_derive]` attribute may only be used on bare functions
#[proc_macro_derive = "2500"] impl S { }
//~^ ERROR the `#[proc_macro_derive]` attribute may only be used on bare functions
}
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Testing gating of `#[rustc_deprecated]` in "weird" places.
//
// This file sits on its own because these signal errors, making
// this test incompatible with the "warnings only" nature of
// issue-43106-gating-of-builtin-attrs.rs
#![rustc_deprecated = "1500"]
//~^ ERROR stability attributes may not be used outside of the standard library
#[rustc_deprecated = "1500"]
//~^ ERROR stability attributes may not be used outside of the standard library
mod rustc_deprecated {
mod inner { #![rustc_deprecated="1500"] }
//~^ ERROR stability attributes may not be used outside of the standard library
#[rustc_deprecated = "1500"] fn f() { }
//~^ ERROR stability attributes may not be used outside of the standard library
#[rustc_deprecated = "1500"] struct S;
//~^ ERROR stability attributes may not be used outside of the standard library
//~| ERROR stability attributes may not be used outside of the standard library
#[rustc_deprecated = "1500"] type T = S;
//~^ ERROR stability attributes may not be used outside of the standard library
#[rustc_deprecated = "1500"] impl S { }
//~^ ERROR stability attributes may not be used outside of the standard library
}
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Testing gating of `#[stable]` in "weird" places.
//
// This file sits on its own because these signal errors, making
// this test incompatible with the "warnings only" nature of
// issue-43106-gating-of-builtin-attrs.rs
#![stable = "1300"]
//~^ ERROR stability attributes may not be used outside of the standard library
#[stable = "1300"]
//~^ ERROR stability attributes may not be used outside of the standard library
mod stable {
mod inner { #![stable="1300"] }
//~^ ERROR stability attributes may not be used outside of the standard library
#[stable = "1300"] fn f() { }
//~^ ERROR stability attributes may not be used outside of the standard library
#[stable = "1300"] struct S;
//~^ ERROR stability attributes may not be used outside of the standard library
//~| ERROR stability attributes may not be used outside of the standard library
#[stable = "1300"] type T = S;
//~^ ERROR stability attributes may not be used outside of the standard library
#[stable = "1300"] impl S { }
//~^ ERROR stability attributes may not be used outside of the standard library
}
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: main function not found
// At time of authorship, crate-level #[test] attribute with no
// `--test` signals unconditional error complaining of missing main
// function (despite having one), similar to #[bench].
//
// (The non-crate level cases are in
// issue-43106-gating-of-builtin-attrs.rs.)
#![test = "4200"]
fn main() { }
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Testing gating of `#[unstable]` in "weird" places.
//
// This file sits on its own because these signal errors, making
// this test incompatible with the "warnings only" nature of
// issue-43106-gating-of-builtin-attrs.rs
#![unstable = "1200"]
//~^ ERROR stability attributes may not be used outside of the standard library
#[unstable = "1200"]
//~^ ERROR stability attributes may not be used outside of the standard library
mod unstable {
mod inner { #![unstable="1200"] }
//~^ ERROR stability attributes may not be used outside of the standard library
#[unstable = "1200"] fn f() { }
//~^ ERROR stability attributes may not be used outside of the standard library
#[unstable = "1200"] struct S;
//~^ ERROR stability attributes may not be used outside of the standard library
//~| ERROR stability attributes may not be used outside of the standard library
#[unstable = "1200"] type T = S;
//~^ ERROR stability attributes may not be used outside of the standard library
#[unstable = "1200"] impl S { }
//~^ ERROR stability attributes may not be used outside of the standard library
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册