Skip to content

Commit 25de6a1

Browse files
committed
Merge pull request #760 from mcarton/small-fix
Small fix × 2
2 parents eba4143 + 0774b20 commit 25de6a1

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

src/len_zero.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn has_is_empty(cx: &LateContext, expr: &Expr) -> bool {
198198
}
199199
ty::TyProjection(_) => ty.ty_to_def_id().map_or(false, |id| has_is_empty_impl(cx, &id)),
200200
ty::TyEnum(ref id, _) | ty::TyStruct(ref id, _) => has_is_empty_impl(cx, &id.did),
201-
ty::TyArray(..) => true,
201+
ty::TyArray(..) | ty::TyStr => true,
202202
_ => false,
203203
}
204204
}

src/panic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ impl LateLintPass for PanicPass {
3737
match_path(path, &BEGIN_UNWIND),
3838
let ExprLit(ref lit) = params[0].node,
3939
let LitKind::Str(ref string, _) = lit.node,
40-
string.contains('{'),
40+
let Some(par) = string.find('{'),
41+
string[par..].contains('}'),
4142
let Some(sp) = cx.sess().codemap()
4243
.with_expn_info(expr.span.expn_id,
4344
|info| info.map(|i| i.call_site))

src/utils/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,14 @@ fn trim_multiline_inner(s: Cow<str>, ignore_first: bool, ch: char) -> Cow<str> {
383383
let x = s.lines()
384384
.skip(ignore_first as usize)
385385
.filter_map(|l| {
386-
if l.len() > 0 {
386+
if l.is_empty() {
387+
None
388+
} else {
387389
// ignore empty lines
388390
Some(l.char_indices()
389391
.find(|&(_, x)| x != ch)
390392
.unwrap_or((l.len(), ch))
391393
.0)
392-
} else {
393-
None
394394
}
395395
})
396396
.min()
@@ -399,7 +399,7 @@ fn trim_multiline_inner(s: Cow<str>, ignore_first: bool, ch: char) -> Cow<str> {
399399
Cow::Owned(s.lines()
400400
.enumerate()
401401
.map(|(i, l)| {
402-
if (ignore_first && i == 0) || l.len() == 0 {
402+
if (ignore_first && i == 0) || l.is_empty() {
403403
l
404404
} else {
405405
l.split_at(x).1

tests/compile-fail/len_zero.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ fn main() {
7676
println!("This should not happen!");
7777
}
7878

79+
if "".len() == 0 {
80+
//~^ERROR length comparison to zero
81+
//~|HELP consider using `is_empty`
82+
//~|SUGGESTION "".is_empty()
83+
}
84+
7985
let y = One;
8086
if y.len() == 0 { //no error because One does not have .is_empty()
8187
println!("This should not happen either!");

tests/compile-fail/panic.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,33 @@
44
#[deny(panic_params)]
55

66
fn missing() {
7-
panic!("{}"); //~ERROR: You probably are missing some parameter
7+
if true {
8+
panic!("{}"); //~ERROR: You probably are missing some parameter
9+
} else {
10+
panic!("{:?}"); //~ERROR: You probably are missing some parameter
11+
}
812
}
913

10-
fn ok_sigle() {
14+
fn ok_single() {
1115
panic!("foo bar");
1216
}
1317

1418
fn ok_multiple() {
1519
panic!("{}", "This is {ok}");
1620
}
1721

22+
fn ok_bracket() {
23+
// the match is just here because of #759, it serves no other purpose for the lint
24+
match 42 {
25+
1337 => panic!("{so is this"),
26+
666 => panic!("so is this}"),
27+
_ => panic!("}so is that{"),
28+
}
29+
}
30+
1831
fn main() {
1932
missing();
20-
ok_sigle();
33+
ok_single();
2134
ok_multiple();
35+
ok_bracket();
2236
}

0 commit comments

Comments
 (0)