forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
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 rust-lang#119721 - compiler-errors:constness-implication, r=fee1-dead `~const` trait and projection bounds do not imply their non-const counterparts This PR removes the hack where we install a non-const trait and projection bound for every `const_trait` and `~const` projection bound we have in the AST. It ends up messing up more things than it fixes, see words below. Fixes rust-lang#119718 cc `@fmease` `@fee1-dead` `@oli-obk` r? fee1-dead or one of y'all i don't care --- My understanding is that this hack was added to support the following code: ```rust pub trait Owo<X = <Self as Uwu>::T> {} #[const_trait] pub trait Uwu: Owo {} ``` Which is concretely lifted from in the `FromResidual` and `Try` traits. Since within the param-env of `trait Uwu`, we only know that `Self: ~const Uwu` and not `Self: Uwu`, the projection `<Self as Uwu>::T` is not satsifyable. This causes problems such as rust-lang#119718, since instantiations of `FnDef` types coming from `const fn` really do **only** implement one of `FnOnce` or `const FnOnce`! --- In the long-term, I believe that such code should really look something more like: ```rust #[const_trait] pub trait Owo<X = <Self as ~const Uwu>::T> {} #[const_trait] pub trait Uwu: Owo {} ``` ... and that we should introduce some sort of `<T as ~const Foo>::Bar` bound syntax, since due to the fact that `~const` bounds can be present in item bounds, e.g. ```rust #[const_trait] trait Foo { type Bar: ~const Destruct; } ``` It's easy to see that `<T as Foo>::Bar` and `<T as ~const Foo>::Bar` (or `<T as const Foo>::Bar`) can be distinct types with distinct item bounds! **Admission**: I know I've said before that I don't like `~const` projection syntax, I do at this point believe they're necessary to fully express bounds and types in a maybe-const world.
- Loading branch information
Showing
14 changed files
with
227 additions
and
128 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
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
86 changes: 86 additions & 0 deletions
86
tests/ui/rfcs/rfc-2632-const-trait-impl/const-fns-are-early-bound.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,86 @@ | ||
// check-pass | ||
|
||
#![crate_type = "lib"] | ||
#![allow(internal_features)] | ||
#![no_std] | ||
#![no_core] | ||
#![feature( | ||
auto_traits, | ||
const_trait_impl, | ||
effects, | ||
lang_items, | ||
no_core, | ||
staged_api, | ||
unboxed_closures | ||
)] | ||
#![stable(feature = "minicore", since = "1.0.0")] | ||
|
||
fn test() { | ||
fn is_const_fn<F>(_: F) | ||
where | ||
F: const FnOnce<()>, | ||
{ | ||
} | ||
|
||
const fn foo() {} | ||
|
||
is_const_fn(foo); | ||
} | ||
|
||
/// ---------------------------------------------------------------------- /// | ||
/// Const fn trait definitions | ||
#[const_trait] | ||
#[lang = "fn"] | ||
#[rustc_paren_sugar] | ||
trait Fn<Args: Tuple>: ~const FnMut<Args> { | ||
extern "rust-call" fn call(&self, args: Args) -> Self::Output; | ||
} | ||
|
||
#[const_trait] | ||
#[lang = "fn_mut"] | ||
#[rustc_paren_sugar] | ||
trait FnMut<Args: Tuple>: ~const FnOnce<Args> { | ||
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output; | ||
} | ||
|
||
#[const_trait] | ||
#[lang = "fn_once"] | ||
#[rustc_paren_sugar] | ||
trait FnOnce<Args: Tuple> { | ||
#[lang = "fn_once_output"] | ||
type Output; | ||
|
||
extern "rust-call" fn call_once(self, args: Args) -> Self::Output; | ||
} | ||
|
||
/// ---------------------------------------------------------------------- /// | ||
/// All this other stuff needed for core. Unrelated to test. | ||
#[lang = "destruct"] | ||
#[const_trait] | ||
trait Destruct {} | ||
|
||
#[lang = "freeze"] | ||
unsafe auto trait Freeze {} | ||
|
||
#[lang = "drop"] | ||
#[const_trait] | ||
trait Drop { | ||
fn drop(&mut self); | ||
} | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
#[lang = "copy"] | ||
trait Copy {} | ||
|
||
#[lang = "tuple_trait"] | ||
trait Tuple {} | ||
|
||
#[lang = "receiver"] | ||
trait Receiver {} | ||
|
||
impl<T: ?Sized> Receiver for &T {} | ||
|
||
impl<T: ?Sized> Receiver for &mut T {} |
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
Oops, something went wrong.