From d8dc31fd3d2a03bc4b01974328c92d2ffb2f4fea Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 23 Oct 2024 23:49:46 +0000 Subject: [PATCH] Consider param-env candidates even if they have errors --- .../src/traits/select/candidate_assembly.rs | 1 - tests/crashes/110630.rs | 28 ---------------- tests/crashes/115808.rs | 27 ---------------- tests/crashes/121052.rs | 32 ------------------- .../in-trait/unconstrained-impl-region.rs | 1 - .../in-trait/unconstrained-impl-region.stderr | 17 ++-------- .../error-reporting/apit-with-bad-path.rs | 10 ++++++ .../error-reporting/apit-with-bad-path.stderr | 14 ++++++++ .../where-clause-with-bad-path.rs | 10 ++++++ .../where-clause-with-bad-path.stderr | 14 ++++++++ 10 files changed, 50 insertions(+), 104 deletions(-) delete mode 100644 tests/crashes/110630.rs delete mode 100644 tests/crashes/115808.rs delete mode 100644 tests/crashes/121052.rs create mode 100644 tests/ui/traits/error-reporting/apit-with-bad-path.rs create mode 100644 tests/ui/traits/error-reporting/apit-with-bad-path.stderr create mode 100644 tests/ui/traits/error-reporting/where-clause-with-bad-path.rs create mode 100644 tests/ui/traits/error-reporting/where-clause-with-bad-path.stderr diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index eea3867190d..c0122d3d552 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -244,7 +244,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .param_env .caller_bounds() .iter() - .filter(|p| !p.references_error()) .filter_map(|p| p.as_trait_clause()) // Micro-optimization: filter out predicates relating to different traits. .filter(|p| p.def_id() == stack.obligation.predicate.def_id()) diff --git a/tests/crashes/110630.rs b/tests/crashes/110630.rs deleted file mode 100644 index f17f6f0781f..00000000000 --- a/tests/crashes/110630.rs +++ /dev/null @@ -1,28 +0,0 @@ -//@ known-bug: #110630 - -#![feature(generic_const_exprs)] - -use std::ops::Mul; - -pub trait Indices { - const NUM_ELEMS: usize = I::NUM_ELEMS * N; -} - -pub trait Concat { - type Output; -} - -pub struct Tensor, const N: usize> -where - [u8; I::NUM_ELEMS]: Sized, {} - -impl, J: Indices, const N: usize> Mul> for Tensor -where - I: Concat, - >::Output: Indices, - [u8; I::NUM_ELEMS]: Sized, - [u8; J::NUM_ELEMS]: Sized, - [u8; >::Output::NUM_ELEMS]: Sized, -{ - type Output = Tensor<>::Output, N>; -} diff --git a/tests/crashes/115808.rs b/tests/crashes/115808.rs deleted file mode 100644 index 79196ac9c65..00000000000 --- a/tests/crashes/115808.rs +++ /dev/null @@ -1,27 +0,0 @@ -//@ known-bug: #115808 -#![feature(generic_const_exprs)] - -use std::ops::Mul; - -pub trait Indices { - const NUM_ELEMS: usize; -} - -pub trait Concat { - type Output; -} - -pub struct Tensor, const N: usize> -where - [u8; I::NUM_ELEMS]: Sized, {} - -impl, J: Indices, const N: usize> Mul> for Tensor -where - I: Concat, - >::Output: Indices, - [u8; I::NUM_ELEMS]: Sized, - [u8; J::NUM_ELEMS]: Sized, - [u8; >::Output::NUM_ELEMS]: Sized, -{ - type Output = Tensor<>::Output, N>; -} diff --git a/tests/crashes/121052.rs b/tests/crashes/121052.rs deleted file mode 100644 index 5d16b06db23..00000000000 --- a/tests/crashes/121052.rs +++ /dev/null @@ -1,32 +0,0 @@ -//@ known-bug: #121052 -#![feature(generic_const_exprs, with_negative_coherence)] - -use std::ops::Mul; - -pub trait Indices { - const NUM_ELEMS: usize; -} - -impl, J: Indices, const N: usize> Mul for Tensor -where - I: Concat, - >::Output: Indices, - [u8; I::NUM_ELEMS]: Sized, - [u8; J::NUM_ELEMS]: Sized, - [u8; >::Output::NUM_ELEMS]: Sized, -{ -} - -pub trait Concat {} - -pub struct Tensor, const N: usize> {} - -impl, J: Indices, const N: usize> Mul for Tensor -where - I: Concat, - >::Output: Indices, - [u8; I::NUM_ELEMS]: Sized, - [u8; J::NUM_ELEMS]: Sized, - [u8; >::Output::NUM_ELEMS]: Sized, -{ -} diff --git a/tests/ui/async-await/in-trait/unconstrained-impl-region.rs b/tests/ui/async-await/in-trait/unconstrained-impl-region.rs index 95ba1f3f277..9382c232364 100644 --- a/tests/ui/async-await/in-trait/unconstrained-impl-region.rs +++ b/tests/ui/async-await/in-trait/unconstrained-impl-region.rs @@ -14,7 +14,6 @@ impl<'a> Actor for () { //~^ ERROR the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates type Message = &'a (); async fn on_mount(self, _: impl Inbox<&'a ()>) {} - //~^ ERROR the trait bound `impl Inbox<&'a ()>: Inbox<&'a ()>` is not satisfied } fn main() {} diff --git a/tests/ui/async-await/in-trait/unconstrained-impl-region.stderr b/tests/ui/async-await/in-trait/unconstrained-impl-region.stderr index 80dc5fdc747..ef7e4ef0eb8 100644 --- a/tests/ui/async-await/in-trait/unconstrained-impl-region.stderr +++ b/tests/ui/async-await/in-trait/unconstrained-impl-region.stderr @@ -1,22 +1,9 @@ -error[E0277]: the trait bound `impl Inbox<&'a ()>: Inbox<&'a ()>` is not satisfied - --> $DIR/unconstrained-impl-region.rs:16:5 - | -LL | async fn on_mount(self, _: impl Inbox<&'a ()>) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Inbox<&'a ()>` is not implemented for `impl Inbox<&'a ()>` - | -note: required by a bound in `<() as Actor>::on_mount` - --> $DIR/unconstrained-impl-region.rs:16:37 - | -LL | async fn on_mount(self, _: impl Inbox<&'a ()>) {} - | ^^^^^^^^^^^^^ required by this bound in `<() as Actor>::on_mount` - error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates --> $DIR/unconstrained-impl-region.rs:13:6 | LL | impl<'a> Actor for () { | ^^ unconstrained lifetime parameter -error: aborting due to 2 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0207, E0277. -For more information about an error, try `rustc --explain E0207`. +For more information about this error, try `rustc --explain E0207`. diff --git a/tests/ui/traits/error-reporting/apit-with-bad-path.rs b/tests/ui/traits/error-reporting/apit-with-bad-path.rs new file mode 100644 index 00000000000..57184b9d0a9 --- /dev/null +++ b/tests/ui/traits/error-reporting/apit-with-bad-path.rs @@ -0,0 +1,10 @@ +// Ensure that we don't emit an E0270 for "`impl AsRef: AsRef` not satisfied". + +fn foo(filename: impl AsRef) { + //~^ ERROR cannot find type `Path` in this scope + std::fs::write(filename, "hello").unwrap(); +} + +fn main() { + foo("/tmp/hello"); +} diff --git a/tests/ui/traits/error-reporting/apit-with-bad-path.stderr b/tests/ui/traits/error-reporting/apit-with-bad-path.stderr new file mode 100644 index 00000000000..19bd5e78b47 --- /dev/null +++ b/tests/ui/traits/error-reporting/apit-with-bad-path.stderr @@ -0,0 +1,14 @@ +error[E0412]: cannot find type `Path` in this scope + --> $DIR/apit-with-bad-path.rs:3:29 + | +LL | fn foo(filename: impl AsRef) { + | ^^^^ not found in this scope + | +help: consider importing this struct + | +LL + use std::path::Path; + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/traits/error-reporting/where-clause-with-bad-path.rs b/tests/ui/traits/error-reporting/where-clause-with-bad-path.rs new file mode 100644 index 00000000000..cbe14887de4 --- /dev/null +++ b/tests/ui/traits/error-reporting/where-clause-with-bad-path.rs @@ -0,0 +1,10 @@ +// Ensure that we don't emit an E0270 for "`impl AsRef: AsRef` not satisfied". + +fn foo>(filename: T) { + //~^ ERROR cannot find type `Path` in this scope + std::fs::write(filename, "hello").unwrap(); +} + +fn main() { + foo("/tmp/hello"); +} diff --git a/tests/ui/traits/error-reporting/where-clause-with-bad-path.stderr b/tests/ui/traits/error-reporting/where-clause-with-bad-path.stderr new file mode 100644 index 00000000000..1137178f611 --- /dev/null +++ b/tests/ui/traits/error-reporting/where-clause-with-bad-path.stderr @@ -0,0 +1,14 @@ +error[E0412]: cannot find type `Path` in this scope + --> $DIR/where-clause-with-bad-path.rs:3:17 + | +LL | fn foo>(filename: T) { + | ^^^^ not found in this scope + | +help: consider importing this struct + | +LL + use std::path::Path; + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0412`.