Review comments.

This commit is contained in:
Camille GILLOT 2020-02-11 23:21:21 +01:00
parent 513eb744c0
commit fc73e196d9
8 changed files with 77 additions and 76 deletions

View File

@ -31,7 +31,7 @@ impl<'tcx> TyCtxt<'tcx> {
})
}
pub fn fn_trait_lang_item(&self, id: DefId) -> Option<ty::ClosureKind> {
pub fn fn_trait_kind_from_lang_item(&self, id: DefId) -> Option<ty::ClosureKind> {
let items = self.lang_items();
match Some(id) {
x if x == items.fn_trait() => Some(ty::ClosureKind::Fn),

View File

@ -1634,7 +1634,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation: &TraitObligation<'tcx>,
candidates: &mut SelectionCandidateSet<'tcx>,
) -> Result<(), SelectionError<'tcx>> {
let kind = match self.tcx().fn_trait_lang_item(obligation.predicate.def_id()) {
let kind = match self.tcx().fn_trait_kind_from_lang_item(obligation.predicate.def_id()) {
Some(k) => k,
None => {
return Ok(());
@ -1677,7 +1677,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
candidates: &mut SelectionCandidateSet<'tcx>,
) -> Result<(), SelectionError<'tcx>> {
// We provide impl of all fn traits for fn pointers.
if self.tcx().fn_trait_lang_item(obligation.predicate.def_id()).is_none() {
if self.tcx().fn_trait_kind_from_lang_item(obligation.predicate.def_id()).is_none() {
return Ok(());
}
@ -2889,7 +2889,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let kind = self
.tcx()
.fn_trait_lang_item(obligation.predicate.def_id())
.fn_trait_kind_from_lang_item(obligation.predicate.def_id())
.unwrap_or_else(|| bug!("closure candidate for non-fn trait {:?}", obligation));
// Okay to skip binder because the substs on closure types never

View File

@ -450,7 +450,7 @@ fn resolve_associated_item<'tcx>(
substs: generator_data.substs,
}),
traits::VtableClosure(closure_data) => {
let trait_closure_kind = tcx.fn_trait_lang_item(trait_id).unwrap();
let trait_closure_kind = tcx.fn_trait_kind_from_lang_item(trait_id).unwrap();
Some(Instance::resolve_closure(
tcx,
closure_data.closure_def_id,

View File

@ -724,7 +724,7 @@ pub trait PrettyPrinter<'tcx>:
let mut resugared = false;
// Special-case `Fn(...) -> ...` and resugar it.
let fn_trait_kind = self.tcx().fn_trait_lang_item(principal.def_id);
let fn_trait_kind = self.tcx().fn_trait_kind_from_lang_item(principal.def_id);
if !self.tcx().sess.verbose() && fn_trait_kind.is_some() {
if let ty::Tuple(ref args) = principal.substs.type_at(0).kind {
let mut projections = predicates.projection_bounds();

View File

@ -40,7 +40,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
),
ty::InstanceDef::FnPtrShim(def_id, ty) => {
let trait_ = tcx.trait_of_item(def_id).unwrap();
let adjustment = match tcx.fn_trait_lang_item(trait_) {
let adjustment = match tcx.fn_trait_kind_from_lang_item(trait_) {
Some(ty::ClosureKind::FnOnce) => Adjustment::Identity,
Some(ty::ClosureKind::FnMut) | Some(ty::ClosureKind::Fn) => Adjustment::Deref,
None => bug!("fn pointer {:?} is not an fn", ty),

View File

@ -174,8 +174,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.deduce_sig_from_projection(None, &pb)
})
.next();
let kind =
object_type.principal_def_id().and_then(|did| self.tcx.fn_trait_lang_item(did));
let kind = object_type
.principal_def_id()
.and_then(|did| self.tcx.fn_trait_kind_from_lang_item(did));
(sig, kind)
}
ty::Infer(ty::TyVar(vid)) => self.deduce_expectations_from_obligations(vid),
@ -213,7 +214,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// many viable options, so pick the most restrictive.
let expected_kind = self
.obligations_for_self_ty(expected_vid)
.filter_map(|(tr, _)| self.tcx.fn_trait_lang_item(tr.def_id()))
.filter_map(|(tr, _)| self.tcx.fn_trait_kind_from_lang_item(tr.def_id()))
.fold(None, |best, cur| Some(best.map_or(cur, |best| cmp::min(best, cur))));
(expected_sig, expected_kind)
@ -236,7 +237,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let trait_ref = projection.to_poly_trait_ref(tcx);
let is_fn = tcx.fn_trait_lang_item(trait_ref.def_id()).is_some();
let is_fn = tcx.fn_trait_kind_from_lang_item(trait_ref.def_id()).is_some();
let gen_trait = tcx.require_lang_item(lang_items::GeneratorTraitLangItem, cause_span);
let is_gen = gen_trait == trait_ref.def_id();
if !is_fn && !is_gen {

View File

@ -138,7 +138,7 @@ pub fn external_generic_args(
match trait_did {
// Attempt to sugar an external path like Fn<(A, B,), C> to Fn(A, B) -> C
Some(did) if cx.tcx.fn_trait_lang_item(did).is_some() => {
Some(did) if cx.tcx.fn_trait_kind_from_lang_item(did).is_some() => {
assert!(ty_kind.is_some());
let inputs = match ty_kind {
Some(ty::Tuple(ref tys)) => tys.iter().map(|t| t.expect_ty().clean(cx)).collect(),