From ce4318ad86f2ccd0710247020269ba0ba22c6d59 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Tue, 2 Dec 2014 15:03:02 -0800 Subject: [PATCH] Reviewer comments --- src/librustc/diagnostics.rs | 5 +- src/librustc/middle/privacy.rs | 4 +- src/librustc/middle/resolve.rs | 4 +- src/librustc/middle/resolve_lifetime.rs | 14 +++-- src/librustc_typeck/astconv.rs | 12 +--- src/librustc_typeck/check/mod.rs | 60 ++----------------- src/librustc_typeck/coherence/mod.rs | 2 +- src/librustc_typeck/collect.rs | 6 +- src/librustc_typeck/diagnostics.rs | 8 ++- src/librustdoc/clean/mod.rs | 13 +++- .../phase-syntax-doesnt-resolve.rs | 2 +- src/test/compile-fail/assoc-eq-expr-path.rs | 28 +++++++++ .../hrtb-precedence-of-plus-error-message.rs | 6 +- 13 files changed, 76 insertions(+), 88 deletions(-) create mode 100644 src/test/compile-fail/assoc-eq-expr-path.rs diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 641d1e1f299..0cdf6a68e44 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -151,9 +151,6 @@ register_diagnostics!( E0172, E0173, E0174, - E0175, - E0176, E0177, - E0178, - E0179 + E0178 ) diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 37b70535306..79bb19a1e53 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -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); } } diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 59bda245f92..2899f60f736 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -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)); diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index b822e658c0d..3ab94d3ca66 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -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 { } 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!() } } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index b65dbff2f61..c84446a2e45 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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()); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 80ea8d90268..7e29e7078d4 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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>, region_defs: &VecPerParamSpace, segment: &ast::PathSegment, - trait_def_id: Option, - 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>, region_defs: &VecPerParamSpace, data: &ast::AngleBracketedParameterData, - trait_def_id: Option, - 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); } { diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index c4e1f6fe8eb..defad95f749 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -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"); } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 0830bd476a2..2e1ba846584 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -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") } } diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index e026fbd05c7..ecd3cafd91f 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -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 ) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index df7b922bd1a..630d41fa7e2 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -693,9 +693,16 @@ pub struct WherePredicate { impl Clean 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!(); + } } } } diff --git a/src/test/compile-fail-fulldeps/phase-syntax-doesnt-resolve.rs b/src/test/compile-fail-fulldeps/phase-syntax-doesnt-resolve.rs index 3972d01850e..00aeb1c1bae 100644 --- a/src/test/compile-fail-fulldeps/phase-syntax-doesnt-resolve.rs +++ b/src/test/compile-fail-fulldeps/phase-syntax-doesnt-resolve.rs @@ -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` } diff --git a/src/test/compile-fail/assoc-eq-expr-path.rs b/src/test/compile-fail/assoc-eq-expr-path.rs new file mode 100644 index 00000000000..1a96b0ca681 --- /dev/null +++ b/src/test/compile-fail/assoc-eq-expr-path.rs @@ -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 or the MIT license +// , 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::::bar(); + //~^ERROR unexpected binding of associated item in expression path +} diff --git a/src/test/compile-fail/hrtb-precedence-of-plus-error-message.rs b/src/test/compile-fail/hrtb-precedence-of-plus-error-message.rs index ff3512ad8e7..41a0be37add 100644 --- a/src/test/compile-fail/hrtb-precedence-of-plus-error-message.rs +++ b/src/test/compile-fail/hrtb-precedence-of-plus-error-message.rs @@ -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, // OK, no paren needed in this context d: fn() -> Bar+'a, - //~^ ERROR E0171 + //~^ ERROR E0178 //~^^ NOTE perhaps you forgot parentheses //~^^^ WARN deprecated syntax }