Skip to content

Commit 5fa5f53

Browse files
authored
Fix Rust compilation with only borrowed structs (#519)
Fixes a mistake from #514
1 parent 8644713 commit 5fa5f53

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

crates/gen-rust-lib/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,13 @@ pub trait RustGenerator<'a> {
382382
fn modes_of(&self, ty: TypeId) -> Vec<(String, TypeMode)> {
383383
let info = self.info(ty);
384384
let mut result = Vec::new();
385-
result.push((self.result_name(ty), TypeMode::Owned));
385+
let first_mode = if info.owned || !info.borrowed {
386+
TypeMode::Owned
387+
} else {
388+
assert!(!self.uses_two_names(&info));
389+
TypeMode::AllBorrowed("'a")
390+
};
391+
result.push((self.result_name(ty), first_mode));
386392
if self.uses_two_names(&info) {
387393
result.push((self.param_name(ty), TypeMode::AllBorrowed("'a")));
388394
}

tests/codegen/simple-http.wit

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
interface http-fetch-imports {
2+
record request{
3+
method: string,
4+
uri: string,
5+
body: string
6+
}
7+
8+
record response{
9+
status: u16,
10+
body: string
11+
}
12+
13+
fetch: func(req: request) -> result<response>
14+
}
15+
16+
default world http-fetch-simple {
17+
import http-fetch-simple: self.http-fetch-imports
18+
}

0 commit comments

Comments
 (0)