Skip to content

Commit 5427d3b

Browse files
committed
Fix try_print_visible_def_path for Rust 2018
The recursive check of `try_print_visible_def_path` did not properly handle the Rust 2018 case of crate-paths without 'extern crate'. Instead, it returned a "not found" via (false, self). This fixes issue rust-lang#56175.
1 parent aab37fe commit 5427d3b

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/librustc_middle/ty/print/pretty.rs

+18-17
Original file line numberDiff line numberDiff line change
@@ -282,26 +282,27 @@ pub trait PrettyPrinter<'tcx>:
282282
// where there is no explicit `extern crate`, we just prepend
283283
// the crate name.
284284
match self.tcx().extern_crate(def_id) {
285-
Some(&ExternCrate {
286-
src: ExternCrateSource::Extern(def_id),
287-
dependency_of: LOCAL_CRATE,
288-
span,
289-
..
290-
}) => {
291-
debug!("try_print_visible_def_path: def_id={:?}", def_id);
292-
return Ok((
293-
if !span.is_dummy() {
294-
self.print_def_path(def_id, &[])?
295-
} else {
296-
self.path_crate(cnum)?
297-
},
298-
true,
299-
));
300-
}
285+
Some(&ExternCrate { src, dependency_of, span, .. }) => match (src, dependency_of) {
286+
(ExternCrateSource::Extern(def_id), LOCAL_CRATE) => {
287+
debug!("try_print_visible_def_path: def_id={:?}", def_id);
288+
return Ok((
289+
if !span.is_dummy() {
290+
self.print_def_path(def_id, &[])?
291+
} else {
292+
self.path_crate(cnum)?
293+
},
294+
true,
295+
));
296+
}
297+
(ExternCrateSource::Path, LOCAL_CRATE) if self.tcx().sess.rust_2018() => {
298+
debug!("try_print_visible_def_path: def_id={:?}", def_id);
299+
return Ok((self.path_crate(cnum)?, true));
300+
}
301+
_ => {}
302+
},
301303
None => {
302304
return Ok((self.path_crate(cnum)?, true));
303305
}
304-
_ => {}
305306
}
306307
}
307308

src/test/ui/issues/issue-56175.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | reexported_trait::FooStruct.trait_method();
77
= help: items from traits can only be used if the trait is in scope
88
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
99
|
10-
LL | use reexported_trait::private::Trait;
10+
LL | use reexported_trait::Trait;
1111
|
1212

1313
error[E0599]: no method named `trait_method_b` found for struct `reexported_trait::FooStruct` in the current scope
@@ -19,7 +19,7 @@ LL | reexported_trait::FooStruct.trait_method_b();
1919
= help: items from traits can only be used if the trait is in scope
2020
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
2121
|
22-
LL | use reexported_trait::private::TraitB;
22+
LL | use reexported_trait::TraitBRename;
2323
|
2424

2525
error: aborting due to 2 previous errors

0 commit comments

Comments
 (0)