about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2020-02-11 23:21:21 +0100
committerCamille GILLOT <gillot.camille@gmail.com>2020-02-11 23:21:21 +0100
commitfc73e196d9cf045c722aff27b9a2e595357384db (patch)
treec6bfbb7dac0b1445eb2db5d1dc1588b9aa28e3a5
parent513eb744c0c2ead6b10a3a3e5f0267e4136a9b4f (diff)
downloadrust-fc73e196d9cf045c722aff27b9a2e595357384db.tar.gz
rust-fc73e196d9cf045c722aff27b9a2e595357384db.zip
Review comments.
-rw-r--r--src/librustc/middle/lang_items.rs2
-rw-r--r--src/librustc/traits/select.rs6
-rw-r--r--src/librustc/ty/instance.rs2
-rw-r--r--src/librustc/ty/print/pretty.rs2
-rw-r--r--src/librustc_hir/lang_items.rs126
-rw-r--r--src/librustc_mir/shim.rs2
-rw-r--r--src/librustc_typeck/check/closure.rs9
-rw-r--r--src/librustdoc/clean/utils.rs2
8 files changed, 76 insertions, 75 deletions
diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs
index 9fbb151ccdf..c8e284be6fc 100644
--- a/src/librustc/middle/lang_items.rs
+++ b/src/librustc/middle/lang_items.rs
@@ -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),
diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs
index 4c4947d134f..bf82d743c2b 100644
--- a/src/librustc/traits/select.rs
+++ b/src/librustc/traits/select.rs
@@ -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
diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs
index b175de6e0e8..b5e17661c5d 100644
--- a/src/librustc/ty/instance.rs
+++ b/src/librustc/ty/instance.rs
@@ -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,
diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs
index 2a43d0486d0..274482cba64 100644
--- a/src/librustc/ty/print/pretty.rs
+++ b/src/librustc/ty/print/pretty.rs
@@ -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();
diff --git a/src/librustc_hir/lang_items.rs b/src/librustc_hir/lang_items.rs
index c5bad979f54..cb5ebba4633 100644
--- a/src/librustc_hir/lang_items.rs
+++ b/src/librustc_hir/lang_items.rs
@@ -28,76 +28,76 @@ macro_rules! language_item_table {
         $( $variant:ident, $name:expr, $method:ident, $target:path; )*
     ) => {
 
-enum_from_u32! {
-    /// A representation of all the valid language items in Rust.
-    #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
-    pub enum LangItem {
-        $($variant,)*
-    }
-}
-
-impl LangItem {
-    /// Returns the `name` in `#[lang = "$name"]`.
-    /// For example, `LangItem::EqTraitLangItem`,
-    /// that is `#[lang = "eq"]` would result in `"eq"`.
-    pub fn name(self) -> &'static str {
-        match self {
-            $( $variant => $name, )*
+        enum_from_u32! {
+            /// A representation of all the valid language items in Rust.
+            #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
+            pub enum LangItem {
+                $($variant,)*
+            }
         }
-    }
-}
-
-#[derive(HashStable_Generic)]
-pub struct LanguageItems {
-    /// Mappings from lang items to their possibly found `DefId`s.
-    /// The index corresponds to the order in `LangItem`.
-    pub items: Vec<Option<DefId>>,
-    /// Lang items that were not found during collection.
-    pub missing: Vec<LangItem>,
-}
-
-impl LanguageItems {
-    /// Construct an empty collection of lang items and no missing ones.
-    pub fn new() -> Self {
-        fn init_none(_: LangItem) -> Option<DefId> { None }
 
-        Self {
-            items: vec![$(init_none($variant)),*],
-            missing: Vec::new(),
+        impl LangItem {
+            /// Returns the `name` in `#[lang = "$name"]`.
+            /// For example, `LangItem::EqTraitLangItem`,
+            /// that is `#[lang = "eq"]` would result in `"eq"`.
+            pub fn name(self) -> &'static str {
+                match self {
+                    $( $variant => $name, )*
+                }
+            }
         }
-    }
-
-    /// Returns the mappings to the possibly found `DefId`s for each lang item.
-    pub fn items(&self) -> &[Option<DefId>] {
-        &*self.items
-    }
 
-    /// Requires that a given `LangItem` was bound and returns the corresponding `DefId`.
-    /// If it wasn't bound, e.g. due to a missing `#[lang = "<it.name()>"]`,
-    /// returns an error message as a string.
-    pub fn require(&self, it: LangItem) -> Result<DefId, String> {
-        self.items[it as usize].ok_or_else(|| format!("requires `{}` lang_item", it.name()))
-    }
+        #[derive(HashStable_Generic)]
+        pub struct LanguageItems {
+            /// Mappings from lang items to their possibly found `DefId`s.
+            /// The index corresponds to the order in `LangItem`.
+            pub items: Vec<Option<DefId>>,
+            /// Lang items that were not found during collection.
+            pub missing: Vec<LangItem>,
+        }
 
-    $(
-        /// Returns the corresponding `DefId` for the lang item
-        #[doc = $name]
-        /// if it exists.
-        #[allow(dead_code)]
-        pub fn $method(&self) -> Option<DefId> {
-            self.items[$variant as usize]
+        impl LanguageItems {
+            /// Construct an empty collection of lang items and no missing ones.
+            pub fn new() -> Self {
+                fn init_none(_: LangItem) -> Option<DefId> { None }
+
+                Self {
+                    items: vec![$(init_none($variant)),*],
+                    missing: Vec::new(),
+                }
+            }
+
+            /// Returns the mappings to the possibly found `DefId`s for each lang item.
+            pub fn items(&self) -> &[Option<DefId>] {
+                &*self.items
+            }
+
+            /// Requires that a given `LangItem` was bound and returns the corresponding `DefId`.
+            /// If it wasn't bound, e.g. due to a missing `#[lang = "<it.name()>"]`,
+            /// returns an error message as a string.
+            pub fn require(&self, it: LangItem) -> Result<DefId, String> {
+                self.items[it as usize].ok_or_else(|| format!("requires `{}` lang_item", it.name()))
+            }
+
+            $(
+                /// Returns the corresponding `DefId` for the lang item
+                #[doc = $name]
+                /// if it exists.
+                #[allow(dead_code)]
+                pub fn $method(&self) -> Option<DefId> {
+                    self.items[$variant as usize]
+                }
+            )*
         }
-    )*
-}
 
-lazy_static! {
-    /// A mapping from the name of the lang item to its order and the form it must be of.
-    pub static ref ITEM_REFS: FxHashMap<&'static str, (usize, Target)> = {
-        let mut item_refs = FxHashMap::default();
-        $( item_refs.insert($name, ($variant as usize, $target)); )*
-        item_refs
-    };
-}
+        lazy_static! {
+            /// A mapping from the name of the lang item to its order and the form it must be of.
+            pub static ref ITEM_REFS: FxHashMap<&'static str, (usize, Target)> = {
+                let mut item_refs = FxHashMap::default();
+                $( item_refs.insert($name, ($variant as usize, $target)); )*
+                item_refs
+            };
+        }
 
 // End of the macro
     }
diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs
index cc5e142351d..bfd30ff5da5 100644
--- a/src/librustc_mir/shim.rs
+++ b/src/librustc_mir/shim.rs
@@ -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),
diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs
index f601a0e8253..396534b3cae 100644
--- a/src/librustc_typeck/check/closure.rs
+++ b/src/librustc_typeck/check/closure.rs
@@ -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 {
diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs
index c1796744323..ef357056504 100644
--- a/src/librustdoc/clean/utils.rs
+++ b/src/librustdoc/clean/utils.rs
@@ -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(),