diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-07-04 05:47:27 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-04 05:47:27 +0200 |
| commit | 05f5690d81ef8ea55edac774b3646daa1e3e1575 (patch) | |
| tree | 9f85a7ab5db029d62955b2f71d56929c505697f7 /compiler/rustc_parse/src/parser/generics.rs | |
| parent | e55514bbbe988f387bcf16b496cc3f1112e4e3e9 (diff) | |
| parent | 3380bfd1a00fe3f85e8597bfdb9ad4d65df75da9 (diff) | |
| download | rust-05f5690d81ef8ea55edac774b3646daa1e3e1575.tar.gz rust-05f5690d81ef8ea55edac774b3646daa1e3e1575.zip | |
Rollup merge of #143380 - cjgillot:kw_span, r=compiler-errors
Replace kw_span by full span for generic const parameters. Small simplification extracted from https://github.com/rust-lang/rust/pull/127241
Diffstat (limited to 'compiler/rustc_parse/src/parser/generics.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/generics.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs index af1d1a1ec66..86326341a75 100644 --- a/compiler/rustc_parse/src/parser/generics.rs +++ b/compiler/rustc_parse/src/parser/generics.rs @@ -114,13 +114,18 @@ impl<'a> Parser<'a> { // Parse optional const generics default value. let default = if self.eat(exp!(Eq)) { Some(self.parse_const_arg()?) } else { None }; + let span = if let Some(ref default) = default { + const_span.to(default.value.span) + } else { + const_span.to(ty.span) + }; Ok(GenericParam { ident, id: ast::DUMMY_NODE_ID, attrs: preceding_attrs, bounds: Vec::new(), - kind: GenericParamKind::Const { ty, kw_span: const_span, default }, + kind: GenericParamKind::Const { ty, span, default }, is_placeholder: false, colon_span: None, }) @@ -137,6 +142,11 @@ impl<'a> Parser<'a> { // Parse optional const generics default value. let default = if self.eat(exp!(Eq)) { Some(self.parse_const_arg()?) } else { None }; + let span = if let Some(ref default) = default { + mistyped_const_ident.span.to(default.value.span) + } else { + mistyped_const_ident.span.to(ty.span) + }; self.dcx() .struct_span_err( @@ -156,7 +166,7 @@ impl<'a> Parser<'a> { id: ast::DUMMY_NODE_ID, attrs: preceding_attrs, bounds: Vec::new(), - kind: GenericParamKind::Const { ty, kw_span: mistyped_const_ident.span, default }, + kind: GenericParamKind::Const { ty, span, default }, is_placeholder: false, colon_span: None, }) |
