-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #66642 - ecstatic-morse:promotion-in-const, r=eddyb
Create promoted MIR fragments for `const` and `static`s Resolves #65732. The previous strategy of removing `Drop` and `StorageDead` for promoted locals only worked for rvalue lifetime extension and only if no `loop`s were present. This PR applies the approach currently used for `fn` and `const fn`s to `const` and `statics`. This may have some performance impacts. r? @eddyb
- Loading branch information
Showing
5 changed files
with
48 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
src/test/ui/consts/rfc-2203-const-array-repeat-exprs/const-fns.rs
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
src/test/ui/consts/rfc-2203-const-array-repeat-exprs/fn-call-in-const.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// run-pass | ||
|
||
#![allow(unused)] | ||
#![feature(const_in_array_repeat_expressions)] | ||
|
||
// Some type that is not copyable. | ||
struct Bar; | ||
|
||
const fn type_no_copy() -> Option<Bar> { | ||
None | ||
} | ||
|
||
const fn type_copy() -> u32 { | ||
3 | ||
} | ||
|
||
const _: [u32; 2] = [type_copy(); 2]; | ||
|
||
// This is allowed because all promotion contexts use the explicit rules for promotability when | ||
// inside an explicit const context. | ||
const _: [Option<Bar>; 2] = [type_no_copy(); 2]; | ||
|
||
fn main() {} |
18 changes: 18 additions & 0 deletions
18
src/test/ui/consts/rfc-2203-const-array-repeat-exprs/fn-call-in-non-const.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#![feature(const_in_array_repeat_expressions)] | ||
|
||
// Some type that is not copyable. | ||
struct Bar; | ||
|
||
const fn no_copy() -> Option<Bar> { | ||
None | ||
} | ||
|
||
const fn copy() -> u32 { | ||
3 | ||
} | ||
|
||
fn main() { | ||
let _: [u32; 2] = [copy(); 2]; | ||
let _: [Option<Bar>; 2] = [no_copy(); 2]; | ||
//~^ ERROR the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied | ||
} |
6 changes: 3 additions & 3 deletions
6
...const-array-repeat-exprs/const-fns.stderr → ...-repeat-exprs/fn-call-in-non-const.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters