Skip to content

don't use type_parameter_def during astconv #26824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2015
Merged
Show file tree
Hide file tree
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
42 changes: 30 additions & 12 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,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>,
assoc_name: ast::Name,
span: Span)
-> Result<ty::PolyTraitRef<'tcx>, ErrorReported>
Expand All @@ -1138,12 +1139,21 @@ fn find_bound_for_assoc_item<'tcx>(this: &AstConv<'tcx>,
.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)

}
}


Expand Down Expand Up @@ -1240,12 +1250,20 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
_ => 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),
}
Expand Down
12 changes: 12 additions & 0 deletions src/test/compile-fail/issue-26812.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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() {}