Skip to content

Commit 5d555bf

Browse files
authored
Rollup merge of #86477 - tlyu:e0716-clarification, r=JohnTitor
E0716: clarify that equivalent code example is erroneous In E0716, there is a code block that is equivalent to the erroneous code example. Especially when viewed with `rustc --explain`, it's not obvious that it is also erroneous, and some users have been confused when they try to change their code to match the erroneous equivalent. `@rustbot` label +A-diagnostics +D-newcomer-roadblock +T-compiler
2 parents 23c652d + 92197a5 commit 5d555bf

File tree

1 file changed

+4
-2
lines changed
  • compiler/rustc_error_codes/src/error_codes

1 file changed

+4
-2
lines changed

compiler/rustc_error_codes/src/error_codes/E0716.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ Here, the expression `&foo()` is borrowing the expression `foo()`. As `foo()` is
1414
a call to a function, and not the name of a variable, this creates a
1515
**temporary** -- that temporary stores the return value from `foo()` so that it
1616
can be borrowed. You could imagine that `let p = bar(&foo());` is equivalent to
17-
this:
17+
the following, which uses an explicit temporary variable.
18+
19+
Erroneous code example:
1820

1921
```compile_fail,E0597
2022
# fn foo() -> i32 { 22 }
2123
# fn bar(x: &i32) -> &i32 { x }
2224
let p = {
2325
let tmp = foo(); // the temporary
24-
bar(&tmp)
26+
bar(&tmp) // error: `tmp` does not live long enough
2527
}; // <-- tmp is freed as we exit this block
2628
let q = p;
2729
```

0 commit comments

Comments
 (0)