Skip to content

Remove incorrect coercion. Define type coercions. - #342

Closed
Havvy wants to merge 1 commit into
rust-lang:masterfrom
Havvy:coercions
Closed

Remove incorrect coercion. Define type coercions.#342
Havvy wants to merge 1 commit into
rust-lang:masterfrom
Havvy:coercions

Conversation

@Havvy

Copy link
Copy Markdown
Contributor

No description provided.

@matthewjaspermatthewjasper left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Comment threadsrc/type-coercions.md
```

* Function results, either the final line of a block if it is not
* Function results – either the final line of a block if it is not

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nitpick: shouldn't this be an em dash without surrounding spaces?

Comment threadsrc/type-coercions.md
Coercion is allowed between the following types:

* `T` to `U` if `T` is a subtype of `U` (*reflexive case*)
* `T` to `U` if `T` is a [subtype] of `U` (*reflexive case*)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the "reflexive case" annotation mean anything here? T to U when they are distinct is not reflexivity, although this does imply reflexivity because T is a subtype of T

Comment threadsrc/type-coercions.md

* `T` to `U`, when `U` is a trait object type and either `T` implements `U` or
`T` is a trait object for a subtrait of `U`.
* `T` to `dyn U`, when `T` implements `U + Sized`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think + Sized is accurate here; without it, coercions of references won't always work because going from &T to &U would require that T be sized. Unless that's actually how it works?

@alercah

Copy link
Copy Markdown
Contributor

@Havvy Can you make the changes for this one?

Comment threadsrc/type-coercions.md

Coercions are defined in [RFC 401]. [RFC 1558] then expanded on that.
A coercion is implicit and has no syntax.
**Type coercions** are implicit changes of the type of a value. They happen

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: An implicit coercion is essentially an implicit operation on a value. The value doesn't so much change type as there's an invisible "function call" on the value that produces a different value (this gets muddied a bit by subtyping and ownership). The language Idris allows one to define implicit functions and one can think of the implicit coercions in Rust as a set of those.

@CentrilCentril self-assigned this Apr 8, 2020
@Havvy

Havvy commented Nov 5, 2020

Copy link
Copy Markdown
ContributorAuthor

This is outdated.

@HavvyHavvy closed this Nov 5, 2020
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@Havvy@alercah@Centril@matthewjasper