diff options
| author | bors <bors@rust-lang.org> | 2021-07-19 18:44:27 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-07-19 18:44:27 +0000 |
| commit | d5af63480fb08b5276a608a8cd4865fa92d4b2bc (patch) | |
| tree | 4dafbbc941ca3ed032a8bdb4c90c36aeab752152 /compiler/rustc_trait_selection | |
| parent | fad295b299d9e93950c27acd6a12026d100185fe (diff) | |
| parent | ba052bd8de1459acb6809215b0bedf4ea476ef9a (diff) | |
| download | rust-d5af63480fb08b5276a608a8cd4865fa92d4b2bc.tar.gz rust-d5af63480fb08b5276a608a8cd4865fa92d4b2bc.zip | |
Auto merge of #87225 - estebank:cleanup, r=oli-obk
Various diagnostics clean ups/tweaks * Always point at macros, including derive macros * Point at non-local items that introduce a trait requirement * On private associated item, point at definition
Diffstat (limited to 'compiler/rustc_trait_selection')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs | 32 |
1 files changed, 20 insertions, 12 deletions
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 adeb1d58d1e..02d87666e96 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1928,12 +1928,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ObligationCauseCode::ItemObligation(item_def_id) => { let item_name = tcx.def_path_str(item_def_id); let msg = format!("required by `{}`", item_name); - if let Some(sp) = tcx.hir().span_if_local(item_def_id) { - let sp = tcx.sess.source_map().guess_head_span(sp); - err.span_label(sp, &msg); - } else { - err.note(&msg); - } + let sp = tcx + .hir() + .span_if_local(item_def_id) + .unwrap_or_else(|| tcx.def_span(item_def_id)); + let sp = tcx.sess.source_map().guess_head_span(sp); + err.span_note(sp, &msg); } ObligationCauseCode::BindingObligation(item_def_id, span) => { let item_name = tcx.def_path_str(item_def_id); @@ -1952,7 +1952,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { if span != DUMMY_SP { err.span_label(span, &msg); } else { - err.note(&msg); + err.span_note( + tcx.def_span(item_def_id), + &format!("required by a bound in `{}`", item_name), + ); } } ObligationCauseCode::ObjectCastObligation(object_ty) => { @@ -1979,9 +1982,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { if self.tcx.sess.is_nightly_build() && is_const_fn { err.help( - "create an inline `const` block, see RFC \ - #2920 <https://github.com/rust-lang/rfcs/pull/2920> \ - for more information", + "create an inline `const` block, see RFC #2920 \ + <https://github.com/rust-lang/rfcs/pull/2920> for more information", ); } } @@ -2168,8 +2170,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { self.tcx.for_each_relevant_impl( parent_def_id, parent_trait_ref.self_ty().skip_binder(), - |impl_def_id| { - candidates.push(impl_def_id); + |impl_def_id| match self.tcx.hir().get_if_local(impl_def_id) { + Some(Node::Item(hir::Item { + kind: hir::ItemKind::Impl(hir::Impl { .. }), + .. + })) => { + candidates.push(impl_def_id); + } + _ => {} }, ); match &candidates[..] { |
