-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[Draft] Supertrait item resolution in subtrait impl
s
#143527
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
Draft
dingxiangfei2009
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
dingxiangfei2009:supertrait-in-impl-subtrait
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.
Draft
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
|
||
pub use rustc_ast_ir::visit::VisitorResult; | ||
pub use rustc_ast_ir::{try_visit, visit_opt, walk_list, walk_visitable_list}; | ||
use rustc_span::def_id::LocalDefId; | ||
use rustc_span::source_map::Spanned; | ||
use rustc_span::{Ident, Span}; | ||
use thin_vec::ThinVec; | ||
|
@@ -52,15 +53,15 @@ pub enum BoundKind { | |
|
||
/// Super traits of a trait. | ||
/// E.g., `trait A: B` | ||
SuperTraits, | ||
SuperTraits { subtrait: LocalDefId }, | ||
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.
|
||
} | ||
impl BoundKind { | ||
pub fn descr(self) -> &'static str { | ||
match self { | ||
BoundKind::Bound => "bounds", | ||
BoundKind::Impl => "`impl Trait`", | ||
BoundKind::TraitObject => "`dyn` trait object bounds", | ||
BoundKind::SuperTraits => "supertrait bounds", | ||
BoundKind::SuperTraits { .. } => "supertrait bounds", | ||
} | ||
} | ||
} | ||
|
@@ -266,8 +267,8 @@ macro_rules! common_visitor_and_walkers { | |
walk_trait_ref(self, t) | ||
} | ||
|
||
fn visit_param_bound(&mut self, bounds: &$($lt)? $($mut)? GenericBound, _ctxt: BoundKind) -> Self::Result { | ||
walk_param_bound(self, bounds) | ||
fn visit_param_bound(&mut self, bound: &$($lt)? $($mut)? GenericBound, _ctxt: BoundKind) -> Self::Result { | ||
walk_param_bound(self, bound) | ||
} | ||
|
||
fn visit_precise_capturing_arg(&mut self, arg: &$($lt)? $($mut)? PreciseCapturingArg) -> Self::Result { | ||
|
@@ -1142,7 +1143,7 @@ macro_rules! common_visitor_and_walkers { | |
vis: &mut V, | ||
p: &$($lt)? $($mut)? PolyTraitRef, | ||
) -> V::Result { | ||
let PolyTraitRef { bound_generic_params, modifiers, trait_ref, span, parens: _ } = p; | ||
let PolyTraitRef { bound_generic_params, modifiers, trait_ref, span, .. } = p; | ||
try_visit!(visit_modifiers(vis, modifiers)); | ||
try_visit!(visit_generic_params(vis, bound_generic_params)); | ||
try_visit!(vis.visit_trait_ref(trait_ref)); | ||
|
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
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
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
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
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
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
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.
We probably don't need this in AST.
This flag is needed after HIR->Ty lowering, I guess, and instead of parser it's equally simple to calculate it at any stage before that (e.g. in AST->HIR lowering, or HIR->Ty lowering).
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 see that
PolyTraitRef
is used in several AST nodes includingdyn
,where
bounds and the trait superbounds. Where would a better place be, to record whether the trait superbound has theauto impl
modifier?Uh oh!
There was an error while loading. Please reload this page.
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.
How about switching out
parse_generic_bounds
parser infn parse_item_trait
and we record the supertrait modifier, ie. withauto impl
or not, on the trait item level?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.
The
auto impl
modifier is in AST, yes.Parser generally shouldn't be too context-sensitive and use things like
in_supertrait_context
, so it would typically parseauto impl
everywhere and then later passes would reject it semantically in inappropriate positions.Otherwise we have two separate but similar grammars for bound lists.
Uh oh!
There was an error while loading. Please reload this page.
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.
But for a prototype both ways are ok, and if we need to track
in_supertrait_context
in the parser anyway forauto impl
, then we can store it into AST too.