review comments: use partition_map
This commit is contained in:
parent
e84cb65fe1
commit
c9f55ea689
@ -3537,6 +3537,7 @@ dependencies = [
|
||||
name = "rustc_ast_passes"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"itertools 0.8.0",
|
||||
"log",
|
||||
"rustc_ast",
|
||||
"rustc_ast_pretty",
|
||||
|
@ -9,6 +9,7 @@ name = "rustc_ast_passes"
|
||||
path = "lib.rs"
|
||||
|
||||
[dependencies]
|
||||
itertools = "0.8"
|
||||
log = "0.4"
|
||||
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
|
||||
rustc_attr = { path = "../librustc_attr" }
|
||||
|
@ -6,6 +6,7 @@
|
||||
// This pass is supposed to perform only simple checks not requiring name resolution
|
||||
// or type checking or some other kind of complex analysis.
|
||||
|
||||
use itertools::{Either, Itertools};
|
||||
use rustc_ast::ast::*;
|
||||
use rustc_ast::attr;
|
||||
use rustc_ast::expand::is_proc_macro_attr;
|
||||
@ -640,7 +641,7 @@ fn deny_items(&self, trait_items: &[P<AssocItem>], ident_span: Span) {
|
||||
}
|
||||
}
|
||||
|
||||
fn suggest_correct_generic_order(&self, data: &AngleBracketedArgs) -> String {
|
||||
fn correct_generic_order_suggestion(&self, data: &AngleBracketedArgs) -> String {
|
||||
// Lifetimes always come first.
|
||||
let lt_sugg = data.args.iter().filter_map(|arg| match arg {
|
||||
AngleBracketedArg::Arg(lt @ GenericArg::Lifetime(_)) => {
|
||||
@ -649,11 +650,12 @@ fn suggest_correct_generic_order(&self, data: &AngleBracketedArgs) -> String {
|
||||
_ => None,
|
||||
});
|
||||
let args_sugg = data.args.iter().filter_map(|a| match a {
|
||||
AngleBracketedArg::Arg(GenericArg::Lifetime(_)) => None,
|
||||
AngleBracketedArg::Arg(GenericArg::Lifetime(_)) | AngleBracketedArg::Constraint(_) => {
|
||||
None
|
||||
}
|
||||
AngleBracketedArg::Arg(arg) => Some(pprust::to_string(|s| s.print_generic_arg(arg))),
|
||||
AngleBracketedArg::Constraint(_) => None,
|
||||
});
|
||||
// Cosntraints always come last.
|
||||
// Constraints always come last.
|
||||
let constraint_sugg = data.args.iter().filter_map(|a| match a {
|
||||
AngleBracketedArg::Arg(_) => None,
|
||||
AngleBracketedArg::Constraint(c) => {
|
||||
@ -673,22 +675,11 @@ fn check_generic_args_before_constraints(&self, data: &AngleBracketedArgs) {
|
||||
return;
|
||||
}
|
||||
// Find all generic argument coming after the first constraint...
|
||||
let constraint_spans = data
|
||||
.args
|
||||
.iter()
|
||||
.filter_map(|arg| match arg {
|
||||
AngleBracketedArg::Constraint(c) => Some(c.span),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let arg_spans = data
|
||||
.args
|
||||
.iter()
|
||||
.filter_map(|arg| match arg {
|
||||
AngleBracketedArg::Arg(a) => Some(a.span()),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let (constraint_spans, arg_spans): (Vec<Span>, Vec<Span>) =
|
||||
data.args.iter().partition_map(|arg| match arg {
|
||||
AngleBracketedArg::Constraint(c) => Either::Left(c.span),
|
||||
AngleBracketedArg::Arg(a) => Either::Right(a.span()),
|
||||
});
|
||||
let args_len = arg_spans.len();
|
||||
let constraint_len = constraint_spans.len();
|
||||
// ...and then error:
|
||||
@ -706,7 +697,7 @@ fn check_generic_args_before_constraints(&self, data: &AngleBracketedArgs) {
|
||||
pluralize!(constraint_len),
|
||||
pluralize!(args_len)
|
||||
),
|
||||
self.suggest_correct_generic_order(&data),
|
||||
self.correct_generic_order_suggestion(&data),
|
||||
Applicability::MachineApplicable,
|
||||
)
|
||||
.emit();
|
||||
|
Loading…
Reference in New Issue
Block a user