mirror of
https://github.com/allankoechke/rust.git
synced 2026-11-30 11:05:36 +00:00
Rollup merge of #163200 - dianne:dyn-satisfies-bounds, r=oli-obk
make `RustaceansAreAwesome` satisfy trait bounds We use `RustaceansAreAwesome` in place of `dyn Trait` when checking whether `Trait`'s methods' receivers are dyn-dispatchable. `Trait`'s where-bounds should hold for it. Fixes https://github.com/rust-lang/rust/issues/161621
This commit is contained in:
@@ -749,6 +749,15 @@ fn receiver_is_dispatchable<'tcx>(
|
||||
let trait_predicate = ty::TraitRef::new_from_args(tcx, trait_def_id, args);
|
||||
clauses.push(trait_predicate.upcast(tcx));
|
||||
|
||||
// U satisfies `Trait`'s where-bounds.
|
||||
clauses.extend(
|
||||
tcx.clauses_of(trait_def_id)
|
||||
.instantiate(tcx, args)
|
||||
.clauses
|
||||
.into_iter()
|
||||
.map(Unnormalized::skip_norm_wip),
|
||||
);
|
||||
|
||||
let meta_sized_predicate = {
|
||||
let meta_sized_did = tcx.require_lang_item(LangItem::MetaSized, DUMMY_SP);
|
||||
ty::TraitRef::new(tcx, meta_sized_did, [unsized_self_ty])
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
//! Regression tests for <https://github.com/rust-lang/rust/issues/161621>. When checking whether
|
||||
//! method receivers for a trait `Trait` are dynamically dispatchable, we use a placeholder type in
|
||||
//! place of `dyn Trait` to avoid a cycle (as that would require determining whether `Trait` is dyn-
|
||||
//! compatible). This placeholder must satisfy `Trait`'s where-bounds to avoid errors in param-
|
||||
//! environment normalization.
|
||||
//@ check-pass
|
||||
|
||||
// Test 1
|
||||
|
||||
use std::ops::Deref;
|
||||
|
||||
trait SignatureToFnPtr {
|
||||
type Ptr;
|
||||
}
|
||||
|
||||
trait DerefsToFn<Args>
|
||||
where
|
||||
(Args, Self::Output): SignatureToFnPtr,
|
||||
Self: Deref<Target = <(Args, Self::Output) as SignatureToFnPtr>::Ptr>,
|
||||
{
|
||||
type Output;
|
||||
fn method(&self);
|
||||
}
|
||||
|
||||
// Test 2
|
||||
|
||||
trait Associator<S: ?Sized> {
|
||||
type Point;
|
||||
}
|
||||
|
||||
trait Marker<T> {}
|
||||
|
||||
trait Trait<A: Associator<Self> + ?Sized>: Marker<A::Point> {
|
||||
fn method(&self);
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -26,6 +26,8 @@ where
|
||||
//~| ERROR the size for values of type `Self` cannot be known
|
||||
//~| ERROR type mismatch resolving
|
||||
//~| ERROR the size for values of type `Self` cannot be known
|
||||
//~| ERROR type mismatch resolving
|
||||
//~| ERROR the size for values of type `RustaceansAreAwesome` cannot be known
|
||||
}
|
||||
|
||||
trait Mirror {
|
||||
|
||||
@@ -5,11 +5,29 @@ LL | fn transmute(&self, t: T) -> <Self as B>::Assoc;
|
||||
| ^ not found in this scope
|
||||
|
||||
error[E0601]: `main` function not found in crate `ice_generics_of_crate_root_152335`
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:34:57
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:36:57
|
||||
|
|
||||
LL | impl<T: Super<ActuallySuper, Assoc = T>> Mirror for T {}
|
||||
| ^ consider adding a `main` function to `$DIR/ice-generics-of-crate-root-152335.rs`
|
||||
|
||||
error[E0271]: type mismatch resolving `<RustaceansAreAwesome as Super<ActuallySuper>>::Assoc == RustaceansAreAwesome`
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:23:5
|
||||
|
|
||||
LL | fn transmute(&self, t: T) -> <Self as B>::Assoc;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `RustaceansAreAwesome`, found type parameter `T`
|
||||
|
|
||||
= note: expected type parameter `RustaceansAreAwesome`
|
||||
found type parameter `T`
|
||||
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
|
||||
note: required for `RustaceansAreAwesome` to implement `Mirror`
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:36:42
|
||||
|
|
||||
LL | impl<T: Super<ActuallySuper, Assoc = T>> Mirror for T {}
|
||||
| --------- ^^^^^^ ^
|
||||
| |
|
||||
| unsatisfied trait bound introduced here
|
||||
|
||||
error[E0271]: type mismatch resolving `<Self as Super<ActuallySuper>>::Assoc == Self`
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:23:5
|
||||
|
|
||||
@@ -21,13 +39,27 @@ LL | fn transmute(&self, t: T) -> <Self as B>::Assoc;
|
||||
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
|
||||
note: required for `Self` to implement `Mirror`
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:34:42
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:36:42
|
||||
|
|
||||
LL | impl<T: Super<ActuallySuper, Assoc = T>> Mirror for T {}
|
||||
| --------- ^^^^^^ ^
|
||||
| |
|
||||
| unsatisfied trait bound introduced here
|
||||
|
||||
error[E0277]: the size for values of type `RustaceansAreAwesome` cannot be known at compilation time
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:23:5
|
||||
|
|
||||
LL | fn transmute(&self, t: T) -> <Self as B>::Assoc;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
note: required for `RustaceansAreAwesome` to implement `Mirror`
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:36:42
|
||||
|
|
||||
LL | impl<T: Super<ActuallySuper, Assoc = T>> Mirror for T {}
|
||||
| - ^^^^^^ ^
|
||||
| |
|
||||
| unsatisfied trait bound implicitly introduced here
|
||||
|
||||
error[E0277]: the size for values of type `Self` cannot be known at compilation time
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:23:5
|
||||
|
|
||||
@@ -35,7 +67,7 @@ LL | fn transmute(&self, t: T) -> <Self as B>::Assoc;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
note: required for `Self` to implement `Mirror`
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:34:42
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:36:42
|
||||
|
|
||||
LL | impl<T: Super<ActuallySuper, Assoc = T>> Mirror for T {}
|
||||
| - ^^^^^^ ^
|
||||
@@ -69,7 +101,7 @@ LL | trait Foo<T, U>: Super<ActuallySuper, Assoc = T>
|
||||
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
|
||||
note: required for `Self` to implement `Mirror`
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:34:42
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:36:42
|
||||
|
|
||||
LL | impl<T: Super<ActuallySuper, Assoc = T>> Mirror for T {}
|
||||
| --------- ^^^^^^ ^
|
||||
@@ -83,7 +115,7 @@ LL | trait Foo<T, U>: Super<ActuallySuper, Assoc = T>
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
note: required for `Self` to implement `Mirror`
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:34:42
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:36:42
|
||||
|
|
||||
LL | impl<T: Super<ActuallySuper, Assoc = T>> Mirror for T {}
|
||||
| - ^^^^^^ ^
|
||||
@@ -95,7 +127,7 @@ LL | trait Foo<T, U>: Super<ActuallySuper, Assoc = T> + Sized
|
||||
| +++++++
|
||||
|
||||
error[E0046]: not all trait items implemented, missing: `Assoc`
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:34:1
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:36:1
|
||||
|
|
||||
LL | type Assoc: ?Sized;
|
||||
| ------------------ `Assoc` from trait
|
||||
@@ -120,7 +152,7 @@ LL | fn transmute(&self, t: T) -> <Self as B>::Assoc;
|
||||
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
|
||||
note: required for `Self` to implement `Mirror`
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:34:42
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:36:42
|
||||
|
|
||||
LL | impl<T: Super<ActuallySuper, Assoc = T>> Mirror for T {}
|
||||
| --------- ^^^^^^ ^
|
||||
@@ -134,7 +166,7 @@ LL | fn transmute(&self, t: T) -> <Self as B>::Assoc;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
note: required for `Self` to implement `Mirror`
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:34:42
|
||||
--> $DIR/ice-generics-of-crate-root-152335.rs:36:42
|
||||
|
|
||||
LL | impl<T: Super<ActuallySuper, Assoc = T>> Mirror for T {}
|
||||
| - ^^^^^^ ^
|
||||
@@ -145,7 +177,7 @@ help: consider further restricting `Self`
|
||||
LL | fn transmute(&self, t: T) -> <Self as B>::Assoc where Self: Sized;
|
||||
| +++++++++++++++++
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
error: aborting due to 12 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0038, E0046, E0271, E0277, E0405, E0601.
|
||||
For more information about an error, try `rustc --explain E0038`.
|
||||
|
||||
@@ -18,6 +18,8 @@ where
|
||||
//~| ERROR the size for values of type `Self` cannot be known at compilation time
|
||||
//~| ERROR type mismatch resolving
|
||||
//~| ERROR the size for values of type `Self` cannot be known at compilation time
|
||||
//~| ERROR type mismatch resolving
|
||||
//~| ERROR the size for values of type `RustaceansAreAwesome` cannot be known at compilation time
|
||||
}
|
||||
|
||||
trait Mirror {
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
error[E0271]: type mismatch resolving `<RustaceansAreAwesome as Super>::Assoc == ()`
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:16:5
|
||||
|
|
||||
LL | fn transmute(&self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^ expected `()`, found type parameter `T`
|
||||
|
|
||||
= note: expected unit type `()`
|
||||
found type parameter `T`
|
||||
note: required for `RustaceansAreAwesome` to implement `Mirror`
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:29:28
|
||||
|
|
||||
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
|
||||
| ---------- ^^^^^^ ^
|
||||
| |
|
||||
| unsatisfied trait bound introduced here
|
||||
|
||||
error[E0271]: type mismatch resolving `<Self as Super>::Assoc == ()`
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:16:5
|
||||
|
|
||||
@@ -7,13 +23,27 @@ LL | fn transmute(&self) {}
|
||||
= note: expected unit type `()`
|
||||
found type parameter `T`
|
||||
note: required for `Self` to implement `Mirror`
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:27:28
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:29:28
|
||||
|
|
||||
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
|
||||
| ---------- ^^^^^^ ^
|
||||
| |
|
||||
| unsatisfied trait bound introduced here
|
||||
|
||||
error[E0277]: the size for values of type `RustaceansAreAwesome` cannot be known at compilation time
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:16:5
|
||||
|
|
||||
LL | fn transmute(&self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
note: required for `RustaceansAreAwesome` to implement `Mirror`
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:29:28
|
||||
|
|
||||
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
|
||||
| - ^^^^^^ ^
|
||||
| |
|
||||
| unsatisfied trait bound implicitly introduced here
|
||||
|
||||
error[E0277]: the size for values of type `Self` cannot be known at compilation time
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:16:5
|
||||
|
|
||||
@@ -21,7 +51,7 @@ LL | fn transmute(&self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
note: required for `Self` to implement `Mirror`
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:27:28
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:29:28
|
||||
|
|
||||
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
|
||||
| - ^^^^^^ ^
|
||||
@@ -37,7 +67,7 @@ LL | trait Foo<T>: Super<Assoc = T>
|
||||
= note: expected unit type `()`
|
||||
found type parameter `T`
|
||||
note: required for `Self` to implement `Mirror`
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:27:28
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:29:28
|
||||
|
|
||||
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
|
||||
| ---------- ^^^^^^ ^
|
||||
@@ -51,7 +81,7 @@ LL | trait Foo<T>: Super<Assoc = T>
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
note: required for `Self` to implement `Mirror`
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:27:28
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:29:28
|
||||
|
|
||||
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
|
||||
| - ^^^^^^ ^
|
||||
@@ -63,7 +93,7 @@ LL | trait Foo<T>: Super<Assoc = T> + Sized
|
||||
| +++++++
|
||||
|
||||
error[E0046]: not all trait items implemented, missing: `Assoc`
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:27:1
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:29:1
|
||||
|
|
||||
LL | type Assoc;
|
||||
| ---------- `Assoc` from trait
|
||||
@@ -83,7 +113,7 @@ LL | fn transmute(&self) {}
|
||||
= note: expected unit type `()`
|
||||
found type parameter `T`
|
||||
note: required for `Self` to implement `Mirror`
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:27:28
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:29:28
|
||||
|
|
||||
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
|
||||
| ---------- ^^^^^^ ^
|
||||
@@ -97,7 +127,7 @@ LL | fn transmute(&self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
note: required for `Self` to implement `Mirror`
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:27:28
|
||||
--> $DIR/unhandled-crate-mod-issue-144888.rs:29:28
|
||||
|
|
||||
LL | impl<T: Super<Assoc = ()>> Mirror for T {}
|
||||
| - ^^^^^^ ^
|
||||
@@ -108,7 +138,7 @@ help: consider further restricting `Self`
|
||||
LL | fn transmute(&self) where Self: Sized {}
|
||||
| +++++++++++++++++
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0046, E0271, E0277.
|
||||
For more information about an error, try `rustc --explain E0046`.
|
||||
|
||||
Reference in New Issue
Block a user