diff options
| author | Mikhail Babenko <misha-babenko@yandex.ru> | 2019-11-21 21:01:14 +0300 |
|---|---|---|
| committer | Mikhail Babenko <misha-babenko@yandex.ru> | 2019-11-29 17:30:21 +0300 |
| commit | f07bd0613790080225cc7f7cc735655dcb2257f8 (patch) | |
| tree | 39d982215eab1f4a6cef2e5b3bbe97efaae4cc19 /src/librustc/traits | |
| parent | fe969f4ec67a5bd317818cbc7a648c5795af15fa (diff) | |
| download | rust-f07bd0613790080225cc7f7cc735655dcb2257f8.tar.gz rust-f07bd0613790080225cc7f7cc735655dcb2257f8.zip | |
allow customising ty::TraitRef's printing behavior
fix clippy allow customising ty::TraitRef's printing behavior fix clippy stylistic fix
Diffstat (limited to 'src/librustc/traits')
| -rw-r--r-- | src/librustc/traits/error_reporting.rs | 18 | ||||
| -rw-r--r-- | src/librustc/traits/select.rs | 4 | ||||
| -rw-r--r-- | src/librustc/traits/specialize/mod.rs | 2 | ||||
| -rw-r--r-- | src/librustc/traits/specialize/specialization_graph.rs | 2 |
4 files changed, 14 insertions, 12 deletions
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 6e723cdc999..90db1fe3195 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -737,7 +737,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let is_try = self.tcx.sess.source_map().span_to_snippet(span) .map(|s| &s == "?") .unwrap_or(false); - let is_from = format!("{}", trait_ref).starts_with("std::convert::From<"); + let is_from = + format!("{}", trait_ref.print_only_trait_path()) + .starts_with("std::convert::From<"); let (message, note) = if is_try && is_from { (Some(format!( "`?` couldn't convert the error to `{}`", @@ -768,7 +770,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { format!( "{}the trait `{}` is not implemented for `{}`", pre_message, - trait_ref, + trait_ref.print_only_trait_path(), trait_ref.self_ty(), ) }; @@ -1189,7 +1191,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { if param_ty => { // Missing generic type parameter bound. let param_name = self_ty.to_string(); - let constraint = trait_ref.to_string(); + let constraint = trait_ref.print_only_trait_path().to_string(); if suggest_constraining_type_param( generics, &mut err, @@ -1416,7 +1418,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let msg = format!( "the trait bound `{}: {}` is not satisfied", found, - obligation.parent_trait_ref.skip_binder(), + obligation.parent_trait_ref.skip_binder().print_only_trait_path(), ); if has_custom_message { err.note(&msg); @@ -1430,7 +1432,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } err.span_label(span, &format!( "expected an implementor of trait `{}`", - obligation.parent_trait_ref.skip_binder(), + obligation.parent_trait_ref.skip_binder().print_only_trait_path(), )); err.span_suggestion( span, @@ -1562,7 +1564,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } else { err.note(&format!( "`{}` is implemented for `{:?}`, but not for `{:?}`", - trait_ref, + trait_ref.print_only_trait_path(), trait_type, trait_ref.skip_binder().self_ty(), )); @@ -2226,7 +2228,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { err.span_note(span, &format!( "future does not implement `{}` as this value is used across an await", - trait_ref, + trait_ref.print_only_trait_path(), )); // Add a note for the item obligation that remains - normally a note pointing to the @@ -2409,7 +2411,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref); err.note( &format!("required because of the requirements on the impl of `{}` for `{}`", - parent_trait_ref, + parent_trait_ref.print_only_trait_path(), parent_trait_ref.skip_binder().self_ty())); let parent_predicate = parent_trait_ref.to_predicate(); self.note_obligation_cause_code(err, diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 283fa56d11f..5f324527a27 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -1044,7 +1044,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let trait_ref = stack.obligation.predicate.skip_binder().trait_ref; let self_ty = trait_ref.self_ty(); let cause = IntercrateAmbiguityCause::DownstreamCrate { - trait_desc: trait_ref.to_string(), + trait_desc: trait_ref.print_only_trait_path().to_string(), self_desc: if self_ty.has_concrete_skeleton() { Some(self_ty.to_string()) } else { @@ -1386,7 +1386,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { if !candidate_set.ambiguous && no_candidates_apply { let trait_ref = stack.obligation.predicate.skip_binder().trait_ref; let self_ty = trait_ref.self_ty(); - let trait_desc = trait_ref.to_string(); + let trait_desc = trait_ref.print_only_trait_path().to_string(); let self_desc = if self_ty.has_concrete_skeleton() { Some(self_ty.to_string()) } else { diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 475037f54ba..88a2db3dc62 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -417,7 +417,7 @@ fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Option<String> w.push('>'); } - write!(w, " {} for {}", trait_ref, tcx.type_of(impl_def_id)).unwrap(); + write!(w, " {} for {}", trait_ref.print_only_trait_path(), tcx.type_of(impl_def_id)).unwrap(); // The predicates will contain default bounds like `T: Sized`. We need to // remove these bounds, and add `T: ?Sized` to any untouched type parameters. diff --git a/src/librustc/traits/specialize/specialization_graph.rs b/src/librustc/traits/specialize/specialization_graph.rs index d945c756f66..b8ddf6078bd 100644 --- a/src/librustc/traits/specialize/specialization_graph.rs +++ b/src/librustc/traits/specialize/specialization_graph.rs @@ -146,7 +146,7 @@ impl<'tcx> Children { let self_ty = trait_ref.self_ty(); OverlapError { with_impl: possible_sibling, - trait_desc: trait_ref.to_string(), + trait_desc: trait_ref.print_only_trait_path().to_string(), // Only report the `Self` type if it has at least // some outer concrete shell; otherwise, it's // not adding much information. |
