about summary refs log tree commit diff
path: root/compiler/rustc_parse_format/src
AgeCommit message (Collapse)AuthorLines
2025-03-23Slim `rustc_parse_format` dependencies downLukas Wirth-1/+1
`rustc_index` is only used for its size assertion macro, so demote it to a dev-dependency gated under testing instead
2025-03-18Revert "Rollup merge of #136355 - ↵Ralf Jung-6/+5
GuillaumeGomez:proc-macro_add_value_retrieval_methods, r=Amanieu" This reverts commit 08dfbf49e30d917c89e49eb14cb3f1e8b8a1c9ef, reversing changes made to 10bcdad7df0de3cfb95c7bdb7b16908e73cafc09.
2025-03-17Rollup merge of #136355 - ↵Jacob Pratt-5/+6
GuillaumeGomez:proc-macro_add_value_retrieval_methods, r=Amanieu Add `*_value` methods to proc_macro lib This is the implementation of https://github.com/rust-lang/libs-team/issues/459. It allows to get the actual value (unescaped) of the different string literals. Part of https://github.com/rust-lang/rust/issues/136652. r? libs-api
2025-03-12Rollup merge of #138331 - nnethercote:use-RUSTC_LINT_FLAGS-more, ↵Matthias Krüger-1/+0
r=onur-ozkan,jieyouxu Use `RUSTC_LINT_FLAGS` more An alternative to the failed #138084. Fixes #138106. r? ````@jieyouxu````
2025-03-11Auto merge of #136932 - m-ou-se:fmt-width-precision-u16, r=scottmcmbors-9/+9
Reduce formatting `width` and `precision` to 16 bits This is part of https://github.com/rust-lang/rust/issues/99012 This is reduces the `width` and `precision` fields in format strings to 16 bits. They are currently full `usize`s, but it's a bit nonsensical that we need to support the case where someone wants to pad their value to eighteen quintillion spaces and/or have eighteen quintillion digits of precision. By reducing these fields to 16 bit, we can reduce `FormattingOptions` to 64 bits (see https://github.com/rust-lang/rust/pull/136974) and improve the in memory representation of `format_args!()`. (See additional context below.) This also fixes a bug where the width or precision is silently truncated when cross-compiling to a target with a smaller `usize`. By reducing the width and precision fields to the minimum guaranteed size of `usize`, 16 bits, this bug is eliminated. This is a breaking change, but affects almost no existing code. --- Details of this change: There are three ways to set a width or precision today: 1. Directly a formatting string, e.g. `println!("{a:1234}")` 2. Indirectly in a formatting string, e.g. `println!("{a:width$}", width=1234)` 3. Through the unstable `FormattingOptions::width` method. This PR: - Adds a compiler error for 1. (`println!("{a:9999999}")` no longer compiles and gives a clear error.) - Adds a runtime check for 2. (`println!("{a:width$}, width=9999999)` will panic.) - Changes the signatures of the (unstable) `FormattingOptions::[get_]width` methods to use a `u16` instead. --- Additional context for improving `FormattingOptions` and `fmt::Arguments`: All the formatting flags and options are currently: - The `+` flag (1 bit) - The `-` flag (1 bit) - The `#` flag (1 bit) - The `0` flag (1 bit) - The `x?` flag (1 bit) - The `X?` flag (1 bit) - The alignment (2 bits) - The fill character (21 bits) - Whether a width is specified (1 bit) - Whether a precision is specified (1 bit) - If used, the width (a full usize) - If used, the precision (a full usize) Everything except the last two can simply fit in a `u32` (those add up to 31 bits in total). If we can accept a max width and precision of u16::MAX, we can make a `FormattingOptions` that is exactly 64 bits in size; the same size as a thin reference on most platforms. If, additionally, we also limit the number of formatting arguments, we can also reduce the size of `fmt::Arguments` (that is, of a `format_args!()` expression).
2025-03-11Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-1/+0
It's no longer necessary now that `-Wunreachable_pub` is being passed.
2025-03-10Limit formatting width and precision to 16 bits.Mara Bos-9/+9
2025-03-10Revert "Use workspace lints for crates in `compiler/` #138084"许杰友 Jieyou Xu (Joe)-0/+1
Revert <https://github.com/rust-lang/rust/pull/138084> to buy time to consider options that avoids breaking downstream usages of cargo on distributed `rustc-src` artifacts, where such cargo invocations fail due to inability to inherit `lints` from workspace root manifest's `workspace.lints` (this is only valid for the source rust-lang/rust workspace, but not really the distributed `rustc-src` artifacts). This breakage was reported in <https://github.com/rust-lang/rust/issues/138304>. This reverts commit 48caf81484b50dca5a5cebb614899a3df81ca898, reversing changes made to c6662879b27f5161e95f39395e3c9513a7b97028.
2025-03-08Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-1/+0
(Except for `rustc_codegen_cranelift`.) It's no longer necessary now that `unreachable_pub` is in the workspace lints.
2025-02-10Extract `unescape` from `rustc_lexer` into its own crateGuillaume Gomez-5/+6
2025-02-08Rustfmtbjorn3-330/+411
2025-01-29use impl Into<String>Marijn Schouten-10/+5
2025-01-28parse_format optimize import useMarijn Schouten-32/+27
2025-01-23Rollup merge of #135920 - hkBst:patch-16, r=SparrowLiiMatthias Krüger-7/+1
simplify parse_format::Parser::ws by using next_if
2025-01-23simplify parse_format::Parser::ws by using next_ifMarijn Schouten-7/+1
2025-01-22remove implied end of sliceMarijn Schouten-1/+1
2024-12-30add suggestion for wrongly ordered format parametersDavis Muro-0/+35
2024-10-14Remove `'apostrophes'` from `rustc_parse_format`Lieselotte-4/+4
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-401/+323
2024-08-29Add `warn(unreachable_pub)` to `rustc_parse_format`.Nicholas Nethercote-0/+1
2024-07-29Reformat `use` declarations.Nicholas Nethercote-4/+2
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-06-12Use `tidy` to sort crate attributes for all compiler crates.Nicholas Nethercote-3/+5
We already do this for a number of crates, e.g. `rustc_middle`, `rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`. For the ones we don't, in many cases the attributes are a mess. - There is no consistency about order of attribute kinds (e.g. `allow`/`deny`/`feature`). - Within attribute kind groups (e.g. the `feature` attributes), sometimes the order is alphabetical, and sometimes there is no particular order. - Sometimes the attributes of a particular kind aren't even grouped all together, e.g. there might be a `feature`, then an `allow`, then another `feature`. This commit extends the existing sorting to all compiler crates, increasing consistency. If any new attribute line is added there is now only one place it can go -- no need for arbitrary decisions. Exceptions: - `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`, because they have no crate attributes. - `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's ignored in `rustfmt.toml`).
2024-05-30Apply x clippy --fix and x fmtr0cky-10/+8
2024-04-18Simplify `static_assert_size`s.Nicholas Nethercote-1/+1
We want to run them on all 64-bit platforms.
2024-04-03Check `x86_64` size assertions on `aarch64`, tooZalathar-1/+1
This makes it easier for contributors on aarch64 workstations (e.g. Macs) to notice when these assertions have been violated.
2024-03-16Extend format arg help for simple tuple index access expression许杰友 Jieyou Xu (Joe)-15/+37
2024-02-17remove a couple of redundant clonesMatthias Krüger-1/+1
2024-02-06Invert diagnostic lints.Nicholas Nethercote-2/+0
That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has be converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted.
2024-01-25Rename the unescaping functions.Nicholas Nethercote-1/+1
`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-22Rollup merge of #118639 - fmease:deny-features-in-stable-rustc-crates, ↵Matthias Krüger-2/+3
r=WaffleLapkin Undeprecate lint `unstable_features` and make use of it in the compiler See also #117937. r? compiler
2024-01-08Removing redudant note from parse errorMads Ravn-1/+1
2024-01-07Adding alignment to the list of cases to test for specific error message. ↵Mads Ravn-6/+22
Covers `>`, `^` and `<`.
2023-12-20Undeprecate and use lint `unstable_features`León Orell Valerian Liehr-2/+3
2023-11-11Make rustc_parse_format compile on stable againLeón Orell Valerian Liehr-5/+2
2023-10-08rustdoc: remove rust logo from non-Rust cratesMichael Howell-0/+3
2023-09-17Rollup merge of #115611 - lukas-code:format!("{r#ident}"), r=compiler-errorsDylan DPC-7/+47
add diagnostic for raw identifiers in format string Format strings don't support raw identifiers (e.g. `format!("{r#type}")`), but they do support keywords in the format string directly (e.g. `format!("{type}")`). This PR improves the error output when attempting to use a raw identifier in a format string and adds a machine-applicable suggestion to remove the `r#`. fixes https://github.com/rust-lang/rust/issues/115466
2023-09-06add diagnostic for raw identifiers in format stringLukas Markeffsky-7/+47
2023-09-05Replace data_structures dependency with index in rustc_parse_formatLukas Wirth-1/+1
2023-07-19Fix unit testsMichael Goulet-0/+15
2023-07-19Improve error message when closing bracket interpreted as formatting fill ↵Michael Goulet-58/+45
character
2023-07-19Fix quotes in outputMichael Goulet-1/+1
2023-04-10Fix typos in compilerDaniPopes-1/+1
2023-03-14Improve heuristics for format_args literal being suggestableNilstrieb-1/+35
Sometimes, we want to create subspans and point at code in the literal if possible. But this doesn't always make sense, sometimes the literal may come from macro expanded code and isn't actually there in the source. Then, we can't really make these suggestions. This now makes sure that the literal is actually there as we see it so that we will not run into ICEs on weird literal transformations.
2023-03-14Properly allow macro expanded `format_args` invocations to uses capturesNilstrieb-8/+10
Originally, this was kinda half-allowed. There were some primitive checks in place that looked at the span to see whether the input was likely a literal. These "source literal" checks are needed because the spans created during `format_args` parsing only make sense when it is indeed a literal that was written in the source code directly. This is orthogonal to the restriction that the first argument must be a "direct literal", not being exanpanded from macros. This restriction was imposed by [RFC 2795] on the basis of being too confusing. But this was only concerned with the argument of the invocation being a literal, not whether it was a source literal (maybe in spirit it meant it being a source literal, this is not clear to me). Since the original check only really cared about source literals (which is good enough to deny the `format_args!(concat!())` example), macros expanding to `format_args` invocations were able to use implicit captures if they spanned the string in a way that lead back to a source string. The "source literal" checks were not strict enough and caused ICEs in certain cases (see # 106191 (the space is intended to avoid spammy backreferences)). So I tightened it up in # 106195 to really only work if it's a direct source literal. This caused the `indoc` crate to break. `indoc` transformed the source literal by removing whitespace, which made it not a "source literal" anymore (which is required to fix the ICE). But since `indoc` spanned the literal in ways that made the old check think that it's a literal, it was able to use implicit captures (which is useful and nice for the users of `indoc`). This commit properly seperates the previously introduced concepts of "source literal" and "direct literal" and therefore allows `indoc` invocations, which don't create "source literals" to use implicit captures again. [RFC 2795]: https://rust-lang.github.io/rfcs/2795-format-args-implicit-identifiers.html#macro-hygiene
2023-02-16Replace some `then`s with some `then_some`sMaybe Waffle-1/+1
2023-02-16`if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)`Maybe Waffle-1/+1
2023-02-10remove redundant clonesMatthias Krüger-3/+1
2023-02-03Rollup merge of #106805 - madsravn:master, r=compiler-errorsMatthias Krüger-1/+28
Suggest `{var:?}` when finding `{?:var}` in inline format strings Link to issue: https://github.com/rust-lang/rust/issues/106572 This is my first PR to this project, so hopefully I can get some good pointers with me from the first PR. Currently my idea was to test out whether or not this is the correct solution to this issue and then hopefully expand upon the idea to not only work for Debug formatting but for all of them. If this is a valid solution, I will create a new issue to give a better error message to a broader range of wrong-order formatting.
2023-02-02PR fixing wrong order of format parameters in strings. Issue #106572Mads Ravn-1/+28
Adding Adding Fixing small issues for PR Adding tests Removing unused binding Changing the wording on note Fixing PR comment
2023-01-27Replace format flags u32 by enums and bools.Mara Bos-43/+97