-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
A-type-systemArea: Type systemArea: Type systemC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-langRelevant to the language teamRelevant to the language teamWG-traits[RETIRED] Working group: Traits[RETIRED] Working group: Traitsdisposition-postponeThis issue / PR is in PFCP or FCP with a disposition to postpone it.This issue / PR is in PFCP or FCP with a disposition to postpone it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
This issue tracks experimental work, overseen by the lang team, on several interrelated topics:
- Improving the ergonomics around
Copy
types and references (i.e. "imagine never having to write&0
orlet z = &u * &(&(&u.square() + &(&A * &u)) + &one);
again) - Improving the consistency of method dispatch for operators with standard dispatch.
- Improving the ergonomics around using owned values where references are expected.
- Improving the interaction between generics and coercions.
- Improving the interaction between function-passing code and coercions.
- Helping to avoid accidental copies of large
Copy
types. - Potentially a very limited form of auto-
Clone
.
None of these bullet items should be taken as signifying a decision, but rather a desire to experiment in a particularly tricky design space.
Ongoing experiments
- RFC: Allow autoderef and autoref in operators
- Rust tracking issue is Tracking issue: Allow autoderef and autoref in operators (experiment) #44762.
- RFC: Autoreferencing
Copy
Types- Rust tracking issue is Autoreferencing copy types #44763.
- Lint warning against undesirable copies.
- Rust tracking issue is Lint for undesirable, implicit copies #45683.
Relevant previous discussions
This tracking issue is a good place to continue discussion, at least initially; we may ultimately want to break out threads on internals to help hash out preliminary design thoughts.
After an experimental period, the expectation is that whatever designs are deemed sufficiently plausible are turned into fresh RFCs, and then go through the standard process.
leoyvens, cramertj, Pratyush, Nokel81, dobkeratops and 11 moreest31, panicbit, Thiez, H2CO3 and danielhenrymantillakannan83burdges, quininer, cramertj, L-as and 2 more
Metadata
Metadata
Assignees
Labels
A-type-systemArea: Type systemArea: Type systemC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-langRelevant to the language teamRelevant to the language teamWG-traits[RETIRED] Working group: Traits[RETIRED] Working group: Traitsdisposition-postponeThis issue / PR is in PFCP or FCP with a disposition to postpone it.This issue / PR is in PFCP or FCP with a disposition to postpone it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
Copy
Types rust-lang/rfcs#2111SergioBenitez commentedon Sep 28, 2017
While trying to generalize a concept in Rocket, I ran into issues when coercions I expected to happen automatically did not. I'll illustrate with examples.
In the code below, the
Handler
trait is implemented for all types that implement the function traitFn(&str) -> &str
(note the implicit HRTB). Among these types, of course, isfor<'r> fn(&'r str) -> &'r str
. The program below typechecks:On the other hand, none of the
is_handler
calls below typecheck:In each of these cases, however, a manual coercion can be applied that results in the call typechecking:
I expected that the coercions applied manually above would be applied automatically by Rust. In particular, I expected the
'static
lifetime in return types to coerce to a generic lifetime.But note that similar coercions are automatically applied when a function trait bound is enjoined without an accompanying
impl
search (re: @eddyb). The following program typechecks without any manual coercions:This implies that there already exists machinery to automatically perform these types of coercions in certain situations. I'd like to see these particular automatic coercions be applied during
impl
search as well, at least in the case of function types.P.S: There are also cases where a manual coercion doesn't result in a typechecked call while an automatic coercion does:
And cases were neither works where it would likely be expected to:
arielb1 commentedon Sep 28, 2017
I think what's going here is just that coercions, like everything else in Rust, don't trigger based on the set of pending trait obligations.I am assuming you are talking about this example:
There are no coercions in either of these examples - the second one successfully uses the
[closure]: Fn(&str) -> &str
impl. The reason the first example doesn't work is because you only get 1 chance to trigger higher-ranked inference (I don't think this is going to get any better - this area is full of undecidable cases and is basically heuristic), and a_: Handler
bound isn't enough to trigger it (while a_: Fn(&str) -> &str
is).However, some specific examples are different, non-coercion problems:
That is just #38714, which is being fixed
This also looks like some sort of screwiness, we might look into it.
SergioBenitez commentedon Sep 28, 2017
This appears to be true sometimes and not other times, but either way, my point is that (at least for function types) coercions should be trigged based on the set of pending trait obligations. For an instance of when these coercions do presently trigger, see the example towards the middle of my comment. I've reproduced it below:
arielb1 commentedon Sep 28, 2017
Actually there are no coercions in any of these examples (except when explicitly triggered via casts), just heuristic HRT inference.
22 remaining items
nikomatsakis commentedon Oct 12, 2020
Like @scottmcm I am happy to close this issue, but I am still in favor of most of the ideas here. I think the right way forward at this point is probably experimenting with implementation. I don't know how much bandwidth there is for such mentoring, but I'd encourage folks to reach out. I would also say that filing lang team proposals for specific ideas here would be great, although I think the response will largely be "we're interested but it's going to require some experimentation!"
Initial draft of copy ergonomics design note
Initial draft of copy ergonomics design note
Mark-Simulacrum commentedon Oct 20, 2020
Closing in favor of rust-lang/lang-team#62 and rust-lang/lang-team#63, as discussed in a recent language team meeting -- but if someone disagrees with that, please feel free to reopen.
Initial draft of copy ergonomics design note