diff options
| author | bors <bors@rust-lang.org> | 2019-07-11 13:34:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-07-11 13:34:29 +0000 |
| commit | 4bb6b4a5ed1cd377c5cfd97721ad12f52e63dd41 (patch) | |
| tree | 584c9e198bacd32313346f952d69805a6ae189ef /src | |
| parent | 97b1128589fdaa786a7cf65c5a6ff7ed37a1d2f3 (diff) | |
| parent | 4c58b29285015f6d7739e342e09bf3be7eea3b12 (diff) | |
| download | rust-4bb6b4a5ed1cd377c5cfd97721ad12f52e63dd41.tar.gz rust-4bb6b4a5ed1cd377c5cfd97721ad12f52e63dd41.zip | |
Auto merge of #62503 - pnkfelix:dont-recur-infiitely-from-print-def-path, r=eddyb
Dont recur infinitely from print_def_path Fix #61711
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/ty/print/pretty.rs | 26 | ||||
| -rw-r--r-- | src/test/ui/issues/auxiliary/xcrate-issue-61711-b.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-61711-once-caused-rustc-inf-loop.rs | 11 |
3 files changed, 41 insertions, 1 deletions
diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index cb0ac0f07f2..e889f2edef2 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -228,8 +228,27 @@ pub trait PrettyPrinter<'tcx>: /// from at least one local module and returns true. If the crate defining `def_id` is /// declared with an `extern crate`, the path is guaranteed to use the `extern crate`. fn try_print_visible_def_path( + self, + def_id: DefId, + ) -> Result<(Self, bool), Self::Error> { + let mut callers = Vec::new(); + self.try_print_visible_def_path_recur(def_id, &mut callers) + } + + /// Does the work of `try_print_visible_def_path`, building the + /// full definition path recursively before attempting to + /// post-process it into the valid and visible version that + /// accounts for re-exports. + /// + /// This method should only be callled by itself or + /// `try_print_visible_def_path`. + /// + /// `callers` is a chain of visible_parent's leading to `def_id`, + /// to support cycle detection during recursion. + fn try_print_visible_def_path_recur( mut self, def_id: DefId, + callers: &mut Vec<DefId>, ) -> Result<(Self, bool), Self::Error> { define_scoped_cx!(self); @@ -302,14 +321,19 @@ pub trait PrettyPrinter<'tcx>: Some(parent) => parent, None => return Ok((self, false)), }; + if callers.contains(&visible_parent) { + return Ok((self, false)); + } + callers.push(visible_parent); // HACK(eddyb) this bypasses `path_append`'s prefix printing to avoid // knowing ahead of time whether the entire path will succeed or not. // To support printers that do not implement `PrettyPrinter`, a `Vec` or // linked list on the stack would need to be built, before any printing. - match self.try_print_visible_def_path(visible_parent)? { + match self.try_print_visible_def_path_recur(visible_parent, callers)? { (cx, false) => return Ok((cx, false)), (cx, true) => self = cx, } + callers.pop(); let actual_parent = self.tcx().parent(def_id); debug!( "try_print_visible_def_path: visible_parent={:?} actual_parent={:?}", diff --git a/src/test/ui/issues/auxiliary/xcrate-issue-61711-b.rs b/src/test/ui/issues/auxiliary/xcrate-issue-61711-b.rs new file mode 100644 index 00000000000..88a040529e7 --- /dev/null +++ b/src/test/ui/issues/auxiliary/xcrate-issue-61711-b.rs @@ -0,0 +1,5 @@ +// edition:2018 +#![crate_type="lib"] +#![crate_name="xcrate_issue_61711_b"] +pub struct Struct; +pub use crate as alias; diff --git a/src/test/ui/issues/issue-61711-once-caused-rustc-inf-loop.rs b/src/test/ui/issues/issue-61711-once-caused-rustc-inf-loop.rs new file mode 100644 index 00000000000..8fc09c89f78 --- /dev/null +++ b/src/test/ui/issues/issue-61711-once-caused-rustc-inf-loop.rs @@ -0,0 +1,11 @@ +// Issue 61711: A crate pub re-exporting `crate` was causing an +// infinite loop. + +// edition:2018 +// aux-build:xcrate-issue-61711-b.rs +// compile-flags:--extern xcrate_issue_61711_b + +// run-pass + +fn f<F: Fn(xcrate_issue_61711_b::Struct)>(_: F) { } +fn main() { } |
