Skip to content

Commit 878d2ae

Browse files
committed
---
yaml --- r: 174425 b: refs/heads/auto c: a87e04c68ab5d29336427e80555fd4711d04d2ce h: refs/heads/master i: 174423: 8f023d6 v: v3
1 parent 7823ab0 commit 878d2ae

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: fd488c1d3c7f330e22385a739d7271c457ada620
13+
refs/heads/auto: a87e04c68ab5d29336427e80555fd4711d04d2ce
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/librustc/middle/check_match.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub const DUMMY_WILD_PAT: &'static Pat = &Pat {
4343
span: DUMMY_SP
4444
};
4545

46-
struct Matrix<'a>(Vec<Vec<&'a Pat>>);
46+
pub struct Matrix<'a>(pub Vec<Vec<&'a Pat>>);
4747

4848
/// Pretty-printer for matrices of patterns, example:
4949
/// ++++++++++++++++++++++++++
@@ -120,14 +120,14 @@ pub enum Constructor {
120120
}
121121

122122
#[derive(Clone, PartialEq)]
123-
enum Usefulness {
123+
pub enum Usefulness {
124124
Useful,
125125
UsefulWithWitness(Vec<P<Pat>>),
126126
NotUseful
127127
}
128128

129129
#[derive(Copy)]
130-
enum WitnessPreference {
130+
pub enum WitnessPreference {
131131
ConstructWitness,
132132
LeaveOutWitness
133133
}
@@ -568,11 +568,11 @@ fn all_constructors(cx: &MatchCheckCtxt, left_ty: Ty,
568568

569569
// Note: is_useful doesn't work on empty types, as the paper notes.
570570
// So it assumes that v is non-empty.
571-
fn is_useful(cx: &MatchCheckCtxt,
572-
matrix: &Matrix,
573-
v: &[&Pat],
574-
witness: WitnessPreference)
575-
-> Usefulness {
571+
pub fn is_useful(cx: &MatchCheckCtxt,
572+
matrix: &Matrix,
573+
v: &[&Pat],
574+
witness: WitnessPreference)
575+
-> Usefulness {
576576
let &Matrix(ref rows) = matrix;
577577
debug!("{:?}", matrix);
578578
if rows.len() == 0u {

branches/auto/src/librustc_trans/trans/_match.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ use self::FailureHandler::*;
191191
use back::abi;
192192
use llvm::{ValueRef, BasicBlockRef};
193193
use middle::check_match::StaticInliner;
194+
use middle::check_match::Usefulness::NotUseful;
195+
use middle::check_match::WitnessPreference::LeaveOutWitness;
194196
use middle::check_match;
195197
use middle::const_eval;
196198
use middle::def::{self, DefMap};
@@ -1417,22 +1419,27 @@ fn trans_match_inner<'blk, 'tcx>(scope_cx: Block<'blk, 'tcx>,
14171419

14181420
// `compile_submatch` works one column of arm patterns a time and
14191421
// then peels that column off. So as we progress, it may become
1420-
// impossible to tell whether we have a genuine default arm, i.e.
1421-
// _ => foo
1422-
// (_, _) => foo
1423-
// or not. Sometimes it is important to know that in order to decide
1424-
// whether moving on to the next arm or falling back to the default
1425-
// one.
1426-
fn all_wild_pat(pat: &ast::Pat) -> bool {
1427-
match pat.node {
1428-
ast::PatWild(ast::PatWildSingle) => true,
1429-
ast::PatTup(ref pats) => pats.iter().all(|p| all_wild_pat(&**p)),
1430-
_ => false,
1422+
// impossible to tell whether we have a genuine default arm or not.
1423+
// Computing such property upfront, however, is straightforward -
1424+
// if the last arm of the match expression shadows a `PatWildSingle`,
1425+
// then it is a genuine default arm.
1426+
//
1427+
// Sometimes it is important to know that in order to decide whether
1428+
// moving on to the next arm or falling back to the default one.
1429+
let is_geniune_default = |&: pats: &Vec<P<ast::Pat>>| {
1430+
let mcx = check_match::MatchCheckCtxt {
1431+
tcx: tcx,
1432+
param_env: ty::empty_parameter_environment(tcx),
1433+
};
1434+
let ps = pats.iter().map(|p| &**p).collect();
1435+
let matrix = check_match::Matrix(vec![ps]);
1436+
let candidate = [check_match::DUMMY_WILD_PAT];
1437+
match check_match::is_useful(&mcx, &matrix, &candidate, LeaveOutWitness) {
1438+
NotUseful => true,
1439+
_ => false
14311440
}
1432-
}
1433-
let has_default = arms.last().map_or(false, |arm| {
1434-
arm.pats.len() == 1 && all_wild_pat(&**arm.pats.last().unwrap())
1435-
});
1441+
};
1442+
let has_default = arm_pats.iter().last().map_or(false, is_geniune_default);
14361443

14371444
compile_submatch(bcx, &matches[], &[discr_datum.val], &chk, has_default);
14381445

0 commit comments

Comments
 (0)