-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Require impl Trait in associated types to appear in method signatures #110454
Require impl Trait in associated types to appear in method signatures #110454
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @compiler-errors (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
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.
Sorry for the delay. Here's some initial implementation thoughts.
compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs
Outdated
Show resolved
Hide resolved
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.
Do we have a test for this case?:
trait Trait {
type Item;
type Iter: IntoIterator<Item = Self::Item>;
fn iter() -> Self::Iter;
}
impl Trait for () {
type Item = impl Sized;
type Iter = impl IntoIterator<Item = Self::Item>;
fn iter() -> Self::Iter { None::<()> }
}
I think it's pretty reasonable to allow fn iter
to constrain impl Sized
, but we should probably have an explicit t-lang decision here?
I also suggest adding a couple tests:
// check-fail
// revisions: compare_ty compare_method
#![feature(impl_trait_in_assoc_type)]
#[cfg(compare_ty)]
mod compare_ty {
trait Trait {
type Ty: IntoIterator<Item = ()>;
}
impl Trait for () {
type Ty = Option<impl Sized>;
}
}
#[cfg(compare_method)]
mod compare_method {
trait Trait {
type Ty;
fn method() -> Self::Ty;
}
impl Trait for () {
type Ty = impl Sized;
fn method() -> () {}
}
}
tests/ui/type-alias-impl-trait/associated-type-impl-trait-lifetime.rs
Outdated
Show resolved
Hide resolved
) -> Option<impl TypeVisitable<TyCtxt<'tcx>>> { | ||
let sig = match tcx.def_kind(def_id) { | ||
DefKind::AssocFn => Ok(tcx.fn_sig(def_id).skip_binder()), | ||
DefKind::AssocConst | DefKind::AssocTy => Err(tcx.type_of(def_id).skip_binder()), |
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.
why DefKid::AssocTy
?
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 added a comment for that. The reason for that is that we do wf checks of opaque types within their parent. So we need to treat their parent as having them in the signature, as we'd otherwise fail that wf check. The wfcheck is fishy anyway and we're working on removing it, so that will go away once we remove the wfcheck
I still need to look into @aliemjay's review, but I was able to get rid of many of the problems we had with the approach by replacing it entirely. It now mirrors |
This comment has been minimized.
This comment has been minimized.
5de24be
to
97b3038
Compare
Yes, we do have https://github.com/rust-lang/rust/blob/master/tests/ui/generic-associated-types/issue-89008.rs I don't think this feature makes sense without automatically recursing into other associated types from the same impl block. |
@rustbot ready |
☔ The latest upstream changes (presumably #111287) made this pull request unmergeable. Please resolve the merge conflicts. |
30120bb
to
f7b5568
Compare
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
This comment was marked as spam.
This comment was marked as spam.
c82a7a1
to
5b9ad1e
Compare
@rustbot ready sorry everyone, no clue what happened here |
It's okay its your first time making a PR here, it happens :) |
@bors r=compiler-errors |
📌 Commit 5cd56f11622c1311c3b54d734d5089e3200b3f7c has been approved by It is now in the queue for this repository. |
This comment has been minimized.
This comment has been minimized.
@bors r- |
…hidden type may be registered for an opaque type
5cd56f1
to
4e92f76
Compare
@bors r=compiler-errors |
Rollup of 6 pull requests Successful merges: - rust-lang#110454 (Require impl Trait in associated types to appear in method signatures) - rust-lang#111096 (Add support for `cfg(overflow_checks)`) - rust-lang#111451 (Note user-facing types of coercion failure) - rust-lang#111469 (Fix data race in llvm source code coverage) - rust-lang#111494 (Encode `VariantIdx` so we can decode ADT variants in the right order) - rust-lang#111499 (asm: loongarch64: Drop efiapi) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This implements the limited version of TAIT that was proposed in #107645 (comment)
Similar to
impl Trait
in return types,impl Trait
in associated types may only be used within the impl block which it is a part of. To make everything simpler and forward compatible to getting desugared to a plain type alias impl trait in the future, we're requiring that any associated functions or constants that want to register hidden types must be using the associated type in their signature (type of the constant or argument/return type of the associated method. Where bounds mentioning the associated type are ignored).We have preexisting tests checking that this works transitively across multiple associated types in situations like