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.
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.
11 // ignore-tidy-linelength
13 macro_rules! enum_from_u32 {
14 ($(#[$attr:meta])* pub enum $name:ident {
15 $($variant:ident = $e:expr,)*
23 pub fn from_u32(u: u32) -> Option<$name> {
24 $(if u == $name::$variant as u32 {
25 return Some($name::$variant)
31 ($(#[$attr:meta])* pub enum $name:ident {
40 pub fn from_u32(u: u32) -> Option<$name> {
41 $(if u == $name::$variant as u32 {
42 return Some($name::$variant)
52 () => ( bug!("impossible case reached") );
53 ($($message:tt)*) => ({
54 $crate::session::bug_fmt(file!(), line!(), format_args!($($message)*))
59 macro_rules! span_bug {
60 ($span:expr, $($message:tt)*) => ({
61 $crate::session::span_bug_fmt(file!(), line!(), $span, format_args!($($message)*))
66 macro_rules! __impl_stable_hash_field {
67 (DECL IGNORED) => (_);
68 (DECL $name:ident) => (ref $name);
69 (USE IGNORED $ctx:expr, $hasher:expr) => ({});
70 (USE $name:ident, $ctx:expr, $hasher:expr) => ($name.hash_stable($ctx, $hasher));
74 macro_rules! impl_stable_hash_for {
75 (enum $enum_name:path { $( $variant:ident $( ( $($arg:ident),* ) )* ),* }) => {
76 impl<'a, 'tcx> ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a, 'tcx>> for $enum_name {
78 fn hash_stable<W: ::rustc_data_structures::stable_hasher::StableHasherResult>(&self,
79 __ctx: &mut $crate::ich::StableHashingContext<'a, 'tcx>,
80 __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher<W>) {
82 ::std::mem::discriminant(self).hash_stable(__ctx, __hasher);
86 $variant $( ( $( __impl_stable_hash_field!(DECL $arg) ),* ) )* => {
87 $($( __impl_stable_hash_field!(USE $arg, __ctx, __hasher) );*)*
94 (struct $struct_name:path { $($field:ident),* }) => {
95 impl<'a, 'tcx> ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a, 'tcx>> for $struct_name {
97 fn hash_stable<W: ::rustc_data_structures::stable_hasher::StableHasherResult>(&self,
98 __ctx: &mut $crate::ich::StableHashingContext<'a, 'tcx>,
99 __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher<W>) {
104 $( $field.hash_stable(__ctx, __hasher));*
108 (tuple_struct $struct_name:path { $($field:ident),* }) => {
109 impl<'a, 'tcx> ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a, 'tcx>> for $struct_name {
111 fn hash_stable<W: ::rustc_data_structures::stable_hasher::StableHasherResult>(&self,
112 __ctx: &mut $crate::ich::StableHashingContext<'a, 'tcx>,
113 __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher<W>) {
118 $( $field.hash_stable(__ctx, __hasher));*
125 macro_rules! impl_stable_hash_for_spanned {
128 impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ::syntax::codemap::Spanned<$T>
131 fn hash_stable<W: StableHasherResult>(&self,
132 hcx: &mut StableHashingContext<'a, 'tcx>,
133 hasher: &mut StableHasher<W>) {
134 self.node.hash_stable(hcx, hasher);
135 self.span.hash_stable(hcx, hasher);