about summary refs log tree commit diff
path: root/tests
AgeCommit message (Collapse)AuthorLines
2024-07-18Rollup merge of #127929 - estebank:addr_of, r=compiler-errorsMatthias Krüger-39/+39
Use more accurate span for `addr_of!` suggestion Use a multipart suggestion instead of a single whole-span replacement: ``` error[E0796]: creating a shared reference to a mutable static --> $DIR/reference-to-mut-static-unsafe-fn.rs:10:18 | LL | let _y = &X; | ^^ shared reference to mutable static | = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior help: use `addr_of!` instead to create a raw pointer | LL | let _y = addr_of!(X); | ~~~~~~~~~ + ```
2024-07-18Rollup merge of #127871 - compiler-errors:recursive, r=estebankMatthias Krüger-22/+63
Mention that type parameters are used recursively on bivariance error Right now when a type parameter is used recursively, even with indirection (so it has a finite size) we say that the type parameter is unused: ``` struct B<T>(Box<B<T>>); ``` This is confusing, because the type parameter is *used*, it just doesn't have its variance constrained. This PR tweaks that message to mention that it must be used *non-recursively*. Not sure if we should actually mention "variance" here, but also I'd somewhat prefer we don't keep the power users in the dark w.r.t the real underlying issue, which is that the variance isn't constrained. That technical detail is reserved for a note, though. cc `@fee1-dead` Fixes #118976 Fixes #26283 Fixes #53191 Fixes #105740 Fixes #110466
2024-07-18Rollup merge of #127835 - estebank:issue-127823, r=compiler-errorsMatthias Krüger-6/+31
Fix ICE in suggestion caused by `⩵` being recovered as `==` The second suggestion shown here would previously incorrectly assume that the span corresponding to `⩵` was 2 bytes wide composed by 2 1 byte wide chars, so a span pointing at `==` could point only at one of the `=` to remove it. Instead, we now replace the whole thing (as we should have the whole time): ``` error: unknown start of token: \u{2a75} --> $DIR/unicode-double-equals-recovery.rs:1:16 | LL | const A: usize ⩵ 2; | ^ | help: Unicode character '⩵' (Two Consecutive Equals Signs) looks like '==' (Double Equals Sign), but it is not | LL | const A: usize == 2; | ~~ error: unexpected `==` --> $DIR/unicode-double-equals-recovery.rs:1:16 | LL | const A: usize ⩵ 2; | ^ | help: try using `=` instead | LL | const A: usize = 2; | ~ ``` Fix #127823.
2024-07-18Rollup merge of #127594 - c6c7:fuchsia-status-code-match-arm, r=tmandryMatthias Krüger-5/+3
Fuchsia status code match arm Adds a match arm for the Fuchsia status code upon a process abort. An additional change moves the Windows status code down into the match arm itself instead of being defined as a constant elsewhere. r​? tmandry
2024-07-18Rollup merge of #127418 - GuillaumeGomez:wrap-too-long-type-name, r=notriddleMatthias Krüger-1/+6
Wrap too long type name Fixes https://github.com/rust-lang/rust/issues/120595. Takeover of #126209. cc `@BradMarr` r? `@notriddle`
2024-07-18Add test for size of items in the items listGuillaume Gomez-1/+6
2024-07-18Use more accurate span for `addr_of!` suggestionEsteban Küber-39/+39
Use a multipart suggestion instead of a single whole-span replacement: ``` error[E0796]: creating a shared reference to a mutable static --> $DIR/reference-to-mut-static-unsafe-fn.rs:10:18 | LL | let _y = &X; | ^^ shared reference to mutable static | = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior help: use `addr_of!` instead to create a raw pointer | LL | let _y = addr_of!(X); | ~~~~~~~~~ + ```
2024-07-18Fix ICE in suggestion caused by `⩵` being recovered as `==`Esteban Küber-6/+31
The second suggestion shown here would previously incorrectly assume that the span corresponding to `⩵` was 2 bytes wide composed by 2 1 byte wide chars, so a span pointing at `==` could point only at one of the `=` to remove it. Instead, we now replace the whole thing (as we should have the whole time): ``` error: unknown start of token: \u{2a75} --> $DIR/unicode-double-equals-recovery.rs:1:16 | LL | const A: usize ⩵ 2; | ^ | help: Unicode character '⩵' (Two Consecutive Equals Signs) looks like '==' (Double Equals Sign), but it is not | LL | const A: usize == 2; | ~~ error: unexpected `==` --> $DIR/unicode-double-equals-recovery.rs:1:16 | LL | const A: usize ⩵ 2; | ^ | help: try using `=` instead | LL | const A: usize = 2; | ~ ```
2024-07-18Rollup merge of #127854 - fmease:glob-import-type_ir_inherent-lint, ↵Matthias Krüger-0/+106
r=compiler-errors Add internal lint for detecting non-glob imports of `rustc_type_ir::inherent` https://github.com/rust-lang/rust/pull/127627#issuecomment-2225295951 r? compiler-errors
2024-07-18Rollup merge of #127748 - scottmcm:option_len, r=joboetMatthias Krüger-1/+34
Use Option's discriminant as its size hint I was looking at this in MIR after a question on discord, and noticed that it ends up with a switch in MIR (<https://rust.godbolt.org/z/3q4cYnnb3>), which it doesn't need because (as `Option::as_slice` uses) the discriminant is already the length.
2024-07-18Rollup merge of #127656 - RalfJung:pub_use_of_private_extern_crate, ↵Matthias Krüger-1/+16
r=petrochenkov make pub_use_of_private_extern_crate show up in cargo's future breakage reports This has been a lint for many years. However, turns out that outright removing it right now would lead to [tons of crater regressions](https://github.com/rust-lang/rust/pull/127656#issuecomment-2233288534) due to crates depending on an ancient version of `bitflags`. So for now this PR just makes this future-compat lint show up in cargo's reports, so people are warned when they use a dependency that is affected by this. r? `@petrochenkov`
2024-07-18Auto merge of #117967 - adetaylor:fix-lifetime-elision-bug, r=lcnrbors-25/+466
Fix ambiguous cases of multiple & in elided self lifetimes This change proposes simpler rules to identify the lifetime on `self` parameters which may be used to elide a return type lifetime. ## The old rules (copied from [this comment](https://github.com/rust-lang/rust/pull/117967#discussion_r1420554242)) Most of the code can be found in [late.rs](https://doc.rust-lang.org/stable/nightly-rustc/src/rustc_resolve/late.rs.html) and acts on AST types. The function [resolve_fn_params](https://doc.rust-lang.org/stable/nightly-rustc/src/rustc_resolve/late.rs.html#2006), in the success case, returns a single lifetime which can be used to elide the lifetime of return types. Here's how: * If the first parameter is called self then we search that parameter using "`self` search rules", below * If no unique applicable lifetime was found, search all other parameters using "regular parameter search rules", below (In practice the code does extra work to assemble good diagnostic information, so it's not quite laid out like the above.) ### `self` search rules This is primarily handled in [find_lifetime_for_self](https://doc.rust-lang.org/stable/nightly-rustc/src/rustc_resolve/late.rs.html#2118) , and is described slightly [here](https://github.com/rust-lang/rust/issues/117715#issuecomment-1813115477) already. The code: 1. Recursively walks the type of the `self` parameter (there's some complexity about resolving various special cases, but it's essentially just walking the type as far as I can see) 2. Each time we find a reference anywhere in the type, if the **direct** referent is `Self` (either spelled `Self` or by some alias resolution which I don't fully understand), then we'll add that to a set of candidate lifetimes 3. If there's exactly one such unique lifetime candidate found, we return this lifetime. ### Regular parameter search rules 1. Find all the lifetimes in each parameter, including implicit, explicit etc. 2. If there's exactly one parameter containing lifetimes, and if that parameter contains exactly one (unique) lifetime, *and if we didn't find a `self` lifetime parameter already*, we'll return this lifetime. ## The new rules There are no changes to the "regular parameter search rules" or to the overall flow, only to the `self` search rules which are now: 1. Recursively walks the type of the `self` parameter, searching for lifetimes of reference types whose referent **contains** `Self`.[^1] 2. Keep a record of: * Whether 0, 1 or n unique lifetimes are found on references encountered during the walk 4. If no lifetime was found, we don't return a lifetime. (This means other parameters' lifetimes may be used for return type lifetime elision). 5. If there's one lifetime found, we return the lifetime. 6. If multiple lifetimes were found, we abort elision entirely (other parameters' lifetimes won't be used). [^1]: this prevents us from considering lifetimes from inside of the self-type ## Examples that were accepted before and will now be rejected ```rust fn a(self: &Box<&Self>) -> &u32 fn b(self: &Pin<&mut Self>) -> &String fn c(self: &mut &Self) -> Option<&Self> fn d(self: &mut &Box<Self>, arg: &usize) -> &usize // previously used the lt from arg ``` ### Examples that change the elided lifetime ```rust fn e(self: &mut Box<Self>, arg: &usize) -> &usize // ^ new ^ previous ``` ## Examples that were rejected before and will now be accepted ```rust fn f(self: &Box<Self>) -> &u32 ``` --- *edit: old PR description:* ```rust struct Concrete(u32); impl Concrete { fn m(self: &Box<Self>) -> &u32 { &self.0 } } ``` resulted in a confusing error. ```rust impl Concrete { fn n(self: &Box<&Self>) -> &u32 { &self.0 } } ``` resulted in no error or warning, despite apparent ambiguity over the elided lifetime. Fixes https://github.com/rust-lang/rust/issues/117715
2024-07-18make pub_use_of_private_extern_crate show up in future breakage reportsRalf Jung-1/+16
2024-07-18Add internal lint for detecting non-glob imports of `rustc_type_ir::inherent`León Orell Valerian Liehr-0/+106
2024-07-18Rollup merge of #127822 - Oneirical:amazon-rainfortest, r=jieyouxuTrevor Gross-29/+71
Migrate `issue-85401-static-mir`, `missing-crate-dependency` and `unstable-flag-required` `run-make` tests to rmake Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html). try-job: armhf-gnu try-job: test-various try-job: x86_64-msvc try-job: aarch64-apple try-job: dist-x86_64-linux
2024-07-18Rollup merge of #127687 - RalfJung:pattern-cleanup, r=oli-obk,lcnrTrevor Gross-108/+70
Const-to-pattern-to-MIR cleanup Now that all uses of constants without structural equality are hard errors, there's a bunch of cleanup we can do in the code that handles patterns: we can always funnel patterns through valtrees first (rather than having a fallback path for when valtree construction fails), and we can make sure that if we emit a `PartialEq` call it is not calling anything user-defined. To keep the error messages the same, I made valtree construction failures return the information of *which* type it is that cannot be valtree'd. `search_for_structural_match_violation` is now not needed any more at all, so I removed it. r? `@oli-obk`
2024-07-18Rollup merge of #127491 - Oneirical:bulletproof-test, r=jieyouxuTrevor Gross-48/+133
Migrate 8 very similar FFI `run-make` tests to rmake Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html). There are some more of these, but while the code is almost always the same, I want to keep the number reasonable so my doc comments can be inspected for potential inaccuracies. Tell me if 8 is too much, I can cut this down. For the tracking issue: - issue-25581 - extern-fn-with-extern-types - extern-fn-struct-passing-abi - longjmp-across-rust - static-extern-type - extern-fn-explicit-align - extern-fn-with-packed-struct - extern-fn-mangle
2024-07-18avoid creating an Instance only to immediately disassemble it againRalf Jung-63/+43
2024-07-18const_to_pat: cleanup leftovers from when we had to deal with non-structural ↵Ralf Jung-45/+27
constants
2024-07-18Rollup merge of #127889 - estebank:anon-arg-sugg, r=compiler-errorsMatthias Krüger-4/+4
More accurate span for anonymous argument suggestion Use smaller span for suggesting adding `_:` ahead of a type: ``` error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)` --> $DIR/anon-params-denied-2018.rs:12:47 | LL | fn foo_with_qualified_path(<Bar as T>::Baz); | ^ expected one of 8 possible tokens | = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) help: explicitly ignore the parameter name | LL | fn foo_with_qualified_path(_: <Bar as T>::Baz); | ++ ```
2024-07-18Rollup merge of #127888 - estebank:type-param-sugg, r=compiler-errorsMatthias Krüger-12/+18
More accurate span for type parameter suggestion After: ``` error[E0229]: associated item constraints are not allowed here --> $DIR/impl-block-params-declared-in-wrong-spot-issue-113073.rs:3:10 | LL | impl Foo<T: Default> for String {} | ^^^^^^^^^^ associated item constraint not allowed here | help: declare the type parameter right after the `impl` keyword | LL - impl Foo<T: Default> for String {} LL + impl<T: Default> Foo<T> for String {} | ``` Before: ``` error[E0229]: associated item constraints are not allowed here --> $DIR/impl-block-params-declared-in-wrong-spot-issue-113073.rs:3:10 | LL | impl Foo<T: Default> for String {} | ^^^^^^^^^^ associated item constraint not allowed here | help: declare the type parameter right after the `impl` keyword | LL | impl<T: Default> Foo<T> for String {} | ++++++++++++ ~ ```
2024-07-18Rollup merge of #127886 - estebank:as-rename-suggestion, r=compiler-errorsMatthias Krüger-37/+37
Accurate `use` rename suggestion span When suggesting to rename an import with `as`, use a smaller span to render the suggestion with a better format: ``` error[E0252]: the name `baz` is defined multiple times --> $DIR/issue-25396.rs:4:5 | LL | use foo::baz; | -------- previous import of the module `baz` here LL | use bar::baz; | ^^^^^^^^ `baz` reimported here | = note: `baz` must be defined only once in the type namespace of this module help: you can use `as` to change the binding name of the import | LL | use bar::baz as other_baz; | ++++++++++++ ```
2024-07-18Rollup merge of #127878 - estebank:assoc-item-removal, r=fmeaseMatthias Krüger-56/+95
Fix associated item removal suggestion We were previously telling people to write what was already there, instead of removal (treating it as a `help`). We now properly suggest to remove the code that needs to be removed. ``` error[E0229]: associated item constraints are not allowed here --> $DIR/E0229.rs:13:25 | LL | fn baz<I>(x: &<I as Foo<A = Bar>>::A) {} | ^^^^^^^ associated item constraint not allowed here | help: consider removing this associated item binding | LL - fn baz<I>(x: &<I as Foo<A = Bar>>::A) {} LL + fn baz<I>(x: &<I as Foo>::A) {} | ```
2024-07-18Rollup merge of #127787 - Rejyr:migrate-atomic-lock-free-rmake, r=jieyouxuMatthias Krüger-48/+52
Migrate `atomic-lock-free` to `rmake` Also adds `llvm_components_contain` to `run-make-support`. Part of #121876. r? ``@jieyouxu`` try-job: dist-x86_64-linux
2024-07-18Rollup merge of #127783 - compiler-errors:rtn-pretty, r=fee1-deadMatthias Krüger-6/+109
Put the dots back in RTN pretty printing Also don't render RTN-like bounds for methods with ty/const params.
2024-07-17Account for structs that have unused params in nested types in fieldsMichael Goulet-14/+32
2024-07-17Rollup merge of #127664 - ↵Trevor Gross-1/+55
compiler-errors:precise-capturing-better-sugg-apit, r=oli-obk Fix precise capturing suggestion for hidden regions when we have APITs Suggests to turn APITs into type parameters so they can be named in precise capturing syntax for hidden type lifetime errors. We also note that it may change the API. This is currently done via a note *and* a suggestion, which feels a bit redundant, but I wasn't totally sure of a better alternative for the presentation. Code is kind of a mess but there's a lot of cases to consider. Happy to iterate on this if you think the approach is too messy. Based on #127619, only the last commit is relevant. r? oli-obk Tracking: - https://github.com/rust-lang/rust/issues/123432
2024-07-17Rollup merge of #127542 - c410-f3r:concat-again, r=petrochenkovTrevor Gross-14/+265
[`macro_metavar_expr_concat`] Add support for literals Adds support for literals in macro parameters. ```rust macro_rules! with_literal { ($literal:literal) => { const ${concat(FOO, $literal)}: i32 = 1; } } fn main() { with_literal!("_BAR"); assert_eq!(FOO_BAR, 1); } ``` cc #124225 r? ``@petrochenkov``
2024-07-18More accurate span for anonymous argument suggestionEsteban Küber-4/+4
Use smaller span for suggesting adding `_:` ahead of a type: ``` error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)` --> $DIR/anon-params-denied-2018.rs:12:47 | LL | fn foo_with_qualified_path(<Bar as T>::Baz); | ^ expected one of 8 possible tokens | = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) help: explicitly ignore the parameter name | LL | fn foo_with_qualified_path(_: <Bar as T>::Baz); | ++ ```
2024-07-18More accurate span for type parameter suggestionEsteban Küber-12/+18
After: ``` error[E0229]: associated item constraints are not allowed here --> $DIR/impl-block-params-declared-in-wrong-spot-issue-113073.rs:3:10 | LL | impl Foo<T: Default> for String {} | ^^^^^^^^^^ associated item constraint not allowed here | help: declare the type parameter right after the `impl` keyword | LL - impl Foo<T: Default> for String {} LL + impl<T: Default> Foo<T> for String {} | ``` Before: ``` error[E0229]: associated item constraints are not allowed here --> $DIR/impl-block-params-declared-in-wrong-spot-issue-113073.rs:3:10 | LL | impl Foo<T: Default> for String {} | ^^^^^^^^^^ associated item constraint not allowed here | help: declare the type parameter right after the `impl` keyword | LL | impl<T: Default> Foo<T> for String {} | ++++++++++++ ~ ```
2024-07-18Accurate `use` rename suggestion spanEsteban Küber-37/+48
When suggesting to rename an import with `as`, use a smaller span to render the suggestion with a better format: ``` error[E0252]: the name `baz` is defined multiple times --> $DIR/issue-25396.rs:4:5 | LL | use foo::baz; | -------- previous import of the module `baz` here LL | use bar::baz; | ^^^^^^^^ `baz` reimported here | = note: `baz` must be defined only once in the type namespace of this module help: you can use `as` to change the binding name of the import | LL | use bar::baz as other_baz; | ++++++++++++ ```
2024-07-17Auto merge of #127865 - matthiaskrgr:rollup-8m49dlg, r=matthiaskrgrbors-187/+269
Rollup of 8 pull requests Successful merges: - #125042 (Use ordinal number in argument error) - #127229 (rustdoc: click target for sidebar items flush left) - #127337 (Move a few intrinsics to Rust abi) - #127472 (MIR building: Stop using `unpack!` for `BlockAnd<()>`) - #127579 (Solve a error `.clone()` suggestion when moving a mutable reference) - #127769 (Don't use implicit features in `Cargo.toml` in `compiler/`) - #127844 (Remove invalid further restricting suggestion for type bound) - #127855 (Add myself to review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2024-07-17Fix associated item removal suggestionEsteban Küber-56/+95
We were previously telling people to write what was already there, instead of removal. ``` error[E0229]: associated item constraints are not allowed here --> $DIR/E0229.rs:13:25 | LL | fn baz<I>(x: &<I as Foo<A = Bar>>::A) {} | ^^^^^^^ associated item constraint not allowed here | help: consider removing this associated item binding | LL - fn baz<I>(x: &<I as Foo<A = Bar>>::A) {} LL + fn baz<I>(x: &<I as Foo>::A) {} | ```
2024-07-17Account for self ty aliasMichael Goulet-9/+23
2024-07-17Migrate `atomic-lock-free` to `rmake`Jerry Wang-48/+52
2024-07-17rewrite unstable-flag-required to rmakeOneirical-6/+14
2024-07-17rewrite missing-crate-dependency to rmakeOneirical-9/+17
2024-07-17rewrite and rename issue-85401-static-mirOneirical-16/+42
2024-07-17Add support for literalsCaio-14/+265
2024-07-17Mention that type parameters are used recursivelyMichael Goulet-28/+37
2024-07-17rewrite extern-fn-mangle to rmakeOneirical-6/+16
2024-07-17rewrite extern-fn-with-packed-struct to rmakeOneirical-6/+17
2024-07-17rewrite extern-fn-explicit-align to rmakeOneirical-6/+17
2024-07-17rewrite static-extern-type to rmakeOneirical-6/+16
2024-07-17rewrite longjmp-across-rust to rmakeOneirical-6/+18
2024-07-17rewrite extern-fn-struct-passing-abi to rmakeOneirical-6/+16
2024-07-17rewrite and rename issue-25581Oneirical-6/+17
2024-07-17rewrite extern-fn-with-extern-types to rmakeOneirical-6/+16
2024-07-17Put the dots backMichael Goulet-6/+109
2024-07-17Fix precise capturing suggestion for hidden type when APITs are involvedMichael Goulet-1/+55