]> git.lizzy.rs Git - rust.git/commitdiff
syntax: make deriving have slightly less cryptic error messages.
authorHuon Wilson <dbau.pp+github@gmail.com>
Mon, 27 Jan 2014 13:20:50 +0000 (00:20 +1100)
committerHuon Wilson <dbau.pp+github@gmail.com>
Tue, 28 Jan 2014 00:07:45 +0000 (11:07 +1100)
This unfortunately changes an error like

    error: mismatched types: expected `&&NotClone` but found `&NotClone`

into

    error: type `NotClone` does not implement any method in scope named `clone`

17 files changed:
src/etc/generate-deriving-span-tests.py
src/libextra/dlist.rs
src/librustc/middle/trans/_match.rs
src/libsyntax/ext/deriving/cmp/ord.rs
src/libsyntax/ext/deriving/generic.rs
src/test/compile-fail/deriving-no-inner-impl-error-message.rs [new file with mode: 0644]
src/test/compile-fail/deriving-span-TotalEq-enum-struct-variant.rs
src/test/compile-fail/deriving-span-TotalEq-enum.rs
src/test/compile-fail/deriving-span-TotalEq-struct.rs
src/test/compile-fail/deriving-span-TotalEq-tuple-struct.rs
src/test/compile-fail/deriving-span-TotalOrd-enum-struct-variant.rs
src/test/compile-fail/deriving-span-TotalOrd-enum.rs
src/test/compile-fail/deriving-span-TotalOrd-struct.rs
src/test/compile-fail/deriving-span-TotalOrd-tuple-struct.rs
src/test/run-pass/deriving-self-lifetime-totalord-totaleq.rs
src/test/run-pass/deriving-self-lifetime.rs
src/test/run-pass/regions-mock-tcx.rs

index e66b7113a451da32881560e201b506585ebb0197..f00168a52c6a8735bbae12a11e216457269356f5 100755 (executable)
@@ -118,7 +118,7 @@ traits = {
 for (trait, supers, errs) in [('Rand', [], 1),
                               ('Clone', [], 1), ('DeepClone', ['Clone'], 1),
                               ('Eq', [], 2), ('Ord', [], 8),
-                              ('TotalEq', [], 2), ('TotalOrd', ['TotalEq'], 2)]:
+                              ('TotalEq', [], 1), ('TotalOrd', ['TotalEq'], 1)]:
     traits[trait] = (ALL, supers, errs)
 
 for (trait, (types, super_traits, error_count)) in traits.items():
index 320797889422c982bce87d4d3882c0fcb78c54b7..4023a4d7e7fbe18853fa0c5226b364166dc83bb2 100644 (file)
@@ -47,13 +47,17 @@ struct Node<T> {
 }
 
 /// Double-ended DList iterator
-#[deriving(Clone)]
 pub struct Items<'a, T> {
     priv head: &'a Link<T>,
     priv tail: Rawlink<Node<T>>,
     priv nelem: uint,
 }
 
+// FIXME #11820: the &'a Option<> of the Link stops clone working.
+impl<'a, T> Clone for Items<'a, T> {
+    fn clone(&self) -> Items<'a, T> { *self }
+}
+
 /// Double-ended mutable DList iterator
 pub struct MutItems<'a, T> {
     priv list: &'a mut DList<T>,
index c8d2cf36938007b2ce106e6e3413fcdaae4c251f..88672a8bf77e5589c51779b33fe32d2cfcefb839 100644 (file)
@@ -399,13 +399,17 @@ struct BindingInfo {
 
 type BindingsMap = HashMap<Ident, BindingInfo>;
 
-#[deriving(Clone)]
 struct ArmData<'a,'b> {
     bodycx: &'b Block<'b>,
     arm: &'a ast::Arm,
     bindings_map: @BindingsMap
 }
 
+// FIXME #11820: method resolution is unreliable with &
+impl<'a,'b> Clone for ArmData<'a, 'b> {
+    fn clone(&self) -> ArmData<'a, 'b> { *self }
+}
+
 /**
  * Info about Match.
  * If all `pats` are matched then arm `data` will be executed.
@@ -2227,5 +2231,3 @@ fn bind_irrefutable_pat<'a>(
     }
     return bcx;
 }
-
-
index 8a2b11b798cda5241994232cd3fdba0bca34060f..5a02d8eead85c9b847a13998a39d3fd1a4955e07 100644 (file)
@@ -78,14 +78,10 @@ fn cs_op(less: bool, equal: bool, cx: &ExtCtxt, span: Span, substr: &Substructur
                 _ => cx.span_bug(span, "Not exactly 2 arguments in `deriving(Ord)`")
             };
 
-            let cmp = cx.expr_binary(span, op,
-                                     cx.expr_deref(span, self_f),
-                                     cx.expr_deref(span, other_f));
+            let cmp = cx.expr_binary(span, op, self_f, other_f);
 
             let not_cmp = cx.expr_unary(span, ast::UnNot,
-                                        cx.expr_binary(span, op,
-                                                       cx.expr_deref(span, other_f),
-                                                       cx.expr_deref(span, self_f)));
+                                        cx.expr_binary(span, op, other_f, self_f));
 
             let and = cx.expr_binary(span, ast::BiAnd, not_cmp, subexpr);
             cx.expr_binary(span, ast::BiOr, cmp, and)
index 1f778779fbd42a30f679681d41db6974ca3b71d7..96428dba1901eb75cf39d2c389fd24e1aaf36ffc 100644 (file)
@@ -1009,7 +1009,8 @@ fn create_struct_pattern(&self,
             };
             let path = cx.path_ident(sp, cx.ident_of(format!("{}_{}", prefix, i)));
             paths.push(path.clone());
-            ident_expr.push((sp, opt_id, cx.expr_path(path)));
+            let val = cx.expr(sp, ast::ExprParen(cx.expr_deref(sp, cx.expr_path(path))));
+            ident_expr.push((sp, opt_id, val));
         }
 
         let subpats = self.create_subpatterns(paths, mutbl);
@@ -1053,7 +1054,8 @@ fn create_enum_variant_pattern(&self,
                     let path = cx.path_ident(sp, cx.ident_of(format!("{}_{}", prefix, i)));
 
                     paths.push(path.clone());
-                    ident_expr.push((sp, None, cx.expr_path(path)));
+                    let val = cx.expr(sp, ast::ExprParen(cx.expr_deref(sp, cx.expr_path(path))));
+                    ident_expr.push((sp, None, val));
                 }
 
                 let subpats = self.create_subpatterns(paths, mutbl);
@@ -1128,7 +1130,7 @@ pub fn cs_same_method(f: |&ExtCtxt, Span, ~[@Expr]| -> @Expr,
                 cx.expr_method_call(field.span,
                                     field.self_,
                                     substructure.method_ident,
-                                    field.other.clone())
+                                    field.other.map(|e| cx.expr_addr_of(field.span, *e)))
             });
 
             f(cx, trait_span, called)
diff --git a/src/test/compile-fail/deriving-no-inner-impl-error-message.rs b/src/test/compile-fail/deriving-no-inner-impl-error-message.rs
new file mode 100644 (file)
index 0000000..604aa0d
--- /dev/null
@@ -0,0 +1,24 @@
+// 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.
+
+struct NoCloneOrEq;
+
+#[deriving(Eq)]
+struct E {
+    x: NoCloneOrEq //~ ERROR does not implement any method in scope named `eq`
+         //~^ ERROR does not implement any method in scope named `ne`
+}
+#[deriving(Clone)]
+struct C {
+    x: NoCloneOrEq //~ ERROR does not implement any method in scope named `clone`
+}
+
+
+fn main() {}
index 22c9351e13a554082ad52d8080931e6e2c7227d2..8e55609a515d83c6644258c8781f2d7c90432bc0 100644 (file)
@@ -20,7 +20,6 @@
 enum Enum {
    A {
      x: Error //~ ERROR
-//~^ ERROR
    }
 }
 
index 36028ebb82cfa9b3d3ebbf189f038292db7f6cc2..968f0420687c57bb16a7e999b17c6b44ba85b5dc 100644 (file)
@@ -20,7 +20,6 @@
 enum Enum {
    A(
      Error //~ ERROR
-//~^ ERROR
      )
 }
 
index f3e38b3df4e678c947dd052b2f5d98e77c5def73..8c53d1167f12ff21b36744349b8150d89e9eaa6d 100644 (file)
@@ -19,7 +19,6 @@
 #[deriving(TotalEq)]
 struct Struct {
     x: Error //~ ERROR
-//~^ ERROR
 }
 
 fn main() {}
index 7293da91471b55deac2669f1bfec12526cff58ad..16d49954dce7ab214184678fa44a208118d9b10b 100644 (file)
@@ -19,7 +19,6 @@
 #[deriving(TotalEq)]
 struct Struct(
     Error //~ ERROR
-//~^ ERROR
 );
 
 fn main() {}
index 27a6bea1b04b7f71241f8975d08fdaf6d1f8e672..fe598906c02880d098b4a95473bf492f71dfe889 100644 (file)
@@ -20,7 +20,6 @@
 enum Enum {
    A {
      x: Error //~ ERROR
-//~^ ERROR
    }
 }
 
index 84c691b0fadc2fcc713bf4730d9e10a8f37186a4..6bccd22c45f8e82710f3583a7306e584d358b3d1 100644 (file)
@@ -20,7 +20,6 @@
 enum Enum {
    A(
      Error //~ ERROR
-//~^ ERROR
      )
 }
 
index c3a83df67d4e6c0b47e6cbf061c881afdc2b5c97..4ff48824a7bace0137cef20dd1de1a62667299f0 100644 (file)
@@ -19,7 +19,6 @@
 #[deriving(TotalOrd,TotalEq)]
 struct Struct {
     x: Error //~ ERROR
-//~^ ERROR
 }
 
 fn main() {}
index 9d913727e6c1eb27b8242d45d26ce79154be1118..08e2c9bcd7d9a03aa780eb1e38b7f9c832d5ae80 100644 (file)
@@ -19,7 +19,6 @@
 #[deriving(TotalOrd,TotalEq)]
 struct Struct(
     Error //~ ERROR
-//~^ ERROR
 );
 
 fn main() {}
index fbeb0a05340aa7a9b524c5cbff3c1b9cc1360152..cf53664e32a14457bdd3911d875748eb8a2c00d8 100644 (file)
@@ -8,6 +8,9 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+
+// xfail-test FIXME #11820: & is unreliable in deriving
+
 use std::cmp::{Less,Equal,Greater};
 
 #[deriving(TotalEq,TotalOrd)]
index 3d7d58878f2189eec6bdc3a0b5774007956c7b81..38eee7430ac5a94676244596d3663934387ca6fa 100644 (file)
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// xfail-test FIXME #11820: & is unreliable in deriving
+
 #[deriving(Eq,Ord)]
 struct A<'a> {
     x: &'a int
index 50a71278c0656cf0b16ed78deba4a14ffbd8f32b..71b9e3ee7bafdb517530a6b87c671956e05fcacc 100644 (file)
 
 type Type<'tcx> = &'tcx TypeStructure<'tcx>;
 
-#[deriving(Eq)]
 enum TypeStructure<'tcx> {
     TypeInt,
     TypeFunction(Type<'tcx>, Type<'tcx>),
 }
+impl<'tcx> Eq for TypeStructure<'tcx> {
+    fn eq(&self, other: &TypeStructure<'tcx>) -> bool {
+        match (*self, *other) {
+            (TypeInt, TypeInt) => true,
+            (TypeFunction(s_a, s_b), TypeFunction(o_a, o_b)) => *s_a == *o_a && *s_b == *o_b,
+            _ => false
+        }
+    }
+}
 
 struct TypeContext<'tcx, 'ast> {
     ty_arena: &'tcx Arena,