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

Don't repeat lifetime names from outer binder in print #102514

Merged
merged 4 commits into from
Oct 9, 2022

Conversation

b-naber
Copy link
Contributor

@b-naber b-naber commented Sep 30, 2022

Fixes #102392
Fixes #102414

r? @lcnr

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 30, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 30, 2022
*self
.region_map
.entry(br)
.or_insert_with(|| name(None, self.current_index, br))
Copy link
Contributor

Choose a reason for hiding this comment

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

is that the issue why we're not printing the binder in the src/test/ui/where-clauses/higher-ranked-fn-type.rs test?

We have both a late-bound region with name 'b and index 0 and a placeholder with name 'b and index 0.

I am not too confident in this code and ideally we stop printing placeholders as if they were bound regions.

@jackh726 do you have an idea how this should work or any expectations for how difficult it is to remove the placeholder hack all-together

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like the reason this isn't printed is that we skip the binder in the error reporting code?!

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, we shouldn't do that. Either map_bound or replace with placeholders. Skipping binders is incorrect for errors as well i think

@@ -2086,7 +2093,9 @@ impl<'a, 'tcx> ty::TypeFolder<'tcx> for RegionFolder<'a, 'tcx> {
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
let name = &mut self.name;
let region = match *r {
ty::ReLateBound(_, br) => *self.region_map.entry(br).or_insert_with(|| name(br)),
ty::ReLateBound(db, br) => {
Copy link
Contributor

@lcnr lcnr Oct 6, 2022

Choose a reason for hiding this comment

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

that's weird, why is this not

Suggested change
ty::ReLateBound(db, br) => {
ty::ReLateBound(db, br) if db == self.current_index => {

we shouldn't replace late-bound regions of inner binders.

Copy link
Contributor

Choose a reason for hiding this comment

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

(ah, that's whatyou're currently doing inside of name. i think it's better to do this here instead)

@jackh726
Copy link
Member

jackh726 commented Oct 6, 2022

Its actually crazy because I half-fixed this completely independently locally, when working on something else.

I don't think we should stop printing placeholders as bound vars. They're sort of an "internal detail" of how we solve higher-ranked bounds. What instead would you want to show the user? The lifetime name must come from somewhere.

@@ -4,7 +4,7 @@ error: higher-ranked lifetime error
LL | foo(&10);
| ^^^^^^^^
|
= note: could not prove `for<'b, 'a> &'b (): 'a`
= note: could not prove `for<'b> &'b (): '_`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the proposed change we don't create names for all anonymous late-bound vars.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this is what I did locally. Kind of weird. I guess it makes more sense to do what you had before.

@lcnr
Copy link
Contributor

lcnr commented Oct 6, 2022

I don't think we should stop printing placeholders as bound vars. They're sort of an "internal detail" of how we solve higher-ranked bounds. What instead would you want to show the user? The lifetime name must come from somewhere.

Haven't thought too deeply about this, but: Ideally we only show placeholders to users after already introducing the binder somewhere. E.g. if they are part of the trace of a selection error, we should start with the higher ranked obligation which uses for<'a> and then can just use 'a without adding a new binder for nested obligations. So we should print placeholders without mentioning their binder at all. Though the infcx should remember all placeholders it created so that we can deal with duplicate names

@jackh726
Copy link
Member

jackh726 commented Oct 8, 2022

I think this is a good start.

@bors r+

@bors
Copy link
Contributor

bors commented Oct 8, 2022

📌 Commit 048e637 has been approved by jackh726

It is now in the queue for this repository.

@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 Oct 8, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 8, 2022
…h726

Don't repeat lifetime names from outer binder in print

Fixes rust-lang#102392
Fixes rust-lang#102414

r? `@lcnr`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 8, 2022
…h726

Don't repeat lifetime names from outer binder in print

Fixes rust-lang#102392
Fixes rust-lang#102414

r? ``@lcnr``
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 9, 2022
Rollup of 8 pull requests

Successful merges:

 - rust-lang#99818 (don't ICE when normalizing closure input tys)
 - rust-lang#102514 (Don't repeat lifetime names from outer binder in print)
 - rust-lang#102661 (rustdoc: Document effect of fundamental types)
 - rust-lang#102782 (Add regression test for rust-lang#102124)
 - rust-lang#102790 (Fix llvm-tblgen for cross compiling)
 - rust-lang#102807 (Document `rust-docs-json` component)
 - rust-lang#102812 (Remove empty core::lazy and std::lazy)
 - rust-lang#102818 (Clean up rustdoc highlight.rs imports a bit)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5ba30a6 into rust-lang:master Oct 9, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 9, 2022
@b-naber b-naber deleted the binder-print-fixes branch October 9, 2022 18:27
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
7 participants