Address review comments

This commit is contained in:
Aaron Hill 2021-08-21 14:11:36 -05:00
parent 17aef21b30
commit 62aea8c913
No known key found for this signature in database
GPG Key ID: B4087E510E98B164
4 changed files with 578 additions and 854 deletions

View File

@ -251,7 +251,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
// Modules, prelude, and resolution:
ungated!(path, Normal, template!(NameValueStr: "file")),
ungated!(no_std, CrateLevel, template!(Word)),
ungated!(no_implicit_prelude, CrateLevel, template!(Word)),
ungated!(no_implicit_prelude, Normal, template!(Word)),
ungated!(non_exhaustive, Normal, template!(Word)),
// Runtime

View File

@ -130,6 +130,12 @@ impl CheckAttrVisitor<'tcx> {
sym::ignore | sym::should_panic | sym::proc_macro_derive => {
self.check_generic_attr(hir_id, attr, target, &[Target::Fn])
}
sym::automatically_derived => {
self.check_generic_attr(hir_id, attr, target, &[Target::Impl])
}
sym::no_implicit_prelude => {
self.check_generic_attr(hir_id, attr, target, &[Target::Mod])
}
_ => {}
}
@ -290,7 +296,6 @@ impl CheckAttrVisitor<'tcx> {
b.push_str(&(allowed_target.to_string() + "s"));
b
});
//let supported_names = allowed_targets.iter().fold(String::new(), |msg, t| msg + ", " + &t.to_string());
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
lint.build(&format!("`#[{name}]` only has an effect on {}", supported_names))
.emit();

View File

@ -275,18 +275,20 @@ mod path {
//~^ WARN `#[path]` only has an effect
}
// Don't warn on `automatically_derived` - a custom derive
// could reasonally annotate anything that it emits with
// this attribute
#[automatically_derived]
//~^ WARN `#[automatically_derived]` only has an effect
mod automatically_derived {
mod inner { #![automatically_derived] }
//~^ WARN `#[automatically_derived]
#[automatically_derived] fn f() { }
//~^ WARN `#[automatically_derived]
#[automatically_derived] struct S;
//~^ WARN `#[automatically_derived]
#[automatically_derived] type T = S;
//~^ WARN `#[automatically_derived]
#[automatically_derived] impl S { }
}
@ -368,22 +370,20 @@ mod ignore {
}
#[no_implicit_prelude]
//~^ WARN crate-level attribute
mod no_implicit_prelude {
mod inner { #![no_implicit_prelude] }
//~^ WARN crate-level attribute
#[no_implicit_prelude] fn f() { }
//~^ WARN crate-level attribute
//~^ WARN `#[no_implicit_prelude]` only has an effect
#[no_implicit_prelude] struct S;
//~^ WARN crate-level attribute
//~^ WARN `#[no_implicit_prelude]` only has an effect
#[no_implicit_prelude] type T = S;
//~^ WARN crate-level attribute
//~^ WARN `#[no_implicit_prelude]` only has an effect
#[no_implicit_prelude] impl S { }
//~^ WARN crate-level attribute
//~^ WARN `#[no_implicit_prelude]` only has an effect
}
#[reexport_test_harness_main = "2900"]