Skip to content

Commit b7c6c30

Browse files
Change lint description
1 parent 7644f8e commit b7c6c30

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ name
4242
[needless_range_loop](https://github.com/Manishearth/rust-clippy/wiki#needless_range_loop) | warn | for-looping over a range of indices where an iterator over items would do
4343
[needless_return](https://github.com/Manishearth/rust-clippy/wiki#needless_return) | warn | using a return statement like `return expr;` where an expression would suffice
4444
[non_ascii_literal](https://github.com/Manishearth/rust-clippy/wiki#non_ascii_literal) | allow | using any literal non-ASCII chars in a string literal; suggests using the \\u escape instead
45-
[nonsensical_open_options](https://github.com/Manishearth/rust-clippy/wiki#nonsensical_open_options) | warn | The options used for opening a file are nonsensical
45+
[nonsensical_open_options](https://github.com/Manishearth/rust-clippy/wiki#nonsensical_open_options) | warn | nonsensical combination of options for opening a file
4646
[option_unwrap_used](https://github.com/Manishearth/rust-clippy/wiki#option_unwrap_used) | allow | using `Option.unwrap()`, which should at least get a better message using `expect()`
4747
[precedence](https://github.com/Manishearth/rust-clippy/wiki#precedence) | warn | catches operations where precedence may be unclear. See the wiki for a list of cases caught
4848
[ptr_arg](https://github.com/Manishearth/rust-clippy/wiki#ptr_arg) | allow | fn arguments of the type `&Vec<...>` or `&String`, suggesting to use `&[...]` or `&str` instead, respectively

src/open_options.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use syntax::ast::Lit_::LitBool;
77
declare_lint! {
88
pub NONSENSICAL_OPEN_OPTIONS,
99
Warn,
10-
"The options used for opening a file are nonsensical"
10+
"nonsensical combination of options for opening a file"
1111
}
1212

1313

@@ -42,14 +42,14 @@ enum Argument {
4242

4343
#[derive(Debug)]
4444
enum OpenOption {
45-
Write(Argument),
46-
Read(Argument),
47-
Truncate(Argument),
48-
Create(Argument),
49-
Append(Argument)
45+
Write,
46+
Read,
47+
Truncate,
48+
Create,
49+
Append
5050
}
5151

52-
fn get_open_options(cx: &LateContext, argument: &Expr, options: &mut Vec<OpenOption>) {
52+
fn get_open_options(cx: &LateContext, argument: &Expr, options: &mut Vec<(OpenOption, Argument)>) {
5353
if let ExprMethodCall(ref name, _, ref arguments) = argument.node {
5454
let (obj_ty, _) = walk_ptrs_ty_depth(cx.tcx.expr_ty(&arguments[0]));
5555

@@ -73,19 +73,19 @@ fn get_open_options(cx: &LateContext, argument: &Expr, options: &mut Vec<OpenOpt
7373

7474
match &*name.node.as_str() {
7575
"create" => {
76-
options.push(OpenOption::Create(argument_option));
76+
options.push((OpenOption::Create, argument_option));
7777
},
7878
"append" => {
79-
options.push(OpenOption::Append(argument_option));
79+
options.push((OpenOption::Append, argument_option));
8080
},
8181
"truncate" => {
82-
options.push(OpenOption::Truncate(argument_option));
82+
options.push((OpenOption::Truncate, argument_option));
8383
},
8484
"read" => {
85-
options.push(OpenOption::Read(argument_option));
85+
options.push((OpenOption::Read, argument_option));
8686
},
8787
"write" => {
88-
options.push(OpenOption::Write(argument_option));
88+
options.push((OpenOption::Write, argument_option));
8989
},
9090
_ => {}
9191
}
@@ -95,45 +95,45 @@ fn get_open_options(cx: &LateContext, argument: &Expr, options: &mut Vec<OpenOpt
9595
}
9696
}
9797

98-
fn check_for_duplicates(cx: &LateContext, options: &[OpenOption], span: Span) {
98+
fn check_for_duplicates(cx: &LateContext, options: &[(OpenOption, Argument)], span: Span) {
9999
// This code is almost duplicated (oh, the irony), but I haven't found a way to unify it.
100-
if options.iter().filter(|o| if let OpenOption::Create(_) = **o {true} else {false}).count() > 1 {
100+
if options.iter().filter(|o| if let (OpenOption::Create, _) = **o {true} else {false}).count() > 1 {
101101
span_lint(cx, NONSENSICAL_OPEN_OPTIONS, span, "The method \"create\" \
102102
is called more than once");
103103
}
104-
if options.iter().filter(|o| if let OpenOption::Append(_) = **o {true} else {false}).count() > 1 {
104+
if options.iter().filter(|o| if let (OpenOption::Append, _) = **o {true} else {false}).count() > 1 {
105105
span_lint(cx, NONSENSICAL_OPEN_OPTIONS, span, "The method \"append\" \
106106
is called more than once");
107107
}
108-
if options.iter().filter(|o| if let OpenOption::Truncate(_) = **o {true} else {false}).count() > 1 {
108+
if options.iter().filter(|o| if let (OpenOption::Truncate, _) = **o {true} else {false}).count() > 1 {
109109
span_lint(cx, NONSENSICAL_OPEN_OPTIONS, span, "The method \"truncate\" \
110110
is called more than once");
111111
}
112-
if options.iter().filter(|o| if let OpenOption::Read(_) = **o {true} else {false}).count() > 1 {
112+
if options.iter().filter(|o| if let (OpenOption::Read, _) = **o {true} else {false}).count() > 1 {
113113
span_lint(cx, NONSENSICAL_OPEN_OPTIONS, span, "The method \"read\" \
114114
is called more than once");
115115
}
116-
if options.iter().filter(|o| if let OpenOption::Write(_) = **o {true} else {false}).count() > 1 {
116+
if options.iter().filter(|o| if let (OpenOption::Write, _) = **o {true} else {false}).count() > 1 {
117117
span_lint(cx, NONSENSICAL_OPEN_OPTIONS, span, "The method \"write\" \
118118
is called more than once");
119119
}
120120
}
121121

122-
fn check_for_inconsistencies(cx: &LateContext, options: &[OpenOption], span: Span) {
122+
fn check_for_inconsistencies(cx: &LateContext, options: &[(OpenOption, Argument)], span: Span) {
123123
// Truncate + read makes no sense.
124-
if options.iter().filter(|o| if let OpenOption::Read(Argument::True) = **o {true} else {false}).count() > 0 &&
125-
options.iter().filter(|o| if let OpenOption::Truncate(Argument::True) = **o {true} else {false}).count() > 0 {
124+
if options.iter().filter(|o| if let (OpenOption::Read, Argument::True) = **o {true} else {false}).count() > 0 &&
125+
options.iter().filter(|o| if let (OpenOption::Truncate, Argument::True) = **o {true} else {false}).count() > 0 {
126126
span_lint(cx, NONSENSICAL_OPEN_OPTIONS, span, "File opened with \"truncate\" and \"read\"");
127127
}
128128

129129
// Append + truncate makes no sense.
130-
if options.iter().filter(|o| if let OpenOption::Append(Argument::True) = **o {true} else {false}).count() > 0 &&
131-
options.iter().filter(|o| if let OpenOption::Truncate(Argument::True) = **o {true} else {false}).count() > 0 {
130+
if options.iter().filter(|o| if let (OpenOption::Append, Argument::True) = **o {true} else {false}).count() > 0 &&
131+
options.iter().filter(|o| if let (OpenOption::Truncate, Argument::True) = **o {true} else {false}).count() > 0 {
132132
span_lint(cx, NONSENSICAL_OPEN_OPTIONS, span, "File opened with \"append\" and \"truncate\"");
133133
}
134134
}
135135

136-
fn check_open_options(cx: &LateContext, options: &[OpenOption], span: Span) {
136+
fn check_open_options(cx: &LateContext, options: &[(OpenOption, Argument)], span: Span) {
137137
check_for_duplicates(cx, options, span);
138138
check_for_inconsistencies(cx, options, span);
139139
}

0 commit comments

Comments
 (0)