Skip to content

Commit 84a845a

Browse files
authored
Rollup merge of rust-lang#64136 - crgl:doc-from-parser-lhs, r=Centril
Document From trait for LhsExpr in parser Add doc for From trait for converting P<Expr> and Option<ThinVec<Attribute>> to LhsExpr As part of issue rust-lang#51430 (cc @skade). Both of these should just be moving an address and setting a discriminant in an enum. The main thing I'm not sure about is whether it's worth documenting the branch in the From<Option<ThinVec<Attribute>>. As far as I can tell it doesn't seem like it is optimized away (although if the discriminant happened to work out you could just copy the pointer and the discriminant which might be cheaper, but that's not guaranteed). So it seems like if it's being called often, it's doubling the number of possible branch mispredictions on this Option, which could be a significant cost. Let me know if there's anything that needs fixing and I'll get to it as soon as possible!
2 parents 97e58c0 + 194d357 commit 84a845a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/libsyntax/parse/parser/expr.rs

+7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ pub(super) enum LhsExpr {
6666
}
6767

6868
impl From<Option<ThinVec<Attribute>>> for LhsExpr {
69+
/// Converts `Some(attrs)` into `LhsExpr::AttributesParsed(attrs)`
70+
/// and `None` into `LhsExpr::NotYetParsed`.
71+
///
72+
/// This conversion does not allocate.
6973
fn from(o: Option<ThinVec<Attribute>>) -> Self {
7074
if let Some(attrs) = o {
7175
LhsExpr::AttributesParsed(attrs)
@@ -76,6 +80,9 @@ impl From<Option<ThinVec<Attribute>>> for LhsExpr {
7680
}
7781

7882
impl From<P<Expr>> for LhsExpr {
83+
/// Converts the `expr: P<Expr>` into `LhsExpr::AlreadyParsed(expr)`.
84+
///
85+
/// This conversion does not allocate.
7986
fn from(expr: P<Expr>) -> Self {
8087
LhsExpr::AlreadyParsed(expr)
8188
}

0 commit comments

Comments
 (0)