Rollup merge of #89413 - matthewjasper:spec-marker-fix, r=nikomatsakis

Correctly handle supertraits for min_specialization

Supertraits of specialization markers could circumvent checks for
min_specialization. Elaborating predicates prevents this.

r? ````@nikomatsakis````
This commit is contained in:
Jubilee 2021-10-04 21:12:35 -07:00 committed by GitHub
commit 05b4cd6789
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 147 additions and 101 deletions

View file

@ -0,0 +1,29 @@
// Check that supertraits cannot be used to work around min_specialization
// limitations.
#![feature(min_specialization)]
#![feature(rustc_attrs)]
trait HasMethod {
fn method(&self);
}
#[rustc_unsafe_specialization_marker]
trait Marker: HasMethod {}
trait Spec {
fn spec_me(&self);
}
impl<T> Spec for T {
default fn spec_me(&self) {}
}
impl<T: Marker> Spec for T {
//~^ ERROR cannot specialize on trait `HasMethod`
fn spec_me(&self) {
self.method();
}
}
fn main() {}

View file

@ -0,0 +1,13 @@
error: cannot specialize on trait `HasMethod`
--> $DIR/spec-marker-supertraits.rs:22:1
|
LL | / impl<T: Marker> Spec for T {
LL | |
LL | | fn spec_me(&self) {
LL | | self.method();
LL | | }
LL | | }
| |_^
error: aborting due to previous error