Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:

- run: cargo clippy -- -D warnings

- run: cd compatibility-tests/compile-fail && cargo test

secondary:
runs-on: ubuntu-latest
strategy:
Expand Down
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ documentation = "https://docs.rs/sxd-document"
license = "MIT"

[features]
compile_failure = []

__internal_expose_string_pool = []

[dependencies]
Expand Down
9 changes: 9 additions & 0 deletions compatibility-tests/compile-fail/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "compile-fail"
version = "0.1.0"
edition = "2021"

[dependencies]
sxd-document = { path = "../..", features = ["__internal_expose_string_pool"] }

trybuild = "1.0"
5 changes: 5 additions & 0 deletions compatibility-tests/compile-fail/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[test]
fn ui() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/*.rs");
}
10 changes: 10 additions & 0 deletions compatibility-tests/compile-fail/tests/ui/string_pool.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use sxd_document::__internal::StringPool;

fn string_cannot_outlive_the_pool() {
let _s = {
let pool = StringPool::new();
pool.intern("hello")
};
}

fn main() {}
11 changes: 11 additions & 0 deletions compatibility-tests/compile-fail/tests/ui/string_pool.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0597]: `pool` does not live long enough
--> tests/ui/string_pool.rs:6:9
|
4 | let _s = {
| -- borrow later stored here
5 | let pool = StringPool::new();
| ---- binding `pool` declared here
6 | pool.intern("hello")
| ^^^^ borrowed value does not live long enough
7 | };
| - `pool` dropped here while still borrowed
48 changes: 48 additions & 0 deletions compatibility-tests/compile-fail/tests/ui/thindom.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use sxd_document::Package;

fn cannot_mutate_connections_while_iterating_over_root_children() {
let package = Package::new();
let (s, mut c) = package.as_thin_document();

let alpha = s.create_element("alpha");

for _ in c.root_children() {
c.append_root_child(alpha);
}
}

fn cannot_mutate_connections_while_iterating_over_element_children() {
let package = Package::new();
let (s, mut c) = package.as_thin_document();

let alpha = s.create_element("alpha");
let beta = s.create_element("beta");

for _ in c.element_children(alpha) {
c.append_element_child(alpha, beta);
}
}

fn cannot_mutate_connections_while_iterating_over_siblings() {
let package = Package::new();
let (s, mut c) = package.as_thin_document();

let alpha = s.create_element("alpha");
let beta = s.create_element("beta");

for _ in c.element_preceding_siblings(alpha) {
c.append_element_child(alpha, beta);
}
}

fn nodes_cannot_live_outside_of_the_document() {
let package = Package::new();

let _node = {
let (s, _) = package.as_thin_document();

s.create_element("hello")
};
}

fn main() {}
45 changes: 45 additions & 0 deletions compatibility-tests/compile-fail/tests/ui/thindom.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
error[E0502]: cannot borrow `c` as mutable because it is also borrowed as immutable
--> tests/ui/thindom.rs:10:9
|
9 | for _ in c.root_children() {
| -----------------
| |
| immutable borrow occurs here
| immutable borrow later used here
10 | c.append_root_child(alpha);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here

error[E0502]: cannot borrow `c` as mutable because it is also borrowed as immutable
--> tests/ui/thindom.rs:22:9
|
21 | for _ in c.element_children(alpha) {
| -------------------------
| |
| immutable borrow occurs here
| immutable borrow later used here
22 | c.append_element_child(alpha, beta);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here

error[E0502]: cannot borrow `c` as mutable because it is also borrowed as immutable
--> tests/ui/thindom.rs:34:9
|
33 | for _ in c.element_preceding_siblings(alpha) {
| -----------------------------------
| |
| immutable borrow occurs here
| immutable borrow later used here
34 | c.append_element_child(alpha, beta);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here

error[E0597]: `s` does not live long enough
--> tests/ui/thindom.rs:44:9
|
41 | let _node = {
| ----- borrow later stored here
42 | let (s, _) = package.as_thin_document();
| - binding `s` declared here
43 |
44 | s.create_element("hello")
| ^ borrowed value does not live long enough
45 | };
| - `s` dropped here while still borrowed
12 changes: 0 additions & 12 deletions src/dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1616,16 +1616,4 @@ mod test {
let element = doc.root().children()[0].element().unwrap();
assert_qname_eq!(element.name(), "hello");
}

#[test]
#[cfg(feature = "compile_failure")]
fn nodes_cannot_live_outside_of_the_document() {
let package = Package::new();

let _ = {
let doc = package.as_document();

doc.create_element("hello")
};
}
}
9 changes: 0 additions & 9 deletions src/string_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,6 @@ mod test {
assert_eq!(interned1.as_bytes().as_ptr(), interned2.as_bytes().as_ptr());
}

#[test]
#[cfg(feature = "compile_failure")]
fn string_cannot_outlive_the_pool() {
let z = {
let s = StringPool::new();
s.intern("hello")
};
}

#[test]
fn ignores_the_lifetime_of_the_input_string() {
let s = StringPool::new();
Expand Down
57 changes: 0 additions & 57 deletions src/thindom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -985,61 +985,4 @@ mod test {
let element = children[0].element().unwrap();
assert_qname_eq!(element.name(), "hello");
}

#[test]
#[cfg(feature = "compile_failure")]
//cannot borrow `c` as mutable because it is also borrowed as immutable
fn cannot_mutate_connections_while_iterating_over_root_children() {
let package = Package::new();
let (s, mut c) = package.as_thin_document();

let alpha = s.create_element("alpha");

for _ in c.root_children() {
c.append_root_child(alpha);
}
}

#[test]
#[cfg(feature = "compile_failure")]
//cannot borrow `c` as mutable because it is also borrowed as immutable
fn cannot_mutate_connections_while_iterating_over_element_children() {
let package = Package::new();
let (s, mut c) = package.as_thin_document();

let alpha = s.create_element("alpha");
let beta = s.create_element("beta");

for _ in c.element_children(alpha) {
c.append_element_child(alpha, beta);
}
}

#[test]
#[cfg(feature = "compile_failure")]
//cannot borrow `c` as mutable because it is also borrowed as immutable
fn cannot_mutate_connections_while_iterating_over_siblings() {
let package = Package::new();
let (s, mut c) = package.as_thin_document();

let alpha = s.create_element("alpha");
let beta = s.create_element("beta");

for _ in c.element_preceding_siblings(alpha) {
c.append_element_child(alpha, beta);
}
}

#[test]
#[cfg(feature = "compile_failure")]
//`s` does not live long enough
fn nodes_cannot_live_outside_of_the_document() {
let package = Package::new();

let _ = {
let (s, _) = package.as_thin_document();

s.create_element("hello")
};
}
}