Skip to content

Commit 0b6dfc1

Browse files
committed
---
yaml --- r: 152393 b: refs/heads/try2 c: e55f64f h: refs/heads/master i: 152391: 7190867 v: v3
1 parent b1ab2dc commit 0b6dfc1

File tree

7 files changed

+82
-47
lines changed

7 files changed

+82
-47
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: da0703973af921626d7235131d14847b1aacffc2
8+
refs/heads/try2: e55f64f99726a44283211d91a702081fe4a1855b
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: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,12 +1253,21 @@ fn check_item_non_camel_case_types(cx: &Context, it: &ast::Item) {
12531253
!ident.char_at(0).is_lowercase() && !ident.contains_char('_')
12541254
}
12551255

1256+
fn to_camel_case(s: &str) -> String {
1257+
s.split('_').flat_map(|word| word.chars().enumerate().map(|(i, c)|
1258+
if i == 0 { c.to_uppercase() }
1259+
else { c }
1260+
)).collect()
1261+
}
1262+
12561263
fn check_case(cx: &Context, sort: &str, ident: ast::Ident, span: Span) {
1264+
let s = token::get_ident(ident);
1265+
12571266
if !is_camel_case(ident) {
12581267
cx.span_lint(
12591268
NonCamelCaseTypes, span,
1260-
format!("{} `{}` should have a camel case identifier",
1261-
sort, token::get_ident(ident)).as_slice());
1269+
format!("{} `{}` should have a camel case name such as `{}`",
1270+
sort, s, to_camel_case(s.get())).as_slice());
12621271
}
12631272
}
12641273

@@ -1296,10 +1305,29 @@ fn check_snake_case(cx: &Context, sort: &str, ident: ast::Ident, span: Span) {
12961305
})
12971306
}
12981307

1308+
fn to_snake_case(str: &str) -> String {
1309+
let mut words = vec![];
1310+
for s in str.split('_') {
1311+
let mut buf = String::new();
1312+
if s.is_empty() { continue; }
1313+
for ch in s.chars() {
1314+
if !buf.is_empty() && ch.is_uppercase() {
1315+
words.push(buf);
1316+
buf = String::new();
1317+
}
1318+
buf.push_char(ch.to_lowercase());
1319+
}
1320+
words.push(buf);
1321+
}
1322+
words.connect("_")
1323+
}
1324+
1325+
let s = token::get_ident(ident);
1326+
12991327
if !is_snake_case(ident) {
13001328
cx.span_lint(NonSnakeCaseFunctions, span,
1301-
format!("{} `{}` should have a snake case identifier",
1302-
sort, token::get_ident(ident)).as_slice());
1329+
format!("{} `{}` should have a snake case name such as `{}`",
1330+
sort, s, to_snake_case(s.get())).as_slice());
13031331
}
13041332
}
13051333

@@ -1313,7 +1341,10 @@ fn check_item_non_uppercase_statics(cx: &Context, it: &ast::Item) {
13131341
// upper/lowercase)
13141342
if s.get().chars().any(|c| c.is_lowercase()) {
13151343
cx.span_lint(NonUppercaseStatics, it.span,
1316-
"static constant should have an uppercase identifier");
1344+
format!("static constant `{}` should have an uppercase name \
1345+
such as `{}`", s.get(),
1346+
s.get().chars().map(|c| c.to_uppercase())
1347+
.collect::<String>().as_slice()).as_slice());
13171348
}
13181349
}
13191350
_ => {}
@@ -1329,7 +1360,10 @@ fn check_pat_non_uppercase_statics(cx: &Context, p: &ast::Pat) {
13291360
let s = token::get_ident(ident);
13301361
if s.get().chars().any(|c| c.is_lowercase()) {
13311362
cx.span_lint(NonUppercasePatternStatics, path.span,
1332-
"static constant in pattern should be all caps");
1363+
format!("static constant in pattern `{}` should have an uppercase \
1364+
name such as `{}`", s.get(),
1365+
s.get().chars().map(|c| c.to_uppercase())
1366+
.collect::<String>().as_slice()).as_slice());
13331367
}
13341368
}
13351369
_ => {}

branches/try2/src/libstd/io/comm_adapters.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ use option::{None, Option, Some};
1717
use result::{Ok, Err};
1818
use super::{Reader, Writer, IoResult};
1919
use str::StrSlice;
20-
use slice::{bytes, CloneableVector, MutableVector, ImmutableVector};
20+
use slice::{bytes, MutableVector, ImmutableVector};
21+
use vec::Vec;
2122

2223
/// Allows reading from a rx.
2324
///
@@ -30,22 +31,22 @@ use slice::{bytes, CloneableVector, MutableVector, ImmutableVector};
3031
/// # drop(tx);
3132
/// let mut reader = ChanReader::new(rx);
3233
///
33-
/// let mut buf = ~[0u8, ..100];
34+
/// let mut buf = [0u8, ..100];
3435
/// match reader.read(buf) {
3536
/// Ok(nread) => println!("Read {} bytes", nread),
3637
/// Err(e) => println!("read error: {}", e),
3738
/// }
3839
/// ```
3940
pub struct ChanReader {
40-
buf: Option<~[u8]>, // A buffer of bytes received but not consumed.
41-
pos: uint, // How many of the buffered bytes have already be consumed.
42-
rx: Receiver<~[u8]>, // The rx to pull data from.
43-
closed: bool, // Whether the pipe this rx connects to has been closed.
41+
buf: Option<Vec<u8>>, // A buffer of bytes received but not consumed.
42+
pos: uint, // How many of the buffered bytes have already be consumed.
43+
rx: Receiver<Vec<u8>>, // The Receiver to pull data from.
44+
closed: bool, // Whether the channel this Receiver connects to has been closed.
4445
}
4546

4647
impl ChanReader {
4748
/// Wraps a `Port` in a `ChanReader` structure
48-
pub fn new(rx: Receiver<~[u8]>) -> ChanReader {
49+
pub fn new(rx: Receiver<Vec<u8>>) -> ChanReader {
4950
ChanReader {
5051
buf: None,
5152
pos: 0,
@@ -99,12 +100,12 @@ impl Reader for ChanReader {
99100
/// writer.write("hello, world".as_bytes());
100101
/// ```
101102
pub struct ChanWriter {
102-
tx: Sender<~[u8]>,
103+
tx: Sender<Vec<u8>>,
103104
}
104105

105106
impl ChanWriter {
106107
/// Wraps a channel in a `ChanWriter` structure
107-
pub fn new(tx: Sender<~[u8]>) -> ChanWriter {
108+
pub fn new(tx: Sender<Vec<u8>>) -> ChanWriter {
108109
ChanWriter { tx: tx }
109110
}
110111
}
@@ -117,7 +118,7 @@ impl Clone for ChanWriter {
117118

118119
impl Writer for ChanWriter {
119120
fn write(&mut self, buf: &[u8]) -> IoResult<()> {
120-
self.tx.send_opt(buf.to_owned()).map_err(|_| {
121+
self.tx.send_opt(Vec::from_slice(buf)).map_err(|_| {
121122
io::IoError {
122123
kind: io::BrokenPipe,
123124
desc: "Pipe closed",
@@ -139,40 +140,40 @@ mod test {
139140
fn test_rx_reader() {
140141
let (tx, rx) = channel();
141142
task::spawn(proc() {
142-
tx.send(box [1u8, 2u8]);
143-
tx.send(box []);
144-
tx.send(box [3u8, 4u8]);
145-
tx.send(box [5u8, 6u8]);
146-
tx.send(box [7u8, 8u8]);
143+
tx.send(vec![1u8, 2u8]);
144+
tx.send(vec![]);
145+
tx.send(vec![3u8, 4u8]);
146+
tx.send(vec![5u8, 6u8]);
147+
tx.send(vec![7u8, 8u8]);
147148
});
148149

149150
let mut reader = ChanReader::new(rx);
150-
let mut buf = box [0u8, ..3];
151+
let mut buf = [0u8, ..3];
151152

152153

153154
assert_eq!(Ok(0), reader.read([]));
154155

155156
assert_eq!(Ok(3), reader.read(buf));
156-
assert_eq!(box [1,2,3], buf);
157+
assert_eq!(&[1,2,3], buf.as_slice());
157158

158159
assert_eq!(Ok(3), reader.read(buf));
159-
assert_eq!(box [4,5,6], buf);
160+
assert_eq!(&[4,5,6], buf.as_slice());
160161

161162
assert_eq!(Ok(2), reader.read(buf));
162-
assert_eq!(box [7,8,6], buf);
163+
assert_eq!(&[7,8,6], buf.as_slice());
163164

164165
match reader.read(buf) {
165166
Ok(..) => fail!(),
166167
Err(e) => assert_eq!(e.kind, io::EndOfFile),
167168
}
168-
assert_eq!(box [7,8,6], buf);
169+
assert_eq!(&[7,8,6], buf.as_slice());
169170

170171
// Ensure it continues to fail in the same way.
171172
match reader.read(buf) {
172173
Ok(..) => fail!(),
173174
Err(e) => assert_eq!(e.kind, io::EndOfFile),
174175
}
175-
assert_eq!(box [7,8,6], buf);
176+
assert_eq!(&[7,8,6], buf.as_slice());
176177
}
177178

178179
#[test]
@@ -181,7 +182,7 @@ mod test {
181182
let mut writer = ChanWriter::new(tx);
182183
writer.write_be_u32(42).unwrap();
183184

184-
let wanted = box [0u8, 0u8, 0u8, 42u8];
185+
let wanted = vec![0u8, 0u8, 0u8, 42u8];
185186
let got = task::try(proc() { rx.recv() }).unwrap();
186187
assert_eq!(wanted, got);
187188

branches/try2/src/test/compile-fail/lint-non-camel-case-types.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@
1111
#![forbid(non_camel_case_types)]
1212
#![allow(dead_code)]
1313

14-
struct foo { //~ ERROR type `foo` should have a camel case identifier
14+
struct foo { //~ ERROR type `foo` should have a camel case name such as `Foo`
1515
bar: int,
1616
}
1717

18-
enum foo2 { //~ ERROR type `foo2` should have a camel case identifier
18+
enum foo2 { //~ ERROR type `foo2` should have a camel case name such as `Foo2`
1919
Bar
2020
}
2121

22-
struct foo3 { //~ ERROR type `foo3` should have a camel case identifier
22+
struct foo3 { //~ ERROR type `foo3` should have a camel case name such as `Foo3`
2323
bar: int
2424
}
2525

26-
type foo4 = int; //~ ERROR type `foo4` should have a camel case identifier
26+
type foo4 = int; //~ ERROR type `foo4` should have a camel case name such as `Foo4`
2727

2828
enum Foo5 {
29-
bar //~ ERROR variant `bar` should have a camel case identifier
29+
bar //~ ERROR variant `bar` should have a camel case name such as `Bar`
3030
}
3131

32-
trait foo6 { //~ ERROR trait `foo6` should have a camel case identifier
32+
trait foo6 { //~ ERROR trait `foo6` should have a camel case name such as `Foo6`
3333
}
3434

3535
fn main() { }

branches/try2/src/test/compile-fail/lint-non-snake-case-functions.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ struct Foo;
1515

1616
impl Foo {
1717
fn Foo_Method() {}
18-
//~^ ERROR method `Foo_Method` should have a snake case identifier
18+
//~^ ERROR method `Foo_Method` should have a snake case name such as `foo_method`
1919

2020
// Don't allow two underscores in a row
2121
fn foo__method(&self) {}
22-
//~^ ERROR method `foo__method` should have a snake case identifier
22+
//~^ ERROR method `foo__method` should have a snake case name such as `foo_method`
2323

2424
pub fn xyZ(&mut self) {}
25-
//~^ ERROR method `xyZ` should have a snake case identifier
25+
//~^ ERROR method `xyZ` should have a snake case name such as `xy_z`
2626
}
2727

2828
trait X {
2929
fn ABC();
30-
//~^ ERROR trait method `ABC` should have a snake case identifier
30+
//~^ ERROR trait method `ABC` should have a snake case name such as `a_b_c`
3131

3232
fn a_b_C(&self) {}
33-
//~^ ERROR trait method `a_b_C` should have a snake case identifier
33+
//~^ ERROR trait method `a_b_C` should have a snake case name such as `a_b_c`
3434

3535
fn something__else(&mut self);
36-
//~^ ERROR trait method `something__else` should have a snake case identifier
36+
//~^ ERROR trait method `something__else` should have a snake case name such as `something_else`
3737
}
3838

3939
impl X for Foo {
@@ -43,9 +43,9 @@ impl X for Foo {
4343
}
4444

4545
fn Cookie() {}
46-
//~^ ERROR function `Cookie` should have a snake case identifier
46+
//~^ ERROR function `Cookie` should have a snake case name such as `cookie`
4747

4848
pub fn bi_S_Cuit() {}
49-
//~^ ERROR function `bi_S_Cuit` should have a snake case identifier
49+
//~^ ERROR function `bi_S_Cuit` should have a snake case name such as `bi_s_cuit`
5050

5151
fn main() { }

branches/try2/src/test/compile-fail/lint-non-uppercase-statics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
#![forbid(non_uppercase_statics)]
1212
#![allow(dead_code)]
1313

14-
static foo: int = 1; //~ ERROR static constant should have an uppercase identifier
14+
static foo: int = 1; //~ ERROR static constant `foo` should have an uppercase name such as `FOO`
1515

1616
fn main() { }

branches/try2/src/test/compile-fail/match-static-const-lc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub static a : int = 97;
1818
fn f() {
1919
let r = match (0,0) {
2020
(0, a) => 0,
21-
//~^ ERROR static constant in pattern should be all caps
21+
//~^ ERROR static constant in pattern `a` should have an uppercase name such as `A`
2222
(x, y) => 1 + x + y,
2323
};
2424
assert!(r == 1);
@@ -32,7 +32,7 @@ fn g() {
3232
use self::m::aha;
3333
let r = match (0,0) {
3434
(0, aha) => 0,
35-
//~^ ERROR static constant in pattern should be all caps
35+
//~^ ERROR static constant in pattern `aha` should have an uppercase name such as `AHA`
3636
(x, y) => 1 + x + y,
3737
};
3838
assert!(r == 1);
@@ -46,7 +46,7 @@ fn h() {
4646
use not_okay = self::n::OKAY;
4747
let r = match (0,0) {
4848
(0, not_okay) => 0,
49-
//~^ ERROR static constant in pattern should be all caps
49+
//~^ ERROR static constant in pattern `not_okay` should have an uppercase name such as `NOT_OKAY`
5050
(x, y) => 1 + x + y,
5151
};
5252
assert!(r == 1);

0 commit comments

Comments
 (0)