Skip to content

Commit

Permalink
Auto merge of #15169 - lowr:patch/impl-header-anon-lifetime, r=HKalbasi
Browse files Browse the repository at this point in the history
Use anonymous lifetime where possible

Because anonymous lifetimes are *super* cool.

More seriously, I believe anonymous lifetimes, especially those in impl headers, reduce cognitive load to a certain extent because they usually signify that they are not relevant in the signature of the methods within (or that we can apply the usual lifetime elision rules even if they are relevant).
  • Loading branch information
bors committed Jun 30, 2023
2 parents 7a3991a + 4e793e7 commit 76bcd99
Show file tree
Hide file tree
Showing 30 changed files with 60 additions and 60 deletions.
4 changes: 2 additions & 2 deletions crates/hir-def/src/body/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct Printer<'a> {
needs_indent: bool,
}

impl<'a> Write for Printer<'a> {
impl Write for Printer<'_> {
fn write_str(&mut self, s: &str) -> fmt::Result {
for line in s.split_inclusive('\n') {
if self.needs_indent {
Expand All @@ -125,7 +125,7 @@ impl<'a> Write for Printer<'a> {
}
}

impl<'a> Printer<'a> {
impl Printer<'_> {
fn indented(&mut self, f: impl FnOnce(&mut Self)) {
self.indent_level += 1;
wln!(self);
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-def/src/item_tree/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct Printer<'a> {
needs_indent: bool,
}

impl<'a> Printer<'a> {
impl Printer<'_> {
fn indented(&mut self, f: impl FnOnce(&mut Self)) {
self.indent_level += 1;
wln!(self);
Expand Down Expand Up @@ -572,7 +572,7 @@ impl<'a> Printer<'a> {
}
}

impl<'a> Write for Printer<'a> {
impl Write for Printer<'_> {
fn write_str(&mut self, s: &str) -> fmt::Result {
for line in s.split_inclusive('\n') {
if self.needs_indent {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ impl<L, R> InFile<Either<L, R>> {
}
}

impl<'a> InFile<&'a SyntaxNode> {
impl InFile<&SyntaxNode> {
pub fn ancestors_with_macros(
self,
db: &dyn db::ExpandDatabase,
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-expand/src/mod_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct Display<'a> {
path: &'a ModPath,
}

impl<'a> fmt::Display for Display<'a> {
impl fmt::Display for Display<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
display_fmt_path(self.db, self.path, f, true)
}
Expand All @@ -137,7 +137,7 @@ struct UnescapedDisplay<'a> {
path: &'a UnescapedModPath<'a>,
}

impl<'a> fmt::Display for UnescapedDisplay<'a> {
impl fmt::Display for UnescapedDisplay<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
display_fmt_path(self.db, self.path.0, f, false)
}
Expand Down
8 changes: 4 additions & 4 deletions crates/hir-expand/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum Repr {
TupleField(usize),
}

impl<'a> UnescapedName<'a> {
impl UnescapedName<'_> {
/// Returns the textual representation of this name as a [`SmolStr`]. Prefer using this over
/// [`ToString::to_string`] if possible as this conversion is cheaper in the general case.
pub fn to_smol_str(&self) -> SmolStr {
Expand All @@ -40,7 +40,7 @@ impl<'a> UnescapedName<'a> {
}
}

pub fn display(&'a self, db: &dyn crate::db::ExpandDatabase) -> impl fmt::Display + 'a {
pub fn display(&self, db: &dyn crate::db::ExpandDatabase) -> impl fmt::Display + '_ {
_ = db;
UnescapedDisplay { name: self }
}
Expand Down Expand Up @@ -162,7 +162,7 @@ struct Display<'a> {
name: &'a Name,
}

impl<'a> fmt::Display for Display<'a> {
impl fmt::Display for Display<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.name.0 {
Repr::Text(text) => fmt::Display::fmt(&text, f),
Expand All @@ -175,7 +175,7 @@ struct UnescapedDisplay<'a> {
name: &'a UnescapedName<'a>,
}

impl<'a> fmt::Display for UnescapedDisplay<'a> {
impl fmt::Display for UnescapedDisplay<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.name.0 .0 {
Repr::Text(text) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/chalk_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Inte
pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>;
pub(crate) type Variances = chalk_ir::Variances<Interner>;

impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
fn associated_ty_data(&self, id: AssocTypeId) -> Arc<AssociatedTyDatum> {
self.db.associated_ty_data(id)
}
Expand Down
6 changes: 3 additions & 3 deletions crates/hir-ty/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub trait HirDisplay {
}
}

impl<'a> HirFormatter<'a> {
impl HirFormatter<'_> {
pub fn write_joined<T: HirDisplay>(
&mut self,
iter: impl IntoIterator<Item = T>,
Expand Down Expand Up @@ -342,7 +342,7 @@ impl<T: HirDisplay> HirDisplayWrapper<'_, T> {
}
}

impl<'a, T> fmt::Display for HirDisplayWrapper<'a, T>
impl<T> fmt::Display for HirDisplayWrapper<'_, T>
where
T: HirDisplay,
{
Expand All @@ -360,7 +360,7 @@ where

const TYPE_HINT_TRUNCATION: &str = "…";

impl<T: HirDisplay> HirDisplay for &'_ T {
impl<T: HirDisplay> HirDisplay for &T {
fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
HirDisplay::hir_fmt(*self, f)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-ty/src/infer/coerce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub(crate) fn coerce(
Ok((adjustments, table.resolve_with_fallback(ty, &fallback)))
}

impl<'a> InferenceContext<'a> {
impl InferenceContext<'_> {
/// Unify two types, but may coerce the first one to the second one
/// using "implicit coercion rules" if needed.
pub(super) fn coerce(
Expand All @@ -239,7 +239,7 @@ impl<'a> InferenceContext<'a> {
}
}

impl<'a> InferenceTable<'a> {
impl InferenceTable<'_> {
/// Unify two types, but may coerce the first one to the second one
/// using "implicit coercion rules" if needed.
pub(crate) fn coerce(
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/infer/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use super::{
InferenceContext, InferenceDiagnostic, TypeMismatch,
};

impl<'a> InferenceContext<'a> {
impl InferenceContext<'_> {
pub(crate) fn infer_expr(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty {
let ty = self.infer_expr_inner(tgt_expr, expected);
if let Some(expected_ty) = expected.only_has_type(&mut self.table) {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/infer/mutability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{lower::lower_to_chalk_mutability, Adjust, Adjustment, AutoBorrow, Ov

use super::InferenceContext;

impl<'a> InferenceContext<'a> {
impl InferenceContext<'_> {
pub(crate) fn infer_mut_body(&mut self) {
self.infer_mut_expr(self.body.body_expr, Mutability::Not);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/infer/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl PatLike for PatId {
}
}

impl<'a> InferenceContext<'a> {
impl InferenceContext<'_> {
/// Infers type for tuple struct pattern or its corresponding assignee expression.
///
/// Ellipses found in the original pattern or expression must be filtered out.
Expand Down
8 changes: 4 additions & 4 deletions crates/hir-ty/src/infer/unify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
TraitEnvironment, Ty, TyBuilder, TyExt, TyKind, VariableKind,
};

impl<'a> InferenceContext<'a> {
impl InferenceContext<'_> {
pub(super) fn canonicalize<T: TypeFoldable<Interner> + HasInterner<Interner = Interner>>(
&mut self,
t: T,
Expand Down Expand Up @@ -547,7 +547,7 @@ impl<'a> InferenceTable<'a> {
table: &'a mut InferenceTable<'b>,
highest_known_var: InferenceVar,
}
impl<'a, 'b> TypeFolder<Interner> for VarFudger<'a, 'b> {
impl TypeFolder<Interner> for VarFudger<'_, '_> {
fn as_dyn(&mut self) -> &mut dyn TypeFolder<Interner, Error = Self::Error> {
self
}
Expand Down Expand Up @@ -798,7 +798,7 @@ impl<'a> InferenceTable<'a> {
}
}

impl<'a> fmt::Debug for InferenceTable<'a> {
impl fmt::Debug for InferenceTable<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("InferenceTable").field("num_vars", &self.type_variable_table.len()).finish()
}
Expand Down Expand Up @@ -826,7 +826,7 @@ mod resolve {
pub(super) var_stack: &'a mut Vec<InferenceVar>,
pub(super) fallback: F,
}
impl<'a, 'b, F> TypeFolder<Interner> for Resolver<'a, 'b, F>
impl<F> TypeFolder<Interner> for Resolver<'_, '_, F>
where
F: Fn(InferenceVar, VariableKind, GenericArg, DebruijnIndex) -> GenericArg,
{
Expand Down
6 changes: 3 additions & 3 deletions crates/hir-ty/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,10 +959,10 @@ impl<'a> TyLoweringContext<'a> {
}

pub(crate) fn lower_where_predicate(
&'a self,
where_predicate: &'a WherePredicate,
&self,
where_predicate: &WherePredicate,
ignore_bindings: bool,
) -> impl Iterator<Item = QuantifiedWhereClause> + 'a {
) -> impl Iterator<Item = QuantifiedWhereClause> {
match where_predicate {
WherePredicate::ForLifetime { target, bound, .. }
| WherePredicate::TypeBound { target, bound } => {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ fn solve(

struct LoggingRustIrDatabaseLoggingOnDrop<'a>(LoggingRustIrDatabase<Interner, ChalkContext<'a>>);

impl<'a> Drop for LoggingRustIrDatabaseLoggingOnDrop<'a> {
impl Drop for LoggingRustIrDatabaseLoggingOnDrop<'_> {
fn drop(&mut self) {
eprintln!("chalk program:\n{}", self.0);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-ty/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct SuperTraits<'a> {
seen: FxHashSet<ChalkTraitId>,
}

impl<'a> SuperTraits<'a> {
impl SuperTraits<'_> {
fn elaborate(&mut self, trait_ref: &TraitRef) {
direct_super_trait_refs(self.db, trait_ref, |trait_ref| {
if !self.seen.contains(&trait_ref.trait_id) {
Expand All @@ -99,7 +99,7 @@ impl<'a> SuperTraits<'a> {
}
}

impl<'a> Iterator for SuperTraits<'a> {
impl Iterator for SuperTraits<'_> {
type Item = TraitRef;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir/src/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ pub struct SemanticsScope<'a> {
resolver: Resolver,
}

impl<'a> SemanticsScope<'a> {
impl SemanticsScope<'_> {
pub fn module(&self) -> Module {
Module { id: self.resolver.module() }
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-assists/src/handlers/pull_assignment_up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct AssignmentsCollector<'a> {
assignments: Vec<(ast::BinExpr, ast::Expr)>,
}

impl<'a> AssignmentsCollector<'a> {
impl AssignmentsCollector<'_> {
fn collect_match(&mut self, match_expr: &ast::MatchExpr) -> Option<()> {
for arm in match_expr.match_arm_list()?.arms() {
match arm.expr()? {
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-db/src/path_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ fn postorder(item: &SyntaxNode) -> impl Iterator<Item = SyntaxNode> {
})
}

impl<'a> Ctx<'a> {
impl Ctx<'_> {
fn apply(&self, item: &SyntaxNode) {
// `transform_path` may update a node's parent and that would break the
// tree traversal. Thus all paths in the tree are collected into a vec
Expand Down
8 changes: 4 additions & 4 deletions crates/ide-db/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,21 +338,21 @@ pub struct FindUsages<'a> {
search_self_mod: bool,
}

impl<'a> FindUsages<'a> {
impl FindUsages<'_> {
/// Enable searching for `Self` when the definition is a type or `self` for modules.
pub fn include_self_refs(mut self) -> FindUsages<'a> {
pub fn include_self_refs(mut self) -> Self {
self.include_self_kw_refs = def_to_ty(self.sema, &self.def);
self.search_self_mod = true;
self
}

/// Limit the search to a given [`SearchScope`].
pub fn in_scope(self, scope: SearchScope) -> FindUsages<'a> {
pub fn in_scope(self, scope: SearchScope) -> Self {
self.set_scope(Some(scope))
}

/// Limit the search to a given [`SearchScope`].
pub fn set_scope(mut self, scope: Option<SearchScope>) -> FindUsages<'a> {
pub fn set_scope(mut self, scope: Option<SearchScope>) -> Self {
assert!(self.scope.is_none());
self.scope = scope;
self
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ struct DiagnosticsContext<'a> {
resolve: &'a AssistResolveStrategy,
}

impl<'a> DiagnosticsContext<'a> {
impl DiagnosticsContext<'_> {
fn resolve_precise_location(
&self,
node: &InFile<SyntaxNodePtr>,
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-ssr/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) struct UsageCache {
usages: Vec<(Definition, UsageSearchResult)>,
}

impl<'db> MatchFinder<'db> {
impl MatchFinder<'_> {
/// Adds all matches for `rule` to `matches_out`. Matches may overlap in ways that make
/// replacement impossible, so further processing is required in order to properly nest matches
/// and remove overlapping matches. This is done in the `nesting` module.
Expand Down
2 changes: 1 addition & 1 deletion crates/mbe/src/expander/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ impl<'a> Iterator for OpDelimitedIter<'a> {
}
}

impl<'a> TtIter<'a> {
impl TtIter<'_> {
fn expect_separator(&mut self, separator: &Separator) -> bool {
let mut fork = self.clone();
let ok = match separator {
Expand Down
12 changes: 6 additions & 6 deletions crates/mbe/src/syntax_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,25 +509,25 @@ trait TokenConverter: Sized {
fn id_alloc(&mut self) -> &mut TokenIdAlloc;
}

impl<'a> SrcToken<RawConverter<'a>> for usize {
fn kind(&self, ctx: &RawConverter<'a>) -> SyntaxKind {
impl SrcToken<RawConverter<'_>> for usize {
fn kind(&self, ctx: &RawConverter<'_>) -> SyntaxKind {
ctx.lexed.kind(*self)
}

fn to_char(&self, ctx: &RawConverter<'a>) -> Option<char> {
fn to_char(&self, ctx: &RawConverter<'_>) -> Option<char> {
ctx.lexed.text(*self).chars().next()
}

fn to_text(&self, ctx: &RawConverter<'_>) -> SmolStr {
ctx.lexed.text(*self).into()
}

fn synthetic_id(&self, _ctx: &RawConverter<'a>) -> Option<SyntheticTokenId> {
fn synthetic_id(&self, _ctx: &RawConverter<'_>) -> Option<SyntheticTokenId> {
None
}
}

impl<'a> TokenConverter for RawConverter<'a> {
impl TokenConverter for RawConverter<'_> {
type Token = usize;

fn convert_doc_comment(&self, &token: &usize, span: tt::TokenId) -> Option<Vec<tt::TokenTree>> {
Expand Down Expand Up @@ -800,7 +800,7 @@ fn delim_to_str(d: tt::DelimiterKind, closing: bool) -> Option<&'static str> {
Some(&texts[idx..texts.len() - (1 - idx)])
}

impl<'a> TtTreeSink<'a> {
impl TtTreeSink<'_> {
/// Parses a float literal as if it was a one to two name ref nodes with a dot inbetween.
/// This occurs when a float literal is used as a field access.
fn float_split(&mut self, has_pseudo_dot: bool) {
Expand Down
2 changes: 1 addition & 1 deletion crates/mbe/src/tt_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,4 @@ impl<'a> Iterator for TtIter<'a> {
}
}

impl<'a> std::iter::ExactSizeIterator for TtIter<'a> {}
impl std::iter::ExactSizeIterator for TtIter<'_> {}
2 changes: 1 addition & 1 deletion crates/parser/src/shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub enum StrStep<'a> {
Error { msg: &'a str, pos: usize },
}

impl<'a> LexedStr<'a> {
impl LexedStr<'_> {
pub fn to_input(&self) -> crate::Input {
let mut res = crate::Input::default();
let mut was_joint = false;
Expand Down

0 comments on commit 76bcd99

Please sign in to comment.