about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorCaleb Cartwright <calebcartwright@users.noreply.github.com>2021-06-24 18:22:28 -0500
committerCaleb Cartwright <calebcartwright@users.noreply.github.com>2021-07-25 22:53:32 -0500
commitb305d62e5b9e08c6f4540de0a349fbf6da3dc0e4 (patch)
tree91c0b7b4d05f417567592f027bb63ef433d5f5b2 /src
parente634a6f9a8ad9435f2d9f6bbfb6a8eb018ee8e3f (diff)
downloadrust-b305d62e5b9e08c6f4540de0a349fbf6da3dc0e4.tar.gz
rust-b305d62e5b9e08c6f4540de0a349fbf6da3dc0e4.zip
fix: correct arm leading pipe check (#4880)
In the event a pattern starts with a leading pipe
the pattern span will contain, and begin with, the pipe.

This updates the process to see if a match arm contains
a leading pipe by leveraging this recent(ish) change to
the patterns in the AST, and avoids an indexing bug that
occurs when a pattern starts with a non-ascii char in the
old implementation.
Diffstat (limited to 'src')
-rw-r--r--src/matches.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/matches.rs b/src/matches.rs
index f33fedce92d..140ec226c02 100644
--- a/src/matches.rs
+++ b/src/matches.rs
@@ -19,7 +19,7 @@ use crate::source_map::SpanUtils;
 use crate::spanned::Spanned;
 use crate::utils::{
     contains_skip, extra_offset, first_line_width, inner_attributes, last_line_extendable, mk_sp,
-    mk_sp_lo_plus_one, semicolon_for_expr, trimmed_last_line_width, unicode_str_width,
+    semicolon_for_expr, trimmed_last_line_width, unicode_str_width,
 };
 
 /// A simple wrapper type against `ast::Arm`. Used inside `write_list()`.
@@ -167,8 +167,9 @@ fn collect_beginning_verts(
     arms.iter()
         .map(|a| {
             context
-                .snippet_provider
-                .opt_span_before(mk_sp_lo_plus_one(a.pat.span.lo()), "|")
+                .snippet(a.pat.span)
+                .starts_with("|")
+                .then(|| a.pat.span().lo())
         })
         .collect()
 }