Skip to content

Commit fc73e19

Browse files
committed
Review comments.
1 parent 513eb74 commit fc73e19

File tree

8 files changed

+76
-75
lines changed

8 files changed

+76
-75
lines changed

src/librustc/middle/lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'tcx> TyCtxt<'tcx> {
3131
})
3232
}
3333

34-
pub fn fn_trait_lang_item(&self, id: DefId) -> Option<ty::ClosureKind> {
34+
pub fn fn_trait_kind_from_lang_item(&self, id: DefId) -> Option<ty::ClosureKind> {
3535
let items = self.lang_items();
3636
match Some(id) {
3737
x if x == items.fn_trait() => Some(ty::ClosureKind::Fn),

src/librustc/traits/select.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16341634
obligation: &TraitObligation<'tcx>,
16351635
candidates: &mut SelectionCandidateSet<'tcx>,
16361636
) -> Result<(), SelectionError<'tcx>> {
1637-
let kind = match self.tcx().fn_trait_lang_item(obligation.predicate.def_id()) {
1637+
let kind = match self.tcx().fn_trait_kind_from_lang_item(obligation.predicate.def_id()) {
16381638
Some(k) => k,
16391639
None => {
16401640
return Ok(());
@@ -1677,7 +1677,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16771677
candidates: &mut SelectionCandidateSet<'tcx>,
16781678
) -> Result<(), SelectionError<'tcx>> {
16791679
// We provide impl of all fn traits for fn pointers.
1680-
if self.tcx().fn_trait_lang_item(obligation.predicate.def_id()).is_none() {
1680+
if self.tcx().fn_trait_kind_from_lang_item(obligation.predicate.def_id()).is_none() {
16811681
return Ok(());
16821682
}
16831683

@@ -2889,7 +2889,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
28892889

28902890
let kind = self
28912891
.tcx()
2892-
.fn_trait_lang_item(obligation.predicate.def_id())
2892+
.fn_trait_kind_from_lang_item(obligation.predicate.def_id())
28932893
.unwrap_or_else(|| bug!("closure candidate for non-fn trait {:?}", obligation));
28942894

28952895
// Okay to skip binder because the substs on closure types never

src/librustc/ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ fn resolve_associated_item<'tcx>(
450450
substs: generator_data.substs,
451451
}),
452452
traits::VtableClosure(closure_data) => {
453-
let trait_closure_kind = tcx.fn_trait_lang_item(trait_id).unwrap();
453+
let trait_closure_kind = tcx.fn_trait_kind_from_lang_item(trait_id).unwrap();
454454
Some(Instance::resolve_closure(
455455
tcx,
456456
closure_data.closure_def_id,

src/librustc/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ pub trait PrettyPrinter<'tcx>:
724724
let mut resugared = false;
725725

726726
// Special-case `Fn(...) -> ...` and resugar it.
727-
let fn_trait_kind = self.tcx().fn_trait_lang_item(principal.def_id);
727+
let fn_trait_kind = self.tcx().fn_trait_kind_from_lang_item(principal.def_id);
728728
if !self.tcx().sess.verbose() && fn_trait_kind.is_some() {
729729
if let ty::Tuple(ref args) = principal.substs.type_at(0).kind {
730730
let mut projections = predicates.projection_bounds();

src/librustc_hir/lang_items.rs

+63-63
Original file line numberDiff line numberDiff line change
@@ -28,76 +28,76 @@ macro_rules! language_item_table {
2828
$( $variant:ident, $name:expr, $method:ident, $target:path; )*
2929
) => {
3030

31-
enum_from_u32! {
32-
/// A representation of all the valid language items in Rust.
33-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
34-
pub enum LangItem {
35-
$($variant,)*
36-
}
37-
}
38-
39-
impl LangItem {
40-
/// Returns the `name` in `#[lang = "$name"]`.
41-
/// For example, `LangItem::EqTraitLangItem`,
42-
/// that is `#[lang = "eq"]` would result in `"eq"`.
43-
pub fn name(self) -> &'static str {
44-
match self {
45-
$( $variant => $name, )*
31+
enum_from_u32! {
32+
/// A representation of all the valid language items in Rust.
33+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
34+
pub enum LangItem {
35+
$($variant,)*
36+
}
4637
}
47-
}
48-
}
49-
50-
#[derive(HashStable_Generic)]
51-
pub struct LanguageItems {
52-
/// Mappings from lang items to their possibly found `DefId`s.
53-
/// The index corresponds to the order in `LangItem`.
54-
pub items: Vec<Option<DefId>>,
55-
/// Lang items that were not found during collection.
56-
pub missing: Vec<LangItem>,
57-
}
58-
59-
impl LanguageItems {
60-
/// Construct an empty collection of lang items and no missing ones.
61-
pub fn new() -> Self {
62-
fn init_none(_: LangItem) -> Option<DefId> { None }
6338

64-
Self {
65-
items: vec![$(init_none($variant)),*],
66-
missing: Vec::new(),
39+
impl LangItem {
40+
/// Returns the `name` in `#[lang = "$name"]`.
41+
/// For example, `LangItem::EqTraitLangItem`,
42+
/// that is `#[lang = "eq"]` would result in `"eq"`.
43+
pub fn name(self) -> &'static str {
44+
match self {
45+
$( $variant => $name, )*
46+
}
47+
}
6748
}
68-
}
69-
70-
/// Returns the mappings to the possibly found `DefId`s for each lang item.
71-
pub fn items(&self) -> &[Option<DefId>] {
72-
&*self.items
73-
}
7449

75-
/// Requires that a given `LangItem` was bound and returns the corresponding `DefId`.
76-
/// If it wasn't bound, e.g. due to a missing `#[lang = "<it.name()>"]`,
77-
/// returns an error message as a string.
78-
pub fn require(&self, it: LangItem) -> Result<DefId, String> {
79-
self.items[it as usize].ok_or_else(|| format!("requires `{}` lang_item", it.name()))
80-
}
50+
#[derive(HashStable_Generic)]
51+
pub struct LanguageItems {
52+
/// Mappings from lang items to their possibly found `DefId`s.
53+
/// The index corresponds to the order in `LangItem`.
54+
pub items: Vec<Option<DefId>>,
55+
/// Lang items that were not found during collection.
56+
pub missing: Vec<LangItem>,
57+
}
8158

82-
$(
83-
/// Returns the corresponding `DefId` for the lang item
84-
#[doc = $name]
85-
/// if it exists.
86-
#[allow(dead_code)]
87-
pub fn $method(&self) -> Option<DefId> {
88-
self.items[$variant as usize]
59+
impl LanguageItems {
60+
/// Construct an empty collection of lang items and no missing ones.
61+
pub fn new() -> Self {
62+
fn init_none(_: LangItem) -> Option<DefId> { None }
63+
64+
Self {
65+
items: vec![$(init_none($variant)),*],
66+
missing: Vec::new(),
67+
}
68+
}
69+
70+
/// Returns the mappings to the possibly found `DefId`s for each lang item.
71+
pub fn items(&self) -> &[Option<DefId>] {
72+
&*self.items
73+
}
74+
75+
/// Requires that a given `LangItem` was bound and returns the corresponding `DefId`.
76+
/// If it wasn't bound, e.g. due to a missing `#[lang = "<it.name()>"]`,
77+
/// returns an error message as a string.
78+
pub fn require(&self, it: LangItem) -> Result<DefId, String> {
79+
self.items[it as usize].ok_or_else(|| format!("requires `{}` lang_item", it.name()))
80+
}
81+
82+
$(
83+
/// Returns the corresponding `DefId` for the lang item
84+
#[doc = $name]
85+
/// if it exists.
86+
#[allow(dead_code)]
87+
pub fn $method(&self) -> Option<DefId> {
88+
self.items[$variant as usize]
89+
}
90+
)*
8991
}
90-
)*
91-
}
9292

93-
lazy_static! {
94-
/// A mapping from the name of the lang item to its order and the form it must be of.
95-
pub static ref ITEM_REFS: FxHashMap<&'static str, (usize, Target)> = {
96-
let mut item_refs = FxHashMap::default();
97-
$( item_refs.insert($name, ($variant as usize, $target)); )*
98-
item_refs
99-
};
100-
}
93+
lazy_static! {
94+
/// A mapping from the name of the lang item to its order and the form it must be of.
95+
pub static ref ITEM_REFS: FxHashMap<&'static str, (usize, Target)> = {
96+
let mut item_refs = FxHashMap::default();
97+
$( item_refs.insert($name, ($variant as usize, $target)); )*
98+
item_refs
99+
};
100+
}
101101

102102
// End of the macro
103103
}

src/librustc_mir/shim.rs

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

src/librustc_typeck/check/closure.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
174174
self.deduce_sig_from_projection(None, &pb)
175175
})
176176
.next();
177-
let kind =
178-
object_type.principal_def_id().and_then(|did| self.tcx.fn_trait_lang_item(did));
177+
let kind = object_type
178+
.principal_def_id()
179+
.and_then(|did| self.tcx.fn_trait_kind_from_lang_item(did));
179180
(sig, kind)
180181
}
181182
ty::Infer(ty::TyVar(vid)) => self.deduce_expectations_from_obligations(vid),
@@ -213,7 +214,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
213214
// many viable options, so pick the most restrictive.
214215
let expected_kind = self
215216
.obligations_for_self_ty(expected_vid)
216-
.filter_map(|(tr, _)| self.tcx.fn_trait_lang_item(tr.def_id()))
217+
.filter_map(|(tr, _)| self.tcx.fn_trait_kind_from_lang_item(tr.def_id()))
217218
.fold(None, |best, cur| Some(best.map_or(cur, |best| cmp::min(best, cur))));
218219

219220
(expected_sig, expected_kind)
@@ -236,7 +237,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
236237

237238
let trait_ref = projection.to_poly_trait_ref(tcx);
238239

239-
let is_fn = tcx.fn_trait_lang_item(trait_ref.def_id()).is_some();
240+
let is_fn = tcx.fn_trait_kind_from_lang_item(trait_ref.def_id()).is_some();
240241
let gen_trait = tcx.require_lang_item(lang_items::GeneratorTraitLangItem, cause_span);
241242
let is_gen = gen_trait == trait_ref.def_id();
242243
if !is_fn && !is_gen {

src/librustdoc/clean/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub fn external_generic_args(
138138

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

0 commit comments

Comments
 (0)