Skip to content

Commit 77135c2

Browse files
committed
Reviewer comments
1 parent 886235d commit 77135c2

File tree

6 files changed

+34
-70
lines changed

6 files changed

+34
-70
lines changed

src/librustc/diagnostics.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,6 @@ register_diagnostics!(
151151
E0172,
152152
E0173,
153153
E0174,
154-
E0175,
155-
E0176,
156154
E0177,
157-
E0178,
158-
E0179
155+
E0178
159156
)

src/librustc/middle/resolve_lifetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ fn early_bound_lifetime_names(generics: &ast::Generics) -> Vec<ast::Name> {
496496
&ast::BoundPredicate(ast::WhereBoundPredicate{ref bounds, ..}) => {
497497
visit::walk_ty_param_bounds_helper(&mut collector, bounds);
498498
}
499-
_ => {}
499+
&ast::EqPredicate(_) => unimplemented!()
500500
}
501501
}
502502
}

src/librustc/middle/typeck/astconv.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,11 @@ fn create_substs_for_ast_path<'tcx,AC,RS>(
367367
}
368368
}
369369

370-
let mut matched_assoc = 0u;
371370
for formal_assoc in decl_generics.types.get_slice(AssocSpace).iter() {
372371
let mut found = false;
373372
for &(ident, ty) in assoc_bindings.iter() {
374373
if formal_assoc.name.ident() == ident {
375374
substs.types.push(AssocSpace, ty);
376-
matched_assoc += 1;
377375
found = true;
378376
break;
379377
}
@@ -385,23 +383,17 @@ fn create_substs_for_ast_path<'tcx,AC,RS>(
385383
formal_assoc.def_id) {
386384
Some(ty) => {
387385
substs.types.push(AssocSpace, ty);
388-
matched_assoc += 1;
389386
}
390387
None => {
391-
span_err!(this.tcx().sess, span, E0179,
388+
substs.types.push(AssocSpace, ty::mk_err());
389+
span_err!(this.tcx().sess, span, E0171,
392390
"missing type for associated type `{}`",
393391
token::get_ident(formal_assoc.name.ident()));
394392
}
395393
}
396394
}
397395
}
398396

399-
if decl_generics.types.get_slice(AssocSpace).len() != matched_assoc {
400-
span_err!(tcx.sess, span, E0171,
401-
"wrong number of associated type parameters: expected {}, found {}",
402-
decl_generics.types.get_slice(AssocSpace).len(), matched_assoc);
403-
}
404-
405397
for &(ident, _) in assoc_bindings.iter() {
406398
let mut formal_idents = decl_generics.types.get_slice(AssocSpace)
407399
.iter().map(|t| t.name.ident());

src/librustc/middle/typeck/check/mod.rs

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5141,18 +5141,12 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
51415141
}
51425142

51435143
Some(space) => {
5144-
let trait_def_id = match def {
5145-
def::DefTrait(did) => Some(did),
5146-
_ => None
5147-
};
51485144
push_explicit_parameters_from_segment_to_substs(fcx,
51495145
space,
51505146
path.span,
51515147
type_defs,
51525148
region_defs,
51535149
segment,
5154-
trait_def_id,
5155-
path.span,
51565150
&mut substs);
51575151
}
51585152
}
@@ -5239,14 +5233,12 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
52395233
type_defs: &VecPerParamSpace<ty::TypeParameterDef<'tcx>>,
52405234
region_defs: &VecPerParamSpace<ty::RegionParameterDef>,
52415235
segment: &ast::PathSegment,
5242-
trait_def_id: Option<DefId>,
5243-
path_span: Span,
52445236
substs: &mut Substs<'tcx>)
52455237
{
52465238
match segment.parameters {
52475239
ast::AngleBracketedParameters(ref data) => {
52485240
push_explicit_angle_bracketed_parameters_from_segment_to_substs(
5249-
fcx, space, type_defs, region_defs, data, trait_def_id, path_span, substs);
5241+
fcx, space, type_defs, region_defs, data, substs);
52505242
}
52515243

52525244
ast::ParenthesizedParameters(ref data) => {
@@ -5262,8 +5254,6 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
52625254
type_defs: &VecPerParamSpace<ty::TypeParameterDef<'tcx>>,
52635255
region_defs: &VecPerParamSpace<ty::RegionParameterDef>,
52645256
data: &ast::AngleBracketedParameterData,
5265-
trait_def_id: Option<DefId>,
5266-
path_span: Span,
52675257
substs: &mut Substs<'tcx>)
52685258
{
52695259
{
@@ -5285,49 +5275,11 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
52855275
}
52865276
}
52875277

5288-
if let Some(trait_def_id) = trait_def_id {
5289-
let ref items = fcx.tcx().trait_item_def_ids.borrow()[trait_def_id];
5290-
let mut assoc_tys = Vec::new();
5291-
for item in items.iter() {
5292-
if let &ty::ImplOrTraitItemId::TypeTraitItemId(id) = item {
5293-
if let ty::ImplOrTraitItem::TypeTraitItem(ref ty) =
5294-
fcx.tcx().impl_or_trait_items.borrow()[id] {
5295-
assoc_tys.push(ty.clone());
5296-
}
5297-
}
5298-
}
5299-
5300-
if data.bindings.len() > assoc_tys.len() {
5301-
span_err!(fcx.tcx().sess, data.bindings[assoc_tys.len()].span, E0174,
5302-
"too many type equality constraints provided: \
5303-
expected at most {} constraint(s), \
5304-
found {} constraint(s)",
5305-
assoc_tys.len(), data.types.len());
5306-
substs.types.truncate(space, 0);
5307-
} else if data.bindings.len() > 0 {
5308-
for assoc_ty in assoc_tys.iter() {
5309-
let mut matched = false;
5310-
for binding in data.bindings.iter() {
5311-
if assoc_ty.name.ident() == binding.ident {
5312-
let t = fcx.to_ty(&*binding.ty);
5313-
substs.types.push(space, t);
5314-
matched = true;
5315-
break;
5316-
}
5317-
}
5318-
if !matched {
5319-
span_err!(fcx.tcx().sess, path_span, E0176,
5320-
"missing type equality constraint for associated type: {}",
5321-
assoc_ty.name);
5322-
substs.types.truncate(space, 0);
5323-
break;
5324-
}
5325-
}
5326-
}
5327-
} else if data.bindings.len() > 0 {
5328-
span_err!(fcx.tcx().sess, path_span, E0175,
5329-
"type equality constraints provided on a non-trait type");
5330-
substs.types.truncate(space, 0);
5278+
if data.bindings.len() > 0 {
5279+
span_err!(fcx.tcx().sess, data.bindings[0].span, E0174,
5280+
"unexpected binding of associated item in expression path \
5281+
(only allowed in type paths)");
5282+
substs.types.truncate(subst::ParamSpace::AssocSpace, 0);
53315283
}
53325284

53335285
{

src/librustc/middle/typeck/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,7 @@ fn ty_generics<'tcx,AC>(this: &AC,
18391839
let trait_def = ty::lookup_trait_def(this.tcx(), trait_def_id);
18401840
let associated_type_defs = trait_def.generics.types.get_slice(subst::AssocSpace);
18411841

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that an associated type cannot be bound in an expression path.
12+
13+
#![feature(associated_types)]
14+
15+
impl Foo for int {
16+
type A = uint;
17+
fn bar() -> int { 42 }
18+
}
19+
20+
pub fn main() {
21+
let x: int = Foo::<A=uint>::bar();
22+
//~^ERROR unexpected binding of associated item in expression path
23+
}

0 commit comments

Comments
 (0)