Skip to content

Commit 254fad9

Browse files
committed
Use LocalInternedString inside of AbsolutePathPrinter
1 parent dae5c9c commit 254fad9

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

clippy_lints/src/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
245245
let def = self.tables.qpath_def(qpath, callee.hir_id);
246246
if let Some(def_id) = def.opt_def_id();
247247
let def_path = get_def_path(self.tcx, def_id);
248-
if let &["core", "num", impl_ty, "max_value"] = &def_path.iter().map(|s| s.as_str()).collect::<Vec<_>>()[..];
248+
if let &["core", "num", impl_ty, "max_value"] = &def_path[..];
249249
then {
250250
let value = match impl_ty {
251251
"<impl i8>" => i8::max_value() as u128,

clippy_lints/src/utils/mod.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use rustc_errors::Applicability;
4343
use syntax::ast::{self, LitKind};
4444
use syntax::attr;
4545
use syntax::source_map::{Span, DUMMY_SP};
46-
use syntax::symbol::{keywords, Symbol};
46+
use syntax::symbol::{keywords, Symbol, LocalInternedString};
4747

4848
use crate::reexport::*;
4949

@@ -107,7 +107,7 @@ use rustc::ty::print::Printer;
107107
impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
108108
type Error = !;
109109

110-
type Path = Vec<String>;
110+
type Path = Vec<LocalInternedString>;
111111
type Region = ();
112112
type Type = ();
113113
type DynExistential = ();
@@ -141,17 +141,18 @@ impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
141141
self,
142142
cnum: CrateNum,
143143
) -> Result<Self::Path, Self::Error> {
144-
Ok(vec![self.tcx.original_crate_name(cnum).to_string()])
144+
Ok(vec![self.tcx.original_crate_name(cnum).as_str()])
145145
}
146+
146147
fn path_qualified(
147148
self,
148149
self_ty: Ty<'tcx>,
149150
trait_ref: Option<ty::TraitRef<'tcx>>,
150151
) -> Result<Self::Path, Self::Error> {
151152
// This shouldn't ever be needed, but just in case:
152153
Ok(vec![match trait_ref {
153-
Some(trait_ref) => format!("{:?}", trait_ref),
154-
None => format!("<{}>", self_ty),
154+
Some(trait_ref) => Symbol::intern(&format!("{:?}", trait_ref)).as_str(),
155+
None => Symbol::intern(&format!("<{}>", self_ty)).as_str(),
155156
}])
156157
}
157158

@@ -167,22 +168,24 @@ impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
167168
// This shouldn't ever be needed, but just in case:
168169
path.push(match trait_ref {
169170
Some(trait_ref) => {
170-
format!("<impl {} for {}>", trait_ref, self_ty)
171+
Symbol::intern(&format!("<impl {} for {}>", trait_ref, self_ty)).as_str()
171172
}
172-
None => format!("<impl {}>", self_ty),
173+
None => Symbol::intern(&format!("<impl {}>", self_ty)).as_str(),
173174
});
174175

175176
Ok(path)
176177
}
178+
177179
fn path_append(
178180
self,
179181
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
180182
disambiguated_data: &DisambiguatedDefPathData,
181183
) -> Result<Self::Path, Self::Error> {
182184
let mut path = print_prefix(self)?;
183-
path.push(disambiguated_data.data.as_interned_str().to_string());
185+
path.push(disambiguated_data.data.as_interned_str().as_str());
184186
Ok(path)
185187
}
188+
186189
fn path_generic_args(
187190
self,
188191
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
@@ -215,8 +218,8 @@ pub fn match_def_path<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, path
215218
/// // The given `def_id` is that of an `Option` type
216219
/// };
217220
/// ```
218-
pub fn get_def_path<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Vec<String> {
219-
AbsolutePathPrinter { tcx }.print_def_path(def_id, &[]).unwrap()
221+
pub fn get_def_path<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Vec<&'static str> {
222+
AbsolutePathPrinter { tcx }.print_def_path(def_id, &[]).unwrap().iter().map(LocalInternedString::get).collect()
220223
}
221224

222225
/// Checks if type is struct, enum or union type with the given def path.

0 commit comments

Comments
 (0)