Don't derive traits on packed structs

This commit is contained in:
Oliver Schneider 2018-03-07 12:56:48 +01:00
parent 47e0bb59db
commit 52dec0e1c9
No known key found for this signature in database
GPG Key ID: A69F8D225B3AD7D9

View File

@ -19,16 +19,37 @@ use hygiene::SyntaxContext;
use rustc_data_structures::fx::FxHashMap;
use std::cell::RefCell;
use std::hash::{Hash, Hasher};
/// A compressed span.
/// Contains either fields of `SpanData` inline if they are small, or index into span interner.
/// The primary goal of `Span` is to be as small as possible and fit into other structures
/// (that's why it uses `packed` as well). Decoding speed is the second priority.
/// See `SpanData` for the info on span fields in decoded representation.
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
#[repr(packed)]
pub struct Span(u32);
impl Copy for Span {}
impl Clone for Span {
fn clone(&self) -> Span {
*self
}
}
impl PartialEq for Span {
fn eq(&self, other: &Span) -> bool {
let a = self.0;
let b = other.0;
a == b
}
}
impl Eq for Span {}
impl Hash for Span {
fn hash<H: Hasher>(&self, state: &mut H) {
let a = self.0;
a.hash(state)
}
}
/// Dummy span, both position and length are zero, syntax context is zero as well.
/// This span is kept inline and encoded with format 0.
pub const DUMMY_SP: Span = Span(0);