From 3cd7f08ed1f801c2fa4983d9eef9162739922373 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 5 Aug 2019 12:25:32 -0400 Subject: [PATCH] Force callers of resolve_ast_path to deal with Res::Err correctly --- src/librustc_resolve/lib.rs | 12 ++---------- src/librustdoc/passes/collect_intra_doc_links.rs | 7 +++++++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 3dd1d7d274d..ba703558998 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1858,16 +1858,8 @@ impl<'a> Resolver<'a> { .collect(), } }; - match self.resolve_ast_path_inner(&path, is_value) { - Ok(res) => { - if res == Res::Err { - Err(()) - } else { - Ok((path, res)) - } - } - Err(_) => Err(()), - } + let res = self.resolve_ast_path_inner(&path, is_value).map_err(|_| ())?; + Ok((path, res)) } /// Like `resolve_ast_path`, but takes a callback in case there was an error. diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 04de3374d05..84cfdd790b7 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -71,6 +71,10 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { resolver.resolve_str_path_error(DUMMY_SP, &path_str, ns == ValueNS) }) }); + let result = match result { + Ok((_, Res::Err)) => Err(()), + _ => result, + }; if let Ok((_, res)) = result { let res = res.map_id(|_| panic!("unexpected node_id")); @@ -134,6 +138,9 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { let (_, ty_res) = cx.enter_resolver(|resolver| resolver.with_scope(node_id, |resolver| { resolver.resolve_str_path_error(DUMMY_SP, &path, false) }))?; + if let Res::Err = ty_res { + return Err(()); + } let ty_res = ty_res.map_id(|_| panic!("unexpected node_id")); match ty_res { Res::Def(DefKind::Struct, did)