]> git.lizzy.rs Git - rust.git/commitdiff
Reviewer comments
authorNick Cameron <ncameron@mozilla.com>
Tue, 2 Dec 2014 23:03:02 +0000 (15:03 -0800)
committerNick Cameron <ncameron@mozilla.com>
Fri, 12 Dec 2014 06:29:17 +0000 (19:29 +1300)
13 files changed:
src/librustc/diagnostics.rs
src/librustc/middle/privacy.rs
src/librustc/middle/resolve.rs
src/librustc/middle/resolve_lifetime.rs
src/librustc_typeck/astconv.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/coherence/mod.rs
src/librustc_typeck/collect.rs
src/librustc_typeck/diagnostics.rs
src/librustdoc/clean/mod.rs
src/test/compile-fail-fulldeps/phase-syntax-doesnt-resolve.rs
src/test/compile-fail/assoc-eq-expr-path.rs [new file with mode: 0644]
src/test/compile-fail/hrtb-precedence-of-plus-error-message.rs

index 641d1e1f2992b6eb07fade0e4d3710156df2ca12..0cdf6a68e44be343a2943c99c7496add4127ef54 100644 (file)
     E0172,
     E0173,
     E0174,
-    E0175,
-    E0176,
     E0177,
-    E0178,
-    E0179
+    E0178
 )
index 37b7053530604dd246d27fb8b8cfae9d4dce9f84..79bb19a1e535f245dc47527d47769979ff7a4967 100644 (file)
@@ -1454,12 +1454,12 @@ fn visit_generics(&mut self, generics: &ast::Generics) {
         }
         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);
                 }
             }
index 59bda245f923305ae45cddc0c973be974ce6a50d..2899f60f736af299579a2ba24b7efaaed1c88535 100644 (file)
@@ -4595,7 +4595,7 @@ fn resolve_trait_reference(&mut self,
     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 @@ fn resolve_where_clause(&mut self, where_clause: &ast::WhereClause) {
                                                           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));
index b822e658c0dffa7f6873f35ad54de6677cade862..3ab94d3ca66197952ca35b0129761e9fb7bfcc70 100644 (file)
@@ -211,11 +211,17 @@ fn visit_generics(&mut self, generics: &ast::Generics) {
         }
         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!()
             }
         }
     }
index b65dbff2f6106c7d323fa5c93bb1bb833853e3fd..c84446a2e4566989ffa9c7aa80848eef2e8fe12a 100644 (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());
index 80ea8d9026856c2075309ce76009924d8042dcae..7e29e7078d4889fb1aed849c2cd8e0145c4cb0e3 100644 (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 @@ fn push_explicit_parameters_from_segment_to_substs<'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 @@ fn push_explicit_angle_bracketed_parameters_from_segment_to_substs<'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 @@ fn push_explicit_angle_bracketed_parameters_from_segment_to_substs<'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);
         }
 
         {
index c4e1f6fe8eb180cfc5a7be8db2383d0da13778ce..defad95f749bd01761ff07687b491fe6d68123f3 100644 (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");
 }
index 0830bd476a2e552907c8be882520e174f0642465..2e1ba846584d2d053e4c098269dcb1e57cad48bf 100644 (file)
@@ -1840,7 +1840,7 @@ fn create_type_parameters_for_associated_types<'tcx, 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")
         }
     }
 
index e026fbd05c7f039c5ca6e4fc9c83d4f7a07744de..ecd3cafd91f1617b24fa1b8d962ac1e9ac85b562 100644 (file)
     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
 )
index df7b922bd1abc31a4884633a13d4e6c433affb4a..630d41fa7e209b7a31ec39288f94091526bfc6b1 100644 (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!();
+            }
         }
     }
 }
index 3972d01850e6373ea5d5a7afb2cd01a69620657d..00aeb1c1bae8f71a2163f888637fb1af7c44d8a8 100644 (file)
@@ -19,6 +19,6 @@
 
 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 (file)
index 0000000..1a96b0c
--- /dev/null
@@ -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
+}
index ff3512ad8e72a6e763d9cac9cd2065f19b5c834d..41a0be37add418a09afb8807c5bb6e9dc3c69c03 100644 (file)
@@ -18,17 +18,17 @@ fn dummy(&self) { }
 
 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
 }