Debian Codegraph @

gcc/testsuite/rust/compile/derive-hash1.rs

raw
1 #![feature(intrinsics)]
2
3 #[lang = "sized"]
4 trait Sized {}
5
6 pub mod core {
7 pub mod intrinsics {
8 #[lang = "discriminant_kind"]
9 pub trait DiscriminantKind {
10 #[lang = "discriminant_type"]
11 type Discriminant;
12 }
13
14 extern "rust-intrinsic" {
15 pub fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;
16 }
17 }
18
19 pub mod hash {
20 pub trait Hasher {}
21
22 pub trait Hash {
23 /// Feeds this value into the given [`Hasher`].
24 ///
25 /// # Examples
26 ///
27 /// ```
28 /// use std::collections::hash_map::DefaultHasher;
29 /// use std::hash::{Hash, Hasher};
30 ///
31 /// let mut hasher = DefaultHasher::new();
32 /// 7920.hash(&mut hasher);
33 /// println!("Hash is {:x}!", hasher.finish());
34 /// ```
35 #[stable(feature = "rust1", since = "1.0.0")]
36 fn hash<H: Hasher>(&self, state: &mut H);
37
38 /// Feeds a slice of this type into the given [`Hasher`].
39 ///
40 /// # Examples
41 ///
42 /// ```
43 /// use std::collections::hash_map::DefaultHasher;
44 /// use std::hash::{Hash, Hasher};
45 ///
46 /// let mut hasher = DefaultHasher::new();
47 /// let numbers = [6, 28, 496, 8128];
48 /// Hash::hash_slice(&numbers, &mut hasher);
49 /// println!("Hash is {:x}!", hasher.finish());
50 /// ```
51 #[stable(feature = "hash_slice", since = "1.3.0")]
52 fn hash_slice<H: Hasher>(data: &[Self], state: &mut H)
53 where
54 Self: Sized,
55 {
56 // for piece in data {
57 // piece.hash(state);
58 // }
59 }
60 }
61 }
62 }
63
64 impl core::hash::Hash for i32 {
65 fn hash<H: core::hash::Hasher>(&self, state: &mut H) {}
66 }
67
68 impl core::hash::Hash for i64 {
69 fn hash<H: core::hash::Hasher>(&self, state: &mut H) {}
70 }
71
72 // for the discriminant value
73 impl core::hash::Hash for isize {
74 fn hash<H: core::hash::Hasher>(&self, state: &mut H) {}
75 }
76
77 #[derive(Hash)]
78 struct Foo { // { dg-warning "never constructed" }
79 a: i32,
80 b: i32,
81 }
82
83 #[derive(Hash)]
84 struct Bar(i32, i64); // { dg-warning "never constructed" }
85
86 #[derive(Hash)]
87 enum Baz {
88 A,
89 B(i32),
90 C { a: i64 }
91 }