forked from LukeMathWalker/pavex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working with mutable references only makes sense if the type can't be…
… cloned (LukeMathWalker#226)
- Loading branch information
1 parent
3a67a93
commit a8bf063
Showing
4 changed files
with
139 additions
and
2 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...tests/borrow_checker/cannot_borrow_clonable_request_scoped_as_mut/expectations/stderr.txt
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,21 @@ | ||
[31m[1mERROR[0m[39m: | ||
[31m×[0m You can't inject `&mut app::A` as an input parameter to `app::handler`, | ||
[31m│[0m since `&mut app::A` has been marked `CloneIfNecessary`. | ||
[31m│[0m Reasoning about mutations becomes impossible if Pavex can't guarantee that | ||
[31m│[0m all mutations will affect *the same* instance of `app::A`. | ||
[31m│[0m | ||
[31m│[0m ╭─[[36;1;4msrc/lib.rs[0m:19:1] | ||
[31m│[0m [2m19[0m │ .cloning(CloningStrategy::CloneIfNecessary); | ||
[31m│[0m [2m20[0m │ bp.route(GET, "/", f!(self::handler)); | ||
[31m│[0m · [35;1m ────────┬────────[0m | ||
[31m│[0m · [35;1m╰── The request handler was registered here[0m | ||
[31m│[0m [2m21[0m │ bp | ||
[31m│[0m ╰──── | ||
[31m│[0m ╭─[[36;1;4msrc/lib.rs[0m:11:1] | ||
[31m│[0m [2m11[0m │ | ||
[31m│[0m [2m12[0m │ pub fn handler(_a: &mut A) -> Response { | ||
[31m│[0m · [35;1m ─────┬────[0m | ||
[31m│[0m · [35;1m╰── The &mut reference[0m | ||
[31m│[0m [2m13[0m │ todo!() | ||
[31m│[0m ╰──── | ||
[31m│[0m [36m help: [0mChange `app::A`'s cloning strategy to `NeverClone`. |
22 changes: 22 additions & 0 deletions
22
...vex_cli/tests/ui_tests/borrow_checker/cannot_borrow_clonable_request_scoped_as_mut/lib.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,22 @@ | ||
use pavex::blueprint::{constructor::CloningStrategy, router::GET, Blueprint}; | ||
use pavex::f; | ||
use pavex::response::Response; | ||
|
||
#[derive(Clone)] | ||
pub struct A; | ||
|
||
pub fn build() -> A { | ||
A | ||
} | ||
|
||
pub fn handler(_a: &mut A) -> Response { | ||
todo!() | ||
} | ||
|
||
pub fn blueprint() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.request_scoped(f!(self::build)) | ||
.cloning(CloningStrategy::CloneIfNecessary); | ||
bp.route(GET, "/", f!(self::handler)); | ||
bp | ||
} |
4 changes: 4 additions & 0 deletions
4
...sts/ui_tests/borrow_checker/cannot_borrow_clonable_request_scoped_as_mut/test_config.toml
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,4 @@ | ||
description = "You can't borrow a mutable reference to a clonable request-scoped component" | ||
|
||
[expectations] | ||
codegen = "fail" |
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