Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,8 @@ impl From<IdentIsRaw> for bool {
}
}

// SAFETY: due to the `Clone` impl below, all fields of all variants other than
// `Interpolated` must impl `Copy`.
#[derive(PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
pub enum TokenKind {
pub enum TokenKind<Nt = Arc<Nonterminal>> {
/* Expression-operator symbols. */
/// `=`
Eq,
Expand Down Expand Up @@ -481,7 +479,7 @@ pub enum TokenKind {
/// The span in the surrounding `Token` is that of the metavariable in the
/// macro's RHS. The span within the Nonterminal is that of the fragment
/// passed to the macro at the call site.
Interpolated(Arc<Nonterminal>),
Interpolated(Nt),

/// A doc comment token.
/// `Symbol` is the doc comment's data excluding its "quotes" (`///`, `/**`, etc)
Expand All @@ -492,6 +490,15 @@ pub enum TokenKind {
Eof,
}

// make sure that everything else in `TokenKind` is actually `Copy`-able, for
// our unsafe use below.
impl Clone for TokenKind<()> {
fn clone(&self) -> Self {
*self
}
}
impl Copy for TokenKind<()> {}

impl Clone for TokenKind {
fn clone(&self) -> Self {
// `TokenKind` would impl `Copy` if it weren't for `Interpolated`. So
Expand Down
Loading