Skip to content

Commit 3bcf818

Browse files
committed
Refactor resolve_crate_relative_path and resolve_module_relative_path
to return a `NameBinding` instead of a `Def`
1 parent 6da1153 commit 3bcf818

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/librustc_resolve/lib.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,8 +1683,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
16831683
match self.resolve_crate_relative_path(prefix.span,
16841684
&prefix.segments,
16851685
TypeNS) {
1686-
Ok(def) =>
1687-
self.record_def(item.id, PathResolution::new(def, 0)),
1686+
Ok(binding) => {
1687+
let def = binding.def().unwrap();
1688+
self.record_def(item.id, PathResolution::new(def, 0));
1689+
}
16881690
Err(true) => self.record_def(item.id, err_path_resolution()),
16891691
Err(false) => {
16901692
resolve_error(self,
@@ -2547,8 +2549,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
25472549
let mk_res = |def| PathResolution::new(def, path_depth);
25482550

25492551
if path.global {
2550-
let def = self.resolve_crate_relative_path(span, segments, namespace);
2551-
return def.map(mk_res);
2552+
let binding = self.resolve_crate_relative_path(span, segments, namespace);
2553+
return binding.map(|binding| mk_res(binding.def().unwrap()));
25522554
}
25532555

25542556
// Try to find a path to an item in a module.
@@ -2584,9 +2586,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
25842586
}
25852587

25862588
let unqualified_def = resolve_identifier_with_fallback(self, false);
2587-
let def = self.resolve_module_relative_path(span, segments, namespace);
2588-
match (def, unqualified_def) {
2589-
(Ok(d), Some(ref ud)) if d == ud.def => {
2589+
let qualified_binding = self.resolve_module_relative_path(span, segments, namespace);
2590+
match (qualified_binding, unqualified_def) {
2591+
(Ok(binding), Some(ref ud)) if binding.def().unwrap() == ud.def => {
25902592
self.session
25912593
.add_lint(lint::builtin::UNUSED_QUALIFICATIONS,
25922594
id,
@@ -2596,7 +2598,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
25962598
_ => {}
25972599
}
25982600

2599-
def.map(mk_res)
2601+
qualified_binding.map(|binding| mk_res(binding.def().unwrap()))
26002602
}
26012603

26022604
// Resolve a single identifier
@@ -2707,7 +2709,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
27072709
span: Span,
27082710
segments: &[hir::PathSegment],
27092711
namespace: Namespace)
2710-
-> Result<Def, bool /* true if an error was reported */> {
2712+
-> Result<&'a NameBinding<'a>,
2713+
bool /* true if an error was reported */> {
27112714
let module_path = segments.split_last()
27122715
.unwrap()
27132716
.1
@@ -2740,7 +2743,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
27402743
let result = self.resolve_name_in_module(containing_module, name, namespace, false, true);
27412744
result.success().map(|binding| {
27422745
self.check_privacy(name, binding, span);
2743-
binding.def().unwrap()
2746+
binding
27442747
}).ok_or(false)
27452748
}
27462749

@@ -2750,7 +2753,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
27502753
span: Span,
27512754
segments: &[hir::PathSegment],
27522755
namespace: Namespace)
2753-
-> Result<Def, bool /* true if an error was reported */> {
2756+
-> Result<&'a NameBinding<'a>,
2757+
bool /* true if an error was reported */> {
27542758
let module_path = segments.split_last()
27552759
.unwrap()
27562760
.1
@@ -2790,7 +2794,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
27902794
let result = self.resolve_name_in_module(containing_module, name, namespace, false, true);
27912795
result.success().map(|binding| {
27922796
self.check_privacy(name, binding, span);
2793-
binding.def().unwrap()
2797+
binding
27942798
}).ok_or(false)
27952799
}
27962800

0 commit comments

Comments
 (0)