Skip to content

Commit c7ce6c0

Browse files
author
Oliver Schneider
committed
Rustup field -> method transition of ..=
1 parent 8f1a98f commit c7ce6c0

File tree

5 files changed

+19
-28
lines changed

5 files changed

+19
-28
lines changed

clippy_lints/src/utils/higher.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ pub fn range(expr: &hir::Expr) -> Option<Range> {
6969
None
7070
}
7171
},
72+
hir::ExprCall(ref path, ref args) => if let hir::ExprPath(ref path) = path.node {
73+
if match_qpath(path, &paths::RANGE_INCLUSIVE_STD_NEW) || match_qpath(path, &paths::RANGE_INCLUSIVE_NEW) {
74+
Some(Range {
75+
start: Some(&args[0]),
76+
end: Some(&args[1]),
77+
limits: ast::RangeLimits::Closed,
78+
})
79+
} else {
80+
None
81+
}
82+
} else {
83+
None
84+
},
7285
hir::ExprStruct(ref path, ref fields, None) => if match_qpath(path, &paths::RANGE_FROM_STD)
7386
|| match_qpath(path, &paths::RANGE_FROM)
7487
{
@@ -77,12 +90,6 @@ pub fn range(expr: &hir::Expr) -> Option<Range> {
7790
end: None,
7891
limits: ast::RangeLimits::HalfOpen,
7992
})
80-
} else if match_qpath(path, &paths::RANGE_INCLUSIVE_STD) || match_qpath(path, &paths::RANGE_INCLUSIVE) {
81-
Some(Range {
82-
start: Some(get_field("start", fields)?),
83-
end: Some(get_field("end", fields)?),
84-
limits: ast::RangeLimits::Closed,
85-
})
8693
} else if match_qpath(path, &paths::RANGE_STD) || match_qpath(path, &paths::RANGE) {
8794
Some(Range {
8895
start: Some(get_field("start", fields)?),

clippy_lints/src/utils/paths.rs

+2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ pub const RANGE_FROM_STD: [&str; 3] = ["std", "ops", "RangeFrom"];
6666
pub const RANGE_FULL: [&str; 3] = ["core", "ops", "RangeFull"];
6767
pub const RANGE_FULL_STD: [&str; 3] = ["std", "ops", "RangeFull"];
6868
pub const RANGE_INCLUSIVE: [&str; 3] = ["core", "ops", "RangeInclusive"];
69+
pub const RANGE_INCLUSIVE_NEW: [&str; 4] = ["core", "ops", "RangeInclusive", "new"];
6970
pub const RANGE_INCLUSIVE_STD: [&str; 3] = ["std", "ops", "RangeInclusive"];
71+
pub const RANGE_INCLUSIVE_STD_NEW: [&str; 4] = ["std", "ops", "RangeInclusive", "new"];
7072
pub const RANGE_STD: [&str; 3] = ["std", "ops", "Range"];
7173
pub const RANGE_TO: [&str; 3] = ["core", "ops", "RangeTo"];
7274
pub const RANGE_TO_INCLUSIVE: [&str; 3] = ["core", "ops", "RangeToInclusive"];

tests/ui/no_effect.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@ error: statement with no effect
108108
76 | 5..6;
109109
| ^^^^^
110110

111-
error: statement with no effect
112-
--> $DIR/no_effect.rs:77:5
113-
|
114-
77 | 5..=6;
115-
| ^^^^^^
116-
117111
error: statement with no effect
118112
--> $DIR/no_effect.rs:78:5
119113
|
@@ -278,5 +272,5 @@ error: statement can be reduced
278272
116 | FooString { s: String::from("blah"), };
279273
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `String::from("blah");`
280274

281-
error: aborting due to 46 previous errors
275+
error: aborting due to 45 previous errors
282276

tests/ui/redundant_field_names.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![warn(redundant_field_names)]
22
#![allow(unused_variables)]
3-
#![feature(inclusive_range, inclusive_range_fields)]
3+
#![feature(inclusive_range, inclusive_range_fields, inclusive_range_methods)]
44

55
#[macro_use]
66
extern crate derive_new;
@@ -53,6 +53,6 @@ fn main() {
5353
let _ = RangeFrom { start: start };
5454
let _ = RangeTo { end: end };
5555
let _ = Range { start: start, end: end };
56-
let _ = RangeInclusive { start: start, end: end };
56+
let _ = RangeInclusive::new(start, end);
5757
let _ = RangeToInclusive { end: end };
5858
}

tests/ui/redundant_field_names.stderr

+1-13
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,11 @@ error: redundant field names in struct initialization
3636
55 | let _ = Range { start: start, end: end };
3737
| ^^^^^^^^ help: replace it with: `end`
3838

39-
error: redundant field names in struct initialization
40-
--> $DIR/redundant_field_names.rs:56:30
41-
|
42-
56 | let _ = RangeInclusive { start: start, end: end };
43-
| ^^^^^^^^^^^^ help: replace it with: `start`
44-
45-
error: redundant field names in struct initialization
46-
--> $DIR/redundant_field_names.rs:56:44
47-
|
48-
56 | let _ = RangeInclusive { start: start, end: end };
49-
| ^^^^^^^^ help: replace it with: `end`
50-
5139
error: redundant field names in struct initialization
5240
--> $DIR/redundant_field_names.rs:57:32
5341
|
5442
57 | let _ = RangeToInclusive { end: end };
5543
| ^^^^^^^^ help: replace it with: `end`
5644

57-
error: aborting due to 9 previous errors
45+
error: aborting due to 7 previous errors
5846

0 commit comments

Comments
 (0)