Skip to content

Commit 59e9cfa

Browse files
author
Jorge Aparicio
committed
use UFCS in #[deriving(Hash)]
expansion now uses `::std::hash::Hash::hash(&*__self_0_0, __arg_0)` instead of `(*__self_0_0).hash(__arg_0)` closes #21160
1 parent 896cb36 commit 59e9cfa

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

src/libcollections/btree/set.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use core::cmp::Ordering::{self, Less, Greater, Equal};
1818
use core::default::Default;
1919
use core::fmt::Show;
2020
use core::fmt;
21+
// NOTE(stage0) remove import after a snapshot
22+
#[cfg(stage0)]
2123
use core::hash::Hash;
2224
use core::iter::{Peekable, Map, FromIterator};
2325
use core::ops::{BitOr, BitAnd, BitXor, Sub};

src/libstd/io/process.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use prelude::v1::*;
2121
use collections::HashMap;
2222
use ffi::CString;
2323
use fmt;
24+
// NOTE(stage0) remove import after a snapshot
25+
#[cfg(stage0)]
2426
use hash::Hash;
2527
use io::pipe::{PipeStream, PipePair};
2628
use io::{IoResult, IoError};

src/libsyntax/ext/deriving/hash.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,19 @@ fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
6565
[ref state_expr] => state_expr,
6666
_ => cx.span_bug(trait_span, "incorrect number of arguments in `deriving(Hash)`")
6767
};
68-
let hash_ident = substr.method_ident;
68+
let hash_path = {
69+
let strs = vec![
70+
cx.ident_of("std"),
71+
cx.ident_of("hash"),
72+
cx.ident_of("Hash"),
73+
cx.ident_of("hash"),
74+
];
75+
76+
cx.expr_path(cx.path_global(trait_span, strs))
77+
};
6978
let call_hash = |&: span, thing_expr| {
70-
let expr = cx.expr_method_call(span, thing_expr, hash_ident, vec!(state_expr.clone()));
79+
let ref_thing = cx.expr_addr_of(span, thing_expr);
80+
let expr = cx.expr_call(span, hash_path.clone(), vec!(ref_thing, state_expr.clone()));
7181
cx.stmt_expr(expr)
7282
};
7383
let mut stmts = Vec::new();

src/test/compile-fail/issue-21160.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 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 Bar;
12+
13+
impl Bar {
14+
fn hash<T>(&self, _: T) {}
15+
}
16+
17+
#[derive(Hash)]
18+
//~^ error: the trait `core::hash::Hash<__S>` is not implemented for the type `Bar`
19+
struct Foo(Bar);
20+
21+
fn main() {}

0 commit comments

Comments
 (0)