Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed Aug 21, 2021
1 parent 17aef21 commit 62aea8c
Show file tree
Hide file tree
Showing 4 changed files with 362 additions and 638 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
_ => {}
}

Expand Down Expand Up @@ -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();
Expand Down
18 changes: 9 additions & 9 deletions src/test/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
}
Expand Down Expand Up @@ -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"]
Expand Down
Loading

0 comments on commit 62aea8c

Please sign in to comment.