Skip to content

Commit 10fbc55

Browse files
committed
rustc: move the FORCE_IMPL_FILENAME_LINE handling into LocalPathPrinter.
1 parent 87c27fd commit 10fbc55

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/librustc/ty/item_path.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<P: ItemPathPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
9191
}
9292

9393
DefPathData::Impl => {
94-
self.default_print_impl_path(def_id)
94+
self.print_impl_path(def_id)
9595
}
9696

9797
// Unclear if there is any value in distinguishing these.
@@ -131,18 +131,6 @@ impl<P: ItemPathPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
131131
debug!("default_print_impl_path: impl_def_id={:?}", impl_def_id);
132132
let parent_def_id = self.tcx.parent_def_id(impl_def_id).unwrap();
133133

134-
// Always use types for non-local impls, where types are always
135-
// available, and filename/line-number is mostly uninteresting.
136-
let use_types = !impl_def_id.is_local() || {
137-
// Otherwise, use filename/line-number if forced.
138-
let force_no_types = FORCE_IMPL_FILENAME_LINE.with(|f| f.get());
139-
!force_no_types
140-
};
141-
142-
if !use_types {
143-
return self.default_print_impl_path_fallback(impl_def_id);
144-
}
145-
146134
// Decide whether to print the parent path for the impl.
147135
// Logically, since impls are global, it's never needed, but
148136
// users may find it useful. Currently, we omit the parent if
@@ -209,19 +197,6 @@ impl<P: ItemPathPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
209197
}
210198
}
211199
}
212-
213-
fn default_print_impl_path_fallback(&mut self, impl_def_id: DefId) -> P::Path {
214-
// If no type info is available, fall back to
215-
// pretty printing some span information. This should
216-
// only occur very early in the compiler pipeline.
217-
// FIXME(eddyb) this should just be using `tcx.def_span(impl_def_id)`
218-
let parent_def_id = self.tcx.parent_def_id(impl_def_id).unwrap();
219-
let path = self.print_item_path(parent_def_id);
220-
let node_id = self.tcx.hir().as_local_node_id(impl_def_id).unwrap();
221-
let item = self.tcx.hir().expect_item(node_id);
222-
let span_str = self.tcx.sess.source_map().span_to_string(item.span);
223-
self.path_append(path, &format!("<impl at {}>", span_str))
224-
}
225200
}
226201

227202
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
@@ -290,6 +265,9 @@ pub trait ItemPathPrinter: Sized {
290265
fn print_item_path(self: &mut PrintCx<'_, '_, '_, Self>, def_id: DefId) -> Self::Path {
291266
self.default_print_item_path(def_id)
292267
}
268+
fn print_impl_path(self: &mut PrintCx<'_, '_, '_, Self>, impl_def_id: DefId) -> Self::Path {
269+
self.default_print_impl_path(impl_def_id)
270+
}
293271

294272
fn path_crate(self: &mut PrintCx<'_, '_, '_, Self>, cnum: CrateNum) -> Self::Path;
295273
fn path_impl(self: &mut PrintCx<'_, '_, '_, Self>, text: &str) -> Self::Path;
@@ -472,6 +450,28 @@ impl ItemPathPrinter for LocalPathPrinter {
472450
self.try_print_visible_item_path(def_id)
473451
.unwrap_or_else(|| self.default_print_item_path(def_id))
474452
}
453+
fn print_impl_path(self: &mut PrintCx<'_, '_, '_, Self>, impl_def_id: DefId) -> Self::Path {
454+
// Always use types for non-local impls, where types are always
455+
// available, and filename/line-number is mostly uninteresting.
456+
let use_types = !impl_def_id.is_local() || {
457+
// Otherwise, use filename/line-number if forced.
458+
let force_no_types = FORCE_IMPL_FILENAME_LINE.with(|f| f.get());
459+
!force_no_types
460+
};
461+
462+
if !use_types {
463+
// If no type info is available, fall back to
464+
// pretty printing some span information. This should
465+
// only occur very early in the compiler pipeline.
466+
// FIXME(eddyb) this should just be using `tcx.def_span(impl_def_id)`
467+
let parent_def_id = self.tcx.parent_def_id(impl_def_id).unwrap();
468+
let path = self.print_item_path(parent_def_id);
469+
let span = self.tcx.def_span(impl_def_id);
470+
return self.path_append(path, &format!("<impl at {:?}>", span));
471+
}
472+
473+
self.default_print_impl_path(impl_def_id)
474+
}
475475

476476
fn path_crate(self: &mut PrintCx<'_, '_, '_, Self>, cnum: CrateNum) -> Self::Path {
477477
if cnum == LOCAL_CRATE {

0 commit comments

Comments
 (0)