about summary refs log tree commit diff
path: root/src/test/ui/fmt
AgeCommit message (Collapse)AuthorLines
2021-02-06parse_format: treat r" as a literalDavid Hewitt-0/+11
2021-02-03Add lint for `panic!(123)` which is not accepted in Rust 2021.Mara Bos-1/+1
This extends the `panic_fmt` lint to warn for all cases where the first argument cannot be interpreted as a format string, as will happen in Rust 2021. It suggests to add `"{}", ` to format the message as a string. In the case of `std::panic!()`, it also suggests the recently stabilized `std::panic::panic_any()` function as an alternative. It renames the lint to `non_fmt_panic` to match the lint naming guidelines.
2020-12-04Move format machinery tests to where they belongAleksey Kladov-0/+486
2020-10-19Ignore panic_fmt lint in format-args-capture ui test.Mara Bos-0/+1
2020-11-09Add `#[cfg(panic = "...")]`David Hewitt-4/+9
2020-10-05Fix span for unicode escape suggestion.Eric Huss-3/+1
2020-09-08Point at named argument not found when using `format_args_capture` instead ↵Esteban Küber-21/+16
of whole format string
2020-09-03Auto merge of #73996 - da-x:short-unique-paths, r=petrochenkovbors-10/+10
diagnostics: shorten paths of unique symbols This is a step towards implementing a fix for #50310, and continuation of the discussion in [Pre-RFC: Nicer Types In Diagnostics - compiler - Rust Internals](https://internals.rust-lang.org/t/pre-rfc-nicer-types-in-diagnostics/11139). Impressed upon me from previous discussion in #21934 that an RFC for this is not needed, and I should just come up with code. The recent improvements to `use` suggestions that I've contributed have given rise to this implementation. Contrary to previous suggestions, it's rather simple logic, and I believe it only reduces the amount of cognitive load that a developer would need when reading type errors. ----- If a symbol name can only be imported from one place, and as long as it was not glob-imported anywhere in the current crate, we can trim its printed path to the last component. This has wide implications on error messages with types, for example, shortening `std::vec::Vec` to just `Vec`, as long as there is no other `Vec` importable from anywhere.
2020-09-02pretty: trim paths of unique symbolsDan Aloni-10/+10
If a symbol name can only be imported from one place for a type, and as long as it was not glob-imported anywhere in the current crate, we can trim its printed path and print only the name. This has wide implications on error messages with types, for example, shortening `std::vec::Vec` to just `Vec`, as long as there is no other `Vec` importable anywhere. This adds a new '-Z trim-diagnostic-paths=false' option to control this feature. On the good path, with no diagnosis printed, we should try to avoid issuing this query, so we need to prevent trimmed_def_paths query on several cases. This change also relies on a previous commit that differentiates between `Debug` and `Display` on various rustc types, where the latter is trimmed and presented to the user and the former is not.
2020-09-02Improve recovery on malformed format callSasha-36/+55
If a comma in a format call is replaced with a similar token, then we emit an error and continue parsing, instead of stopping at this point.
2020-08-30Use string literal directly when available in formatSasha-0/+54
Previous implementation used the `Parser::parse_expr` function in order to extract the format expression. If the first comma following the format expression was mistakenly replaced with a dot, then the next format expression was eaten by the function, because it looked as a syntactically valid expression, which resulted in incorrectly spanned error messages. The way the format expression is exctracted is changed: we first look at the first available token in the first argument supplied to the `format!` macro call. If it is a string literal, then it is promoted as a format expression immediatly, otherwise we fall back to the original `parse_expr`-related method. This allows us to ensure that the parser won't consume too much tokens when a typo is made. A test has been created so that it is ensured that the issue is properly fixed.
2020-07-03Ignore test with panic on wasm targetsDavid Hewitt-0/+2
2020-07-01Update src/librustc_builtin_macros/format.rsDavid Hewitt-2/+2
Apply suggestion from varkor Co-authored-by: varkor <github@varkor.com>
2020-07-01Amend wording of noteDavid Hewitt-2/+2
2020-06-27Improve messaging from PR feedbackDavid Hewitt-4/+2
2020-06-24Add `format_args_capture` featureDavid Hewitt-0/+190
2020-04-08Small tweaks to required bound spanEsteban Küber-2/+2
2020-02-17Move to using an extern type for opaquenessMark Rousskov-12/+8
This prevents accidental dereferences and so forth of the Void type, as well as cleaning up the error message to reference Opaque rather than the more complicated PhantomData type.
2019-11-28Allow any identifier as format arg nameDavid Tolnay-20/+30
Previously: error: invalid format string: invalid argument name `_x` --> src/main.rs:2:16 | 2 | println!("{_x}", a=0); | ^^ invalid argument name in format string | = note: argument names cannot start with an underscore Not supporting identifiers starting with underscore appears to have been an arbitrary limitation from 2013 in code that was most likely never reviewed: https://github.com/rust-lang/rust/pull/8245/files#diff-0347868ef389c805e97636623e4a4ea6R277 The error message was dutifully improved in #50610 but is there any reason that leading underscore would be a special case? This commit updates the format_args parser to accept identifiers with leading underscores.
2019-10-23Tweak format string error to point at arguments alwaysEsteban Küber-1/+9
Add secondary span labels with no text to make it clear when there's a mismatch bewteen the positional arguments in a format string and the arguments to the macro. This shouldn't affect experienced users, but it should make it easier for newcomers to more clearly understand how `format!()` and `println!()` are supposed to be used. ``` error: 2 positional arguments in format string, but there is 1 argument --> file8.rs:2:14 | 2 | format!("{} {}", 1); | ^^ ^^ - ``` instead of ``` error: 2 positional arguments in format string, but there is 1 argument --> file8.rs:2:14 | 2 | format!("{} {}", 1); | ^^ ^^ ```
2019-09-22On obligation errors point at the unfulfilled binding when possibleEsteban Küber-2/+2
2019-08-31Use span label instead of note for cause in E0631Esteban Küber-10/+6
2019-05-31fix tidyEsteban Küber-19/+18
2019-05-30Remove unecessary `-Z continue-parse-after-error` from testsEsteban Küber-1/+1
2019-05-02don't amplify errors in format! with bad literalsAleksey Kladov-14/+3
2019-05-02introduce unescape moduleAleksey Kladov-26/+29
Currently, we deal with escape sequences twice: once when we lex a string, and a second time when we unescape literals. This PR aims to remove this duplication, by introducing a new `unescape` mode as a single source of truth for character escaping rules
2019-03-25compiletest: make path normalization smarterAndy Russell-28/+28
2019-03-11Update testsVadim Petrochenkov-2/+2
2018-12-31Use structured suggestion for braceless unicode escape squenceEsteban Küber-7/+3
2018-12-31Account for `\xFF` and `\u{FF}` sequences in string format errorsEsteban Küber-1/+62
2018-12-26Point at correct span for arguments in format stringsEsteban Küber-1/+9
When a format string has escaped whitespace characters format arguments were shifted by one per each escaped character. Account for these escaped characters when synthesizing the spans. Fix #55155.
2018-12-26Various changes to string format diagnosticsEsteban Küber-8/+230
- Point at opening mismatched formatting brace - Account for differences between raw and regular strings - Account for differences between the code snippet and `InternedString` - Add more tests
2018-12-25Remove licensesMark Rousskov-36/+16
2018-07-19Use correct spans for format string errorsEsteban Küber-8/+82
When encountering format string errors in a raw string, or regular string literal with embedded newlines, account for the positional change to use correct spans. :drive by fix: 🚗
2018-07-19Improve suggestion for missing fmt str in printlnEsteban Küber-11/+11
Avoid using `concat!(fmt, "\n")` to improve the diagnostics being emitted when the first `println!()` argument isn't a formatting string literal.
2018-06-23add `dyn` to display of dynamic (trait) type namesZack M. Davis-8/+8
The `dyn Trait` syntax was stabilized in 199ee327. Resolves #49277.
2018-05-10Improve format string errorsEsteban Küber-4/+51
- Point at format string position inside the formatting string - Explain that argument names can't start with an underscore
2018-03-15Auto merge of #48138 - estebank:issue-45092, r=nikomatsakisbors-6/+6
Reword E0044 and message for `!Send` types - Reword E0044 help. - Change error message for types that don't implement `Send` CC #45092, #46678, #24909, #33307.
2018-03-14Reword E0044 and message for `!Send` typesEsteban Küber-6/+6
- Reword E0044 help. - Change error message for types that don't implement `Send`
2018-03-14update testsGuillaume Gomez-1/+1
2018-02-26Update UI testsVadim Petrochenkov-6/+6
2018-02-25Update ui testsGuillaume Gomez-0/+1
2018-01-15On E0283, point at method with the requirementsEsteban Küber-2/+10
On required type annotation diagnostic error, point at method with the requirements if the span is available.
2017-11-26mention nightly in -Z external-macro-backtrace noteAlex Burka-2/+2
2017-11-24Merge cfail and ui tests into ui testsOliver Schneider-4/+4
2017-11-22Auto merge of #45198 - oli-obk:fmt_args, r=sfacklerbors-0/+54
Prevent fmt::Arguments from being shared across threads Fixes #45197 This is a **breaking change**! Without doing this it's very easy to create race conditions. There's probably a way to do this without breaking valid use cases, but it would require quite an overhaul of the formatting machinery.
2017-11-20address review commentsAlex Burka-2/+2
2017-11-19use -Z flag instead of env varAlex Burka-2/+2
2017-11-19update UI testsAlex Burka-2/+2
2017-10-11Prevent fmt::Arguments from being shared across threadsOliver Schneider-0/+54
Fixes #45197