Skip to content

Commit 52dec0e

Browse files
committed
Don't derive traits on packed structs
1 parent 47e0bb5 commit 52dec0e

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/libsyntax_pos/span_encoding.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,37 @@ use hygiene::SyntaxContext;
1919

2020
use rustc_data_structures::fx::FxHashMap;
2121
use std::cell::RefCell;
22+
use std::hash::{Hash, Hasher};
2223

2324
/// A compressed span.
2425
/// Contains either fields of `SpanData` inline if they are small, or index into span interner.
2526
/// The primary goal of `Span` is to be as small as possible and fit into other structures
2627
/// (that's why it uses `packed` as well). Decoding speed is the second priority.
2728
/// See `SpanData` for the info on span fields in decoded representation.
28-
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
2929
#[repr(packed)]
3030
pub struct Span(u32);
3131

32+
impl Copy for Span {}
33+
impl Clone for Span {
34+
fn clone(&self) -> Span {
35+
*self
36+
}
37+
}
38+
impl PartialEq for Span {
39+
fn eq(&self, other: &Span) -> bool {
40+
let a = self.0;
41+
let b = other.0;
42+
a == b
43+
}
44+
}
45+
impl Eq for Span {}
46+
impl Hash for Span {
47+
fn hash<H: Hasher>(&self, state: &mut H) {
48+
let a = self.0;
49+
a.hash(state)
50+
}
51+
}
52+
3253
/// Dummy span, both position and length are zero, syntax context is zero as well.
3354
/// This span is kept inline and encoded with format 0.
3455
pub const DUMMY_SP: Span = Span(0);

0 commit comments

Comments
 (0)