Skip to content

Commit 81c1189

Browse files
authored
Rollup merge of #105768 - fee1-dead-contrib:iat-style, r=eholk
Detect inherent associated types not having CamelCase Fixes #105341.
2 parents a6c6a8d + 08a0e71 commit 81c1189

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Diff for: compiler/rustc_lint/src/nonstandard_style.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,23 @@ impl EarlyLintPass for NonCamelCaseTypes {
175175
return;
176176
}
177177

178-
match it.kind {
178+
match &it.kind {
179179
ast::ItemKind::TyAlias(..)
180180
| ast::ItemKind::Enum(..)
181181
| ast::ItemKind::Struct(..)
182182
| ast::ItemKind::Union(..) => self.check_case(cx, "type", &it.ident),
183183
ast::ItemKind::Trait(..) => self.check_case(cx, "trait", &it.ident),
184184
ast::ItemKind::TraitAlias(..) => self.check_case(cx, "trait alias", &it.ident),
185+
186+
// N.B. This check is only for inherent associated types, so that we don't lint against
187+
// trait impls where we should have warned for the trait definition already.
188+
ast::ItemKind::Impl(box ast::Impl { of_trait: None, items, .. }) => {
189+
for it in items {
190+
if let ast::AssocItemKind::Type(..) = it.kind {
191+
self.check_case(cx, "associated type", &it.ident);
192+
}
193+
}
194+
}
185195
_ => (),
186196
}
187197
}

Diff for: src/test/ui/associated-inherent-types/style.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(inherent_associated_types)]
2+
#![allow(incomplete_features, dead_code)]
3+
#![deny(non_camel_case_types)]
4+
5+
struct S;
6+
7+
impl S {
8+
type typ = ();
9+
//~^ ERROR associated type `typ` should have an upper camel case name
10+
}
11+
12+
fn main() {}

Diff for: src/test/ui/associated-inherent-types/style.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: associated type `typ` should have an upper camel case name
2+
--> $DIR/style.rs:8:10
3+
|
4+
LL | type typ = ();
5+
| ^^^ help: convert the identifier to upper camel case: `Typ`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/style.rs:3:9
9+
|
10+
LL | #![deny(non_camel_case_types)]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)