Skip to content
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

Merged
merged 5 commits into from
Jun 2, 2022

Conversation

cjgillot
Copy link
Contributor

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

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 13, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 13, 2022
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented May 23, 2022

☔ 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)`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

@cjgillot cjgillot force-pushed the uniform-anon branch 2 times, most recently from a28aeaf to 58cceeb Compare May 29, 2022 09:18
@rust-log-analyzer

This comment has been minimized.

@estebank
Copy link
Contributor

estebank commented Jun 1, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jun 1, 2022

📌 Commit 0cf79d7 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 1, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 1, 2022
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`
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 2, 2022
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``
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 2, 2022
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
@bors bors merged commit 5c041f9 into rust-lang:master Jun 2, 2022
@rustbot rustbot added this to the 1.63.0 milestone Jun 2, 2022
@cjgillot cjgillot deleted the uniform-anon branch June 2, 2022 17:15
// 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();
Copy link
Member

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 BoundRegionKinds 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).

Comment on lines -2224 to +2220
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];
Copy link
Member

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.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 4, 2022
…x, r=compiler-errors

Fix pretty printing named bound regions under -Zverbose

Fixed regression introduced in rust-lang#97023

r? `@compiler-errors`

cc `@cjgillot`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants