summary refs log tree commit diff
path: root/src/test/ui/hrtb
AgeCommit message (Collapse)AuthorLines
2020-05-02On type mismatch involving associated type, suggest constraintEsteban Küber-1/+1
When an associated type is found when a specific type was expected, if possible provide a structured suggestion constraining the associated type in a bound. ``` error[E0271]: type mismatch resolving `<T as Foo>::Y == i32` --> $DIR/associated-types-multiple-types-one-trait.rs:13:5 | LL | want_y(t); | ^^^^^^ expected `i32`, found associated type ... LL | fn want_y<T:Foo<Y=i32>>(t: &T) { } | ----- required by this bound in `want_y` | = note: expected type `i32` found associated type `<T as Foo>::Y` help: consider constraining the associated type `<T as Foo>::Y` to `i32` | LL | fn have_x_want_y<T:Foo<X=u32, Y = i32>>(t: &T) | ^^^^^^^^^ ``` ``` error[E0308]: mismatched types --> $DIR/trait-with-missing-associated-type-restriction.rs:12:9 | LL | qux(x.func()) | ^^^^^^^^ expected `usize`, found associated type | = note: expected type `usize` found associated type `<impl Trait as Trait>::A` help: consider constraining the associated type `<impl Trait as Trait>::A` to `usize` | LL | fn foo(x: impl Trait<A = usize>) { | ^^^^^^^^^^ ```
2020-04-30Rollup merge of #70950 - nikomatsakis:leak-check-nll-2, r=matthewjasperDylan DPC-1/+1
extend NLL checker to understand `'empty` combined with universes This PR extends the NLL region checker to understand `'empty` combined with universes. In particular, it means that the NLL region checker no longer considers `exists<R2> { forall<R1> { R1: R2 } }` to be provable. This is work towards https://github.com/rust-lang/rust/issues/59490, but we're not all the way there. One thing in particular it does not address is error messages. The modifications to the NLL region inference code turned out to be simpler than expected. The main change is to require that if `R1: R2` then `universe(R1) <= universe(R2)`. This constraint follows from the region lattice (shown below), because we assume then that `R2` is "at least" `empty(Universe(R2))`, and hence if `R1: R2` (i.e., `R1 >= R2` on the lattice) then `R1` must be in some universe that can name `'empty(Universe(R2))`, which requires that `Universe(R1) <= Universe(R2)`. ``` static ----------+-----...------+ (greatest) | | | early-bound and | | free regions | | | | | scope regions | | | | | empty(root) placeholder(U1) | | / | | / placeholder(Un) empty(U1) -- / | / ... / | / empty(Un) -------- (smallest) ``` I also made what turned out to be a somewhat unrelated change to add a special region to represent `'empty(U0)`, which we use (somewhat hackily) to indicate well-formedness checks in some parts of the compiler. This fixes #68550. I did some investigation into fixing the error message situation. That's a bit trickier: the existing "nice region error" code around placeholders relies on having better error tracing than NLL currently provides, so that it knows (e.g.) that the constraint arose from applying a trait impl and things like that. I feel like I was hoping *not* to do such fine-grained tracing in NLL, and it seems like we...largely...got away with that. I'm not sure yet if we'll have to add more tracing information or if there is some sort of alternative. It's worth pointing out though that I've not kind of shifted my opinion on whose job it should be to enforce lifetimes: I tend to think we ought to be moving back towards *something like* the leak-check (just not the one we *had*). If we took that approach, it would actually resolve this aspect of the error message problem, because we would be resolving 'higher-ranked errors' in the trait solver itself, and hence we wouldn't have to thread as much causal information back to the region checker. I think it would also help us with removing the leak check while not breaking some of the existing crates out there. Regardless, I think it's worth landing this change, because it was relatively simple and it aligns the set of programs that NLL accepts with those that are accepted by the main region checker, and hence should at least *help* us in migration (though I guess we still also have to resolve the existing crates that rely on leak check for coherence). r? @matthewjasper
2020-04-18Add label to item source of bound obligationEsteban Küber-9/+9
2020-04-16reserve variable for empty root regionNiko Matsakis-1/+1
2020-04-11rustc: Add a warning count upon completionRoccoDev-1/+1
2020-04-08Small tweaks to required bound spanEsteban Küber-1/+1
2020-03-30Rollup merge of #70546 - lqd:polonius_update, r=nikomatsakisDylan DPC-1/+2
Polonius: update to 0.12.1, fix more move errors false positives, update test expectations This PR: - updates `polonius-engine` to version 0.12.1 to fix some move errors false positives - fixes a fact generation mistake creating the other move errors false positives - updates the test expectations for the polonius compare-mode so that all (minus the 2 OOMs) ui tests pass again (matching the [analysis doc](https://hackmd.io/CjYB0fs4Q9CweyeTdKWyEg?view) starting at case 34) In my opinion, this is safe to rollup. r? @nikomatsakis
2020-03-30bless output of ui test hrtb/hrtb-perfect-forwarding.rsRemy Rakic-1/+2
trivial formatting changes
2020-03-29Tweak `suggest_constraining_type_param`Esteban Küber-12/+9
Some of the bound restriction structured suggestions were incorrect while others had subpar output.
2020-02-20Rollup merge of #68877 - estebank:point-at-params, r=petrochenkovMazdak Farrokhzad-3/+5
On mismatched argument count point at arguments
2020-02-11On mismatched argument count point at argumentsEsteban Küber-3/+5
2020-02-09Improve reporting errors and suggestions for trait boundsPatryk Wychowaniec-9/+18
2020-01-09Address review comments + Update NLL testsVadim Petrochenkov-1/+2
2020-01-09Update testsVadim Petrochenkov-4/+55
2019-12-23Refactor region error handling to be done by mirborrowckctxMark Mansi-6/+6
2019-12-06bless polonius output of test hrtb-perfect-forwarding.rsRemy Rakic-0/+68
The plan is to use chalk and not have polonius deal with this.
2019-11-28Deduplicate type param constraint suggestion codeEsteban Küber-3/+3
2019-11-21Point at type in `let` assignment on type errorsEsteban Küber-1/+3
2019-11-21Auto merge of #66389 - estebank:type-err-labels, r=petrochenkovbors-6/+4
Specific labels when referring to "expected" and "found" types
2019-11-18Remove E0308 note when primary label has all infoEsteban Küber-2/+0
2019-11-18Specific labels when referring to "expected" and "found" typesEsteban Küber-6/+6
2019-10-27update testsMark Mansi-0/+2
2019-10-15Use structured suggestion for restricting boundsEsteban Küber-6/+9
When a trait bound is not met and restricting a type parameter would make the restriction hold, use a structured suggestion pointing at an appropriate place (type param in param list or `where` clause). Account for opaque parameters where instead of suggesting extending the `where` clause, we suggest appending the new restriction: `fn foo(impl Trait + UnmetTrait)`.
2019-10-04Rollup merge of #64749 - matthewjasper:liveness-opt, r=nikomatsakisMazdak Farrokhzad-4/+9
Fix most remaining Polonius test differences This fixes most of the Polonius test differences and also avoids overflow in issue-38591.rs. r? @nikomatsakis
2019-10-02Make lifetimes in constants live at the point of useMatthew Jasper-4/+9
2019-10-01Fixup testsAaron Hill-4/+11
2019-10-01Improve HRTB error span when -Zno-leak-check is usedAaron Hill-0/+1
As described in #57374, NLL currently produces unhelpful higher-ranked trait bound (HRTB) errors when '-Zno-leak-check' is enabled. This PR tackles one half of this issue - making the error message point at the proper span. The error message itself is still the very generic "higher-ranked subtype error", but this can be improved in a follow-up PR. The root cause of the bad spans lies in how NLL attempts to compute the 'blamed' region, for which it will retrieve a span for. Consider the following code, which (correctly) does not compile: ```rust let my_val: u8 = 25; let a: &u8 = &my_val; let b = a; let c = b; let d: &'static u8 = c; ``` This will cause NLL to generate the following subtype constraints: d :< c c :< b b <: a Since normal Rust lifetimes are covariant, this results in the following region constraints (I'm using 'd to denote the lifetime of 'd', 'c to denote the lifetime of 'c, etc.): 'c: 'd 'b: 'c 'a: 'b From this, we can derive that 'a: 'd holds, which implies that 'a: 'static must hold. However, this is not the case, since 'a refers to 'my_val', which does not outlive the current function. When NLL attempts to infer regions for this code, it will see that the region 'a has grown 'too large' - it will be inferred to outlive 'static, despite the fact that is not declared as outliving 'static We can find the region responsible, 'd, by starting at the *end* of the 'constraint chain' we generated above. This works because for normal (non-higher-ranked) lifetimes, we generally build up a 'chain' of lifetime constraints *away* from the original variable/lifetime. That is, our original lifetime 'a is required to outlive progressively more regions. If it ends up living for too long, we can look at the 'end' of this chain to determine the 'most recent' usage that caused the lifetime to grow too large. However, this logic does not work correctly when higher-ranked trait bounds (HRTBs) come into play. This is because HRTBs have *contravariance* with respect to their bound regions. For example, this code snippet compiles: ```rust let a: for<'a> fn(&'a ()) = |_| {}; let b: fn(&'static ()) = a; ``` Here, we require that 'a' is a subtype of 'b'. Because of contravariance, we end up with the region constraint 'static: 'a, *not* 'a: 'static This means that our 'constraint chains' grow in the opposite direction of 'normal lifetime' constraint chains. As we introduce subtypes, our lifetime ends up being outlived by other lifetimes, rather than outliving other lifetimes. Therefore, starting at the end of the 'constraint chain' will cause us to 'blame' a lifetime close to the original definition of a variable, instead of close to where the bad lifetime constraint is introduced. This PR improves how we select the region to blame for 'too large' universal lifetimes, when bound lifetimes are involved. If the region we're checking is a 'placeholder' region (e.g. the region 'a' in for<'a>, or the implicit region in fn(&())), we start traversing the constraint chain from the beginning, rather than the end. There are two (maybe more) different ways we generate region constraints for NLL: requirements generated from trait queries, and requirements generated from MIR subtype constraints. While the former always use explicit placeholder regions, the latter is more tricky. In order to implement contravariance for HRTBs, TypeRelating replaces placeholder regions with existential regions. This requires us to keep track of whether or not an existential region was originally a placeholder region. When we look for a region to blame, we check if our starting region is either a placeholder region or is an existential region created from a placeholder region. If so, we start iterating from the beginning of the constraint chain, rather than the end.
2019-09-22Point at type param when it's cause of unfulfilled obligationEsteban Küber-14/+14
2019-09-22Fix rebaseEsteban Küber-5/+2
2019-09-22On obligation errors point at the unfulfilled binding when possibleEsteban Küber-72/+58
2019-09-21Rollup merge of #63907 - estebank:assoc-type-mismatch, r=oli-obkMazdak Farrokhzad-0/+2
Add explanation to type mismatch involving type params and assoc types CC #63711
2019-09-19When possible point at argument causing item obligation failureEsteban Küber-6/+6
2019-09-18Add explanation to type mismatch involving type params and assoc typesEsteban Küber-0/+2
2019-09-16Tweak unsatisfied HRTB errorsEsteban Küber-10/+53
2019-09-08Update test stderr with results of enabling unused lintsMark Rousskov-1/+1
2019-08-31Use span label instead of note for cause in E0631Esteban Küber-83/+63
2019-08-16Update stderr files with --blesssd234678-1/+1
2019-08-16Remove meaningless comments in src/testsd234678-1/+0
2019-07-25Rollup merge of #62736 - lqd:polonius_tests3, r=matthewjasperMazdak Farrokhzad-5/+6
Polonius: fix some cases of `killed` fact generation, and most of the `ui` test suite Since basic Polonius functionality was re-enabled by @matthewjasper in #54468, some tests were still failing in the polonius compare-mode. This PR fixes all but one test in the `ui` suite by: - fixing some bugs in the fact generation code, related to the `killed` relation: Polonius would incorrectly reject some NLL-accepted code, because of these missing `killed` facts. - ignoring some tests in the polonius compare-mode: a lot of those manually test the NLL or migrate mode, and the failures were mostly artifacts of the test revisions, e.g. that `-Z polonius` requires full NLLs. Some others were also both failing with NLL and succeeding with Polonius, which we can't encode in tests at the moment. - blessing the output of some tests: whenever Polonius and NLL have basically the same errors, except for diagnostics differences, the Polonius output is blessed. Whenever we've advanced into a less experimental phase, we'll want to revisit these cases (much like we did on the NLL test suite last year) to specifically work on diagnostics. Fact generation changes: - we now kill loans on the destination place of `Call` terminators - we now kill loans on the locals destroyed by `StorageDead` - we now also handle assignments to projections: killing the loans on a either a deref-ed local, or the ones whose `borrowed_place` conflicts with the current place. One failing test remains: an overflow during fact generation, on a case of polymorphic recursion (and which I'll continue investigating later). This adds some tests for the fact generation changes, with some simple Polonius cases similar to the existing smoke tests, but also for some cases encountered in the wild (in the `rand` crate for example). A more detailed write-up is available [here](https://hackmd.io/CjYB0fs4Q9CweyeTdKWyEg?view) with an explanation for each test failure, the steps taken to resolve it (as a commit in the current PR), NLL and Polonius outputs (and diff), etc. Since they've worked on this before, and we've discussed some of these failures together: r? @matthewjasper
2019-07-23Rollup merge of #62523 - pnkfelix:delay-bug-to-resolve-issue-62203-ice, r=varkorMark Rousskov-0/+72
Delay bug to resolve HRTB ICE Fix #62203
2019-07-22Ignore test hrtb/issue-30786.rs in Polonius compare modelqd-5/+6
2019-07-17normalize use of backticks in compiler messages for librustc/lintSamy Kacimi-1/+1
https://github.com/rust-lang/rust/issues/60532
2019-07-10Regression test for issue 30786.Felix S. Klock II-0/+140
2019-07-09Regression test.Felix S. Klock II-0/+72
2019-05-12Change compare mode to use -Zborrowck=mirMatthew Jasper-0/+85
2019-04-22update tests for migrate mode by defaultMatthew Jasper-48/+6
2019-03-17Updated UI test output to remove test annotations for revisionsMathias Blikstad-3/+3
2019-03-11Update NLL testsVadim Petrochenkov-1/+1
2019-03-11Update testsVadim Petrochenkov-12/+12
2019-02-21update test files to reflect new outputNiko Matsakis-48/+183
One surprise: old-lub-glb-object.rs, may indicate a bug