From 00b976a1381b301a74b4f97f041de9a6cc58dba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Sun, 19 Feb 2023 18:28:44 +0100 Subject: [PATCH] Collect fulfillment errors across impls --- .../rustc_hir_analysis/src/astconv/mod.rs | 4 ++-- ...nd-unsatisfied-bounds-in-multiple-impls.rs | 20 +++++++++++++++++++ ...nsatisfied-bounds-in-multiple-impls.stderr | 20 +++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 tests/ui/associated-inherent-types/not-found-unsatisfied-bounds-in-multiple-impls.rs create mode 100644 tests/ui/associated-inherent-types/not-found-unsatisfied-bounds-in-multiple-impls.stderr diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 4098de59f9e..03b1af76f33 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -2261,9 +2261,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { ocx.register_obligations(impl_obligations); - let errors = ocx.select_where_possible(); + let mut errors = ocx.select_where_possible(); if !errors.is_empty() { - fulfillment_errors = errors; + fulfillment_errors.append(&mut errors); return None; } diff --git a/tests/ui/associated-inherent-types/not-found-unsatisfied-bounds-in-multiple-impls.rs b/tests/ui/associated-inherent-types/not-found-unsatisfied-bounds-in-multiple-impls.rs new file mode 100644 index 00000000000..5b0e8de9c58 --- /dev/null +++ b/tests/ui/associated-inherent-types/not-found-unsatisfied-bounds-in-multiple-impls.rs @@ -0,0 +1,20 @@ +#![feature(inherent_associated_types)] +#![allow(incomplete_features)] + +struct S(A, B); +struct Featureless; + +trait One {} +trait Two {} + +impl S { + type X = (); +} + +impl S { + type X = String; +} + +fn main() { + let _: S::::X; //~ ERROR the associated type `X` exists for `S`, but its trait bounds were not satisfied +} diff --git a/tests/ui/associated-inherent-types/not-found-unsatisfied-bounds-in-multiple-impls.stderr b/tests/ui/associated-inherent-types/not-found-unsatisfied-bounds-in-multiple-impls.stderr new file mode 100644 index 00000000000..3ddab25deb5 --- /dev/null +++ b/tests/ui/associated-inherent-types/not-found-unsatisfied-bounds-in-multiple-impls.stderr @@ -0,0 +1,20 @@ +error: the associated type `X` exists for `S`, but its trait bounds were not satisfied + --> $DIR/not-found-unsatisfied-bounds-in-multiple-impls.rs:19:43 + | +LL | struct S(A, B); + | -------------- associated item `X` not found for this struct +LL | struct Featureless; + | ------------------ + | | + | doesn't satisfy `Featureless: One` + | doesn't satisfy `Featureless: Two` +... +LL | let _: S::::X; + | ^ associated type cannot be referenced on `S` due to unsatisfied trait bounds + | + = note: the following trait bounds were not satisfied: + `Featureless: One` + `Featureless: Two` + +error: aborting due to previous error +