Skip to content

Commit 4a919cb

Browse files
authored
Rollup merge of #39813 - sanxiyn:non-camel-case-variant, r=petrochenkov
Use check_variant for non_camel_case_types lint This way we automatically consider lint attributes. Fix #38452.
2 parents 4246f37 + 255b5ed commit 4a919cb

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/librustc_lint/bad_style.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCamelCaseTypes {
117117

118118
match it.node {
119119
hir::ItemTy(..) |
120+
hir::ItemEnum(..) |
120121
hir::ItemStruct(..) |
121122
hir::ItemUnion(..) => self.check_case(cx, "type", it.name, it.span),
122123
hir::ItemTrait(..) => self.check_case(cx, "trait", it.name, it.span),
123-
hir::ItemEnum(ref enum_definition, _) => {
124-
if has_extern_repr {
125-
return;
126-
}
127-
self.check_case(cx, "type", it.name, it.span);
128-
for variant in &enum_definition.variants {
129-
self.check_case(cx, "variant", variant.node.name, variant.span);
130-
}
131-
}
132124
_ => (),
133125
}
134126
}
135127

128+
fn check_variant(&mut self, cx: &LateContext, v: &hir::Variant, _: &hir::Generics) {
129+
self.check_case(cx, "variant", v.node.name, v.span);
130+
}
131+
136132
fn check_generics(&mut self, cx: &LateContext, it: &hir::Generics) {
137133
for gen in it.ty_params.iter() {
138134
self.check_case(cx, "type parameter", gen.name, gen.span);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2017 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+
#![deny(non_camel_case_types)]
12+
13+
pub enum Foo {
14+
#[allow(non_camel_case_types)]
15+
bar
16+
}
17+
18+
fn main() {}

0 commit comments

Comments
 (0)