Skip to content

Commit 5a12beb

Browse files
committed
Add PointerMutability
1 parent c11a4db commit 5a12beb

File tree

11 files changed

+206
-3
lines changed

11 files changed

+206
-3
lines changed

src/expr.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,17 @@ ast_enum! {
10991099
}
11001100
}
11011101

1102+
#[cfg(feature = "full")]
1103+
ast_enum! {
1104+
/// Mutability of a raw pointer (`*const T`, `*mut T`), in which non-mutable
1105+
/// isn't the implicit default.
1106+
#[cfg_attr(docsrs, doc(cfg(feature = "full")))]
1107+
pub enum PointerMutability {
1108+
Const(Token![const]),
1109+
Mut(Token![mut]),
1110+
}
1111+
}
1112+
11021113
#[cfg(feature = "parsing")]
11031114
pub(crate) mod parsing {
11041115
#[cfg(feature = "full")]
@@ -1112,7 +1123,7 @@ pub(crate) mod parsing {
11121123
Arm, ExprArray, ExprAssign, ExprAsync, ExprAwait, ExprBlock, ExprBreak, ExprClosure,
11131124
ExprConst, ExprContinue, ExprForLoop, ExprIf, ExprInfer, ExprLet, ExprLoop, ExprMatch,
11141125
ExprRange, ExprRepeat, ExprReturn, ExprTry, ExprTryBlock, ExprUnsafe, ExprWhile, ExprYield,
1115-
Label, RangeLimits,
1126+
Label, PointerMutability, RangeLimits,
11161127
};
11171128
use crate::expr::{
11181129
Expr, ExprBinary, ExprCall, ExprCast, ExprField, ExprGroup, ExprIndex, ExprLit, ExprMacro,
@@ -2969,6 +2980,21 @@ pub(crate) mod parsing {
29692980
}
29702981
}
29712982

2983+
#[cfg(feature = "full")]
2984+
#[cfg_attr(docsrs, doc(cfg(feature = "parsing")))]
2985+
impl Parse for PointerMutability {
2986+
fn parse(input: ParseStream) -> Result<Self> {
2987+
let lookahead = input.lookahead1();
2988+
if lookahead.peek(Token![const]) {
2989+
Ok(PointerMutability::Const(input.parse()?))
2990+
} else if lookahead.peek(Token![mut]) {
2991+
Ok(PointerMutability::Mut(input.parse()?))
2992+
} else {
2993+
Err(lookahead.error())
2994+
}
2995+
}
2996+
}
2997+
29722998
fn check_cast(input: ParseStream) -> Result<()> {
29732999
let kind = if input.peek(Token![.]) && !input.peek(Token![..]) {
29743000
if input.peek2(Token![await]) {
@@ -3004,7 +3030,7 @@ pub(crate) mod printing {
30043030
Arm, ExprArray, ExprAssign, ExprAsync, ExprAwait, ExprBlock, ExprBreak, ExprClosure,
30053031
ExprConst, ExprContinue, ExprForLoop, ExprIf, ExprInfer, ExprLet, ExprLoop, ExprMatch,
30063032
ExprRange, ExprRepeat, ExprReturn, ExprTry, ExprTryBlock, ExprUnsafe, ExprWhile, ExprYield,
3007-
Label, RangeLimits,
3033+
Label, PointerMutability, RangeLimits,
30083034
};
30093035
use crate::expr::{
30103036
Expr, ExprBinary, ExprCall, ExprCast, ExprField, ExprGroup, ExprIndex, ExprLit, ExprMacro,
@@ -3928,4 +3954,15 @@ pub(crate) mod printing {
39283954
}
39293955
}
39303956
}
3957+
3958+
#[cfg(feature = "full")]
3959+
#[cfg_attr(docsrs, doc(cfg(feature = "printing")))]
3960+
impl ToTokens for PointerMutability {
3961+
fn to_tokens(&self, tokens: &mut TokenStream) {
3962+
match self {
3963+
PointerMutability::Const(const_token) => const_token.to_tokens(tokens),
3964+
PointerMutability::Mut(mut_token) => mut_token.to_tokens(tokens),
3965+
}
3966+
}
3967+
}
39313968
}

src/gen/clone.rs

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gen/debug.rs

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gen/eq.rs

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gen/fold.rs

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gen/hash.rs

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gen/visit.rs

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/gen/visit_mut.rs

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ pub use crate::error::{Error, Result};
363363
mod expr;
364364
#[cfg(feature = "full")]
365365
#[cfg_attr(docsrs, doc(cfg(feature = "full")))]
366-
pub use crate::expr::{Arm, Label, RangeLimits};
366+
pub use crate::expr::{Arm, Label, PointerMutability, RangeLimits};
367367
#[cfg(any(feature = "full", feature = "derive"))]
368368
#[cfg_attr(docsrs, doc(cfg(any(feature = "full", feature = "derive"))))]
369369
pub use crate::expr::{

syn.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/debug/gen.rs

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)