Skip to content

Commit f5b939a

Browse files
committed
syntax: Change #[derive(Eq)] imply #[derive(PartialEq)]
1 parent 214113a commit f5b939a

File tree

7 files changed

+27
-6
lines changed

7 files changed

+27
-6
lines changed

src/libcollections/string.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ impl<'a, 'b> Pattern<'a> for &'b String {
793793
}
794794
}
795795

796+
#[cfg(stage0)]
796797
#[stable(feature = "rust1", since = "1.0.0")]
797798
impl PartialEq for String {
798799
#[inline]

src/librustc/middle/ty.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1708,7 +1708,7 @@ pub enum UnconstrainedNumeric {
17081708
}
17091709

17101710

1711-
#[derive(Clone, RustcEncodable, RustcDecodable, Eq, Hash, Debug, Copy)]
1711+
#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
17121712
pub enum InferRegion {
17131713
ReVar(RegionVid),
17141714
ReSkolemized(u32, BoundRegion)
@@ -1731,6 +1731,8 @@ impl cmp::PartialEq for InferRegion {
17311731
}
17321732
}
17331733

1734+
impl cmp::Eq for InferRegion {}
1735+
17341736
impl fmt::Debug for TyVid {
17351737
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result{
17361738
write!(f, "_#{}t", self.index)

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl<'tcx> Loan<'tcx> {
278278
}
279279
}
280280

281-
#[derive(Eq, Hash, Debug)]
281+
#[derive(Hash, Debug)]
282282
pub struct LoanPath<'tcx> {
283283
kind: LoanPathKind<'tcx>,
284284
ty: ty::Ty<'tcx>,
@@ -293,6 +293,9 @@ impl<'tcx> PartialEq for LoanPath<'tcx> {
293293
}
294294
}
295295

296+
impl<'tcx> Eq for LoanPath<'tcx> {}
297+
298+
296299
#[derive(PartialEq, Eq, Hash, Debug)]
297300
pub enum LoanPathKind<'tcx> {
298301
LpVar(ast::NodeId), // `x` in README.md

src/libstd/path.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ enum State {
449449
///
450450
/// Does not occur on Unix.
451451
#[stable(feature = "rust1", since = "1.0.0")]
452-
#[derive(Copy, Clone, Eq, Hash, Debug)]
452+
#[derive(Copy, Clone, Hash, Debug)]
453453
pub struct PrefixComponent<'a> {
454454
/// The prefix as an unparsed `OsStr` slice.
455455
raw: &'a OsStr,
@@ -472,6 +472,9 @@ impl<'a> PrefixComponent<'a> {
472472
}
473473
}
474474

475+
#[stable(feature = "rust1", since = "1.0.0")]
476+
impl<'a> cmp::Eq for PrefixComponent<'a> {}
477+
475478
#[stable(feature = "rust1", since = "1.0.0")]
476479
impl<'a> cmp::PartialEq for PrefixComponent<'a> {
477480
fn eq(&self, other: &PrefixComponent<'a>) -> bool {

src/libsyntax/ast.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ use serialize::{Encodable, Decodable, Encoder, Decoder};
7878
/// table) and a SyntaxContext to track renaming and
7979
/// macro expansion per Flatt et al., "Macros
8080
/// That Work Together"
81-
#[derive(Clone, Copy, Hash, PartialOrd, Eq, Ord)]
81+
#[derive(Clone, Copy, Hash, PartialOrd, Ord)]
8282
pub struct Ident {
8383
pub name: Name,
8484
pub ctxt: SyntaxContext
@@ -149,6 +149,8 @@ impl PartialEq for Ident {
149149
}
150150
}
151151

152+
impl Eq for Ident {}
153+
152154
/// A SyntaxContext represents a chain of macro-expandings
153155
/// and renamings. Each macro expansion corresponds to
154156
/// a fresh u32
@@ -502,7 +504,7 @@ pub struct Crate {
502504

503505
pub type MetaItem = Spanned<MetaItem_>;
504506

505-
#[derive(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
507+
#[derive(Clone, RustcEncodable, RustcDecodable, Hash, Debug)]
506508
pub enum MetaItem_ {
507509
MetaWord(InternedString),
508510
MetaList(InternedString, Vec<P<MetaItem>>),
@@ -534,6 +536,8 @@ impl PartialEq for MetaItem_ {
534536
}
535537
}
536538

539+
impl Eq for MetaItem_ {}
540+
537541
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
538542
pub struct Block {
539543
/// Statements in a block

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use ext::deriving::generic::ty::*;
1717
use parse::token::InternedString;
1818
use ptr::P;
1919

20+
use super::partial_eq;
21+
2022
pub fn expand_deriving_eq(cx: &mut ExtCtxt,
2123
span: Span,
2224
mitem: &MetaItem,
@@ -66,5 +68,8 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
6668
),
6769
associated_types: Vec::new(),
6870
};
69-
trait_def.expand(cx, mitem, item, push)
71+
72+
trait_def.expand(cx, mitem, item, push);
73+
74+
partial_eq::expand_deriving_partial_eq(cx, span, mitem, item, push)
7075
}

src/libsyntax/ext/deriving/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,14 @@ fn expand_derive(cx: &mut ExtCtxt,
9494

9595
// FIXME: This can be removed after a snapshot
9696
let mut seen_copy = false;
97+
let mut seen_eq = false;
9798

9899
for titem in traits.iter() {
99100
match titem.node {
100101
MetaWord(ref tname) => {
101102
match &**tname {
102103
"Copy" => { seen_copy = true; }
104+
"Eq" => { seen_eq = true; }
103105
_ => { }
104106
}
105107
}
@@ -126,6 +128,7 @@ fn expand_derive(cx: &mut ExtCtxt,
126128

127129
// FIXME: This can be removed after a snapshot
128130
if seen_copy && &**tname == "Clone" { continue; }
131+
if seen_eq && &**tname == "PartialEq" { continue; }
129132

130133
// #[derive(Foo, Bar)] expands to #[derive_Foo] #[derive_Bar]
131134
item.attrs.push(cx.attribute(titem.span, cx.meta_word(titem.span,

0 commit comments

Comments
 (0)