Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions compiler/rustc_middle/src/ty/print/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::ty::{self, Ty, TyCtxt};

use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sso::SsoHashSet;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};

Expand Down Expand Up @@ -128,16 +129,27 @@ pub trait Printer<'tcx>: Sized {
self.print_impl_path(def_id, substs, self_ty, impl_trait_ref)
}

_ => {
def_path_data => {
let parent_def_id = DefId { index: key.parent.unwrap(), ..def_id };

// Inherent projections
if let DefPathData::TypeNs(_) = def_path_data
&& let DefKind::Impl { of_trait: false } = self.tcx().def_kind(parent_def_id)
&& let Some(self_ty) = substs.get(0).and_then(|subst| subst.as_type())
{
return self.path_generic_args(|cx| cx.path_append(
|cx| cx.path_qualified(self_ty, None),
&key.disambiguated_data,
), &substs[1..]);
}

let mut parent_substs = substs;
let mut trait_qualify_parent = false;
if !substs.is_empty() {
let generics = self.tcx().generics_of(def_id);
parent_substs = &substs[..generics.parent_count.min(substs.len())];

match key.disambiguated_data.data {
match def_path_data {
// Closures' own generics are only captures, don't print them.
DefPathData::ClosureExpr => {}
// This covers both `DefKind::AnonConst` and `DefKind::InlineConst`.
Expand Down