about summary refs log tree commit diff
path: root/tests
AgeCommit message (Collapse)AuthorLines
2023-02-07Auto merge of #107671 - CastilloDel:master, r=estebankbors-0/+79
Fix suggestions rendering when the diff span is multiline Fixes #92741 cc `@estebank` I think, I finally fixed. I still want to go back and try to clean up the code a bit. I'm open to suggestions. Some examples of the new suggestions: ``` help: consider removing the borrow | 2 - & | ``` ``` help: consider removing the borrow | 2 - & 3 - mut | ``` ``` help: consider removing the borrow | 2 - & 3 - mut if true { true } else { false } 2 + if true { true } else { false } | ``` Should we add a test to ensure this behavior doesn't disappear in the future?
2023-02-07Auto merge of #106180 - RalfJung:dereferenceable-generators, r=nbdd0121bors-3/+29
make &mut !Unpin not dereferenceable, and Box<!Unpin> not noalias See https://github.com/rust-lang/unsafe-code-guidelines/issues/381 and [this LLVM discussion](https://discourse.llvm.org/t/interaction-of-noalias-and-dereferenceable/66979). The exact semantics of how `noalias` and `dereferenceable` interact are unclear, and `@comex` found a case of LLVM actually exploiting that ambiguity for optimizations. I think for now we should treat LLVM `dereferenceable` as implying a "fake read" to happen immediately at the top of the function (standing in for the spurious reads that LLVM might introduce), and that fake read is subject to all the usual `noalias` restrictions. This means we cannot put `dereferenceable` on `&mut !Unpin` references as those references can alias with other references that are being read and written inside the function (e.g. for self-referential generators), meaning the fake read introduces aliasing conflicts with those other accesses. For `&` this is already not a problem due to https://github.com/rust-lang/rust/pull/98017 which removed the `dereferenceable` attribute for other reasons. Regular `&mut Unpin` references are unaffected, so I hope the impact of this is going to be tiny. The first commit does some refactoring of the `PointerKind` enum since I found the old code very confusing each time I had to touch it. It doesn't change behavior. Fixes https://github.com/rust-lang/miri/issues/2714 EDIT: Turns out our `Box<!Unpin>` treatment was incorrect, too, so the PR also fixes that now (in codegen and Miri): we do not put `noalias` on these boxes any more.
2023-02-06Rollup merge of #107692 - Swatinem:printsizeyield, r=compiler-errorsMatthias Krüger-10/+10
Sort Generator `print-type-sizes` according to their yield points Especially when trying to diagnose runaway future sizes, it might be more intuitive to sort the variants according to the control flow (aka their yield points) rather than the size of the variants.
2023-02-06Rollup merge of #106477 - ↵Matthias Krüger-14/+588
Nathan-Fenner:nathanf/refined-error-span-trait-impl, r=compiler-errors Refine error spans for "The trait bound `T: Trait` is not satisfied" when passing literal structs/tuples This PR adds a new heuristic which refines the error span reported for "`T: Trait` is not satisfied" errors, by "drilling down" into individual fields of structs/enums/tuples to point to the "problematic" value. Here's a self-contained example of the difference in error span: ```rs struct Burrito<Filling> { filling: Filling, } impl <Filling: Delicious> Delicious for Burrito<Filling> {} fn eat_delicious_food<Food: Delicious>(food: Food) {} fn will_type_error() { eat_delicious_food(Burrito { filling: Kale }); // ^~~~~~~~~~~~~~~~~~~~~~~~~ (before) The trait bound `Kale: Delicious` is not satisfied // ^~~~ (after) The trait bound `Kale: Delicious` is not satisfied } ``` (kale is fine, this is just a silly food-based example) Before this PR, the error span is identified as the entire argument to the generic function `eat_delicious_food`. However, since only `Kale` is the "problematic" part, we can point at it specifically. In particular, the primary error message itself mentions the missing `Kale: Delicious` trait bound, so it's much clearer if this part is called out explicitly. --- The _existing_ heuristic tries to label the right function argument in `point_at_arg_if_possible`. It goes something like this: - Look at the broken base trait `Food: Delicious` and find which generics it mentions (in this case, only `Food`) - Look at the parameter type definitions and find which of them mention `Filling` (in this case, only `food`) - If there is exactly one relevant parameter, label the corresponding argument with the error span, instead of the entire call This PR extends this heuristic by further refining the resulting expression span in the new `point_at_specific_expr_if_possible` function. For each `impl` in the (broken) chain, we apply the following strategy: The strategy to determine this span involves connecting information about our generic `impl` with information about our (struct) type and the (struct) literal expression: - Find the `impl` (`impl <Filling: Delicious> Delicious for Burrito<Filling>`) that links our obligation (`Kale: Delicious`) with the parent obligation (`Burrito<Kale>: Delicious`) - Find the "original" predicate constraint in the impl (`Filling: Delicious`) which produced our obligation. - Find all of the generics that are mentioned in the predicate (`Filling`). - Examine the `Self` type in the `impl`, and see which of its type argument(s) mention any of those generics. - Examing the definition for the `Self` type, and identify (for each of its variants) if there's a unique field which uses those generic arguments. - If there is a unique field mentioning the "blameable" arguments, use that field for the error span. Before we do any of this logic, we recursively call `point_at_specific_expr_if_possible` on the parent obligation. Hence we refine the `expr` "outwards-in" and bail at the first kind of expression/impl we don't recognize. This function returns a `Result<&Expr, &Expr>` - either way, it returns the `Expr` whose span should be reported as an error. If it is `Ok`, then it means it refined successfull. If it is `Err`, then it may be only a partial success - but it cannot be refined even further. --- I added a new test file which exercises this new behavior. A few existing tests were affected, since their error spans are now different. In one case, this leads to a different code suggestion for the autofix - although the new suggestion isn't _wrong_, it is different from what used to be. This change doesn't create any new errors or remove any existing ones, it just adjusts the spans where they're presented. --- Some considerations: right now, this check occurs in addition to some similar logic in `adjust_fulfillment_error_for_expr_obligation` function, which tidies up various kinds of error spans (not just trait-fulfillment error). It's possible that this new code would be better integrated into that function (or another one) - but I haven't looked into this yet. Although this code only occurs when there's a type error, it's definitely not as efficient as possible. In particular, there are definitely some cases where it degrades to quadratic performance (e.g. for a trait `impl` with 100+ generic parameters or 100 levels deep nesting of generic types). I'm not sure if these are realistic enough to worry about optimizing yet. There's also still a lot of repetition in some of the logic, where the behavior for different types (namely, `struct` vs `enum` variant) is _similar_ but not the same. --- I think the biggest win here is better targeting for tuples; in particular, if you're using tuples + traits to express variadic-like functions, the compiler can't tell you which part of a tuple has the wrong type, since the span will cover the entire argument. This change allows the individual field in the tuple to be highlighted, as in this example: ``` // NEW LL | want(Wrapper { value: (3, q) }); | ---- ^ the trait `T3` is not implemented for `Q` // OLD LL | want(Wrapper { value: (3, q) }); | ---- ^~~~~~~~~~~~~~~~~~~~~~~~~ the trait `T3` is not implemented for `Q` ``` Especially with large tuples, the existing error spans are not very effective at quickly narrowing down the source of the problem.
2023-02-06Auto merge of #107727 - Dylan-DPC:rollup-b1yexcl, r=Dylan-DPCbors-133/+550
Rollup of 5 pull requests Successful merges: - #107553 (Suggest std::ptr::null if literal 0 is given to a raw pointer function argument) - #107580 (Recover from lifetimes with default lifetimes in generic args) - #107669 (rustdoc: combine duplicate rules in ayu CSS) - #107685 (Suggest adding a return type for async functions) - #107687 (Adapt SROA MIR opt for aggregated MIR) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-02-06Add `run-rustfix` to tests/ui/issues/issue-92741.rsCastilloDel-15/+29
2023-02-06Add more test cases to tests/ui/issues/issue-92741.rsCastilloDel-1/+41
2023-02-06Rollup merge of #107687 - cjgillot:sroa-2, r=oli-obkDylan DPC-133/+334
Adapt SROA MIR opt for aggregated MIR The pass was broken by https://github.com/rust-lang/rust/pull/107267. This PR extends it to replace: ``` x = Struct { 0: a, 1: b } y = move? x ``` by assignment between locals ``` x_0 = a x_1 = b y_0 = move? x_0 y_1 = move? x_1 ``` The improved pass runs to fixpoint, so we can flatten nested field accesses.
2023-02-06Rollup merge of #107685 - jieyouxu:issue-90027, r=compiler-errorsDylan DPC-0/+57
Suggest adding a return type for async functions Fixes #90027.
2023-02-06Rollup merge of #107580 - ↵Dylan DPC-0/+14
lenko-d:default_value_for_a_lifetime_generic_parameter_produces_confusing_diagnostic, r=compiler-errors Recover from lifetimes with default lifetimes in generic args Fixes [#107492](https://github.com/rust-lang/rust/issues/107492)
2023-02-06Rollup merge of #107553 - edward-shen:edward-shen/suggest-null-ptr, ↵Dylan DPC-0/+145
r=WaffleLapkin Suggest std::ptr::null if literal 0 is given to a raw pointer function argument Implementation feels a little sus (we're parsing the span for a `0`) but it seems to fall in line the string-expected-found-char condition right above this check, so I think it's fine. Feedback appreciated on help text? I think it's consistent but it does sound a little awkward maybe? Fixes #107517
2023-02-06Auto merge of #103761 - chenyukang:yukang/fix-103320-must-use, r=compiler-errorsbors-0/+94
Add explanatory message for [#must_use] in ops Fixes #103320
2023-02-06also do not add noalias on not-Unpin BoxRalf Jung-2/+8
2023-02-06make &mut !Unpin not dereferenceableRalf Jung-1/+15
See https://github.com/rust-lang/unsafe-code-guidelines/issues/381 for discussion.
2023-02-06make PointerKind directly reflect pointer typesRalf Jung-0/+6
The code that consumes PointerKind (`adjust_for_rust_scalar` in rustc_ty_utils) ended up using PointerKind variants to talk about Rust reference types (& and &mut) anyway, making the old code structure quite confusing: one always had to keep in mind which PointerKind corresponds to which type. So this changes PointerKind to directly reflect the type. This does not change behavior.
2023-02-06Suggest return type for async function without return type许杰友 Jieyou Xu (Joe)-0/+57
2023-02-06Auto merge of #107141 - notriddle:notriddle/max-lev-distance-2023, ↵bors-9/+24
r=GuillaumeGomez rustdoc: compute maximum Levenshtein distance based on the query Preview: https://notriddle.com/notriddle-rustdoc-demos/search-lev-distance-2023/std/index.html?search=regex The heuristic is pretty close to the name resolver, maxLevDistance = `Math.floor(queryLen / 3)`. Fixes #103357 Fixes #82131 Similar to https://github.com/rust-lang/rust/pull/103710, but following the suggestion in https://github.com/rust-lang/rust/pull/103710#issuecomment-1296360267 to use `floor` instead of `ceil`, and unblocked now that https://github.com/rust-lang/rust/pull/105796 made it so that setting the max lev distance to `0` doesn't cause substring matches to be removed.
2023-02-05Auto merge of #107526 - obeis:for-missing-iterator, r=estebank,compiler-errorsbors-0/+18
Recover form missing expression in `for` loop Close #78537 r? `@estebank`
2023-02-05Add UI test for issue #92741CastilloDel-0/+25
2023-02-05Auto merge of #107663 - matthiaskrgr:107423-point-at-EOF-code, r=compiler-errorsbors-0/+39
don't point at nonexisting code beyond EOF when warning about delims Previously we would show this: ``` warning: unnecessary braces around block return value --> /tmp/bad.rs:1:8 | 1 | fn a(){{{ | ^ ^ | = note: `#[warn(unused_braces)]` on by default help: remove these braces | 1 - fn a(){{{ 1 + fn a(){{ | ``` which is now hidden in this case. We would create a span spanning between the pair of redundant {}s but there is only EOF instead of the `}` so we would previously point at nothing. This would cause the debug assertion ice to trigger. I would have loved to just only point at the second delim and say "you can remove that" but I'm not sure how to do that without refactoring the entire diagnostic which seems tricky. :( But given that this does not seem to regress any other tests we have, I think this edge-casey enough be acceptable. Fixes https://github.com/rust-lang/rust/issues/107423 r? `@compiler-errors`
2023-02-05Sort Generator `print-type-sizes` according to their yield pointsArpad Borsos-10/+10
Especially when trying to diagnose runaway future sizes, it might be more intuitive to sort the variants according to the control flow (aka their yield points) rather than the size of the variants.
2023-02-05Add ui test for missing expression in for loopObei Sideg-0/+18
2023-02-05Auto merge of #102842 - rol1510:issue-85566-fix, r=notriddlebors-10/+44
rustdoc: change trait bound formatting Fixes #85566 Before <img width="268" alt="image" src="https://user-images.githubusercontent.com/29011024/208326689-cc9b4bae-529c-473c-81e2-fc5ddb738f07.png"> Now <img width="268" alt="image" src="https://user-images.githubusercontent.com/29011024/216216918-d7923787-3e3b-486d-9735-4cecd2988dba.png">
2023-02-05Bless 32bit tests.Camille GILLOT-19/+21
2023-02-05Run SROA to fixpoint.Camille GILLOT-25/+44
2023-02-05Simplify construction of replacement map.Camille GILLOT-70/+126
2023-02-05Make SROA expand assignments.Camille GILLOT-9/+123
2023-02-05Fix SROA without deaggregation.Camille GILLOT-82/+92
2023-02-05emit `ConstEquate` in `TypeRelating<D>`Boxy-0/+70
2023-02-04Suggest null ptr if 0 is given as a raw ptr argEdward Shen-0/+145
2023-02-04Recover from default value for a lifetime in generic parameters.Lenko Donchev-0/+14
2023-02-04Rollup merge of #107646 - estebank:specific-span, r=compiler-errorsMatthias Krüger-24/+41
Provide structured suggestion for binding needing type on E0594 Partially address #45405.
2023-02-04rustdoc: trait bound formattingRoland Strasser-10/+44
rustdoc: fix item-spacer rustdoc: use proper comment style rustdoc: change formatting where clauses for traits rustdoc: remove semicolon from provided methods update provided methods formatting
2023-02-04Auto merge of #107267 - cjgillot:keep-aggregate, r=oli-obkbors-821/+528
Do not deaggregate MIR This turns out to simplify a lot of things. I haven't checked the consequences for miri yet. cc `@JakobDegen` r? `@oli-obk`
2023-02-04don't point at nonexisting code beyond EOF when warning about unused delimsMatthias Krüger-0/+39
Previously we would show this: ``` warning: unnecessary braces around block return value --> /tmp/bad.rs:1:8 | 1 | fn a(){{{ | ^ ^ | = note: `#[warn(unused_braces)]` on by default help: remove these braces | 1 - fn a(){{{ 1 + fn a(){{ | ``` which is now hidden in this case. We would create a span spanning between the pair of redundant {}s but there is only EOF instead of the `}` so we would previously point at nothing. This would cause the debug assertion ice to trigger. I would have loved to just only point at the second delim and say "you can remove that" but I'm not sure how to do that without refactoring the entire diagnostic which seems tricky. :( But given that this does not seem to regress any other tests we have, I think this edge-casey enough be acceptable. Fixes https://github.com/rust-lang/rust/issues/107423 r? @compiler-errors
2023-02-03Rollup merge of #107615 - notriddle:notriddle/nbsp, r=GuillaumeGomezMichael Goulet-5/+5
Replace nbsp in all rustdoc code blocks Based on #106125 by `@dtolnay` — this PR fixes the line wrapping bug. Fixes #106098. This makes code copyable from rustdoc rendered documentation into a Rust source file.
2023-02-03Rollup merge of #107551 - fee1-dead-contrib:rm_const_fnmut_helper, r=oli-obkMichael Goulet-3/+13
Replace `ConstFnMutClosure` with const closures Also fixes a parser bug. cc `@oli-obk` for compiler changes
2023-02-03Make const/fn return params more suggestableMichael Goulet-0/+36
2023-02-03Provide structured suggestion for binding needing type on E0594Esteban Küber-24/+41
Partially address #45405.
2023-02-03Auto merge of #107642 - Dylan-DPC:rollup-edcqhm5, r=Dylan-DPCbors-45/+285
Rollup of 6 pull requests Successful merges: - #107082 (Autotrait bounds on dyn-safe trait methods) - #107427 (Add candidates for DiscriminantKind builtin) - #107539 (Emit warnings on unused parens in index expressions) - #107544 (Improve `TokenCursor`.) - #107585 (Don't cause a cycle when formatting query description that references a FnDef) - #107633 (Fix suggestion for coercing Option<&String> to Option<&str>) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-02-03Rollup merge of #107633 - clubby789:option-string-coerce-fix, r=NilstriebDylan DPC-9/+77
Fix suggestion for coercing Option<&String> to Option<&str> Fixes #107604 This also makes the diagnostic `MachineApplicable`, and runs `rustfix` to check we're not producing incorrect code. ``@rustbot`` label +A-diagnostics
2023-02-03Rollup merge of #107585 - compiler-errors:fndef-sig-cycle, r=oli-obkDylan DPC-10/+25
Don't cause a cycle when formatting query description that references a FnDef When a function returns `-> _`, we use typeck to compute what the resulting type of the body _should_ be. If we call another query inside of typeck and hit a cycle error, we attempt to report the cycle error which requires us to compute all of the query descriptions for the stack. However, if one of the queries in that cycle has a query description that references this function as a FnDef type, we'll cause a *second* cycle error from within the cycle error reporting code, since rendering a FnDef requires us to compute its signature. This causes an unwrap to ICE, since during the *second* cycle reporting code, we try to look for a job that isn't in the active jobs list. We can avoid this by using `with_no_queries!` when computing these query descriptions. Fixes #107089 The only drawback is that the rendering of opaque types in cycles regresses a bit :| I'm open to alternate suggestions about how we may handle this...
2023-02-03Rollup merge of #107539 - PossiblyAShrub:unused-parens-in-index, r=lcnrDylan DPC-0/+41
Emit warnings on unused parens in index expressions Fixes: #96606. I am not sure what the best term for "index expression" is. Is there a better term we could use?
2023-02-03Autotrait bounds on dyn-safe trait methodsDavid Tolnay-0/+38
2023-02-03Disallow impl autotrait for trait objectDavid Tolnay-26/+104
2023-02-04Fix #103320, add explanatory message for [#must_use]yukang-0/+94
2023-02-03Replace nbsp in all rustdoc code blocksMichael Howell-5/+5
Co-Authored-By: David Tolnay <dtolnay@gmail.com>
2023-02-03Auto merge of #107599 - clubby789:debug-less-ref, r=nnethercotebors-7/+7
Don't generate unecessary `&&self.field` in deriving Debug Since unsized fields may only be the last one in a struct, we only need to generate a double reference (`&&self.field`) for the final one. cc `@nnethercote`
2023-02-03Fix suggestion for coercing Option<&String> to Option<&str>clubby789-9/+77
2023-02-03Rollup merge of #107602 - estebank:anon-enum-access, r=compiler-errorsMatthias Krüger-27/+125
Parse and recover from type ascription in patterns Reintroduce part of #106960, which was reverted in #107478. r? `@compiler-errors`