-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Diagnose anonymous lifetimes errors more uniformly between async and regular fns #97023
Conversation
This comment has been minimized.
This comment has been minimized.
f66f4fd
to
62f7854
Compare
☔ The latest upstream changes (presumably #97258) made this pull request unmergeable. Please resolve the merge conflicts. |
LL | &'a self, foo: &dyn Foo | ||
| - let's call the lifetime of this reference `'1` | ||
| -------- help: add explicit lifetime `'a` to the type of `foo`: `&'a (dyn Foo + 'a)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3
src/test/ui/async-await/issue-75785-confusing-named-region.stderr
Outdated
Show resolved
Hide resolved
a28aeaf
to
58cceeb
Compare
This comment has been minimized.
This comment has been minimized.
@bors r+ |
📌 Commit 0cf79d7 has been approved by |
Diagnose anonymous lifetimes errors more uniformly between async and regular fns Async fns and regular fns are desugared differently. For the former, we create a generic parameter at HIR level. For the latter, we just create an anonymous region for typeck. I plan to migrate regular fns to the async fn desugaring. Before that, this PR attempts to merge the diagnostics for both cases. r? `@estebank`
Diagnose anonymous lifetimes errors more uniformly between async and regular fns Async fns and regular fns are desugared differently. For the former, we create a generic parameter at HIR level. For the latter, we just create an anonymous region for typeck. I plan to migrate regular fns to the async fn desugaring. Before that, this PR attempts to merge the diagnostics for both cases. r? ``@estebank``
Rollup of 6 pull requests Successful merges: - rust-lang#96894 (Apply track_caller to closure on `expect_non_local()`) - rust-lang#97023 (Diagnose anonymous lifetimes errors more uniformly between async and regular fns) - rust-lang#97397 (Stabilize `box_into_pin`) - rust-lang#97587 (Migrate more diagnostics to use the `#[derive(SessionDiagnostic)]`) - rust-lang#97603 (Arc make_mut doc comment spelling correction.) - rust-lang#97635 (Fix file metadata documentation for Windows) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
// If we want to print verbosely, then print *all* binders, even if they | ||
// aren't named. Eventually, we might just want this as the default, but | ||
// this is not *quite* right and changes the ordering of some output | ||
// anyways. | ||
let (new_value, map) = if self.tcx().sess.verbose() { | ||
// anon index + 1 (BrEnv takes 0) -> name | ||
let mut region_map: BTreeMap<u32, Symbol> = BTreeMap::default(); | ||
let mut region_map: FxHashMap<_, _> = Default::default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is a bit sus to me. This relies on us not having duplicate BoundRegionKind
s in binders. This is how the compiler behaves today (or should barring bugs), but there isn't nothing to say that we can't (you could, for example, imagine that we drop the anon index).
This makes more sense as just a Vec
where each index is just the BoundRegionKind
that corresponds to the binder (or just some placeholder value for non-regions) and then use BoundRegion.var.as_usize()
as an index into that vec, which is exactly how bound variables work.
(I'm making these changes currently for the bug below).
let kind = match br.kind { | ||
ty::BrNamed(_, _) => br.kind, | ||
ty::BrAnon(i) => { | ||
let name = region_map[&(i + 1)]; | ||
ty::BrNamed(CRATE_DEF_ID.to_def_id(), name) | ||
} | ||
ty::BrEnv => { | ||
let name = region_map[&0]; | ||
ty::BrNamed(CRATE_DEF_ID.to_def_id(), name) | ||
} | ||
}; | ||
let kind = region_map[&br.kind]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This broke cases under -Zverbose
where we try to print a named bound region. Above, we don't insert them in the region_map
but here we try to lookup the variable anyways.
…x, r=compiler-errors Fix pretty printing named bound regions under -Zverbose Fixed regression introduced in rust-lang#97023 r? `@compiler-errors` cc `@cjgillot`
Async fns and regular fns are desugared differently. For the former, we create a generic parameter at HIR level. For the latter, we just create an anonymous region for typeck.
I plan to migrate regular fns to the async fn desugaring.
Before that, this PR attempts to merge the diagnostics for both cases.
r? @estebank