Skip to content

Commit

Permalink
Reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Dec 12, 2014
1 parent ae8ba88 commit ce4318a
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 88 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
)
4 changes: 2 additions & 2 deletions src/librustc/middle/privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1454,12 +1454,12 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
}
for predicate in generics.where_clause.predicates.iter() {
match predicate {
&ast::BoundPredicate(ref bound_pred) => {
&ast::WherePredicate::BoundPredicate(ref bound_pred) => {
for bound in bound_pred.bounds.iter() {
self.check_ty_param_bound(bound_pred.span, bound)
}
}
&ast::EqPredicate(ref eq_pred) => {
&ast::WherePredicate::EqPredicate(ref eq_pred) => {
self.visit_ty(&*eq_pred.ty);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4595,7 +4595,7 @@ impl<'a> Resolver<'a> {
fn resolve_where_clause(&mut self, where_clause: &ast::WhereClause) {
for predicate in where_clause.predicates.iter() {
match predicate {
&ast::BoundPredicate(ref bound_pred) => {
&ast::WherePredicate::BoundPredicate(ref bound_pred) => {
match self.resolve_identifier(bound_pred.ident,
TypeNS,
true,
Expand All @@ -4617,7 +4617,7 @@ impl<'a> Resolver<'a> {
TraitBoundingTypeParameter);
}
}
&ast::EqPredicate(ref eq_pred) => {
&ast::WherePredicate::EqPredicate(ref eq_pred) => {
match self.resolve_path(eq_pred.id, &eq_pred.path, TypeNS, true) {
Some((def @ DefTyParam(..), last_private)) => {
self.record_def(eq_pred.id, (def, last_private));
Expand Down
14 changes: 10 additions & 4 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,17 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
}
for predicate in generics.where_clause.predicates.iter() {
match predicate {
&ast::BoundPredicate(ast::WhereBoundPredicate{ident, ref bounds, span, ..}) => {
&ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate{ ident,
ref bounds,
span,
.. }) => {
self.visit_ident(span, ident);
visit::walk_ty_param_bounds_helper(self, bounds);
}
&ast::EqPredicate(ast::WhereEqPredicate{id, ref path, ref ty, ..}) => {
&ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ id,
ref path,
ref ty,
.. }) => {
self.visit_path(path, id);
self.visit_ty(&**ty);
}
Expand Down Expand Up @@ -495,10 +501,10 @@ fn early_bound_lifetime_names(generics: &ast::Generics) -> Vec<ast::Name> {
}
for predicate in generics.where_clause.predicates.iter() {
match predicate {
&ast::BoundPredicate(ast::WhereBoundPredicate{ref bounds, ..}) => {
&ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate{ref bounds, ..}) => {
visit::walk_ty_param_bounds_helper(&mut collector, bounds);
}
_ => {}
&ast::WherePredicate::EqPredicate(_) => unimplemented!()
}
}
}
Expand Down
12 changes: 2 additions & 10 deletions src/librustc_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_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5152,18 +5152,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 @@ -5250,14 +5244,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 @@ -5273,8 +5265,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 @@ -5296,49 +5286,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, E0182,
"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_typeck/coherence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ fn enforce_trait_manually_implementable(tcx: &ty::ctxt, sp: Span, trait_def_id:
} else {
return // everything OK
};
span_err!(tcx.sess, sp, E0173, "manual implementations of `{}` are experimental", trait_name);
span_err!(tcx.sess, sp, E0183, "manual implementations of `{}` are experimental", trait_name);
span_help!(tcx.sess, sp,
"add `#![feature(unboxed_closures)]` to the crate attributes to enable");
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,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 Expand Up @@ -2042,7 +2042,7 @@ fn merge_param_bounds<'a>(tcx: &ty::ctxt,

for predicate in where_clause.predicates.iter() {
match predicate {
&ast::BoundPredicate(ref bound_pred) => {
&ast::WherePredicate::BoundPredicate(ref bound_pred) => {
let predicate_param_id =
tcx.def_map
.borrow()
Expand All @@ -2057,7 +2057,7 @@ fn merge_param_bounds<'a>(tcx: &ty::ctxt,
result.push(bound);
}
}
&ast::EqPredicate(_) => panic!("not implemented")
&ast::WherePredicate::EqPredicate(_) => panic!("not implemented")
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,11 @@ register_diagnostics!(
E0171,
E0172,
E0173, // manual implementations of unboxed closure traits are experimental
E0174 // explicit use of unboxed closure methods are experimental
E0174, // explicit use of unboxed closure methods are experimental
E0177,
E0178,
E0180,
E0181,
E0182,
E0183
)
13 changes: 10 additions & 3 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,16 @@ pub struct WherePredicate {

impl Clean<WherePredicate> for ast::WherePredicate {
fn clean(&self, cx: &DocContext) -> WherePredicate {
WherePredicate {
name: self.ident.clean(cx),
bounds: self.bounds.clean(cx)
match *self {
ast::WherePredicate::BoundPredicate(ref wbp) => {
WherePredicate {
name: wbp.ident.clean(cx),
bounds: wbp.bounds.clean(cx)
}
}
ast::WherePredicate::EqPredicate(_) => {
unimplemented!();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ extern crate macro_crate_test;

fn main() {
macro_crate_test::foo();
//~^ ERROR failed to resolve. Use of undeclared module `macro_crate_test`
//~^ ERROR failed to resolve. Use of undeclared type or module `macro_crate_test`
//~^^ ERROR unresolved name `macro_crate_test::foo`
}
28 changes: 28 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,28 @@
// 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)]

trait Foo {
type A;
fn bar() -> int;
}

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
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ trait Bar {

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

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

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

d: fn() -> Bar+'a,
//~^ ERROR E0171
//~^ ERROR E0178
//~^^ NOTE perhaps you forgot parentheses
//~^^^ WARN deprecated syntax
}
Expand Down

13 comments on commit ce4318a

@bors
Copy link
Contributor

@bors bors commented on ce4318a Dec 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at nrc@ce4318a

@bors
Copy link
Contributor

@bors bors commented on ce4318a Dec 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nick29581/rust/assoc-eq = ce4318a into auto

@bors
Copy link
Contributor

@bors bors commented on ce4318a Dec 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nick29581/rust/assoc-eq = ce4318a merged ok, testing candidate = ab6a1d54

@bors
Copy link
Contributor

@bors bors commented on ce4318a Dec 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on ce4318a Dec 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at nrc@ce4318a

@bors
Copy link
Contributor

@bors bors commented on ce4318a Dec 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nick29581/rust/assoc-eq = ce4318a into auto

@bors
Copy link
Contributor

@bors bors commented on ce4318a Dec 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nick29581/rust/assoc-eq = ce4318a merged ok, testing candidate = 9c8bcbd

@bors
Copy link
Contributor

@bors bors commented on ce4318a Dec 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at nrc@ce4318a

@bors
Copy link
Contributor

@bors bors commented on ce4318a Dec 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nick29581/rust/assoc-eq = ce4318a into auto

@bors
Copy link
Contributor

@bors bors commented on ce4318a Dec 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nick29581/rust/assoc-eq = ce4318a merged ok, testing candidate = 9146a91

@bors
Copy link
Contributor

@bors bors commented on ce4318a Dec 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 9146a91

Please sign in to comment.