Reviewer comments

This commit is contained in:
Nick Cameron 2014-12-02 15:03:02 -08:00
parent ae8ba88424
commit ce4318ad86
13 changed files with 76 additions and 88 deletions

View File

@ -151,9 +151,6 @@ register_diagnostics!(
E0172,
E0173,
E0174,
E0175,
E0176,
E0177,
E0178,
E0179
E0178
)

View File

@ -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);
}
}

View File

@ -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,
@ -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));

View File

@ -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);
}
@ -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!()
}
}
}

View File

@ -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;
}
@ -385,10 +383,10 @@ 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()));
}
@ -396,12 +394,6 @@ fn create_substs_for_ast_path<'tcx,AC,RS>(
}
}
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());

View File

@ -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);
}
}
@ -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) => {
@ -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>)
{
{
@ -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);
}
{

View File

@ -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");
}

View File

@ -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();
@ -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()
@ -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")
}
}

View File

@ -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
)

View File

@ -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!();
}
}
}
}

View File

@ -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`
}

View File

@ -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
}

View File

@ -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
}