about summary refs log tree commit diff
path: root/compiler/rustc_parse_format
AgeCommit message (Collapse)AuthorLines
2023-11-15Auto merge of #117819 - fmease:rustc_parse_format-stable-rustc, r=Nilstriebbors-5/+2
Make `rustc_parse_format` compile on stable again Fixes [#115948 (review comment)](https://github.com/rust-lang/rust/pull/115948/files/822233559619e7e77d984f9020d05302b784cf50#r1385932710). cc `@Veykril` `@notriddle` r? compiler
2023-11-11Make rustc_parse_format compile on stable againLeón Orell Valerian Liehr-5/+2
2023-10-30Clean up `rustc_*/Cargo.toml`.Nicholas Nethercote-1/+3
- Sort dependencies and features sections. - Add `tidy` markers to the sorted sections so they stay sorted. - Remove empty `[lib`] sections. - Remove "See more keys..." comments. Excluded files: - rustc_codegen_{cranelift,gcc}, because they're external. - rustc_lexer, because it has external use. - stable_mir, because it has external use.
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-2/+2
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
2023-01-18Revert "Improve heuristics whether `format_args` string is a source literal"Nilstrieb-35/+2
This reverts commit e6c02aad9345925cfed74f86b414c4d0715d381b. Keeps the code improvements from the PR and the test (as a known-bug).
2023-01-05Fix `uninlined_format_args` for some compiler cratesnils-4/+4
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).
2022-12-28Add enum for `find_width_map_from_snippet`Nilstrieb-7/+18
This makes the relationship between the vec and the boolean clearer.
2022-12-28Improve heuristics whether `format_args` string is a source literalNilstrieb-1/+36
Previously, it only checked whether there was _a_ literal at the span of the first argument, not whether the literal actually matched up. This caused issues when a proc macro was generating a different literal with the same span. This requires an annoying special case for literals ending in `\n` because otherwise `println` wouldn't give detailed diagnostics anymore which would be bad.
2022-12-26Auto merge of #103828 - cassaundra:fix-format-args-span2, r=cjgillotbors-48/+79
Fix incorrect span when using byte-escaped rbrace Fix #103826, a format args span issue introduced in #102214. The current solution for tracking skipped characters made it so that certain situations were ambiguous enough that the original span couldn't be worked out later. This PR improves on the original solution by keeping track of groups of skipped characters using a map, and fixes the previous bug. See an example of this ambiguity in the [previous PR's discussion](https://github.com/rust-lang/rust/pull/102214#issuecomment-1258711015).
2022-12-08Assert size of `rustc_parse_format::Piece<'_>`Maybe Waffle-0/+5
2022-12-06Box `rustc_parse_format::Piece::NextArgument`Maybe Waffle-43/+43
This makes both variants closer together in size (previously they were different by 208 bytes -- 16 vs 224). This may make things worse, but it's worth a try.
2022-11-21Fix incorrect span when using byte-escaped rbraceCassaundra Smith-48/+79
Fix #103826.
2022-11-15shift no characters when using raw string literalsTakayuki Maeda-76/+74
remove `find_skips` remove unnecessary variables
2022-10-27Fix rustc_parse_format spans following escaped utf-8 multibyte charsAlex Macleod-18/+29
2022-10-01Detect and reject out-of-range integers in format string literalsColin Baumgarten-4/+39
Until now out-of-range integers in format string literals were silently ignored. They wrapped around to zero at usize::MAX, producing unexpected results. When using debug builds of rustc, such integers in format string literals even cause an 'attempt to add with overflow' panic in rustc. Fix this by producing an error diagnostic for integers in format string literals which do not fit into usize. Fixes #102528
2022-09-28Fix span of byte-escaped left format args braceCassaundra Smith-1/+1
Fix #102057.
2022-08-25Separate CountIsStar from CountIsParam in rustc_parse_format.Mara Bos-2/+4
2022-08-21Fix rustc_parse_format precision & width spansAlex Macleod-54/+68
2022-08-18Add diagnostic translation lints to crates that don't emit them5225225-0/+2
2022-08-04add a comment about what we can parse nowTakayuki Maeda-0/+2
2022-08-04return when captured argument is not a struct fieldTakayuki Maeda-13/+12
2022-08-03suggest a positional formatting argument instead of a captured argumentTakayuki Maeda-7/+41
2022-07-31Always include a position span in rustc_parse_format::ArgumentAlex Macleod-29/+81
2022-07-25Generate correct suggestion with named arguments used positionallyPreston From-12/+36
Address issue #99265 by checking each positionally used argument to see if the argument is named and adding a lint to use the name instead. This way, when named arguments are used positionally in a different order than their argument order, the suggested lint is correct. For example: ``` println!("{b} {}", a=1, b=2); ``` This will now generate the suggestion: ``` println!("{b} {a}", a=1, b=2); ``` Additionally, this check now also correctly replaces or inserts only where the positional argument is (or would be if implicit). Also, width and precision are replaced with their argument names when they exists. Since the issues were so closely related, this fix for issue #99265 also fixes issue #99266. Fixes #99265 Fixes #99266
2022-07-20Add diagnostic width span when '0$' is used as width.miam-miam100-1/+19
2022-05-03Make rustc_parse_format compile on stablebjorn3-104/+113
This allows it to be used by lightweight formatting systems and may allow it to be used by rust-analyzer.
2022-03-30Spellchecking compiler commentsYuri Astrakhan-1/+1
This PR cleans up the rest of the spelling mistakes in the compiler comments. This PR does not change any literal or code spelling issues.
2022-02-16Correctly mark the span of captured arguments in `format_args!()`Chayim Refael Friedman-8/+12
It should only include the identifier, or misspelling suggestions will be wrong.
2021-09-20Migrate to 2021Mark Rousskov-1/+1
2021-07-29rfc3052: Remove authors field from Cargo manifestsJade-1/+0
Since RFC 3052 soft deprecated the authors field anyway, hiding it from crates.io, docs.rs, and making Cargo not add it by default, and it is not generally up to date/useful information, we should remove it from crates in this repo.
2021-07-08Rework SESSION_GLOBALS API to prevent overwriting itGuillaume Gomez-2/+1
2021-05-24remove cfg(bootstrap)Pietro Albini-1/+0
2021-03-28Rollup merge of #83348 - osa1:issue83344, r=jackh726Yuki Okushi-4/+6
format macro argument parsing fix When the character next to `{}` is "shifted" (when mapping a byte index in the format string to span) we should avoid shifting the span end index, so first map the index of `}` to span, then bump the span, instead of first mapping the next byte index to a span (which causes bumping the end span too much). Regression test added. Fixes #83344 --- r? ```@estebank```
2021-03-27format macro argument parsing fixÖmer Sinan Ağacan-4/+6
When the character next to `{}` is "shifted" (when mapping a byte index in the format string to span) we should avoid shifting the span end index, so first map the index of `}` to span, then bump the span, instead of first mapping the next byte index to a span (which causes bumping the end span too much). Regression test added. Fixes #83344
2021-03-27Rollup merge of #83343 - osa1:issue83340, r=jackh726Yuki Okushi-14/+9
Simplify and fix byte skipping in format! string parser Fixes '\\' handling in format strings. Fixes #83340