Skip to content
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

Unify unsized types in type inference #17178

Closed
nrc opened this issue Sep 11, 2014 · 4 comments · Fixed by #18121
Closed

Unify unsized types in type inference #17178

nrc opened this issue Sep 11, 2014 · 4 comments · Fixed by #18121
Assignees
Labels
A-DSTs Area: Dynamically-sized types (DSTs)
Milestone

Comments

@nrc
Copy link
Member

nrc commented Sep 11, 2014

In order not have a tonne of coherence errors, we currently do not unify unsized types with type variables in type inference. For example, [T] with U. This mimics our old behaviour where unsized types were not types.

This prevents us having an impl for &T which will use an impl for [T], i.e., we need a separate impl for &[T]. This is one of the primary benefits of DST. It also causes problems when the compiler needs to infer a DST for a type parameter, e.g., in function calls. See #17122 for one example.

Blocks #16918, #12938

@nrc
Copy link
Member Author

nrc commented Sep 11, 2014

Nominating for p-backcompat-lang. This is the last backwards incompatible part of DST, so we can unblock #12938 from 1.0. This change is backwards incompatible since it will introduce coherence errors for impls for both sized and unsized types.

@nrc nrc mentioned this issue Sep 11, 2014
23 tasks
@nrc
Copy link
Member Author

nrc commented Sep 11, 2014

Plan A:

  • modified variation on trait-reform nested obligation rules (consider the bounds of T in &T so that &T where T is Sized vs not Sized are different types)
  • make snapshot
  • update impls
  • patch up trait-reform nested obligation rules

Plan B

  • hack up type inference to track whether the parameter was Sized?
  • prevent unification if not
  • as above

@pnkfelix
Copy link
Member

Assigning P-backcompat-lang, 1.0 milestone.

@pnkfelix pnkfelix added this to the 1.0 milestone Sep 18, 2014
@huonw huonw added the A-DSTs Area: Dynamically-sized types (DSTs) label Oct 5, 2014
@brson brson assigned nrc Oct 9, 2014
nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Oct 21, 2014
Also:
1. stop eagerly coercing from `[T, ..n]` to `[T]` only do so if requested.
2. permit error to be interact more freely.

Fixes rust-lang#17178.
bors added a commit that referenced this issue Oct 22, 2014
…ng-infrastructure-2, r=pcwalton

Convert trait method dispatch to use new trait matching machinery.

This fixes about 90% of #17918. What remains to be done is to make inherent dispatch work with conditional dispatch as well. I plan to do this in a future patch by generalizing the "method match" code slightly to work for inherent impls as well (the basic algorithm is precisely the same).

Fixes #17178.

This is a [breaking-change] for two reasons:

1. The old code was a bit broken. I found various minor cases, particularly around operators, where the old code incorrectly matched, but an extra `*` or other change is now required. (See commit e8cef25 ("Correct case where the old version of method lookup...") for examples.)
2. The old code didn't type check calls against the method signature from the *trait* but rather the *impl*. The two can be different in subtle ways. This makes the new method dispatch both more liberal and more conservative than the original. (See commit 8308332 ("The new method lookup mechanism typechecks...") for examples.)

r? @pcwalton since he's been reviewing most of this series of changes
f? @nick29581 for commit 39df55f ("Permit DST types to unify like other types")
cc @aturon as this relates to library stabilization
@alexchandel
Copy link

This is closed, yet still listed as blocking on #12938

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-DSTs Area: Dynamically-sized types (DSTs)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants