Implement unique types per fn item, rather than having all fn items have fn pointer type#19891
Merged
Merged
Conversation
Member
|
r=me with nits fixed |
2 tasks
e4ec6c7 to
a568b53
Compare
Contributor
Author
|
@nick29581 I was thinking, perhaps we should have special type rules for this case so that we permit |
c25c3a8 to
89afce2
Compare
Contributor
Author
|
Re-examining the fallout, it's clear that the most useful change would be to propagate coercions through |
89afce2 to
1085a6b
Compare
1085a6b to
0263c41
Compare
0263c41 to
973d26e
Compare
df31867 to
96ffaf5
Compare
96ffaf5 to
dd18fa2
Compare
dd18fa2 to
2f04db6
Compare
type of a fn item or a fn pointer, which are now differentiated. Introduce coercion from fn item to fn pointer.
cannot use an `as` expression to coerce, so I used a one-off function instead (this is a no-op in stage0, but in stage1+ it triggers coercion from the fn pointer to the fn item type).
post-unboxed-closure-conversion. This requires a fair amount of annoying coercions because all the `map` etc types are defined generically over the `F`, so the automatic coercions don't propagate; this is compounded by the need to use `let` and not `as` due to stage0. That said, this pattern is to a large extent temporary and unusual.
…cions between them.
…cion changes, and also stop printing semi-useless inference by-products.
2f04db6 to
763152b
Compare
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this pull request
Dec 22, 2014
Conflicts: src/libcore/str.rs src/librustc_trans/trans/closure.rs src/librustc_typeck/collect.rs src/libstd/path/posix.rs src/libstd/path/windows.rs
This was referenced Dec 23, 2014
aturon
added a commit
to steveklabnik/rustbook
that referenced
this pull request
Dec 29, 2014
fix breakage from rust-lang/rust#19891
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.
This is part of the coercion RFC but also makes sense given unboxed closures. The idea is that every fn item has its own type. This type can be coerced to a fn pointer but is not a fn pointer. This PR does almost all the end-user visible changes, but leaves one thing undone: the representation of an instance of a "fn item type" is still a fn pointer at runtime. A later PR will have to change them to zero-sized values (I'll open an isssue on this).
This is a [breaking-change]. In general, the coercion rules ensure that code which used to take a
fn()type continus to work, but there are some patterns that need to be changed to insert explicit coercions.Example 1:
If/match arms sometimes require explicit types now:
Example 2:
Generic functions are another place where coercions often fail to trigger. Example:
This one may or may not get fixed going forward; inserting coercions in cases like these involves subtle changes to program semantics that may not be appropriate.
r? @nick29581