Skip to content

Commit 87708b7

Browse files
committed
Refactor away check_ribs
1 parent 210109c commit 87708b7

File tree

1 file changed

+18
-40
lines changed

1 file changed

+18
-40
lines changed

src/librustc_resolve/lib.rs

+18-40
Original file line numberDiff line numberDiff line change
@@ -1874,7 +1874,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
18741874
trait_path: &Path,
18751875
path_depth: usize)
18761876
-> Result<PathResolution, ()> {
1877-
if let Some(path_res) = self.resolve_path(id, trait_path, path_depth, TypeNS, true) {
1877+
if let Some(path_res) = self.resolve_path(id, trait_path, path_depth, TypeNS) {
18781878
if let Def::Trait(_) = path_res.base_def {
18791879
debug!("(resolving trait) found trait def: {:?}", path_res);
18801880
Ok(path_res)
@@ -1932,7 +1932,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
19321932
&hir::WherePredicate::BoundPredicate(_) |
19331933
&hir::WherePredicate::RegionPredicate(_) => {}
19341934
&hir::WherePredicate::EqPredicate(ref eq_pred) => {
1935-
let path_res = self.resolve_path(eq_pred.id, &eq_pred.path, 0, TypeNS, true);
1935+
let path_res = self.resolve_path(eq_pred.id, &eq_pred.path, 0, TypeNS);
19361936
if let Some(PathResolution { base_def: Def::TyParam(..), .. }) = path_res {
19371937
self.record_def(eq_pred.id, path_res.unwrap());
19381938
} else {
@@ -2198,8 +2198,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
21982198
let resolution = match self.resolve_possibly_assoc_item(ty.id,
21992199
maybe_qself.as_ref(),
22002200
path,
2201-
TypeNS,
2202-
true) {
2201+
TypeNS) {
22032202
// `<T>::a::b::c` is resolved by typeck alone.
22042203
TypecheckRequired => {
22052204
// Resolve embedded types.
@@ -2224,7 +2223,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
22242223
self.record_def(ty.id, err_path_resolution());
22252224

22262225
// Keep reporting some errors even if they're ignored above.
2227-
self.resolve_path(ty.id, path, 0, TypeNS, true);
2226+
self.resolve_path(ty.id, path, 0, TypeNS);
22282227

22292228
let kind = if maybe_qself.is_some() {
22302229
"associated type"
@@ -2402,8 +2401,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
24022401
let resolution = match self.resolve_possibly_assoc_item(pat_id,
24032402
None,
24042403
path,
2405-
ValueNS,
2406-
false) {
2404+
ValueNS) {
24072405
// The below shouldn't happen because all
24082406
// qualified paths should be in PatKind::QPath.
24092407
TypecheckRequired =>
@@ -2475,8 +2473,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
24752473
let resolution = match self.resolve_possibly_assoc_item(pat_id,
24762474
Some(qself),
24772475
path,
2478-
ValueNS,
2479-
false) {
2476+
ValueNS) {
24802477
TypecheckRequired => {
24812478
// All `<T>::CONST` should end up here, and will
24822479
// require use of the trait map to resolve
@@ -2526,7 +2523,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
25262523
}
25272524

25282525
PatKind::Struct(ref path, _, _) => {
2529-
match self.resolve_path(pat_id, path, 0, TypeNS, false) {
2526+
match self.resolve_path(pat_id, path, 0, TypeNS) {
25302527
Some(definition) => {
25312528
self.record_def(pattern.id, definition);
25322529
}
@@ -2607,8 +2604,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
26072604
id: NodeId,
26082605
maybe_qself: Option<&hir::QSelf>,
26092606
path: &Path,
2610-
namespace: Namespace,
2611-
check_ribs: bool)
2607+
namespace: Namespace)
26122608
-> AssocItemResolveResult {
26132609
let max_assoc_types;
26142610

@@ -2627,14 +2623,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
26272623
}
26282624

26292625
let mut resolution = self.with_no_errors(|this| {
2630-
this.resolve_path(id, path, 0, namespace, check_ribs)
2626+
this.resolve_path(id, path, 0, namespace)
26312627
});
26322628
for depth in 1..max_assoc_types {
26332629
if resolution.is_some() {
26342630
break;
26352631
}
26362632
self.with_no_errors(|this| {
2637-
resolution = this.resolve_path(id, path, depth, TypeNS, true);
2633+
resolution = this.resolve_path(id, path, depth, TypeNS);
26382634
});
26392635
}
26402636
if let Some(Def::Mod(_)) = resolution.map(|r| r.base_def) {
@@ -2644,16 +2640,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
26442640
ResolveAttempt(resolution)
26452641
}
26462642

2647-
/// If `check_ribs` is true, checks the local definitions first; i.e.
2648-
/// doesn't skip straight to the containing module.
26492643
/// Skips `path_depth` trailing segments, which is also reflected in the
26502644
/// returned value. See `middle::def::PathResolution` for more info.
26512645
pub fn resolve_path(&mut self,
26522646
id: NodeId,
26532647
path: &Path,
26542648
path_depth: usize,
2655-
namespace: Namespace,
2656-
check_ribs: bool)
2649+
namespace: Namespace)
26572650
-> Option<PathResolution> {
26582651
let span = path.span;
26592652
let segments = &path.segments[..path.segments.len() - path_depth];
@@ -2668,14 +2661,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
26682661
// Try to find a path to an item in a module.
26692662
let last_ident = segments.last().unwrap().identifier;
26702663
if segments.len() <= 1 {
2671-
let unqualified_def = self.resolve_identifier(last_ident, namespace, check_ribs, true);
2664+
let unqualified_def = self.resolve_identifier(last_ident, namespace, true);
26722665
return unqualified_def.and_then(|def| self.adjust_local_def(def, span))
26732666
.map(|def| {
26742667
PathResolution::new(def, path_depth)
26752668
});
26762669
}
26772670

2678-
let unqualified_def = self.resolve_identifier(last_ident, namespace, check_ribs, false);
2671+
let unqualified_def = self.resolve_identifier(last_ident, namespace, false);
26792672
let def = self.resolve_module_relative_path(span, segments, namespace);
26802673
match (def, unqualified_def) {
26812674
(Some(d), Some(ref ud)) if d == ud.def => {
@@ -2695,7 +2688,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
26952688
fn resolve_identifier(&mut self,
26962689
identifier: hir::Ident,
26972690
namespace: Namespace,
2698-
check_ribs: bool,
26992691
record_used: bool)
27002692
-> Option<LocalDef> {
27012693
if identifier.name == special_idents::invalid.name {
@@ -2711,20 +2703,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
27112703
}
27122704
}
27132705

2714-
if check_ribs {
2715-
return self.resolve_identifier_in_local_ribs(identifier, namespace, record_used);
2716-
}
2717-
2718-
// Check the items.
2719-
let name = identifier.unhygienic_name;
2720-
match self.resolve_item_in_lexical_scope(name, namespace, record_used) {
2721-
Success(binding) => binding.def().map(LocalDef::from_def),
2722-
Failed(Some((span, msg))) => {
2723-
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
2724-
None
2725-
}
2726-
_ => None,
2727-
}
2706+
self.resolve_identifier_in_local_ribs(identifier, namespace, record_used)
27282707
}
27292708

27302709
// Resolve a local definition, potentially adjusting for closures.
@@ -3104,8 +3083,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
31043083
let resolution = match self.resolve_possibly_assoc_item(expr.id,
31053084
maybe_qself.as_ref(),
31063085
path,
3107-
ValueNS,
3108-
true) {
3086+
ValueNS) {
31093087
// `<T>::a::b::c` is resolved by typeck alone.
31103088
TypecheckRequired => {
31113089
let method_name = path.segments.last().unwrap().identifier.name;
@@ -3165,7 +3143,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
31653143
// structs, which wouldn't result in this error.)
31663144
let path_name = path_names_to_string(path, 0);
31673145
let type_res = self.with_no_errors(|this| {
3168-
this.resolve_path(expr.id, path, 0, TypeNS, false)
3146+
this.resolve_path(expr.id, path, 0, TypeNS)
31693147
});
31703148

31713149
self.record_def(expr.id, err_path_resolution());
@@ -3186,7 +3164,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
31863164
}
31873165
_ => {
31883166
// Keep reporting some errors even if they're ignored above.
3189-
self.resolve_path(expr.id, path, 0, ValueNS, true);
3167+
self.resolve_path(expr.id, path, 0, ValueNS);
31903168

31913169
let mut method_scope = false;
31923170
self.value_ribs.iter().rev().all(|rib| {
@@ -3260,7 +3238,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
32603238
// Resolve the path to the structure it goes to. We don't
32613239
// check to ensure that the path is actually a structure; that
32623240
// is checked later during typeck.
3263-
match self.resolve_path(expr.id, path, 0, TypeNS, false) {
3241+
match self.resolve_path(expr.id, path, 0, TypeNS) {
32643242
Some(definition) => self.record_def(expr.id, definition),
32653243
None => {
32663244
debug!("(resolving expression) didn't find struct def",);

0 commit comments

Comments
 (0)