-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tweak output of resolve errors #126810
Open
estebank
wants to merge
9
commits into
rust-lang:master
Choose a base branch
from
estebank:resolve-error-wording
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,063
−1,814
Open
Tweak output of resolve errors #126810
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
86f8aae
Remove redundancy in resolve error between main message and primary l…
estebank 3abad14
Unify output of the different "cannot find X" errors
estebank 5f47d1f
revert wording changes to main message
estebank ec83028
More accurate description of unresolved imported item
estebank de92cd4
Account for `_` in import paths
estebank 045e8dd
Fix miri test
estebank a9fe7c8
fix windows test
estebank f0d9e3f
Add scope context to unresolved macros
estebank e1fed5f
Fix ui-fulldeps test
estebank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use rustc_ast::{self as ast, NodeId}; | ||
use rustc_errors::ErrorGuaranteed; | ||
use rustc_errors::{Applicability, ErrorGuaranteed}; | ||
use rustc_hir::def::{DefKind, Namespace, NonMacroAttrKind, PartialRes, PerNS}; | ||
use rustc_middle::bug; | ||
use rustc_middle::ty; | ||
|
@@ -1463,9 +1463,28 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { | |
continue; | ||
} | ||
} | ||
return PathResult::failed(ident, false, finalize.is_some(), module, || { | ||
("there are too many leading `super` keywords".to_string(), None) | ||
}); | ||
let mut item_type = "module"; | ||
let mut suggestion = None; | ||
let label = if path.len() == 1 | ||
&& let Some(ribs) = ribs | ||
&& let RibKind::Normal = ribs[ValueNS][ribs[ValueNS].len() - 1].kind | ||
{ | ||
item_type = "item"; | ||
suggestion = Some((vec![(ident.span.shrink_to_lo(), "r#".to_string())], "if you still want to call your identifier `super`, use the raw identifier format".to_string(), Applicability::MachineApplicable)); | ||
"can't use `super` as an identifier" | ||
} else if segment_idx == 0 { | ||
"can't use `super` on the crate root, there are no further modules to go \"up\" to" | ||
} else { | ||
"there are too many leading `super` keywords" | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All this logic should go into the closure, so it's not executed on a good path ( |
||
return PathResult::failed( | ||
ident, | ||
false, | ||
finalize.is_some(), | ||
module, | ||
|| (label.to_string(), suggestion), | ||
item_type, | ||
); | ||
} | ||
if segment_idx == 0 { | ||
if name == kw::SelfLower { | ||
|
@@ -1497,19 +1516,26 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { | |
|
||
// Report special messages for path segment keywords in wrong positions. | ||
if ident.is_path_segment_keyword() && segment_idx != 0 { | ||
return PathResult::failed(ident, false, finalize.is_some(), module, || { | ||
let name_str = if name == kw::PathRoot { | ||
"crate root".to_string() | ||
} else { | ||
format!("`{name}`") | ||
}; | ||
let label = if segment_idx == 1 && path[0].ident.name == kw::PathRoot { | ||
format!("global paths cannot start with {name_str}") | ||
} else { | ||
format!("{name_str} in paths can only be used in start position") | ||
}; | ||
(label, None) | ||
}); | ||
return PathResult::failed( | ||
ident, | ||
false, | ||
finalize.is_some(), | ||
module, | ||
|| { | ||
let name_str = if name == kw::PathRoot { | ||
"crate root".to_string() | ||
} else { | ||
format!("`{name}`") | ||
}; | ||
let label = if segment_idx == 1 && path[0].ident.name == kw::PathRoot { | ||
format!("global paths cannot start with {name_str}") | ||
} else { | ||
format!("{name_str} in paths can only be used in start position") | ||
}; | ||
(label, None) | ||
}, | ||
"module", | ||
); | ||
} | ||
|
||
let binding = if let Some(module) = module { | ||
|
@@ -1605,6 +1631,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { | |
); | ||
(label, None) | ||
}, | ||
"module", | ||
); | ||
} | ||
} | ||
|
@@ -1619,18 +1646,29 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { | |
} | ||
} | ||
|
||
return PathResult::failed(ident, is_last, finalize.is_some(), module, || { | ||
self.report_path_resolution_error( | ||
path, | ||
opt_ns, | ||
parent_scope, | ||
ribs, | ||
ignore_binding, | ||
module, | ||
segment_idx, | ||
ident, | ||
) | ||
}); | ||
return PathResult::failed( | ||
ident, | ||
is_last, | ||
finalize.is_some(), | ||
module, | ||
|| { | ||
self.report_path_resolution_error( | ||
path, | ||
opt_ns, | ||
parent_scope, | ||
ribs, | ||
ignore_binding, | ||
module, | ||
segment_idx, | ||
ident, | ||
) | ||
}, | ||
match opt_ns { | ||
Some(ValueNS) if path.len() == 1 => "item or value", | ||
Some(ns) if path.len() - 1 == segment_idx => ns.descr(), | ||
Some(_) | None => "item", | ||
}, | ||
); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree with this change, "in this scope" is a meaningful and significant part of the message.
We can lookup names in many places, e.g. in a module, or in extern prelude specifically, and here were are saying where we are looking up the name in this case - in the current scope (which happens when we resolve first segments of paths).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@petrochenkov the primary span label retains that context of the message. I feel like it is bad practice in general to have redundant information in the different parts of the error, and we already get too many complains about "too much text in the errors". This was an attempt to walk that line. In the particular case of "in this scope" you and I know what why that is meaningful, but in practice that wording ends up being more text to say something that is generally implied: if it's not on a specific other scope, it's always "this scope". Whenever we do have additional context from "this scope", then it does make sense to mention it ("in trait
Trait
"). If we were to actually mention the scope ("cannot find macrofoo
from methodbar
"), that would change my opinion on the use of this (because then the message can be read in isolation without having to read the code to understand the context).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that "in this scope" is pretty general, and replacing it with "from this specific place called
foo
" when possible would be better, but it's definitely better than nothing because it still says which resolution mode is used.If it was entirely useless, then it could be dropped from the label messages as well.
(As for the redundancy, I've answered below.)