]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/lint/context.rs
Auto merge of #61203 - memoryruins:bare_trait_objects, r=Centril
[rust.git] / src / librustc / lint / context.rs
index 7e1e751e856478197de92a2e69dc2e2b86ebcea3..c6583dd7a27b707cd1057dc24b9804f6a96ade1c 100644 (file)
@@ -759,27 +759,27 @@ pub fn current_lint_root(&self) -> hir::HirId {
     /// # Examples
     ///
     /// ```rust,ignore (no context or def id available)
-    /// if cx.match_def_path(def_id, &["core", "option", "Option"]) {
+    /// if cx.match_def_path(def_id, &[sym::core, sym::option, sym::Option]) {
     ///     // The given `def_id` is that of an `Option` type
     /// }
     /// ```
-    pub fn match_def_path(&self, def_id: DefId, path: &[&str]) -> bool {
+    pub fn match_def_path(&self, def_id: DefId, path: &[Symbol]) -> bool {
         let names = self.get_def_path(def_id);
 
-        names.len() == path.len() && names.into_iter().zip(path.iter()).all(|(a, &b)| *a == *b)
+        names.len() == path.len() && names.into_iter().zip(path.iter()).all(|(a, &b)| a == b)
     }
 
-    /// Gets the absolute path of `def_id` as a vector of `&str`.
+    /// Gets the absolute path of `def_id` as a vector of `Symbol`.
     ///
     /// # Examples
     ///
     /// ```rust,ignore (no context or def id available)
     /// let def_path = cx.get_def_path(def_id);
-    /// if let &["core", "option", "Option"] = &def_path[..] {
+    /// if let &[sym::core, sym::option, sym::Option] = &def_path[..] {
     ///     // The given `def_id` is that of an `Option` type
     /// }
     /// ```
-    pub fn get_def_path(&self, def_id: DefId) -> Vec<LocalInternedString> {
+    pub fn get_def_path(&self, def_id: DefId) -> Vec<Symbol> {
         pub struct AbsolutePathPrinter<'a, 'tcx> {
             pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
         }
@@ -787,10 +787,11 @@ pub struct AbsolutePathPrinter<'a, 'tcx> {
         impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
             type Error = !;
 
-            type Path = Vec<LocalInternedString>;
+            type Path = Vec<Symbol>;
             type Region = ();
             type Type = ();
             type DynExistential = ();
+            type Const = ();
 
             fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
                 self.tcx
@@ -807,19 +808,26 @@ fn print_type(self, _ty: Ty<'tcx>) -> Result<Self::Type, Self::Error> {
             fn print_dyn_existential(
                 self,
                 _predicates: &'tcx ty::List<ty::ExistentialPredicate<'tcx>>,
-                ) -> Result<Self::DynExistential, Self::Error> {
+            ) -> Result<Self::DynExistential, Self::Error> {
+                Ok(())
+            }
+
+            fn print_const(
+                self,
+                _ct: &'tcx ty::Const<'tcx>,
+            ) -> Result<Self::Const, Self::Error> {
                 Ok(())
             }
 
             fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
-                Ok(vec![self.tcx.original_crate_name(cnum).as_str()])
+                Ok(vec![self.tcx.original_crate_name(cnum)])
             }
 
             fn path_qualified(
                 self,
                 self_ty: Ty<'tcx>,
                 trait_ref: Option<ty::TraitRef<'tcx>>,
-                ) -> Result<Self::Path, Self::Error> {
+            ) -> Result<Self::Path, Self::Error> {
                 if trait_ref.is_none() {
                     if let ty::Adt(def, substs) = self_ty.sty {
                         return self.print_def_path(def.did, substs);
@@ -828,8 +836,8 @@ fn path_qualified(
 
                 // This shouldn't ever be needed, but just in case:
                 Ok(vec![match trait_ref {
-                    Some(trait_ref) => LocalInternedString::intern(&format!("{:?}", trait_ref)),
-                    None => LocalInternedString::intern(&format!("<{}>", self_ty)),
+                    Some(trait_ref) => Symbol::intern(&format!("{:?}", trait_ref)),
+                    None => Symbol::intern(&format!("<{}>", self_ty)),
                 }])
             }
 
@@ -839,16 +847,16 @@ fn path_append_impl(
                 _disambiguated_data: &DisambiguatedDefPathData,
                 self_ty: Ty<'tcx>,
                 trait_ref: Option<ty::TraitRef<'tcx>>,
-                ) -> Result<Self::Path, Self::Error> {
+            ) -> Result<Self::Path, Self::Error> {
                 let mut path = print_prefix(self)?;
 
                 // This shouldn't ever be needed, but just in case:
                 path.push(match trait_ref {
                     Some(trait_ref) => {
-                        LocalInternedString::intern(&format!("<impl {} for {}>", trait_ref,
+                        Symbol::intern(&format!("<impl {} for {}>", trait_ref,
                                                     self_ty))
                     },
-                    None => LocalInternedString::intern(&format!("<impl {}>", self_ty)),
+                    None => Symbol::intern(&format!("<impl {}>", self_ty)),
                 });
 
                 Ok(path)
@@ -858,7 +866,7 @@ fn path_append(
                 self,
                 print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
                 disambiguated_data: &DisambiguatedDefPathData,
-                ) -> Result<Self::Path, Self::Error> {
+            ) -> Result<Self::Path, Self::Error> {
                 let mut path = print_prefix(self)?;
 
                 // Skip `::{{constructor}}` on tuple/unit structs.
@@ -867,7 +875,7 @@ fn path_append(
                     _ => {}
                 }
 
-                path.push(disambiguated_data.data.as_interned_str().as_str());
+                path.push(disambiguated_data.data.as_interned_str().as_symbol());
                 Ok(path)
             }
 
@@ -875,7 +883,7 @@ fn path_generic_args(
                 self,
                 print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
                 _args: &[Kind<'tcx>],
-                ) -> Result<Self::Path, Self::Error> {
+            ) -> Result<Self::Path, Self::Error> {
                 print_prefix(self)
             }
         }