Auto merge of #15169 - lowr:patch/impl-header-anon-lifetime, r=HKalbasi

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).
This commit is contained in:
bors
2023-06-30 16:57:20 +00:00
30 changed files with 60 additions and 60 deletions
+2 -2
View File
@@ -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 {
@@ -125,7 +125,7 @@ fn write_str(&mut self, s: &str) -> fmt::Result {
}
}
impl<'a> Printer<'a> {
impl Printer<'_> {
fn indented(&mut self, f: impl FnOnce(&mut Self)) {
self.indent_level += 1;
wln!(self);
+2 -2
View File
@@ -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);
@@ -572,7 +572,7 @@ fn print_where_clause(&mut self, params: &GenericParams) -> 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 {
+1 -1
View File
@@ -850,7 +850,7 @@ pub fn transpose(self) -> Either<InFile<L>, InFile<R>> {
}
}
impl<'a> InFile<&'a SyntaxNode> {
impl InFile<&SyntaxNode> {
pub fn ancestors_with_macros(
self,
db: &dyn db::ExpandDatabase,
+2 -2
View File
@@ -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)
}
@@ -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)
}
+4 -4
View File
@@ -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 {
@@ -40,7 +40,7 @@ pub fn to_smol_str(&self) -> SmolStr {
}
}
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 }
}
@@ -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),
@@ -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) => {
+1 -1
View File
@@ -46,7 +46,7 @@
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)
}
+3 -3
View File
@@ -192,7 +192,7 @@ fn display_test<'a>(&'a self, db: &'a dyn HirDatabase) -> HirDisplayWrapper<'a,
}
}
impl<'a> HirFormatter<'a> {
impl HirFormatter<'_> {
pub fn write_joined<T: HirDisplay>(
&mut self,
iter: impl IntoIterator<Item = T>,
@@ -342,7 +342,7 @@ pub fn with_closure_style(mut self, c: ClosureStyle) -> Self {
}
}
impl<'a, T> fmt::Display for HirDisplayWrapper<'a, T>
impl<T> fmt::Display for HirDisplayWrapper<'_, T>
where
T: HirDisplay,
{
@@ -360,7 +360,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
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)
}
+2 -2
View File
@@ -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(
@@ -239,7 +239,7 @@ pub(super) fn coerce(
}
}
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(
+1 -1
View File
@@ -50,7 +50,7 @@
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) {
+1 -1
View File
@@ -12,7 +12,7 @@
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);
}
+1 -1
View File
@@ -56,7 +56,7 @@ fn infer(
}
}
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.
+4 -4
View File
@@ -22,7 +22,7 @@
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,
@@ -547,7 +547,7 @@ struct VarFudger<'a, 'b> {
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
}
@@ -798,7 +798,7 @@ pub(super) fn insert_const_vars_shallow(&mut self, c: Const) -> Const {
}
}
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()
}
@@ -826,7 +826,7 @@ pub(super) struct Resolver<
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,
{
+3 -3
View File
@@ -959,10 +959,10 @@ fn trait_ref_substs_from_path(
}
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 } => {
+1 -1
View File
@@ -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);
}
+2 -2
View File
@@ -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) {
@@ -99,7 +99,7 @@ fn elaborate(&mut self, trait_ref: &TraitRef) {
}
}
impl<'a> Iterator for SuperTraits<'a> {
impl Iterator for SuperTraits<'_> {
type Item = TraitRef;
fn next(&mut self) -> Option<Self::Item> {
+1 -1
View File
@@ -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() }
}
@@ -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()? {
+1 -1
View File
@@ -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
+4 -4
View File
@@ -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
+1 -1
View File
@@ -194,7 +194,7 @@ struct DiagnosticsContext<'a> {
resolve: &'a AssistResolveStrategy,
}
impl<'a> DiagnosticsContext<'a> {
impl DiagnosticsContext<'_> {
fn resolve_precise_location(
&self,
node: &InFile<SyntaxNodePtr>,
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -884,7 +884,7 @@ fn size_hint(&self) -> (usize, Option<usize>) {
}
}
impl<'a> TtIter<'a> {
impl TtIter<'_> {
fn expect_separator(&mut self, separator: &Separator) -> bool {
let mut fork = self.clone();
let ok = match separator {
+6 -6
View File
@@ -509,12 +509,12 @@ fn convert_doc_comment(
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()
}
@@ -522,12 +522,12 @@ 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>> {
@@ -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) {
+1 -1
View File
@@ -197,4 +197,4 @@ fn size_hint(&self) -> (usize, Option<usize>) {
}
}
impl<'a> std::iter::ExactSizeIterator for TtIter<'a> {}
impl std::iter::ExactSizeIterator for TtIter<'_> {}
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -72,7 +72,7 @@ struct NodeIter<'a, T> {
next: Option<Idx<T>>,
}
impl<'a, T> Iterator for NodeIter<'a, T> {
impl<T> Iterator for NodeIter<'_, T> {
type Item = Idx<T>;
fn next(&mut self) -> Option<Idx<T>> {
+2 -2
View File
@@ -32,10 +32,10 @@ pub(crate) struct LoggerConfig {
struct MakeWriterStderr;
impl<'a> MakeWriter<'a> for MakeWriterStderr {
impl MakeWriter<'_> for MakeWriterStderr {
type Writer = Stderr;
fn make_writer(&'a self) -> Self::Writer {
fn make_writer(&self) -> Self::Writer {
io::stderr()
}
}
+2 -2
View File
@@ -32,7 +32,7 @@ pub(crate) struct RequestDispatcher<'a> {
pub(crate) global_state: &'a mut GlobalState,
}
impl<'a> RequestDispatcher<'a> {
impl RequestDispatcher<'_> {
/// Dispatches the request onto the current thread, given full access to
/// mutable global state. Unlike all other methods here, this one isn't
/// guarded by `catch_unwind`, so, please, don't make bugs :-)
@@ -306,7 +306,7 @@ pub(crate) struct NotificationDispatcher<'a> {
pub(crate) global_state: &'a mut GlobalState,
}
impl<'a> NotificationDispatcher<'a> {
impl NotificationDispatcher<'_> {
pub(crate) fn on_sync_mut<N>(
&mut self,
f: fn(&mut GlobalState, N::Params) -> anyhow::Result<()>,
@@ -25,7 +25,7 @@ pub(crate) struct Project<'a> {
config: serde_json::Value,
}
impl<'a> Project<'a> {
impl Project<'_> {
pub(crate) fn with_fixture(fixture: &str) -> Project<'_> {
Project {
fixture,
@@ -48,17 +48,17 @@ pub(crate) fn with_fixture(fixture: &str) -> Project<'_> {
}
}
pub(crate) fn tmp_dir(mut self, tmp_dir: TestDir) -> Project<'a> {
pub(crate) fn tmp_dir(mut self, tmp_dir: TestDir) -> Self {
self.tmp_dir = Some(tmp_dir);
self
}
pub(crate) fn root(mut self, path: &str) -> Project<'a> {
pub(crate) fn root(mut self, path: &str) -> Self {
self.roots.push(path.into());
self
}
pub(crate) fn with_config(mut self, config: serde_json::Value) -> Project<'a> {
pub(crate) fn with_config(mut self, config: serde_json::Value) -> Self {
fn merge(dst: &mut serde_json::Value, src: serde_json::Value) {
match (dst, src) {
(Value::Object(dst), Value::Object(src)) => {
+3 -3
View File
@@ -134,7 +134,7 @@ pub enum TokenTreeRef<'a, Span> {
Leaf(&'a Leaf<Span>, &'a TokenTree<Span>),
}
impl<'a, Span: Clone> TokenTreeRef<'a, Span> {
impl<Span: Clone> TokenTreeRef<'_, Span> {
pub fn cloned(&self) -> TokenTree<Span> {
match self {
TokenTreeRef::Subtree(subtree, tt) => match tt {
@@ -153,13 +153,13 @@ pub struct Cursor<'a, Span> {
ptr: EntryPtr,
}
impl<'a, Span> PartialEq for Cursor<'a, Span> {
impl<Span> PartialEq for Cursor<'_, Span> {
fn eq(&self, other: &Cursor<'_, Span>) -> bool {
self.ptr == other.ptr && std::ptr::eq(self.buffer, other.buffer)
}
}
impl<'a, Span> Eq for Cursor<'a, Span> {}
impl<Span> Eq for Cursor<'_, Span> {}
impl<'a, Span> Cursor<'a, Span> {
/// Check whether it is eof