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

Say that ... range patterns are rejected in the 2021 edition #1114

Merged
merged 2 commits into from
Dec 11, 2021

Conversation

mattheww
Copy link
Contributor

@mattheww mattheww commented Dec 3, 2021

Corresponding issue is #1071

src/patterns.md Outdated
@@ -535,6 +533,8 @@ minimum to maximum value. The range of values for a `char` type are precisely th
ranges containing all Unicode Scalar Values: `'\u{0000}'..='\u{D7FF}'` and
`'\u{E000}'..='\u{10FFFF}'`.

> **Edition Differences**: Before the 2021 edition, closed range patterns may be written using `...` in place of `..=`, with the same meaning.
Copy link
Member

Choose a reason for hiding this comment

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

Can you clarify that before the 2021 edition ..= is also allowed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've reworded in b83fcc1

@ehuss
Copy link
Contributor

ehuss commented Dec 8, 2021

Thanks for the PR!

The _ObsoleteRangePattern_ grammar needs to have some kind of indication that it is for < 2021 editions. The grammar blocks are intended to be standalone for the purpose of parsing (text in the English prose is intended for things done after parsing). There isn't much precedent for how that should be formatted. The only things currently are the footnotes in the functions grammar. I think it would be fine to do something similar here. It's a bit awkward to define multiple languages simultaneously.

@mattheww
Copy link
Contributor Author

I've added a footnote.

I'm not sure anything currently defines whether this rule is considered to be part of the grammar or something that happens after parsing: I don't know a way to make rustc distinguish these cases.

As far as the implementation is concerned, ... isn't rejected when parsing, but by a lint that runs over the generated AST.

I see rust-lang/wg-grammar#6 and rust-lang/wg-grammar#41 have been left unsettled.

Out of interest, I checked what syn does, and it unconditionally accepts both ... and ..= without distinguishing them in the returned AST. It doesn't seem to contemplate parsing varying by edition.

@ehuss
Copy link
Contributor

ehuss commented Dec 11, 2021

I'm sorry, I misremembered how that was implemented. I went ahead and removed the last commit, since I was mistaken about how this works. I was thinking this was done in the parser.

From a language perspective, you can test how parsing works via macros, or using false #[cfg] attributes. For example, the following are some examples that work in 2021:

macro_rules! pat {
    ($e:pat) => {};
}

#[cfg(FALSE)]
fn f(x: i32) {
    match x {
        1...2 => {}
    }
}

fn main() {
    pat!(1...2);
}

The idea for the grammar in the reference is to capture what ends up in the AST, which is relevant to macros and expansion.

As for how this is actually implemented, the key part is here where the lint is defined with FutureIncompatibilityReason::EditionError. The majority of lints are handled after expansion.

@ehuss ehuss merged commit 1ecc70d into rust-lang:master Dec 11, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 23, 2021
Update books

## nomicon

1 commits in 49681ea4a9fa81173dbe9ffed74b4d4a35eae9e3..c05c452b36358821bf4122f9c418674edd1d713d
2021-11-24 16:27:28 +0900 to 2021-12-13 15:23:48 +0900
- Update the guidance on uninitialized data with ptr::addr_of_mut (rust-lang/nomicon#325)

## reference

3 commits in 954f3d441ad880737a13e241108f791a4d2a38cd..06f9e61931bcf58b91dfe6c924057e42ce273ee1
2021-11-29 11:11:30 -0800 to 2021-12-17 07:31:40 -0800
- keep consistent for primitive types (rust-lang/reference#1118)
- README.md: link to mdbook docs (rust-lang/reference#1117)
- Say that `...` range patterns are rejected in the 2021 edition (rust-lang/reference#1114)

## book

4 commits in 5f9358faeb1f46e19b8a23a21e79fd7fe150491e..8a0bb3c96e71927b80fa2286d7a5a5f2547c6aa4
2021-12-05 21:33:16 -0500 to 2021-12-22 20:54:27 -0500
- Propagate edits back
- Fix number disagreement. Fixes rust-lang/book#2858.
- Wrap some code in main to make scopes clearer. Fixes rust-lang/book#2830.
- Respond to ch5 nostarch edits

## rustc-dev-guide

9 commits in a374e7d8bb6b79de45b92295d06b4ac0ef35bc09..9bf0028b557798ddd07a6f652e4d0c635d3d6620
2021-12-03 09:26:47 -0800 to 2021-12-20 21:53:57 +0900
- remove rustfix item in test intro (rust-lang/rustc-dev-guide#1277)
- Move date-check comment to fix Markdown syntax
- Update humor docs for special-casing ferris emoji
- Fix some broken links (rust-lang/rustc-dev-guide#1274)
- Update rustdoc internals
- Update HIR chapter to use `HirId` instead of `NodeId`
- Fix some broken links
- Update src/getting-started.md
- Improve documentation on r?
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.

None yet

3 participants