Skip to content

Commit af961c1

Browse files
committed
Fix nits
1 parent 18571da commit af961c1

File tree

3 files changed

+95
-108
lines changed

3 files changed

+95
-108
lines changed

src/librustc_resolve/lib.rs

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ mod check_unused;
8484
mod build_reduced_graph;
8585
mod resolve_imports;
8686

87-
pub struct ResolvePath<'a>
88-
{
89-
ident : &'a [Ident],
90-
source : Option<NodeId>, // None if this path is speculative
91-
speculative : bool,
87+
pub struct ResolvePath<'a> {
88+
ident: &'a [Ident],
89+
/// NodeId of the path that we are attempting to resolve. When None, this path is being
90+
/// speculatively resolved and we should not emit errors or lints about it
91+
source: Option<NodeId>,
9292
}
9393

9494
/// A free importable items suggested in case of resolution failure.
@@ -1662,17 +1662,16 @@ impl<'a> Resolver<'a> {
16621662
.map(|seg| Ident::new(seg.name, span))
16631663
.collect();
16641664

1665-
let resolve_path = ResolvePath {
1666-
ident : &path,
1667-
source : None,
1668-
speculative : true,
1669-
};
1665+
let path = ResolvePath {
1666+
ident: &path,
1667+
source: None,
1668+
};
16701669
// FIXME (Manishearth): Intra doc links won't get warned of epoch changes
1671-
match self.resolve_path(&resolve_path, Some(namespace), true, span) {
1670+
match self.resolve_path(&path, Some(namespace), true, span) {
16721671
PathResult::Module(module) => *def = module.def().unwrap(),
16731672
PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 =>
16741673
*def = path_res.base_def(),
1675-
PathResult::NonModule(..) => match self.resolve_path(&resolve_path, None, true, span) {
1674+
PathResult::NonModule(..) => match self.resolve_path(&path, None, true, span) {
16761675
PathResult::Failed(span, msg, _) => {
16771676
error_callback(self, span, ResolutionError::FailedToResolve(&msg));
16781677
}
@@ -2365,10 +2364,9 @@ impl<'a> Resolver<'a> {
23652364
.map(|seg| seg.ident)
23662365
.collect();
23672366
let path = ResolvePath {
2368-
ident : &path,
2369-
source : Some(trait_ref.ref_id),
2370-
speculative : false,
2371-
};
2367+
ident: &path,
2368+
source: Some(trait_ref.ref_id),
2369+
};
23722370
let def = self.smart_resolve_path_fragment(
23732371
trait_ref.ref_id,
23742372
None,
@@ -2805,10 +2803,9 @@ impl<'a> Resolver<'a> {
28052803
.map(|seg| seg.ident)
28062804
.collect::<Vec<_>>();
28072805
let resolve_path = ResolvePath {
2808-
ident : &segments,
2809-
source : Some(id),
2810-
speculative : false,
2811-
};
2806+
ident: &segments,
2807+
source: Some(id),
2808+
};
28122809
self.smart_resolve_path_fragment(id, qself, &resolve_path, path.span, source)
28132810
}
28142811

@@ -2844,10 +2841,9 @@ impl<'a> Resolver<'a> {
28442841
(format!(""), format!("the crate root"))
28452842
} else {
28462843
let mod_path = ResolvePath {
2847-
ident : &path.ident[..path.ident.len() - 1],
2848-
source : Some(id),
2849-
speculative : false,
2850-
};
2844+
ident: &path.ident[..path.ident.len() - 1],
2845+
source: Some(id),
2846+
};
28512847
let mod_prefix = match this.resolve_path(&mod_path, Some(TypeNS),
28522848
false, span) {
28532849
PathResult::Module(module) => module.def(),
@@ -3172,12 +3168,11 @@ impl<'a> Resolver<'a> {
31723168
}
31733169
// Make sure `A::B` in `<T as A>::B::C` is a trait item.
31743170
let ns = if qself.position + 1 == path.ident.len() { ns } else { TypeNS };
3175-
let resolve_path = ResolvePath {
3176-
ident : &path.ident[..qself.position + 1],
3177-
source : Some(id),
3178-
speculative : false,
3179-
};
3180-
let res = self.smart_resolve_path_fragment(id, None, &resolve_path,
3171+
let path = ResolvePath {
3172+
ident: &path.ident[..qself.position + 1],
3173+
source: Some(id),
3174+
};
3175+
let res = self.smart_resolve_path_fragment(id, None, &path,
31813176
span, PathSource::TraitItem(ns));
31823177
return Some(PathResolution::with_unresolved_segments(
31833178
res.base_def(), res.unresolved_segments() + path.ident.len() - qself.position - 1
@@ -3221,12 +3216,11 @@ impl<'a> Resolver<'a> {
32213216
path.ident[0].name != keywords::CrateRoot.name() &&
32223217
path.ident[0].name != keywords::DollarCrate.name() {
32233218
let unqualified_result = {
3224-
let resolve_path = ResolvePath {
3225-
ident : &[*path.ident.last().unwrap()],
3226-
source : None,
3227-
speculative : true,
3228-
};
3229-
match self.resolve_path(&resolve_path, Some(ns), false, span) {
3219+
let path = ResolvePath {
3220+
ident: &[*path.ident.last().unwrap()],
3221+
source: None,
3222+
};
3223+
match self.resolve_path(&path, Some(ns), false, span) {
32303224
PathResult::NonModule(path_res) => path_res.base_def(),
32313225
PathResult::Module(module) => module.def().unwrap(),
32323226
_ => return Some(result),
@@ -3639,10 +3633,9 @@ impl<'a> Resolver<'a> {
36393633
} else {
36403634
// Search in module.
36413635
let mod_path = ResolvePath {
3642-
ident : &path[..path.len() - 1],
3643-
source : None,
3644-
speculative : true,
3645-
};
3636+
ident: &path[..path.len() - 1],
3637+
source: None,
3638+
};
36463639
if let PathResult::Module(module) = self.resolve_path(&mod_path, Some(TypeNS),
36473640
false, span) {
36483641
add_module_candidates(module, &mut names);
@@ -4062,12 +4055,12 @@ impl<'a> Resolver<'a> {
40624055
let segments = path.make_root().iter().chain(path.segments.iter())
40634056
.map(|seg| seg.ident)
40644057
.collect::<Vec<_>>();
4065-
let resolve_path = ResolvePath {
4066-
ident : &segments,
4067-
source : None,
4068-
speculative : true,
4069-
};
4070-
let def = self.smart_resolve_path_fragment(id, None, &resolve_path, path.span,
4058+
let span = path.span;
4059+
let path = ResolvePath {
4060+
ident: &segments,
4061+
source: None,
4062+
};
4063+
let def = self.smart_resolve_path_fragment(id, None, &path, span,
40714064
PathSource::Visibility).base_def();
40724065
if def == Def::Err {
40734066
ty::Visibility::Public
@@ -4076,8 +4069,8 @@ impl<'a> Resolver<'a> {
40764069
if self.is_accessible(vis) {
40774070
vis
40784071
} else {
4079-
self.session.span_err(path.span, "visibilities can only be restricted \
4080-
to ancestor modules");
4072+
self.session.span_err(span, "visibilities can only be restricted \
4073+
to ancestor modules");
40814074
ty::Visibility::Public
40824075
}
40834076
}

src/librustc_resolve/macros.rs

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,15 @@ impl<'a> Resolver<'a> {
426426
-> Result<Def, Determinacy> {
427427
let ast::Path { ref segments, span } = *path;
428428
let path: Vec<_> = segments.iter().map(|seg| seg.ident).collect();
429+
let path = ResolvePath {
430+
ident: &path,
431+
source: None,
432+
};
429433
let invocation = self.invocations[&scope];
430434
let module = invocation.module.get();
431435
self.current_module = if module.is_trait() { module.parent.unwrap() } else { module };
432436

433-
if path.len() > 1 {
437+
if path.ident.len() > 1 {
434438
if !self.use_extern_macros && self.gated_errors.insert(span) {
435439
let msg = "non-ident macro paths are experimental";
436440
let feature = "use_extern_macros";
@@ -439,43 +443,37 @@ impl<'a> Resolver<'a> {
439443
return Err(Determinacy::Determined);
440444
}
441445

442-
let def = {
443-
let resolve_path = ResolvePath {
444-
ident : &path,
445-
source : None,
446-
speculative : false,
447-
};
448-
match self.resolve_path(&resolve_path, Some(MacroNS), false, span) {
449-
PathResult::NonModule(path_res) => match path_res.base_def() {
450-
Def::Err => Err(Determinacy::Determined),
451-
def @ _ => {
452-
if path_res.unresolved_segments() > 0 {
453-
self.found_unresolved_macro = true;
454-
self.session.span_err(span, "fail to resolve non-ident macro path");
455-
Err(Determinacy::Determined)
456-
} else {
457-
Ok(def)
458-
}
446+
let def = match self.resolve_path(&path, Some(MacroNS), false, span) {
447+
PathResult::NonModule(path_res) => match path_res.base_def() {
448+
Def::Err => Err(Determinacy::Determined),
449+
def @ _ => {
450+
if path_res.unresolved_segments() > 0 {
451+
self.found_unresolved_macro = true;
452+
self.session.span_err(span, "fail to resolve non-ident macro path");
453+
Err(Determinacy::Determined)
454+
} else {
455+
Ok(def)
459456
}
460-
},
461-
PathResult::Module(..) => unreachable!(),
462-
PathResult::Indeterminate if !force => return Err(Determinacy::Undetermined),
463-
_ => {
464-
self.found_unresolved_macro = true;
465-
Err(Determinacy::Determined)
466-
},
467-
}
457+
}
458+
},
459+
PathResult::Module(..) => unreachable!(),
460+
PathResult::Indeterminate if !force => return Err(Determinacy::Undetermined),
461+
_ => {
462+
self.found_unresolved_macro = true;
463+
Err(Determinacy::Determined)
464+
},
468465
};
469466
self.current_module.nearest_item_scope().macro_resolutions.borrow_mut()
470-
.push((path.into_boxed_slice(), span));
467+
.push((path_segments.into_boxed_slice(), span));
471468
return def;
472469
}
473470

474-
let legacy_resolution = self.resolve_legacy_scope(&invocation.legacy_scope, path[0], false);
471+
let legacy_resolution = self.resolve_legacy_scope(&invocation.legacy_scope, path.ident[0],
472+
false);
475473
let result = if let Some(MacroBinding::Legacy(binding)) = legacy_resolution {
476474
Ok(Def::Macro(binding.def_id, MacroKind::Bang))
477475
} else {
478-
match self.resolve_lexical_macro_path_segment(path[0], MacroNS, false, span) {
476+
match self.resolve_lexical_macro_path_segment(path.ident[0], MacroNS, false, span) {
479477
Ok(binding) => Ok(binding.binding().def_ignoring_ambiguity()),
480478
Err(Determinacy::Undetermined) if !force => return Err(Determinacy::Undetermined),
481479
Err(_) => {
@@ -486,7 +484,7 @@ impl<'a> Resolver<'a> {
486484
};
487485

488486
self.current_module.nearest_item_scope().legacy_macro_resolutions.borrow_mut()
489-
.push((scope, path[0], span, kind));
487+
.push((scope, path.ident[0], span, kind));
490488

491489
result
492490
}
@@ -624,12 +622,11 @@ impl<'a> Resolver<'a> {
624622
pub fn finalize_current_module_macro_resolutions(&mut self) {
625623
let module = self.current_module;
626624
for &(ref path, span) in module.macro_resolutions.borrow().iter() {
627-
let resolve_path = ResolvePath {
628-
ident : &path,
629-
source : None,
630-
speculative : true,
631-
};
632-
match self.resolve_path(&resolve_path, Some(MacroNS), true, span) {
625+
let path = ResolvePath {
626+
ident: &path,
627+
source: None,
628+
};
629+
match self.resolve_path(&path, Some(MacroNS), true, span) {
633630
PathResult::NonModule(_) => {},
634631
PathResult::Failed(span, msg, _) => {
635632
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));

src/librustc_resolve/resolve_imports.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,11 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
535535
// For better failure detection, pretend that the import will not define any names
536536
// while resolving its module path.
537537
directive.vis.set(ty::Visibility::Invisible);
538-
let resolve_path = ResolvePath {
539-
ident : &directive.module_path[..],
540-
source : Some(directive.id),
541-
speculative : false,
542-
};
543-
let result = self.resolve_path(&resolve_path, None, false, directive.span);
538+
let path = ResolvePath {
539+
ident: &directive.module_path[..],
540+
source: Some(directive.id),
541+
};
542+
let result = self.resolve_path(&path, None, false, directive.span);
544543
directive.vis.set(vis);
545544

546545
match result {
@@ -668,35 +667,33 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
668667
}
669668
}
670669

671-
let module_resolve_path = ResolvePath {
672-
ident : &module_path,
673-
source : Some(directive.id),
674-
speculative : false,
675-
};
676-
let module_result = self.resolve_path(&module_resolve_path, None, true, span);
670+
let module_path = ResolvePath {
671+
ident: &module_path,
672+
source: Some(directive.id),
673+
};
674+
let module_result = self.resolve_path(&module_path, None, true, span);
677675
let module = match module_result {
678676
PathResult::Module(module) => module,
679677
PathResult::Failed(span, msg, false) => {
680678
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
681679
return None;
682680
}
683681
PathResult::Failed(span, msg, true) => {
684-
let (mut self_path, mut self_result) = (module_path.clone(), None);
682+
let (mut self_path_ident, mut self_result) = (module_path.ident.clone(), None);
685683
let is_special = |ident| token::is_path_segment_keyword(ident) &&
686684
ident.name != keywords::CrateRoot.name();
687-
if !self_path.is_empty() && !is_special(self_path[0]) &&
688-
!(self_path.len() > 1 && is_special(self_path[1])) {
689-
self_path[0].name = keywords::SelfValue.name();
690-
691-
let self_resolve_path = ResolvePath {
692-
ident : &self_path,
693-
source : None,
694-
speculative : true,
695-
};
696-
self_result = Some(self.resolve_path(&self_resolve_path, None, false, span));
685+
if !self_path_ident.is_empty() && !is_special(self_path_ident[0]) &&
686+
!(self_path_ident.len() > 1 && is_special(self_path_ident[1])) {
687+
self_path_ident[0].name = keywords::SelfValue.name();
688+
let self_path = ResolvePath {
689+
ident: self_path_ident,
690+
source: None,
691+
};
692+
self_result = Some(self.resolve_path(&self_path, None, false, span));
697693
}
698694
return if let Some(PathResult::Module(..)) = self_result {
699-
Some((span, format!("Did you mean `{}`?", names_to_string(&self_path[..]))))
695+
Some((span, format!("Did you mean `{}`?",
696+
names_to_string(&self_path_ident[..]))))
700697
} else {
701698
Some((span, msg))
702699
};

0 commit comments

Comments
 (0)