Skip to content

Commit 4d8f4fc

Browse files
author
Palmer Cox
committed
---
yaml --- r: 106603 b: refs/heads/try c: 258dbd0 h: refs/heads/master i: 106601: 0a54c9b 106599: a4997d7 v: v3
1 parent 4a4e1e5 commit 4d8f4fc

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: b8ef9fd9c9f642ce7b8aed82782a1ed745d08d64
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b8601a3d8b91ad3b653d143307611f2f5c75617e
5-
refs/heads/try: e3723dc4f1f256e5a454cafb62fd892d85767750
5+
refs/heads/try: 258dbd09ba4aa868b373df7e82721ba0c40167ba
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/librustc/middle/lint.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
212212
("uppercase_variables",
213213
LintSpec {
214214
lint: UppercaseVariables,
215-
desc: "variable names should start with a lowercase character",
215+
desc: "variable and structure field names should start with a lowercase character",
216216
default: warn
217217
}),
218218

@@ -1201,6 +1201,23 @@ fn check_pat_uppercase_variable(cx: &Context, p: &ast::Pat) {
12011201
}
12021202
}
12031203

1204+
fn check_struct_uppercase_variable(cx: &Context, s: &ast::StructDef) {
1205+
for sf in s.fields.iter() {
1206+
match sf.node {
1207+
ast::StructField_ { kind: ast::NamedField(ident, _), .. } => {
1208+
let s = token::get_ident(ident);
1209+
if s.get().char_at(0).is_uppercase() {
1210+
cx.span_lint(
1211+
UppercaseVariables,
1212+
sf.span,
1213+
"structure field names should start with a lowercase character");
1214+
}
1215+
}
1216+
_ => {}
1217+
}
1218+
}
1219+
}
1220+
12041221
fn check_unnecessary_parens_core(cx: &Context, value: &ast::Expr, msg: &str) {
12051222
match value.node {
12061223
ast::ExprParen(_) => {
@@ -1665,6 +1682,8 @@ impl<'a> Visitor<()> for Context<'a> {
16651682
g: &ast::Generics,
16661683
id: ast::NodeId,
16671684
_: ()) {
1685+
check_struct_uppercase_variable(self, s);
1686+
16681687
let old_id = self.cur_struct_def_id;
16691688
self.cur_struct_def_id = id;
16701689
visit::walk_struct_def(self, s, i, g, id, ());

branches/try/src/test/compile-fail/lint-uppercase-variables.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
use std::io::File;
1414
use std::io::IoError;
1515

16+
struct Something {
17+
X: uint //~ ERROR structure field names should start with a lowercase character
18+
}
19+
1620
fn test(Xx: uint) { //~ ERROR variable names should start with a lowercase character
1721
println!("{}", Xx);
1822
}
@@ -30,5 +34,7 @@ fn main() {
3034
}
3135

3236
test(1);
37+
38+
let _ = Something { X: 0 };
3339
}
3440

0 commit comments

Comments
 (0)