-
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
Add implement_via_object
to rustc_deny_explicit_impl
to control object candidate assembly
#112320
Conversation
Some changes occurred to the core trait solver cc @rust-lang/initiative-trait-system-refactor |
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.
as a thought, do we want to change this to instead add a argument to rustc_deny_explicit_impl
, i.e. #[rustc_deny_explicit_impl(builtin_object_impl = <bool>)]
🤔
going with opt-out here feels dangerous to me as getting it wrong is unsound(?), so maybe alternatively change it to #[rustc_builtin_has_object_impl]
? 🤔
if self.tcx().has_attr( | ||
goal.predicate.trait_def_id(self.tcx()), | ||
sym::rustc_do_not_implement_via_object, | ||
) { |
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.
please instead add another field to TraitDef
and access that here. you can then mark rustc_do_not_implement_via_object
as @only_local
.
I don't think we can do that, since the transmutability trait |
7d1ad1e
to
457c05e
Compare
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.
pls add check to rustc_passes/src/check_attr.rs
, after that r=me
If you're asking about custom implementations in rustc itself... I can check with @jswrenn offline and get back to you |
Well, given that Maybe we could uplift this into something like |
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.
r=me after nits and updating PR descr + title
2f177b5
to
ca68cf0
Compare
rustc_do_not_implement_via_object
implement_via_object
to rustc_deny_explicit_impl
to control object candidate assembly
@bors r=lcnr |
☀️ Test successful - checks-actions |
Finished benchmarking commit (6fc0273): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 658.605s -> 655.831s (-0.42%) |
…a-obj-unless-denied, r=compiler-errors Add tests impl via obj unless denied Fixes rust-lang#112737 Add simple tests to check feature change in rust-lang#112320 is performing as expected. Note: - Unsure about filenames, locations & function signature names (tried to make them something sensible)
Some built-in traits are special, since they are used to prove facts about the program that are important for later phases of compilation such as codegen and CTFE. For example, the
Unsize
trait is used to assert to the compiler that we are able to unsize a type into another type. It doesn't have any methods because it doesn't actually instruct the compiler how to do this unsizing, but this is later used (alongside an exhaustive match of combinations of unsizeable types) during codegen to generate unsize coercion code.Due to this, these built-in traits are incompatible with the type erasure provided by object types. For example, the existence of
dyn Unsize<T>
does not mean that the compiler is able to unsizeBox<dyn Unsize<T>>
intoBox<T>
, sinceUnsize
is a witness to the fact that a type can be unsized, and it doesn't actually encode that unsizing operation in its vtable as mentioned above.The old trait solver gets around this fact by having complex control flow that never considers object bounds for certain built-in traits:
rust/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs
Lines 61 to 132 in 2f896da
However, candidate assembly in the new solver is much more lovely, and I'd hate to add this list of opt-out cases into the new solver. Instead of maintaining this complex and hard-coded control flow, instead we can make this a property of the trait via a built-in attribute. We already have such a build attribute that's applied to every single trait that we care about:
rustc_deny_explicit_impl
. This PR addsimplement_via_object
as a meta-item to that attribute that allows us to opt a trait out of object-bound candidate assembly as well.r? @lcnr