Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-diagnostics/src/handlers/unimplemented_trait.rs')
| -rw-r--r-- | crates/ide-diagnostics/src/handlers/unimplemented_trait.rs | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/crates/ide-diagnostics/src/handlers/unimplemented_trait.rs b/crates/ide-diagnostics/src/handlers/unimplemented_trait.rs index 4a253bc831..702f9fa7c9 100644 --- a/crates/ide-diagnostics/src/handlers/unimplemented_trait.rs +++ b/crates/ide-diagnostics/src/handlers/unimplemented_trait.rs @@ -9,18 +9,19 @@ pub(crate) fn unimplemented_trait<'db>( ctx: &DiagnosticsContext<'_, 'db>, d: &hir::UnimplementedTrait<'db>, ) -> Diagnostic { - let message = match &d.root_trait_predicate { - Some(root_predicate) if *root_predicate != d.trait_predicate => format!( - "the trait bound `{}` is not satisfied\n\ - required by the bound `{}`\n", - d.trait_predicate.display(ctx.db(), ctx.display_target), - root_predicate.display(ctx.db(), ctx.display_target), - ), - _ => format!( - "the trait bound `{}` is not satisfied", - d.trait_predicate.display(ctx.db(), ctx.display_target), - ), - }; + let mut message = format!( + "the trait bound `{}` is not satisfied", + d.trait_predicate.display(ctx.db(), ctx.display_target), + ); + for parent_predicate in &d.parent_trait_predicates { + message.push_str(&format!( + "\nrequired by the bound `{}`", + parent_predicate.display(ctx.db(), ctx.display_target), + )); + } + if !d.parent_trait_predicates.is_empty() { + message.push('\n'); + } Diagnostic::new_with_syntax_node_ptr( ctx, DiagnosticCode::RustcHardError("E0277"), @@ -46,6 +47,10 @@ fn bar() { foo([1]); // ^^^ error: the trait bound `i32: Trait` is not satisfied // | required by the bound `[i32; 1]: Trait` + foo([[1]]); + // ^^^ error: the trait bound `i32: Trait` is not satisfied + // | required by the bound `[i32; 1]: Trait` + // | required by the bound `[[i32; 1]; 1]: Trait` } "#, ); @@ -78,7 +83,6 @@ fn foo() { fn foo() { for _ in () {} // ^^ error: the trait bound `(): Iterator` is not satisfied - // ^^ error: the trait bound `(): Iterator` is not satisfied // | required by the bound `(): IntoIterator` } |