Reject generic self types using impl defid: do not merge.#130120
Closed
adetaylor wants to merge 1 commit intorust-lang:masterfrom
Closed
Reject generic self types using impl defid: do not merge.#130120adetaylor wants to merge 1 commit intorust-lang:masterfrom
adetaylor wants to merge 1 commit intorust-lang:masterfrom
Conversation
The RFC for arbitrary self types v2 declares that we should reject "generic" self types. This commit does so. The definition of "generic" was unclear in the RFC, but has been explored in rust-lang#129147 and the conclusion is that "generic" means any `self` type which is a type parameter defined on the method itself, or references to such a type. This approach was chosen because other definitions of "generic" don't work. Specifically, * we can't filter out generic type _arguments_, because that would filter out Rc<Self> and all the other types of smart pointer we want to support; * we can't filter out all type params, because Self itself is a type param, and because existing Rust code depends on other type params declared on the type (as opposed to the method). This PR is a second attempt at achieving this, based on producing a new well-formedness checking context which is only aware of the type params of the impl block, not of the method itself. It doesn't currently work because it turns out we do need some method params under some circumstances, but raising it for completeness. This PR adds lots of extra tests to arbitrary-self-from-method-substs. Most of these are ways to trigger a "type mismatch" error which https://github.com/rust-lang/rust/blob/9b82580c7347f800c2550e6719e4218a60a80b28/compiler/rustc_hir_typeck/src/method/confirm.rs#L519 hopes can be minimized by filtering out generics in this way. We remove a FIXME from confirm.rs suggesting that we make this change. It's still possible to cause type mismatch errors, and a subsequent PR may be able to improve diagnostics in this area, but it's harder to cause these errors without contrived uses of the turbofish. This is a part of the arbitrary self types v2 project, rust-lang/rfcs#3519 rust-lang#44874 r? @wesleywiser
Contributor
Author
|
@rustbot label +S-waiting-on-author -S-waiting-on-review |
Collaborator
|
The job Click to see the possible cause of the failure (guessed by this bot) |
Member
|
(oops, I didn't mean to mark it as ready for review ^^) |
18 tasks
Collaborator
|
☔ The latest upstream changes (presumably #132027) made this pull request unmergeable. Please resolve the merge conflicts. |
Member
|
@adetaylor Should I still review this or has this been superseded by #130098? |
Contributor
Author
|
If you are happy with the approach in #130098 then yes I think this is probably irrelevant now (the pros and cons were discussed here). |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The RFC for arbitrary self types v2 declares that we should reject "generic" self types. This commit does so.
The definition of "generic" was unclear in the RFC, but has been explored in
#129147
and the conclusion is that "generic" means any
selftype which is a type parameter defined on the method itself, or references to such a type.This approach was chosen because other definitions of "generic" don't work. Specifically,
This PR is a second attempt at achieving this, based on producing a new well-formedness checking context which is only aware of the type params of the impl block, not of the method itself.
It doesn't currently work because it turns out we do need some method params under some circumstances, but raising it for completeness.
This PR adds lots of extra tests to arbitrary-self-from-method-substs. Most of these are ways to trigger a "type mismatch" error which
rust/compiler/rustc_hir_typeck/src/method/confirm.rs
Line 519 in 9b82580
This is a part of the arbitrary self types v2 project, rust-lang/rfcs#3519
#44874
r? @wesleywiser