-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #122222 - Nadrieril:deref-pat-feature-gate, r=compile…
…r-errors deref patterns: bare-bones feature gate and typechecking I am restarting the deref patterns experimentation. This introduces a feature gate under the lang-team [experimental feature](https://github.com/rust-lang/lang-team/blob/master/src/how_to/experiment.md) process, with [````@cramertj```` as lang-team liaison](rust-lang/lang-team#88) (it's been a while though, you still ok with this ````@cramertj?).```` Tracking issue: #87121. This is the barest-bones implementation I could think of: - explicit syntax, reusing `box <pat>` because that saves me a ton of work; - use `Deref` as a marker trait (instead of a yet-to-design `DerefPure`); - no support for mutable patterns with `DerefMut` for now; - MIR lowering will come in the next PR. It's the trickiest part. My goal is to let us figure out the MIR lowering part, which might take some work. And hopefully get something working for std types soon. This is in large part salvaged from ````@fee1-dead's```` #119467. r? ````@compiler-errors````
- Loading branch information
Showing
16 changed files
with
139 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fn main() { | ||
// We reuse the `box` syntax so this doesn't actually test the feature gate but eh. | ||
let box x = Box::new('c'); //~ ERROR box pattern syntax is experimental | ||
println!("x: {}", x); | ||
|
||
// `box` syntax is allowed to be cfg-ed out for historical reasons (#65742). | ||
#[cfg(FALSE)] | ||
let box _x = Box::new('c'); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error[E0658]: box pattern syntax is experimental | ||
--> $DIR/feature-gate-deref_patterns.rs:3:9 | ||
| | ||
LL | let box x = Box::new('c'); | ||
| ^^^^^ | ||
| | ||
= note: see issue #29641 <https://github.com/rust-lang/rust/issues/29641> for more information | ||
= help: add `#![feature(box_patterns)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//@ check-pass | ||
#![feature(deref_patterns)] | ||
#![allow(incomplete_features)] | ||
|
||
use std::rc::Rc; | ||
|
||
fn main() { | ||
let vec: Vec<u32> = Vec::new(); | ||
match vec { | ||
box [..] => {} | ||
_ => {} | ||
} | ||
match Box::new(true) { | ||
box true => {} | ||
_ => {} | ||
} | ||
match &Box::new(true) { | ||
box true => {} | ||
_ => {} | ||
} | ||
match &Rc::new(0) { | ||
box (1..) => {} | ||
_ => {} | ||
} | ||
// FIXME(deref_patterns): fails to typecheck because `"foo"` has type &str but deref creates a | ||
// place of type `str`. | ||
// match "foo".to_string() { | ||
// box "foo" => {} | ||
// _ => {} | ||
// } | ||
} |