Skip to content

Commit e8d2f62

Browse files
committed
Prefer Symbol to Ident when there's no sensible Span
1 parent ca3766e commit e8d2f62

File tree

3 files changed

+28
-33
lines changed

3 files changed

+28
-33
lines changed

src/librustc_lint/unused.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -618,24 +618,19 @@ impl UnusedImportBraces {
618618
}
619619

620620
// Trigger the lint if the nested item is a non-self single item
621-
let node_ident;
622-
match items[0].0.kind {
621+
let node_name = match items[0].0.kind {
623622
ast::UseTreeKind::Simple(rename, ..) => {
624623
let orig_ident = items[0].0.prefix.segments.last().unwrap().ident;
625624
if orig_ident.name == kw::SelfLower {
626625
return;
627626
}
628-
node_ident = rename.unwrap_or(orig_ident);
627+
rename.unwrap_or(orig_ident).name
629628
}
630-
ast::UseTreeKind::Glob => {
631-
node_ident = ast::Ident::from_str("*");
632-
}
633-
ast::UseTreeKind::Nested(_) => {
634-
return;
635-
}
636-
}
629+
ast::UseTreeKind::Glob => Symbol::intern("*"),
630+
ast::UseTreeKind::Nested(_) => return,
631+
};
637632

638-
let msg = format!("braces around {} is unnecessary", node_ident.name);
633+
let msg = format!("braces around {} is unnecessary", node_name);
639634
cx.span_lint(UNUSED_IMPORT_BRACES, item.span, &msg);
640635
}
641636
}

src/librustc_resolve/lib.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use rustc_metadata::cstore::CStore;
4040
use syntax::ext::hygiene::{ExpnId, Transparency, SyntaxContext};
4141
use syntax::ast::{self, Name, NodeId, Ident, FloatTy, IntTy, UintTy};
4242
use syntax::ext::base::{SyntaxExtension, MacroKind, SpecialDerives};
43-
use syntax::symbol::{Symbol, kw, sym};
43+
use syntax::symbol::{kw, sym};
4444

4545
use syntax::visit::{self, Visitor};
4646
use syntax::attr;
@@ -241,7 +241,7 @@ impl Segment {
241241

242242
fn names_to_string(segments: &[Segment]) -> String {
243243
names_to_string(&segments.iter()
244-
.map(|seg| seg.ident)
244+
.map(|seg| seg.ident.name)
245245
.collect::<Vec<_>>())
246246
}
247247
}
@@ -951,7 +951,7 @@ pub struct Resolver<'a> {
951951
struct_constructors: DefIdMap<(Res, ty::Visibility)>,
952952

953953
/// Features enabled for this crate.
954-
active_features: FxHashSet<Symbol>,
954+
active_features: FxHashSet<Name>,
955955

956956
/// Stores enum visibilities to properly build a reduced graph
957957
/// when visiting the correspondent variants.
@@ -1018,8 +1018,8 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
10181018
fn resolve_str_path(
10191019
&mut self,
10201020
span: Span,
1021-
crate_root: Option<Symbol>,
1022-
components: &[Symbol],
1021+
crate_root: Option<Name>,
1022+
components: &[Name],
10231023
ns: Namespace,
10241024
) -> (ast::Path, Res) {
10251025
let root = if crate_root.is_some() {
@@ -2555,7 +2555,7 @@ impl<'a> Resolver<'a> {
25552555
fn add_suggestion_for_rename_of_use(
25562556
&self,
25572557
err: &mut DiagnosticBuilder<'_>,
2558-
name: Symbol,
2558+
name: Name,
25592559
directive: &ImportDirective<'_>,
25602560
binding_span: Span,
25612561
) {
@@ -2770,38 +2770,37 @@ impl<'a> Resolver<'a> {
27702770
}
27712771
}
27722772

2773-
fn names_to_string(idents: &[Ident]) -> String {
2773+
fn names_to_string(names: &[Name]) -> String {
27742774
let mut result = String::new();
2775-
for (i, ident) in idents.iter()
2776-
.filter(|ident| ident.name != kw::PathRoot)
2775+
for (i, name) in names.iter()
2776+
.filter(|name| **name != kw::PathRoot)
27772777
.enumerate() {
27782778
if i > 0 {
27792779
result.push_str("::");
27802780
}
2781-
result.push_str(&ident.as_str());
2781+
result.push_str(&name.as_str());
27822782
}
27832783
result
27842784
}
27852785

27862786
fn path_names_to_string(path: &Path) -> String {
27872787
names_to_string(&path.segments.iter()
2788-
.map(|seg| seg.ident)
2788+
.map(|seg| seg.ident.name)
27892789
.collect::<Vec<_>>())
27902790
}
27912791

27922792
/// A somewhat inefficient routine to obtain the name of a module.
27932793
fn module_to_string(module: Module<'_>) -> Option<String> {
27942794
let mut names = Vec::new();
27952795

2796-
fn collect_mod(names: &mut Vec<Ident>, module: Module<'_>) {
2796+
fn collect_mod(names: &mut Vec<Name>, module: Module<'_>) {
27972797
if let ModuleKind::Def(.., name) = module.kind {
27982798
if let Some(parent) = module.parent {
2799-
names.push(Ident::with_dummy_span(name));
2799+
names.push(name);
28002800
collect_mod(names, parent);
28012801
}
28022802
} else {
2803-
// danger, shouldn't be ident?
2804-
names.push(Ident::from_str("<opaque>"));
2803+
names.push(Name::intern("<opaque>"));
28052804
collect_mod(names, module.parent.unwrap());
28062805
}
28072806
}
@@ -2810,9 +2809,8 @@ fn module_to_string(module: Module<'_>) -> Option<String> {
28102809
if names.is_empty() {
28112810
return None;
28122811
}
2813-
Some(names_to_string(&names.into_iter()
2814-
.rev()
2815-
.collect::<Vec<_>>()))
2812+
names.reverse();
2813+
Some(names_to_string(&names))
28162814
}
28172815

28182816
#[derive(Copy, Clone, Debug)]

src/librustc_resolve/resolve_imports.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,15 +1433,17 @@ fn import_path_to_string(names: &[Ident],
14331433
let global = !names.is_empty() && names[0].name == kw::PathRoot;
14341434
if let Some(pos) = pos {
14351435
let names = if global { &names[1..pos + 1] } else { &names[..pos + 1] };
1436-
names_to_string(names)
1436+
names_to_string(&names.iter().map(|ident| ident.name).collect::<Vec<_>>())
14371437
} else {
14381438
let names = if global { &names[1..] } else { names };
14391439
if names.is_empty() {
14401440
import_directive_subclass_to_string(subclass)
14411441
} else {
1442-
format!("{}::{}",
1443-
names_to_string(names),
1444-
import_directive_subclass_to_string(subclass))
1442+
format!(
1443+
"{}::{}",
1444+
names_to_string(&names.iter().map(|ident| ident.name).collect::<Vec<_>>()),
1445+
import_directive_subclass_to_string(subclass),
1446+
)
14451447
}
14461448
}
14471449
}

0 commit comments

Comments
 (0)