Rollup merge of #102922 - kper:bugfix/102902-filtering-json, r=oli-obk
Filtering spans when emitting json According to the issue #102902, we shouldn't emit spans which have an empty span and no suggested replacement.
This commit is contained in:
commit
0a0e9f73af
8 changed files with 81 additions and 117 deletions
|
@ -567,6 +567,11 @@ impl Diagnostic {
|
|||
style: SuggestionStyle,
|
||||
) -> &mut Self {
|
||||
assert!(!suggestion.is_empty());
|
||||
debug_assert!(
|
||||
!(suggestion.iter().any(|(sp, text)| sp.is_empty() && text.is_empty())),
|
||||
"Span must not be empty and have no suggestion"
|
||||
);
|
||||
|
||||
self.push_suggestion(CodeSuggestion {
|
||||
substitutions: vec![Substitution {
|
||||
parts: suggestion
|
||||
|
@ -644,6 +649,10 @@ impl Diagnostic {
|
|||
applicability: Applicability,
|
||||
style: SuggestionStyle,
|
||||
) -> &mut Self {
|
||||
debug_assert!(
|
||||
!(sp.is_empty() && suggestion.to_string().is_empty()),
|
||||
"Span must not be empty and have no suggestion"
|
||||
);
|
||||
self.push_suggestion(CodeSuggestion {
|
||||
substitutions: vec![Substitution {
|
||||
parts: vec![SubstitutionPart { snippet: suggestion.to_string(), span: sp }],
|
||||
|
@ -684,6 +693,12 @@ impl Diagnostic {
|
|||
) -> &mut Self {
|
||||
let mut suggestions: Vec<_> = suggestions.collect();
|
||||
suggestions.sort();
|
||||
|
||||
debug_assert!(
|
||||
!(sp.is_empty() && suggestions.iter().any(|suggestion| suggestion.is_empty())),
|
||||
"Span must not be empty and have no suggestion"
|
||||
);
|
||||
|
||||
let substitutions = suggestions
|
||||
.into_iter()
|
||||
.map(|snippet| Substitution { parts: vec![SubstitutionPart { snippet, span: sp }] })
|
||||
|
@ -705,8 +720,18 @@ impl Diagnostic {
|
|||
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
|
||||
applicability: Applicability,
|
||||
) -> &mut Self {
|
||||
let suggestions: Vec<_> = suggestions.collect();
|
||||
debug_assert!(
|
||||
!(suggestions
|
||||
.iter()
|
||||
.flat_map(|suggs| suggs)
|
||||
.any(|(sp, suggestion)| sp.is_empty() && suggestion.is_empty())),
|
||||
"Span must not be empty and have no suggestion"
|
||||
);
|
||||
|
||||
self.push_suggestion(CodeSuggestion {
|
||||
substitutions: suggestions
|
||||
.into_iter()
|
||||
.map(|sugg| Substitution {
|
||||
parts: sugg
|
||||
.into_iter()
|
||||
|
|
|
@ -22,7 +22,7 @@ use rustc_span::edition::Edition;
|
|||
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId};
|
||||
use rustc_span::source_map::SourceMap;
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{FileName, Span, DUMMY_SP};
|
||||
use rustc_span::{BytePos, FileName, Span, DUMMY_SP};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
|
||||
use std::default::Default;
|
||||
|
@ -1228,8 +1228,9 @@ pub fn expr_to_spanned_string<'a>(
|
|||
ast::LitKind::Str(s, style) => return Ok((s, style, expr.span)),
|
||||
ast::LitKind::ByteStr(_) => {
|
||||
let mut err = cx.struct_span_err(l.span, err_msg);
|
||||
let span = expr.span.shrink_to_lo();
|
||||
err.span_suggestion(
|
||||
expr.span.shrink_to_lo(),
|
||||
span.with_hi(span.lo() + BytePos(1)),
|
||||
"consider removing the leading `b`",
|
||||
"",
|
||||
Applicability::MaybeIncorrect,
|
||||
|
|
|
@ -3051,24 +3051,27 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
.map_or(false, |s| s.trim_end().ends_with('<'));
|
||||
|
||||
let is_global = poly_trait_ref.trait_ref.path.is_global();
|
||||
let sugg = Vec::from_iter([
|
||||
(
|
||||
self_ty.span.shrink_to_lo(),
|
||||
format!(
|
||||
"{}dyn {}",
|
||||
if needs_bracket { "<" } else { "" },
|
||||
if is_global { "(" } else { "" },
|
||||
),
|
||||
|
||||
let mut sugg = Vec::from_iter([(
|
||||
self_ty.span.shrink_to_lo(),
|
||||
format!(
|
||||
"{}dyn {}",
|
||||
if needs_bracket { "<" } else { "" },
|
||||
if is_global { "(" } else { "" },
|
||||
),
|
||||
(
|
||||
)]);
|
||||
|
||||
if is_global || needs_bracket {
|
||||
sugg.push((
|
||||
self_ty.span.shrink_to_hi(),
|
||||
format!(
|
||||
"{}{}",
|
||||
if is_global { ")" } else { "" },
|
||||
if needs_bracket { ">" } else { "" },
|
||||
),
|
||||
),
|
||||
]);
|
||||
));
|
||||
}
|
||||
|
||||
if self_ty.span.edition() >= Edition::Edition2021 {
|
||||
let msg = "trait objects must include the `dyn` keyword";
|
||||
let label = "add `dyn` keyword before this trait";
|
||||
|
|
|
@ -1374,9 +1374,17 @@ impl<'a> Parser<'a> {
|
|||
kind: IncDecRecovery,
|
||||
(pre_span, post_span): (Span, Span),
|
||||
) -> MultiSugg {
|
||||
let mut patches = Vec::new();
|
||||
|
||||
if !pre_span.is_empty() {
|
||||
patches.push((pre_span, String::new()));
|
||||
}
|
||||
|
||||
patches.push((post_span, format!(" {}= 1", kind.op.chr())));
|
||||
|
||||
MultiSugg {
|
||||
msg: format!("use `{}= 1` instead", kind.op.chr()),
|
||||
patches: vec![(pre_span, String::new()), (post_span, format!(" {}= 1", kind.op.chr()))],
|
||||
patches,
|
||||
applicability: Applicability::MachineApplicable,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue