Skip to content

Commit 7e9948f

Browse files
committed
Add proper names to impl Trait parameters.
Uses Symbol::intern and hir.node_to_pretty_string to create a name for the impl Trait parameter that is just impl and then a ' + ' separated list of bounds that the user typed.
1 parent 2786ea6 commit 7e9948f

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/librustc/hir/print.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ impl<'a> State<'a> {
423423
}
424424
hir::TyImplTraitExistential(ref bounds) |
425425
hir::TyImplTraitUniversal(_, ref bounds) => {
426-
self.print_bounds("impl ", &bounds[..])?;
426+
self.print_bounds("impl", &bounds[..])?;
427427
}
428428
hir::TyArray(ref ty, v) => {
429429
self.s.word("[")?;

src/librustc_typeck/astconv.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use util::nodemap::FxHashSet;
3030

3131
use std::iter;
3232
use syntax::{abi, ast};
33-
use syntax::symbol::keywords;
33+
use syntax::symbol::Symbol;
3434
use syntax::feature_gate::{GateIssue, emit_feature_err};
3535
use syntax_pos::Span;
3636

@@ -1042,7 +1042,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
10421042
let impl_trait_def_id = tcx.hir.local_def_id(ast_ty.id);
10431043
let generics = tcx.generics_of(fn_def_id);
10441044
let index = generics.type_param_to_index[&impl_trait_def_id.index];
1045-
tcx.mk_param(index, keywords::Invalid.name() /* FIXME(chrisvittal) invalid? */)
1045+
tcx.mk_param(index,
1046+
Symbol::intern(&tcx.hir.node_to_pretty_string(ast_ty.id)))
10461047
}
10471048
hir::TyPath(hir::QPath::Resolved(ref maybe_qself, ref path)) => {
10481049
debug!("ast_ty_to_ty: maybe_qself={:?} path={:?}", maybe_qself, path);

src/librustc_typeck/collect.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10011001
.chain(univ_impl_trait_info.iter().enumerate().map(|(i, info)| {
10021002
ty::TypeParameterDef {
10031003
index: other_type_start + i as u32,
1004-
name: keywords::Invalid.name() /* FIXME(chrisvittal) maybe make not Invalid */,
1004+
name: Symbol::intern(&tcx.hir.node_to_pretty_string(info.id)),
10051005
def_id: info.def_id,
10061006
has_default: false,
10071007
object_lifetime_default: rl::Set1::Empty,
@@ -1732,6 +1732,7 @@ fn is_auto_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
17321732
}
17331733

17341734
struct ImplTraitUniversalInfo<'hir> {
1735+
id: ast::NodeId,
17351736
def_id: DefId,
17361737
span: Span,
17371738
bounds: &'hir [hir::TyParamBound],
@@ -1767,6 +1768,7 @@ fn extract_universal_impl_trait_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
17671768
});
17681769
visitor.items.into_iter().map(|ty| if let hir::TyImplTraitUniversal(_, ref bounds) = ty.node {
17691770
ImplTraitUniversalInfo {
1771+
id: ty.id,
17701772
def_id: tcx.hir.local_def_id(ty.id),
17711773
span: ty.span,
17721774
bounds: bounds

0 commit comments

Comments
 (0)