-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1820863
commit 264f242
Showing
15 changed files
with
325 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
tests/ui/coherence/indirect-impl-blanket-doesnt-overlap-object.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//@ check-pass | ||
|
||
// Make sure that if we don't disqualify a built-in object impl | ||
// due to a blanket with a trait bound that will never apply to | ||
// the object. | ||
|
||
pub trait SimpleService { | ||
type Resp; | ||
} | ||
|
||
trait Service { | ||
type Resp; | ||
} | ||
|
||
impl<S> Service for S where S: SimpleService + ?Sized { | ||
type Resp = <S as SimpleService>::Resp; | ||
} | ||
|
||
fn implements_service(x: &(impl Service<Resp = ()> + ?Sized)) {} | ||
|
||
fn test(x: &dyn Service<Resp = ()>) { | ||
implements_service(x); | ||
} | ||
|
||
fn main() {} |
43 changes: 43 additions & 0 deletions
43
tests/ui/coherence/indirect-impl-blanket-downstream-trait-2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
trait Trait { | ||
type Assoc; | ||
fn generate(&self) -> Self::Assoc; | ||
} | ||
|
||
trait Other {} | ||
|
||
impl<S> Trait for S where S: Other + ?Sized { | ||
type Assoc = &'static str; | ||
fn generate(&self) -> Self::Assoc { "hi" } | ||
} | ||
|
||
trait Downstream: Trait<Assoc = usize> {} | ||
impl<T> Other for T where T: ?Sized + Downstream + OnlyDyn {} | ||
|
||
trait OnlyDyn {} | ||
impl OnlyDyn for dyn Downstream {} | ||
|
||
struct Concrete; | ||
impl Trait for Concrete { | ||
type Assoc = usize; | ||
fn generate(&self) -> Self::Assoc { 42 } | ||
} | ||
impl Downstream for Concrete {} | ||
|
||
fn test<T: ?Sized + Other>(x: &T) { | ||
let s: &str = x.generate(); | ||
println!("{s}"); | ||
} | ||
|
||
fn impl_downstream<T: ?Sized + Downstream>(x: &T) {} | ||
|
||
fn main() { | ||
let x: &dyn Downstream = &Concrete; | ||
|
||
test(x); // This call used to segfault. | ||
//~^ ERROR type mismatch resolving | ||
|
||
// This no longer holds since `Downstream: Trait<Assoc = usize>`, | ||
// but the `Trait<Assoc = &'static str>` blanket impl now shadows. | ||
impl_downstream(x); | ||
//~^ ERROR type mismatch resolving | ||
} |
47 changes: 47 additions & 0 deletions
47
tests/ui/coherence/indirect-impl-blanket-downstream-trait-2.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
error[E0271]: type mismatch resolving `<dyn Downstream as Trait>::Assoc == usize` | ||
--> $DIR/indirect-impl-blanket-downstream-trait-2.rs:36:10 | ||
| | ||
LL | test(x); // This call used to segfault. | ||
| ---- ^ type mismatch resolving `<dyn Downstream as Trait>::Assoc == usize` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: expected this to be `usize` | ||
--> $DIR/indirect-impl-blanket-downstream-trait-2.rs:9:18 | ||
| | ||
LL | type Assoc = &'static str; | ||
| ^^^^^^^^^^^^ | ||
note: required for `dyn Downstream` to implement `Other` | ||
--> $DIR/indirect-impl-blanket-downstream-trait-2.rs:14:9 | ||
| | ||
LL | impl<T> Other for T where T: ?Sized + Downstream + OnlyDyn {} | ||
| ^^^^^ ^ ---------- unsatisfied trait bound introduced here | ||
= note: associated types for the current `impl` cannot be restricted in `where` clauses | ||
note: required by a bound in `test` | ||
--> $DIR/indirect-impl-blanket-downstream-trait-2.rs:26:21 | ||
| | ||
LL | fn test<T: ?Sized + Other>(x: &T) { | ||
| ^^^^^ required by this bound in `test` | ||
|
||
error[E0271]: type mismatch resolving `<dyn Downstream as Trait>::Assoc == usize` | ||
--> $DIR/indirect-impl-blanket-downstream-trait-2.rs:41:21 | ||
| | ||
LL | impl_downstream(x); | ||
| --------------- ^ type mismatch resolving `<dyn Downstream as Trait>::Assoc == usize` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: expected this to be `usize` | ||
--> $DIR/indirect-impl-blanket-downstream-trait-2.rs:9:18 | ||
| | ||
LL | type Assoc = &'static str; | ||
| ^^^^^^^^^^^^ | ||
note: required by a bound in `impl_downstream` | ||
--> $DIR/indirect-impl-blanket-downstream-trait-2.rs:31:32 | ||
| | ||
LL | fn impl_downstream<T: ?Sized + Downstream>(x: &T) {} | ||
| ^^^^^^^^^^ required by this bound in `impl_downstream` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0271`. |
Oops, something went wrong.