rustc_hir: Less error-prone methods for accessing PartialRes resolution
This commit is contained in:
@@ -642,8 +642,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
|
||||
// Check whether we should interpret this as a bare trait object.
|
||||
if qself.is_none()
|
||||
&& let Some(partial_res) = self.r.partial_res_map.get(&ty.id)
|
||||
&& partial_res.unresolved_segments() == 0
|
||||
&& let Res::Def(DefKind::Trait | DefKind::TraitAlias, _) = partial_res.base_res()
|
||||
&& let Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) = partial_res.full_res()
|
||||
{
|
||||
// This path is actually a bare trait object. In case of a bare `Fn`-trait
|
||||
// object with anonymous lifetimes, we need this rib to correctly place the
|
||||
@@ -1930,7 +1929,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
match ty.kind {
|
||||
TyKind::ImplicitSelf => true,
|
||||
TyKind::Path(None, _) => {
|
||||
let path_res = self.r.partial_res_map[&ty.id].base_res();
|
||||
let path_res = self.r.partial_res_map[&ty.id].expect_full_res();
|
||||
if let Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } = path_res {
|
||||
return true;
|
||||
}
|
||||
@@ -1971,7 +1970,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
None
|
||||
}
|
||||
})
|
||||
.map(|res| res.base_res())
|
||||
.map(|res| res.expect_full_res())
|
||||
.filter(|res| {
|
||||
// Permit the types that unambiguously always
|
||||
// result in the same type constructor being used
|
||||
@@ -2531,7 +2530,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
Finalize::new(trait_ref.ref_id, trait_ref.path.span),
|
||||
);
|
||||
self.diagnostic_metadata.currently_processing_impl_trait = None;
|
||||
if let Some(def_id) = res.base_res().opt_def_id() {
|
||||
if let Some(def_id) = res.expect_full_res().opt_def_id() {
|
||||
new_id = Some(def_id);
|
||||
new_val = Some((self.r.expect_module(def_id), trait_ref.clone()));
|
||||
}
|
||||
@@ -2860,7 +2859,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
}
|
||||
|
||||
fn is_base_res_local(&self, nid: NodeId) -> bool {
|
||||
matches!(self.r.partial_res_map.get(&nid).map(|res| res.base_res()), Some(Res::Local(..)))
|
||||
matches!(
|
||||
self.r.partial_res_map.get(&nid).map(|res| res.expect_full_res()),
|
||||
Some(Res::Local(..))
|
||||
)
|
||||
}
|
||||
|
||||
/// Checks that all of the arms in an or-pattern have exactly the
|
||||
@@ -3347,12 +3349,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
source.defer_to_typeck(),
|
||||
finalize,
|
||||
) {
|
||||
Ok(Some(partial_res)) if partial_res.unresolved_segments() == 0 => {
|
||||
if source.is_expected(partial_res.base_res()) || partial_res.base_res() == Res::Err
|
||||
{
|
||||
Ok(Some(partial_res)) if let Some(res) = partial_res.full_res() => {
|
||||
if source.is_expected(res) || res == Res::Err {
|
||||
partial_res
|
||||
} else {
|
||||
report_errors(self, Some(partial_res.base_res()))
|
||||
report_errors(self, Some(res))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3560,20 +3561,21 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
};
|
||||
|
||||
if path.len() > 1
|
||||
&& result.base_res() != Res::Err
|
||||
&& let Some(res) = result.full_res()
|
||||
&& res != Res::Err
|
||||
&& path[0].ident.name != kw::PathRoot
|
||||
&& path[0].ident.name != kw::DollarCrate
|
||||
{
|
||||
let unqualified_result = {
|
||||
match self.resolve_path(&[*path.last().unwrap()], Some(ns), None) {
|
||||
PathResult::NonModule(path_res) => path_res.base_res(),
|
||||
PathResult::NonModule(path_res) => path_res.expect_full_res(),
|
||||
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
|
||||
module.res().unwrap()
|
||||
}
|
||||
_ => return Ok(Some(result)),
|
||||
}
|
||||
};
|
||||
if result.base_res() == unqualified_result {
|
||||
if res == unqualified_result {
|
||||
let lint = lint::builtin::UNUSED_QUALIFICATIONS;
|
||||
self.r.lint_buffer.buffer_lint(
|
||||
lint,
|
||||
|
||||
Reference in New Issue
Block a user