diff options
| author | Tyler Mandry <tmandry@gmail.com> | 2021-09-30 01:06:56 +0000 |
|---|---|---|
| committer | Tyler Mandry <tmandry@gmail.com> | 2021-10-13 23:26:00 +0000 |
| commit | 5c14433c00b29fb2065af0eb664e2040f88b4429 (patch) | |
| tree | 0a0a40c2f79eebcc5857ee9b64eff20e4b5e61db /src/test | |
| parent | 2c31c31bb87092fec3da6eefe6d5a3a836c6c5ba (diff) | |
| download | rust-5c14433c00b29fb2065af0eb664e2040f88b4429.tar.gz rust-5c14433c00b29fb2065af0eb664e2040f88b4429.zip | |
Fix incorrect Box::pin suggestion
The suggestion checked if Pin<Box<T>> could be coeerced to the expected type, but did not check predicates created by the coercion. We now look for predicates that definitely cannot be satisfied before giving the suggestion. The suggestion is marked MaybeIncorrect because we allow predicates that are still ambiguous and can't be proven.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/suggestions/box-future-wrong-output.rs | 22 | ||||
| -rw-r--r-- | src/test/ui/suggestions/box-future-wrong-output.stderr | 14 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/box-future-wrong-output.rs b/src/test/ui/suggestions/box-future-wrong-output.rs new file mode 100644 index 00000000000..d49819fcb14 --- /dev/null +++ b/src/test/ui/suggestions/box-future-wrong-output.rs @@ -0,0 +1,22 @@ +// Issue #72117 +// edition:2018 + +use core::future::Future; +use core::pin::Pin; + +pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>; + +impl<T: ?Sized> FutureExt for T where T: Future {} +trait FutureExt: Future { + fn boxed<'a>(self) -> BoxFuture<'a, Self::Output> + where + Self: Sized + Send + 'a, + { + Box::pin(self) + } +} + +fn main() { + let _: BoxFuture<'static, bool> = async {}.boxed(); + //~^ ERROR: mismatched types +} diff --git a/src/test/ui/suggestions/box-future-wrong-output.stderr b/src/test/ui/suggestions/box-future-wrong-output.stderr new file mode 100644 index 00000000000..e0c57af25b3 --- /dev/null +++ b/src/test/ui/suggestions/box-future-wrong-output.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/box-future-wrong-output.rs:20:39 + | +LL | let _: BoxFuture<'static, bool> = async {}.boxed(); + | ------------------------ ^^^^^^^^^^^^^^^^ expected `bool`, found `()` + | | + | expected due to this + | + = note: expected struct `Pin<Box<(dyn Future<Output = bool> + Send + 'static)>>` + found struct `Pin<Box<dyn Future<Output = ()> + Send>>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. |
