From d6276b37eace2e49794679fb927b6b499e00a064 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 5 Jul 2024 21:59:07 -0400 Subject: [PATCH] Don't try to label ObligationCauseCode::CompareImplItem for an RPITIT, since it has no name --- .../src/traits/error_reporting/suggestions.rs | 4 + tests/crashes/125099.rs | 24 --- ...-predicate-entailment-error.current.stderr | 173 ++++++++++++++++++ ...lse-positive-predicate-entailment-error.rs | 51 ++++++ 4 files changed, 228 insertions(+), 24 deletions(-) delete mode 100644 tests/crashes/125099.rs create mode 100644 tests/ui/impl-trait/in-trait/false-positive-predicate-entailment-error.current.stderr create mode 100644 tests/ui/impl-trait/in-trait/false-positive-predicate-entailment-error.rs diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index a0a8e5963f1..52edffce614 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -3472,6 +3472,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { ) }); } + // Suppress `compare_type_predicate_entailment` errors for RPITITs, since they + // should be implied by the parent method. + ObligationCauseCode::CompareImplItem { trait_item_def_id, .. } + if tcx.is_impl_trait_in_trait(trait_item_def_id) => {} ObligationCauseCode::CompareImplItem { trait_item_def_id, kind, .. } => { let item_name = tcx.item_name(trait_item_def_id); let msg = format!( diff --git a/tests/crashes/125099.rs b/tests/crashes/125099.rs deleted file mode 100644 index bfc8c8fdcf6..00000000000 --- a/tests/crashes/125099.rs +++ /dev/null @@ -1,24 +0,0 @@ -//@ known-bug: rust-lang/rust#125099 - -pub trait ContFn: Fn(T) -> Self::Future { - type Future; -} -impl ContFn for F -where - F: Fn(T), -{ - type Future = (); -} - -pub trait SeqHandler { - type Requires; - fn process>() -> impl Sized; -} - -pub struct ConvertToU64; -impl SeqHandler for ConvertToU64 { - type Requires = u64; - fn process>() -> impl Sized {} -} - -fn main() {} diff --git a/tests/ui/impl-trait/in-trait/false-positive-predicate-entailment-error.current.stderr b/tests/ui/impl-trait/in-trait/false-positive-predicate-entailment-error.current.stderr new file mode 100644 index 00000000000..d71c1768a6a --- /dev/null +++ b/tests/ui/impl-trait/in-trait/false-positive-predicate-entailment-error.current.stderr @@ -0,0 +1,173 @@ +error[E0277]: the trait bound `F: MyFn` is not satisfied + --> $DIR/false-positive-predicate-entailment-error.rs:36:5 + | +LL | / fn autobatch(self) -> impl Trait +LL | | +LL | | +LL | | +... | +LL | | where +LL | | F: Callback, + | |_______________________________________^ the trait `MyFn` is not implemented for `F`, which is required by `F: Callback` + | +note: required for `F` to implement `Callback` + --> $DIR/false-positive-predicate-entailment-error.rs:14:21 + | +LL | impl> Callback for F { + | ------- ^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here +help: consider further restricting this bound + | +LL | F: Callback + MyFn, + | +++++++++++ + +error[E0277]: the trait bound `F: MyFn` is not satisfied + --> $DIR/false-positive-predicate-entailment-error.rs:36:30 + | +LL | fn autobatch(self) -> impl Trait + | ^^^^^^^^^^ the trait `MyFn` is not implemented for `F`, which is required by `F: Callback` + | +note: required for `F` to implement `Callback` + --> $DIR/false-positive-predicate-entailment-error.rs:14:21 + | +LL | impl> Callback for F { + | ------- ^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here +note: required by a bound in `::autobatch` + --> $DIR/false-positive-predicate-entailment-error.rs:43:12 + | +LL | fn autobatch(self) -> impl Trait + | --------- required by a bound in this associated function +... +LL | F: Callback, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `::autobatch` +help: consider further restricting this bound + | +LL | F: Callback + MyFn, + | +++++++++++ + +error[E0277]: the trait bound `F: MyFn` is not satisfied + --> $DIR/false-positive-predicate-entailment-error.rs:36:5 + | +LL | / fn autobatch(self) -> impl Trait +LL | | +LL | | +LL | | +... | +LL | | where +LL | | F: Callback, + | |_______________________________________^ the trait `MyFn` is not implemented for `F`, which is required by `F: Callback` + | +note: required for `F` to implement `Callback` + --> $DIR/false-positive-predicate-entailment-error.rs:14:21 + | +LL | impl> Callback for F { + | ------- ^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: consider further restricting this bound + | +LL | F: Callback + MyFn, + | +++++++++++ + +error[E0277]: the trait bound `F: Callback` is not satisfied + --> $DIR/false-positive-predicate-entailment-error.rs:43:12 + | +LL | F: Callback, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MyFn` is not implemented for `F`, which is required by `F: Callback` + | +note: required for `F` to implement `Callback` + --> $DIR/false-positive-predicate-entailment-error.rs:14:21 + | +LL | impl> Callback for F { + | ------- ^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here +note: the requirement `F: Callback` appears on the `impl`'s method `autobatch` but not on the corresponding trait's method + --> $DIR/false-positive-predicate-entailment-error.rs:25:8 + | +LL | trait ChannelSender { + | ------------- in this trait +... +LL | fn autobatch(self) -> impl Trait + | ^^^^^^^^^ this trait's method doesn't have the requirement `F: Callback` +help: consider further restricting this bound + | +LL | F: Callback + MyFn, + | +++++++++++ + +error[E0277]: the trait bound `F: MyFn` is not satisfied + --> $DIR/false-positive-predicate-entailment-error.rs:36:30 + | +LL | fn autobatch(self) -> impl Trait + | ^^^^^^^^^^ the trait `MyFn` is not implemented for `F`, which is required by `F: Callback` + | +note: required for `F` to implement `Callback` + --> $DIR/false-positive-predicate-entailment-error.rs:14:21 + | +LL | impl> Callback for F { + | ------- ^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here + +error[E0277]: the trait bound `F: Callback` is not satisfied + --> $DIR/false-positive-predicate-entailment-error.rs:27:12 + | +LL | F: Callback; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MyFn` is not implemented for `F`, which is required by `F: Callback` + | +note: required for `F` to implement `Callback` + --> $DIR/false-positive-predicate-entailment-error.rs:14:21 + | +LL | impl> Callback for F { + | ------- ^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here + +error[E0277]: the trait bound `F: MyFn` is not satisfied + --> $DIR/false-positive-predicate-entailment-error.rs:36:5 + | +LL | / fn autobatch(self) -> impl Trait +LL | | +LL | | +LL | | +... | +LL | | where +LL | | F: Callback, + | |_______________________________________^ the trait `MyFn` is not implemented for `F`, which is required by `F: Callback` + | +note: required for `F` to implement `Callback` + --> $DIR/false-positive-predicate-entailment-error.rs:14:21 + | +LL | impl> Callback for F { + | ------- ^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: consider further restricting this bound + | +LL | F: Callback + MyFn, + | +++++++++++ + +error[E0277]: the trait bound `F: MyFn` is not satisfied + --> $DIR/false-positive-predicate-entailment-error.rs:43:12 + | +LL | F: Callback, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MyFn` is not implemented for `F` + | +note: required by a bound in `Callback` + --> $DIR/false-positive-predicate-entailment-error.rs:10:20 + | +LL | trait Callback: MyFn { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Callback` +help: consider further restricting this bound + | +LL | F: Callback + MyFn, + | +++++++++++ + +error: aborting due to 8 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/impl-trait/in-trait/false-positive-predicate-entailment-error.rs b/tests/ui/impl-trait/in-trait/false-positive-predicate-entailment-error.rs new file mode 100644 index 00000000000..59fdeab9e0a --- /dev/null +++ b/tests/ui/impl-trait/in-trait/false-positive-predicate-entailment-error.rs @@ -0,0 +1,51 @@ +//@ revisions: current next +//@ ignore-compare-mode-next-solver (explicit revisions) +//@[next] compile-flags: -Znext-solver +//@[next] check-pass + +trait MyFn { + type Output; +} + +trait Callback: MyFn { + type Ret; +} + +impl> Callback for F { + type Ret = F::Output; +} + +struct Thing; +trait Trait {} +impl Trait for Thing {} + +trait ChannelSender { + type CallbackArg; + + fn autobatch(self) -> impl Trait + where + F: Callback; + //[current]~^ ERROR the trait bound `F: Callback` is not satisfied +} + +struct Sender; + +impl ChannelSender for Sender { + type CallbackArg = i32; + + fn autobatch(self) -> impl Trait + //[current]~^ ERROR the trait bound `F: MyFn` is not satisfied + //[current]~| ERROR the trait bound `F: MyFn` is not satisfied + //[current]~| ERROR the trait bound `F: MyFn` is not satisfied + //[current]~| ERROR the trait bound `F: MyFn` is not satisfied + //[current]~| ERROR the trait bound `F: MyFn` is not satisfied + where + F: Callback, + //[current]~^ ERROR the trait bound `F: Callback` is not satisfied + //[current]~| ERROR the trait bound `F: MyFn` is not satisfied + { + Thing + } +} + +fn main() {}