Skip to content

Commit 6bd79d3

Browse files
committed
rustc: Always mark #[crate_name] as used
It's just an annoying error if you use --crate-name on the command line and you also have a #[crate_name] specified
1 parent f9fe251 commit 6bd79d3

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/librustc/back/link.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,12 @@ pub fn find_crate_name(sess: Option<&Session>,
555555
s
556556
};
557557

558+
// Look in attributes 100% of the time to make sure the attribute is marked
559+
// as used. After doing this, however, favor crate names from the command
560+
// line.
561+
let attr_crate_name = attrs.iter().find(|at| at.check_name("crate_name"))
562+
.and_then(|at| at.value_str().map(|s| (at, s)));
563+
558564
match sess {
559565
Some(sess) => {
560566
match sess.opts.crate_name {
@@ -565,9 +571,7 @@ pub fn find_crate_name(sess: Option<&Session>,
565571
None => {}
566572
}
567573

568-
let crate_name = attrs.iter().find(|at| at.check_name("crate_name"))
569-
.and_then(|at| at.value_str().map(|s| (at, s)));
570-
match crate_name {
574+
match attr_crate_name {
571575
Some((attr, s)) => return validate(s.get().to_string(), Some(attr.span)),
572576
None => {}
573577
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags:--crate-name crate-name-attr-used -F unused-attribute
12+
13+
#![crate_name = "test"]
14+
15+
fn main() {}

0 commit comments

Comments
 (0)