about summary refs log tree commit diff
path: root/src/test/ui
AgeCommit message (Collapse)AuthorLines
2022-01-22Fix let_chains and if_let_guard feature flagsCaio-20/+95
2022-01-22Rollup merge of #93153 - tmiasko:reject-unsupported-naked-functions, r=AmanieuMatthias Krüger-165/+87
Reject unsupported naked functions Transition unsupported naked functions future incompatibility lint into an error: * Naked functions must contain a single inline assembly block. Introduced as future incompatibility lint in 1.50 #79653. Change into an error fixes a soundness issue described in #32489. * Naked functions must not use any forms of inline attribute. Introduced as future incompatibility lint in 1.56 #87652. Closes #32490. Closes #32489. r? ```@Amanieu``` ```@npmccallum``` ```@joshtriplett```
2022-01-21Move param count error emission to near end of check_argument_typesJack Huey-1/+8
2022-01-21Auto merge of #93173 - matthiaskrgr:rollup-49bj7ta, r=matthiaskrgrbors-142/+140
Rollup of 10 pull requests Successful merges: - #91965 (Add more granular `--exclude` in `x.py`) - #92467 (Ensure that early-bound function lifetimes are always 'local') - #92586 (Set the allocation MIN_ALIGN for espidf to 4.) - #92835 (Improve error message for key="value" cfg arguments.) - #92843 (Improve string concatenation suggestion) - #92963 (Implement tuple array diagnostic) - #93046 (Use let_else in even more places) - #93109 (Improve `Arc` and `Rc` documentation) - #93134 (delete `Stdin::split` forwarder) - #93139 (rustdoc: fix overflow-wrap for table layouts) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-01-21Implement stable with negative coherence modeSantiago Pastorino-0/+26
2022-01-21Rollup merge of #92963 - terrarier2111:tuple-diagnostic, r=davidtwcoMatthias Krüger-4/+18
Implement tuple array diagnostic Fixes https://github.com/rust-lang/rust/issues/92089
2022-01-21Rollup merge of #92843 - camelid:str-concat-sugg, r=davidtwcoMatthias Krüger-30/+43
Improve string concatenation suggestion Before: error[E0369]: cannot add `&str` to `&str` --> file.rs:2:22 | 2 | let _x = "hello" + " world"; | ------- ^ -------- &str | | | | | `+` cannot be used to concatenate two `&str` strings | &str | help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left | 2 | let _x = "hello".to_owned() + " world"; | ~~~~~~~~~~~~~~~~~~ After: error[E0369]: cannot add `&str` to `&str` --> file.rs:2:22 | 2 | let _x = "hello" + " world"; | ------- ^ -------- &str | | | | | `+` cannot be used to concatenate two `&str` strings | &str | = note: string concatenation requires an owned `String` on the left help: create an owned `String` from a string reference | 2 | let _x = "hello".to_owned() + " world"; | +++++++++++
2022-01-21Rollup merge of #92835 - iwanders:issue-66450-improve-cfg-error-message, ↵Matthias Krüger-2/+8
r=nagisa Improve error message for key="value" cfg arguments. Hi, I ran into difficulties using the `--cfg` flag syntax, first hit when googling for the error was issue https://github.com/rust-lang/rust/issues/66450. Reading that issue, it sounded like the best way to improve the experience was to improve the error message, this is low risk and doesn't introduce any additional argument parsing. The issue mentions that it is entirely dependent on the shell, while this may be true, I think guiding the the user into the realization that the quotes may need to be escaped is helpful. The two suggested escapings both work in Bash and in the Windows command prompt. fyi `@ehuss`
2022-01-21Rollup merge of #92467 - Aaron1011:extern-local-region, r=oli-obkMatthias Krüger-106/+71
Ensure that early-bound function lifetimes are always 'local' During borrowchecking, we treat any free (early-bound) regions on the 'defining type' as `RegionClassification::External`. According to the doc comments, we should only have 'external' regions when checking a closure/generator. However, a plain function can also have some if its regions be considered 'early bound' - this occurs when the region is constrained by an argument, appears in a `where` clause, or in an opaque type. This was causing us to incorrectly mark these regions as 'external', which caused some diagnostic code to act as if we were referring to a 'parent' region from inside a closure. This PR marks all instantiated region variables as 'local' when we're borrow-checking something other than a closure/generator/inline-const.
2022-01-21Auto merge of #92363 - the8472:less-compiletest-normalization, r=Mark-Simulacrumbors-35/+35
Override rustc version in ui and mir-opt tests to get stable hashes Building a dozen separate regexps for each test in compiletest consumes significant amounts of CPU cycles. UI test timings on my machine: OLD: 39.63s NEW: 30.27s
2022-01-21Add regression test for #93161Eric Holk-0/+93
2022-01-21Disable drop range tracking in generatorsEric Holk-0/+20
Generator drop tracking caused an ICE for generators involving the Never type (Issue #93161). Since this breaks miri, we temporarily disable drop tracking so miri is unblocked while we properly fix the issue.
2022-01-21Auto merge of #91359 - dtolnay:args, r=Mark-Simulacrumbors-12/+17
Emit simpler code from format_args I made this PR so that `cargo expand` dumps a less overwhelming amount of formatting-related code. <br> `println!("rust")` **Before:** ```rust { ::std::io::_print(::core::fmt::Arguments::new_v1(&["rust\n"], &match () { _args => [], })); }; ``` **After:** ```rust { ::std::io::_print(::core::fmt::Arguments::new_v1(&["rust\n"], &[])); }; ``` `println!("{}", x)` **Before:** ```rust { ::std::io::_print(::core::fmt::Arguments::new_v1( &["", "\n"], &match (&x,) { _args => [::core::fmt::ArgumentV1::new( _args.0, ::core::fmt::Display::fmt, )], }, )); }; ``` **After:** ```rust { ::std::io::_print(::core::fmt::Arguments::new_v1( &["", "\n"], &[::core::fmt::ArgumentV1::new(&x, ::core::fmt::Display::fmt)], )); }; ```
2022-01-21Auto merge of #93138 - matthiaskrgr:rollup-m8akifd, r=matthiaskrgrbors-105/+507
Rollup of 17 pull requests Successful merges: - #91032 (Introduce drop range tracking to generator interior analysis) - #92856 (Exclude "test" from doc_auto_cfg) - #92860 (Fix errors on blanket impls by ignoring the children of generated impls) - #93038 (Fix star handling in block doc comments) - #93061 (Only suggest adding `!` to expressions that can be macro invocation) - #93067 (rustdoc mobile: fix scroll offset when jumping to internal id) - #93086 (Add tests to ensure that `let_chains` works with `if_let_guard`) - #93087 (Fix src/test/run-make/raw-dylib-alt-calling-convention) - #93091 (⬆ chalk to 0.76.0) - #93094 (src/test/rustdoc-json: Check for `struct_field`s in `variant_tuple_struct.rs`) - #93098 (Show a more informative panic message when `DefPathHash` does not exist) - #93099 (rustdoc: auto create output directory when "--output-format json") - #93102 (Pretty printer algorithm revamp step 3) - #93104 (Support --bless for pp-exact pretty printer tests) - #93114 (update comment for `ensure_monomorphic_enough`) - #93128 (Add script to prevent point releases with same number as existing ones) - #93136 (Backport the 1.58.1 release notes to master) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-01-21Reject may_unwind option in naked functionsTomasz Miąsko-10/+22
2022-01-21Reject unsupported naked functionsTomasz Miąsko-165/+75
Transition unsupported naked functions future incompatibility lint into an error: * Naked functions must contain a single inline assembly block. Introduced as future incompatibility lint in 1.50 #79653. Change into an error fixes a soundness issue described in #32489. * Naked functions must not use any forms of inline attribute. Introduced as future incompatibility lint in 1.56 #87652.
2022-01-21Override rustc version in ui and mir-opt tests to get stable hashesThe 8472-35/+35
Building a dozen separate regexps for each test in compiletest consumes significant amounts of CPU cycles. Using `RUSTC_FORCE_INCR_COMP_ARTIFACT_HEADER` stabilizes hashes calcuated for the individual tests so no test-dependent normalization is needed. Hashes for the standard library still change so some normalizations are still needed.
2022-01-20Rollup merge of #93086 - c410-f3r:let-guard, r=Mark-SimulacrumMatthias Krüger-2/+26
Add tests to ensure that `let_chains` works with `if_let_guard` The current machinery already makes such combination possible but lacks tests. cc `@matthewjasper`
2022-01-20Rollup merge of #93061 - estebank:macr-suggestion, r=cjgillotMatthias Krüger-23/+68
Only suggest adding `!` to expressions that can be macro invocation
2022-01-20Rollup merge of #91032 - eholk:generator-drop-tracking, r=nikomatsakisMatthias Krüger-80/+413
Introduce drop range tracking to generator interior analysis This PR addresses cases such as this one from #57478: ```rust struct Foo; impl !Send for Foo {} let _: impl Send = || { let guard = Foo; drop(guard); yield; }; ``` Previously, the `generator_interior` pass would unnecessarily include the type `Foo` in the generator because it was not aware of the behavior of `drop`. We fix this issue by introducing a drop range analysis that finds portions of the code where a value is guaranteed to be dropped. If a value is dropped at all suspend points, then it is no longer included in the generator type. Note that we are using "dropped" in a generic sense to include any case in which a value has been moved. That is, we do not only look at calls to the `drop` function. There are several phases to the drop tracking algorithm, and we'll go into more detail below. 1. Use `ExprUseVisitor` to find values that are consumed and borrowed. 2. `DropRangeVisitor` uses consume and borrow information to gather drop and reinitialization events, as well as build a control flow graph. 3. We then propagate drop and reinitialization information through the CFG until we reach a fix point (see `DropRanges::propagate_to_fixpoint`). 4. When recording a type (see `InteriorVisitor::record`), we check the computed drop ranges to see if that value is definitely dropped at the suspend point. If so, we skip including it in the type. ## 1. Use `ExprUseVisitor` to find values that are consumed and borrowed. We use `ExprUseVisitor` to identify the places where values are consumed. We track both the `hir_id` of the value, and the `hir_id` of the expression that consumes it. For example, in the expression `[Foo]`, the `Foo` is consumed by the array expression, so after the array expression we can consider the `Foo` temporary to be dropped. In this process, we also collect values that are borrowed. The reason is that the MIR transform for generators conservatively assumes anything borrowed is live across a suspend point (see `rustc_mir_transform::generator::locals_live_across_suspend_points`). We match this behavior here as well. ## 2. Gather drop events, reinitialization events, and control flow graph After finding the values of interest, we perform a post-order traversal over the HIR tree to find the points where these values are dropped or reinitialized. We use the post-order index of each event because this is how the existing generator interior analysis refers to the position of suspend points and the scopes of variables. During this traversal, we also record branching and merging information to handle control flow constructs such as `if`, `match`, and `loop`. This is necessary because values may be dropped along some control flow paths but not others. ## 3. Iterate to fixed point The previous pass found the interesting events and locations, but now we need to find the actual ranges where things are dropped. Upon entry, we have a list of nodes ordered by their position in the post-order traversal. Each node has a set of successors. For each node we additionally keep a bitfield with one bit per potentially consumed value. The bit is set if we the value is dropped along all paths entering this node. To compute the drop information, we first reverse the successor edges to find each node's predecessors. Then we iterate through each node, and for each node we set its dropped value bitfield to the intersection of all incoming dropped value bitfields. If any bitfield for any node changes, we re-run the propagation loop again. ## 4. Ignore dropped values across suspend points At this point we have a data structure where we can ask whether a value is guaranteed to be dropped at any post order index for the HIR tree. We use this information in `InteriorVisitor` to check whether a value in question is dropped at a particular suspend point. If it is, we do not include that value's type in the generator type. Note that we had to augment the region scope tree to include all yields in scope, rather than just the last one as we did before. r? `@nikomatsakis`
2022-01-20Rollup merge of #92704 - 5225225:std_mem_transmute_ref_t_mut_t, ↵Matthias Krüger-2/+2
r=michaelwoerister Change lint message to be stronger for &T -> &mut T transmute The old message implied that it's only UB if you use the reference to mutate, which (as far as I know) is not true. As in, the following program has UB, and a &T -> &mut T transmute is effectively an `unreachable_unchecked`. ```rust fn main() { #[allow(mutable_transmutes)] unsafe { let _ = std::mem::transmute::<&i32, &mut i32>(&0); } } ``` In the future, it might be a good idea to use the edition system to make this a hard error, since I don't think it is *ever* defined behaviour? Unless we rule that `&UnsafeCell<i32> -> &mut i32` is fine. (That, and you always could just use `.get()`, so you're not losing anything)
2022-01-20Rollup merge of #92582 - lcnr:generic-arg-infer, r=BoxyUwUMatthias Krüger-216/+375
improve `_` constants in item signature handling removing the "type" from the error messages does slightly worsen the error messages for types, but figuring out whether the placeholder is for a type or a constant and correctly dealing with that seemed fairly difficult to me so I took the easy way out :sparkles: Imo the error message is still clear enough. r? `@BoxyUwU` cc `@estebank`
2022-01-20Rollup merge of #92183 - tmandry:issue-74256, r=estebankMatthias Krüger-174/+133
Point at correct argument when async fn output type lifetime disagrees with signature Fixes most of #74256. ## Problems fixed This PR fixes a couple of related problems in the error reporting code. ### Highlighting the wrong argument First, the error reporting code was looking at the desugared return type of an `async fn` to decide which parameter to highlight. For example, a function like ```rust async fn async_fn(self: &Struct, f: &u32) -> &u32 { f } ``` desugars to ```rust async fn async_fn<'a, 'b>(self: &'a Struct, f: &'b u32) -> impl Future<Output = &'a u32> + 'a + 'b { f } ``` Since `f: &'b u32` is returned but the output type is `&'a u32`, the error would occur when checking that `'a: 'b`. The reporting code would look to see if the "offending" lifetime `'b` was included in the return type, and because the code was looking at the desugared future type, it was included. So it defaulted to reporting that the source of the other lifetime `'a` (the `self` type) was the problem, when it was really the type of `f`. (Note that if it had chosen instead to look at `'a` first, it too would have been included in the output type, and it would have arbitrarily reported the error (correctly this time) on the type of `f`.) Looking at the actual future type isn't useful for this reason; it captures all input lifetimes. Using the written return type for `async fn` solves this problem and results in less confusing error messages for the user. This isn't a perfect fix, unfortunately; writing the "manually desugared" form of the above function still results in the wrong parameter being highlighted. Looking at the output type of every `impl Future` return type doesn't feel like a very principled approach, though it might work. The problem would remain for function signatures that look like the desugared one above but use different traits. There may be deeper changes required to pinpoint which part of each type is conflicting. ### Lying about await point capture causing lifetime conflicts The second issue fixed by this PR is the unnecessary complexity in `try_report_anon_anon_conflict`. It turns out that the root cause I suggested in https://github.com/rust-lang/rust/issues/76547#issuecomment-692863608 wasn't really the root cause. Adding special handling to report that a variable was captured over an await point only made the error messages less correct and pointed to a problem other than the one that actually occurred. Given the above discussion, it's easy to see why: `async fn`s capture all input lifetimes in their return type, so holding an argument across an await point should never cause a lifetime conflict! Removing the special handling simplified the code and improved the error messages (though they still aren't very good!) ## Future work * Fix error reporting on the "desugared" form of this code * Get the `suggest_adding_lifetime_params` suggestion firing on these examples * cc #42703, I think r? `@estebank`
2022-01-20Tweak `expr.await` desugaring `Span`Esteban Kuber-0/+38
Fix #93074
2022-01-19Foreign types are trivially dropMichael Goulet-0/+13
- Also rename a trivial_const_drop to match style of other functions in the util module. - Also add a test for `const Drop` that doesn't depend on a `~const` bound. - Also comment a bit why we remove the const bound during dropck impl check.
2022-01-19Simplify error reporting code, remove await point wordingTyler Mandry-135/+100
2022-01-19NiceRegionError: Use written return type for async fnTyler Mandry-139/+133
2022-01-19never is trivially const-drop, and add testMichael Goulet-0/+2
2022-01-19Add links to the reference and rust by example for asm! docs and lintsAmanieu d'Antras-0/+36
2022-01-19Add tests to ensure that let_chains works with if_let_guardCaio-2/+26
2022-01-19Rollup merge of #92316 - petrochenkov:extmangle, r=wesleywiserMatthias Krüger-0/+39
mangling_v0: Skip extern blocks during mangling There's no need to include the dummy `Nt` into the symbol name, items in extern blocks belong to their parent modules for all purposes except for inheriting the ABI and attributes. Follow up to https://github.com/rust-lang/rust/pull/92032 (There's also a drive-by fix to the `rust-demangler` tool's tests, which don't run on CI, I initially attempted using them for testing this PR.)
2022-01-19Only suggest adding `!` to expressions that can be macro invocationEsteban Kuber-23/+68
2022-01-19Rollup merge of #92783 - FabianWolff:issue-92726, r=nikomatsakisMatthias Krüger-0/+33
Annotate dead code lint with notes about ignored derived impls Fixes #92726. CC `@pmetzger,` is this what you had in mind? r? `@nikomatsakis`
2022-01-19Rollup merge of #88642 - c410-f3r:let_chains_2, r=matthewjasperMatthias Krüger-304/+463
Formally implement let chains ## Let chains My longest and hardest contribution since #64010. Thanks to `@Centril` for creating the RFC and special thanks to `@matthewjasper` for helping me since the beginning of this journey. In fact, `@matthewjasper` did much of the complicated MIR stuff so it's true to say that this feature wouldn't be possible without him. Thanks again `@matthewjasper!` With the changes proposed in this PR, it will be possible to chain let expressions along side local variable declarations or ordinary conditional expressions. In other words, do much of what the `if_chain` crate already does. ## Other considerations * `if let guard` and `let ... else` features need special care and should be handled in a following PR. * Irrefutable patterns are allowed within a let chain context * ~~Three Clippy lints were already converted to start dogfooding and help detect possible corner cases~~ cc #53667
2022-01-18Make suggestions verboseNoah Lev-43/+77
2022-01-18Shorten and improve messagesNoah Lev-107/+55
2022-01-18Formally implement let chainsCaio-304/+463
2022-01-18Respond to code review commentsEric Holk-4/+69
2022-01-18Safely handle partial dropsEric Holk-2/+83
We previously weren't tracking partial re-inits while being too aggressive around partial drops. With this change, we simply ignore partial drops, which is the safer, more conservative choice.
2022-01-18Update async-fn-nonsend.rsEric Holk-5/+43
The previous commit made the non_sync_with_method_call case pass due to the await being unreachable. Unfortunately, this isn't actually the behavior the test was verifying. This change lifts the panic into a helper function so that the generator analysis still thinks the await is reachable, and therefore we preserve the same testing behavior.
2022-01-18Handle uninhabited return typesEric Holk-29/+3
This changes drop range analysis to handle uninhabited return types such as `!`. Since these calls to these functions do not return, we model them as ending in an infinite loop.
2022-01-18Handle empty loops betterEric Holk-4/+12
2022-01-18Handle reinits in match guardsEric Holk-0/+25
2022-01-18Update stderr filesEric Holk-5/+5
2022-01-18Address code review commentsEric Holk-0/+21
1. Add test case for partial drops 2. Simplify code in `propagate_to_fixpoint` and remove most clones 3. Clean up PostOrderIndex creation
2022-01-18Update async-fn-nonsend.stderrEric Holk-29/+6
2022-01-18Handle more cases with conditionally initialized/dropped valuesEric Holk-2/+42
2022-01-18Basic loop supportEric Holk-1/+1
2022-01-18Support reinitialization of variablesEric Holk-22/+81
2022-01-18Support conditional dropsEric Holk-0/+22
This adds support for branching and merging control flow and uses this to correctly handle the case where a value is dropped in one branch of an if expression but not another. There are other cases we need to handle, which will come in follow up patches. Issue #57478