From 787feaad4b9d03805e2e6aa5a4266cbd5b140f85 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 28 Sep 2016 18:22:53 +0200 Subject: [PATCH] allow tuple field indexing into anonymous tuples --- src/interpreter/mod.rs | 9 +++- .../send-is-not-static-par-for.rs | 43 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/compile-fail/send-is-not-static-par-for.rs diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index c9d18507337..70b7806706f 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -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; diff --git a/tests/compile-fail/send-is-not-static-par-for.rs b/tests/compile-fail/send-is-not-static-par-for.rs new file mode 100644 index 00000000000..bee05ecd7fa --- /dev/null +++ b/tests/compile-fail/send-is-not-static-par-for.rs @@ -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 or the MIT license +// , 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(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) +}