-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #113661 - oli-obk:tait_wtf, r=lcnr
Double check that hidden types match the expected hidden type Fixes #113278 specifically, but I left a TODO for where we should also add some hardening. It feels a bit like papering over the issue, but at least this way we don't get unsoundness, but just surprising errors. Errors will be improved and given spans before this PR lands. r? `@compiler-errors` `@lcnr`
- Loading branch information
Showing
8 changed files
with
260 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//! This test checks that we don't lose hidden types | ||
//! for *other* opaque types that we register and use | ||
//! to prove bounds while checking that a hidden type | ||
//! satisfies its opaque type's bounds. | ||
#![feature(trivial_bounds, type_alias_impl_trait)] | ||
#![allow(trivial_bounds)] | ||
|
||
mod sus { | ||
use super::*; | ||
pub type Sep = impl Sized + std::fmt::Display; | ||
//~^ ERROR: concrete type differs from previous defining opaque type use | ||
pub fn mk_sep() -> Sep { | ||
String::from("hello") | ||
} | ||
|
||
pub trait Proj { | ||
type Assoc; | ||
} | ||
impl Proj for () { | ||
type Assoc = sus::Sep; | ||
} | ||
|
||
pub struct Bar<T: Proj> { | ||
pub inner: <T as Proj>::Assoc, | ||
pub _marker: T, | ||
} | ||
impl<T: Proj> Clone for Bar<T> { | ||
fn clone(&self) -> Self { | ||
todo!() | ||
} | ||
} | ||
impl<T: Proj<Assoc = i32> + Copy> Copy for Bar<T> {} | ||
// This allows producing `Tait`s via `From`, even though | ||
// `define_tait` is not actually callable, and thus assumed | ||
// `Bar<()>: Copy` even though it isn't. | ||
pub type Tait = impl Copy + From<Bar<()>> + Into<Bar<()>>; | ||
pub fn define_tait() -> Tait | ||
where | ||
// this proves `Bar<()>: Copy`, but `define_tait` is | ||
// now uncallable | ||
(): Proj<Assoc = i32>, | ||
{ | ||
Bar { inner: 1i32, _marker: () } | ||
} | ||
} | ||
|
||
fn copy_tait(x: sus::Tait) -> (sus::Tait, sus::Tait) { | ||
(x, x) | ||
} | ||
|
||
fn main() { | ||
let bar = sus::Bar { inner: sus::mk_sep(), _marker: () }; | ||
let (y, z) = copy_tait(bar.into()); // copy a string | ||
drop(y.into()); // drop one instance | ||
println!("{}", z.into().inner); // print the other | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/ui/type-alias-impl-trait/hidden_type_mismatch.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,14 @@ | ||
error: concrete type differs from previous defining opaque type use | ||
--> $DIR/hidden_type_mismatch.rs:11:20 | ||
| | ||
LL | pub type Sep = impl Sized + std::fmt::Display; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, got `String` | ||
| | ||
note: previous use here | ||
--> $DIR/hidden_type_mismatch.rs:37:21 | ||
| | ||
LL | pub type Tait = impl Copy + From<Bar<()>> + Into<Bar<()>>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
4 changes: 2 additions & 2 deletions
4
tests/ui/issues/issue-83190.rs → ...-impl-trait/nested-rpit-with-lifetimes.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