Skip to content

Commit d21b183

Browse files
committed
auto merge of #11826 : huonw/rust/7621-deriving-errors, r=alexcrichton
cc #7621. See the commit message. I'm not sure if we should merge this now, or wait until we can write `Clone::clone(x)` which will directly solve the above issue with perfect error messages.
2 parents 8c6c229 + cb02a37 commit d21b183

17 files changed

+56
-23
lines changed

src/etc/generate-deriving-span-tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def write_file(name, string):
118118
for (trait, supers, errs) in [('Rand', [], 1),
119119
('Clone', [], 1), ('DeepClone', ['Clone'], 1),
120120
('Eq', [], 2), ('Ord', [], 8),
121-
('TotalEq', [], 2), ('TotalOrd', ['TotalEq'], 2)]:
121+
('TotalEq', [], 1), ('TotalOrd', ['TotalEq'], 1)]:
122122
traits[trait] = (ALL, supers, errs)
123123

124124
for (trait, (types, super_traits, error_count)) in traits.items():

src/libextra/dlist.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ struct Node<T> {
4747
}
4848

4949
/// Double-ended DList iterator
50-
#[deriving(Clone)]
5150
pub struct Items<'a, T> {
5251
priv head: &'a Link<T>,
5352
priv tail: Rawlink<Node<T>>,
5453
priv nelem: uint,
5554
}
5655

56+
// FIXME #11820: the &'a Option<> of the Link stops clone working.
57+
impl<'a, T> Clone for Items<'a, T> {
58+
fn clone(&self) -> Items<'a, T> { *self }
59+
}
60+
5761
/// Double-ended mutable DList iterator
5862
pub struct MutItems<'a, T> {
5963
priv list: &'a mut DList<T>,

src/librustc/middle/trans/_match.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,17 @@ struct BindingInfo {
399399

400400
type BindingsMap = HashMap<Ident, BindingInfo>;
401401

402-
#[deriving(Clone)]
403402
struct ArmData<'a,'b> {
404403
bodycx: &'b Block<'b>,
405404
arm: &'a ast::Arm,
406405
bindings_map: @BindingsMap
407406
}
408407

408+
// FIXME #11820: method resolution is unreliable with &
409+
impl<'a,'b> Clone for ArmData<'a, 'b> {
410+
fn clone(&self) -> ArmData<'a, 'b> { *self }
411+
}
412+
409413
/**
410414
* Info about Match.
411415
* If all `pats` are matched then arm `data` will be executed.
@@ -2227,5 +2231,3 @@ fn bind_irrefutable_pat<'a>(
22272231
}
22282232
return bcx;
22292233
}
2230-
2231-

src/libsyntax/ext/deriving/cmp/ord.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,10 @@ fn cs_op(less: bool, equal: bool, cx: &ExtCtxt, span: Span, substr: &Substructur
7878
_ => cx.span_bug(span, "Not exactly 2 arguments in `deriving(Ord)`")
7979
};
8080

81-
let cmp = cx.expr_binary(span, op,
82-
cx.expr_deref(span, self_f),
83-
cx.expr_deref(span, other_f));
81+
let cmp = cx.expr_binary(span, op, self_f, other_f);
8482

8583
let not_cmp = cx.expr_unary(span, ast::UnNot,
86-
cx.expr_binary(span, op,
87-
cx.expr_deref(span, other_f),
88-
cx.expr_deref(span, self_f)));
84+
cx.expr_binary(span, op, other_f, self_f));
8985

9086
let and = cx.expr_binary(span, ast::BiAnd, not_cmp, subexpr);
9187
cx.expr_binary(span, ast::BiOr, cmp, and)

src/libsyntax/ext/deriving/generic.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,8 @@ impl<'a> TraitDef<'a> {
10131013
};
10141014
let path = cx.path_ident(sp, cx.ident_of(format!("{}_{}", prefix, i)));
10151015
paths.push(path.clone());
1016-
ident_expr.push((sp, opt_id, cx.expr_path(path)));
1016+
let val = cx.expr(sp, ast::ExprParen(cx.expr_deref(sp, cx.expr_path(path))));
1017+
ident_expr.push((sp, opt_id, val));
10171018
}
10181019

10191020
let subpats = self.create_subpatterns(paths, mutbl);
@@ -1057,7 +1058,8 @@ impl<'a> TraitDef<'a> {
10571058
let path = cx.path_ident(sp, cx.ident_of(format!("{}_{}", prefix, i)));
10581059

10591060
paths.push(path.clone());
1060-
ident_expr.push((sp, None, cx.expr_path(path)));
1061+
let val = cx.expr(sp, ast::ExprParen(cx.expr_deref(sp, cx.expr_path(path))));
1062+
ident_expr.push((sp, None, val));
10611063
}
10621064

10631065
let subpats = self.create_subpatterns(paths, mutbl);
@@ -1132,7 +1134,7 @@ pub fn cs_same_method(f: |&ExtCtxt, Span, ~[@Expr]| -> @Expr,
11321134
cx.expr_method_call(field.span,
11331135
field.self_,
11341136
substructure.method_ident,
1135-
field.other.clone())
1137+
field.other.map(|e| cx.expr_addr_of(field.span, *e)))
11361138
});
11371139

11381140
f(cx, trait_span, called)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct NoCloneOrEq;
12+
13+
#[deriving(Eq)]
14+
struct E {
15+
x: NoCloneOrEq //~ ERROR does not implement any method in scope named `eq`
16+
//~^ ERROR does not implement any method in scope named `ne`
17+
}
18+
#[deriving(Clone)]
19+
struct C {
20+
x: NoCloneOrEq //~ ERROR does not implement any method in scope named `clone`
21+
}
22+
23+
24+
fn main() {}

src/test/compile-fail/deriving-span-TotalEq-enum-struct-variant.rs

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ struct Error;
2020
enum Enum {
2121
A {
2222
x: Error //~ ERROR
23-
//~^ ERROR
2423
}
2524
}
2625

src/test/compile-fail/deriving-span-TotalEq-enum.rs

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ struct Error;
2020
enum Enum {
2121
A(
2222
Error //~ ERROR
23-
//~^ ERROR
2423
)
2524
}
2625

src/test/compile-fail/deriving-span-TotalEq-struct.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ struct Error;
1919
#[deriving(TotalEq)]
2020
struct Struct {
2121
x: Error //~ ERROR
22-
//~^ ERROR
2322
}
2423

2524
fn main() {}

src/test/compile-fail/deriving-span-TotalEq-tuple-struct.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ struct Error;
1919
#[deriving(TotalEq)]
2020
struct Struct(
2121
Error //~ ERROR
22-
//~^ ERROR
2322
);
2423

2524
fn main() {}

src/test/compile-fail/deriving-span-TotalOrd-enum-struct-variant.rs

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ struct Error;
2020
enum Enum {
2121
A {
2222
x: Error //~ ERROR
23-
//~^ ERROR
2423
}
2524
}
2625

src/test/compile-fail/deriving-span-TotalOrd-enum.rs

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ struct Error;
2020
enum Enum {
2121
A(
2222
Error //~ ERROR
23-
//~^ ERROR
2423
)
2524
}
2625

src/test/compile-fail/deriving-span-TotalOrd-struct.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ struct Error;
1919
#[deriving(TotalOrd,TotalEq)]
2020
struct Struct {
2121
x: Error //~ ERROR
22-
//~^ ERROR
2322
}
2423

2524
fn main() {}

src/test/compile-fail/deriving-span-TotalOrd-tuple-struct.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ struct Error;
1919
#[deriving(TotalOrd,TotalEq)]
2020
struct Struct(
2121
Error //~ ERROR
22-
//~^ ERROR
2322
);
2423

2524
fn main() {}

src/test/run-pass/deriving-self-lifetime-totalord-totaleq.rs

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
12+
// xfail-test FIXME #11820: & is unreliable in deriving
13+
1114
use std::cmp::{Less,Equal,Greater};
1215

1316
#[deriving(TotalEq,TotalOrd)]

src/test/run-pass/deriving-self-lifetime.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// xfail-test FIXME #11820: & is unreliable in deriving
12+
1113
#[deriving(Eq,Ord)]
1214
struct A<'a> {
1315
x: &'a int

src/test/run-pass/regions-mock-tcx.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ use std::mem;
2727

2828
type Type<'tcx> = &'tcx TypeStructure<'tcx>;
2929

30-
#[deriving(Eq)]
3130
enum TypeStructure<'tcx> {
3231
TypeInt,
3332
TypeFunction(Type<'tcx>, Type<'tcx>),
3433
}
34+
impl<'tcx> Eq for TypeStructure<'tcx> {
35+
fn eq(&self, other: &TypeStructure<'tcx>) -> bool {
36+
match (*self, *other) {
37+
(TypeInt, TypeInt) => true,
38+
(TypeFunction(s_a, s_b), TypeFunction(o_a, o_b)) => *s_a == *o_a && *s_b == *o_b,
39+
_ => false
40+
}
41+
}
42+
}
3543

3644
struct TypeContext<'tcx, 'ast> {
3745
ty_arena: &'tcx Arena,

0 commit comments

Comments
 (0)