mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 06:51:58 +00:00
add debug assertion for suggestions with overlapping parts
This commit is contained in:
parent
a6269dad38
commit
b9e8286c85
@ -629,19 +629,27 @@ impl Diagnostic {
|
||||
applicability: Applicability,
|
||||
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"
|
||||
let mut parts = suggestion
|
||||
.into_iter()
|
||||
.map(|(span, snippet)| SubstitutionPart { snippet, span })
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
parts.sort_unstable_by_key(|part| part.span);
|
||||
|
||||
assert!(!parts.is_empty());
|
||||
debug_assert_eq!(
|
||||
parts.iter().find(|part| part.span.is_empty() && part.snippet.is_empty()),
|
||||
None,
|
||||
"Span must not be empty and have no suggestion",
|
||||
);
|
||||
debug_assert_eq!(
|
||||
parts.array_windows().find(|[a, b]| a.span.overlaps(b.span)),
|
||||
None,
|
||||
"suggestion must not have overlapping parts",
|
||||
);
|
||||
|
||||
self.push_suggestion(CodeSuggestion {
|
||||
substitutions: vec![Substitution {
|
||||
parts: suggestion
|
||||
.into_iter()
|
||||
.map(|(span, snippet)| SubstitutionPart { snippet, span })
|
||||
.collect(),
|
||||
}],
|
||||
substitutions: vec![Substitution { parts }],
|
||||
msg: self.subdiagnostic_message_to_diagnostic_message(msg),
|
||||
style,
|
||||
applicability,
|
||||
@ -802,25 +810,34 @@ impl Diagnostic {
|
||||
suggestions: impl IntoIterator<Item = Vec<(Span, String)>>,
|
||||
applicability: Applicability,
|
||||
) -> &mut Self {
|
||||
let suggestions: Vec<_> = suggestions.into_iter().collect();
|
||||
debug_assert!(
|
||||
!(suggestions
|
||||
.iter()
|
||||
.flatten()
|
||||
.any(|(sp, suggestion)| sp.is_empty() && suggestion.is_empty())),
|
||||
"Span must not be empty and have no suggestion"
|
||||
);
|
||||
let substitutions = suggestions
|
||||
.into_iter()
|
||||
.map(|sugg| {
|
||||
let mut parts = sugg
|
||||
.into_iter()
|
||||
.map(|(span, snippet)| SubstitutionPart { snippet, span })
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
parts.sort_unstable_by_key(|part| part.span);
|
||||
|
||||
assert!(!parts.is_empty());
|
||||
debug_assert_eq!(
|
||||
parts.iter().find(|part| part.span.is_empty() && part.snippet.is_empty()),
|
||||
None,
|
||||
"Span must not be empty and have no suggestion",
|
||||
);
|
||||
debug_assert_eq!(
|
||||
parts.array_windows().find(|[a, b]| a.span.overlaps(b.span)),
|
||||
None,
|
||||
"suggestion must not have overlapping parts",
|
||||
);
|
||||
|
||||
Substitution { parts }
|
||||
})
|
||||
.collect();
|
||||
|
||||
self.push_suggestion(CodeSuggestion {
|
||||
substitutions: suggestions
|
||||
.into_iter()
|
||||
.map(|sugg| Substitution {
|
||||
parts: sugg
|
||||
.into_iter()
|
||||
.map(|(span, snippet)| SubstitutionPart { snippet, span })
|
||||
.collect(),
|
||||
})
|
||||
.collect(),
|
||||
substitutions,
|
||||
msg: self.subdiagnostic_message_to_diagnostic_message(msg),
|
||||
style: SuggestionStyle::ShowCode,
|
||||
applicability,
|
||||
|
@ -3,6 +3,7 @@
|
||||
//! This module contains the code for creating and emitting diagnostics.
|
||||
|
||||
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
||||
#![feature(array_windows)]
|
||||
#![feature(drain_filter)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(is_terminal)]
|
||||
|
Loading…
Reference in New Issue
Block a user