Skip to content

pretty: fix to print some lifetimes on HIR pretty-print #103080

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Oct 16, 2022

Conversation

ohno418
Copy link
Contributor

@ohno418 ohno418 commented Oct 15, 2022

HIR pretty-printer doesn't seem to print some lifetimes in types. This PR fixes that.

Closes #85089

@rust-highfive
Copy link
Contributor

r? @jackh726

(rust-highfive has picked a reviewer for you, use r? to override)

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 15, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 15, 2022
if !is_elided_lifetime {
nonelided_generic_args = true;
}
is_elided_lifetime
Copy link
Contributor Author

@ohno418 ohno418 Oct 15, 2022

Choose a reason for hiding this comment

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

A bit messy around here. I feel like if any better way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you replace this branch by changing the if nonelided_generic_args to if nonelided_generic_args || !elide_lifetimes below the loop?

Copy link
Contributor Author

@ohno418 ohno418 Oct 15, 2022

Choose a reason for hiding this comment

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

Yeah, that would work fine. But I have a concern that it would make nonelided_generic_args differ from what is inferred from its name.
Because in that case, nonelided_generic_args can be false, even when we have lifetime generic_args that are not elided.

Isn't it a concern that much? (or do I understand wrong?)

Copy link
Contributor

Choose a reason for hiding this comment

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

nonelided_generic_args is only used in one place, just below, so I'm not really concerned. If you want to fix that, you can change the name.
Another possibility: make lt.is_elided() into an arm guard, and let the non-elided case fall through the _ => case.
I'll let this to your judgement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nonelided_generic_args is only used in one place, just below, so I'm not really concerned.

Ah, indeed.

Another possibility: make lt.is_elided() into an arm guard, and let the non-elided case fall through the _ => case.

Thanks for the suggestion! I prefer this one a bit. But looks like non-elided case cannot fall to the _ => case, so may be like this:

                GenericArg::Lifetime(lt) if lt.is_elided() => true,
                GenericArg::Lifetime(_) => {
                    nonelided_generic_args = true;
                    false
                }
                _ => {
                    nonelided_generic_args = true;
                    true
                }

Copy link
Contributor Author

@ohno418 ohno418 Oct 15, 2022

Choose a reason for hiding this comment

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

done.

@ohno418 ohno418 force-pushed the fix-hir-pretty-print-lifetimes branch from 106bbbe to 7334526 Compare October 15, 2022 14:34
@cjgillot
Copy link
Contributor

Thanks!
@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Oct 15, 2022

📌 Commit 7334526 has been approved by cjgillot

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 15, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 15, 2022
…imes, r=cjgillot

pretty: fix to print some lifetimes on HIR pretty-print

HIR pretty-printer doesn't seem to print some lifetimes in types. This PR fixes that.

Closes rust-lang#85089
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 15, 2022
…imes, r=cjgillot

pretty: fix to print some lifetimes on HIR pretty-print

HIR pretty-printer doesn't seem to print some lifetimes in types. This PR fixes that.

Closes rust-lang#85089
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 15, 2022
…imes, r=cjgillot

pretty: fix to print some lifetimes on HIR pretty-print

HIR pretty-printer doesn't seem to print some lifetimes in types. This PR fixes that.

Closes rust-lang#85089
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 16, 2022
Rollup of 6 pull requests

Successful merges:

 - rust-lang#101717 (Add documentation about the memory layout of `UnsafeCell<T>`)
 - rust-lang#102023 (Add MaybeUninit array transpose From impls)
 - rust-lang#103033 (Update pkg-config)
 - rust-lang#103080 (pretty: fix to print some lifetimes on HIR pretty-print)
 - rust-lang#103082 (Surround type with backticks)
 - rust-lang#103088 (Fix settings page)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d08f4a6 into rust-lang:master Oct 16, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 16, 2022
@ohno418 ohno418 deleted the fix-hir-pretty-print-lifetimes branch October 16, 2022 12:23
# for free to join this conversation on GitHub. Already have an account? # 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.

HIR pretty-printer does not print lifetimes in types
6 participants