diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2020-08-18 16:15:55 -0700 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2020-09-11 17:05:18 -0700 |
| commit | ff297fafbfb9af47bc75bc7eac9ff76d83fdd49c (patch) | |
| tree | de6829375f03899ead62aa89e6cbaee03c083ace /compiler | |
| parent | fd9133b9c336e55d12bd5da1c610949473844dcf (diff) | |
| download | rust-ff297fafbfb9af47bc75bc7eac9ff76d83fdd49c.tar.gz rust-ff297fafbfb9af47bc75bc7eac9ff76d83fdd49c.zip | |
Make suggestion have a more targetted underline
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_infer/src/infer/error_reporting/mod.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/check/coercion.rs | 10 |
2 files changed, 12 insertions, 14 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index e772aacfbf9..fe53ccdbad5 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -70,7 +70,7 @@ use rustc_middle::ty::{ subst::{Subst, SubstsRef}, Region, Ty, TyCtxt, TypeFoldable, }; -use rustc_span::{DesugaringKind, Pos, Span}; +use rustc_span::{BytePos, DesugaringKind, Pos, Span}; use rustc_target::spec::abi; use std::{cmp, fmt}; @@ -731,16 +731,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { return_sp: Span, arm_spans: impl Iterator<Item = Span>, ) { - let snippet = self - .tcx - .sess - .source_map() - .span_to_snippet(return_sp) - .unwrap_or_else(|_| "dyn Trait".to_string()); - err.span_suggestion_verbose( - return_sp, + err.multipart_suggestion( "you could change the return type to be a boxed trait object", - format!("Box<dyn {}>", &snippet[5..]), + vec![ + (return_sp.with_hi(return_sp.lo() + BytePos(4)), "Box<dyn".to_string()), + (return_sp.shrink_to_hi(), ">".to_string()), + ], Applicability::MaybeIncorrect, ); let sugg = arm_spans diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index c19bc767563..b669476483b 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -51,7 +51,7 @@ use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{self, Ty, TypeAndMut}; use rustc_session::parse::feature_err; use rustc_span::symbol::sym; -use rustc_span::{self, Span}; +use rustc_span::{self, BytePos, Span}; use rustc_target::spec::abi::Abi; use rustc_trait_selection::traits::error_reporting::InferCtxtExt; use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode}; @@ -1523,10 +1523,12 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { }; if has_impl { if is_object_safe { - err.span_suggestion_verbose( - return_sp, + err.multipart_suggestion( "you could change the return type to be a boxed trait object", - format!("Box<dyn {}>", &snippet[5..]), + vec![ + (return_sp.with_hi(return_sp.lo() + BytePos(4)), "Box<dyn".to_string()), + (return_sp.shrink_to_hi(), ">".to_string()), + ], Applicability::MachineApplicable, ); } else { |
