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