Skip to content

Make deriving errors slightly less cryptic #11826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/etc/generate-deriving-span-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def write_file(name, string):
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():
Expand Down
6 changes: 5 additions & 1 deletion src/libextra/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
8 changes: 5 additions & 3 deletions src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -2227,5 +2231,3 @@ fn bind_irrefutable_pat<'a>(
}
return bcx;
}


8 changes: 2 additions & 6 deletions src/libsyntax/ext/deriving/cmp/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions src/libsyntax/ext/deriving/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,8 @@ impl<'a> TraitDef<'a> {
};
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);
Expand Down Expand Up @@ -1053,7 +1054,8 @@ impl<'a> TraitDef<'a> {
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);
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions src/test/compile-fail/deriving-no-inner-impl-error-message.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ struct Error;
enum Enum {
A {
x: Error //~ ERROR
//~^ ERROR
}
}

Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/deriving-span-TotalEq-enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ struct Error;
enum Enum {
A(
Error //~ ERROR
//~^ ERROR
)
}

Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/deriving-span-TotalEq-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct Error;
#[deriving(TotalEq)]
struct Struct {
x: Error //~ ERROR
//~^ ERROR
}

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct Error;
#[deriving(TotalEq)]
struct Struct(
Error //~ ERROR
//~^ ERROR
);

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ struct Error;
enum Enum {
A {
x: Error //~ ERROR
//~^ ERROR
}
}

Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/deriving-span-TotalOrd-enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ struct Error;
enum Enum {
A(
Error //~ ERROR
//~^ ERROR
)
}

Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/deriving-span-TotalOrd-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct Error;
#[deriving(TotalOrd,TotalEq)]
struct Struct {
x: Error //~ ERROR
//~^ ERROR
}

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct Error;
#[deriving(TotalOrd,TotalEq)]
struct Struct(
Error //~ ERROR
//~^ ERROR
);

fn main() {}
3 changes: 3 additions & 0 deletions src/test/run-pass/deriving-self-lifetime-totalord-totaleq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/deriving-self-lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/test/run-pass/regions-mock-tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@ use std::mem;

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,
Expand Down