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

ty::pretty: prevent infinite recursion for extern crate paths. #89738

Merged
merged 2 commits into from
Oct 17, 2021

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Oct 10, 2021

Fixes #55779, fixes #87932.

This fix is based on @estebank's idea in #55779 (comment) - but instead of trying to get try_print_visible_def_path_recur's cycle detection to work in this case, this PR "just" disables the "visible path" feature when printing the path to an extern crate, so that the old recursion chain of try_print_visible_def_path -> print_def_path -> try_print_visible_def_path, is now impossible.

Both tests have been confirmed to crash rustc because of a stack overflow, without the fix.

@rust-highfive
Copy link
Collaborator

r? @nagisa

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 10, 2021
@eddyb
Copy link
Member Author

eddyb commented Oct 10, 2021

cc @nikomatsakis @petrochenkov (I'm not sure who should review)

// in cases where the `extern crate foo` has non-trivial
// parents, e.g. it's nested in `impl foo::Trait for Bar`
// (see also issues #55779 and #87932).
self = with_no_visible_paths(|| self.print_def_path(def_id, &[]))?;
Copy link
Member

Choose a reason for hiding this comment

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

Reassigning self like this seems somewhat footgunny but looks like its already being done elsewhere…

Copy link
Member Author

Choose a reason for hiding this comment

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

This mess of an API is all "linear" so there's not really any risk - the result has to be used, because a Self value has to be returned, and the call consumes self.

@nagisa
Copy link
Member

nagisa commented Oct 10, 2021

Seems reasonable enough to me. r=me, but giving some time for others to give a look too.

@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 14, 2021
@nagisa
Copy link
Member

nagisa commented Oct 16, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Oct 16, 2021

📌 Commit f14e8dd has been approved by nagisa

@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 16, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 17, 2021
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#89738 (ty::pretty: prevent infinite recursion for `extern crate` paths.)
 - rust-lang#89888 (Make `llvm.download-ci-llvm="if-available"` work for tier 2 targets with host tools)
 - rust-lang#89945 (Remove a mention to `copy_from_slice` from `clone_from_slice` doc)
 - rust-lang#89946 (Fix an ICE with TAITs and Future)
 - rust-lang#89963 (Some "parenthesis" and "parentheses" fixes)
 - rust-lang#89975 (Add a regression test for rust-lang#85921)
 - rust-lang#89977 (Make Result::as_mut const)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 59dc218 into rust-lang:master Oct 17, 2021
@rustbot rustbot added this to the 1.57.0 milestone Oct 17, 2021
@eddyb eddyb deleted the extern-crate-recursion branch November 4, 2021 09:59
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
6 participants