diff options
| author | Jason Newcomb <jsnewcomb@pm.me> | 2025-07-14 08:15:29 -0400 |
|---|---|---|
| committer | Jason Newcomb <jsnewcomb@pm.me> | 2025-07-14 10:57:27 -0400 |
| commit | 104e265b9601106d6a6a44edc2845922a911fbd9 (patch) | |
| tree | 59e5dc9b07e2f2d2d7f50e86047b04716ef9e936 | |
| parent | 06e6927d55047ed779400b62323d7214e8a6830c (diff) | |
| download | rust-104e265b9601106d6a6a44edc2845922a911fbd9.tar.gz rust-104e265b9601106d6a6a44edc2845922a911fbd9.zip | |
`ineffective_open_options`: don't subtract a constant `BytePos`
| -rw-r--r-- | clippy_lints/src/ineffective_open_options.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/clippy_lints/src/ineffective_open_options.rs b/clippy_lints/src/ineffective_open_options.rs index 424f069f5a8..a159f615718 100644 --- a/clippy_lints/src/ineffective_open_options.rs +++ b/clippy_lints/src/ineffective_open_options.rs @@ -1,4 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; +use clippy_utils::source::SpanRangeExt; use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::{peel_blocks, peel_hir_expr_while, sym}; use rustc_ast::LitKind; @@ -6,7 +7,6 @@ use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; -use rustc_span::BytePos; declare_clippy_lint! { /// ### What it does @@ -63,7 +63,17 @@ impl<'tcx> LateLintPass<'tcx> for IneffectiveOpenOptions { { match name.ident.name { sym::append => append = true, - sym::write => write = Some(call_span.with_lo(call_span.lo() - BytePos(1))), + sym::write + if let Some(range) = call_span.map_range(cx, |_, text, range| { + if text.get(..range.start)?.ends_with('.') { + Some(range.start - 1..range.end) + } else { + None + } + }) => + { + write = Some(call_span.with_lo(range.start)); + }, _ => {}, } } |
