diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-01-06 06:48:51 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-01-09 08:57:24 +0100 |
| commit | 2db97ede2702b64426d3209ce8ec787a16cbf4e7 (patch) | |
| tree | 9087626ae3e4f4e443d7e3a6c145d55bf69d165c | |
| parent | 4e6329ec3a7d971972e0a876ae3e6b86ad506d82 (diff) | |
| download | rust-2db97ede2702b64426d3209ce8ec787a16cbf4e7.tar.gz rust-2db97ede2702b64426d3209ce8ec787a16cbf4e7.zip | |
refactor 'Output = $ty' & reduce rustc dep
| -rw-r--r-- | src/librustc/traits/project.rs | 3 | ||||
| -rw-r--r-- | src/librustc/util/common.rs | 5 | ||||
| -rw-r--r-- | src/librustc_ast_lowering/lib.rs | 8 | ||||
| -rw-r--r-- | src/librustc_ast_lowering/path.rs | 19 | ||||
| -rw-r--r-- | src/librustc_hir/hir.rs | 3 |
5 files changed, 17 insertions, 21 deletions
diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index 79e1b6444a9..738bbd936fe 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -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, }); diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 95746852157..9324b26a09b 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -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 { diff --git a/src/librustc_ast_lowering/lib.rs b/src/librustc_ast_lowering/lib.rs index 3211c57f6bb..062b093b8e6 100644 --- a/src/librustc_ast_lowering/lib.rs +++ b/src/librustc_ast_lowering/lib.rs @@ -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, }); diff --git a/src/librustc_ast_lowering/path.rs b/src/librustc_ast_lowering/path.rs index 7209dbfdcc7..4f71910b0bf 100644 --- a/src/librustc_ast_lowering/path.rs +++ b/src/librustc_ast_lowering/path.rs @@ -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 } + } } diff --git a/src/librustc_hir/hir.rs b/src/librustc_hir/hir.rs index 2303a85df4a..603c21188e3 100644 --- a/src/librustc_hir/hir.rs +++ b/src/librustc_hir/hir.rs @@ -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 = |
