Skip to content

Commit 05c8888

Browse files
committed
Actually ensure that TokenKind's fields are safely copyable
.. by making it generic so that we can use an `impl Copy` to ensure it on the type level.
1 parent 65fa0ab commit 05c8888

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

compiler/rustc_ast/src/token.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,8 @@ impl From<IdentIsRaw> for bool {
337337
}
338338
}
339339

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

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

493+
// make sure that everything else in `TokenKind` is actually `Copy`-able, for
494+
// our unsafe use below.
495+
impl Clone for TokenKind<()> {
496+
fn clone(&self) -> Self {
497+
*self
498+
}
499+
}
500+
impl Copy for TokenKind<()> {}
501+
495502
impl Clone for TokenKind {
496503
fn clone(&self) -> Self {
497504
// `TokenKind` would impl `Copy` if it weren't for `Interpolated`. So

0 commit comments

Comments
 (0)