mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-27 06:14:55 +00:00
fix review comments, round 2
This commit is contained in:
parent
78f7e854f9
commit
f4dc1c5d64
@ -134,7 +134,6 @@ use std::collections::hash_map::Entry;
|
||||
use std::cmp;
|
||||
use std::fmt::Display;
|
||||
use std::iter;
|
||||
use std::vec;
|
||||
use std::mem::replace;
|
||||
use std::ops::{self, Deref};
|
||||
use std::slice;
|
||||
@ -143,6 +142,7 @@ use require_c_abi_if_variadic;
|
||||
use session::{CompileIncomplete, config, Session};
|
||||
use TypeAndSubsts;
|
||||
use lint;
|
||||
use util::captures::Captures;
|
||||
use util::common::{ErrorReported, indenter};
|
||||
use util::nodemap::{DefIdMap, DefIdSet, FxHashMap, FxHashSet, NodeMap};
|
||||
|
||||
@ -2751,55 +2751,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// FIXME: impl Trait why u give me lifetime errors?
|
||||
pub struct ObligationMapper<'a, 'gcx, 'tcx>(&'a FnCtxt<'a, 'gcx, 'tcx>, ty::TyVid);
|
||||
|
||||
impl<'a, 'gcx, 'tcx> FnOnce<(traits::PredicateObligation<'tcx>,)>
|
||||
for ObligationMapper<'a, 'gcx, 'tcx>
|
||||
{
|
||||
type Output = Option<ty::PolyTraitRef<'tcx>>;
|
||||
|
||||
extern "rust-call" fn call_once(mut self, args: (traits::PredicateObligation<'tcx>,))
|
||||
-> Self::Output {
|
||||
self.call_mut(args)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'gcx, 'tcx> FnMut<(traits::PredicateObligation<'tcx>,)>
|
||||
for ObligationMapper<'a, 'gcx, 'tcx>
|
||||
{
|
||||
extern "rust-call" fn call_mut(&mut self, args: (traits::PredicateObligation<'tcx>,))
|
||||
-> Self::Output {
|
||||
match args.0.predicate {
|
||||
ty::Predicate::Projection(ref data) => Some(data.to_poly_trait_ref(self.0.tcx)),
|
||||
ty::Predicate::Trait(ref data) => Some(data.to_poly_trait_ref()),
|
||||
ty::Predicate::Subtype(..) => None,
|
||||
ty::Predicate::RegionOutlives(..) => None,
|
||||
ty::Predicate::TypeOutlives(..) => None,
|
||||
ty::Predicate::WellFormed(..) => None,
|
||||
ty::Predicate::ObjectSafe(..) => None,
|
||||
ty::Predicate::ConstEvaluatable(..) => None,
|
||||
// N.B., this predicate is created by breaking down a
|
||||
// `ClosureType: FnFoo()` predicate, where
|
||||
// `ClosureType` represents some `Closure`. It can't
|
||||
// possibly be referring to the current closure,
|
||||
// because we haven't produced the `Closure` for
|
||||
// this closure yet; this is exactly why the other
|
||||
// code is looking for a self type of a unresolved
|
||||
// inference variable.
|
||||
ty::Predicate::ClosureKind(..) => None,
|
||||
}.filter(|tr| {
|
||||
self.0.self_type_matches_expected_vid(*tr, self.1)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
fn obligations_for_self_ty<'b>(&'b self, self_ty: ty::TyVid)
|
||||
-> iter::FilterMap<vec::IntoIter<traits::PredicateObligation<'tcx>>,
|
||||
ObligationMapper<'b, 'gcx, 'tcx>>
|
||||
-> impl Iterator<Item=ty::PolyTraitRef<'tcx>> + Captures<'gcx> + 'b
|
||||
{
|
||||
let ty_var_root = self.root_var(self_ty);
|
||||
debug!("obligations_for_self_ty: self_ty={:?} ty_var_root={:?} pending_obligations={:?}",
|
||||
@ -2810,12 +2764,30 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
.borrow()
|
||||
.pending_obligations()
|
||||
.into_iter()
|
||||
.filter_map(ObligationMapper(self, ty_var_root))
|
||||
.filter_map(move |obligation| match obligation.predicate {
|
||||
ty::Predicate::Projection(ref data) => Some(data.to_poly_trait_ref(self.tcx)),
|
||||
ty::Predicate::Trait(ref data) => Some(data.to_poly_trait_ref()),
|
||||
ty::Predicate::Subtype(..) => None,
|
||||
ty::Predicate::RegionOutlives(..) => None,
|
||||
ty::Predicate::TypeOutlives(..) => None,
|
||||
ty::Predicate::WellFormed(..) => None,
|
||||
ty::Predicate::ObjectSafe(..) => None,
|
||||
ty::Predicate::ConstEvaluatable(..) => None,
|
||||
// N.B., this predicate is created by breaking down a
|
||||
// `ClosureType: FnFoo()` predicate, where
|
||||
// `ClosureType` represents some `Closure`. It can't
|
||||
// possibly be referring to the current closure,
|
||||
// because we haven't produced the `Closure` for
|
||||
// this closure yet; this is exactly why the other
|
||||
// code is looking for a self type of a unresolved
|
||||
// inference variable.
|
||||
ty::Predicate::ClosureKind(..) => None,
|
||||
}).filter(move |tr| self.self_type_matches_expected_vid(*tr, ty_var_root))
|
||||
}
|
||||
|
||||
fn type_var_is_sized(&self, self_ty: ty::TyVid) -> bool {
|
||||
self.obligations_for_self_ty(self_ty).any(|tr| {
|
||||
Some(tr.def_id()) == self.tcx.lang_items().sized_trait()
|
||||
Some(tr.def_id()) == self.tcx.lang_items().sized_trait()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,6 @@ This API is completely unstable and subject to change.
|
||||
#![feature(box_syntax)]
|
||||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(exhaustive_patterns)]
|
||||
#![feature(fn_traits)]
|
||||
#![feature(nll)]
|
||||
#![feature(quote)]
|
||||
#![feature(refcell_replace_swap)]
|
||||
@ -83,7 +82,6 @@ This API is completely unstable and subject to change.
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(slice_sort_by_cached_key)]
|
||||
#![feature(never_type)]
|
||||
#![feature(unboxed_closures)]
|
||||
|
||||
#![recursion_limit="256"]
|
||||
|
||||
|
@ -55,7 +55,7 @@ fn foo_no_never() {
|
||||
|
||||
let mut y : Option<S> = None;
|
||||
// assert types are equal
|
||||
mem::replace(&mut x, &mut y);
|
||||
mem::swap(&mut x, &mut y);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
Loading…
Reference in New Issue
Block a user