Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show pending obligations as unsatisfied constraints in report_similar_impl_candidates #134348

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_infer/src/traits/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use crate::traits::Obligation;
pub enum ScrubbedTraitError<'tcx> {
/// A real error. This goal definitely does not hold.
TrueError,
// A select error with pending obligations
Select(PredicateObligations<'tcx>),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that it's not really documented, but this is antithetical to the design of ScrubbedTraitError. That type should be very lightweight.

/// An ambiguity. This goal may hold if further inference is done.
Ambiguity,
/// An old-solver-style cycle error, which will fatal.
Expand All @@ -26,7 +28,7 @@ pub enum ScrubbedTraitError<'tcx> {
impl<'tcx> ScrubbedTraitError<'tcx> {
pub fn is_true_error(&self) -> bool {
match self {
ScrubbedTraitError::TrueError => true,
ScrubbedTraitError::TrueError | ScrubbedTraitError::Select(_) => true,
ScrubbedTraitError::Ambiguity | ScrubbedTraitError::Cycle(_) => false,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
use rustc_hir::intravisit::Visitor;
use rustc_hir::{self as hir, LangItem, Node};
use rustc_infer::infer::{InferOk, TypeTrace};
use rustc_infer::traits::ScrubbedTraitError;
use rustc_middle::traits::SignatureMismatchData;
use rustc_middle::traits::select::OverflowError;
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
Expand Down Expand Up @@ -1852,7 +1853,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
{
terrs.push(terr);
}
if !ocx.select_where_possible().is_empty() {

let errors = ocx.select_where_possible();

if !errors.is_empty() {
for error in errors.iter() {
if let ScrubbedTraitError::Select(obligations) = error {
for obligation in obligations.iter() {
let predicate = &obligation.predicate;
err.help(format!(
"the following constraint is not satisfied: `{}`",
predicate
));
}
}
}
return false;
}
}
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_trait_selection/src/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,13 @@ impl<'tcx> FromSolverError<'tcx, OldSolverError<'tcx>> for FulfillmentError<'tcx
impl<'tcx> FromSolverError<'tcx, OldSolverError<'tcx>> for ScrubbedTraitError<'tcx> {
fn from_solver_error(_infcx: &InferCtxt<'tcx>, error: OldSolverError<'tcx>) -> Self {
match error.0.error {
FulfillmentErrorCode::Select(_)
| FulfillmentErrorCode::Project(_)
FulfillmentErrorCode::Select(_) => {
let pendings_obligations =
error.0.backtrace.into_iter().map(|p| p.obligation).collect();

ScrubbedTraitError::Select(pendings_obligations)
}
FulfillmentErrorCode::Project(_)
| FulfillmentErrorCode::Subtype(_, _)
| FulfillmentErrorCode::ConstEquate(_, _) => ScrubbedTraitError::TrueError,
FulfillmentErrorCode::Ambiguity { overflow: _ } => ScrubbedTraitError::Ambiguity,
Expand Down
Loading