summaryrefslogtreecommitdiff
path: root/compiler/rustc_parse_format
Commit message (Collapse)AuthorAgeFilesLines
* Fix typos in compilerDaniPopes2023-04-101-1/+1
|
* Improve heuristics for format_args literal being suggestableNilstrieb2023-03-141-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.
* Properly allow macro expanded `format_args` invocations to uses capturesNilstrieb2023-03-141-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
* Replace some `then`s with some `then_some`sMaybe Waffle2023-02-161-1/+1
|
* `if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)`Maybe Waffle2023-02-161-1/+1
|
* remove redundant clonesMatthias Krüger2023-02-101-3/+1
|
* Rollup merge of #106805 - madsravn:master, r=compiler-errorsMatthias Krüger2023-02-031-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.
| * PR fixing wrong order of format parameters in strings. Issue #106572Mads Ravn2023-02-021-1/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adding Adding Fixing small issues for PR Adding tests Removing unused binding Changing the wording on note Fixing PR comment
* | Replace format flags u32 by enums and bools.Mara Bos2023-01-272-43/+97
| |
* | Revert "Improve heuristics whether `format_args` string is a source literal"Nilstrieb2023-01-181-35/+2
|/ | | | | | This reverts commit e6c02aad9345925cfed74f86b414c4d0715d381b. Keeps the code improvements from the PR and the test (as a known-bug).
* Fix `uninlined_format_args` for some compiler cratesnils2023-01-051-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).
* Add enum for `find_width_map_from_snippet`Nilstrieb2022-12-281-7/+18
| | | | This makes the relationship between the vec and the boolean clearer.
* Improve heuristics whether `format_args` string is a source literalNilstrieb2022-12-281-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.
* Auto merge of #103828 - cassaundra:fix-format-args-span2, r=cjgillotbors2022-12-261-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).
| * Fix incorrect span when using byte-escaped rbraceCassaundra Smith2022-11-211-48/+79
| | | | | | | | Fix #103826.
* | Assert size of `rustc_parse_format::Piece<'_>`Maybe Waffle2022-12-082-0/+5
| |
* | Box `rustc_parse_format::Piece::NextArgument`Maybe Waffle2022-12-062-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.
* shift no characters when using raw string literalsTakayuki Maeda2022-11-151-76/+74
| | | | | | remove `find_skips` remove unnecessary variables
* Fix rustc_parse_format spans following escaped utf-8 multibyte charsAlex Macleod2022-10-271-18/+29
|
* Detect and reject out-of-range integers in format string literalsColin Baumgarten2022-10-012-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
* Fix span of byte-escaped left format args braceCassaundra Smith2022-09-281-1/+1
| | | | Fix #102057.
* Separate CountIsStar from CountIsParam in rustc_parse_format.Mara Bos2022-08-252-2/+4
|
* Fix rustc_parse_format precision & width spansAlex Macleod2022-08-212-54/+68
|
* Add diagnostic translation lints to crates that don't emit them52252252022-08-181-0/+2
|
* add a comment about what we can parse nowTakayuki Maeda2022-08-041-0/+2
|
* return when captured argument is not a struct fieldTakayuki Maeda2022-08-041-13/+12
|
* suggest a positional formatting argument instead of a captured argumentTakayuki Maeda2022-08-031-7/+41
|
* Always include a position span in rustc_parse_format::ArgumentAlex Macleod2022-07-312-29/+81
|
* Generate correct suggestion with named arguments used positionallyPreston From2022-07-252-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
* Add diagnostic width span when '0$' is used as width.miam-miam1002022-07-202-1/+19
|
* Make rustc_parse_format compile on stablebjorn32022-05-033-104/+113
| | | | | This allows it to be used by lightweight formatting systems and may allow it to be used by rust-analyzer.
* Spellchecking compiler commentsYuri Astrakhan2022-03-301-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.
* Correctly mark the span of captured arguments in `format_args!()`Chayim Refael Friedman2022-02-162-8/+12
| | | | It should only include the identifier, or misspelling suggestions will be wrong.
* Migrate to 2021Mark Rousskov2021-09-201-1/+1
|
* rfc3052: Remove authors field from Cargo manifestsJade2021-07-291-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.
* Rework SESSION_GLOBALS API to prevent overwriting itGuillaume Gomez2021-07-081-2/+1
|
* remove cfg(bootstrap)Pietro Albini2021-05-241-1/+0
|
* Rollup merge of #83348 - osa1:issue83344, r=jackh726Yuki Okushi2021-03-281-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```
| * format macro argument parsing fixÖmer Sinan Ağacan2021-03-271-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
* | Rollup merge of #83343 - osa1:issue83340, r=jackh726Yuki Okushi2021-03-271-14/+9
|\ \ | |/ |/| | | | | | | | | | | Simplify and fix byte skipping in format! string parser Fixes '\\' handling in format strings. Fixes #83340
| * Simplify and fix byte skipping in format! string parserÖmer Sinan Ağacan2021-03-211-14/+9
| | | | | | | | | | | | Fixes '\\' handling in format strings. Fixes #83340
* | stabilize or_patternsmark2021-03-191-1/+1
|/
* parse_format: treat r" as a literalDavid Hewitt2021-02-061-1/+1
|
* rustc_parse_format: Fix character indices in find_skipsÖmer Sinan Ağacan2021-01-171-1/+1
| | | | Fixes #81006
* Use Option::map_or instead of `.map(..).unwrap_or(..)`LingMan2021-01-141-2/+2
|
* /nightly/nightly-rustcErik Hofmayer2020-09-231-1/+1
|
* Updated html_root_url for compiler cratesErik Hofmayer2020-09-231-1/+1
|
* Rollup merge of #76888 - matthiaskrgr:clippy_single_match_2, r=Dylan-DPCecstatic-morse2020-09-211-6/+3
|\ | | | | | | | | | | use if let instead of single match arm expressions use if let instead of single match arm expressions to compact code and reduce nesting (clippy::single_match)
| * use if let instead of single match arm expressions to compact code and ↵Matthias Krüger2020-09-201-6/+3
| | | | | | | | reduce nesting (clippy::single_match)
* | Remove redundant #![feature(...)] 's from compiler/est312020-09-171-2/+0
|/