Skip to content

Commit ce4318a

Browse files
committed
Reviewer comments
1 parent ae8ba88 commit ce4318a

File tree

13 files changed

+76
-88
lines changed

13 files changed

+76
-88
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/privacy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,12 +1454,12 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
14541454
}
14551455
for predicate in generics.where_clause.predicates.iter() {
14561456
match predicate {
1457-
&ast::BoundPredicate(ref bound_pred) => {
1457+
&ast::WherePredicate::BoundPredicate(ref bound_pred) => {
14581458
for bound in bound_pred.bounds.iter() {
14591459
self.check_ty_param_bound(bound_pred.span, bound)
14601460
}
14611461
}
1462-
&ast::EqPredicate(ref eq_pred) => {
1462+
&ast::WherePredicate::EqPredicate(ref eq_pred) => {
14631463
self.visit_ty(&*eq_pred.ty);
14641464
}
14651465
}

src/librustc/middle/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4595,7 +4595,7 @@ impl<'a> Resolver<'a> {
45954595
fn resolve_where_clause(&mut self, where_clause: &ast::WhereClause) {
45964596
for predicate in where_clause.predicates.iter() {
45974597
match predicate {
4598-
&ast::BoundPredicate(ref bound_pred) => {
4598+
&ast::WherePredicate::BoundPredicate(ref bound_pred) => {
45994599
match self.resolve_identifier(bound_pred.ident,
46004600
TypeNS,
46014601
true,
@@ -4617,7 +4617,7 @@ impl<'a> Resolver<'a> {
46174617
TraitBoundingTypeParameter);
46184618
}
46194619
}
4620-
&ast::EqPredicate(ref eq_pred) => {
4620+
&ast::WherePredicate::EqPredicate(ref eq_pred) => {
46214621
match self.resolve_path(eq_pred.id, &eq_pred.path, TypeNS, true) {
46224622
Some((def @ DefTyParam(..), last_private)) => {
46234623
self.record_def(eq_pred.id, (def, last_private));

src/librustc/middle/resolve_lifetime.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,17 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
211211
}
212212
for predicate in generics.where_clause.predicates.iter() {
213213
match predicate {
214-
&ast::BoundPredicate(ast::WhereBoundPredicate{ident, ref bounds, span, ..}) => {
214+
&ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate{ ident,
215+
ref bounds,
216+
span,
217+
.. }) => {
215218
self.visit_ident(span, ident);
216219
visit::walk_ty_param_bounds_helper(self, bounds);
217220
}
218-
&ast::EqPredicate(ast::WhereEqPredicate{id, ref path, ref ty, ..}) => {
221+
&ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ id,
222+
ref path,
223+
ref ty,
224+
.. }) => {
219225
self.visit_path(path, id);
220226
self.visit_ty(&**ty);
221227
}
@@ -495,10 +501,10 @@ fn early_bound_lifetime_names(generics: &ast::Generics) -> Vec<ast::Name> {
495501
}
496502
for predicate in generics.where_clause.predicates.iter() {
497503
match predicate {
498-
&ast::BoundPredicate(ast::WhereBoundPredicate{ref bounds, ..}) => {
504+
&ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate{ref bounds, ..}) => {
499505
visit::walk_ty_param_bounds_helper(&mut collector, bounds);
500506
}
501-
_ => {}
507+
&ast::WherePredicate::EqPredicate(_) => unimplemented!()
502508
}
503509
}
504510
}

src/librustc_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_typeck/check/mod.rs

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

51545154
Some(space) => {
5155-
let trait_def_id = match def {
5156-
def::DefTrait(did) => Some(did),
5157-
_ => None
5158-
};
51595155
push_explicit_parameters_from_segment_to_substs(fcx,
51605156
space,
51615157
path.span,
51625158
type_defs,
51635159
region_defs,
51645160
segment,
5165-
trait_def_id,
5166-
path.span,
51675161
&mut substs);
51685162
}
51695163
}
@@ -5250,14 +5244,12 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
52505244
type_defs: &VecPerParamSpace<ty::TypeParameterDef<'tcx>>,
52515245
region_defs: &VecPerParamSpace<ty::RegionParameterDef>,
52525246
segment: &ast::PathSegment,
5253-
trait_def_id: Option<DefId>,
5254-
path_span: Span,
52555247
substs: &mut Substs<'tcx>)
52565248
{
52575249
match segment.parameters {
52585250
ast::AngleBracketedParameters(ref data) => {
52595251
push_explicit_angle_bracketed_parameters_from_segment_to_substs(
5260-
fcx, space, type_defs, region_defs, data, trait_def_id, path_span, substs);
5252+
fcx, space, type_defs, region_defs, data, substs);
52615253
}
52625254

52635255
ast::ParenthesizedParameters(ref data) => {
@@ -5273,8 +5265,6 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
52735265
type_defs: &VecPerParamSpace<ty::TypeParameterDef<'tcx>>,
52745266
region_defs: &VecPerParamSpace<ty::RegionParameterDef>,
52755267
data: &ast::AngleBracketedParameterData,
5276-
trait_def_id: Option<DefId>,
5277-
path_span: Span,
52785268
substs: &mut Substs<'tcx>)
52795269
{
52805270
{
@@ -5296,49 +5286,11 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
52965286
}
52975287
}
52985288

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

53445296
{

src/librustc_typeck/coherence/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ fn enforce_trait_manually_implementable(tcx: &ty::ctxt, sp: Span, trait_def_id:
562562
} else {
563563
return // everything OK
564564
};
565-
span_err!(tcx.sess, sp, E0173, "manual implementations of `{}` are experimental", trait_name);
565+
span_err!(tcx.sess, sp, E0183, "manual implementations of `{}` are experimental", trait_name);
566566
span_help!(tcx.sess, sp,
567567
"add `#![feature(unboxed_closures)]` to the crate attributes to enable");
568568
}

src/librustc_typeck/collect.rs

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

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

@@ -2042,7 +2042,7 @@ fn merge_param_bounds<'a>(tcx: &ty::ctxt,
20422042

20432043
for predicate in where_clause.predicates.iter() {
20442044
match predicate {
2045-
&ast::BoundPredicate(ref bound_pred) => {
2045+
&ast::WherePredicate::BoundPredicate(ref bound_pred) => {
20462046
let predicate_param_id =
20472047
tcx.def_map
20482048
.borrow()
@@ -2057,7 +2057,7 @@ fn merge_param_bounds<'a>(tcx: &ty::ctxt,
20572057
result.push(bound);
20582058
}
20592059
}
2060-
&ast::EqPredicate(_) => panic!("not implemented")
2060+
&ast::WherePredicate::EqPredicate(_) => panic!("not implemented")
20612061
}
20622062
}
20632063

src/librustc_typeck/diagnostics.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,11 @@ register_diagnostics!(
149149
E0171,
150150
E0172,
151151
E0173, // manual implementations of unboxed closure traits are experimental
152-
E0174 // explicit use of unboxed closure methods are experimental
152+
E0174, // explicit use of unboxed closure methods are experimental
153+
E0177,
154+
E0178,
155+
E0180,
156+
E0181,
157+
E0182,
158+
E0183
153159
)

src/librustdoc/clean/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,16 @@ pub struct WherePredicate {
693693

694694
impl Clean<WherePredicate> for ast::WherePredicate {
695695
fn clean(&self, cx: &DocContext) -> WherePredicate {
696-
WherePredicate {
697-
name: self.ident.clean(cx),
698-
bounds: self.bounds.clean(cx)
696+
match *self {
697+
ast::WherePredicate::BoundPredicate(ref wbp) => {
698+
WherePredicate {
699+
name: wbp.ident.clean(cx),
700+
bounds: wbp.bounds.clean(cx)
701+
}
702+
}
703+
ast::WherePredicate::EqPredicate(_) => {
704+
unimplemented!();
705+
}
699706
}
700707
}
701708
}

src/test/compile-fail-fulldeps/phase-syntax-doesnt-resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ extern crate macro_crate_test;
1919

2020
fn main() {
2121
macro_crate_test::foo();
22-
//~^ ERROR failed to resolve. Use of undeclared module `macro_crate_test`
22+
//~^ ERROR failed to resolve. Use of undeclared type or module `macro_crate_test`
2323
//~^^ ERROR unresolved name `macro_crate_test::foo`
2424
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
trait Foo {
16+
type A;
17+
fn bar() -> int;
18+
}
19+
20+
impl Foo for int {
21+
type A = uint;
22+
fn bar() -> int { 42 }
23+
}
24+
25+
pub fn main() {
26+
let x: int = Foo::<A=uint>::bar();
27+
//~^ERROR unexpected binding of associated item in expression path
28+
}

src/test/compile-fail/hrtb-precedence-of-plus-error-message.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ trait Bar {
1818

1919
struct Foo<'a> {
2020
a: &'a Bar+'a,
21-
//~^ ERROR E0171
21+
//~^ ERROR E0178
2222
//~^^ NOTE perhaps you meant `&'a (Bar + 'a)`?
2323

2424
b: &'a mut Bar+'a,
25-
//~^ ERROR E0171
25+
//~^ ERROR E0178
2626
//~^^ NOTE perhaps you meant `&'a mut (Bar + 'a)`?
2727

2828
c: Box<Bar+'a>, // OK, no paren needed in this context
2929

3030
d: fn() -> Bar+'a,
31-
//~^ ERROR E0171
31+
//~^ ERROR E0178
3232
//~^^ NOTE perhaps you forgot parentheses
3333
//~^^^ WARN deprecated syntax
3434
}

0 commit comments

Comments
 (0)