1
Fork 0

add testcase for 112590

This commit is contained in:
yukang 2023-06-22 11:19:05 +08:00
parent e7e1a39fa0
commit b26701ea79
12 changed files with 136 additions and 76 deletions

View file

@ -3499,7 +3499,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
let report_errors = |this: &mut Self, res: Option<Res>| {
if this.should_report_errs() {
let (err, candidates) =
this.smart_resolve_report_errors(path, path_span, source, res);
this.smart_resolve_report_errors(path, path, path_span, source, res);
let def_id = this.parent_scope.module.nearest_parent_mod();
let instead = res.is_some();
@ -3556,12 +3556,13 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
_ => return Some(parent_err),
};
let (mut err, mut candidates) =
this.smart_resolve_report_errors(prefix_path, path_span, PathSource::Type, None);
if candidates.is_empty() {
candidates = this.smart_resolve_partial_mod_path_errors(prefix_path, path);
}
let (mut err, candidates) = this.smart_resolve_report_errors(
prefix_path,
path,
path_span,
PathSource::Type,
None,
);
// There are two different error messages user might receive at
// this point:

View file

@ -334,16 +334,36 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
prefix_path: &[Segment],
path: &[Segment],
) -> Vec<ImportSuggestion> {
if path.len() <= 1 {
return Vec::new();
let next_seg = if path.len() >= prefix_path.len() + 1 && prefix_path.len() == 1 {
path.get(prefix_path.len())
} else {
None
};
if let Some(segment) = prefix_path.last() &&
let Some(next_seg) = next_seg {
let candidates = self.r.lookup_import_candidates(
segment.ident,
Namespace::TypeNS,
&self.parent_scope,
&|res: Res| matches!(res, Res::Def(DefKind::Mod, _)),
);
// double check next seg is valid
candidates
.into_iter()
.filter(|candidate| {
if let Some(def_id) = candidate.did &&
let Some(module) = self.r.get_module(def_id) {
self.r.resolutions(module).borrow().iter().any(|(key, _r)| {
key.ident.name == next_seg.ident.name
})
} else {
false
}
})
.collect::<Vec<_>>()
} else {
Vec::new()
}
let ident = prefix_path.last().unwrap().ident;
self.r.lookup_import_candidates(
ident,
Namespace::TypeNS,
&self.parent_scope,
&|res: Res| matches!(res, Res::Def(DefKind::Mod, _)),
)
}
/// Handles error reporting for `smart_resolve_path_fragment` function.
@ -351,6 +371,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
pub(crate) fn smart_resolve_report_errors(
&mut self,
path: &[Segment],
full_path: &[Segment],
span: Span,
source: PathSource<'_>,
res: Option<Res>,
@ -392,7 +413,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
}
let (found, candidates) =
self.try_lookup_name_relaxed(&mut err, source, path, span, res, &base_error);
self.try_lookup_name_relaxed(&mut err, source, path, full_path, span, res, &base_error);
if found {
return (err, candidates);
}
@ -498,6 +519,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
err: &mut Diagnostic,
source: PathSource<'_>,
path: &[Segment],
full_path: &[Segment],
span: Span,
res: Option<Res>,
base_error: &BaseError,
@ -667,6 +689,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
}
}
if candidates.is_empty() {
candidates = self.smart_resolve_partial_mod_path_errors(path, full_path);
}
return (false, candidates);
}