Skip to content

Commit 97b24c3

Browse files
committed
[NOT USEFUL] Start working on rust-lang#74207
This doesn't do what we actually want, which is apply the smart suggestions from https://doc.rust-lang.org/nightly/nightly-rustc/rustc_resolve/late/struct.LateResolutionVisitor.html#method.smart_resolve_report_errors.
1 parent 9900178 commit 97b24c3

File tree

4 files changed

+98
-63
lines changed

4 files changed

+98
-63
lines changed

src/librustc_resolve/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::{ParentScope, PathResult, ResolutionError, Resolver, Scope, ScopeSet,
3131
type Res = def::Res<ast::NodeId>;
3232

3333
/// A vector of spans and replacements, a message and applicability.
34-
crate type Suggestion = (Vec<(Span, String)>, String, Applicability);
34+
pub type Suggestion = (Vec<(Span, String)>, String, Applicability);
3535

3636
/// Potential candidate for an undeclared or out-of-scope label - contains the ident of a
3737
/// similarly named label and whether or not it is reachable.

src/librustc_resolve/lib.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ use std::{cmp, fmt, iter, ptr};
6060
use tracing::debug;
6161

6262
use diagnostics::{extend_span_to_previous_binding, find_span_of_binding_until_next_binding};
63-
use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion};
63+
use diagnostics::{ImportSuggestion, LabelSuggestion};
64+
pub use diagnostics::Suggestion;
6465
use imports::{Import, ImportKind, ImportResolver, NameResolution};
6566
use late::{HasGenericParams, PathSource, Rib, RibKind::*};
6667
use macros::{MacroRulesBinding, MacroRulesScope};
@@ -3041,16 +3042,16 @@ impl<'a> Resolver<'a> {
30413042

30423043
/// Rustdoc uses this to resolve things in a recoverable way. `ResolutionError<'a>`
30433044
/// isn't something that can be returned because it can't be made to live that long,
3044-
/// and also it's a private type. Fortunately rustdoc doesn't need to know the error,
3045-
/// just that an error occurred.
3045+
/// and also it's a private type. However, we can still return the suggestion in case
3046+
/// an item failed to resolve.
30463047
// FIXME(Manishearth): intra-doc links won't get warned of epoch changes.
30473048
pub fn resolve_str_path_error(
30483049
&mut self,
30493050
span: Span,
30503051
path_str: &str,
30513052
ns: Namespace,
30523053
module_id: DefId,
3053-
) -> Result<(ast::Path, Res), ()> {
3054+
) -> Result<(ast::Path, Res), Option<Suggestion>> {
30543055
let path = if path_str.starts_with("::") {
30553056
ast::Path {
30563057
span,
@@ -3071,8 +3072,11 @@ impl<'a> Resolver<'a> {
30713072
};
30723073
let module = self.get_module(module_id);
30733074
let parent_scope = &ParentScope::module(module);
3074-
let res = self.resolve_ast_path(&path, ns, parent_scope).map_err(|_| ())?;
3075-
Ok((path, res))
3075+
match self.resolve_ast_path(&path, ns, parent_scope) {
3076+
Ok(res) => Ok((path, res)),
3077+
Err((_, ResolutionError::FailedToResolve { suggestion, .. })) => Err(suggestion),
3078+
Err(_) => Err(None),
3079+
}
30763080
}
30773081

30783082
// Resolve a path passed from rustdoc or HIR lowering.

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
432432
TypeNS,
433433
LocalDefId { local_def_index: CRATE_DEF_INDEX }.to_def_id(),
434434
)
435-
.unwrap_or_else(|()| {
435+
.unwrap_or_else(|_| {
436436
panic!("Unable to resolve external crate {}", extern_name)
437437
});
438438
}

0 commit comments

Comments
 (0)