-
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 all 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use rustc_ast::{ | ||
mut_visit::{self, MutVisitor}, | ||
ptr::P, | ||
Path, TraitObjectSyntax, Ty, TyKind, | ||
}; | ||
use rustc_hir::def::DefKind; | ||
|
||
use crate::{Res, Resolver}; | ||
|
||
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 the type is a path, and that path resolves to a trate, desugar it | ||
// into a bare trait object. | ||
|
||
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); | ||
|
||
// TODO(axelmagn): extract bounds from path? | ||
let bounds = vec![]; | ||
// TODO(axelmagn): is this the right choice? I don't think a trait | ||
// path would ever imply Dyn, so None is the only other option. | ||
let syntax = TraitObjectSyntax::None; | ||
let trait_obj = TyKind::TraitObject(bounds, syntax); | ||
ty.kind = trait_obj; | ||
|
||
// TODO(axelmagn): Do the type tokens need to be rewritten? I would | ||
// assume so, for use in AST lowering. | ||
|
||
debug!("->\n{:#?}\n", ty); | ||
} | ||
|
||
mut_visit::noop_visit_ty(ty, self); | ||
} | ||
|
||
fn visit_path(&mut self, path: &mut Path) { | ||
// TODO(axelmagn): Desugar type-relative paths during resolution. | ||
// Transform a::b::c::d to <a::b::c>::d when a::b::c can be resolved to | ||
// a type and ::d cannot (for instance because it is a trait method). | ||
// (check rustc_ast_lowering::path::lower_qpath for current impl) | ||
|
||
mut_visit::noop_visit_path(path, 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
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.)