Stabilize match_default_bindings

This includes a submodule update to rustfmt
in order to allow a stable feature declaration.
This commit is contained in:
Taylor Cramer 2018-03-26 23:39:29 +02:00
parent e58df0d8c5
commit 3c65f53620
56 changed files with 55 additions and 389 deletions

48
src/Cargo.lock generated
View File

@ -1511,7 +1511,7 @@ dependencies = [
[[package]]
name = "rustc-ap-rustc_cratesio_shim"
version = "67.0.0"
version = "73.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1520,7 +1520,7 @@ dependencies = [
[[package]]
name = "rustc-ap-rustc_data_structures"
version = "67.0.0"
version = "73.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1528,20 +1528,20 @@ dependencies = [
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot_core 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-serialize 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-serialize 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-ap-rustc_errors"
version = "67.0.0"
version = "73.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"atty 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-rustc_data_structures 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-serialize 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-syntax_pos 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-rustc_data_structures 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-serialize 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-syntax_pos 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1549,32 +1549,32 @@ dependencies = [
[[package]]
name = "rustc-ap-serialize"
version = "67.0.0"
version = "73.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc-ap-syntax"
version = "67.0.0"
version = "73.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-rustc_cratesio_shim 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-rustc_data_structures 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-rustc_errors 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-serialize 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-syntax_pos 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-rustc_cratesio_shim 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-rustc_data_structures 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-rustc_errors 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-serialize 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-syntax_pos 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"scoped-tls 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-ap-syntax_pos"
version = "67.0.0"
version = "73.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rustc-ap-rustc_data_structures 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-serialize 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-rustc_data_structures 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-serialize 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"scoped-tls 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2009,7 +2009,7 @@ dependencies = [
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-syntax 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-ap-syntax 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2729,12 +2729,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum rls-rustc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "885f66b92757420572cbb02e033d4a9558c7413ca9b7ac206f28fd58ffdb44ea"
"checksum rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d7c7046dc6a92f2ae02ed302746db4382e75131b9ce20ce967259f6b5867a6a"
"checksum rls-vfs 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "be231e1e559c315bc60ced5ad2cc2d7a9c208ed7d4e2c126500149836fda19bb"
"checksum rustc-ap-rustc_cratesio_shim 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "adc16e4a6e50a4ffbd4633d737aedbdfcb565bdf658159e0544266908180a919"
"checksum rustc-ap-rustc_data_structures 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ec5f0a018fbec07f64b689ac20f7343ed77939055ca07d2aceb37c832245b1b"
"checksum rustc-ap-rustc_errors 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8301221cc07002666eed552a089b15000bc954c94b14a460c0653363a7f42f4c"
"checksum rustc-ap-serialize 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5212ee40fc332d791cacf202ae5fb99197341857c0a14bcdf60541fea7dfc5ed"
"checksum rustc-ap-syntax 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "168571b3878c6c61aef4bacef95c86d30fa61fb1cff04395d9535c80c196e559"
"checksum rustc-ap-syntax_pos 67.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cd7a0486f56db583caa665c8b4ff02c4774fe279db1741509437bc8a84c53361"
"checksum rustc-ap-rustc_cratesio_shim 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "421262e22426c06306e46057a75048f883dbc43886f78dbe1e750397a9c9b8e6"
"checksum rustc-ap-rustc_data_structures 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8460c1207f9abb48a9720aee8be418bcfac018b6eee7b740b98a410e7799d24a"
"checksum rustc-ap-rustc_errors 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad2077469162e52fcd84543334e18632088b9e342fe54e3b78c37d7077d09714"
"checksum rustc-ap-serialize 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "69943901ae255dca5f63faeae2ff08b402d34a56d1eb50d34fbff6e83e6ace60"
"checksum rustc-ap-syntax 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a44363359a43df753e26a4d4fef72720af183de635ebae8699686cb5d5de813"
"checksum rustc-ap-syntax_pos 73.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "413f464657e8d5f3864de308dba1867526f21a44809b6f338b34e8c0caf88fb0"
"checksum rustc-demangle 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11fb43a206a04116ffd7cfcf9bcb941f8eb6cc7ff667272246b0a1c74259a3cb"
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
"checksum same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cfb6eded0b06a0b512c8ddbcf04089138c9b4362c2f696f3c3d76039d68f3637"

View File

@ -1,58 +0,0 @@
# `match_default_bindings`
The tracking issue for this feature is: [#42640]
[#42640]: https://github.com/rust-lang/rust/issues/42640
------------------------
Match default bindings (also called "default binding modes in match") improves ergonomics for
pattern-matching on references by introducing automatic dereferencing (and a corresponding shift
in binding modes) for large classes of patterns that would otherwise not compile.
For example, under match default bindings,
```rust
#![feature(match_default_bindings)]
fn main() {
let x: &Option<_> = &Some(0);
match x {
Some(y) => {
println!("y={}", *y);
},
None => {},
}
}
```
compiles and is equivalent to either of the below:
```rust
fn main() {
let x: &Option<_> = &Some(0);
match *x {
Some(ref y) => {
println!("y={}", *y);
},
None => {},
}
}
```
or
```rust
fn main() {
let x: &Option<_> = &Some(0);
match x {
&Some(ref y) => {
println!("y={}", *y);
},
&None => {},
}
}
```

View File

@ -887,65 +887,6 @@ foo(3_i8);
// therefore the type-checker complains with this error code.
```
Here is a more subtle instance of the same problem, that can
arise with for-loops in Rust:
```compile_fail
let vs: Vec<i32> = vec![1, 2, 3, 4];
for v in &vs {
match v {
1 => {},
_ => {},
}
}
```
The above fails because of an analogous type mismatch,
though may be harder to see. Again, here are some
explanatory comments for the same example:
```compile_fail
{
let vs = vec![1, 2, 3, 4];
// `for`-loops use a protocol based on the `Iterator`
// trait. Each item yielded in a `for` loop has the
// type `Iterator::Item` -- that is, `Item` is the
// associated type of the concrete iterator impl.
for v in &vs {
// ~ ~~~
// | |
// | We borrow `vs`, iterating over a sequence of
// | *references* of type `&Elem` (where `Elem` is
// | vector's element type). Thus, the associated
// | type `Item` must be a reference `&`-type ...
// |
// ... and `v` has the type `Iterator::Item`, as dictated by
// the `for`-loop protocol ...
match v {
1 => {}
// ~
// |
// ... but *here*, `v` is forced to have some integral type;
// only types like `u8`,`i8`,`u16`,`i16`, et cetera can
// match the pattern `1` ...
_ => {}
}
// ... therefore, the compiler complains, because it sees
// an attempt to solve the equations
// `some integral-type` = type-of-`v`
// = `Iterator::Item`
// = `&Elem` (i.e. `some reference type`)
//
// which cannot possibly all be true.
}
}
```
To avoid those issues, you have to make the types match correctly.
So we can fix the previous examples like this:

View File

@ -55,7 +55,7 @@
#![cfg_attr(stage0, feature(i128_type, i128))]
#![cfg_attr(stage0, feature(inclusive_range_syntax))]
#![cfg_attr(windows, feature(libc))]
#![feature(match_default_bindings)]
#![cfg_attr(stage0, feature(match_default_bindings))]
#![feature(macro_lifetime_matcher)]
#![feature(macro_vis_matcher)]
#![feature(exhaustive_patterns)]

View File

@ -16,7 +16,7 @@
#![allow(non_camel_case_types)]
#![feature(from_ref)]
#![feature(match_default_bindings)]
#![cfg_attr(stage0, feature(match_default_bindings))]
#![feature(quote)]
#[macro_use] extern crate log;

View File

@ -30,7 +30,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
#![cfg_attr(stage0, feature(i128_type))]
#![cfg_attr(stage0, feature(inclusive_range_syntax))]
#![feature(macro_vis_matcher)]
#![feature(match_default_bindings)]
#![cfg_attr(stage0, feature(match_default_bindings))]
#![feature(exhaustive_patterns)]
#![feature(range_contains)]
#![feature(rustc_diagnostic_macros)]

View File

@ -14,7 +14,7 @@
#![deny(warnings)]
#![feature(crate_visibility_modifier)]
#![feature(match_default_bindings)]
#![cfg_attr(stage0, feature(match_default_bindings))]
#![feature(underscore_lifetimes)]
#[macro_use]

View File

@ -23,7 +23,6 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::cmp;
use syntax::ast;
use syntax::codemap::Spanned;
use syntax::feature_gate;
use syntax::ptr::P;
use syntax_pos::Span;
@ -114,42 +113,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
};
if pat_adjustments.len() > 0 {
if tcx.features().match_default_bindings {
debug!("default binding mode is now {:?}", def_bm);
self.inh.tables.borrow_mut()
.pat_adjustments_mut()
.insert(pat.hir_id, pat_adjustments);
} else {
let mut ref_sp = pat.span;
let mut id = pat.id;
loop { // make span include all enclosing `&` to avoid confusing diag output
id = tcx.hir.get_parent_node(id);
let node = tcx.hir.find(id);
if let Some(hir::map::NodePat(pat)) = node {
if let hir::PatKind::Ref(..) = pat.node {
ref_sp = pat.span;
} else {
break;
}
} else {
break;
}
}
let sp = ref_sp.to(pat.span);
let mut err = feature_gate::feature_err(
&tcx.sess.parse_sess,
"match_default_bindings",
sp,
feature_gate::GateIssue::Language,
"non-reference pattern used to match a reference",
);
if let Ok(snippet) = tcx.sess.codemap().span_to_snippet(sp) {
err.span_suggestion(sp,
"consider using a reference",
format!("&{}", &snippet));
}
err.emit();
}
debug!("default binding mode is now {:?}", def_bm);
self.inh.tables.borrow_mut()
.pat_adjustments_mut()
.insert(pat.hir_id, pat_adjustments);
}
} else if let PatKind::Ref(..) = pat.node {
// When you encounter a `&pat` pattern, reset to "by

View File

@ -79,7 +79,7 @@ This API is completely unstable and subject to change.
#![cfg_attr(stage0, feature(copy_closures, clone_closures))]
#![feature(crate_visibility_modifier)]
#![feature(from_ref)]
#![feature(match_default_bindings)]
#![cfg_attr(stage0, feature(match_default_bindings))]
#![feature(exhaustive_patterns)]
#![feature(option_filter)]
#![feature(quote)]

View File

@ -385,9 +385,6 @@ declare_features! (
// allow `'_` placeholder lifetimes
(active, underscore_lifetimes, "1.22.0", Some(44524), None),
// Default match binding modes (RFC 2005)
(active, match_default_bindings, "1.22.0", Some(42640), None),
// Trait object syntax with `dyn` prefix
(active, dyn_trait, "1.22.0", Some(44662), Some(Edition::Edition2018)),
@ -563,6 +560,8 @@ declare_features! (
(accepted, conservative_impl_trait, "1.26.0", Some(34511), None),
// The `i128` type
(accepted, i128_type, "1.26.0", Some(35118), None),
// Default match binding modes (RFC 2005)
(accepted, match_default_bindings, "1.26.0", Some(42640), None),
);
// If you change this, please modify src/doc/unstable-book as well. You must

View File

@ -22,7 +22,7 @@
#![feature(unicode)]
#![feature(rustc_diagnostic_macros)]
#![feature(match_default_bindings)]
#![cfg_attr(stage0, feature(match_default_bindings))]
#![feature(non_exhaustive)]
#![cfg_attr(stage0, feature(i128_type))]
#![feature(const_atomic_usize_new)]

View File

@ -17,5 +17,4 @@ fn main() {
let Slice { data: data, len: len } = "foo";
//~^ ERROR mismatched types
//~| found type `Slice<_>`
//~| ERROR non-reference pattern used to match a reference
}

View File

@ -11,7 +11,7 @@
fn main() {
// NB: this (almost) typechecks when default binding modes are enabled.
for (ref i,) in [].iter() {
//~^ ERROR non-reference pattern used to match a reference
i.clone();
//~^ ERROR type annotations needed
}
}

View File

@ -15,7 +15,6 @@ fn main() {
//~^^ ERROR only char and numeric types are allowed in range
//~| start type: &'static str
//~| end type: &'static str
//~| ERROR non-reference pattern used to match a reference
match "wow" {
10 ... "what" => ()
@ -23,7 +22,6 @@ fn main() {
//~^^ ERROR only char and numeric types are allowed in range
//~| start type: {integer}
//~| end type: &'static str
//~| ERROR non-reference pattern used to match a reference
match 5 {
'c' ... 100 => { }

View File

@ -19,7 +19,7 @@ fn main() {
// Note that this one works with default binding modes.
match &[0, 1, 2] {
[..] => {} //~ ERROR non-reference pattern used to match a reference
[..] => {}
};
match &[0, 1, 2] {

View File

@ -14,7 +14,6 @@
// `x`. The lexical checker makes this very painful. The NLL checker
// does not.
#![feature(match_default_bindings)]
#![feature(nll)]
use std::rc::Rc;

View File

@ -9,7 +9,6 @@
// except according to those terms.
#![feature(box_syntax, box_patterns)]
#![feature(match_default_bindings)]
struct Foo{}

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
const CONST_REF: &[u8; 3] = b"foo";
trait Foo {

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
enum Wrapper {
Wrap(i32),
}

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
pub fn main() {
let mut tups = vec![(0u8, 1u8)];

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
fn some_or_wildcard(r: &Option<i32>, b: &i32) {
let _: &i32 = match r {
Some(a) => a,

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
fn with_u8() {
let s = 5u8;
let r = match &s {

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
pub fn main() {
let i = 5;
match &&&&i {

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
fn foo<'a, 'b>(x: &'a &'b Option<u32>) -> &'a u32 {
let x: &'a &'a Option<u32> = x;
match x {

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
// Test that we "reset" the mode as we pass through a `&` pattern.
//
// cc #46688

View File

@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
#![feature(slice_patterns)]
fn slice_pat() {

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
#[derive(Debug, PartialEq)]
struct Foo {
x: u8,

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
enum Foo {
Bar(Option<i8>, (), (), Vec<i32>),
Baz,

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
pub fn main() {
let foo = (Some(1), (), (), vec![2, 3]);

View File

@ -16,7 +16,6 @@ fn main() {
match s {
"hello" ... "world" => {}
//~^ ERROR only char and numeric types are allowed in range patterns
//~| ERROR non-reference pattern used to match a reference
_ => {}
}
}

View File

@ -1,11 +1,3 @@
error[E0658]: non-reference pattern used to match a reference (see issue #42640)
--> $DIR/E0029-teach.rs:17:9
|
LL | "hello" ... "world" => {}
| ^^^^^^^^^^^^^^^^^^^ help: consider using a reference: `&"hello" ... "world"`
|
= help: add #![feature(match_default_bindings)] to the crate attributes to enable
error[E0029]: only char and numeric types are allowed in range patterns
--> $DIR/E0029-teach.rs:17:9
|
@ -16,7 +8,6 @@ LL | "hello" ... "world" => {}
= note: end type: &'static str
= note: In a match expression, only numbers and characters can be matched against a range. This is because the compiler checks that the range is non-empty at compile-time, and is unable to evaluate arbitrary comparison functions. If you want to capture values of an orderable type between two end-points, you can use a guard.
error: aborting due to 2 previous errors
error: aborting due to previous error
Some errors occurred: E0029, E0658.
For more information about an error, try `rustc --explain E0029`.
For more information about this error, try `rustc --explain E0029`.

View File

@ -14,7 +14,6 @@ fn main() {
match s {
"hello" ... "world" => {}
//~^ ERROR only char and numeric types are allowed in range patterns
//~| ERROR non-reference pattern used to match a reference
_ => {}
}
}

View File

@ -1,11 +1,3 @@
error[E0658]: non-reference pattern used to match a reference (see issue #42640)
--> $DIR/E0029.rs:15:9
|
LL | "hello" ... "world" => {}
| ^^^^^^^^^^^^^^^^^^^ help: consider using a reference: `&"hello" ... "world"`
|
= help: add #![feature(match_default_bindings)] to the crate attributes to enable
error[E0029]: only char and numeric types are allowed in range patterns
--> $DIR/E0029.rs:15:9
|
@ -15,7 +7,6 @@ LL | "hello" ... "world" => {}
= note: start type: &'static str
= note: end type: &'static str
error: aborting due to 2 previous errors
error: aborting due to previous error
Some errors occurred: E0029, E0658.
For more information about an error, try `rustc --explain E0029`.
For more information about this error, try `rustc --explain E0029`.

View File

@ -1,17 +0,0 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub fn main() {
match &Some(3) {
Some(n) => {},
//~^ ERROR non-reference pattern used to match a reference
_ => panic!(),
}
}

View File

@ -1,11 +0,0 @@
error[E0658]: non-reference pattern used to match a reference (see issue #42640)
--> $DIR/feature-gate-match_default_bindings.rs:13:9
|
LL | Some(n) => {},
| ^^^^^^^ help: consider using a reference: `&Some(n)`
|
= help: add #![feature(match_default_bindings)] to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View File

@ -1,27 +0,0 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// NB: this test was introduced in #23121 and will have to change when default match binding modes
// stabilizes.
#![feature(slice_patterns)]
fn slice_pat(x: &[u8]) {
// OLD!
match x {
[a, b..] => {},
//~^ ERROR non-reference pattern used to match a reference
_ => panic!(),
}
}
fn main() {
slice_pat("foo".as_bytes());
}

View File

@ -1,11 +0,0 @@
error[E0658]: non-reference pattern used to match a reference (see issue #42640)
--> $DIR/pat-slice-old-style.rs:19:9
|
LL | [a, b..] => {},
| ^^^^^^^^ help: consider using a reference: `&[a, b..]`
|
= help: add #![feature(match_default_bindings)] to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View File

@ -10,8 +10,6 @@
// FIXME(tschottdorf): this test should pass.
#![feature(match_default_bindings)]
#[derive(PartialEq, Eq)]
struct Foo {
bar: i32,

View File

@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/const.rs:26:9
--> $DIR/const.rs:24:9
|
LL | FOO => {}, //~ ERROR mismatched types
| ^^^ expected &Foo, found struct `Foo`

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
enum Wrapper {
Wrap(i32),
}

View File

@ -1,5 +1,5 @@
error[E0594]: cannot assign to immutable borrowed content `*x`
--> $DIR/enum.rs:21:5
--> $DIR/enum.rs:19:5
|
LL | let Wrap(x) = &Wrap(3);
| - consider changing this to `x`
@ -7,7 +7,7 @@ LL | *x += 1; //~ ERROR cannot assign to immutable
| ^^^^^^^ cannot borrow as mutable
error[E0594]: cannot assign to immutable borrowed content `*x`
--> $DIR/enum.rs:25:9
--> $DIR/enum.rs:23:9
|
LL | if let Some(x) = &Some(3) {
| - consider changing this to `x`
@ -15,7 +15,7 @@ LL | *x += 1; //~ ERROR cannot assign to immutable
| ^^^^^^^ cannot borrow as mutable
error[E0594]: cannot assign to immutable borrowed content `*x`
--> $DIR/enum.rs:31:9
--> $DIR/enum.rs:29:9
|
LL | while let Some(x) = &Some(3) {
| - consider changing this to `x`

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
// Verify the binding mode shifts - only when no `&` are auto-dereferenced is the
// final default binding mode mutable.

View File

@ -1,5 +1,5 @@
error[E0594]: cannot assign to immutable borrowed content `*n`
--> $DIR/explicit-mut.rs:19:13
--> $DIR/explicit-mut.rs:17:13
|
LL | Some(n) => {
| - consider changing this to `n`
@ -7,7 +7,7 @@ LL | *n += 1; //~ ERROR cannot assign to immutable
| ^^^^^^^ cannot borrow as mutable
error[E0594]: cannot assign to immutable borrowed content `*n`
--> $DIR/explicit-mut.rs:27:13
--> $DIR/explicit-mut.rs:25:13
|
LL | Some(n) => {
| - consider changing this to `n`
@ -15,7 +15,7 @@ LL | *n += 1; //~ ERROR cannot assign to immutable
| ^^^^^^^ cannot borrow as mutable
error[E0594]: cannot assign to immutable borrowed content `*n`
--> $DIR/explicit-mut.rs:35:13
--> $DIR/explicit-mut.rs:33:13
|
LL | Some(n) => {
| - consider changing this to `n`

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
struct Foo {}
pub fn main() {

View File

@ -1,5 +1,5 @@
error[E0009]: cannot bind by-move and by-ref in the same pattern
--> $DIR/for.rs:18:13
--> $DIR/for.rs:16:13
|
LL | for (n, mut m) in &tups {
| - ^^^^^ by-move pattern here

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
// FIXME(tschottdorf): This should compile. See #44912.
pub fn main() {

View File

@ -1,5 +1,5 @@
error[E0409]: variable `x` is bound in inconsistent ways within the same match arm
--> $DIR/issue-44912-or.rs:18:35
--> $DIR/issue-44912-or.rs:16:35
|
LL | Some((x, 3)) | &Some((ref x, 5)) => x,
| - first binding ^ bound in different ways

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
// FIXME(tschottdorf): we want these to compile, but they don't.
fn with_str() {

View File

@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/lit.rs:19:13
--> $DIR/lit.rs:17:13
|
LL | "abc" => true, //~ ERROR mismatched types
| ^^^^^ expected &str, found str
@ -8,7 +8,7 @@ LL | "abc" => true, //~ ERROR mismatched types
found type `&'static str`
error[E0308]: mismatched types
--> $DIR/lit.rs:28:9
--> $DIR/lit.rs:26:9
|
LL | b"abc" => true, //~ ERROR mismatched types
| ^^^^^^ expected &[u8], found array of 3 elements

View File

@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(match_default_bindings)]
#![feature(slice_patterns)]
pub fn main() {

View File

@ -1,5 +1,5 @@
error[E0004]: non-exhaustive patterns: `&[]` not covered
--> $DIR/slice.rs:17:11
--> $DIR/slice.rs:16:11
|
LL | match sl { //~ ERROR non-exhaustive patterns
| ^^ pattern `&[]` not covered

View File

@ -1,15 +0,0 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
if let Some(y) = &Some(22) { //~ ERROR non-reference pattern
println!("{}", y);
}
}

View File

@ -1,11 +0,0 @@
error[E0658]: non-reference pattern used to match a reference (see issue #42640)
--> $DIR/suggestion.rs:12:12
|
LL | if let Some(y) = &Some(22) { //~ ERROR non-reference pattern
| ^^^^^^^ help: consider using a reference: `&Some(y)`
|
= help: add #![feature(match_default_bindings)] to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View File

@ -1,19 +0,0 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn foo(s: &str) -> bool { true }
fn main() {
let x = vec![(String::new(), String::new())];
x.iter()
.filter(|&(ref a, _)| foo(a))
//~^ ERROR non-reference pattern used to match a reference
.collect();
}

View File

@ -1,11 +0,0 @@
error[E0658]: non-reference pattern used to match a reference (see issue #42640)
--> $DIR/dont-suggest-dereference-on-arg.rs:16:18
|
LL | .filter(|&(ref a, _)| foo(a))
| ^^^^^^^^^^^ help: consider using a reference: `&&(ref a, _)`
|
= help: add #![feature(match_default_bindings)] to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

@ -1 +1 @@
Subproject commit 374dba833e22cc8df8e16e19cccbde61c69d9aed
Subproject commit a4462d18bf6b92aaec1eeb1c30d5ddf94a3ca987