Skip to content

Commit

Permalink
Fix Rust compilation with only borrowed structs (#519)
Browse files Browse the repository at this point in the history
Fixes a mistake from #514
  • Loading branch information
alexcrichton authored Feb 22, 2023
1 parent 8644713 commit 5fa5f53
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/gen-rust-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,13 @@ pub trait RustGenerator<'a> {
fn modes_of(&self, ty: TypeId) -> Vec<(String, TypeMode)> {
let info = self.info(ty);
let mut result = Vec::new();
result.push((self.result_name(ty), TypeMode::Owned));
let first_mode = if info.owned || !info.borrowed {
TypeMode::Owned
} else {
assert!(!self.uses_two_names(&info));
TypeMode::AllBorrowed("'a")
};
result.push((self.result_name(ty), first_mode));
if self.uses_two_names(&info) {
result.push((self.param_name(ty), TypeMode::AllBorrowed("'a")));
}
Expand Down
18 changes: 18 additions & 0 deletions tests/codegen/simple-http.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
interface http-fetch-imports {
record request{
method: string,
uri: string,
body: string
}

record response{
status: u16,
body: string
}

fetch: func(req: request) -> result<response>
}

default world http-fetch-simple {
import http-fetch-simple: self.http-fetch-imports
}

0 comments on commit 5fa5f53

Please sign in to comment.