diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-02-07 15:50:42 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-02-07 15:50:42 +0000 |
| commit | c93f571c2a040a29525b077e557b3d592072fcf2 (patch) | |
| tree | fca9f71e0581cae7493106f6de5fff2eb21dd232 /compiler/rustc_middle | |
| parent | 75461633350a24c3c23d387155c200ae31ccc870 (diff) | |
| download | rust-c93f571c2a040a29525b077e557b3d592072fcf2.tar.gz rust-c93f571c2a040a29525b077e557b3d592072fcf2.zip | |
Print opaque types from type aliases via their path
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/ty/print/pretty.rs | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 11a3ee53629..6521957ec94 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -644,18 +644,23 @@ pub trait PrettyPrinter<'tcx>: return Ok(self); } - let def_key = self.tcx().def_key(def_id); - if let Some(name) = def_key.disambiguated_data.data.get_opt_name() { - p!(write("{}", name)); - // FIXME(eddyb) print this with `print_def_path`. - if !substs.is_empty() { - p!("::"); - p!(generic_delimiters(|cx| cx.comma_sep(substs.iter()))); + let parent = self.tcx().parent(def_id).expect("opaque types always have a parent"); + match self.tcx().def_kind(parent) { + DefKind::TyAlias | DefKind::AssocTy => { + if let ty::Opaque(d, _) = *self.tcx().type_of(parent).kind() { + if d == def_id { + // If the type alias directly starts with the `impl` of the + // opaque type we're printing, then skip the `::{opaque#1}`. + p!(print_def_path(parent, substs)); + return Ok(self); + } + } + // Complex opaque type, e.g. `type Foo = (i32, impl Debug);` + p!(print_def_path(def_id, substs)); + return Ok(self); } - return Ok(self); + _ => return self.pretty_print_opaque_impl_type(def_id, substs), } - - return self.pretty_print_opaque_impl_type(def_id, substs); } ty::Str => p!("str"), ty::Generator(did, substs, movability) => { @@ -898,15 +903,6 @@ pub trait PrettyPrinter<'tcx>: if !first { p!(", "); } - if let GenericArgKind::Type(ty) = ty.unpack() { - if let ty::Opaque(d, substs) = *ty.kind() { - if d == def_id { - p!(print_def_path(d, substs)); - first = false; - continue; - } - } - } p!(print(trait_ref.rebind(*ty))); first = false; } |
