-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Closed
Labels
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.fixed-by-TAITFixed by the feature `type_alias_impl_trait`.Fixed by the feature `type_alias_impl_trait`.
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
mpfaff and ISibboI
Metadata
Metadata
Assignees
Labels
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.fixed-by-TAITFixed by the feature `type_alias_impl_trait`.Fixed by the feature `type_alias_impl_trait`.