about summary refs log tree commit diff
path: root/src/test/ui/fmt
AgeCommit message (Collapse)AuthorLines
2023-01-11Move /src/test to /testsAlbert Larsan-1891/+0
2023-01-02maybegimbles-3/+3
2022-12-28Improve heuristics whether `format_args` string is a source literalNilstrieb-1/+42
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-0/+28
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-13Make some diagnostics not depend on the source of what they reference being ↵Oli Scherer-9/+0
available
2022-11-21Fix incorrect span when using byte-escaped rbraceCassaundra Smith-0/+28
Fix #103826.
2022-11-15shift no characters when using raw string literalsTakayuki Maeda-0/+29
remove `find_skips` remove unnecessary variables
2022-10-27Fix rustc_parse_format spans following escaped utf-8 multibyte charsAlex Macleod-0/+82
2022-09-30Fix format_args capture for macro expanded format stringsAlex Macleod-14/+108
2022-09-29Rollup merge of #102214 - cassaundra:fix-format-args-span, r=cjgillotMichael Howell-0/+64
Fix span of byte-escaped left format args brace Fix #102057 (see issue for example). Previously, the use of escaped left braces (`\x7B`) in format args resulted in an incorrectly offset span. This patch fixes that by considering any escaped characters within the string instead of using a constant offset.
2022-09-28Fix span of byte-escaped left format args braceCassaundra Smith-0/+64
Fix #102057.
2022-09-27Update test.Mara Bos-6/+4
2022-09-27Update tests.Mara Bos-62/+41
2022-09-27Rewrite and refactor format_args!() builtin macro.Mara Bos-7/+7
2022-08-25Add test for {:.0$} diagnostic issue.Mara Bos-1/+14
2022-08-21Comment a bit, use find_ancestor_in_same_ctxt to suppress some weird macro notesMichael Goulet-2/+0
2022-08-21Rework point-at-argMichael Goulet-4/+10
2022-08-18Reword "Required because of the requirements on the impl of ..."Andy Wang-2/+2
2022-08-03add tests for `Debug` formatters and precision formattersTakayuki Maeda-1/+40
2022-08-03suggest a positional formatting argument instead of a captured argumentTakayuki Maeda-0/+76
2022-07-20Fix off by one error and add ui test.miam-miam100-2/+16
2022-07-19Mention first and last macro in backtraceMichael Goulet-3/+3
2022-06-16 fix one more case of trailing spaceklensy-1/+1
2022-04-16Implementation for 65853Jack Huey-2/+18
This attempts to bring better error messages to invalid method calls, by applying some heuristics to identify common mistakes. The algorithm is inspired by Levenshtein distance and longest common sub-sequence. In essence, we treat the types of the function, and the types of the arguments you provided as two "words" and compute the edits to get from one to the other. We then modify that algorithm to detect 4 cases: - A function input is missing - An extra argument was provided - The type of an argument is straight up invalid - Two arguments have been swapped - A subset of the arguments have been shuffled (We detect the last two as separate cases so that we can detect two swaps, instead of 4 parameters permuted.) It helps to understand this argument by paying special attention to terminology: "inputs" refers to the inputs being *expected* by the function, and "arguments" refers to what has been provided at the call site. The basic sketch of the algorithm is as follows: - Construct a boolean grid, with a row for each argument, and a column for each input. The cell [i, j] is true if the i'th argument could satisfy the j'th input. - If we find an argument that could satisfy no inputs, provided for an input that can't be satisfied by any other argument, we consider this an "invalid type". - Extra arguments are those that can't satisfy any input, provided for an input that *could* be satisfied by another argument. - Missing inputs are inputs that can't be satisfied by any argument, where the provided argument could satisfy another input - Swapped / Permuted arguments are identified with a cycle detection algorithm. As each issue is found, we remove the relevant inputs / arguments and check for more issues. If we find no issues, we match up any "valid" arguments, and start again. Note that there's a lot of extra complexity: - We try to stay efficient on the happy path, only computing the diagonal until we find a problem, and then filling in the rest of the matrix. - Closure arguments are wrapped in a tuple and need to be unwrapped - We need to resolve closure types after the rest, to allow the most specific type constraints - We need to handle imported C functions that might be variadic in their inputs. I tried to document a lot of this in comments in the code and keep the naming clear.
2022-04-04Mention implementers of unsatisfied traitEsteban Kuber-0/+10
When encountering an unsatisfied trait bound, if there are no other suggestions, mention all the types that *do* implement that trait: ``` error[E0277]: the trait bound `f32: Foo` is not satisfied --> $DIR/impl_wf.rs:22:6 | LL | impl Baz<f32> for f32 { } | ^^^^^^^^ the trait `Foo` is not implemented for `f32` | = help: the following other types implement trait `Foo`: Option<T> i32 str note: required by a bound in `Baz` --> $DIR/impl_wf.rs:18:31 | LL | trait Baz<U: ?Sized> where U: Foo { } | ^^^ required by this bound in `Baz` ``` Mention implementers of traits in `ImplObligation`s. Do not mention other `impl`s for closures, ranges and `?`.
2022-02-19Rollup merge of #93658 - cchiw:issue-77443-fix, r=joshtriplettMatthias Krüger-1/+0
Stabilize `#[cfg(panic = "...")]` [Stabilization PR](https://rustc-dev-guide.rust-lang.org/stabilization_guide.html#stabilization-pr) for #77443
2022-02-16Correctly mark the span of captured arguments in `format_args!()`Chayim Refael Friedman-26/+53
It should only include the identifier, or misspelling suggestions will be wrong.
2022-02-10replace feature expression (cfg_panic) in lib and remove expression from testsCharisee-1/+0
Rebase commit
2022-02-07Rollup merge of #93394 - m-ou-se:fix-93378, r=estebankMara Bos-0/+41
Don't allow {} to refer to implicit captures in format_args. Fixes #93378
2022-01-31Rollup merge of #93461 - dtolnay:fmtyield, r=davidtwcoMatthias Krüger-0/+33
Accommodate yield points in the format_args expansion Fixes #93274. For the case `println!("{} {:?}", "", async {}.await)` in the issue, the expansion before: ```rust ::std::io::_print( ::core::fmt::Arguments::new_v1( &["", " ", "\n"], &[ ::core::fmt::ArgumentV1::new(&"", ::core::fmt::Display::fmt), ::core::fmt::ArgumentV1::new(&async {}.await, ::core::fmt::Debug::fmt), ], ), ); ``` After: ```rust ::std::io::_print( ::core::fmt::Arguments::new_v1( &["", " ", "\n"], &match (&"", &async {}.await) { _args => [ ::core::fmt::ArgumentV1::new(_args.0, ::core::fmt::Display::fmt), ::core::fmt::ArgumentV1::new(_args.1, ::core::fmt::Debug::fmt), ], }, ), ); ```
2022-01-30Mac callsDavid Tolnay-2/+12
2022-01-30Add regression test for issue 93274David Tolnay-0/+23
Currently fails with: error: future cannot be sent between threads safely --> $DIR/src/test/ui/fmt/format-with-yield-point.rs:21:17 | LL | assert_send(with_await()); | ^^^^^^^^^^^^ future returned by `with_await` is not `Send` | = help: the trait `Sync` is not implemented for `core::fmt::Opaque` note: future is not `Send` as this value is used across an await --> $DIR/src/test/ui/fmt/format-with-yield-point.rs:11:37 | LL | println!("{} {:?}", "", async {}.await); | --------------------------------^^^^^^- | | | | | await occurs here, with `$crate::format_args_nl!($($arg)*)` maybe used later | has type `ArgumentV1<'_>` which is not `Send` | `$crate::format_args_nl!($($arg)*)` is later dropped here note: required by a bound in `assert_send` --> $DIR/src/test/ui/fmt/format-with-yield-point.rs:18:24 | LL | fn assert_send(_: impl Send) {} | ^^^^ required by this bound in `assert_send` error: future cannot be sent between threads safely --> $DIR/src/test/ui/fmt/format-with-yield-point.rs:22:17 | LL | assert_send(with_macro_call()); | ^^^^^^^^^^^^^^^^^ future returned by `with_macro_call` is not `Send` | = help: the trait `Sync` is not implemented for `core::fmt::Opaque` note: future is not `Send` as this value is used across an await --> $DIR/src/test/ui/fmt/format-with-yield-point.rs:6:17 | LL | async {}.await | ^^^^^^ await occurs here, with `$crate::format_args_nl!($($arg)*)` maybe used later ... LL | println!("{} {:?}", "", m!()); | ----------------------------- | | | | | in this macro invocation | has type `ArgumentV1<'_>` which is not `Send` | `$crate::format_args_nl!($($arg)*)` is later dropped here note: required by a bound in `assert_send` --> $DIR/src/test/ui/fmt/format-with-yield-point.rs:18:24 | LL | fn assert_send(_: impl Send) {} | ^^^^ required by this bound in `assert_send` = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors
2022-01-29Create `core::fmt::ArgumentV1` with generics instead of fn pointerGary Guo-0/+5
2022-01-28Extend format-args capture test.Mara Bos-1/+25
2022-01-28Add test for format args capture bug.Mara Bos-0/+17
2021-12-09Fix span calculation on secondary_label as wellMichael Goulet-0/+19
2021-11-20Do not mention associated items when they introduce an obligationEsteban Kuber-5/+0
2021-11-15Update test outputJosh Triplett-50/+46
2021-11-15Stabilize format_args_captureJosh Triplett-34/+0
Works as expected, and there are widespread reports of success with it, as well as interest in it.
2021-10-15Bless testsCameron Steffen-1/+1
2021-09-29Improve error message for `printf`-style format stringsFabian Wolff-0/+32
2021-08-16Use note to point at bound introducing requirementEsteban Küber-6/+10
2021-08-12Rollup merge of #87671 - jesyspa:issue-87319-multiple-newlines, r=estebankYuki Okushi-4/+4
Warn when an escaped newline skips multiple lines Resolves #87319
2021-08-11Modify structured suggestion outputEsteban Küber-1/+1
* On suggestions that include deletions, use a diff inspired output format * When suggesting addition, use `+` as underline * Color highlight modified span
2021-08-11Update format string tests to explicitly escape multiple newlinesAnton Golov-4/+4
From what I can tell, the goal of the tests is to ensure that the error formatting is correct. I think this is still being tested as intended after this change.
2021-07-19Various diagnostics clean ups/tweaksEsteban Küber-1/+5
* Always point at macros, including derive macros * Point at non-local items that introduce a trait requirement * On private associated item, point at definition
2021-07-06Add s to non_fmt_panicRyan Levick-7/+9
2021-06-07Fix span calculation in format stringsFabian Wolff-0/+43
2021-05-12Show macro name in 'this error originates in macro' messageAaron Hill-6/+6
When there are multiple macros in use, it can be difficult to tell which one was responsible for producing an error.
2021-02-06parse_format: treat r" as a literalDavid Hewitt-0/+11