-
Notifications
You must be signed in to change notification settings - Fork 13.3k
WIP Add late desugaring to rustc_resolve #120247
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
Closed
Closed
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6819706
Fix doc typo in LateResolutionVisitor
axelmagn 849cdcf
WIP add a stub desugarer, fixing mutable borrows
axelmagn 725b09f
WIP add check for bare traits (needs test)
axelmagn 78e347f
WIP sort of get bare trait desugaring working
axelmagn 88f425e
WIP move to debug statements
axelmagn cbc52bf
WIP remove debug helper
axelmagn 95dd33b
WIP move AST desugaring to its own module
axelmagn 8286160
WIP stub out path visitor
axelmagn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -12,6 +12,7 @@ use crate::{path_names_to_string, rustdoc, BindingError, Finalize, LexicalScopeB | |
use crate::{Module, ModuleOrUniformRoot, NameBinding, ParentScope, PathResult}; | ||
use crate::{ResolutionError, Resolver, Segment, UseError}; | ||
|
||
use rustc_ast::mut_visit::MutVisitor; | ||
use rustc_ast::ptr::P; | ||
use rustc_ast::visit::{self, AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor}; | ||
use rustc_ast::*; | ||
|
@@ -669,7 +670,7 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { | |
/// State used to know whether to ignore resolution errors for function bodies. | ||
/// | ||
/// In particular, rustdoc uses this to avoid giving errors for `cfg()` items. | ||
/// In most cases this will be `None`, in which case errors will always be reported. | ||
/// In most cases this will be `false`, in which case errors will always be reported. | ||
/// If it is `true`, then it will be updated when entering a nested function or trait body. | ||
in_func_body: bool, | ||
|
||
|
@@ -4592,13 +4593,55 @@ impl<'ast> Visitor<'ast> for LifetimeCountVisitor<'_, '_, '_> { | |
} | ||
|
||
impl<'a, 'tcx> Resolver<'a, 'tcx> { | ||
pub(crate) fn late_resolve_crate(&mut self, krate: &Crate) { | ||
pub(crate) fn late_resolve_crate(&mut self, krate: &mut Crate) { | ||
visit::walk_crate(&mut LifetimeCountVisitor { r: self }, krate); | ||
let mut late_resolution_visitor = LateResolutionVisitor::new(self); | ||
late_resolution_visitor.resolve_doc_links(&krate.attrs, MaybeExported::Ok(CRATE_NODE_ID)); | ||
visit::walk_crate(&mut late_resolution_visitor, krate); | ||
for (id, span) in late_resolution_visitor.diagnostic_metadata.unused_labels.iter() { | ||
self.lint_buffer.buffer_lint(lint::builtin::UNUSED_LABELS, *id, *span, "unused label"); | ||
{ | ||
let mut late_resolution_visitor = LateResolutionVisitor::new(self); | ||
late_resolution_visitor | ||
.resolve_doc_links(&krate.attrs, MaybeExported::Ok(CRATE_NODE_ID)); | ||
visit::walk_crate(&mut late_resolution_visitor, krate); | ||
for (id, span) in late_resolution_visitor.diagnostic_metadata.unused_labels.iter() { | ||
self.lint_buffer.buffer_lint( | ||
lint::builtin::UNUSED_LABELS, | ||
*id, | ||
*span, | ||
"unused label", | ||
); | ||
} | ||
} | ||
|
||
{ | ||
let mut late_desugar_visitor = LateDesugarVisitor::new(self); | ||
late_desugar_visitor.visit_crate(krate); | ||
} | ||
} | ||
} | ||
|
||
struct LateDesugarVisitor<'a, 'b, 'tcx> { | ||
r: &'b mut Resolver<'a, 'tcx>, | ||
} | ||
|
||
impl<'a, 'b, 'tcx> LateDesugarVisitor<'a, 'b, 'tcx> { | ||
fn new(resolver: &'b mut Resolver<'a, 'tcx>) -> Self { | ||
LateDesugarVisitor { r: resolver } | ||
} | ||
} | ||
|
||
impl MutVisitor for LateDesugarVisitor<'_, '_, '_> { | ||
fn visit_ty(&mut self, ty: &mut P<Ty>) { | ||
if let TyKind::Path(None, _path) = &ty.kind | ||
&& let Some(partial_res) = self.r.partial_res_map.get(&ty.id) | ||
&& let Some(res @ Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) = | ||
partial_res.full_res() | ||
{ | ||
debug!("[Desugar][Ty][BareTrait][{:?}] {:?}\n{:#?}", ty.span, res, ty); | ||
|
||
let trait_obj = TyKind::TraitObject(vec![], TraitObjectSyntax::None); | ||
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. You are creating a trait object with a single generic bound, which is a trait with no bound generics ( |
||
ty.kind = trait_obj; | ||
|
||
debug!("->\n{:#?}\n", ty); | ||
} | ||
|
||
mut_visit::noop_visit_ty(ty, self); | ||
} | ||
} |
This file contains hidden or 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
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 think the new pass is supposed to run right after this function finishes, at least for the step 1 in #99669 (comment).
Also makes sense to put this pass into a separate file.
(I'm still not sure it's a good idea, all in all, maybe it will become more visible once the step 1 is finished.)