Uh oh!
There was an error while loading. Please reload this page.
Replace #[default_method_body_is_const] with #[const_trait] - #96964
Conversation
rust-highfive
commented
May 12, 2022
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
rust-highfive
commented
May 12, 2022
(rust-highfive has picked a reviewer for you, use r? to override) |
Uh oh!
There was an error while loading. Please reload this page.
bors
commented
May 12, 2022
☔ The latest upstream changes (presumably #95562) made this pull request unmergeable. Please resolve the merge conflicts. |
fee1-dead
commented
May 16, 2022
(Please do not r? me because I have written parts of this PR.) |
jhpratt
left a comment
There was a problem hiding this comment.
Part of me would like the syntax to require const fn for the default methods, as it's not immediately clear that it's the case with this change. But I understand that the syntax/attributes is largely in flux, so that's not a deal-breaker for me.
Overall, the PR looks good. Just some minor nits.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
bors
commented
May 17, 2022
☔ The latest upstream changes (presumably #96825) made this pull request unmergeable. Please resolve the merge conflicts. |
compiler-errors
left a comment
There was a problem hiding this comment.
r=me, left a few comments (or ignore them, that's fine too)
There was a problem hiding this comment.
I wish if chains could be booleans, sigh
There was a problem hiding this comment.
sorry, meant let chains. just don't like how this has to be a mutable assignment lol. not an actionable comment.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…ait can be treated as `const`
…esugar to a method in a new impl block
Co-authored-by: fee1-dead <ent3rm4n@gmail.com>
oli-obk
commented
May 30, 2022
@bors r=compiler-errors |
bors
commented
May 30, 2022
📌 Commit 2f96fbe has been approved by |
bors
commented
May 30, 2022
bors
commented
May 30, 2022
☀️ Test successful - checks-actions |
rust-timer
commented
May 30, 2022
Finished benchmarking commit (5c780b9): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Footnotes |
pnkfelix
commented
Jun 1, 2022
@rustbot label: +perf-regression-triaged |
| let trait_def_id = imp.of_trait.as_ref()?.trait_def_id()?; | ||
| let ancestors = tcx | ||
| .trait_def(trait_def_id) | ||
| .ancestors(tcx, item.def_id.to_def_id()) | ||
| .ok()?; | ||
| let mut to_implement = Vec::new(); | ||
| for trait_item in tcx.associated_items(trait_def_id).in_definition_order() | ||
| { | ||
| if let ty::AssocItem { | ||
| kind: ty::AssocKind::Fn, | ||
| defaultness, | ||
| def_id: trait_item_id, | ||
| .. | ||
| } = *trait_item | ||
| { | ||
| // we can ignore functions that do not have default bodies: | ||
| // if those are unimplemented it will be caught by typeck. | ||
| if !defaultness.has_value() | ||
| || tcx | ||
| .has_attr(trait_item_id, sym::default_method_body_is_const) | ||
| { | ||
| continue; | ||
| } | ||
| let is_implemented = ancestors | ||
| .leaf_def(tcx, trait_item_id) | ||
| .map(|node_item| !node_item.defining_node.is_from_trait()) | ||
| .unwrap_or(false); | ||
| if !is_implemented { | ||
| to_implement.push(trait_item_id); | ||
| } | ||
| } | ||
| } | ||
| // all nonconst trait functions (not marked with #[default_method_body_is_const]) | ||
| // must be implemented | ||
| if !to_implement.is_empty() { | ||
| let not_implemented = to_implement | ||
| .into_iter() | ||
| .map(|did| tcx.item_name(did).to_string()) | ||
| .collect::<Vec<_>>() | ||
| .join("`, `"); | ||
| tcx | ||
| .sess | ||
| .struct_span_err( | ||
| item.span, | ||
| "const trait implementations may not use non-const default functions", | ||
| ) | ||
| .note(&format!("`{}` not implemented", not_implemented)) | ||
| .emit(); | ||
| } | ||
| } |
There was a problem hiding this comment.
I think we forgot to actually forbid impl const on non #[const_trait] which would be here
pulled out of #96077
related issues: #67792 and #92158
cc @fee1-dead
This is groundwork to only allowing
impl const Traitfor traits that are marked with#[const_trait]. This is necessary to prevent adding a new default method from becoming a breaking change (as it could be a non-const fn).