refactor 'Output = $ty' & reduce rustc dep

This commit is contained in:
Mazdak Farrokhzad 2020-01-06 06:48:51 +01:00
parent 4e6329ec3a
commit 2db97ede27
5 changed files with 17 additions and 21 deletions

View file

@ -17,7 +17,6 @@ use crate::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
use crate::ty::fold::{TypeFoldable, TypeFolder};
use crate::ty::subst::{InternalSubsts, Subst};
use crate::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt};
use crate::util::common::FN_OUTPUT_NAME;
use rustc_data_structures::snapshot_map::{Snapshot, SnapshotMap};
use rustc_hir::def_id::DefId;
use rustc_macros::HashStable;
@ -1364,7 +1363,7 @@ fn confirm_callable_candidate<'cx, 'tcx>(
projection_ty: ty::ProjectionTy::from_ref_and_name(
tcx,
trait_ref,
Ident::with_dummy_span(FN_OUTPUT_NAME),
Ident::with_dummy_span(rustc_hir::FN_OUTPUT_NAME),
),
ty: ret_type,
});

View file

@ -5,14 +5,9 @@ use rustc_data_structures::sync::Lock;
use std::fmt::Debug;
use std::time::{Duration, Instant};
use rustc_span::symbol::{sym, Symbol};
#[cfg(test)]
mod tests;
// The name of the associated type for `Fn` return types.
pub const FN_OUTPUT_NAME: Symbol = sym::Output;
pub use errors::ErrorReported;
pub fn to_readable_str(mut val: usize) -> String {

View file

@ -41,7 +41,6 @@ use rustc::lint;
use rustc::lint::builtin;
use rustc::middle::cstore::CrateStore;
use rustc::util::captures::Captures;
use rustc::util::common::FN_OUTPUT_NAME;
use rustc::{bug, span_bug};
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::Lrc;
@ -1978,12 +1977,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// "<Output = T>"
let future_params = self.arena.alloc(hir::GenericArgs {
args: &[],
bindings: arena_vec![self; hir::TypeBinding {
ident: Ident::with_dummy_span(FN_OUTPUT_NAME),
kind: hir::TypeBindingKind::Equality { ty: output_ty },
hir_id: self.next_id(),
span,
}],
bindings: arena_vec![self; self.output_ty_binding(span, output_ty)],
parenthesized: false,
});

View file

@ -3,7 +3,6 @@ use super::{GenericArgsCtor, ParenthesizedGenericArgs};
use rustc::lint::builtin::{self, ELIDED_LIFETIMES_IN_PATHS};
use rustc::span_bug;
use rustc::util::common::FN_OUTPUT_NAME;
use rustc_error_codes::*;
use rustc_errors::{struct_span_err, Applicability};
use rustc_hir as hir;
@ -406,16 +405,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
FunctionRetTy::Default(_) => this.arena.alloc(this.ty_tup(span, &[])),
};
let args = smallvec![GenericArg::Type(this.ty_tup(span, inputs))];
let binding = hir::TypeBinding {
hir_id: this.next_id(),
ident: Ident::with_dummy_span(FN_OUTPUT_NAME),
span: output_ty.span,
kind: hir::TypeBindingKind::Equality { ty: output_ty },
};
let binding = this.output_ty_binding(output_ty.span, output_ty);
(
GenericArgsCtor { args, bindings: arena_vec![this; binding], parenthesized: true },
false,
)
})
}
/// An associated type binding `Output = $ty`.
crate fn output_ty_binding(
&mut self,
span: Span,
ty: &'hir hir::Ty<'hir>,
) -> hir::TypeBinding<'hir> {
let ident = Ident::with_dummy_span(hir::FN_OUTPUT_NAME);
let kind = hir::TypeBindingKind::Equality { ty };
hir::TypeBinding { hir_id: self.next_id(), span, ident, kind }
}
}

View file

@ -1875,6 +1875,9 @@ pub enum ImplItemKind<'hir> {
OpaqueTy(GenericBounds<'hir>),
}
// The name of the associated type for `Fn` return types.
pub const FN_OUTPUT_NAME: Symbol = sym::Output;
/// Bind a type to an associated type (i.e., `A = Foo`).
///
/// Bindings like `A: Debug` are represented as a special type `A =