Skip to content

Commit 636d61f

Browse files
committed
Check for ident length. Fixes rust-lang#13105
1 parent bc37b8f commit 636d61f

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

src/librustc/middle/lint.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,11 +1204,13 @@ fn check_pat_uppercase_variable(cx: &Context, p: &ast::Pat) {
12041204
// last identifier alone is right choice for this lint.
12051205
let ident = path.segments.last().unwrap().identifier;
12061206
let s = token::get_ident(ident);
1207-
if s.get().char_at(0).is_uppercase() {
1208-
cx.span_lint(
1209-
UppercaseVariables,
1210-
path.span,
1211-
"variable names should start with a lowercase character");
1207+
if s.get().len() > 0 {
1208+
if s.get().char_at(0).is_uppercase() {
1209+
cx.span_lint(
1210+
UppercaseVariables,
1211+
path.span,
1212+
"variable names should start with a lowercase character");
1213+
}
12121214
}
12131215
}
12141216
_ => {}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2012 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+
12+
// Regression test for issue #13105
13+
14+
#[deny(uppercase_variables)];
15+
16+
trait Foo {
17+
// Good
18+
fn foo(&self);
19+
20+
// Good
21+
fn bar(u8);
22+
23+
// Good
24+
fn baz(&self) {
25+
26+
}
27+
28+
// ICE
29+
fn quux(u8) {
30+
31+
}
32+
}
33+
34+
fn main() {
35+
36+
}

0 commit comments

Comments
 (0)