-
Notifications
You must be signed in to change notification settings - Fork 13.5k
fix: impl Trait desugaring in trait objects' assoc constraints #97335
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
Changes from 13 commits
383825b
95dc803
192b6f6
8d1a48c
711fc0e
a02dc2f
3c4e763
305ef51
032d3d3
48f8cae
d8138a2
3f55d23
a9ff3f3
ba2aa48
e4adc7e
573e1e8
fdd03bc
44a1135
9629511
d942c14
4cab123
b818e30
3b67462
1e69472
6deece1
adaa6b0
550a550
61f6677
2743ece
7068ec0
1cd9779
05ad36a
2f17fa2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||
use crate::{ImplTraitContext, Resolver}; | ||||||
use rustc_ast::visit::{self, FnKind}; | ||||||
use rustc_ast::visit::{self, BoundKind, FnKind}; | ||||||
use rustc_ast::walk_list; | ||||||
use rustc_ast::*; | ||||||
use rustc_ast_lowering::ResolverAstLowering; | ||||||
|
@@ -285,19 +285,36 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> { | |||||
TyKind::MacCall(..) => self.visit_macro_invoc(ty.id), | ||||||
TyKind::ImplTrait(node_id, _) => { | ||||||
let parent_def = match self.impl_trait_context { | ||||||
ImplTraitContext::Universal(item_def) => self.resolver.create_def( | ||||||
item_def, | ||||||
node_id, | ||||||
DefPathData::ImplTrait, | ||||||
self.expansion.to_expn_id(), | ||||||
ty.span, | ||||||
), | ||||||
ImplTraitContext::Universal(item_def) => { | ||||||
//| ImplTraitContext::UniversalInDyn(item_def) => { | ||||||
let def_id = self.resolver.create_def( | ||||||
item_def, | ||||||
node_id, | ||||||
DefPathData::ImplTrait, | ||||||
self.expansion.to_expn_id(), | ||||||
ty.span, | ||||||
); | ||||||
self.resolver | ||||||
.impl_trait_context | ||||||
.insert(def_id, ImplTraitContext::Universal(item_def)); | ||||||
cjgillot marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
def_id | ||||||
} | ||||||
ImplTraitContext::Existential => { | ||||||
self.create_def(node_id, DefPathData::ImplTrait, ty.span) | ||||||
let def_id = self.create_def(node_id, DefPathData::ImplTrait, ty.span); | ||||||
self.resolver | ||||||
.impl_trait_context | ||||||
.insert(def_id, ImplTraitContext::Existential); | ||||||
def_id | ||||||
} | ||||||
ImplTraitContext::UniversalInDyn(_) => self.parent_def, | ||||||
}; | ||||||
self.with_parent(parent_def, |this| visit::walk_ty(this, ty)) | ||||||
} | ||||||
TyKind::TraitObject(ref bounds, ..) => { | ||||||
self.with_impl_trait(ImplTraitContext::UniversalInDyn(self.parent_def), |this| { | ||||||
walk_list!(this, visit_param_bound, bounds, BoundKind::TraitObject); | ||||||
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.
Suggested change
No need to re-code the default behaviour. |
||||||
}); | ||||||
} | ||||||
_ => visit::walk_ty(self, ty), | ||||||
} | ||||||
} | ||||||
|
@@ -352,4 +369,29 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> { | |||||
visit::walk_crate(self, krate) | ||||||
} | ||||||
} | ||||||
|
||||||
fn visit_assoc_constraint(&mut self, constraint: &'a AssocConstraint) { | ||||||
/*if let ImplTraitContext::UniversalInDyn(item_def) = self.impl_trait_context { | ||||||
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. This version is correct. 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. We should only create the definition is |
||||||
let node_id = constraint.impl_trait_id; | ||||||
let def_id = self.resolver.create_def( | ||||||
item_def, | ||||||
node_id, | ||||||
DefPathData::ImplTrait, | ||||||
self.expansion.to_expn_id(), | ||||||
constraint.span, | ||||||
); | ||||||
self.resolver | ||||||
.impl_trait_context | ||||||
.insert(def_id, ImplTraitContext::UniversalInDyn(item_def)); | ||||||
}*/ | ||||||
if let ImplTraitContext::UniversalInDyn(_) = self.impl_trait_context { | ||||||
let node_id = constraint.impl_trait_id; | ||||||
let def_id = self.create_def(node_id, DefPathData::ImplTrait, constraint.span); | ||||||
self.resolver | ||||||
.impl_trait_context | ||||||
.insert(def_id, ImplTraitContext::UniversalInDyn(def_id)); | ||||||
} | ||||||
|
||||||
visit::walk_assoc_constraint(self, constraint); | ||||||
} | ||||||
} |
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.
This is the correct behaviour here.