Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
93eaf15
Add SessionDiagnostic derive macro.
jumbatm Aug 27, 2020
57edf88
Replace some trivial struct_span_err!s in typeck.
jumbatm Aug 27, 2020
5956254
Fix typos in E0224
jumbatm Aug 25, 2020
d80415a
Improve ayu doc source line number contrast
pickfire Sep 5, 2020
4fff14d
rustbuild: Remove `Mode::Codegen`
petrochenkov Sep 5, 2020
5acd272
Fix HashMap visualizers in Visual Studio (Code)
MaulingMonkey Sep 5, 2020
b92b0d6
Fix typo in tracking issue template
dylni Sep 6, 2020
4efe97a
Check placement of more attributes
calebzulawski Jun 14, 2020
f745b34
Emit warnings for misplaced attributes used by some crates
calebzulawski Jul 11, 2020
0c62ef0
Allow #[cold], #[track_caller] on closures. Fix whitespace in error m…
calebzulawski Aug 12, 2020
acd68b5
Fix broken test on musl
calebzulawski Sep 6, 2020
8f69266
Emit warnings on misplaced #[no_mangle]
calebzulawski Sep 6, 2020
9e14033
Update linker-plugin-lto.md to contain up to rust 1.46
elichai Sep 6, 2020
84fc6fd
Fix documentation for TyCtxt::all_impls
scrabsha Sep 6, 2020
2e82589
linker-plugin-lto.md: Convert the rust-clang MxN table to a 2xM table
elichai Sep 6, 2020
720293b
do not premote non-ZST mutable references ever
RalfJung Aug 16, 2020
28ddda7
add compile-fail test for &mut promotion
RalfJung Aug 16, 2020
2656d34
Make bootstrap build on stable
Mark-Simulacrum Sep 6, 2020
936b830
Rollup merge of #73461 - calebzulawski:validate-attribute-placement, …
Dylan-DPC Sep 7, 2020
b5468e1
Rollup merge of #75138 - jumbatm:session-diagnostic-derive, r=oli-obk
Dylan-DPC Sep 7, 2020
fddf315
Rollup merge of #75585 - RalfJung:demotion, r=oli-obk
Dylan-DPC Sep 7, 2020
f037dca
Rollup merge of #76374 - pickfire:patch-4, r=Cldfire
Dylan-DPC Sep 7, 2020
547806c
Rollup merge of #76379 - petrochenkov:nodegen, r=Mark-Simulacrum
Dylan-DPC Sep 7, 2020
b4007b5
Rollup merge of #76389 - MaulingMonkey:pr-natvis-hashmap-vsc, r=petro…
Dylan-DPC Sep 7, 2020
a79c360
Rollup merge of #76396 - dylni:fix-typo-in-tracking-issue-template, r…
Dylan-DPC Sep 7, 2020
9d649ed
Rollup merge of #76402 - elichai:patch-2, r=wesleywiser
Dylan-DPC Sep 7, 2020
910c87c
Rollup merge of #76403 - scileo:doc-all-impls, r=lcnr
Dylan-DPC Sep 7, 2020
4ab3677
Rollup merge of #76423 - Mark-Simulacrum:stable-bootstrap, r=jyn514
Dylan-DPC Sep 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Emit warnings on misplaced #[no_mangle]
  • Loading branch information
calebzulawski committed Sep 6, 2020
commit 8f69266f799c2fc33a871c41f72a1d79eef4126e
23 changes: 23 additions & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ impl CheckAttrVisitor<'tcx> {
self.check_link_name(hir_id, attr, span, target);
} else if self.tcx.sess.check_name(attr, sym::link_section) {
self.check_link_section(hir_id, attr, span, target);
} else if self.tcx.sess.check_name(attr, sym::no_mangle) {
self.check_no_mangle(hir_id, attr, span, target);
}
true
};
Expand Down Expand Up @@ -419,6 +421,27 @@ impl CheckAttrVisitor<'tcx> {
}
}

/// Checks if `#[no_mangle]` is applied to a function or static.
fn check_no_mangle(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
match target {
Target::Static | Target::Fn | Target::Method(..) => {}
_ => {
// FIXME: #[no_mangle] was previously allowed on non-functions/statics and some
// crates used this, so only emit a warning.
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
lint.build("attribute should be applied to a function or static")
.warn(
"this was previously accepted by the compiler but is \
being phased out; it will become a hard error in \
a future release!",
)
.span_label(*span, "not a function or static")
.emit();
});
}
}
}

/// Checks if the `#[repr]` attributes on `item` are valid.
fn check_repr(
&self,
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,31 @@ mod automatically_derived {
}

#[no_mangle]
//~^ WARN attribute should be applied to a function or static [unused_attributes]
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
mod no_mangle {
//~^ NOTE not a function or static
mod inner { #![no_mangle] }
//~^ WARN attribute should be applied to a function or static [unused_attributes]
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//~| NOTE not a function or static

#[no_mangle] fn f() { }

#[no_mangle] struct S;
//~^ WARN attribute should be applied to a function or static [unused_attributes]
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//~| NOTE not a function or static

#[no_mangle] type T = S;
//~^ WARN attribute should be applied to a function or static [unused_attributes]
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//~| NOTE not a function or static

#[no_mangle] impl S { }
//~^ WARN attribute should be applied to a function or static [unused_attributes]
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//~| NOTE not a function or static
}

#[should_panic]
Expand Down
Loading