|
| 1 | +use super::errors::{ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding}; |
1 | 2 | use super::ResolverAstLoweringExt; |
2 | 3 | use super::{ImplTraitContext, LoweringContext, ParamMode}; |
3 | 4 | use crate::ImplTraitPosition; |
4 | 5 |
|
5 | 6 | use rustc_ast::ptr::P; |
6 | 7 | use rustc_ast::*; |
7 | 8 | use rustc_data_structures::stack::ensure_sufficient_stack; |
8 | | -use rustc_errors::Applicability; |
9 | 9 | use rustc_hir as hir; |
10 | 10 | use rustc_hir::def::Res; |
11 | 11 | use rustc_span::symbol::Ident; |
@@ -134,20 +134,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { |
134 | 134 | // This is not allowed as a sub-tuple pattern |
135 | 135 | PatKind::Ident(ref _bm, ident, Some(ref sub)) if sub.is_rest() => { |
136 | 136 | let sp = pat.span; |
137 | | - self.diagnostic() |
138 | | - .struct_span_err( |
139 | | - sp, |
140 | | - &format!("`{} @` is not allowed in a {}", ident.name, ctx), |
141 | | - ) |
142 | | - .span_label(sp, "this is only allowed in slice patterns") |
143 | | - .help("remove this and bind each tuple field independently") |
144 | | - .span_suggestion_verbose( |
145 | | - sp, |
146 | | - &format!("if you don't need to use the contents of {}, discard the tuple's remaining fields", ident), |
147 | | - "..", |
148 | | - Applicability::MaybeIncorrect, |
149 | | - ) |
150 | | - .emit(); |
| 137 | + self.tcx.sess.emit_err(SubTupleBinding { |
| 138 | + span: sp, |
| 139 | + ident_name: ident.name, |
| 140 | + ident, |
| 141 | + ctx, |
| 142 | + }); |
151 | 143 | } |
152 | 144 | _ => {} |
153 | 145 | } |
@@ -296,19 +288,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { |
296 | 288 |
|
297 | 289 | /// Emit a friendly error for extra `..` patterns in a tuple/tuple struct/slice pattern. |
298 | 290 | pub(crate) fn ban_extra_rest_pat(&self, sp: Span, prev_sp: Span, ctx: &str) { |
299 | | - self.diagnostic() |
300 | | - .struct_span_err(sp, &format!("`..` can only be used once per {} pattern", ctx)) |
301 | | - .span_label(sp, &format!("can only be used once per {} pattern", ctx)) |
302 | | - .span_label(prev_sp, "previously used here") |
303 | | - .emit(); |
| 291 | + self.tcx.sess.emit_err(ExtraDoubleDot { span: sp, prev_span: prev_sp, ctx }); |
304 | 292 | } |
305 | 293 |
|
306 | 294 | /// Used to ban the `..` pattern in places it shouldn't be semantically. |
307 | 295 | fn ban_illegal_rest_pat(&self, sp: Span) -> hir::PatKind<'hir> { |
308 | | - self.diagnostic() |
309 | | - .struct_span_err(sp, "`..` patterns are not allowed here") |
310 | | - .note("only allowed in tuple, tuple struct, and slice patterns") |
311 | | - .emit(); |
| 296 | + self.tcx.sess.emit_err(MisplacedDoubleDot { span: sp }); |
312 | 297 |
|
313 | 298 | // We're not in a list context so `..` can be reasonably treated |
314 | 299 | // as `_` because it should always be valid and roughly matches the |
|
0 commit comments