While reading through When matching on enums, read the discriminant even if there's only a single variant by meithecatte · Pull Request #154756 · rust-lang/rust · GitHub, I noticed that it mentioned that in current Rust, there is a semver compatibility hazard in which removing #[non_exhaustive] could cause a downstream library to stop compiling. The intent of that pull request is to remove the hazard.
However, it made me realise that the same principle could be used to determine during const-eval, from a downstream crate, whether any particular type implements any particular trait. The basic idea is that a closure like || drop(t) will capture t by value if its type is not provably Copy, but by reference if its type is provably Copy. In the former case, the closure will have the same type as t, but in the latter case, the closure will be pointer-sized, and it's possible to use size_of_val to distinguish the two cases. By using a type that conditionally implements Copy based on whether another type implements another trait, you can expand the technique to work on any type (even pointer-sized types), and any trait (not just Copy).
I wrote an example program that defines a macro that exploits this difference to return true if a specified type provably implements a given trait and false if this can't be proven.
Unlike with specialization, I don't think this is unsound: the unsoundnesses with specialization happen when it changes the definition of a generic item depending on a generic that got monomorphized into that item, whereas this code runs pre-monomorphization (thus, if you run provably_implements! on a type parameter, you get a true return only if all possible values for that type parameter would implement the trait).
However, this nonetheless makes me very uncomfortable and seems like a potentially serious problem, even if there's no actual unsoundness. Using a conditional Copy impl is a little contrived, but even without those, it implies that adding an implementation of Copy to a type could well end up breaking a downstream crate (because the Copy version of the closure has a shorter lifetime in addition to a different size, something which could break programs even if they aren't doing anything weird).
I'm not sure whether anything actually can or should be changed about this. (Perhaps there should be some way to explicitly move a Copy type, so that at least it would be possible for downstreams to defend against this sort of thing without needing to place all upstream types into a non-Copy wrapper.) But I thought I'd flag up the potential problem in case people have comments and/or want to suggest changes as a consequence (or in case it's worse than I thought).