Skip to content

Commit

Permalink
Reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Dec 3, 2014
1 parent 886235d commit 77135c2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 70 deletions.
5 changes: 1 addition & 4 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ register_diagnostics!(
E0172,
E0173,
E0174,
E0175,
E0176,
E0177,
E0178,
E0179
E0178
)
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ fn early_bound_lifetime_names(generics: &ast::Generics) -> Vec<ast::Name> {
&ast::BoundPredicate(ast::WhereBoundPredicate{ref bounds, ..}) => {
visit::walk_ty_param_bounds_helper(&mut collector, bounds);
}
_ => {}
&ast::EqPredicate(_) => unimplemented!()
}
}
}
Expand Down
12 changes: 2 additions & 10 deletions src/librustc/middle/typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,11 @@ fn create_substs_for_ast_path<'tcx,AC,RS>(
}
}

let mut matched_assoc = 0u;
for formal_assoc in decl_generics.types.get_slice(AssocSpace).iter() {
let mut found = false;
for &(ident, ty) in assoc_bindings.iter() {
if formal_assoc.name.ident() == ident {
substs.types.push(AssocSpace, ty);
matched_assoc += 1;
found = true;
break;
}
Expand All @@ -385,23 +383,17 @@ fn create_substs_for_ast_path<'tcx,AC,RS>(
formal_assoc.def_id) {
Some(ty) => {
substs.types.push(AssocSpace, ty);
matched_assoc += 1;
}
None => {
span_err!(this.tcx().sess, span, E0179,
substs.types.push(AssocSpace, ty::mk_err());
span_err!(this.tcx().sess, span, E0171,
"missing type for associated type `{}`",
token::get_ident(formal_assoc.name.ident()));
}
}
}
}

if decl_generics.types.get_slice(AssocSpace).len() != matched_assoc {
span_err!(tcx.sess, span, E0171,
"wrong number of associated type parameters: expected {}, found {}",
decl_generics.types.get_slice(AssocSpace).len(), matched_assoc);
}

for &(ident, _) in assoc_bindings.iter() {
let mut formal_idents = decl_generics.types.get_slice(AssocSpace)
.iter().map(|t| t.name.ident());
Expand Down
60 changes: 6 additions & 54 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5141,18 +5141,12 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
}

Some(space) => {
let trait_def_id = match def {
def::DefTrait(did) => Some(did),
_ => None
};
push_explicit_parameters_from_segment_to_substs(fcx,
space,
path.span,
type_defs,
region_defs,
segment,
trait_def_id,
path.span,
&mut substs);
}
}
Expand Down Expand Up @@ -5239,14 +5233,12 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
type_defs: &VecPerParamSpace<ty::TypeParameterDef<'tcx>>,
region_defs: &VecPerParamSpace<ty::RegionParameterDef>,
segment: &ast::PathSegment,
trait_def_id: Option<DefId>,
path_span: Span,
substs: &mut Substs<'tcx>)
{
match segment.parameters {
ast::AngleBracketedParameters(ref data) => {
push_explicit_angle_bracketed_parameters_from_segment_to_substs(
fcx, space, type_defs, region_defs, data, trait_def_id, path_span, substs);
fcx, space, type_defs, region_defs, data, substs);
}

ast::ParenthesizedParameters(ref data) => {
Expand All @@ -5262,8 +5254,6 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
type_defs: &VecPerParamSpace<ty::TypeParameterDef<'tcx>>,
region_defs: &VecPerParamSpace<ty::RegionParameterDef>,
data: &ast::AngleBracketedParameterData,
trait_def_id: Option<DefId>,
path_span: Span,
substs: &mut Substs<'tcx>)
{
{
Expand All @@ -5285,49 +5275,11 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
}
}

if let Some(trait_def_id) = trait_def_id {
let ref items = fcx.tcx().trait_item_def_ids.borrow()[trait_def_id];
let mut assoc_tys = Vec::new();
for item in items.iter() {
if let &ty::ImplOrTraitItemId::TypeTraitItemId(id) = item {
if let ty::ImplOrTraitItem::TypeTraitItem(ref ty) =
fcx.tcx().impl_or_trait_items.borrow()[id] {
assoc_tys.push(ty.clone());
}
}
}

if data.bindings.len() > assoc_tys.len() {
span_err!(fcx.tcx().sess, data.bindings[assoc_tys.len()].span, E0174,
"too many type equality constraints provided: \
expected at most {} constraint(s), \
found {} constraint(s)",
assoc_tys.len(), data.types.len());
substs.types.truncate(space, 0);
} else if data.bindings.len() > 0 {
for assoc_ty in assoc_tys.iter() {
let mut matched = false;
for binding in data.bindings.iter() {
if assoc_ty.name.ident() == binding.ident {
let t = fcx.to_ty(&*binding.ty);
substs.types.push(space, t);
matched = true;
break;
}
}
if !matched {
span_err!(fcx.tcx().sess, path_span, E0176,
"missing type equality constraint for associated type: {}",
assoc_ty.name);
substs.types.truncate(space, 0);
break;
}
}
}
} else if data.bindings.len() > 0 {
span_err!(fcx.tcx().sess, path_span, E0175,
"type equality constraints provided on a non-trait type");
substs.types.truncate(space, 0);
if data.bindings.len() > 0 {
span_err!(fcx.tcx().sess, data.bindings[0].span, E0174,
"unexpected binding of associated item in expression path \
(only allowed in type paths)");
substs.types.truncate(subst::ParamSpace::AssocSpace, 0);
}

{
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,7 @@ fn ty_generics<'tcx,AC>(this: &AC,
let trait_def = ty::lookup_trait_def(this.tcx(), trait_def_id);
let associated_type_defs = trait_def.generics.types.get_slice(subst::AssocSpace);

// Find any assocaited type bindings in the bound.
// Find any associated type bindings in the bound.
let ref segments = ast_trait_ref.trait_ref.path.segments;
let bindings = segments[segments.len() -1].parameters.bindings();

Expand Down
23 changes: 23 additions & 0 deletions src/test/compile-fail/assoc-eq-expr-path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2014 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.

// Check that an associated type cannot be bound in an expression path.

#![feature(associated_types)]

impl Foo for int {
type A = uint;
fn bar() -> int { 42 }
}

pub fn main() {
let x: int = Foo::<A=uint>::bar();
//~^ERROR unexpected binding of associated item in expression path

This comment has been minimized.

Copy link
@nikomatsakis

nikomatsakis Dec 3, 2014

Contributor

maybe use ERROR E0174?

}

0 comments on commit 77135c2

Please sign in to comment.