Skip to content

Commit 13dc0d7

Browse files
committed
auto merge of #15584 : alexcrichton/rust/warn-annoyances, r=cmr
* Don't warn about `#[crate_name]` if `--crate-name` is specified * Don't warn about non camel case identifiers on `#[repr(C)]` structs * Switch `mode` to `mode_t` in libc.
2 parents ad7ef8c + 2dfbe7f commit 13dc0d7

File tree

8 files changed

+109
-64
lines changed

8 files changed

+109
-64
lines changed

src/liblibc/lib.rs

+61-57
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,7 @@ pub mod consts {
20082008
pub mod posix88 {
20092009
use types::os::arch::c95::c_int;
20102010
use types::common::c95::c_void;
2011+
use types::os::arch::posix88::mode_t;
20112012

20122013
pub static O_RDONLY : c_int = 0;
20132014
pub static O_WRONLY : c_int = 1;
@@ -2016,20 +2017,20 @@ pub mod consts {
20162017
pub static O_CREAT : c_int = 64;
20172018
pub static O_EXCL : c_int = 128;
20182019
pub static O_TRUNC : c_int = 512;
2019-
pub static S_IFIFO : c_int = 4096;
2020-
pub static S_IFCHR : c_int = 8192;
2021-
pub static S_IFBLK : c_int = 24576;
2022-
pub static S_IFDIR : c_int = 16384;
2023-
pub static S_IFREG : c_int = 32768;
2024-
pub static S_IFLNK : c_int = 40960;
2025-
pub static S_IFMT : c_int = 61440;
2026-
pub static S_IEXEC : c_int = 64;
2027-
pub static S_IWRITE : c_int = 128;
2028-
pub static S_IREAD : c_int = 256;
2029-
pub static S_IRWXU : c_int = 448;
2030-
pub static S_IXUSR : c_int = 64;
2031-
pub static S_IWUSR : c_int = 128;
2032-
pub static S_IRUSR : c_int = 256;
2020+
pub static S_IFIFO : mode_t = 4096;
2021+
pub static S_IFCHR : mode_t = 8192;
2022+
pub static S_IFBLK : mode_t = 24576;
2023+
pub static S_IFDIR : mode_t = 16384;
2024+
pub static S_IFREG : mode_t = 32768;
2025+
pub static S_IFLNK : mode_t = 40960;
2026+
pub static S_IFMT : mode_t = 61440;
2027+
pub static S_IEXEC : mode_t = 64;
2028+
pub static S_IWRITE : mode_t = 128;
2029+
pub static S_IREAD : mode_t = 256;
2030+
pub static S_IRWXU : mode_t = 448;
2031+
pub static S_IXUSR : mode_t = 64;
2032+
pub static S_IWUSR : mode_t = 128;
2033+
pub static S_IRUSR : mode_t = 256;
20332034
pub static F_OK : c_int = 0;
20342035
pub static R_OK : c_int = 4;
20352036
pub static W_OK : c_int = 2;
@@ -2220,6 +2221,7 @@ pub mod consts {
22202221
pub mod posix88 {
22212222
use types::os::arch::c95::c_int;
22222223
use types::common::c95::c_void;
2224+
use types::os::arch::posix88::mode_t;
22232225

22242226
pub static O_RDONLY : c_int = 0;
22252227
pub static O_WRONLY : c_int = 1;
@@ -2228,20 +2230,20 @@ pub mod consts {
22282230
pub static O_CREAT : c_int = 256;
22292231
pub static O_EXCL : c_int = 1024;
22302232
pub static O_TRUNC : c_int = 512;
2231-
pub static S_IFIFO : c_int = 4096;
2232-
pub static S_IFCHR : c_int = 8192;
2233-
pub static S_IFBLK : c_int = 24576;
2234-
pub static S_IFDIR : c_int = 16384;
2235-
pub static S_IFREG : c_int = 32768;
2236-
pub static S_IFLNK : c_int = 40960;
2237-
pub static S_IFMT : c_int = 61440;
2238-
pub static S_IEXEC : c_int = 64;
2239-
pub static S_IWRITE : c_int = 128;
2240-
pub static S_IREAD : c_int = 256;
2241-
pub static S_IRWXU : c_int = 448;
2242-
pub static S_IXUSR : c_int = 64;
2243-
pub static S_IWUSR : c_int = 128;
2244-
pub static S_IRUSR : c_int = 256;
2233+
pub static S_IFIFO : mode_t = 4096;
2234+
pub static S_IFCHR : mode_t = 8192;
2235+
pub static S_IFBLK : mode_t = 24576;
2236+
pub static S_IFDIR : mode_t = 16384;
2237+
pub static S_IFREG : mode_t = 32768;
2238+
pub static S_IFLNK : mode_t = 40960;
2239+
pub static S_IFMT : mode_t = 61440;
2240+
pub static S_IEXEC : mode_t = 64;
2241+
pub static S_IWRITE : mode_t = 128;
2242+
pub static S_IREAD : mode_t = 256;
2243+
pub static S_IRWXU : mode_t = 448;
2244+
pub static S_IXUSR : mode_t = 64;
2245+
pub static S_IWUSR : mode_t = 128;
2246+
pub static S_IRUSR : mode_t = 256;
22452247
pub static F_OK : c_int = 0;
22462248
pub static R_OK : c_int = 4;
22472249
pub static W_OK : c_int = 2;
@@ -2759,6 +2761,7 @@ pub mod consts {
27592761
pub mod posix88 {
27602762
use types::common::c95::c_void;
27612763
use types::os::arch::c95::c_int;
2764+
use types::os::arch::posix88::mode_t;
27622765

27632766
pub static O_RDONLY : c_int = 0;
27642767
pub static O_WRONLY : c_int = 1;
@@ -2767,20 +2770,20 @@ pub mod consts {
27672770
pub static O_CREAT : c_int = 512;
27682771
pub static O_EXCL : c_int = 2048;
27692772
pub static O_TRUNC : c_int = 1024;
2770-
pub static S_IFIFO : c_int = 4096;
2771-
pub static S_IFCHR : c_int = 8192;
2772-
pub static S_IFBLK : c_int = 24576;
2773-
pub static S_IFDIR : c_int = 16384;
2774-
pub static S_IFREG : c_int = 32768;
2775-
pub static S_IFLNK : c_int = 40960;
2776-
pub static S_IFMT : c_int = 61440;
2777-
pub static S_IEXEC : c_int = 64;
2778-
pub static S_IWRITE : c_int = 128;
2779-
pub static S_IREAD : c_int = 256;
2780-
pub static S_IRWXU : c_int = 448;
2781-
pub static S_IXUSR : c_int = 64;
2782-
pub static S_IWUSR : c_int = 128;
2783-
pub static S_IRUSR : c_int = 256;
2773+
pub static S_IFIFO : mode_t = 4096;
2774+
pub static S_IFCHR : mode_t = 8192;
2775+
pub static S_IFBLK : mode_t = 24576;
2776+
pub static S_IFDIR : mode_t = 16384;
2777+
pub static S_IFREG : mode_t = 32768;
2778+
pub static S_IFLNK : mode_t = 40960;
2779+
pub static S_IFMT : mode_t = 61440;
2780+
pub static S_IEXEC : mode_t = 64;
2781+
pub static S_IWRITE : mode_t = 128;
2782+
pub static S_IREAD : mode_t = 256;
2783+
pub static S_IRWXU : mode_t = 448;
2784+
pub static S_IXUSR : mode_t = 64;
2785+
pub static S_IWUSR : mode_t = 128;
2786+
pub static S_IRUSR : mode_t = 256;
27842787
pub static F_OK : c_int = 0;
27852788
pub static R_OK : c_int = 4;
27862789
pub static W_OK : c_int = 2;
@@ -3148,6 +3151,7 @@ pub mod consts {
31483151
pub mod posix88 {
31493152
use types::common::c95::c_void;
31503153
use types::os::arch::c95::c_int;
3154+
use types::os::arch::posix88::mode_t;
31513155

31523156
pub static O_RDONLY : c_int = 0;
31533157
pub static O_WRONLY : c_int = 1;
@@ -3156,20 +3160,20 @@ pub mod consts {
31563160
pub static O_CREAT : c_int = 512;
31573161
pub static O_EXCL : c_int = 2048;
31583162
pub static O_TRUNC : c_int = 1024;
3159-
pub static S_IFIFO : c_int = 4096;
3160-
pub static S_IFCHR : c_int = 8192;
3161-
pub static S_IFBLK : c_int = 24576;
3162-
pub static S_IFDIR : c_int = 16384;
3163-
pub static S_IFREG : c_int = 32768;
3164-
pub static S_IFLNK : c_int = 40960;
3165-
pub static S_IFMT : c_int = 61440;
3166-
pub static S_IEXEC : c_int = 64;
3167-
pub static S_IWRITE : c_int = 128;
3168-
pub static S_IREAD : c_int = 256;
3169-
pub static S_IRWXU : c_int = 448;
3170-
pub static S_IXUSR : c_int = 64;
3171-
pub static S_IWUSR : c_int = 128;
3172-
pub static S_IRUSR : c_int = 256;
3163+
pub static S_IFIFO : mode_t = 4096;
3164+
pub static S_IFCHR : mode_t = 8192;
3165+
pub static S_IFBLK : mode_t = 24576;
3166+
pub static S_IFDIR : mode_t = 16384;
3167+
pub static S_IFREG : mode_t = 32768;
3168+
pub static S_IFLNK : mode_t = 40960;
3169+
pub static S_IFMT : mode_t = 61440;
3170+
pub static S_IEXEC : mode_t = 64;
3171+
pub static S_IWRITE : mode_t = 128;
3172+
pub static S_IREAD : mode_t = 256;
3173+
pub static S_IRWXU : mode_t = 448;
3174+
pub static S_IXUSR : mode_t = 64;
3175+
pub static S_IWUSR : mode_t = 128;
3176+
pub static S_IRUSR : mode_t = 256;
31733177
pub static F_OK : c_int = 0;
31743178
pub static R_OK : c_int = 4;
31753179
pub static W_OK : c_int = 2;
@@ -3858,7 +3862,7 @@ pub mod funcs {
38583862
use types::os::arch::posix88::mode_t;
38593863

38603864
extern {
3861-
pub fn open(path: *const c_char, oflag: c_int, mode: c_int)
3865+
pub fn open(path: *const c_char, oflag: c_int, mode: mode_t)
38623866
-> c_int;
38633867
pub fn creat(path: *const c_char, mode: mode_t) -> c_int;
38643868
pub fn fcntl(fd: c_int, cmd: c_int, ...) -> c_int;

src/librustc/back/link.rs

+7-3
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
}

src/librustc/lint/builtin.rs

+5
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,11 @@ impl LintPass for NonCamelCaseTypes {
758758
}
759759
}
760760

761+
let has_extern_repr = it.attrs.iter().fold(attr::ReprAny, |acc, attr| {
762+
attr::find_repr_attr(cx.tcx.sess.diagnostic(), attr, acc)
763+
}) == attr::ReprExtern;
764+
if has_extern_repr { return }
765+
761766
match it.node {
762767
ast::ItemTy(..) | ast::ItemStruct(..) => {
763768
check_case(cx, "type", it.ident, it.span)

src/librustuv/file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ mod test {
547547
let path = &"./tmp/mk_rm_dir".to_c_str();
548548
let mode = S_IWUSR | S_IRUSR;
549549

550-
let result = FsRequest::mkdir(l(), path, mode);
550+
let result = FsRequest::mkdir(l(), path, mode as c_int);
551551
assert!(result.is_ok());
552552

553553
let result = FsRequest::rmdir(l(), path);

src/libstd/io/fs.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ pub fn lstat(path: &Path) -> IoResult<FileStat> {
330330
}
331331

332332
fn from_rtio(s: rtio::FileStat) -> FileStat {
333+
#[cfg(windows)]
334+
type Mode = libc::c_int;
335+
#[cfg(unix)]
336+
type Mode = libc::mode_t;
337+
333338
let rtio::FileStat {
334339
size, kind, perm, created, modified,
335340
accessed, device, inode, rdev,
@@ -338,7 +343,7 @@ fn from_rtio(s: rtio::FileStat) -> FileStat {
338343

339344
FileStat {
340345
size: size,
341-
kind: match (kind as libc::c_int) & libc::S_IFMT {
346+
kind: match (kind as Mode) & libc::S_IFMT {
342347
libc::S_IFREG => io::TypeFile,
343348
libc::S_IFDIR => io::TypeDirectory,
344349
libc::S_IFIFO => io::TypeNamedPipe,

src/libsyntax/ast.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ impl Ident {
5858

5959
impl Show for Ident {
6060
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
61-
write!(f, "\"{}\"#{}", token::get_ident(*self).get(), self.ctxt)
61+
write!(f, "{}#{}", self.name, self.ctxt)
62+
}
63+
}
64+
65+
impl Show for Name {
66+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
67+
let Name(nm) = *self;
68+
write!(f, "\"{}\"({})", token::get_name(*self).get(), nm)
6269
}
6370
}
6471

@@ -106,7 +113,7 @@ pub static ILLEGAL_CTXT : SyntaxContext = 1;
106113

107114
/// A name is a part of an identifier, representing a string or gensym. It's
108115
/// the result of interning.
109-
#[deriving(Eq, Ord, PartialEq, PartialOrd, Hash, Encodable, Decodable, Clone, Show)]
116+
#[deriving(Eq, Ord, PartialEq, PartialOrd, Hash, Encodable, Decodable, Clone)]
110117
pub struct Name(pub u32);
111118

112119
impl Name {

src/test/compile-fail/lint-non-camel-case-types.rs

+5
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ enum Foo5 {
3232
trait foo6 { //~ ERROR trait `foo6` should have a camel case name such as `Foo6`
3333
}
3434

35+
#[repr(C)]
36+
struct foo7 {
37+
bar: int,
38+
}
39+
3540
fn main() { }
+15
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)