Skip to content

Rollup of 7 pull requests #50345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
256096d
Make Vec::new const
mark-i-m Apr 25, 2018
a2105b8
make RawVec::empty const
mark-i-m Apr 25, 2018
20ef0e0
make Vec::new const :P
mark-i-m Apr 26, 2018
c122b3a
not insta-stable
mark-i-m Apr 27, 2018
0212e02
feature on test
mark-i-m Apr 29, 2018
368fe37
Add more links in panic docs
Pazzaz Apr 29, 2018
269d279
Fix some broken links in docs.
ehuss Apr 29, 2018
e5280e4
use const trick
mark-i-m Apr 29, 2018
0a6e91b
Add a few more tests for proc macro feature gating
petrochenkov Apr 29, 2018
f9f9923
heh, logic is hard
mark-i-m Apr 29, 2018
cc53db8
Correct unused field warning on &struct match
varkor Apr 29, 2018
8e8fe90
Correct unused field warning on box struct match
varkor Apr 29, 2018
2eb8343
Correct unused field warning on struct match container patterns
varkor Apr 30, 2018
bd4ebf2
check that #[used] is used only on statics
japaric Apr 30, 2018
21941c8
Update Cargo to 2018-04-28 122fd5be5201913d42e219e132d6569493583bca
SimonSapin Apr 30, 2018
b88c152
Rollup merge of #50233 - mark-i-m:const_vec, r=kennytm
kennytm Apr 30, 2018
1308d99
Rollup merge of #50312 - Pazzaz:master, r=GuillaumeGomez
kennytm Apr 30, 2018
b239293
Rollup merge of #50316 - ehuss:fix-doc-links, r=frewsxcv
kennytm Apr 30, 2018
30c990b
Rollup merge of #50325 - petrochenkov:pmgate, r=alexcrichton
kennytm Apr 30, 2018
cbbdf99
Rollup merge of #50327 - varkor:match-unused-struct-field, r=estebank
kennytm Apr 30, 2018
909ba8a
Rollup merge of #50330 - japaric:used, r=nagisa
kennytm Apr 30, 2018
6166f20
Rollup merge of #50344 - SimonSapin:cargo, r=alexcrichton
kennytm Apr 30, 2018
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
12 changes: 12 additions & 0 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum Target {
Expression,
Statement,
Closure,
Static,
Other,
}

Expand All @@ -43,6 +44,7 @@ impl Target {
hir::ItemEnum(..) => Target::Enum,
hir::ItemConst(..) => Target::Const,
hir::ItemForeignMod(..) => Target::ForeignMod,
hir::ItemStatic(..) => Target::Static,
_ => Target::Other,
}
}
Expand Down Expand Up @@ -102,6 +104,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
}

self.check_repr(item, target);
self.check_used(item, target);
}

/// Check if an `#[inline]` is applied to a function or a closure.
Expand Down Expand Up @@ -305,6 +308,15 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
}
}
}

fn check_used(&self, item: &hir::Item, target: Target) {
for attr in &item.attrs {
if attr.name().map(|name| name == "used").unwrap_or(false) && target != Target::Static {
self.tcx.sess
.span_err(attr.span, "attribute must be applied to a `static` variable");
}
}
}
}

impl<'a, 'tcx> Visitor<'tcx> for CheckAttrVisitor<'a, 'tcx> {
Expand Down
28 changes: 28 additions & 0 deletions src/test/compile-fail/used.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2018 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.

#![feature(used)]

#[used]
static FOO: u32 = 0; // OK

#[used] //~ ERROR attribute must be applied to a `static` variable
fn foo() {}

#[used] //~ ERROR attribute must be applied to a `static` variable
struct Foo {}

#[used] //~ ERROR attribute must be applied to a `static` variable
trait Bar {}

#[used] //~ ERROR attribute must be applied to a `static` variable
impl Bar for Foo {}

fn main() {}