about summary refs log tree commit diff
path: root/src/test/ui/nll/relate_tys
AgeCommit message (Collapse)AuthorLines
2023-01-11Move /src/test to /testsAlbert Larsan-307/+0
2022-09-26address reviewb-naber-4/+4
2022-08-09don't normalize wf predicateslcnr-1/+11
this allows us to soundly use unnormalized projections for wf
2022-06-03Fully stabilize NLLJack Huey-26/+10
2022-03-28Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk"Oli Scherer-0/+27
This reverts commit 6499c5e7fc173a3f55b7a3bd1e6a50e9edef782d, reversing changes made to 78450d2d602b06d9b94349aaf8cece1a4acaf3a8.
2022-02-11Revert "Auto merge of #92306 - Aaron1011:opaque-type-op, r=oli-obk"Oli Scherer-27/+0
This reverts commit 1f0a96862ac9d4c6ca3e4bb500c8b9eac4d83049, reversing changes made to bf242bb1199e25ca2274df5c4114e0c9436b74e9.
2022-02-08Improve opaque type higher-ranked region error message under NLLAaron Hill-0/+27
Currently, any higher-ranked region errors involving opaque types fall back to a generic "higher-ranked subtype error" message when run under NLL. This PR adds better error message handling for this case, giving us the same kinds of error messages that we currently get without NLL: ``` error: implementation of `MyTrait` is not general enough --> $DIR/opaque-hrtb.rs:12:13 | LL | fn foo() -> impl for<'a> MyTrait<&'a str> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `MyTrait` is not general enough | = note: `impl MyTrait<&'2 str>` must implement `MyTrait<&'1 str>`, for any lifetime `'1`... = note: ...but it actually implements `MyTrait<&'2 str>`, for some specific lifetime `'2` error: aborting due to previous error ``` To accomplish this, several different refactoring needed to be made: * We now have a dedicated `InstantiateOpaqueType` struct which implements `TypeOp`. This is used to invoke `instantiate_opaque_types` during MIR type checking. * `TypeOp` is refactored to pass around a `MirBorrowckCtxt`, which is needed to report opaque type region errors. * We no longer assume that all `TypeOp`s correspond to canonicalized queries. This allows us to properly handle opaque type instantiation (which does not occur in a query) as a `TypeOp`. A new `ErrorInfo` associated type is used to determine what additional information is used during higher-ranked region error handling. * The body of `try_extract_error_from_fulfill_cx` has been moved out to a new function `try_extract_error_from_region_constraints`. This allows us to re-use the same error reporting code between canonicalized queries (which can extract region constraints directly from a fresh `InferCtxt`) and opaque type handling (which needs to take region constraints from the pre-existing `InferCtxt` that we use throughout MIR borrow checking).
2021-09-25Don't anonymize bound region names during typeckAaron Hill-4/+4
Once this anonymization has performed, we have no way of recovering the original names during NLL borrow checking. Keeping the original names allows error messages in full NLL mode to contain the original bound region names. As a result, the typeck results may contain types that differ only in the names used for their bound regions. However, anonimization of bound regions does not guarantee that all distinct types are unqual (e.g. not subtypes of each other). For example, `for<'a> fn(&'a u32, &'a u32)` and `for<'b, 'c> fn(&'b u32, &'c u32)` are subtypes of each other, as explained here: https://github.com/rust-lang/rust/blob/63cc2bb3d07d6c726dfcdc5f95cbe5ed4760641a/compiler/rustc_infer/src/infer/nll_relate/mod.rs#L682-L690 Therefore, any code handling types with higher-ranked regions already needs to handle the case where two distinct `Ty`s are 'actually' equal.
2021-08-15Report nicer errors for HRTB NLL errors from queriesMatthew Jasper-9/+19
2021-08-15Report mismatched type errors for bound region errors in NLLMatthew Jasper-13/+28
2020-10-06Separate bounds and predicates for associated/opaque typesMatthew Jasper-8/+1
2020-04-16enforce that R1: R2 requires univ(R1) <= univ(R2)Niko Matsakis-0/+56
2020-01-23Use check-pass mode for nll testsTomasz Miąsko-2/+2
2019-11-04Use check-pass in ui tests where appropriateTomasz Miąsko-1/+1
2019-10-01Improve HRTB error span when -Zno-leak-check is usedAaron Hill-0/+42
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-07-03Migrate compile-pass annotations to build-passYuki Okushi-3/+3
2019-05-12Remove feature(nll) when compare mode is sufficientMatthew Jasper-8/+1
2019-03-11Update testsVadim Petrochenkov-2/+2
2018-12-25Remove licensesMark Rousskov-53/+3
2018-12-04Update testsOliver Scherer-2/+2
2018-10-21Use new region infer errors for explaining borrowsMatthew Jasper-3/+3
This gives at least some explanation for why a borrow is expected to last for a certain free region. Also: * Reports E0373: "closure may outlive the current function" with NLL. * Special cases the case of returning a reference to (or value referencing) a local variable or temporary (E0515). * Special case assigning a reference to a local variable in a closure to a captured variable.
2018-10-10Use the span of the user type for `AscribeUserType`Matthew Jasper-2/+2
Also change the order of the fake read for let and the AscribeUserType, so that we use the better span and message from the fake read in errors.
2018-09-19Update ui testsMatthew Jasper-2/+2
2018-09-10optimize `let x: T = ..` to avoid a temporaryNiko Matsakis-14/+16
For some weird reason this fixes `intrinsic-move-val`. It also affects various test heuristics. I removed one test (`reborrow_basic`) that didn't seem to really be testing anything in particular anymore, compared to all the other tests we've got.
2018-09-10fix SCCs containing mixture of universesNiko Matsakis-0/+31
And add a test showing a universe violation getting caught.
2018-09-10insert `AscribeUserType` for ascriptionsNiko Matsakis-1/+8
2018-09-10now that we can handle subtyping, fix higher-ranked equalityNiko Matsakis-12/+1
2018-09-10add a test for variables used twiceNiko Matsakis-0/+52
2018-07-26fix reference fileNiko Matsakis-1/+1
2018-07-25Nit: improve comment in hr-fn-aau-eq-abu.rsNiko Matsakis-10/+10
2018-07-25add regression test for #48071Niko Matsakis-0/+38
Fixes #48071
2018-07-25introduce new subtypingNiko Matsakis-0/+108