about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/ty.rs
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-11-28 15:06:37 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2024-11-28 17:01:50 +1100
commit90ad2adfea5a7f4baebb083cd3a190fa491d0ec8 (patch)
tree2dc01463e4066a86f7e5410c75963b6668d21438 /compiler/rustc_parse/src/parser/ty.rs
parent6b6a867ae9eac4e78d041ac4ee84be1072a48cf7 (diff)
downloadrust-90ad2adfea5a7f4baebb083cd3a190fa491d0ec8.tar.gz
rust-90ad2adfea5a7f4baebb083cd3a190fa491d0ec8.zip
Improve span handling in `parse_expr_bottom`.
`parse_expr_bottom` stores `this.token.span` in `lo`, but then fails to
use it in many places where it could. This commit fixes that, and
likewise (to a smaller extent) in `parse_ty_common`.
Diffstat (limited to 'compiler/rustc_parse/src/parser/ty.rs')
-rw-r--r--compiler/rustc_parse/src/parser/ty.rs11
1 files changed, 4 insertions, 7 deletions
diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs
index c561ea3823d..505586e74f1 100644
--- a/compiler/rustc_parse/src/parser/ty.rs
+++ b/compiler/rustc_parse/src/parser/ty.rs
@@ -274,7 +274,6 @@ impl<'a> Parser<'a> {
             // Function pointer type
             self.parse_ty_bare_fn(lo, ThinVec::new(), None, recover_return_sign)?
         } else if self.check_keyword(kw::For) {
-            let for_span = self.token.span;
             // Function pointer type or bound list (trait object type) starting with a poly-trait.
             //   `for<'lt> [unsafe] [extern "ABI"] fn (&'lt S) -> T`
             //   `for<'lt> Trait1<'lt> + Trait2 + 'a`
@@ -302,7 +301,7 @@ impl<'a> Parser<'a> {
                         kw: kw.name.as_str(),
                         sugg: errors::TransposeDynOrImplSugg {
                             removal_span,
-                            insertion_span: for_span.shrink_to_lo(),
+                            insertion_span: lo.shrink_to_lo(),
                             kw: kw.name.as_str(),
                         },
                     });
@@ -345,16 +344,14 @@ impl<'a> Parser<'a> {
                     // FIXME(c_variadic): Should we just allow `...` syntactically
                     // anywhere in a type and use semantic restrictions instead?
                     // NOTE: This may regress certain MBE calls if done incorrectly.
-                    let guar = self
-                        .dcx()
-                        .emit_err(NestedCVariadicType { span: lo.to(self.prev_token.span) });
+                    let guar = self.dcx().emit_err(NestedCVariadicType { span: lo });
                     TyKind::Err(guar)
                 }
             }
         } else {
             let msg = format!("expected type, found {}", super::token_descr(&self.token));
-            let mut err = self.dcx().struct_span_err(self.token.span, msg);
-            err.span_label(self.token.span, "expected type");
+            let mut err = self.dcx().struct_span_err(lo, msg);
+            err.span_label(lo, "expected type");
             return Err(err);
         };