allow tuple field indexing into anonymous tuples
This commit is contained in:
parent
51abf19e12
commit
787feaad4b
@ -1,5 +1,6 @@
|
||||
use rustc::middle::const_val::ConstVal;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::map::definitions::DefPathData;
|
||||
use rustc::mir::mir_map::MirMap;
|
||||
use rustc::mir::repr as mir;
|
||||
use rustc::traits::Reveal;
|
||||
@ -712,13 +713,15 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||
Ok(adt_def.struct_variant().fields[field_index].ty(self.tcx, substs))
|
||||
}
|
||||
|
||||
ty::TyTuple(fields) => Ok(fields[field_index]),
|
||||
|
||||
ty::TyRef(_, ty::TypeAndMut { ty, .. }) |
|
||||
ty::TyRawPtr(ty::TypeAndMut { ty, .. }) |
|
||||
ty::TyBox(ty) => {
|
||||
assert_eq!(field_index, 0);
|
||||
Ok(ty)
|
||||
}
|
||||
_ => Err(EvalError::Unimplemented(format!("can't handle type: {:?}", ty))),
|
||||
_ => Err(EvalError::Unimplemented(format!("can't handle type: {:?}, {:?}", ty, ty.sty))),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1255,6 +1258,10 @@ fn report(tcx: TyCtxt, ecx: &EvalContext, e: EvalError) {
|
||||
};
|
||||
let mut err = tcx.sess.struct_span_err(span, &e.to_string());
|
||||
for &Frame { def_id, substs, span, .. } in ecx.stack().iter().rev() {
|
||||
if tcx.def_key(def_id).disambiguated_data.data == DefPathData::ClosureExpr {
|
||||
err.span_note(span, "inside call to closure");
|
||||
continue;
|
||||
}
|
||||
// FIXME(solson): Find a way to do this without this Display impl hack.
|
||||
use rustc::util::ppaux;
|
||||
use std::fmt;
|
||||
|
43
tests/compile-fail/send-is-not-static-par-for.rs
Normal file
43
tests/compile-fail/send-is-not-static-par-for.rs
Normal file
@ -0,0 +1,43 @@
|
||||
// Copyright 2015 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.
|
||||
|
||||
//error-pattern: no mir for `std::panicking::panicking`
|
||||
|
||||
use std::sync::Mutex;
|
||||
|
||||
fn par_for<I, F>(iter: I, f: F)
|
||||
where I: Iterator,
|
||||
I::Item: Send,
|
||||
F: Fn(I::Item) + Sync
|
||||
{
|
||||
for item in iter {
|
||||
f(item)
|
||||
}
|
||||
}
|
||||
|
||||
fn sum(x: &[i32]) {
|
||||
let sum_lengths = Mutex::new(0);
|
||||
par_for(x.windows(4), |x| {
|
||||
*sum_lengths.lock().unwrap() += x.len()
|
||||
});
|
||||
|
||||
assert_eq!(*sum_lengths.lock().unwrap(), (x.len() - 3) * 4);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut elements = [0; 20];
|
||||
|
||||
// iterators over references into this stack frame
|
||||
par_for(elements.iter_mut().enumerate(), |(i, x)| {
|
||||
*x = i as i32
|
||||
});
|
||||
|
||||
sum(&elements)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user