Rustup field -> method transition of ..=

This commit is contained in:
Oliver Schneider 2018-05-03 15:52:44 +02:00
parent 8f1a98ff08
commit c7ce6c07b1
5 changed files with 19 additions and 28 deletions

View File

@ -69,6 +69,19 @@ pub fn range(expr: &hir::Expr) -> Option<Range> {
None
}
},
hir::ExprCall(ref path, ref args) => if let hir::ExprPath(ref path) = path.node {
if match_qpath(path, &paths::RANGE_INCLUSIVE_STD_NEW) || match_qpath(path, &paths::RANGE_INCLUSIVE_NEW) {
Some(Range {
start: Some(&args[0]),
end: Some(&args[1]),
limits: ast::RangeLimits::Closed,
})
} else {
None
}
} else {
None
},
hir::ExprStruct(ref path, ref fields, None) => if match_qpath(path, &paths::RANGE_FROM_STD)
|| match_qpath(path, &paths::RANGE_FROM)
{
@ -77,12 +90,6 @@ pub fn range(expr: &hir::Expr) -> Option<Range> {
end: None,
limits: ast::RangeLimits::HalfOpen,
})
} else if match_qpath(path, &paths::RANGE_INCLUSIVE_STD) || match_qpath(path, &paths::RANGE_INCLUSIVE) {
Some(Range {
start: Some(get_field("start", fields)?),
end: Some(get_field("end", fields)?),
limits: ast::RangeLimits::Closed,
})
} else if match_qpath(path, &paths::RANGE_STD) || match_qpath(path, &paths::RANGE) {
Some(Range {
start: Some(get_field("start", fields)?),

View File

@ -66,7 +66,9 @@ pub const RANGE_FROM_STD: [&str; 3] = ["std", "ops", "RangeFrom"];
pub const RANGE_FULL: [&str; 3] = ["core", "ops", "RangeFull"];
pub const RANGE_FULL_STD: [&str; 3] = ["std", "ops", "RangeFull"];
pub const RANGE_INCLUSIVE: [&str; 3] = ["core", "ops", "RangeInclusive"];
pub const RANGE_INCLUSIVE_NEW: [&str; 4] = ["core", "ops", "RangeInclusive", "new"];
pub const RANGE_INCLUSIVE_STD: [&str; 3] = ["std", "ops", "RangeInclusive"];
pub const RANGE_INCLUSIVE_STD_NEW: [&str; 4] = ["std", "ops", "RangeInclusive", "new"];
pub const RANGE_STD: [&str; 3] = ["std", "ops", "Range"];
pub const RANGE_TO: [&str; 3] = ["core", "ops", "RangeTo"];
pub const RANGE_TO_INCLUSIVE: [&str; 3] = ["core", "ops", "RangeToInclusive"];

View File

@ -108,12 +108,6 @@ error: statement with no effect
76 | 5..6;
| ^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:77:5
|
77 | 5..=6;
| ^^^^^^
error: statement with no effect
--> $DIR/no_effect.rs:78:5
|
@ -278,5 +272,5 @@ error: statement can be reduced
116 | FooString { s: String::from("blah"), };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `String::from("blah");`
error: aborting due to 46 previous errors
error: aborting due to 45 previous errors

View File

@ -1,6 +1,6 @@
#![warn(redundant_field_names)]
#![allow(unused_variables)]
#![feature(inclusive_range, inclusive_range_fields)]
#![feature(inclusive_range, inclusive_range_fields, inclusive_range_methods)]
#[macro_use]
extern crate derive_new;
@ -53,6 +53,6 @@ fn main() {
let _ = RangeFrom { start: start };
let _ = RangeTo { end: end };
let _ = Range { start: start, end: end };
let _ = RangeInclusive { start: start, end: end };
let _ = RangeInclusive::new(start, end);
let _ = RangeToInclusive { end: end };
}

View File

@ -36,23 +36,11 @@ error: redundant field names in struct initialization
55 | let _ = Range { start: start, end: end };
| ^^^^^^^^ help: replace it with: `end`
error: redundant field names in struct initialization
--> $DIR/redundant_field_names.rs:56:30
|
56 | let _ = RangeInclusive { start: start, end: end };
| ^^^^^^^^^^^^ help: replace it with: `start`
error: redundant field names in struct initialization
--> $DIR/redundant_field_names.rs:56:44
|
56 | let _ = RangeInclusive { start: start, end: end };
| ^^^^^^^^ help: replace it with: `end`
error: redundant field names in struct initialization
--> $DIR/redundant_field_names.rs:57:32
|
57 | let _ = RangeToInclusive { end: end };
| ^^^^^^^^ help: replace it with: `end`
error: aborting due to 9 previous errors
error: aborting due to 7 previous errors