Issue #1125: Words borrowed from a String parameter, called with a temporary text.clone(): rustc “temporary value dropped while borrowed”

Open and answer this issue on GitHub.

ready · opened 2026-11-01 · updated 2026-11-01 · 0 comments

The builder of the focus rotation (scripts/drive.nika --focus) found this on 2026-11-01. It worked around it in drive.nika by passing text instead of text.clone(). Once this is fixed, that call should go back to the plain form.

A function returns the words of its String parameter, made with split().collect(), so the result borrows from the parameter. The function is called with the temporary text.clone(). Check accepts this, but the lowered Rust fails with “temporary value dropped while borrowed”. Either the result has to own its words, or the argument has to live long enough.

Probe

fn words_of(text: String, key: String) -> Vec[String] {
	for line in text.split("\n") {
		let w = line.trim().split(" ").collect()
		if w.len() > 1 && w[0] == key {
			return w
		}
	}
	let n: Vec[String] = []
	return n
}

fn current(text: String) -> String {
	let w = words_of(text.clone(), "current")
	if w.len() > 1 {
		return w[1].clone()
	}
	return text
}

fn main() {
	println(current("block 3\ncurrent converter 0"))
}

Expected output: converter. Actual: rustc E0716 (temporary value dropped while borrowed).

To build

Back to Open Issues