Prefer `Symbol` to `Ident` when there's no sensible `Span`
diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs
index 561bf20..21ea476 100644
--- a/src/librustc_lint/unused.rs
+++ b/src/librustc_lint/unused.rs
@@ -618,24 +618,19 @@
}
// Trigger the lint if the nested item is a non-self single item
- let node_ident;
- match items[0].0.kind {
+ let node_name = match items[0].0.kind {
ast::UseTreeKind::Simple(rename, ..) => {
let orig_ident = items[0].0.prefix.segments.last().unwrap().ident;
if orig_ident.name == kw::SelfLower {
return;
}
- node_ident = rename.unwrap_or(orig_ident);
+ rename.unwrap_or(orig_ident).name
}
- ast::UseTreeKind::Glob => {
- node_ident = ast::Ident::from_str("*");
- }
- ast::UseTreeKind::Nested(_) => {
- return;
- }
- }
+ ast::UseTreeKind::Glob => Symbol::intern("*"),
+ ast::UseTreeKind::Nested(_) => return,
+ };
- let msg = format!("braces around {} is unnecessary", node_ident.name);
+ let msg = format!("braces around {} is unnecessary", node_name);
cx.span_lint(UNUSED_IMPORT_BRACES, item.span, &msg);
}
}
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index f97fcb0..74f68e5 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -40,7 +40,7 @@
use syntax::ext::hygiene::{ExpnId, Transparency, SyntaxContext};
use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy};
use syntax::ext::base::{SyntaxExtension, MacroKind, SpecialDerives};
-use syntax::symbol::{Symbol, kw, sym};
+use syntax::symbol::{kw, sym};
use syntax::visit::{self, Visitor};
use syntax::attr;
@@ -241,7 +241,7 @@
fn names_to_string(segments: &[Segment]) -> String {
names_to_string(&segments.iter()
- .map(|seg| seg.ident)
+ .map(|seg| seg.ident.name)
.collect::<Vec<_>>())
}
}
@@ -951,7 +951,7 @@
struct_constructors: DefIdMap<(Res, ty::Visibility)>,
/// Features enabled for this crate.
- active_features: FxHashSet<Symbol>,
+ active_features: FxHashSet<Name>,
/// Stores enum visibilities to properly build a reduced graph
/// when visiting the correspondent variants.
@@ -1018,8 +1018,8 @@
fn resolve_str_path(
&mut self,
span: Span,
- crate_root: Option<Symbol>,
- components: &[Symbol],
+ crate_root: Option<Name>,
+ components: &[Name],
ns: Namespace,
) -> (ast::Path, Res) {
let root = if crate_root.is_some() {
@@ -2555,7 +2555,7 @@
fn add_suggestion_for_rename_of_use(
&self,
err: &mut DiagnosticBuilder<'_>,
- name: Symbol,
+ name: Name,
directive: &ImportDirective<'_>,
binding_span: Span,
) {
@@ -2770,22 +2770,22 @@
}
}
-fn names_to_string(idents: &[Ident]) -> String {
+fn names_to_string(names: &[Name]) -> String {
let mut result = String::new();
- for (i, ident) in idents.iter()
- .filter(|ident| ident.name != kw::PathRoot)
+ for (i, name) in names.iter()
+ .filter(|name| **name != kw::PathRoot)
.enumerate() {
if i > 0 {
result.push_str("::");
}
- result.push_str(&ident.as_str());
+ result.push_str(&name.as_str());
}
result
}
fn path_names_to_string(path: &Path) -> String {
names_to_string(&path.segments.iter()
- .map(|seg| seg.ident)
+ .map(|seg| seg.ident.name)
.collect::<Vec<_>>())
}
@@ -2793,15 +2793,14 @@
fn module_to_string(module: Module<'_>) -> Option<String> {
let mut names = Vec::new();
- fn collect_mod(names: &mut Vec<Ident>, module: Module<'_>) {
+ fn collect_mod(names: &mut Vec<Name>, module: Module<'_>) {
if let ModuleKind::Def(.., name) = module.kind {
if let Some(parent) = module.parent {
- names.push(Ident::with_dummy_span(name));
+ names.push(name);
collect_mod(names, parent);
}
} else {
- // danger, shouldn't be ident?
- names.push(Ident::from_str("<opaque>"));
+ names.push(Name::intern("<opaque>"));
collect_mod(names, module.parent.unwrap());
}
}
@@ -2810,9 +2809,8 @@
if names.is_empty() {
return None;
}
- Some(names_to_string(&names.into_iter()
- .rev()
- .collect::<Vec<_>>()))
+ names.reverse();
+ Some(names_to_string(&names))
}
#[derive(Copy, Clone, Debug)]
diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs
index eb509f1..e77e829 100644
--- a/src/librustc_resolve/resolve_imports.rs
+++ b/src/librustc_resolve/resolve_imports.rs
@@ -1433,15 +1433,17 @@
let global = !names.is_empty() && names[0].name == kw::PathRoot;
if let Some(pos) = pos {
let names = if global { &names[1..pos + 1] } else { &names[..pos + 1] };
- names_to_string(names)
+ names_to_string(&names.iter().map(|ident| ident.name).collect::<Vec<_>>())
} else {
let names = if global { &names[1..] } else { names };
if names.is_empty() {
import_directive_subclass_to_string(subclass)
} else {
- format!("{}::{}",
- names_to_string(names),
- import_directive_subclass_to_string(subclass))
+ format!(
+ "{}::{}",
+ names_to_string(&names.iter().map(|ident| ident.name).collect::<Vec<_>>()),
+ import_directive_subclass_to_string(subclass),
+ )
}
}
}