forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#132289 - compiler-errors:vanquish-dyn-incompl…
…eteness, r=<try> Disqualify built-in trait impl if it seems likely to overlap in an unsound way with a blanket impl cc rust-lang#57893 r? lcnr
- Loading branch information
Showing
22 changed files
with
453 additions
and
20 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
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 | ||
} |
Oops, something went wrong.