-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #89359 - fee1-dead:const-it, r=oli-obk
Various fixes for const_trait_impl A few problems I found while making `Iterator` easier to const-implement. 1. More generous `~const Drop` check. We check for nested fields with caller bounds. For example, an ADT type with fields of types `A`, `B`, `C`, check if all of them are either: - Bounded (`A: ~const Drop`, `B: Copy`) - Known to be able to destruct at compile time (`C = i32`, `struct C(i32)`, `C = some_fn`) 2. Don't treat trait functions marked with `#[default_method_body_is_const]` as stable const fns when checking `const_for` and `const_try` feature gates. I think anyone can review this, so no r? this time.
- Loading branch information
Showing
5 changed files
with
106 additions
and
11 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
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
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
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,20 @@ | ||
// check-pass | ||
|
||
#![feature(const_trait_impl)] | ||
#![feature(const_fn_trait_bound)] | ||
#![feature(const_precise_live_drops)] | ||
|
||
const fn foo<T, E>(res: Result<T, E>) -> Option<T> where E: ~const Drop { | ||
match res { | ||
Ok(t) => Some(t), | ||
Err(_e) => None, | ||
} | ||
} | ||
|
||
pub struct Foo<T>(T); | ||
|
||
const fn baz<T: ~const Drop, E: ~const Drop>(res: Result<Foo<T>, Foo<E>>) -> Option<Foo<T>> { | ||
foo(res) | ||
} | ||
|
||
fn main() {} |
51 changes: 51 additions & 0 deletions
51
src/test/ui/rfc-2632-const-trait-impl/trait-default-body-stability.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,51 @@ | ||
// check-pass | ||
|
||
#![feature(staged_api)] | ||
#![feature(const_trait_impl)] | ||
#![feature(const_fn_trait_bound)] | ||
#![feature(const_t_try)] | ||
#![feature(const_try)] | ||
#![feature(try_trait_v2)] | ||
|
||
#![stable(feature = "foo", since = "1.0")] | ||
|
||
use std::ops::{ControlFlow, FromResidual, Try}; | ||
|
||
#[stable(feature = "foo", since = "1.0")] | ||
pub struct T; | ||
|
||
#[stable(feature = "foo", since = "1.0")] | ||
#[rustc_const_unstable(feature = "const_t_try", issue = "none")] | ||
impl const Try for T { | ||
type Output = T; | ||
type Residual = T; | ||
|
||
fn from_output(t: T) -> T { | ||
t | ||
} | ||
|
||
fn branch(self) -> ControlFlow<T, T> { | ||
ControlFlow::Continue(self) | ||
} | ||
} | ||
|
||
#[stable(feature = "foo", since = "1.0")] | ||
#[rustc_const_unstable(feature = "const_t_try", issue = "none")] | ||
impl const FromResidual for T { | ||
fn from_residual(t: T) -> T { | ||
t | ||
} | ||
} | ||
|
||
#[stable(feature = "foo", since = "1.0")] | ||
pub trait Tr { | ||
#[default_method_body_is_const] | ||
#[stable(feature = "foo", since = "1.0")] | ||
fn bar() -> T { | ||
T? | ||
// Should be allowed. | ||
// Must enable unstable features to call this trait fn in const contexts. | ||
} | ||
} | ||
|
||
fn main() {} |