Skip to content

Commit f4dc1c5

Browse files
committed
fix review comments, round 2
1 parent 78f7e85 commit f4dc1c5

File tree

3 files changed

+23
-53
lines changed

3 files changed

+23
-53
lines changed

src/librustc_typeck/check/mod.rs

+22-50
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ use std::collections::hash_map::Entry;
134134
use std::cmp;
135135
use std::fmt::Display;
136136
use std::iter;
137-
use std::vec;
138137
use std::mem::replace;
139138
use std::ops::{self, Deref};
140139
use std::slice;
@@ -143,6 +142,7 @@ use require_c_abi_if_variadic;
143142
use session::{CompileIncomplete, config, Session};
144143
use TypeAndSubsts;
145144
use lint;
145+
use util::captures::Captures;
146146
use util::common::{ErrorReported, indenter};
147147
use util::nodemap::{DefIdMap, DefIdSet, FxHashMap, FxHashSet, NodeMap};
148148

@@ -2751,55 +2751,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
27512751
_ => false
27522752
}
27532753
}
2754-
}
2755-
2756-
/// FIXME: impl Trait why u give me lifetime errors?
2757-
pub struct ObligationMapper<'a, 'gcx, 'tcx>(&'a FnCtxt<'a, 'gcx, 'tcx>, ty::TyVid);
2758-
2759-
impl<'a, 'gcx, 'tcx> FnOnce<(traits::PredicateObligation<'tcx>,)>
2760-
for ObligationMapper<'a, 'gcx, 'tcx>
2761-
{
2762-
type Output = Option<ty::PolyTraitRef<'tcx>>;
2763-
2764-
extern "rust-call" fn call_once(mut self, args: (traits::PredicateObligation<'tcx>,))
2765-
-> Self::Output {
2766-
self.call_mut(args)
2767-
}
2768-
}
27692754

2770-
impl<'a, 'gcx, 'tcx> FnMut<(traits::PredicateObligation<'tcx>,)>
2771-
for ObligationMapper<'a, 'gcx, 'tcx>
2772-
{
2773-
extern "rust-call" fn call_mut(&mut self, args: (traits::PredicateObligation<'tcx>,))
2774-
-> Self::Output {
2775-
match args.0.predicate {
2776-
ty::Predicate::Projection(ref data) => Some(data.to_poly_trait_ref(self.0.tcx)),
2777-
ty::Predicate::Trait(ref data) => Some(data.to_poly_trait_ref()),
2778-
ty::Predicate::Subtype(..) => None,
2779-
ty::Predicate::RegionOutlives(..) => None,
2780-
ty::Predicate::TypeOutlives(..) => None,
2781-
ty::Predicate::WellFormed(..) => None,
2782-
ty::Predicate::ObjectSafe(..) => None,
2783-
ty::Predicate::ConstEvaluatable(..) => None,
2784-
// N.B., this predicate is created by breaking down a
2785-
// `ClosureType: FnFoo()` predicate, where
2786-
// `ClosureType` represents some `Closure`. It can't
2787-
// possibly be referring to the current closure,
2788-
// because we haven't produced the `Closure` for
2789-
// this closure yet; this is exactly why the other
2790-
// code is looking for a self type of a unresolved
2791-
// inference variable.
2792-
ty::Predicate::ClosureKind(..) => None,
2793-
}.filter(|tr| {
2794-
self.0.self_type_matches_expected_vid(*tr, self.1)
2795-
})
2796-
}
2797-
}
2798-
2799-
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
28002755
fn obligations_for_self_ty<'b>(&'b self, self_ty: ty::TyVid)
2801-
-> iter::FilterMap<vec::IntoIter<traits::PredicateObligation<'tcx>>,
2802-
ObligationMapper<'b, 'gcx, 'tcx>>
2756+
-> impl Iterator<Item=ty::PolyTraitRef<'tcx>> + Captures<'gcx> + 'b
28032757
{
28042758
let ty_var_root = self.root_var(self_ty);
28052759
debug!("obligations_for_self_ty: self_ty={:?} ty_var_root={:?} pending_obligations={:?}",
@@ -2810,12 +2764,30 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
28102764
.borrow()
28112765
.pending_obligations()
28122766
.into_iter()
2813-
.filter_map(ObligationMapper(self, ty_var_root))
2767+
.filter_map(move |obligation| match obligation.predicate {
2768+
ty::Predicate::Projection(ref data) => Some(data.to_poly_trait_ref(self.tcx)),
2769+
ty::Predicate::Trait(ref data) => Some(data.to_poly_trait_ref()),
2770+
ty::Predicate::Subtype(..) => None,
2771+
ty::Predicate::RegionOutlives(..) => None,
2772+
ty::Predicate::TypeOutlives(..) => None,
2773+
ty::Predicate::WellFormed(..) => None,
2774+
ty::Predicate::ObjectSafe(..) => None,
2775+
ty::Predicate::ConstEvaluatable(..) => None,
2776+
// N.B., this predicate is created by breaking down a
2777+
// `ClosureType: FnFoo()` predicate, where
2778+
// `ClosureType` represents some `Closure`. It can't
2779+
// possibly be referring to the current closure,
2780+
// because we haven't produced the `Closure` for
2781+
// this closure yet; this is exactly why the other
2782+
// code is looking for a self type of a unresolved
2783+
// inference variable.
2784+
ty::Predicate::ClosureKind(..) => None,
2785+
}).filter(move |tr| self.self_type_matches_expected_vid(*tr, ty_var_root))
28142786
}
28152787

28162788
fn type_var_is_sized(&self, self_ty: ty::TyVid) -> bool {
28172789
self.obligations_for_self_ty(self_ty).any(|tr| {
2818-
Some(tr.def_id()) == self.tcx.lang_items().sized_trait()
2790+
Some(tr.def_id()) == self.tcx.lang_items().sized_trait()
28192791
})
28202792
}
28212793

src/librustc_typeck/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,13 @@ This API is completely unstable and subject to change.
7575
#![feature(box_syntax)]
7676
#![feature(crate_visibility_modifier)]
7777
#![feature(exhaustive_patterns)]
78-
#![feature(fn_traits)]
7978
#![feature(nll)]
8079
#![feature(quote)]
8180
#![feature(refcell_replace_swap)]
8281
#![feature(rustc_diagnostic_macros)]
8382
#![feature(slice_patterns)]
8483
#![feature(slice_sort_by_cached_key)]
8584
#![feature(never_type)]
86-
#![feature(unboxed_closures)]
8785

8886
#![recursion_limit="256"]
8987

src/test/ui/coercion/coerce-issue-49593-box-never.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn foo_no_never() {
5555

5656
let mut y : Option<S> = None;
5757
// assert types are equal
58-
mem::replace(&mut x, &mut y);
58+
mem::swap(&mut x, &mut y);
5959
}
6060

6161
fn main() {

0 commit comments

Comments
 (0)