Skip to content

Commit aff676c

Browse files
author
Ype Kingma
committed
More code docs, remove unused generics_span
1 parent 96e2592 commit aff676c

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

clippy_lints/src/lifetimes_bound_nested_ref.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use std::collections::btree_map::Entry;
2323
use std::collections::BTreeMap;
2424

25-
use clippy_utils::diagnostics::{span_lint, span_lint_and_note, span_lint_and_then};
25+
use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_then};
2626
use rustc_ast::visit::FnKind;
2727
use rustc_ast::{
2828
AngleBracketedArg, FnRetTy, GenericArg, GenericArgs, GenericBound, GenericParamKind, Generics, Item, ItemKind,
@@ -210,11 +210,13 @@ impl BoundLftPair {
210210
}
211211
}
212212

213-
fn to_bound_declaration(&self) -> String {
213+
/// A declarion for the lifetimes bound
214+
fn to_declaration(&self) -> String {
214215
format!("{}: {}", self.long_lft_sym, self.outlived_lft_sym)
215216
}
216217
}
217218

219+
/// From a [Generics] provide an [FxHashMap] of the declared lifetime symbols to their spans.
218220
fn get_declared_lifetimes_spans(generics: &Generics) -> FxHashMap<Symbol, Span> {
219221
generics
220222
.params
@@ -229,6 +231,8 @@ fn get_declared_lifetimes_spans(generics: &Generics) -> FxHashMap<Symbol, Span>
229231
.collect()
230232
}
231233

234+
/// From a [Generics] provide a [BTreeMap] of the declared lifetime bounds to the spans of the
235+
/// declarations.
232236
fn get_declared_bounds_spans(generics: &Generics) -> BTreeMap<BoundLftPair, Span> {
233237
let mut declared_bounds = BTreeMap::new();
234238
generics.params.iter().for_each(|gp| {
@@ -261,7 +265,6 @@ fn get_declared_bounds_spans(generics: &Generics) -> BTreeMap<BoundLftPair, Span
261265
#[derive(Debug)]
262266
struct ImpliedBoundsLinter {
263267
declared_lifetimes_spans: FxHashMap<Symbol, Span>,
264-
generics_span: Span,
265268
declared_bounds_spans: BTreeMap<BoundLftPair, Span>,
266269
implied_bounds_spans: BTreeMap<BoundLftPair, (Span, Span)>,
267270
}
@@ -271,7 +274,6 @@ impl ImpliedBoundsLinter {
271274
ImpliedBoundsLinter {
272275
declared_lifetimes_spans,
273276
declared_bounds_spans: get_declared_bounds_spans(generics),
274-
generics_span: generics.span,
275277
implied_bounds_spans: BTreeMap::new(),
276278
}
277279
}
@@ -457,8 +459,8 @@ impl ImpliedBoundsLinter {
457459

458460
for (implied_bound, (outlived_lft_span, long_lft_span)) in &self.implied_bounds_spans {
459461
if !self.declared_bounds_spans.contains_key(implied_bound) {
460-
let declaration = implied_bound.to_bound_declaration();
461-
let msg_missing = format!("missing lifetimes bound declaration: {declaration}");
462+
let impl_bound_decl = implied_bound.to_declaration();
463+
let msg_missing = format!("missing lifetimes bound declaration: {impl_bound_decl}");
462464
if let Some(long_lft_decl_span) = self.declared_lifetimes_spans.get(&implied_bound.long_lft_sym) {
463465
let nested_ref_span = spans_merge(*outlived_lft_span, *long_lft_span);
464466
span_lint_and_fix_sugg_and_note_cause(
@@ -467,13 +469,10 @@ impl ImpliedBoundsLinter {
467469
*long_lft_decl_span,
468470
&msg_missing,
469471
"try",
470-
declaration,
472+
impl_bound_decl,
471473
nested_ref_span,
472474
bound_implied_here_note,
473475
);
474-
} else {
475-
// unreachable!(); collected only bounds on declared lifetimes
476-
span_lint(cx, EXPLICIT_LIFETIMES_BOUND, self.generics_span, msg_missing);
477476
}
478477
}
479478
}
@@ -488,7 +487,7 @@ impl ImpliedBoundsLinter {
488487
format!(
489488
// only remove these lifetime bounds after the compiler is fixed
490489
"declared lifetimes bound: {} is redundant, but do not remove it",
491-
declared_bound.to_bound_declaration(),
490+
declared_bound.to_declaration(),
492491
),
493492
Some(nested_ref_span),
494493
bound_implied_here_note,

0 commit comments

Comments
 (0)