aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar René Kijewski <rene.kijewski@fu-berlin.de>2023-08-01 02:21:59 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-08-01 10:51:57 +0200
commitb3843d90a85d84e44ccd6cb188a5aa375df84104 (patch)
tree49589fcad4f22c9ea623e8c52e463af749079019
parent7c3a85de4fe8851bbff7c477237ed88954b9f9c5 (diff)
downloadaskama-b3843d90a85d84e44ccd6cb188a5aa375df84104.tar.gz
askama-b3843d90a85d84e44ccd6cb188a5aa375df84104.tar.bz2
askama-b3843d90a85d84e44ccd6cb188a5aa375df84104.zip
parser: ensure correct drop order for `Parsed`
According to [RFC 1857] the fields of a struct are dropped in the same order as they are declared. For `struct S { a: A, b: B }` field `a` is dropped before field `b`. Our struct `Parsed` is self referencial. Its field `ast` depends on `source`, so `source` must outlife `ast`. This PR changes the order of the fields to reflect this requirement. In practice it should not matter, because we know that the variant of `Node` won't access the string data during their `Drop`, but better safe than sorry - maybe `Node` changes in the future. [RFC 1857]: https://rust-lang.github.io/rfcs/1857-stabilize-drop-order.html
-rw-r--r--askama_parser/src/lib.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/askama_parser/src/lib.rs b/askama_parser/src/lib.rs
index cf105cb..bc29a22 100644
--- a/askama_parser/src/lib.rs
+++ b/askama_parser/src/lib.rs
@@ -28,9 +28,10 @@ mod _parsed {
use super::{Ast, Node, ParseError, Syntax};
pub struct Parsed {
+ // `source` must outlive `ast`, so `ast` must be declared before `source`
+ ast: Ast<'static>,
#[allow(dead_code)]
source: String,
- ast: Ast<'static>,
}
impl Parsed {
@@ -44,7 +45,7 @@ mod _parsed {
Err(e) => return Err(e),
};
- Ok(Self { source, ast })
+ Ok(Self { ast, source })
}
// The return value's lifetime must be limited to `self` to uphold the unsafe invariant.