-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Implement a feature for a sound specialization subset #68970
Changes from all commits
a62dd0e
c24b4bf
32d330d
0bbbe71
4377ac3
39ee66a
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 |
---|---|---|
|
@@ -542,15 +542,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { | |
} | ||
|
||
fn visit_assoc_item(&mut self, i: &'a ast::AssocItem, ctxt: AssocCtxt) { | ||
if let ast::Defaultness::Default(_) = i.kind.defaultness() { | ||
gate_feature_post!(&self, specialization, i.span, "specialization is unstable"); | ||
} | ||
|
||
match i.kind { | ||
let is_fn = match i.kind { | ||
ast::AssocItemKind::Fn(_, ref sig, _, _) => { | ||
if let (ast::Const::Yes(_), AssocCtxt::Trait) = (sig.header.constness, ctxt) { | ||
gate_feature_post!(&self, const_fn, i.span, "const fn is unstable"); | ||
} | ||
true | ||
} | ||
ast::AssocItemKind::TyAlias(_, ref generics, _, ref ty) => { | ||
if let (Some(_), AssocCtxt::Trait) = (ty, ctxt) { | ||
|
@@ -565,8 +562,19 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { | |
self.check_impl_trait(ty); | ||
} | ||
self.check_gat(generics, i.span); | ||
false | ||
} | ||
_ => {} | ||
_ => false, | ||
}; | ||
if let ast::Defaultness::Default(_) = i.kind.defaultness() { | ||
// Limit `min_specialization` to only specializing functions. | ||
gate_feature_fn!( | ||
&self, | ||
|x: &Features| x.specialization || (is_fn && x.min_specialization), | ||
Comment on lines
+570
to
+573
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. Are there soundness issues with specializing associated constants? If not, could they be permissible in 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. The reason to only for functions being a simpler than constants and types is that we only ever work out which impl to select for a (non-const) function when generating code. For constants we can evaluate them during type checking and during codegen and I wanted to avoid potential bugs with any mismatches there. |
||
i.span, | ||
sym::specialization, | ||
"specialization is unstable" | ||
); | ||
} | ||
visit::walk_assoc_item(self, i, ctxt) | ||
} | ||
|
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 find this term ("Specializing on this trait") a bit ambiguous. I think it means "Specialized impls of this trait are allowed"? Maybe we can update the comment to be more precise.
You mentioned that this is not sound in general. I'm not sure if that's true, actually -- for marker traits, I don't think specialization causes any problems. Maybe I don't know what you mean by that, though.