]> git.lizzy.rs Git - rust.git/commitdiff
clean-up find_bound_for_assoc_item
authorAriel Ben-Yehuda <ariel.byd@gmail.com>
Sun, 19 Jul 2015 16:21:31 +0000 (19:21 +0300)
committerAriel Ben-Yehuda <ariel.byd@gmail.com>
Sun, 19 Jul 2015 21:16:37 +0000 (00:16 +0300)
src/librustc_typeck/astconv.rs

index 3bb3a630041539e737b87dfdde118fb45c79cab1..837f1be8511e700dfd674b721c6a9317b44b4daa 100644 (file)
@@ -1112,7 +1112,7 @@ fn report_ambiguous_associated_type(tcx: &ty::ctxt,
 // any ambiguity.
 fn find_bound_for_assoc_item<'tcx>(this: &AstConv<'tcx>,
                                    ty_param_node_id: ast::NodeId,
-                                   ty_param_name: Option<ast::Name>,
+                                   ty_param_name: ast::Name,
                                    assoc_name: ast::Name,
                                    span: Span)
                                    -> Result<ty::PolyTraitRef<'tcx>, ErrorReported>
@@ -1138,21 +1138,11 @@ fn find_bound_for_assoc_item<'tcx>(this: &AstConv<'tcx>,
         .filter(|b| this.trait_defines_associated_type_named(b.def_id(), assoc_name))
         .collect();
 
-    if let Some(s) = ty_param_name {
-        // borrowck doesn't like this any other way
-        one_bound_for_assoc_type(tcx,
-                                 suitable_bounds,
-                                 &token::get_name(s),
-                                 &token::get_name(assoc_name),
-                                 span)
-    } else {
-        one_bound_for_assoc_type(tcx,
-                                 suitable_bounds,
-                                 "Self",
-                                 &token::get_name(assoc_name),
-                                 span)
-
-    }
+    one_bound_for_assoc_type(tcx,
+                             suitable_bounds,
+                             &token::get_name(ty_param_name),
+                             &token::get_name(assoc_name),
+                             span)
 }
 
 
@@ -1251,7 +1241,11 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
         }
         (&ty::TyParam(_), def::DefSelfTy(Some(trait_did),  None)) => {
             assert_eq!(trait_did.krate, ast::LOCAL_CRATE);
-            match find_bound_for_assoc_item(this, trait_did.node, None, assoc_name, span) {
+            match find_bound_for_assoc_item(this,
+                                            trait_did.node,
+                                            token::special_idents::type_self.name,
+                                            assoc_name,
+                                            span) {
                 Ok(bound) => bound,
                 Err(ErrorReported) => return (tcx.types.err, ty_path_def),
             }
@@ -1260,7 +1254,7 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
             assert_eq!(param_did.krate, ast::LOCAL_CRATE);
             match find_bound_for_assoc_item(this,
                                             param_did.node,
-                                            Some(param_name),
+                                            param_name,
                                             assoc_name,
                                             span) {
                 Ok(bound) => bound,