diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2021-09-30 23:41:08 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-30 23:41:08 -0700 |
| commit | 8c5114b4e84a5a707c071982e3357fcbb3fb0a75 (patch) | |
| tree | 421b457d0454d60efb399ea5df29b6676a692bd4 /compiler/rustc_borrowck | |
| parent | 27269554b85d9202f5cdbfa09c6350498adf9d31 (diff) | |
| parent | 87a4a79554b03e2002691b8734d23fb7a556fab1 (diff) | |
| download | rust-8c5114b4e84a5a707c071982e3357fcbb3fb0a75.tar.gz rust-8c5114b4e84a5a707c071982e3357fcbb3fb0a75.zip | |
Rollup merge of #89327 - oli-obk:nll_diag_infer_vars, r=wesleywiser
Pick one possible lifetime in case there are multiple choices
In case a lifetime variable is created, but doesn't have an obvious lifetime in the list of named lifetimes that it should be inferred to, just pick the first one for the diagnostic.
This happens e.g. in
```rust
fn foo<'a, 'b>(a: Struct<'a>, b: Struct<'b>) -> impl Trait<'a, 'b> {
if bar() { a } else { b }
}
```
where we get a lifetime variable that combines the lifetimes of `a` and `b` creating a lifetime that is the intersection of both. Right now the type system cannot express this and thus we get an error, but that error also can't express this.
I can also create an entirely new diagnostic that mentions all involved lifetimes, so it would actually mention `'a` and `'b` instead of just `'b`.
Diffstat (limited to 'compiler/rustc_borrowck')
| -rw-r--r-- | compiler/rustc_borrowck/src/region_infer/opaque_types.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index b35e76b96ad..4eb7be542e7 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -124,7 +124,22 @@ impl<'tcx> RegionInferenceContext<'tcx> { ty::ReVar(vid) => { // Find something that we can name let upper_bound = self.approx_universal_upper_bound(vid); - self.definitions[upper_bound].external_name.unwrap_or(region) + let upper_bound = &self.definitions[upper_bound]; + match upper_bound.external_name { + Some(reg) => reg, + None => { + // Nothing exact found, so we pick the first one that we find. + let scc = self.constraint_sccs.scc(vid); + for vid in self.rev_scc_graph.as_ref().unwrap().upper_bounds(scc) { + match self.definitions[vid].external_name { + None => {} + Some(&ty::ReStatic) => {} + Some(region) => return region, + } + } + region + } + } } _ => region, }) |
