Skip to content

Commit b2100cc

Browse files
committed
fix damage in librustc
1 parent 8ac3b46 commit b2100cc

File tree

7 files changed

+53
-31
lines changed

7 files changed

+53
-31
lines changed

src/librustc/ty/layout.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use session::Session;
1717
use traits;
1818
use ty::{self, Ty, TyCtxt, TypeFoldable};
1919

20+
use util::common::slice_pat;
21+
2022
use syntax::ast::{FloatTy, IntTy, UintTy};
2123
use syntax::attr;
2224
use syntax::codemap::DUMMY_SP;
@@ -98,17 +100,17 @@ impl TargetDataLayout {
98100

99101
let mut dl = TargetDataLayout::default();
100102
for spec in sess.target.target.data_layout.split("-") {
101-
match &spec.split(":").collect::<Vec<_>>()[..] {
102-
["e"] => dl.endian = Endian::Little,
103-
["E"] => dl.endian = Endian::Big,
104-
["a", a..] => dl.aggregate_align = align(a, "a"),
105-
["f32", a..] => dl.f32_align = align(a, "f32"),
106-
["f64", a..] => dl.f64_align = align(a, "f64"),
107-
[p @ "p", s, a..] | [p @ "p0", s, a..] => {
103+
match slice_pat(&&spec.split(":").collect::<Vec<_>>()[..]) {
104+
&["e"] => dl.endian = Endian::Little,
105+
&["E"] => dl.endian = Endian::Big,
106+
&["a", ref a..] => dl.aggregate_align = align(a, "a"),
107+
&["f32", ref a..] => dl.f32_align = align(a, "f32"),
108+
&["f64", ref a..] => dl.f64_align = align(a, "f64"),
109+
&[p @ "p", s, ref a..] | &[p @ "p0", s, ref a..] => {
108110
dl.pointer_size = size(s, p);
109111
dl.pointer_align = align(a, p);
110112
}
111-
[s, a..] if s.starts_with("i") => {
113+
&[s, ref a..] if s.starts_with("i") => {
112114
let ty_align = match s[1..].parse::<u64>() {
113115
Ok(1) => &mut dl.i8_align,
114116
Ok(8) => &mut dl.i8_align,
@@ -123,7 +125,7 @@ impl TargetDataLayout {
123125
};
124126
*ty_align = align(a, s);
125127
}
126-
[s, a..] if s.starts_with("v") => {
128+
&[s, ref a..] if s.starts_with("v") => {
127129
let v_size = size(&s[1..], "v");
128130
let a = align(a, s);
129131
if let Some(v) = dl.vector_align.iter_mut().find(|v| v.0 == v_size) {

src/librustc/util/common.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,15 @@ pub fn path2cstr(p: &Path) -> CString {
247247
pub fn path2cstr(p: &Path) -> CString {
248248
CString::new(p.to_str().unwrap()).unwrap()
249249
}
250+
251+
// FIXME(stage0): remove this
252+
// HACK: this is needed because the interpretation of slice
253+
// patterns changed between stage0 and now.
254+
#[cfg(stage0)]
255+
pub fn slice_pat<'a, 'b, T>(t: &'a &'b [T]) -> &'a &'b [T] {
256+
t
257+
}
258+
#[cfg(not(stage0))]
259+
pub fn slice_pat<'a, 'b, T>(t: &'a &'b [T]) -> &'b [T] {
260+
*t
261+
}

src/librustc_const_eval/check_match.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use rustc::hir::fold::{Folder, noop_fold_pat};
4242
use rustc::hir::print::pat_to_string;
4343
use syntax::ptr::P;
4444
use rustc::util::nodemap::FnvHashMap;
45+
use rustc::util::common::slice_pat;
4546

4647
pub const DUMMY_WILD_PAT: &'static Pat = &Pat {
4748
id: DUMMY_NODE_ID,
@@ -401,8 +402,8 @@ fn check_exhaustive<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>,
401402
hir::MatchSource::ForLoopDesugar => {
402403
// `witnesses[0]` has the form `Some(<head>)`, peel off the `Some`
403404
let witness = match witnesses[0].node {
404-
PatKind::TupleStruct(_, ref pats, _) => match &pats[..] {
405-
[ref pat] => &**pat,
405+
PatKind::TupleStruct(_, ref pats, _) => match slice_pat(&&pats[..]) {
406+
&[ref pat] => &**pat,
406407
_ => bug!(),
407408
},
408409
_ => bug!(),

src/librustc_lint/types.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc::ty::{self, Ty, TyCtxt};
1616
use middle::const_val::ConstVal;
1717
use rustc_const_eval::eval_const_expr_partial;
1818
use rustc_const_eval::EvalHint::ExprTypeChecked;
19+
use util::common::slice_pat;
1920
use util::nodemap::{FnvHashSet};
2021
use lint::{LateContext, LintContext, LintArray};
2122
use lint::{LintPass, LateLintPass};
@@ -459,8 +460,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
459460
// Check for a repr() attribute to specify the size of the
460461
// discriminant.
461462
let repr_hints = cx.lookup_repr_hints(def.did);
462-
match &**repr_hints {
463-
[] => {
463+
match slice_pat(&&**repr_hints) {
464+
&[] => {
464465
// Special-case types like `Option<extern fn()>`.
465466
if !is_repr_nullable_ptr(cx, def, substs) {
466467
return FfiUnsafe(
@@ -470,7 +471,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
470471
the type")
471472
}
472473
}
473-
[ref hint] => {
474+
&[ref hint] => {
474475
if !hint.is_ffi_safe() {
475476
// FIXME: This shouldn't be reachable: we should check
476477
// this earlier.

src/librustc_mir/build/matches/mod.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -432,17 +432,18 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
432432
/// apply to. The classical example involves wildcards:
433433
///
434434
/// ```rust,ignore
435-
/// match (x, y) {
436-
/// (true, _) => true, // (0)
437-
/// (_, true) => true, // (1)
438-
/// (false, false) => false // (2)
435+
/// match (x, y, z) {
436+
/// (true, _, true) => true, // (0)
437+
/// (_, true, _) => true, // (1)
438+
/// (false, false, _) => false, // (2)
439+
/// (true, _, false) => false, // (3)
439440
/// }
440441
/// ```
441442
///
442443
/// In that case, after we test on `x`, there are 2 overlapping candidate
443444
/// sets:
444445
///
445-
/// - If the outcome is that `x` is true, candidates 0 and 2
446+
/// - If the outcome is that `x` is true, candidates 0, 1, and 3
446447
/// - If the outcome is that `x` is false, candidates 1 and 2
447448
///
448449
/// Here, the traditional "decision tree" method would generate 2
@@ -481,11 +482,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
481482
/// ```
482483
///
483484
/// Here we first test the match-pair `x @ "foo"`, which is an `Eq` test.
484-
/// It might seem that we would end up with 2 disjoint candidate sets,
485-
/// consisting of the first candidate or the other 3, but our algorithm
486-
/// doesn't reason about "foo" being distinct from the other constants,
487-
/// it considers to latter arms to potentially match after both outcomes,
488-
/// which obviously leads to an exponential amount of tests.
485+
///
486+
/// It might seem that we would end up with 2 disjoint candidate
487+
/// sets, consisting of the first candidate or the other 3, but our
488+
/// algorithm doesn't reason about "foo" being distinct from the other
489+
/// constants; it considers the latter arms to potentially match after
490+
/// both outcomes, which obviously leads to an exponential amount
491+
/// of tests.
492+
///
489493
/// To avoid these kinds of problems, our algorithm tries to ensure
490494
/// the amount of generated tests is linear. When we do a k-way test,
491495
/// we return an additional "unmatched" set alongside the obvious `k`

src/librustdoc/clean/inline.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc::hir::def_id::DefId;
2222
use rustc::hir::print as pprust;
2323
use rustc::ty::{self, TyCtxt};
2424
use rustc::ty::subst;
25+
use rustc::util::common::slice_pat;
2526

2627
use rustc_const_eval::lookup_const_by_id;
2728

@@ -197,10 +198,10 @@ fn build_struct<'a, 'tcx>(cx: &DocContext, tcx: TyCtxt<'a, 'tcx, 'tcx>,
197198
let variant = tcx.lookup_adt_def(did).struct_variant();
198199

199200
clean::Struct {
200-
struct_type: match &*variant.fields {
201-
[] => doctree::Unit,
202-
[_] if variant.kind == ty::VariantKind::Tuple => doctree::Newtype,
203-
[..] if variant.kind == ty::VariantKind::Tuple => doctree::Tuple,
201+
struct_type: match slice_pat(&&*variant.fields) {
202+
&[] => doctree::Unit,
203+
&[_] if variant.kind == ty::VariantKind::Tuple => doctree::Newtype,
204+
&[..] if variant.kind == ty::VariantKind::Tuple => doctree::Tuple,
204205
_ => doctree::Plain,
205206
},
206207
generics: (&t.generics, &predicates, subst::TypeSpace).clean(cx),

src/librustdoc/html/format.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::iter::repeat;
2020

2121
use rustc::middle::cstore::LOCAL_CRATE;
2222
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
23+
use rustc::util::common::slice_pat;
2324
use syntax::abi::Abi;
2425
use rustc::hir;
2526

@@ -474,9 +475,9 @@ impl fmt::Display for clean::Type {
474475
decl.decl)
475476
}
476477
clean::Tuple(ref typs) => {
477-
match &**typs {
478-
[] => primitive_link(f, clean::PrimitiveTuple, "()"),
479-
[ref one] => {
478+
match slice_pat(&&**typs) {
479+
&[] => primitive_link(f, clean::PrimitiveTuple, "()"),
480+
&[ref one] => {
480481
primitive_link(f, clean::PrimitiveTuple, "(")?;
481482
write!(f, "{},", one)?;
482483
primitive_link(f, clean::PrimitiveTuple, ")")

0 commit comments

Comments
 (0)