Skip to content

Commit f53eca6

Browse files
committed
Revert "Don't use raw in comparisons."
This reverts commit 9ff9176. Per the discussion in #6, having the `Eq` and `Ord` instances ignore the `raw` field of `Ident` causes more trouble than it's worth, as it causes the parser to incorrectly deem raw identifiers like `r#return` to be keywords. While we could fix this issue by changing the parser, this would take quite a bit of code changes to accomplish. As such, we revert the change here, and we make a note in the Haddocks for the `Eq` and `Ord` instances to beware of the fact that `raw` is taken into account. After this change, the `rustc-tests` test suite passes once more. As such, this change fixes #6.
1 parent 82acd31 commit f53eca6

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/Language/Rust/Data/Ident.hs

+9-7
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ data Ident
3333
= Ident { hash :: {-# UNPACK #-} !Int -- ^ hash for quick comparision
3434
, name :: Name -- ^ payload of the identifier
3535
, raw :: Bool -- ^ whether the identifier is raw
36-
} deriving (Data, Typeable, Generic, NFData)
37-
38-
instance Eq Ident where
39-
x == y = (hash x, name x) == (hash y, name y)
40-
41-
instance Ord Ident where
42-
compare x y = compare (hash x, name x) (hash y, name y)
36+
}
37+
deriving ( Data, Typeable, Generic, NFData
38+
-- | Note that this instance takes the 'raw' field into account, so
39+
-- the identifiers @x@ and @r#x@ are judged /not/ to be equal.
40+
, Eq
41+
-- | Note that this instance takes the 'raw' field into account, so
42+
-- the identifiers @x@ and @r#x@ are judged /not/ to be equal.
43+
, Ord
44+
)
4345

4446
-- | Shows the identifier as a string (for use with @-XOverloadedStrings@)
4547
instance Show Ident where

0 commit comments

Comments
 (0)