Remove the unboxed closure |:| notation from types and trait references completely.
This commit is contained in:
parent
221edbae38
commit
d0fa4c6239
17 changed files with 29 additions and 348 deletions
|
|
@ -40,7 +40,7 @@ use syntax::ast::{TupleVariantKind, Ty, TyBool, TyChar, TyClosure, TyF32};
|
|||
use syntax::ast::{TyF64, TyFloat, TyI, TyI8, TyI16, TyI32, TyI64, TyInt};
|
||||
use syntax::ast::{TyParam, TyParamBound, TyPath, TyPtr, TyProc, TyQPath};
|
||||
use syntax::ast::{TyRptr, TyStr, TyU, TyU8, TyU16, TyU32, TyU64, TyUint};
|
||||
use syntax::ast::{TypeImplItem, UnboxedFnTyParamBound, UnnamedField};
|
||||
use syntax::ast::{TypeImplItem, UnnamedField};
|
||||
use syntax::ast::{Variant, ViewItem, ViewItemExternCrate};
|
||||
use syntax::ast::{ViewItemUse, ViewPathGlob, ViewPathList, ViewPathSimple};
|
||||
use syntax::ast::{Visibility};
|
||||
|
|
@ -4523,41 +4523,6 @@ impl<'a> Resolver<'a> {
|
|||
TraitTyParamBound(ref tref) => {
|
||||
self.resolve_trait_reference(id, tref, reference_type)
|
||||
}
|
||||
UnboxedFnTyParamBound(ref unboxed_function) => {
|
||||
match self.resolve_path(unboxed_function.ref_id,
|
||||
&unboxed_function.path,
|
||||
TypeNS,
|
||||
true) {
|
||||
None => {
|
||||
let path_str = self.path_names_to_string(
|
||||
&unboxed_function.path);
|
||||
self.resolve_error(unboxed_function.path.span,
|
||||
format!("unresolved trait `{}`",
|
||||
path_str).as_slice())
|
||||
}
|
||||
Some(def) => {
|
||||
match def {
|
||||
(DefTrait(_), _) => {
|
||||
self.record_def(unboxed_function.ref_id, def);
|
||||
}
|
||||
_ => {
|
||||
let msg =
|
||||
format!("`{}` is not a trait",
|
||||
self.path_names_to_string(
|
||||
&unboxed_function.path));
|
||||
self.resolve_error(unboxed_function.path.span,
|
||||
msg.as_slice());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for argument in unboxed_function.decl.inputs.iter() {
|
||||
self.resolve_type(&*argument.ty);
|
||||
}
|
||||
|
||||
self.resolve_type(&*unboxed_function.decl.output);
|
||||
}
|
||||
RegionTyParamBound(..) => {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -204,9 +204,6 @@ impl<'a> LifetimeContext<'a> {
|
|||
ast::TraitTyParamBound(ref trait_ref) => {
|
||||
self.visit_trait_ref(trait_ref);
|
||||
}
|
||||
ast::UnboxedFnTyParamBound(ref fn_decl) => {
|
||||
self.visit_unboxed_fn_ty_param_bound(&**fn_decl);
|
||||
}
|
||||
ast::RegionTyParamBound(ref lifetime) => {
|
||||
self.visit_lifetime_ref(lifetime);
|
||||
}
|
||||
|
|
@ -226,18 +223,6 @@ impl<'a> LifetimeContext<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
fn visit_unboxed_fn_ty_param_bound(&mut self,
|
||||
bound: &ast::UnboxedFnBound) {
|
||||
self.with(|scope, f| {
|
||||
f(LateScope(bound.ref_id, &bound.lifetimes, scope))
|
||||
}, |v| {
|
||||
for argument in bound.decl.inputs.iter() {
|
||||
v.visit_ty(&*argument.ty);
|
||||
}
|
||||
v.visit_ty(&*bound.decl.output);
|
||||
})
|
||||
}
|
||||
|
||||
/// Visits self by adding a scope and handling recursive walk over the contents with `walk`.
|
||||
fn visit_fn_decl(&mut self,
|
||||
n: ast::NodeId,
|
||||
|
|
|
|||
|
|
@ -705,7 +705,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
|
|||
ast::TraitTyParamBound(ref trait_ref) => {
|
||||
trait_ref
|
||||
}
|
||||
ast::UnboxedFnTyParamBound(..) | ast::RegionTyParamBound(..) => {
|
||||
ast::RegionTyParamBound(..) => {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -620,15 +620,6 @@ enum PointerTy {
|
|||
Uniq
|
||||
}
|
||||
|
||||
impl PointerTy {
|
||||
fn default_region(&self) -> ty::Region {
|
||||
match *self {
|
||||
Uniq => ty::ReStatic,
|
||||
RPtr(r) => r,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn trait_ref_for_unboxed_function<'tcx, AC: AstConv<'tcx>,
|
||||
RS:RegionScope>(
|
||||
this: &AC,
|
||||
|
|
@ -687,31 +678,6 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
|||
let ty = ast_ty_to_ty(this, rscope, &**ty);
|
||||
return constr(ty::mk_vec(tcx, ty, None));
|
||||
}
|
||||
ast::TyUnboxedFn(ref unboxed_function) => {
|
||||
let ty::TraitRef {
|
||||
def_id,
|
||||
substs
|
||||
} = trait_ref_for_unboxed_function(this,
|
||||
rscope,
|
||||
unboxed_function.kind,
|
||||
&*unboxed_function.decl,
|
||||
None);
|
||||
let r = ptr_ty.default_region();
|
||||
let tr = ty::mk_trait(this.tcx(),
|
||||
def_id,
|
||||
substs,
|
||||
ty::region_existential_bound(r));
|
||||
match ptr_ty {
|
||||
Uniq => {
|
||||
return ty::mk_uniq(this.tcx(), tr);
|
||||
}
|
||||
RPtr(r) => {
|
||||
return ty::mk_rptr(this.tcx(),
|
||||
r,
|
||||
ty::mt {mutbl: a_seq_mutbl, ty: tr});
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::TyPath(ref path, ref opt_bounds, id) => {
|
||||
// Note that the "bounds must be empty if path is not a trait"
|
||||
// restriction is enforced in the below case for ty_path, which
|
||||
|
|
@ -941,11 +907,6 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
|
|||
|
||||
ty::mk_closure(tcx, fn_decl)
|
||||
}
|
||||
ast::TyUnboxedFn(..) => {
|
||||
tcx.sess.span_err(ast_ty.span,
|
||||
"cannot use unboxed functions here");
|
||||
ty::mk_err()
|
||||
}
|
||||
ast::TyPath(ref path, ref bounds, id) => {
|
||||
let a_def = match tcx.def_map.borrow().find(&id) {
|
||||
None => {
|
||||
|
|
@ -1425,8 +1386,7 @@ pub fn conv_existential_bounds<'tcx, AC: AstConv<'tcx>, RS:RegionScope>(
|
|||
|
||||
let PartitionedBounds { builtin_bounds,
|
||||
trait_bounds,
|
||||
region_bounds,
|
||||
unboxed_fn_ty_bounds } =
|
||||
region_bounds } =
|
||||
partition_bounds(this.tcx(), span, ast_bound_refs.as_slice());
|
||||
|
||||
if !trait_bounds.is_empty() {
|
||||
|
|
@ -1437,13 +1397,6 @@ pub fn conv_existential_bounds<'tcx, AC: AstConv<'tcx>, RS:RegionScope>(
|
|||
as closure or object bounds").as_slice());
|
||||
}
|
||||
|
||||
if !unboxed_fn_ty_bounds.is_empty() {
|
||||
this.tcx().sess.span_err(
|
||||
span,
|
||||
format!("only the builtin traits can be used \
|
||||
as closure or object bounds").as_slice());
|
||||
}
|
||||
|
||||
// The "main trait refs", rather annoyingly, have no type
|
||||
// specified for the `Self` parameter of the trait. The reason for
|
||||
// this is that they are, after all, *existential* types, and
|
||||
|
|
@ -1572,7 +1525,6 @@ fn compute_region_bound<'tcx, AC: AstConv<'tcx>, RS:RegionScope>(
|
|||
pub struct PartitionedBounds<'a> {
|
||||
pub builtin_bounds: ty::BuiltinBounds,
|
||||
pub trait_bounds: Vec<&'a ast::TraitRef>,
|
||||
pub unboxed_fn_ty_bounds: Vec<&'a ast::UnboxedFnBound>,
|
||||
pub region_bounds: Vec<&'a ast::Lifetime>,
|
||||
}
|
||||
|
||||
|
|
@ -1590,7 +1542,6 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
|
|||
let mut builtin_bounds = ty::empty_builtin_bounds();
|
||||
let mut region_bounds = Vec::new();
|
||||
let mut trait_bounds = Vec::new();
|
||||
let mut unboxed_fn_ty_bounds = Vec::new();
|
||||
let mut trait_def_ids = HashMap::new();
|
||||
for &ast_bound in ast_bounds.iter() {
|
||||
match *ast_bound {
|
||||
|
|
@ -1635,9 +1586,6 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
|
|||
ast::RegionTyParamBound(ref l) => {
|
||||
region_bounds.push(l);
|
||||
}
|
||||
ast::UnboxedFnTyParamBound(ref unboxed_function) => {
|
||||
unboxed_fn_ty_bounds.push(&**unboxed_function);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1645,7 +1593,6 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
|
|||
builtin_bounds: builtin_bounds,
|
||||
trait_bounds: trait_bounds,
|
||||
region_bounds: region_bounds,
|
||||
unboxed_fn_ty_bounds: unboxed_fn_ty_bounds
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -638,7 +638,7 @@ pub fn ensure_no_ty_param_bounds(ccx: &CrateCtxt,
|
|||
let mut bounds = bounds.chain(ty_param.unbound.iter());
|
||||
for bound in bounds {
|
||||
match *bound {
|
||||
ast::TraitTyParamBound(..) | ast::UnboxedFnTyParamBound(..) => {
|
||||
ast::TraitTyParamBound(..) => {
|
||||
// According to accepted RFC #XXX, we should
|
||||
// eventually accept these, but it will not be
|
||||
// part of this PR. Still, convert to warning to
|
||||
|
|
@ -1356,20 +1356,6 @@ pub fn instantiate_trait_ref<'tcx,AC>(this: &AC,
|
|||
}
|
||||
}
|
||||
|
||||
pub fn instantiate_unboxed_fn_ty<'tcx,AC>(this: &AC,
|
||||
unboxed_function: &ast::UnboxedFnTy,
|
||||
param_ty: ty::ParamTy)
|
||||
-> Rc<ty::TraitRef>
|
||||
where AC: AstConv<'tcx> {
|
||||
let rscope = ExplicitRscope;
|
||||
let param_ty = param_ty.to_ty(this.tcx());
|
||||
Rc::new(astconv::trait_ref_for_unboxed_function(this,
|
||||
&rscope,
|
||||
unboxed_function.kind,
|
||||
&*unboxed_function.decl,
|
||||
Some(param_ty)))
|
||||
}
|
||||
|
||||
fn get_trait_def(ccx: &CrateCtxt, trait_id: ast::DefId) -> Rc<ty::TraitDef> {
|
||||
if trait_id.krate != ast::LOCAL_CRATE {
|
||||
return ty::lookup_trait_def(ccx.tcx, trait_id)
|
||||
|
|
@ -1879,7 +1865,6 @@ fn ty_generics<'tcx,AC>(this: &AC,
|
|||
// In the above example, `ast_trait_ref` is `Iterator`.
|
||||
let ast_trait_ref = match *bound {
|
||||
ast::TraitTyParamBound(ref r) => r,
|
||||
ast::UnboxedFnTyParamBound(..) => { continue; }
|
||||
ast::RegionTyParamBound(..) => { continue; }
|
||||
};
|
||||
|
||||
|
|
@ -2057,45 +2042,8 @@ fn conv_param_bounds<'tcx,AC>(this: &AC,
|
|||
merge_param_bounds(this.tcx(), param_ty, ast_bounds, where_clause);
|
||||
let astconv::PartitionedBounds { builtin_bounds,
|
||||
trait_bounds,
|
||||
region_bounds,
|
||||
unboxed_fn_ty_bounds } =
|
||||
region_bounds } =
|
||||
astconv::partition_bounds(this.tcx(), span, all_bounds.as_slice());
|
||||
|
||||
let unboxed_fn_ty_bounds = unboxed_fn_ty_bounds.into_iter().map(|b| {
|
||||
let trait_id = (*this.tcx().def_map.borrow())[b.ref_id].def_id();
|
||||
let mut kind = None;
|
||||
for &(lang_item, this_kind) in [
|
||||
(this.tcx().lang_items.fn_trait(), ast::FnUnboxedClosureKind),
|
||||
(this.tcx().lang_items.fn_mut_trait(),
|
||||
ast::FnMutUnboxedClosureKind),
|
||||
(this.tcx().lang_items.fn_once_trait(),
|
||||
ast::FnOnceUnboxedClosureKind)
|
||||
].iter() {
|
||||
if Some(trait_id) == lang_item {
|
||||
kind = Some(this_kind);
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
let kind = match kind {
|
||||
Some(kind) => kind,
|
||||
None => {
|
||||
this.tcx().sess.span_err(b.path.span,
|
||||
"unboxed function trait must be one \
|
||||
of `Fn`, `FnMut`, or `FnOnce`");
|
||||
ast::FnMutUnboxedClosureKind
|
||||
}
|
||||
};
|
||||
|
||||
let rscope = ExplicitRscope;
|
||||
let param_ty = param_ty.to_ty(this.tcx());
|
||||
Rc::new(astconv::trait_ref_for_unboxed_function(this,
|
||||
&rscope,
|
||||
kind,
|
||||
&*b.decl,
|
||||
Some(param_ty)))
|
||||
});
|
||||
|
||||
let trait_bounds: Vec<Rc<ty::TraitRef>> =
|
||||
trait_bounds.into_iter()
|
||||
.map(|b| {
|
||||
|
|
@ -2104,7 +2052,6 @@ fn conv_param_bounds<'tcx,AC>(this: &AC,
|
|||
param_ty.to_ty(this.tcx()),
|
||||
Some(param_ty.to_ty(this.tcx())))
|
||||
})
|
||||
.chain(unboxed_fn_ty_bounds)
|
||||
.collect();
|
||||
let region_bounds: Vec<ty::Region> =
|
||||
region_bounds.into_iter()
|
||||
|
|
|
|||
|
|
@ -1102,9 +1102,6 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
|
|||
// be passing down a map.
|
||||
ast::RegionTyParamBound(lt)
|
||||
}
|
||||
&ast::UnboxedFnTyParamBound(ref unboxed_function_type) => {
|
||||
ast::UnboxedFnTyParamBound((*unboxed_function_type).clone())
|
||||
}
|
||||
&ast::TraitTyParamBound(ref tr) => {
|
||||
let last_seg = tr.path.segments.last().unwrap();
|
||||
let mut insert = Vec::new();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue