store the segment name when resolution fails
This commit is contained in:
parent
284cb714d2
commit
c288cb1f74
10 changed files with 58 additions and 51 deletions
|
@ -786,7 +786,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
ResolutionError::SelfImportOnlyInImportListWithNonEmptyPrefix => {
|
ResolutionError::SelfImportOnlyInImportListWithNonEmptyPrefix => {
|
||||||
self.dcx().create_err(errs::SelfImportOnlyInImportListWithNonEmptyPrefix { span })
|
self.dcx().create_err(errs::SelfImportOnlyInImportListWithNonEmptyPrefix { span })
|
||||||
}
|
}
|
||||||
ResolutionError::FailedToResolve { last_segment, label, suggestion, module } => {
|
ResolutionError::FailedToResolve { segment, label, suggestion, module } => {
|
||||||
let mut err =
|
let mut err =
|
||||||
struct_span_code_err!(self.dcx(), span, E0433, "failed to resolve: {}", &label);
|
struct_span_code_err!(self.dcx(), span, E0433, "failed to resolve: {}", &label);
|
||||||
err.span_label(span, label);
|
err.span_label(span, label);
|
||||||
|
@ -801,9 +801,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
if let Some(ModuleOrUniformRoot::Module(module)) = module
|
if let Some(ModuleOrUniformRoot::Module(module)) = module
|
||||||
&& let Some(module) = module.opt_def_id()
|
&& let Some(module) = module.opt_def_id()
|
||||||
&& let Some(last_segment) = last_segment
|
&& let Some(segment) = segment
|
||||||
{
|
{
|
||||||
self.find_cfg_stripped(&mut err, &last_segment, module);
|
self.find_cfg_stripped(&mut err, &segment, module);
|
||||||
}
|
}
|
||||||
|
|
||||||
err
|
err
|
||||||
|
@ -981,12 +981,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
VisResolutionError::FailedToResolve(span, label, suggestion) => self.into_struct_error(
|
VisResolutionError::FailedToResolve(span, label, suggestion) => self.into_struct_error(
|
||||||
span,
|
span,
|
||||||
ResolutionError::FailedToResolve {
|
ResolutionError::FailedToResolve { segment: None, label, suggestion, module: None },
|
||||||
last_segment: None,
|
|
||||||
label,
|
|
||||||
suggestion,
|
|
||||||
module: None,
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
VisResolutionError::ExpectedFound(span, path_str, res) => {
|
VisResolutionError::ExpectedFound(span, path_str, res) => {
|
||||||
self.dcx().create_err(errs::ExpectedFound { span, res, path_str })
|
self.dcx().create_err(errs::ExpectedFound { span, res, path_str })
|
||||||
|
@ -2450,7 +2445,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
pub(crate) fn find_cfg_stripped(
|
pub(crate) fn find_cfg_stripped(
|
||||||
&mut self,
|
&mut self,
|
||||||
err: &mut Diagnostic,
|
err: &mut Diagnostic,
|
||||||
last_segment: &Symbol,
|
segment: &Symbol,
|
||||||
module: DefId,
|
module: DefId,
|
||||||
) {
|
) {
|
||||||
let local_items;
|
let local_items;
|
||||||
|
@ -2469,7 +2464,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
for &StrippedCfgItem { parent_module, name, ref cfg } in symbols {
|
for &StrippedCfgItem { parent_module, name, ref cfg } in symbols {
|
||||||
if parent_module != module || name.name != *last_segment {
|
if parent_module != module || name.name != *segment {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1381,13 +1381,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return PathResult::failed(
|
return PathResult::failed(ident, false, finalize.is_some(), module, || {
|
||||||
ident.span,
|
("there are too many leading `super` keywords".to_string(), None)
|
||||||
false,
|
});
|
||||||
finalize.is_some(),
|
|
||||||
module,
|
|
||||||
|| ("there are too many leading `super` keywords".to_string(), None),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if segment_idx == 0 {
|
if segment_idx == 0 {
|
||||||
if name == kw::SelfLower {
|
if name == kw::SelfLower {
|
||||||
|
@ -1419,7 +1415,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
// Report special messages for path segment keywords in wrong positions.
|
// Report special messages for path segment keywords in wrong positions.
|
||||||
if ident.is_path_segment_keyword() && segment_idx != 0 {
|
if ident.is_path_segment_keyword() && segment_idx != 0 {
|
||||||
return PathResult::failed(ident.span, false, finalize.is_some(), module, || {
|
return PathResult::failed(ident, false, finalize.is_some(), module, || {
|
||||||
let name_str = if name == kw::PathRoot {
|
let name_str = if name == kw::PathRoot {
|
||||||
"crate root".to_string()
|
"crate root".to_string()
|
||||||
} else {
|
} else {
|
||||||
|
@ -1515,7 +1511,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
return PathResult::failed(
|
return PathResult::failed(
|
||||||
ident.span,
|
ident,
|
||||||
is_last,
|
is_last,
|
||||||
finalize.is_some(),
|
finalize.is_some(),
|
||||||
module,
|
module,
|
||||||
|
@ -1541,24 +1537,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return PathResult::failed(
|
return PathResult::failed(ident, is_last, finalize.is_some(), module, || {
|
||||||
ident.span,
|
self.report_path_resolution_error(
|
||||||
is_last,
|
path,
|
||||||
finalize.is_some(),
|
opt_ns,
|
||||||
module,
|
parent_scope,
|
||||||
|| {
|
ribs,
|
||||||
self.report_path_resolution_error(
|
ignore_binding,
|
||||||
path,
|
module,
|
||||||
opt_ns,
|
segment_idx,
|
||||||
parent_scope,
|
ident,
|
||||||
ribs,
|
)
|
||||||
ignore_binding,
|
});
|
||||||
module,
|
|
||||||
segment_idx,
|
|
||||||
ident,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -886,6 +886,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
PathResult::Failed {
|
PathResult::Failed {
|
||||||
is_error_from_last_segment: false,
|
is_error_from_last_segment: false,
|
||||||
span,
|
span,
|
||||||
|
segment_name,
|
||||||
label,
|
label,
|
||||||
suggestion,
|
suggestion,
|
||||||
module,
|
module,
|
||||||
|
@ -895,7 +896,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
self.report_error(
|
self.report_error(
|
||||||
span,
|
span,
|
||||||
ResolutionError::FailedToResolve {
|
ResolutionError::FailedToResolve {
|
||||||
last_segment: None,
|
segment: Some(segment_name),
|
||||||
label,
|
label,
|
||||||
suggestion,
|
suggestion,
|
||||||
module,
|
module,
|
||||||
|
|
|
@ -4054,11 +4054,12 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
label,
|
label,
|
||||||
suggestion,
|
suggestion,
|
||||||
module,
|
module,
|
||||||
|
segment_name,
|
||||||
} => {
|
} => {
|
||||||
return Err(respan(
|
return Err(respan(
|
||||||
span,
|
span,
|
||||||
ResolutionError::FailedToResolve {
|
ResolutionError::FailedToResolve {
|
||||||
last_segment: None,
|
segment: Some(segment_name),
|
||||||
label,
|
label,
|
||||||
suggestion,
|
suggestion,
|
||||||
module,
|
module,
|
||||||
|
|
|
@ -213,7 +213,7 @@ enum ResolutionError<'a> {
|
||||||
SelfImportOnlyInImportListWithNonEmptyPrefix,
|
SelfImportOnlyInImportListWithNonEmptyPrefix,
|
||||||
/// Error E0433: failed to resolve.
|
/// Error E0433: failed to resolve.
|
||||||
FailedToResolve {
|
FailedToResolve {
|
||||||
last_segment: Option<Symbol>,
|
segment: Option<Symbol>,
|
||||||
label: String,
|
label: String,
|
||||||
suggestion: Option<Suggestion>,
|
suggestion: Option<Suggestion>,
|
||||||
module: Option<ModuleOrUniformRoot<'a>>,
|
module: Option<ModuleOrUniformRoot<'a>>,
|
||||||
|
@ -396,12 +396,14 @@ enum PathResult<'a> {
|
||||||
suggestion: Option<Suggestion>,
|
suggestion: Option<Suggestion>,
|
||||||
is_error_from_last_segment: bool,
|
is_error_from_last_segment: bool,
|
||||||
module: Option<ModuleOrUniformRoot<'a>>,
|
module: Option<ModuleOrUniformRoot<'a>>,
|
||||||
|
/// The segment name of target
|
||||||
|
segment_name: Symbol,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PathResult<'a> {
|
impl<'a> PathResult<'a> {
|
||||||
fn failed(
|
fn failed(
|
||||||
span: Span,
|
ident: Ident,
|
||||||
is_error_from_last_segment: bool,
|
is_error_from_last_segment: bool,
|
||||||
finalize: bool,
|
finalize: bool,
|
||||||
module: Option<ModuleOrUniformRoot<'a>>,
|
module: Option<ModuleOrUniformRoot<'a>>,
|
||||||
|
@ -409,7 +411,14 @@ impl<'a> PathResult<'a> {
|
||||||
) -> PathResult<'a> {
|
) -> PathResult<'a> {
|
||||||
let (label, suggestion) =
|
let (label, suggestion) =
|
||||||
if finalize { label_and_suggestion() } else { (String::new(), None) };
|
if finalize { label_and_suggestion() } else { (String::new(), None) };
|
||||||
PathResult::Failed { span, label, suggestion, is_error_from_last_segment, module }
|
PathResult::Failed {
|
||||||
|
span: ident.span,
|
||||||
|
segment_name: ident.name,
|
||||||
|
label,
|
||||||
|
suggestion,
|
||||||
|
is_error_from_last_segment,
|
||||||
|
module,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -779,7 +779,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
self.report_error(
|
self.report_error(
|
||||||
span,
|
span,
|
||||||
ResolutionError::FailedToResolve {
|
ResolutionError::FailedToResolve {
|
||||||
last_segment: path.last().map(|segment| segment.ident.name),
|
segment: path.last().map(|segment| segment.ident.name),
|
||||||
label,
|
label,
|
||||||
suggestion,
|
suggestion,
|
||||||
module,
|
module,
|
||||||
|
|
|
@ -14,9 +14,9 @@ fn main() {
|
||||||
|
|
||||||
// The module isn't found - we would like to get a diagnostic, but currently don't due to
|
// The module isn't found - we would like to get a diagnostic, but currently don't due to
|
||||||
// the awkward way the resolver diagnostics are currently implemented.
|
// the awkward way the resolver diagnostics are currently implemented.
|
||||||
// FIXME(Nilstrieb): Also add a note to the cfg diagnostic here
|
|
||||||
cfged_out::inner::doesnt_exist::hello(); //~ ERROR failed to resolve
|
cfged_out::inner::doesnt_exist::hello(); //~ ERROR failed to resolve
|
||||||
//~^ NOTE could not find `doesnt_exist` in `inner`
|
//~^ NOTE could not find `doesnt_exist` in `inner`
|
||||||
|
//~| NOTE found an item that was configured out
|
||||||
|
|
||||||
// It should find the one in the right module, not the wrong one.
|
// It should find the one in the right module, not the wrong one.
|
||||||
cfged_out::inner::right::meow(); //~ ERROR cannot find function
|
cfged_out::inner::right::meow(); //~ ERROR cannot find function
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner`
|
error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner`
|
||||||
--> $DIR/diagnostics-cross-crate.rs:18:23
|
--> $DIR/diagnostics-cross-crate.rs:17:23
|
||||||
|
|
|
|
||||||
LL | cfged_out::inner::doesnt_exist::hello();
|
LL | cfged_out::inner::doesnt_exist::hello();
|
||||||
| ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner`
|
| ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner`
|
||||||
|
|
|
||||||
|
note: found an item that was configured out
|
||||||
|
--> $DIR/auxiliary/cfged_out.rs:6:13
|
||||||
|
|
|
||||||
|
LL | pub mod doesnt_exist {
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0425]: cannot find function `uwu` in crate `cfged_out`
|
error[E0425]: cannot find function `uwu` in crate `cfged_out`
|
||||||
--> $DIR/diagnostics-cross-crate.rs:7:16
|
--> $DIR/diagnostics-cross-crate.rs:7:16
|
||||||
|
|
|
@ -4,7 +4,7 @@ pub mod inner {
|
||||||
//~^ NOTE found an item that was configured out
|
//~^ NOTE found an item that was configured out
|
||||||
|
|
||||||
#[cfg(FALSE)]
|
#[cfg(FALSE)]
|
||||||
pub mod doesnt_exist {
|
pub mod doesnt_exist { //~ NOTE found an item that was configured out
|
||||||
pub fn hello() {}
|
pub fn hello() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,6 @@ fn main() {
|
||||||
|
|
||||||
// The module isn't found - we would like to get a diagnostic, but currently don't due to
|
// The module isn't found - we would like to get a diagnostic, but currently don't due to
|
||||||
// the awkward way the resolver diagnostics are currently implemented.
|
// the awkward way the resolver diagnostics are currently implemented.
|
||||||
// FIXME(Nilstrieb): Also add a note to the cfg diagnostic here
|
|
||||||
inner::doesnt_exist::hello(); //~ ERROR failed to resolve
|
inner::doesnt_exist::hello(); //~ ERROR failed to resolve
|
||||||
//~| NOTE could not find `doesnt_exist` in `inner`
|
//~| NOTE could not find `doesnt_exist` in `inner`
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner`
|
error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner`
|
||||||
--> $DIR/diagnostics-same-crate.rs:38:12
|
--> $DIR/diagnostics-same-crate.rs:37:12
|
||||||
|
|
|
|
||||||
LL | inner::doesnt_exist::hello();
|
LL | inner::doesnt_exist::hello();
|
||||||
| ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner`
|
| ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner`
|
||||||
|
|
|
||||||
|
note: found an item that was configured out
|
||||||
|
--> $DIR/diagnostics-same-crate.rs:7:13
|
||||||
|
|
|
||||||
|
LL | pub mod doesnt_exist {
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0425]: cannot find function `uwu` in module `inner`
|
error[E0425]: cannot find function `uwu` in module `inner`
|
||||||
--> $DIR/diagnostics-same-crate.rs:32:12
|
--> $DIR/diagnostics-same-crate.rs:32:12
|
||||||
|
@ -17,7 +23,7 @@ LL | pub fn uwu() {}
|
||||||
| ^^^
|
| ^^^
|
||||||
|
|
||||||
error[E0425]: cannot find function `meow` in module `inner::right`
|
error[E0425]: cannot find function `meow` in module `inner::right`
|
||||||
--> $DIR/diagnostics-same-crate.rs:42:19
|
--> $DIR/diagnostics-same-crate.rs:41:19
|
||||||
|
|
|
|
||||||
LL | inner::right::meow();
|
LL | inner::right::meow();
|
||||||
| ^^^^ not found in `inner::right`
|
| ^^^^ not found in `inner::right`
|
||||||
|
@ -36,7 +42,7 @@ LL | uwu();
|
||||||
| ^^^ not found in this scope
|
| ^^^ not found in this scope
|
||||||
|
|
||||||
error[E0425]: cannot find function `vanished` in this scope
|
error[E0425]: cannot find function `vanished` in this scope
|
||||||
--> $DIR/diagnostics-same-crate.rs:49:5
|
--> $DIR/diagnostics-same-crate.rs:48:5
|
||||||
|
|
|
|
||||||
LL | vanished();
|
LL | vanished();
|
||||||
| ^^^^^^^^ not found in this scope
|
| ^^^^^^^^ not found in this scope
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue