Skip to content

Commit becd479

Browse files
committed
review comment: simplify code by using slice pat
1 parent b9585fd commit becd479

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/librustc_resolve/late/diagnostics.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -1378,17 +1378,18 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
13781378
}
13791379
};
13801380

1381-
match (lifetime_names.len(), lifetime_names.iter().next(), snippet.as_deref()) {
1382-
(1, Some(name), Some("&")) => {
1381+
let lifetime_names: Vec<_> = lifetime_names.into_iter().collect();
1382+
match (&lifetime_names[..], snippet.as_deref()) {
1383+
([name], Some("&")) => {
13831384
suggest_existing(err, &name.as_str()[..], &|name| format!("&{} ", name));
13841385
}
1385-
(1, Some(name), Some("'_")) => {
1386+
([name], Some("'_")) => {
13861387
suggest_existing(err, &name.as_str()[..], &|n| n.to_string());
13871388
}
1388-
(1, Some(name), Some("")) => {
1389+
([name], Some("")) => {
13891390
suggest_existing(err, &name.as_str()[..], &|n| format!("{}, ", n).repeat(count));
13901391
}
1391-
(1, Some(name), Some(snippet)) if !snippet.ends_with('>') => {
1392+
([name], Some(snippet)) if !snippet.ends_with('>') => {
13921393
let f = |name: &str| {
13931394
format!(
13941395
"{}<{}>",
@@ -1401,13 +1402,13 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
14011402
};
14021403
suggest_existing(err, &name.as_str()[..], &f);
14031404
}
1404-
(0, _, Some("&")) if count == 1 => {
1405+
([], Some("&")) if count == 1 => {
14051406
suggest_new(err, "&'a ");
14061407
}
1407-
(0, _, Some("'_")) if count == 1 => {
1408+
([], Some("'_")) if count == 1 => {
14081409
suggest_new(err, "'a");
14091410
}
1410-
(0, _, Some(snippet)) if !snippet.ends_with('>') && count == 1 => {
1411+
([], Some(snippet)) if !snippet.ends_with('>') && count == 1 => {
14111412
if snippet == "" {
14121413
// This happens when we have `type Bar<'a> = Foo<T>` where we point at the space
14131414
// before `T`. We will suggest `type Bar<'a> = Foo<'a, T>`.
@@ -1416,7 +1417,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
14161417
suggest_new(err, &format!("{}<'a>", snippet));
14171418
}
14181419
}
1419-
(n, ..) if n > 1 => {
1420+
(lts, ..) if lts.len() > 1 => {
14201421
err.span_note(lifetime_spans, "these named lifetimes are available to use");
14211422
if Some("") == snippet.as_deref() {
14221423
// This happens when we have `Foo<T>` where we point at the space before `T`,

0 commit comments

Comments
 (0)