|
1 | 1 | use rustc_data_structures::fx::FxHashMap;
|
2 | 2 |
|
3 |
| -use clippy_utils::diagnostics::{span_lint, span_lint_and_then}; |
| 3 | +use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; |
4 | 4 | use clippy_utils::paths;
|
5 | 5 | use clippy_utils::ty::match_type;
|
6 | 6 | use rustc_ast::ast::LitKind;
|
@@ -120,49 +120,39 @@ fn check_open_options(cx: &LateContext<'_>, settings: &[(OpenOption, Argument, S
|
120 | 120 | }
|
121 | 121 | }
|
122 | 122 |
|
123 |
| - if_chain! { |
124 |
| - if let Some((Argument::Set(true), _)) = options.get(&OpenOption::Read); |
125 |
| - if let Some((Argument::Set(true), _)) = options.get(&OpenOption::Truncate); |
126 |
| - if let None | Some((Argument::Set(false), _)) = options.get(&OpenOption::Write); |
127 |
| - then { |
| 123 | + if let Some((Argument::Set(true), _)) = options.get(&OpenOption::Read) |
| 124 | + && let Some((Argument::Set(true), _)) = options.get(&OpenOption::Truncate) |
| 125 | + && let None | Some((Argument::Set(false), _)) = options.get(&OpenOption::Write) |
| 126 | + { |
128 | 127 | span_lint(
|
129 | 128 | cx,
|
130 | 129 | NONSENSICAL_OPEN_OPTIONS,
|
131 | 130 | span,
|
132 | 131 | "file opened with `truncate` and `read`",
|
133 | 132 | );
|
134 | 133 | }
|
135 |
| - } |
136 | 134 |
|
137 |
| - if_chain! { |
138 |
| - if let Some((Argument::Set(true), _)) = options.get(&OpenOption::Append); |
139 |
| - if let Some((Argument::Set(true), _)) = options.get(&OpenOption::Truncate); |
140 |
| - if let None | Some((Argument::Set(false), _)) = options.get(&OpenOption::Write); |
141 |
| - then { |
| 135 | + if let Some((Argument::Set(true), _)) = options.get(&OpenOption::Append) |
| 136 | + && let Some((Argument::Set(true), _)) = options.get(&OpenOption::Truncate) |
| 137 | + { |
142 | 138 | span_lint(
|
143 | 139 | cx,
|
144 | 140 | NONSENSICAL_OPEN_OPTIONS,
|
145 | 141 | span,
|
146 | 142 | "file opened with `append` and `truncate`",
|
147 | 143 | );
|
148 |
| - } |
149 | 144 | }
|
150 | 145 |
|
151 |
| - if_chain! { |
152 |
| - if let Some((Argument::Set(true), create_span)) = options.get(&OpenOption::Create); |
153 |
| - if let None = options.get(&OpenOption::Truncate); |
154 |
| - then { |
155 |
| - span_lint_and_then( |
| 146 | + if let Some((Argument::Set(true), create_span)) = options.get(&OpenOption::Create) |
| 147 | + && let None = options.get(&OpenOption::Truncate) |
| 148 | + { |
| 149 | + span_lint_and_help( |
156 | 150 | cx,
|
157 | 151 | SUSPICIOUS_OPEN_OPTIONS,
|
158 | 152 | *create_span,
|
159 | 153 | "file opened with `create`, but `truncate` behavior not defined",
|
160 |
| - |diag| { |
161 |
| - diag |
162 |
| - //.span_suggestion(create_span.shrink_to_hi(), "add", ".truncate(true)".to_string(), rustc_errors::Applicability::MaybeIncorrect) |
163 |
| - .help("if you intend to overwrite an existing file entirely, call `.truncate(true)`. if you instead know that you may want to keep some parts of the old file, call `.truncate(false)`"); |
164 |
| - }, |
| 154 | + Some(span), |
| 155 | + "if you intend to overwrite an existing file entirely, call `.truncate(true)`. if you instead know that you may want to keep some parts of the old file, call `.truncate(false)`" |
165 | 156 | );
|
166 |
| - } |
167 | 157 | }
|
168 | 158 | }
|
0 commit comments