Skip to content

Commit aeeb03a

Browse files
author
Palmer Cox
committed
---
yaml --- r: 149743 b: refs/heads/try2 c: 258dbd0 h: refs/heads/master i: 149741: b8606e7 149739: 77150ab 149735: c0da104 149727: 8b8e7c1 v: v3
1 parent 884e85e commit aeeb03a

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: e3723dc4f1f256e5a454cafb62fd892d85767750
8+
refs/heads/try2: 258dbd09ba4aa868b373df7e82721ba0c40167ba
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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/try2/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)