Closed
Description
I tried this code:
fn erase<T>(_: T) -> impl core::fmt::Debug + 'static {}
fn create(v: ()) -> Box<dyn core::fmt::Debug> {
Box::new(erase(&v))
}
I expected it to compile, but there was an error:
error[E0515]: cannot return value referencing function parameter `v`
--> src/lib.rs:3:5
|
3 | Box::new(erase(&v))
| ^^^^^^^^^^^^^^^--^^
| | |
| | `v` is borrowed here
| returns a value referencing data owned by the current function
Meta
rustc --version --verbose
:
rustc 1.48.0 (7eac88abb 2020-11-16)
binary: rustc
commit-hash: 7eac88abb2e57e752f3302f02be5f3ce3d7adfb4
commit-date: 2020-11-16
host: x86_64-pc-windows-msvc
release: 1.48.0
LLVM version: 11.0
rustc 1.50.0-nightly (a0d664bae 2020-11-22)
binary: rustc
commit-hash: a0d664bae6ca79c54cc054aa2403198e105190a2
commit-date: 2020-11-22
host: x86_64-pc-windows-msvc
release: 1.50.0-nightly
The issue also affects -Zpolonius
Metadata
Metadata
Assignees
Labels
Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: Lifetimes / regionsCategory: This is a bug.Diagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint; hard to understand for new users.Relevant to the compiler team, which will review and decide on the PR/issue.Fixed by the feature `type_alias_impl_trait`.