-
-
Notifications
You must be signed in to change notification settings - Fork 913
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1345 from Demonthos/fix-borrowed-props
Constrain Props lifetime to parent, not child scope lifetime
- Loading branch information
Showing
4 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
packages/core/compile_tests/props_safety_temporary_values.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use dioxus::prelude::*; | ||
|
||
fn main() {} | ||
|
||
fn app(cx: Scope) -> Element { | ||
let count = vec![1, 2, 3]; | ||
|
||
render! { | ||
unsafe_child_component { | ||
borrowed: &count | ||
} | ||
} | ||
} | ||
|
||
#[derive(Props)] | ||
struct Testing<'a> { | ||
borrowed: &'a Vec<u32>, | ||
} | ||
|
||
fn unsafe_child_component<'a>(cx: Scope<'a, Testing<'a>>) -> Element<'a> { | ||
cx.render(rsx! { | ||
div { "{cx.props.borrowed:?}" } | ||
}) | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/core/compile_tests/props_safety_temporary_values.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0515]: cannot return value referencing local variable `count` | ||
--> compile_tests/props_safety_temporary_values.rs:8:5 | ||
| | ||
8 | / render! { | ||
9 | | unsafe_child_component { | ||
10 | | borrowed: &count | ||
| | ------ `count` is borrowed here | ||
11 | | } | ||
12 | | } | ||
| |_____^ returns a value referencing data owned by the current function | ||
| | ||
= note: this error originates in the macro `render` (in Nightly builds, run with -Z macro-backtrace for more info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters