use rustc::mir::tcx::LvalueTy;
use rustc::ty::{self, layout, Ty, TyCtxt, TypeFoldable};
use rustc::ty::cast::{CastTy, IntTy};
-use rustc::ty::subst::Substs;
+use rustc::ty::subst::{Kind, Substs};
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
use {abi, adt, base, Disr, machine};
use callee::Callee;
.unwrap().def_id;
// Now create its substs [Closure, Tuple]
let input = tcx.closure_type(def_id, substs).sig.input(0);
- let substs = Substs::for_item(tcx,
- call_once,
- |_, _| {bug!()},
- |def, _| { match def.index {
- 0 => operand.ty.clone(),
- 1 => input.skip_binder(),
- _ => bug!(),
- } }
- );
-
+ let substs = tcx.mk_substs([operand.ty, input.skip_binder()]
+ .iter().cloned().map(Kind::from));
Callee::def(self.ccx, call_once, substs)
.reify(self.ccx)
}
use rustc::ty::{self, Ty};
use rustc::ty::cast::{CastTy, IntTy};
use rustc::ty::layout::Layout;
-use rustc::ty::subst::Substs;
+use rustc::ty::subst::Kind;
use rustc::mir::tcx::LvalueTy;
use rustc::mir;
use middle::lang_items::ExchangeMallocFnLangItem;
.unwrap().def_id;
// Now create its substs [Closure, Tuple]
let input = bcx.tcx().closure_type(def_id, substs).sig.input(0);
- let substs = Substs::for_item(bcx.tcx(),
- call_once,
- |_, _| {bug!()},
- |def, _| { match def.index {
- 0 => operand.ty.clone(),
- 1 => input.skip_binder(),
- _ => bug!(),
- } }
- );
-
+ let substs = bcx.tcx().mk_substs([operand.ty, input.skip_binder()]
+ .iter().cloned().map(Kind::from));
OperandValue::Immediate(
Callee::def(bcx.ccx, call_once, substs)
.reify(bcx.ccx))
use rustc::infer::{Coercion, InferOk, TypeTrace};
use rustc::traits::{self, ObligationCause, ObligationCauseCode};
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow};
-use rustc::ty::{self, LvaluePreference, TypeVariants, TypeAndMut,
+use rustc::ty::{self, LvaluePreference, TypeAndMut,
Ty, ClosureSubsts};
use rustc::ty::fold::TypeFoldable;
use rustc::ty::error::TypeError;
use rustc::ty::relate::RelateResult;
-use syntax::ast::NodeId;
use syntax::abi;
use syntax::feature_gate;
use util::common::indent;
let b = self.shallow_resolve(b);
- let node_id_a :NodeId = self.tcx.hir.as_local_node_id(def_id_a).unwrap();
+ let node_id_a = self.tcx.hir.as_local_node_id(def_id_a).unwrap();
match b.sty {
ty::TyFnPtr(_) if self.tcx.with_freevars(node_id_a, |v| v.is_empty()) => {
if !self.tcx.sess.features.borrow().closure_to_fn_coercion {
// to
// `fn(arg0,arg1,...) -> _`
let sig = self.closure_type(def_id_a, substs_a).sig;
- let converted_sig = sig.input(0).map_bound(|v| {
- let params_iter = match v.sty {
- TypeVariants::TyTuple(params, _) => {
+ let converted_sig = sig.map_bound(|s| {
+ let params_iter = match s.inputs()[0].sty {
+ ty::TyTuple(params, _) => {
params.into_iter().cloned()
}
_ => bug!(),
};
self.tcx.mk_fn_sig(params_iter,
- sig.output().skip_binder(),
- sig.variadic())
+ s.output(),
+ s.variadic)
});
let fn_ty = self.tcx.mk_bare_fn(ty::BareFnTy {
unsafety: hir::Unsafety::Normal,
fn main() {
let mut a = 0u8;
- let foo :fn(u8) -> u8 = |v: u8| { a += v; a };
+ let foo: fn(u8) -> u8 = |v: u8| { a += v; a };
//~^ ERROR mismatched types
let b = 0u8;
- let bar :fn() -> u8 = || { b };
+ let bar: fn() -> u8 = || { b };
//~^ ERROR mismatched types
- let baz :fn() -> u8 = || { b } as fn() -> u8;
+ let baz: fn() -> u8 = || { b } as fn() -> u8;
//~^ ERROR mismatched types
//~^^ ERROR non-scalar cast
}
#[cfg(a)]
mod a {
- const FOO :fn(u8) -> u8 = |v: u8| { v };
+ const FOO: fn(u8) -> u8 = |v: u8| { v };
//[a]~^ ERROR non-capturing closure to fn coercion is experimental
//[a]~^^ ERROR mismatched types
fn foo() {
// Items
assert_eq!(func_specific()(), 42);
- let foo :fn(u8) -> u8 = |v: u8| { v };
+ let foo: fn(u8) -> u8 = |v: u8| { v };
//[b]~^ ERROR non-capturing closure to fn coercion is experimental
//[b]~^^ ERROR mismatched types
}
#![feature(closure_to_fn_coercion)]
-const FOO :fn(u8) -> u8 = |v: u8| { v };
+const FOO: fn(u8) -> u8 = |v: u8| { v };
const BAR: [fn(&mut u32); 5] = [
|_: &mut u32| {},
fn main() {
// Items
assert_eq!(func_specific()(), 42);
- let foo :fn(u8) -> u8 = |v: u8| { v };
+ let foo: fn(u8) -> u8 = |v: u8| { v };
assert_eq!(foo(31), 31);
// Constants
assert_eq!(FOO(31), 31);
- let mut a :u32 = 0;
- assert_eq!({BAR[0](&mut a); a }, 0);
- assert_eq!({BAR[1](&mut a); a }, 1);
- assert_eq!({BAR[2](&mut a); a }, 3);
- assert_eq!({BAR[3](&mut a); a }, 6);
- assert_eq!({BAR[4](&mut a); a }, 10);
+ let mut a: u32 = 0;
+ assert_eq!({ BAR[0](&mut a); a }, 0);
+ assert_eq!({ BAR[1](&mut a); a }, 1);
+ assert_eq!({ BAR[2](&mut a); a }, 3);
+ assert_eq!({ BAR[3](&mut a); a }, 6);
+ assert_eq!({ BAR[4](&mut a); a }, 10);
}