// any ambiguity.
fn find_bound_for_assoc_item<'tcx>(this: &AstConv<'tcx>,
ty_param_node_id: ast::NodeId,
+ ty_param_name: Option<ast::Name>,
assoc_name: ast::Name,
span: Span)
-> Result<ty::PolyTraitRef<'tcx>, ErrorReported>
.filter(|b| this.trait_defines_associated_type_named(b.def_id(), assoc_name))
.collect();
- let ty_param_name = tcx.type_parameter_def(ty_param_node_id).name;
- one_bound_for_assoc_type(tcx,
- suitable_bounds,
- &token::get_name(ty_param_name),
- &token::get_name(assoc_name),
- span)
+ 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)
+
+ }
}
_ => unreachable!()
}
}
- (&ty::TyParam(_), def::DefTyParam(..)) |
- (&ty::TyParam(_), def::DefSelfTy(Some(_), None)) => {
- // A type parameter or Self, we need to find the associated item from
- // a bound.
- let ty_param_node_id = ty_path_def.local_node_id();
- match find_bound_for_assoc_item(this, ty_param_node_id, assoc_name, span) {
+ (&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) {
+ Ok(bound) => bound,
+ Err(ErrorReported) => return (tcx.types.err, ty_path_def),
+ }
+ }
+ (&ty::TyParam(_), def::DefTyParam(_, _, param_did, param_name)) => {
+ assert_eq!(param_did.krate, ast::LOCAL_CRATE);
+ match find_bound_for_assoc_item(this,
+ param_did.node,
+ Some(param_name),
+ assoc_name,
+ span) {
Ok(bound) => bound,
Err(ErrorReported) => return (tcx.types.err, ty_path_def),
}
--- /dev/null
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn avg<T=T::Item>(_: T) {} //~ ERROR associated type `Item` not found for `T`
+fn main() {}