Skip to content

Commit 2db97ed

Browse files
committed
refactor 'Output = $ty' & reduce rustc dep
1 parent 4e6329e commit 2db97ed

File tree

5 files changed

+17
-21
lines changed

5 files changed

+17
-21
lines changed

src/librustc/traits/project.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use crate::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
1717
use crate::ty::fold::{TypeFoldable, TypeFolder};
1818
use crate::ty::subst::{InternalSubsts, Subst};
1919
use crate::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt};
20-
use crate::util::common::FN_OUTPUT_NAME;
2120
use rustc_data_structures::snapshot_map::{Snapshot, SnapshotMap};
2221
use rustc_hir::def_id::DefId;
2322
use rustc_macros::HashStable;
@@ -1364,7 +1363,7 @@ fn confirm_callable_candidate<'cx, 'tcx>(
13641363
projection_ty: ty::ProjectionTy::from_ref_and_name(
13651364
tcx,
13661365
trait_ref,
1367-
Ident::with_dummy_span(FN_OUTPUT_NAME),
1366+
Ident::with_dummy_span(rustc_hir::FN_OUTPUT_NAME),
13681367
),
13691368
ty: ret_type,
13701369
});

src/librustc/util/common.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@ use rustc_data_structures::sync::Lock;
55
use std::fmt::Debug;
66
use std::time::{Duration, Instant};
77

8-
use rustc_span::symbol::{sym, Symbol};
9-
108
#[cfg(test)]
119
mod tests;
1210

13-
// The name of the associated type for `Fn` return types.
14-
pub const FN_OUTPUT_NAME: Symbol = sym::Output;
15-
1611
pub use errors::ErrorReported;
1712

1813
pub fn to_readable_str(mut val: usize) -> String {

src/librustc_ast_lowering/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use rustc::lint;
4141
use rustc::lint::builtin;
4242
use rustc::middle::cstore::CrateStore;
4343
use rustc::util::captures::Captures;
44-
use rustc::util::common::FN_OUTPUT_NAME;
4544
use rustc::{bug, span_bug};
4645
use rustc_data_structures::fx::FxHashSet;
4746
use rustc_data_structures::sync::Lrc;
@@ -1978,12 +1977,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19781977
// "<Output = T>"
19791978
let future_params = self.arena.alloc(hir::GenericArgs {
19801979
args: &[],
1981-
bindings: arena_vec![self; hir::TypeBinding {
1982-
ident: Ident::with_dummy_span(FN_OUTPUT_NAME),
1983-
kind: hir::TypeBindingKind::Equality { ty: output_ty },
1984-
hir_id: self.next_id(),
1985-
span,
1986-
}],
1980+
bindings: arena_vec![self; self.output_ty_binding(span, output_ty)],
19871981
parenthesized: false,
19881982
});
19891983

src/librustc_ast_lowering/path.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use super::{GenericArgsCtor, ParenthesizedGenericArgs};
33

44
use rustc::lint::builtin::{self, ELIDED_LIFETIMES_IN_PATHS};
55
use rustc::span_bug;
6-
use rustc::util::common::FN_OUTPUT_NAME;
76
use rustc_error_codes::*;
87
use rustc_errors::{struct_span_err, Applicability};
98
use rustc_hir as hir;
@@ -406,16 +405,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
406405
FunctionRetTy::Default(_) => this.arena.alloc(this.ty_tup(span, &[])),
407406
};
408407
let args = smallvec![GenericArg::Type(this.ty_tup(span, inputs))];
409-
let binding = hir::TypeBinding {
410-
hir_id: this.next_id(),
411-
ident: Ident::with_dummy_span(FN_OUTPUT_NAME),
412-
span: output_ty.span,
413-
kind: hir::TypeBindingKind::Equality { ty: output_ty },
414-
};
408+
let binding = this.output_ty_binding(output_ty.span, output_ty);
415409
(
416410
GenericArgsCtor { args, bindings: arena_vec![this; binding], parenthesized: true },
417411
false,
418412
)
419413
})
420414
}
415+
416+
/// An associated type binding `Output = $ty`.
417+
crate fn output_ty_binding(
418+
&mut self,
419+
span: Span,
420+
ty: &'hir hir::Ty<'hir>,
421+
) -> hir::TypeBinding<'hir> {
422+
let ident = Ident::with_dummy_span(hir::FN_OUTPUT_NAME);
423+
let kind = hir::TypeBindingKind::Equality { ty };
424+
hir::TypeBinding { hir_id: self.next_id(), span, ident, kind }
425+
}
421426
}

src/librustc_hir/hir.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,9 @@ pub enum ImplItemKind<'hir> {
18751875
OpaqueTy(GenericBounds<'hir>),
18761876
}
18771877

1878+
// The name of the associated type for `Fn` return types.
1879+
pub const FN_OUTPUT_NAME: Symbol = sym::Output;
1880+
18781881
/// Bind a type to an associated type (i.e., `A = Foo`).
18791882
///
18801883
/// Bindings like `A: Debug` are represented as a special type `A =

0 commit comments

Comments
 (0)