Skip to content

Commit

Permalink
Fix try_print_visible_def_path for Rust 2018
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
da-x committed Jun 29, 2020
1 parent aab37fe commit 5427d3b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
35 changes: 18 additions & 17 deletions src/librustc_middle/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,26 +282,27 @@ pub trait PrettyPrinter<'tcx>:
// where there is no explicit `extern crate`, we just prepend
// the crate name.
match self.tcx().extern_crate(def_id) {
Some(&ExternCrate {
src: ExternCrateSource::Extern(def_id),
dependency_of: LOCAL_CRATE,
span,
..
}) => {
debug!("try_print_visible_def_path: def_id={:?}", def_id);
return Ok((
if !span.is_dummy() {
self.print_def_path(def_id, &[])?
} else {
self.path_crate(cnum)?
},
true,
));
}
Some(&ExternCrate { src, dependency_of, span, .. }) => match (src, dependency_of) {
(ExternCrateSource::Extern(def_id), LOCAL_CRATE) => {
debug!("try_print_visible_def_path: def_id={:?}", def_id);
return Ok((
if !span.is_dummy() {
self.print_def_path(def_id, &[])?
} else {
self.path_crate(cnum)?
},
true,
));
}
(ExternCrateSource::Path, LOCAL_CRATE) if self.tcx().sess.rust_2018() => {
debug!("try_print_visible_def_path: def_id={:?}", def_id);
return Ok((self.path_crate(cnum)?, true));
}
_ => {}
},
None => {
return Ok((self.path_crate(cnum)?, true));
}
_ => {}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-56175.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | reexported_trait::FooStruct.trait_method();
= help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
LL | use reexported_trait::private::Trait;
LL | use reexported_trait::Trait;
|

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

error: aborting due to 2 previous errors
Expand Down

0 comments on commit 5427d3b

Please sign in to comment.