diff options
| author | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2018-11-26 10:23:42 +0200 |
|---|---|---|
| committer | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2018-12-17 01:59:32 +0200 |
| commit | f4dc1c5d64d5439ba8b70f93490d7dc8ee512c7e (patch) | |
| tree | d78fdff9e3379a1ebace6b4cb4e8073c33f6683b | |
| parent | 78f7e854f981c5f0c23f0eaf4c750ce1aa581ac6 (diff) | |
| download | rust-f4dc1c5d64d5439ba8b70f93490d7dc8ee512c7e.tar.gz rust-f4dc1c5d64d5439ba8b70f93490d7dc8ee512c7e.zip | |
fix review comments, round 2
| -rw-r--r-- | src/librustc_typeck/check/mod.rs | 72 | ||||
| -rw-r--r-- | src/librustc_typeck/lib.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/coercion/coerce-issue-49593-box-never.rs | 2 |
3 files changed, 23 insertions, 53 deletions
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 8f044f9a7c3..e8252f55735 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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() }) } diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 5ecf24c4a10..8d6fb8b7f39 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -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"] diff --git a/src/test/ui/coercion/coerce-issue-49593-box-never.rs b/src/test/ui/coercion/coerce-issue-49593-box-never.rs index 407484e3d26..bea8586452e 100644 --- a/src/test/ui/coercion/coerce-issue-49593-box-never.rs +++ b/src/test/ui/coercion/coerce-issue-49593-box-never.rs @@ -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() { |
