Only borrow place for matching under specific conditions
This commit is contained in:
parent
685a4c6b6b
commit
74fc64303f
11 changed files with 193 additions and 49 deletions
|
|
@ -0,0 +1,24 @@
|
|||
//check-pass
|
||||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
#![warn(unused)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(btree_drain_filter)]
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::panic::{catch_unwind, AssertUnwindSafe};
|
||||
|
||||
fn main() {
|
||||
let mut map = BTreeMap::new();
|
||||
map.insert("a", ());
|
||||
map.insert("b", ());
|
||||
map.insert("c", ());
|
||||
|
||||
{
|
||||
let mut it = map.drain_filter(|_, _| true);
|
||||
catch_unwind(AssertUnwindSafe(|| while it.next().is_some() {})).unwrap_err();
|
||||
let result = catch_unwind(AssertUnwindSafe(|| it.next()));
|
||||
assert!(matches!(result, Ok(None)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/lit-pattern-matching-with-methods.rs:2:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
//check-pass
|
||||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
#![warn(unused)]
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
enum PointType {
|
||||
TwoD { x: u32, y: u32 },
|
||||
|
||||
ThreeD{ x: u32, y: u32, z: u32 }
|
||||
}
|
||||
|
||||
struct Points {
|
||||
points: Vec<PointType>,
|
||||
}
|
||||
|
||||
impl Points {
|
||||
pub fn test1(&mut self) -> Vec<usize> {
|
||||
(0..self.points.len())
|
||||
.filter_map(|i| {
|
||||
let idx = i as usize;
|
||||
match self.test2(idx) {
|
||||
PointType::TwoD { .. } => Some(i),
|
||||
PointType::ThreeD { .. } => None,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn test2(&mut self, i: usize) -> PointType {
|
||||
self.points[i]
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut points = Points {
|
||||
points: Vec::<PointType>::new()
|
||||
};
|
||||
|
||||
points.points.push(PointType::ThreeD { x:0, y:0, z:0 });
|
||||
points.points.push(PointType::TwoD{ x:0, y:0 });
|
||||
points.points.push(PointType::ThreeD{ x:0, y:0, z:0 });
|
||||
points.points.push(PointType::TwoD{ x:0, y:0 });
|
||||
|
||||
println!("{:?}", points.test1());
|
||||
println!("{:?}", points.points);
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/struct-pattern-matching-with-methods.rs:2:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
//check-pass
|
||||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
enum PointType {
|
||||
TwoD(u32, u32),
|
||||
ThreeD(u32, u32, u32)
|
||||
}
|
||||
|
||||
struct Points {
|
||||
points: Vec<PointType>,
|
||||
}
|
||||
|
||||
impl Points {
|
||||
pub fn test1(&mut self) -> Vec<usize> {
|
||||
(0..self.points.len())
|
||||
.filter_map(|i| {
|
||||
match self.test2(i) {
|
||||
PointType::TwoD (..) => Some(i),
|
||||
PointType::ThreeD (..) => None,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn test2(&mut self, i: usize) -> PointType {
|
||||
self.points[i]
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut points = Points {
|
||||
points: Vec::<PointType>::new()
|
||||
};
|
||||
|
||||
points.points.push(PointType::ThreeD(0,0,0));
|
||||
points.points.push(PointType::TwoD(0,0));
|
||||
points.points.push(PointType::ThreeD(0,0,1));
|
||||
points.points.push(PointType::TwoD(0,1));
|
||||
|
||||
println!("{:?}", points.test1());
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/tuple-struct-pattern-matching-with-methods.rs:2:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue