about summary refs log tree commit diff
path: root/compiler/rustc_ast/src/util
AgeCommit message (Collapse)AuthorLines
2024-04-02Fix precedence of postfix matchMichael Goulet-1/+3
2024-03-14Add compiler support for parsing `f16` and `f128`Trevor Gross-0/+2
2024-03-01Move `gather_comments`.Nicholas Nethercote-125/+1
To the module where it is used, so it doesn't have to be `pub`.
2024-02-25Add `ErrorGuaranteed` to `ast::ExprKind::Err`Lieselotte-1/+1
2024-02-25Add `ast::ExprKind::Dummy`Lieselotte-1/+2
2024-02-15Add suffixes to `LitError`.Nicholas Nethercote-11/+13
To avoid some unwrapping.
2024-02-15Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.Nicholas Nethercote-3/+3
This mostly works well, and eliminates a couple of delayed bugs. One annoying thing is that we should really also add an `ErrorGuaranteed` to `proc_macro::bridge::LitKind::Err`. But that's difficult because `proc_macro` doesn't have access to `ErrorGuaranteed`, so we have to fake it.
2024-02-15Remove `LitError::LexerError`.Nicholas Nethercote-8/+3
`cook_lexer_literal` can emit an error about an invalid int literal but then return a non-`Err` token. And then `integer_lit` has to account for this to avoid printing a redundant error message. This commit changes `cook_lexer_literal` to return `Err` in that case. Then `integer_lit` doesn't need the special case, and `LitError::LexerError` can be removed.
2024-01-25Rename the unescaping functions.Nicholas Nethercote-5/+4
`unescape_literal` becomes `unescape_unicode`, and `unescape_c_string` becomes `unescape_mixed`. Because rfc3349 will mean that C string literals will no longer be the only mixed utf8 literals.
2024-01-25Rework `CStrUnit`.Nicholas Nethercote-3/+3
- Rename it as `MixedUnit`, because it will soon be used in more than just C string literals. - Change the `Byte` variant to `HighByte` and use it only for `\x80`..`\xff` cases. This fixes the old inexactness where ASCII chars could be encoded with either `Byte` or `Char`. - Add useful comments. - Remove `is_ascii`, in favour of `u8::is_ascii`.
2024-01-25Avoid useless checking in `from_token_lit`.Nicholas Nethercote-62/+21
The parser already does a check-only unescaping which catches all errors. So the checking done in `from_token_lit` never hits. But literals causing warnings can still occur in `from_token_lit`. So the commit changes `str-escape.rs` to use byte string literals and C string literals as well, to give better coverage and ensure the new assertions in `from_token_lit` are correct.
2024-01-19Pack the u128 in LitKind::IntJosh Stone-1/+1
2024-01-19Rollup merge of #119062 - compiler-errors:asm-in-let-else, r=davidtwco,est31Matthias Krüger-3/+7
Deny braced macro invocations in let-else Fixes #119057 Pending T-lang decision cc `@dtolnay`
2024-01-17Deny braced macro invocations in let-elseMichael Goulet-3/+7
2024-01-12Detect `NulInCStr` error earlier.Nicholas Nethercote-10/+2
By making it an `EscapeError` instead of a `LitError`. This makes it like the other errors produced when checking string literals contents, e.g. for invalid escape sequences or bare CR chars. NOTE: this means these errors are issued earlier, before expansion, which changes behaviour. It will be possible to move the check back to the later point if desired. If that happens, it's likely that all the string literal contents checks will be delayed together. One nice thing about this: the old approach had some code in `report_lit_error` to calculate the span of the nul char from a range. This code used a hardwired `+2` to account for the `c"` at the start of a C string literal, but this should have changed to a `+3` for raw C string literals to account for the `cr"`, which meant that the caret in `cr"` nul error messages was one short of where it should have been. The new approach doesn't need any of this and avoids the off-by-one error.
2023-12-19Plumb awaitness of for loopsEric Holk-3/+11
2023-12-17Rollup merge of #118880 - GearsDatapacks:issue-118859-fix, r=compiler-errorsMatthias Krüger-3/+32
More expressions correctly are marked to end with curly braces Fixes #118859, and replaces the mentioned match statement with an exhaustive list, so that this code doesn't get overlooked in the future
2023-12-14Change expr_trailing_brace to an exhaustive match to force new expression ↵GearsDatapacks-3/+32
kinds to specify whether they contain a brace Add inline const and other possible curly brace expressions to expr_trailing_brace Add tests for `}` before `else` in `let...else` error Change to explicit cases for expressions with optional values when being checked for trailing braces Add tests for more complex cases of `}` before `else` in `let..else` statement Move other possible `}` cases into separate arm and add FIXME for future reference
2023-12-13Unify single-char and multi-char `CStrUnit::Char` handling.Nicholas Nethercote-1/+0
The two cases are equivalent. C string literals aren't common so there is no performance need here.
2023-12-13Don't rebuild raw strings when unescaping.Nicholas Nethercote-43/+30
Raw strings don't have escape sequences, so for them "unescaping" just means checking for invalid chars like bare CR. Which means there is no need to rebuild them one char or byte at a time while escaping, because the unescaped version will be the same. This commit removes that rebuilding. Also, the commit changes things so that "unescaping" is unconditional for raw strings and raw byte strings. That's simpler and they're rare enough that the perf effect is negligible.
2023-10-27Add gen blocks to ast and do some broken ast loweringOli Scherer-3/+3
2023-09-11Move let expression checking to parsingMatthew Jasper-1/+1
There was an incomplete version of the check in parsing and a second version in AST validation. This meant that some, but not all, invalid uses were allowed inside macros/disabled cfgs. It also means that later passes have a hard time knowing when the let expression is in a valid location, sometimes causing ICEs. - Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location. - Suppress later errors and MIR construction for invalid let expressions.
2023-08-04Improve spans for indexing expressionsNilstrieb-1/+1
Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location. This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR.
2023-07-23more clippy::style fixes:Matthias Krüger-1/+1
get_first single_char_add_str unnecessary_mut_passed manual_map manual_is_ascii_check
2023-06-19Syntatically accept `become` expressionsMaybe Waffle-1/+3
2023-05-24Use `Option::is_some_and` and `Result::is_ok_and` in the compilerMaybe Waffle-2/+1
2023-05-05Rollup merge of #108801 - fee1-dead-contrib:c-str, r=compiler-errorsDylan DPC-1/+62
Implement RFC 3348, `c"foo"` literals RFC: https://github.com/rust-lang/rfcs/pull/3348 Tracking issue: #105723
2023-05-02make it semantic errorDeadbeef-0/+2
2023-05-02fix TODO commentsDeadbeef-2/+8
2023-05-02update and add a few testsDeadbeef-2/+2
2023-05-02initial step towards implementing C string literalsDeadbeef-1/+54
2023-05-01Rip it outNilstrieb-14/+9
My type ascription Oh rip it out Ah If you think we live too much then You can sacrifice diagnostics Don't mix your garbage Into my syntax So many weird hacks keep diagnostics alive Yet I don't even step outside So many bad diagnostics keep tyasc alive Yet tyasc doesn't even bother to survive!
2023-04-27Tweak await spanMichael Goulet-1/+1
2023-04-21offset_ofDrMeepster-1/+3
2023-03-14Remove box expressions from HIRclubby789-3/+1
2023-03-12Remove `box_syntax` from AST and use in toolsclubby789-1/+0
2023-03-03Match unmatched backticks in comments in compiler/est31-1/+1
2023-01-30Replace enum `==`s with `match`es where it makes senseMaybe Waffle-16/+17
2023-01-28Rollup merge of #107194 - ↵Yuki Okushi-1/+1
xfix:remove-slice-internals-dependency-in-rustc-ast, r=Nilstrieb Remove dependency on slice_internals feature in rustc_ast This reduces dependency on unstable features by the compiler.
2023-01-26Auto merge of #106745 - m-ou-se:format-args-ast, r=oli-obkbors-1/+3
Move format_args!() into AST (and expand it during AST lowering) Implements https://github.com/rust-lang/compiler-team/issues/541 This moves FormatArgs from rustc_builtin_macros to rustc_ast_lowering. For now, the end result is the same. But this allows for future changes to do smarter things with format_args!(). It also allows Clippy to directly access the ast::FormatArgs, making things a lot easier. This change turns the format args types into lang items. The builtin macro used to refer to them by their path. After this change, the path is no longer relevant, making it easier to make changes in `core`. This updates clippy to use the new language items, but this doesn't yet make clippy use the ast::FormatArgs structure that's now available. That should be done after this is merged.
2023-01-22Remove dependency on slice_internals feature in rustc_astKonrad Borowski-1/+1
2023-01-17Remove double spaces after dots in commentsMaybe Waffle-1/+1
2023-01-12Expand format_args!() in rust_ast_lowering.Mara Bos-1/+3
2023-01-05Fix `uninlined_format_args` for some compiler cratesnils-3/+3
Convert all the crates that have had their diagnostic migration completed (except save_analysis because that will be deleted soon and apfloat because of the licensing problem).
2023-01-02Print correct base for too-large literalsclubby789-2/+2
Also update tests
2022-12-20rustc: Remove needless lifetimesJeremy Stucki-1/+1
2022-12-12Auto merge of #105160 - nnethercote:rm-Lit-token_lit, r=petrochenkovbors-48/+94
Remove `token::Lit` from `ast::MetaItemLit`. Currently `ast::MetaItemLit` represents the literal kind twice. This PR removes that redundancy. Best reviewed one commit at a time. r? `@petrochenkov`
2022-12-05Remove `LitKind::synthesize_token_lit`.Nicholas Nethercote-39/+44
It has a single call site in the HIR pretty printer, where the resulting token lit is immediately converted to a string. This commit replaces `LitKind::synthesize_token_lit` with a `Display` impl for `LitKind`, which can be used by the HIR pretty printer.
2022-12-05Remove `ExtCtxt::expr_lit`.Nicholas Nethercote-11/+23
2022-12-04Rollup merge of #105142 - nbdd0121:inline_const, r=petrochenkovMatthias Krüger-0/+1
Make inline const block `ExprWithBlock` Fix https://github.com/rust-lang/rust/pull/104087#issuecomment-1324190817 `@rustbot` label: +T-lang +F-inline_const