-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
arbitrary_self_types: Split the Autoderef chain #146095
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
Open
dingxiangfei2009
wants to merge
3
commits into
rust-lang:main
Choose a base branch
from
dingxiangfei2009:autoderef-split
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1773,7 +1773,9 @@ fn check_method_receiver<'tcx>( | |
| // Report error; would not have worked with `arbitrary_self_types[_pointers]`. | ||
| { | ||
| match receiver_validity_err { | ||
| ReceiverValidityError::DoesNotDeref if arbitrary_self_types_level.is_some() => { | ||
| ReceiverValidityError::DoesNotReceive | ||
| if arbitrary_self_types_level.is_some() => | ||
| { | ||
| let hint = match receiver_ty | ||
| .builtin_deref(false) | ||
| .unwrap_or(receiver_ty) | ||
|
|
@@ -1787,7 +1789,7 @@ fn check_method_receiver<'tcx>( | |
|
|
||
| tcx.dcx().emit_err(errors::InvalidReceiverTy { span, receiver_ty, hint }) | ||
| } | ||
| ReceiverValidityError::DoesNotDeref => { | ||
| ReceiverValidityError::DoesNotReceive => { | ||
| tcx.dcx().emit_err(errors::InvalidReceiverTyNoArbitrarySelfTypes { | ||
| span, | ||
| receiver_ty, | ||
|
|
@@ -1809,7 +1811,7 @@ fn check_method_receiver<'tcx>( | |
| enum ReceiverValidityError { | ||
| /// The self type does not get to the receiver type by following the | ||
| /// autoderef chain. | ||
| DoesNotDeref, | ||
| DoesNotReceive, | ||
| /// A type was found which is a method type parameter, and that's not allowed. | ||
| MethodGenericParamUsed, | ||
| } | ||
|
|
@@ -1865,17 +1867,21 @@ fn receiver_is_valid<'tcx>( | |
|
|
||
| confirm_type_is_not_a_method_generic_param(receiver_ty, method_generics)?; | ||
|
|
||
| let mut autoderef = Autoderef::new(infcx, wfcx.param_env, wfcx.body_def_id, span, receiver_ty); | ||
| let cache = Default::default(); | ||
| let mut autoderef = | ||
| Autoderef::new(infcx, Some(&cache), wfcx.param_env, wfcx.body_def_id, span, receiver_ty); | ||
|
|
||
| // The `arbitrary_self_types` feature allows custom smart pointer | ||
| // types to be method receivers, as identified by following the Receiver<Target=T> | ||
| // types to be method receivers, as identified by following the Receiver<Target = T> | ||
| // chain. | ||
| if arbitrary_self_types_enabled.is_some() { | ||
| autoderef = autoderef.use_receiver_trait(); | ||
| // We are in the wf check, so we would like to deref the references in the type head. | ||
| // However, we do not want to walk `Deref` chain. | ||
| autoderef = autoderef.follow_receiver_chain(); | ||
|
Comment on lines
+1878
to
+1880
Member
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'm curious why that is here? But in |
||
| } | ||
|
|
||
| // The `arbitrary_self_types_pointers` feature allows raw pointer receivers like `self: *const Self`. | ||
| if arbitrary_self_types_enabled == Some(ArbitrarySelfTypesLevel::WithPointers) { | ||
| if matches!(arbitrary_self_types_enabled, Some(ArbitrarySelfTypesLevel::WithPointers)) { | ||
| autoderef = autoderef.include_raw_pointers(); | ||
| } | ||
|
|
||
|
|
@@ -1929,7 +1935,7 @@ fn receiver_is_valid<'tcx>( | |
| } | ||
|
|
||
| debug!("receiver_is_valid: type `{:?}` does not deref to `{:?}`", receiver_ty, self_ty); | ||
| Err(ReceiverValidityError::DoesNotDeref) | ||
| Err(ReceiverValidityError::DoesNotReceive) | ||
| } | ||
|
|
||
| fn legacy_receiver_is_implemented<'tcx>( | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Are these impls required? I imagine this might be a consequence of my comment in
wfcheck?