mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Don't sort span_suggestions
, leave that to caller
This commit is contained in:
parent
42aa1273b0
commit
f1ae02f4bd
@ -759,9 +759,6 @@ impl Diagnostic {
|
|||||||
suggestions: impl IntoIterator<Item = String>,
|
suggestions: impl IntoIterator<Item = String>,
|
||||||
applicability: Applicability,
|
applicability: Applicability,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
let mut suggestions: Vec<_> = suggestions.into_iter().collect();
|
|
||||||
suggestions.sort();
|
|
||||||
|
|
||||||
self.span_suggestions_with_style(
|
self.span_suggestions_with_style(
|
||||||
sp,
|
sp,
|
||||||
msg,
|
msg,
|
||||||
@ -771,9 +768,7 @@ impl Diagnostic {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [`Diagnostic::span_suggestions()`] but you can set the [`SuggestionStyle`]. This version
|
/// [`Diagnostic::span_suggestions()`] but you can set the [`SuggestionStyle`].
|
||||||
/// *doesn't* sort the suggestions, so the caller has control of the order in which they are
|
|
||||||
/// presented.
|
|
||||||
pub fn span_suggestions_with_style(
|
pub fn span_suggestions_with_style(
|
||||||
&mut self,
|
&mut self,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
|
@ -945,7 +945,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
match (types, traits) {
|
let mut types = types.to_vec();
|
||||||
|
types.sort();
|
||||||
|
let mut traits = traits.to_vec();
|
||||||
|
traits.sort();
|
||||||
|
match (&types[..], &traits[..]) {
|
||||||
([], []) => {
|
([], []) => {
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
span,
|
span,
|
||||||
|
@ -2703,7 +2703,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
self.get_field_candidates_considering_privacy(span, ty, mod_id, id)
|
self.get_field_candidates_considering_privacy(span, ty, mod_id, id)
|
||||||
{
|
{
|
||||||
let field_names = found_fields.iter().map(|field| field.name).collect::<Vec<_>>();
|
let field_names = found_fields.iter().map(|field| field.name).collect::<Vec<_>>();
|
||||||
let candidate_fields: Vec<_> = found_fields
|
let mut candidate_fields: Vec<_> = found_fields
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|candidate_field| {
|
.filter_map(|candidate_field| {
|
||||||
self.check_for_nested_field_satisfying(
|
self.check_for_nested_field_satisfying(
|
||||||
@ -2724,6 +2724,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
.collect::<String>()
|
.collect::<String>()
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
candidate_fields.sort();
|
||||||
|
|
||||||
let len = candidate_fields.len();
|
let len = candidate_fields.len();
|
||||||
if len > 0 {
|
if len > 0 {
|
||||||
|
@ -1426,6 +1426,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
if !suggs.is_empty()
|
if !suggs.is_empty()
|
||||||
&& let Some(span) = sugg_span
|
&& let Some(span) = sugg_span
|
||||||
{
|
{
|
||||||
|
suggs.sort();
|
||||||
err.span_suggestions(
|
err.span_suggestions(
|
||||||
span.with_hi(item_name.span.lo()),
|
span.with_hi(item_name.span.lo()),
|
||||||
"use fully-qualified syntax to disambiguate",
|
"use fully-qualified syntax to disambiguate",
|
||||||
@ -2000,8 +2001,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
self.tcx.get_diagnostic_item(sym::Borrow),
|
self.tcx.get_diagnostic_item(sym::Borrow),
|
||||||
self.tcx.get_diagnostic_item(sym::BorrowMut),
|
self.tcx.get_diagnostic_item(sym::BorrowMut),
|
||||||
];
|
];
|
||||||
let candidate_fields: Vec<_> = fields
|
let mut candidate_fields: Vec<_> = fields
|
||||||
.iter()
|
|
||||||
.filter_map(|candidate_field| {
|
.filter_map(|candidate_field| {
|
||||||
self.check_for_nested_field_satisfying(
|
self.check_for_nested_field_satisfying(
|
||||||
span,
|
span,
|
||||||
@ -2035,6 +2035,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
.join(".")
|
.join(".")
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
candidate_fields.sort();
|
||||||
|
|
||||||
let len = candidate_fields.len();
|
let len = candidate_fields.len();
|
||||||
if len > 0 {
|
if len > 0 {
|
||||||
@ -2567,13 +2568,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
self.tcx.item_name(*trait_did),
|
self.tcx.item_name(*trait_did),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
let mut sugg: Vec<_> = path_strings.chain(glob_path_strings).collect();
|
||||||
|
sugg.sort();
|
||||||
|
|
||||||
err.span_suggestions(
|
err.span_suggestions(span, msg, sugg, Applicability::MaybeIncorrect);
|
||||||
span,
|
|
||||||
msg,
|
|
||||||
path_strings.chain(glob_path_strings),
|
|
||||||
Applicability::MaybeIncorrect,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn suggest_valid_traits(
|
fn suggest_valid_traits(
|
||||||
|
@ -442,12 +442,10 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
|
|||||||
|
|
||||||
self.formatting_init.extend(code_init);
|
self.formatting_init.extend(code_init);
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
let mut code: Vec<_> = #code_field.into_iter().collect();
|
|
||||||
code.sort();
|
|
||||||
#diag.span_suggestions_with_style(
|
#diag.span_suggestions_with_style(
|
||||||
#span_field,
|
#span_field,
|
||||||
crate::fluent_generated::#slug,
|
crate::fluent_generated::#slug,
|
||||||
code,
|
#code_field,
|
||||||
#applicability,
|
#applicability,
|
||||||
#style
|
#style
|
||||||
);
|
);
|
||||||
|
@ -186,6 +186,7 @@ fn emit_malformed_attribute(
|
|||||||
msg.push_str(&format!("`{code}`"));
|
msg.push_str(&format!("`{code}`"));
|
||||||
suggestions.push(code);
|
suggestions.push(code);
|
||||||
}
|
}
|
||||||
|
suggestions.sort();
|
||||||
if should_warn(name) {
|
if should_warn(name) {
|
||||||
sess.buffer_lint(&ILL_FORMED_ATTRIBUTE_INPUT, span, ast::CRATE_NODE_ID, msg);
|
sess.buffer_lint(&ILL_FORMED_ATTRIBUTE_INPUT, span, ast::CRATE_NODE_ID, msg);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1639,9 +1639,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||||||
} else {
|
} else {
|
||||||
3
|
3
|
||||||
};
|
};
|
||||||
return Some((order, item.name));
|
Some((order, item.name))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
None
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
items.sort_by_key(|(order, _)| *order);
|
items.sort_by_key(|(order, _)| *order);
|
||||||
@ -2147,11 +2148,12 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||||||
if suggest_only_tuple_variants {
|
if suggest_only_tuple_variants {
|
||||||
// Suggest only tuple variants regardless of whether they have fields and do not
|
// Suggest only tuple variants regardless of whether they have fields and do not
|
||||||
// suggest path with added parentheses.
|
// suggest path with added parentheses.
|
||||||
let suggestable_variants = variants
|
let mut suggestable_variants = variants
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(.., kind)| *kind == CtorKind::Fn)
|
.filter(|(.., kind)| *kind == CtorKind::Fn)
|
||||||
.map(|(variant, ..)| path_names_to_string(variant))
|
.map(|(variant, ..)| path_names_to_string(variant))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
suggestable_variants.sort();
|
||||||
|
|
||||||
let non_suggestable_variant_count = variants.len() - suggestable_variants.len();
|
let non_suggestable_variant_count = variants.len() - suggestable_variants.len();
|
||||||
|
|
||||||
@ -2202,7 +2204,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let suggestable_variants = variants
|
let mut suggestable_variants = variants
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(_, def_id, kind)| !needs_placeholder(*def_id, *kind))
|
.filter(|(_, def_id, kind)| !needs_placeholder(*def_id, *kind))
|
||||||
.map(|(variant, _, kind)| (path_names_to_string(variant), kind))
|
.map(|(variant, _, kind)| (path_names_to_string(variant), kind))
|
||||||
@ -2211,6 +2213,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||||||
CtorKind::Fn => format!("({variant}())"),
|
CtorKind::Fn => format!("({variant}())"),
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
suggestable_variants.sort();
|
||||||
let no_suggestable_variant = suggestable_variants.is_empty();
|
let no_suggestable_variant = suggestable_variants.is_empty();
|
||||||
|
|
||||||
if !no_suggestable_variant {
|
if !no_suggestable_variant {
|
||||||
@ -2228,7 +2231,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let suggestable_variants_with_placeholders = variants
|
let mut suggestable_variants_with_placeholders = variants
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(_, def_id, kind)| needs_placeholder(*def_id, *kind))
|
.filter(|(_, def_id, kind)| needs_placeholder(*def_id, *kind))
|
||||||
.map(|(variant, _, kind)| (path_names_to_string(variant), kind))
|
.map(|(variant, _, kind)| (path_names_to_string(variant), kind))
|
||||||
@ -2237,6 +2240,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
suggestable_variants_with_placeholders.sort();
|
||||||
|
|
||||||
if !suggestable_variants_with_placeholders.is_empty() {
|
if !suggestable_variants_with_placeholders.is_empty() {
|
||||||
let msg =
|
let msg =
|
||||||
|
@ -424,8 +424,9 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
|
|||||||
improvements.push(suggestion);
|
improvements.push(suggestion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let nonminimal_bool_lint = |suggestions: Vec<_>| {
|
let nonminimal_bool_lint = |mut suggestions: Vec<_>| {
|
||||||
if self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, e.hir_id).0 != Level::Allow {
|
if self.cx.tcx.lint_level_at_node(NONMINIMAL_BOOL, e.hir_id).0 != Level::Allow {
|
||||||
|
suggestions.sort();
|
||||||
span_lint_hir_and_then(
|
span_lint_hir_and_then(
|
||||||
self.cx,
|
self.cx,
|
||||||
NONMINIMAL_BOOL,
|
NONMINIMAL_BOOL,
|
||||||
|
@ -6,10 +6,10 @@ LL | fn foo(_: *()) {
|
|||||||
|
|
|
|
||||||
help: add `mut` or `const` here
|
help: add `mut` or `const` here
|
||||||
|
|
|
|
||||||
LL | fn foo(_: *const ()) {
|
|
||||||
| +++++
|
|
||||||
LL | fn foo(_: *mut ()) {
|
LL | fn foo(_: *mut ()) {
|
||||||
| +++
|
| +++
|
||||||
|
LL | fn foo(_: *const ()) {
|
||||||
|
| +++++
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -6,10 +6,10 @@ LL | let dptr: **const i32 = &ptr;
|
|||||||
|
|
|
|
||||||
help: add `mut` or `const` here
|
help: add `mut` or `const` here
|
||||||
|
|
|
|
||||||
LL | let dptr: *const *const i32 = &ptr;
|
|
||||||
| +++++
|
|
||||||
LL | let dptr: *mut *const i32 = &ptr;
|
LL | let dptr: *mut *const i32 = &ptr;
|
||||||
| +++
|
| +++
|
||||||
|
LL | let dptr: *const *const i32 = &ptr;
|
||||||
|
| +++++
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user