-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-lowLow priorityLow priorityT-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.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
#![feature(nll)]
#[derive(Clone)]
struct Foo<'a>(fn(&'a ()) -> &'a ());
impl Copy for Foo<'static> {}
fn mk_foo<'a>() -> Foo<'a> {
println!("mk_foo");
Foo(|x| x)
}
fn foo<'a>() -> [Foo<'a>; 100] {
[mk_foo::<'a>(); 100]
}
fn main() {
foo();
}
this compiles both with and without feature(nll)
. Note that mk_foo
creates a value of type Foo<'a>
which may not be copied.
Moving mk_foo::<'a>()
into a local errors as expected:
#![feature(nll)]
#[derive(Clone)]
struct Foo<'a>(fn(&'a ()) -> &'a ());
impl Copy for Foo<'static> {}
fn mk_foo<'a>() -> Foo<'a> {
println!("mk_foo");
Foo(|x| x)
}
fn foo<'a>() -> [Foo<'a>; 100] {
let x = mk_foo::<'a>();
[x; 100]
}
this results in
error: lifetime may not live long enough
--> src/main.rs:15:6
|
13 | fn foo<'a>() -> [Foo<'a>; 100] {
| -- lifetime `'a` defined here
14 | let x = mk_foo::<'a>();
15 | [x; 100]
| ^ copying this value requires that `'a` must outlive `'static`
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-lowLow priorityLow priorityT-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.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Type
Projects
Status
Completed