Skip to content

Commit 104e265

Browse files
committed
ineffective_open_options: don't subtract a constant BytePos
1 parent 06e6927 commit 104e265

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

clippy_lints/src/ineffective_open_options.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2+
use clippy_utils::source::SpanRangeExt;
23
use clippy_utils::ty::is_type_diagnostic_item;
34
use clippy_utils::{peel_blocks, peel_hir_expr_while, sym};
45
use rustc_ast::LitKind;
56
use rustc_errors::Applicability;
67
use rustc_hir::{Expr, ExprKind};
78
use rustc_lint::{LateContext, LateLintPass};
89
use rustc_session::declare_lint_pass;
9-
use rustc_span::BytePos;
1010

1111
declare_clippy_lint! {
1212
/// ### What it does
@@ -63,7 +63,17 @@ impl<'tcx> LateLintPass<'tcx> for IneffectiveOpenOptions {
6363
{
6464
match name.ident.name {
6565
sym::append => append = true,
66-
sym::write => write = Some(call_span.with_lo(call_span.lo() - BytePos(1))),
66+
sym::write
67+
if let Some(range) = call_span.map_range(cx, |_, text, range| {
68+
if text.get(..range.start)?.ends_with('.') {
69+
Some(range.start - 1..range.end)
70+
} else {
71+
None
72+
}
73+
}) =>
74+
{
75+
write = Some(call_span.with_lo(range.start));
76+
},
6777
_ => {},
6878
}
6979
}

0 commit comments

Comments
 (0)