-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implement ~const
item bounds in RPIT
#133218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2117,7 +2117,13 @@ impl<'tcx> TyCtxt<'tcx> { | |
_ => bug!("unexpected parent item of associated item: {parent_def_id:?}"), | ||
} | ||
} | ||
DefKind::Closure | DefKind::OpaqueTy => { | ||
DefKind::OpaqueTy => match self.opaque_ty_origin(def_id) { | ||
hir::OpaqueTyOrigin::FnReturn { parent, .. } => self.is_conditionally_const(parent), | ||
Comment on lines
+2120
to
+2121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am I understanding this correctly that this would treat the const fn a() -> impl Trait {} as conditionally const? If so, then this is wrong, and the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, you're misreading. It's conditionally const, but it just has no const item bounds. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll try to state the situation in a bit clearer terms.
So, opaques are not What marking them as conditionally const means, for an alias, is that we try to look at the So for something like:
We know that the RPIT implements
where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, thanks |
||
hir::OpaqueTyOrigin::AsyncFn { .. } => false, | ||
// FIXME(const_trait_impl): ATPITs could be conditionally const? | ||
hir::OpaqueTyOrigin::TyAlias { .. } => false, | ||
}, | ||
DefKind::Closure => { | ||
// Closures and RPITs will eventually have const conditions | ||
// for `~const` bounds. | ||
false | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0277]: the trait bound `(): const Foo` is not satisfied | ||
--> $DIR/const-opaque.rs:31:18 | ||
| | ||
LL | let opaque = bar(()); | ||
| ^^^^^^^ | ||
|
||
error[E0277]: the trait bound `(): const Foo` is not satisfied | ||
--> $DIR/const-opaque.rs:33:5 | ||
| | ||
LL | opaque.method(); | ||
| ^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//@ revisions: yes no | ||
//@ compile-flags: -Znext-solver | ||
//@[yes] check-pass | ||
|
||
#![feature(const_trait_impl)] | ||
|
||
#[const_trait] | ||
trait Foo { | ||
fn method(&self); | ||
} | ||
|
||
impl<T: ~const Foo> const Foo for (T,) { | ||
fn method(&self) {} | ||
} | ||
|
||
#[cfg(yes)] | ||
impl const Foo for () { | ||
fn method(&self) {} | ||
} | ||
|
||
#[cfg(no)] | ||
impl Foo for () { | ||
fn method(&self) {} | ||
} | ||
|
||
const fn bar<T: ~const Foo>(t: T) -> impl ~const Foo { | ||
(t,) | ||
} | ||
|
||
const _: () = { | ||
let opaque = bar(()); | ||
//[no]~^ ERROR the trait bound `(): const Foo` is not satisfied | ||
opaque.method(); | ||
//[no]~^ ERROR the trait bound `(): const Foo` is not satisfied | ||
std::mem::forget(opaque); | ||
}; | ||
|
||
fn main() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this is necessary but it helps make sure we report errors in the right order.