Compute the source location for the pattern's anchor token(s). Returns `(line_start, col_start, line_end, col_end)` where lines are 1-indexed and columns are 0-indexed (proc_macro2 convention). Returns `(0, 0, 0, 0)` for patterns without a meaningful source location. Computes start and end from constituent tokens independently to avoid `Span::join()`, which is nightly-only in proc_macro context.
(&self)
| 103 | /// for the end. Enum and struct paths highlight only the type path, not the |
| 104 | /// arguments or fields that follow. |
| 105 | pub(crate) fn location(&self) -> (u32, u32, u32, u32) { |
| 106 | match self { |
| 107 | Pattern::Simple(PatternSimple { expr, .. }) => { |
| 108 | let start = expr.span().start(); |
| 109 | let end = expr.span().end(); |
| 110 | ( |
| 111 | start.line as u32, |
| 112 | start.column as u32, |
| 113 | end.line as u32, |
| 114 | end.column as u32, |
| 115 | ) |
| 116 | } |
| 117 | Pattern::String(PatternString { lit, .. }) => { |
| 118 | let start = lit.span().start(); |
| 119 | let end = lit.span().end(); |
| 120 | ( |
| 121 | start.line as u32, |
| 122 | start.column as u32, |
| 123 | end.line as u32, |
| 124 | end.column as u32, |
| 125 | ) |
| 126 | } |
| 127 | Pattern::Comparison(PatternComparison { op, expr, .. }) => { |
| 128 | let start = op.span().start(); |
| 129 | let end = expr.span().end(); |
| 130 | ( |
| 131 | start.line as u32, |
| 132 | start.column as u32, |
| 133 | end.line as u32, |
| 134 | end.column as u32, |
| 135 | ) |
| 136 | } |
| 137 | Pattern::Range(PatternRange { expr, .. }) => { |
| 138 | if let syn::Expr::Range(range_expr) = expr { |
| 139 | let start = range_expr |
| 140 | .start |
| 141 | .as_ref() |
| 142 | .map(|s| s.span().start()) |
| 143 | .unwrap_or_else(|| range_expr.limits.span().start()); |
| 144 | let end = range_expr |
| 145 | .end |
| 146 | .as_ref() |
| 147 | .map(|e| e.span().end()) |
| 148 | .unwrap_or_else(|| range_expr.limits.span().end()); |
| 149 | ( |
| 150 | start.line as u32, |
| 151 | start.column as u32, |
| 152 | end.line as u32, |
| 153 | end.column as u32, |
| 154 | ) |
| 155 | } else { |
| 156 | let start = expr.span().start(); |
| 157 | let end = expr.span().end(); |
| 158 | ( |
| 159 | start.line as u32, |
| 160 | start.column as u32, |
| 161 | end.line as u32, |
| 162 | end.column as u32, |
no test coverage detected