]> git.lizzy.rs Git - rust.git/commitdiff
Add proper names to impl Trait parameters.
authorChris Vittal <christopher.vittal@gmail.com>
Tue, 14 Nov 2017 17:27:55 +0000 (12:27 -0500)
committerChristopher Vittal <christopher.vittal@gmail.com>
Wed, 15 Nov 2017 20:46:01 +0000 (15:46 -0500)
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.

src/librustc/hir/print.rs
src/librustc_typeck/astconv.rs
src/librustc_typeck/collect.rs

index 5d8e732b17c78c976bbee230acc58c4730f25b6a..451e870f500ddcad67929e078ad6d50fb9540176 100644 (file)
@@ -423,7 +423,7 @@ pub fn print_type(&mut self, ty: &hir::Ty) -> io::Result<()> {
             }
             hir::TyImplTraitExistential(ref bounds) |
                 hir::TyImplTraitUniversal(_, ref bounds) => {
-                self.print_bounds("impl ", &bounds[..])?;
+                self.print_bounds("impl", &bounds[..])?;
             }
             hir::TyArray(ref ty, v) => {
                 self.s.word("[")?;
index 34d617a2054034ad64f685979313d7ad1353c450..7aaf65e1fd07d583e28febabc244132cc064070f 100644 (file)
@@ -30,7 +30,7 @@
 
 use std::iter;
 use syntax::{abi, ast};
-use syntax::symbol::keywords;
+use syntax::symbol::Symbol;
 use syntax::feature_gate::{GateIssue, emit_feature_err};
 use syntax_pos::Span;
 
@@ -1042,7 +1042,8 @@ pub fn ast_ty_to_ty(&self, ast_ty: &hir::Ty) -> Ty<'tcx> {
                 let impl_trait_def_id = tcx.hir.local_def_id(ast_ty.id);
                 let generics = tcx.generics_of(fn_def_id);
                 let index = generics.type_param_to_index[&impl_trait_def_id.index];
-                tcx.mk_param(index, keywords::Invalid.name() /* FIXME(chrisvittal) invalid? */)
+                tcx.mk_param(index,
+                             Symbol::intern(&tcx.hir.node_to_pretty_string(ast_ty.id)))
             }
             hir::TyPath(hir::QPath::Resolved(ref maybe_qself, ref path)) => {
                 debug!("ast_ty_to_ty: maybe_qself={:?} path={:?}", maybe_qself, path);
index 909855c1669f11f829eb98e31524c06727bf3782..76afd4e2bd1d88d5eb18a32a5a01a832740fbe28 100644 (file)
@@ -1001,7 +1001,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
         .chain(univ_impl_trait_info.iter().enumerate().map(|(i, info)| {
             ty::TypeParameterDef {
                 index: other_type_start + i as u32,
-                name: keywords::Invalid.name() /* FIXME(chrisvittal) maybe make not Invalid */,
+                name: Symbol::intern(&tcx.hir.node_to_pretty_string(info.id)),
                 def_id: info.def_id,
                 has_default: false,
                 object_lifetime_default: rl::Set1::Empty,
@@ -1732,6 +1732,7 @@ fn is_auto_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
 }
 
 struct ImplTraitUniversalInfo<'hir> {
+    id: ast::NodeId,
     def_id: DefId,
     span: Span,
     bounds: &'hir [hir::TyParamBound],
@@ -1767,6 +1768,7 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
     });
     visitor.items.into_iter().map(|ty| if let hir::TyImplTraitUniversal(_, ref bounds) = ty.node {
         ImplTraitUniversalInfo {
+            id: ty.id,
             def_id: tcx.hir.local_def_id(ty.id),
             span: ty.span,
             bounds: bounds