about summary refs log tree commit diff
path: root/src/test/ui/macros
AgeCommit message (Collapse)AuthorLines
2022-08-02Improve position named arguments lint underline and formatting namesPreston From-104/+220
For named arguments used as implicit position arguments, underline both the opening curly brace and either: * if there is formatting, the next character (which will either be the closing curl brace or the `:` denoting the start of formatting args) * if there is no formatting, the entire arg span (important if there is whitespace like `{ }`) This should make it more obvious where the named argument should be. Additionally, in the lint message, emit the formatting argument names without a dollar sign to avoid potentially confusion. Fixes #99907
2022-07-29Auto merge of #99660 - PrestonFrom:issue_99265, r=compiler-errorsbors-24/+864
Generate correct suggestion with named arguments used positionally 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-25Generate correct suggestion with named arguments used positionallyPreston From-24/+864
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-24Move write! and writeln! temporaries test to check-failDavid Tolnay-16/+93
2022-07-24Regression in issue 99684 fixedDavid Tolnay-31/+1
2022-07-24Add regression test minimized from async-std writeDavid Tolnay-0/+67
2022-07-19better error for bad depth on macro metavar exprMichael Goulet-8/+27
2022-07-19Rollup merge of #99435 - CAD97:revert-dollar-dollar-crate, r=Mark-SimulacrumMatthias Krüger-19/+55
Revert "Stabilize $$ in Rust 1.63.0" This mechanically reverts commit 9edaa76adce4de737db54194eb13d6c298827b37, the one commit from #95860. https://github.com/rust-lang/rust/issues/99035; the behavior of `$$crate` is potentially unexpected and not ready to be stabilized. https://github.com/rust-lang/rust/pull/99193 attempts to forbid `$$crate` without also destabilizing `$$` more generally. `@rustbot` modify labels +T-compiler +T-lang +P-medium +beta-nominated +relnotes (applying the labels I think are accurate from the issue and alternative partial revert) cc `@Mark-Simulacrum`
2022-07-19Mention first and last macro in backtraceMichael Goulet-15/+15
2022-07-18Revert "Stabilize $$ in Rust 1.63.0"Christopher Durham-19/+55
This reverts commit 9edaa76adce4de737db54194eb13d6c298827b37.
2022-07-16Rollup merge of #99213 - davidtwco:translation-migrate-passes, r=compiler-errorsMatthias Krüger-2/+2
migrate some of `rustc_passes::check_attr`'s diagnostics and derive improvements - Implements `IntoDiagnosticArg` for `char` using its `Debug` implementation and introduces a macro for those types which just delegate the implementation to `ToString`. - Apply the `#[rustc_lint_diagnostics]` attribute to `LintDiagnosticBuilder::build` so that diagnostic migration lints will trigger for it - some diagnostics in `rustc_privacy` need updated after this since the lints apply to that crate. - Add support for `MultiSpan` with any of the attributes that work on a `Span` in the diagnostic derive (`SessionDiagnostic` + `LintDiagnostic`). Requires that diagnostic logic generated for these attributes are emitted in the by-move block rather than the by-ref block that they would normally have been generated in. - Both diagnostic and subdiagnostic derives were missing the ability to add warnings to diagnostics - this is made more difficult by the `warn` attribute already existing, so this name being unavailable for the derives to use. `#[warn_]` is used instead, which requires special-casing so that `{span_,}warn` is called instead of `{span_,}warn_`. - Migrate half of the `rustc_passes::check_attr` diagnostics to using diagnostic derives and being translatable. I got tired after a while. I modified some diagnostic output for consistency while doing this, nothing too crazy. r? `@compiler-errors`
2022-07-15Fix ICE in named_arguments_used_positionally lintMichael Goulet-0/+17
2022-07-15passes: migrate half of `check_attr`David Wood-2/+2
Migrate half of the `rustc_passes::check_attr` diagnostics to using diagnostic derives and being translatable.
2022-07-13Emit warning when named arguments are used positionally in formatPreston From-0/+199
Addresses Issue 98466 by emitting a warning if a named argument is used like a position argument (i.e. the name is not used in the string to be formatted). Fixes rust-lang#98466
2022-07-01Shorten def_span for more items.Camille GILLOT-6/+2
2022-06-28Rollup merge of #98337 - c410-f3r:assert-compiler, r=oli-obkDylan DPC-38/+179
[RFC 2011] Optimize non-consuming operators Tracking issue: https://github.com/rust-lang/rust/issues/44838 Fifth step of https://github.com/rust-lang/rust/pull/96496 The most non-invasive approach that will probably have very little to no performance impact. ## Current behaviour Captures are handled "on-the-fly", i.e., they are performed in the same place expressions are located. ```rust // `let a = 1; let b = 2; assert!(a > 1 && b < 100);` if !( { ***try capture `a` and then return `a`*** } > 1 && { ***try capture `b` and then return `b`*** } < 100 ) { panic!( ... ); } ``` As such, some overhead is likely to occur (Specially with very large chains of conditions). ## New behaviour for non-consuming operators When an operator is known to not take `self`, then it is possible to capture variables **AFTER** the condition. ```rust // `let a = 1; let b = 2; assert!(a > 1 && b < 100);` if !( a > 1 && b < 100 ) { { ***try capture `a`*** } { ***try capture `b`*** } panic!( ... ); } ``` So the possible impact on the runtime execution time will be diminished. r? ````@oli-obk````
2022-06-23Rollup merge of #98353 - beetrees:builtin-macros-cfg-diag, r=davidtwcoMichael Goulet-1/+10
Migrate two diagnostics from the `rustc_builtin_macros` crate Migrate two diagnostics to use the struct derive and be translatable. r? ```@davidtwco```
2022-06-21Add UI test for `cfg!(foo, bar)`beetrees-1/+10
2022-06-21[RFC 2011] Optimize non-consuming operatorsCaio-38/+179
2022-06-21Move some tests to more reasonable directoriesCaio-0/+30
2022-06-21Auto merge of #98148 - c410-f3r:assert-compiler, r=oli-obkbors-0/+42
[RFC 2011] Expand expressions where possible Tracking issue: https://github.com/rust-lang/rust/issues/44838 Fourth step of https://github.com/rust-lang/rust/pull/96496 Extends https://github.com/rust-lang/rust/pull/97665 considering expressions that are good candidates for expansion. r? `@oli-obk`
2022-06-16diagnostics: fix trailing spaceklensy-1/+1
2022-06-15[RFC 2011] Expand expressions where possibleCaio-0/+42
2022-06-15[RFC 2011] Minimal initial implementationCaio-15/+379
2022-06-13Move testsCaio-0/+26
2022-06-07Stabilize $$ in Rust 1.63.0Caio-55/+19
2022-06-02Bless tests.Camille GILLOT-16/+1
2022-05-23Rollup merge of #97254 - jhpratt:remove-crate-vis, r=cjgillotDylan DPC-3/+1
Remove feature: `crate` visibility modifier FCP completed in #53120.
2022-05-22Add test of temporaries inside format_args of core/std macrosDavid Tolnay-0/+70
2022-05-22Rollup merge of #97043 - c410-f3r:z-errors, r=petrochenkovJack Huey-0/+17
Move some tests to more reasonable directories r? `@petrochenkov`
2022-05-21Remove feature: `crate` visibility modifierJacob Pratt-3/+1
2022-05-21Remove `crate` visibility modifier in libs, testsJacob Pratt-10/+9
2022-05-20Move testsCaio-0/+17
2022-05-13Rollup merge of #96948 - ludfo774:macro-trailing-comma-test, r=joshtriplettMatthias Krüger-0/+6
Add test of matches macro for trailing commas Almost all macros are tested for trailing commas. The macro matches! was however not tested. This PR adds that test case. Related to #46238
2022-05-12Auto merge of #96150 - est31:unused_macro_rules, r=petrochenkovbors-1/+10
Implement a lint to warn about unused macro rules This implements a new lint to warn about unused macro rules (arms/matchers), similar to the `unused_macros` lint added by #41907 that warns about entire macros. ```rust macro_rules! unused_empty { (hello) => { println!("Hello, world!") }; () => { println!("empty") }; //~ ERROR: 1st rule of macro `unused_empty` is never used } fn main() { unused_empty!(hello); } ``` Builds upon #96149 and #96156. Fixes #73576
2022-05-11Add test of matches macro for trailing commasludfo774-0/+6
2022-05-08Move some tests to more reasonable placesCaio-0/+21
2022-05-05Allow unused rules in the testsuite where the lint triggersest31-1/+10
2022-05-03Tweak wordingEsteban Kuber-2/+2
2022-05-03When suggesting to import an item, also suggest changing the path if appropriateEsteban Küber-1/+6
When we don't find an item we search all of them for an appropriate import and suggest `use`ing it. This is sometimes done for expressions that have paths with more than one segment. We now also suggest changing that path to work with the `use`. Fix #95413
2022-05-01Move some tests to more reasonable placesCaio-0/+13
2022-04-27Make [e]println macros eagerly drop temporaries (for backport)David Tolnay-1/+1
2022-04-21Move some tests to more reasonable directoriesCaio-0/+28
2022-04-16Auto merge of #92364 - jackh726:Quantumplation/65853/param-heuristics, ↵bors-1/+11
r=estebank Better method call error messages Rebase/continuation of #71827 ~Based on #92360~ ~Based on #93118~ There's a decent description in #71827 that I won't copy here (for now at least) In addition to rebasing, I've tried to restore most of the original suggestions for invalid arguments. Unfortunately, this does make some of the errors a bit verbose. To fix this will require a bit of refactoring to some of the generalized error suggestion functions, and I just don't have the time to go into it right now. I think this is in a state that the error messages are overall better than before without a reduction in the suggestions given. ~I've tried to split out some of the easier and self-contained changes into separate commits (mostly in #92360, but also one here). There might be more than can be done here, but again just lacking time.~ r? `@estebank` as the original reviewer of #71827
2022-04-16Implementation for 65853Jack Huey-1/+11
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-15Rollup merge of #94457 - jhpratt:stabilize-derive_default_enum, r=davidtwcoDylan DPC-30/+29
Stabilize `derive_default_enum` This stabilizes `#![feature(derive_default_enum)]`, as proposed in [RFC 3107](https://github.com/rust-lang/rfcs/pull/3107) and tracked in #87517. In short, it permits you to `#[derive(Default)]` on `enum`s, indicating what the default should be by placing a `#[default]` attribute on the desired variant (which must be a unit variant in the interest of forward compatibility). ```````@rustbot``````` label +S-waiting-on-review +T-lang
2022-04-09expand: Remove `ParseSess::missing_fragment_specifiers`Vadim Petrochenkov-7/+102
It was used for deduplicating some errors for legacy code which are mostly deduplicated even without that, but at cost of global mutable state, which is not a good tradeoff.
2022-04-07Stabilize `derive_default_enum`Jacob Pratt-30/+29
2022-04-07[macro_metavar_expr] Add tests to ensure the feature requirementCaio-1/+117
2022-04-01Fix `thread_local!` macro to be compatible with `no_implicit_prelude`niluxv-0/+8
Fixes issue #95533