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

Reflect changes about unsizing casts in const context #1221

Merged
merged 1 commit into from
May 27, 2022

Conversation

AnthonyMikh
Copy link
Contributor

Since Rust 1.61.0 it is possible to do unsizing casts in const context, so reflect that in reference.

Since Rust 1.61.0 it is possible to do unsizing casts in const context
@ehuss
Copy link
Contributor

ehuss commented May 25, 2022

Thanks! It's not entirely clear to me that this is related to 1.61. From what I can tell, unsizing casts in a const fn has been stable since rust-lang/rust#85078 (1.54). Unsizing casts for dyn trait in a const context seem to go back further, but I can't pinpoint it (at least 1.28?)

@oli-obk Do you perhaps remember what this line was referring to? The only thing I can find is rust-lang/rust#64992, where @RalfJung noticed that dyn unsizing is disallowed, but only in const fn. I tried making an example where dyn unsizing was rejected in a const context, but kept running into other const limitations preventing me from creating an example.

@RalfJung
Copy link
Member

Mentioning dyn traits in const fn (in any expression, including casts) was disallowed until rust-lang/rust#93827. So 1.61 sounds right I think.

@ehuss
Copy link
Contributor

ehuss commented May 26, 2022

This section defines what is allowed in any const context (not just const fn). From what I can tell, dyn traits in something like a const works fine since at least 1.28 (needed const_let till 1.33, 1.27 and earlier complains about not allowing blocks). But perhaps I am misunderstanding about what it means about an "unsizing cast"?

(Sorry for the questions, I'm trying to fully understand what this means.)

@RalfJung
Copy link
Member

This section defines what is allowed in any const context (not just const fn).

Well, the rules were different between const and const fn for quite a while. (They still are different, but now floating point operations are the only difference.)

In const/static initializers, this has worked since 1.0:

trait Trait: Send + Sync {}
impl Trait for i32 {}

static X: i32 = 5;
static Y: &'static Trait = &X; // implicit dyn Trait unsizing

and this has worked since 1.2:

trait Trait: Send + Sync {}
impl Trait for i32 {}

static X: i32 = 5;
static Y: &'static Trait = &X as &Trait; // explicit dyn Trait unsizing cast

@ehuss
Copy link
Contributor

ehuss commented May 27, 2022

Hm, OK, I'm still unsure then why it was included since there is a separate section that explicitly lists the differences for const fn.

There are several other errors in the list. It would be nice if someone could audit it, though I'm not sure if anyone really reads this page.

Thanks @AnthonyMikh for the fix!

@ehuss ehuss merged commit 683bfe5 into rust-lang:master May 27, 2022
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jun 8, 2022
Update books

## nomicon

5 commits in 10d40c59a581c66d8ecd29ad18d410bf97ed524d..3a43983b76174342b7dbd3e12ea2c49f762e52be
2022-05-07 10:45:07 +0900 to 2022-05-30 17:01:30 +0900
- Changes for `c_unwind` (rust-lang/nomicon#365)
- Upgrade actions/checkout to v3 (rust-lang/nomicon#367)
- Clarification of borrowck (rust-lang/nomicon#354)
- Update the now stale warning about `PhantomData<T>` and dropck (rust-lang/nomicon#363)
- Minor language fixes (rust-lang/nomicon#364)

## reference

1 commits in b74825d8f88b685e239ade00f00de68ba4cd63d4..683bfe5cd64d589c6a1645312ab5f93b6385ccbb
2022-05-20 14:30:30 -0700 to 2022-05-27 11:54:20 -0700
- Reflect changes about unsizing casts in const context (rust-lang/reference#1221)

## book

58 commits in b4dd5f00b87190ad5ef42cbc2a88a783c6ae57ef..396fdb69de7fb18f24b15c7ad13491b1c1fa7231
2022-05-24 21:37:06 -0400 to 2022-06-08 10:02:35 -0400
- Make not-equals operator example consistent. Fixes rust-lang/book#3189.
- Propagate nostarch appendix edits to src
- Edits to edits to appendices
- Edits from nostarch for the appendices
- Propagate edits to chapter 20 to src
- Edits to edits of chapter 20
- Update reference to chapter 12 code that was changed
- Edits from nostarch to chapter 20
- Fix spelling mistake
- Propagate ch17 tech review changes to src
- Responses to tech review for ch17
- Chapter 17 tech review comments
- Update dependencies via `cargo update`
- Propagate changes from ch16 tech review to src
- Tech review comments and responses for chapter 16
- Println captures in chapter 15
- Propagate chapter 15 tech review edits to src
- Responses to tech review for chapter 15
- Tech review comments for chapter 15
- Merge branch 'ch14-tr'
- Upgrade to Rust 1.61
- Upgrade to Rust 1.60
- More little improvements to chapter 12
- Update references to ch12 to be Config::build instead of new
- Propagate ch12 tech review edits to src
- Responses to tech review of chapter 12
- Tech review comments of chapter 12
- Show directory layouts including integration test files
- Clarify that integration/doc tests aren't run if unit tests fail
- Propagate ch11 tech review edits to src
- Edits in response to tech review of chapter 11
- Comments from tech review in chapter 11
- Propagate other edits to nostarch
- Adjust listing so error output line numbers match
- Merge remote-tracking branch 'origin/pr/3153' into ch10-tr
- Reword a rewording about lifetimes of values vs references
- Merge remote-tracking branch 'origin/pr/3107' into ch10-tr
- Merge remote-tracking branch 'origin/pr/3104' into ch10-tr
- Propagate ch10 edits to src
- Edits in response to tech review
- Comments from tech review for chapter 10
- New dictionary entries
- Demonstrate a better expect message. Fixes rust-lang/book#2918.
- Propagate tech review ch9 edits to src
- Termination has stabilized! Fixes rust-lang/book#3116.
- Respond to tech review comments to chapter 9
- Comments from tech review on chapter 9
- Propagate changes for ch8 to src
- Clarify that split_whitespace returns an iterator
- Add type annotation in nostarch snapshot too
- Extra-clarity qualification
- Edits to chapter 8 in response to tech review
- Comments from tech review for chapter 8
- Propagate tech review edits to ch06 src
- Responses to tech review comments on chapter 6
- Chapter 6 after tech review
- Snapshot of chapter 1 for nostarch
- src: use TLSv1.3 if we're going to specify at all

## rust-by-example

4 commits in 2ed26865e8c29ef939dc913a97bd321cadd72a9a..dbb7e5e2345ee26199ffba218156b6009016a20c
2022-05-18 17:23:47 -0300 to 2022-06-02 16:30:51 -0300
- Fix typo in Traits → "impl Trait" (rust-lang/rust-by-example#1544)
- doc_testing.md: clarify tests vs doc-tests (rust-lang/rust-by-example#1547)
- unsafe::asm.md: add some explicit declarations (rust-lang/rust-by-example#1548)
- Update dsl.md to remove unnecessary braces (rust-lang/rust-by-example#1543)

## rustc-dev-guide

6 commits in 554c00e4805df7f7bffac7db408437d62d6dfb9a..6e4d6435db89bcc027b1bba9742e4f59666f5412
2022-05-24 17:15:35 -0700 to 2022-06-08 08:06:32 +0900
- Make build scripts and proc macros work with the suggested rust-analyzer config (rust-lang/rustc-dev-guide#1365)
- improve rustc_interface examples a little (rust-lang/rustc-dev-guide#1362)
- Bump regex from 1.4.3 to 1.5.5 in /ci/date-check (rust-lang/rustc-dev-guide#1364)
- Clarify cargo fallback behavior for rustup link (rust-lang/rustc-dev-guide#1273)
- Update rustc-driver related examples
- Triage some date references related to traits

## embedded-book

1 commits in f7cefbb995eec8c6148f213235e9e2e03268e775..cbb494f96da3268c2925bdadc65ca83d42f2d4ef
2022-04-20 10:38:51 +0000 to 2022-05-26 06:58:43 +0000
- Add Chinese translation repository  (rust-embedded/book#318)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 8, 2022
Update books

## nomicon

5 commits in 10d40c59a581c66d8ecd29ad18d410bf97ed524d..3a43983b76174342b7dbd3e12ea2c49f762e52be
2022-05-07 10:45:07 +0900 to 2022-05-30 17:01:30 +0900
- Changes for `c_unwind` (rust-lang/nomicon#365)
- Upgrade actions/checkout to v3 (rust-lang/nomicon#367)
- Clarification of borrowck (rust-lang/nomicon#354)
- Update the now stale warning about `PhantomData<T>` and dropck (rust-lang/nomicon#363)
- Minor language fixes (rust-lang/nomicon#364)

## reference

1 commits in b74825d8f88b685e239ade00f00de68ba4cd63d4..683bfe5cd64d589c6a1645312ab5f93b6385ccbb
2022-05-20 14:30:30 -0700 to 2022-05-27 11:54:20 -0700
- Reflect changes about unsizing casts in const context (rust-lang/reference#1221)

## book

58 commits in b4dd5f00b87190ad5ef42cbc2a88a783c6ae57ef..396fdb69de7fb18f24b15c7ad13491b1c1fa7231
2022-05-24 21:37:06 -0400 to 2022-06-08 10:02:35 -0400
- Make not-equals operator example consistent. Fixes rust-lang/book#3189.
- Propagate nostarch appendix edits to src
- Edits to edits to appendices
- Edits from nostarch for the appendices
- Propagate edits to chapter 20 to src
- Edits to edits of chapter 20
- Update reference to chapter 12 code that was changed
- Edits from nostarch to chapter 20
- Fix spelling mistake
- Propagate ch17 tech review changes to src
- Responses to tech review for ch17
- Chapter 17 tech review comments
- Update dependencies via `cargo update`
- Propagate changes from ch16 tech review to src
- Tech review comments and responses for chapter 16
- Println captures in chapter 15
- Propagate chapter 15 tech review edits to src
- Responses to tech review for chapter 15
- Tech review comments for chapter 15
- Merge branch 'ch14-tr'
- Upgrade to Rust 1.61
- Upgrade to Rust 1.60
- More little improvements to chapter 12
- Update references to ch12 to be Config::build instead of new
- Propagate ch12 tech review edits to src
- Responses to tech review of chapter 12
- Tech review comments of chapter 12
- Show directory layouts including integration test files
- Clarify that integration/doc tests aren't run if unit tests fail
- Propagate ch11 tech review edits to src
- Edits in response to tech review of chapter 11
- Comments from tech review in chapter 11
- Propagate other edits to nostarch
- Adjust listing so error output line numbers match
- Merge remote-tracking branch 'origin/pr/3153' into ch10-tr
- Reword a rewording about lifetimes of values vs references
- Merge remote-tracking branch 'origin/pr/3107' into ch10-tr
- Merge remote-tracking branch 'origin/pr/3104' into ch10-tr
- Propagate ch10 edits to src
- Edits in response to tech review
- Comments from tech review for chapter 10
- New dictionary entries
- Demonstrate a better expect message. Fixes rust-lang/book#2918.
- Propagate tech review ch9 edits to src
- Termination has stabilized! Fixes rust-lang/book#3116.
- Respond to tech review comments to chapter 9
- Comments from tech review on chapter 9
- Propagate changes for ch8 to src
- Clarify that split_whitespace returns an iterator
- Add type annotation in nostarch snapshot too
- Extra-clarity qualification
- Edits to chapter 8 in response to tech review
- Comments from tech review for chapter 8
- Propagate tech review edits to ch06 src
- Responses to tech review comments on chapter 6
- Chapter 6 after tech review
- Snapshot of chapter 1 for nostarch
- src: use TLSv1.3 if we're going to specify at all

## rust-by-example

4 commits in 2ed26865e8c29ef939dc913a97bd321cadd72a9a..dbb7e5e2345ee26199ffba218156b6009016a20c
2022-05-18 17:23:47 -0300 to 2022-06-02 16:30:51 -0300
- Fix typo in Traits → "impl Trait" (rust-lang/rust-by-example#1544)
- doc_testing.md: clarify tests vs doc-tests (rust-lang/rust-by-example#1547)
- unsafe::asm.md: add some explicit declarations (rust-lang/rust-by-example#1548)
- Update dsl.md to remove unnecessary braces (rust-lang/rust-by-example#1543)

## rustc-dev-guide

6 commits in 554c00e4805df7f7bffac7db408437d62d6dfb9a..6e4d6435db89bcc027b1bba9742e4f59666f5412
2022-05-24 17:15:35 -0700 to 2022-06-08 08:06:32 +0900
- Make build scripts and proc macros work with the suggested rust-analyzer config (rust-lang/rustc-dev-guide#1365)
- improve rustc_interface examples a little (rust-lang/rustc-dev-guide#1362)
- Bump regex from 1.4.3 to 1.5.5 in /ci/date-check (rust-lang/rustc-dev-guide#1364)
- Clarify cargo fallback behavior for rustup link (rust-lang/rustc-dev-guide#1273)
- Update rustc-driver related examples
- Triage some date references related to traits

## embedded-book

1 commits in f7cefbb995eec8c6148f213235e9e2e03268e775..cbb494f96da3268c2925bdadc65ca83d42f2d4ef
2022-04-20 10:38:51 +0000 to 2022-05-26 06:58:43 +0000
- Add Chinese translation repository  (rust-embedded/book#318)
Sign up for free to 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.

3 participants