Skip to content

Conversation

@SignalWalker
Copy link

@SignalWalker SignalWalker commented Oct 9, 2025

Partially addressing #15569, document items in clippy_utils::{consts, higher, macros, paths, res, source, str_utils, sugg, usage, visitors}. The specific items documented are listed in each commit description, along with notes.

This is my first time contributing to any official Rust internals/tools, so please let me know if I misunderstood anything. (I'm not really sure that "refers" is the right verb for the relationship between a Place and a HIR node, for example.)

As I understand it, this is considered purely an internal change, so:
changelog: none

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 9, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 9, 2025

r? @llogiq

rustbot has assigned @llogiq.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot

This comment has been minimized.

@SignalWalker SignalWalker changed the title Document pub items in clippy_utils::usage Document pub items in multiple clippy_utils modules Oct 12, 2025
}
}

/// Recursively consume [`Constant::Ref`] and return the innermost value.
Copy link
Author

@SignalWalker SignalWalker Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "Recursively" is technically the right word, but I couldn't think of anything better that would still be succinct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "removing all references to return the contained expression, e.g. &&T → T"?

}
}

/// Attempts to evaluate the given [pattern expression](PatExpr) as a [`Constant`].
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure this is accurate?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? I think it is.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly don't remember. I think it was because the name of the function doesn't seem to imply that it has anything to do with constants?

/// - If `val` is a [`ConstValue::Indirect`] and `ty` is an [`Array`](ty::Array) of
/// [`Float`](ty::Float), returns a [`Constant::Vec`]
///
/// Otherwise, returns `None`.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function actually as particular as described or am I missing something

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed the Bool and RawPtr cases.

pub body: &'hir Expr<'hir>,
/// Span of the loop header
pub span: Span,
/// The loop's label, if present
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pub let_expr: &'hir Expr<'hir>,
/// `while let` loop body
pub if_then: &'hir Expr<'hir>,
/// The loop's label, if present
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

matches!(name, sym::assert_macro | sym::debug_assert_macro)
}

/// A `panic!()` expression, which may contain arguments
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about this one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expn stands for expansion here, not expression. So it refers to the expansion of the panic! macro.

@@ -1,3 +1,5 @@
//! Utilities for node resolution.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this fully describes this module?


/// Conversion of a value into the range portion of a `Span`.
pub trait SpanRange: Sized {
/// Converts `self` into the range portion of a [`Span`].
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about this one

}
}

/// Extensions to [`SpanRange`].
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could probably be more descriptive

/// Checks whether the code snippet referred to by the given [`Span`] is present in the source code.
///
/// For example, if the span refers to an attribute inserted during macro expansion, this will
/// return false.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is accurate

}

/// Same as [`snippet_block_with_applicability()`], but first walks the span up to the given context
/// using [`snippet_with_context()`].
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be more descriptive?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please. I for one wouldn't understand what this does without following the link.

//! Utilities for analyzing and transforming strings.
/// Dealing with string indices can be hard, this struct ensures that both the
/// character and byte index are provided for correct indexing.
Copy link
Author

@SignalWalker SignalWalker Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this mention that char_index and byte_index aren't guaranteed to agree with each other?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I keep remembering it because it's bitten me a few times, but it's always good to have a reminder nevertheless.

}

/// Dealing with string comparison can be complicated, this struct ensures that both the
/// character and byte count are provided for correct indexing.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this mention that char_count and byte_count aren't guaranteed to agree with each other?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we already have a note at the beginning of the file, that shouldn't be necessary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to have it in the docs for the structs, since it'll show up in, for example, IDE hints.

}
}

/// Convert this suggestion into a [`String`] to be displayed to the user.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming that this is this function's purpose based on how it's used elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Convert/Format/, otherwise I agree.

@@ -1,3 +1,5 @@
//! Contains utility functions for checking expression usage.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about this one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more about variable usage, IIRC.

mutated_variables(expr, cx).is_none_or(|mutated| mutated.contains(&variable))
}

/// Checks whether it is possible that the given [Place] refers to the given local.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"refers to"?

.is_some()
}

/// Checks whether the given expression contains `return`, `break`, `continue`, or a macro call.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Describe why it checks for macro calls?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably because of panic! et al.

@rustbot

This comment has been minimized.

Copy link
Contributor

@llogiq llogiq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good. I left a few suggestions.

View changes since this review

}
}

/// Recursively consume [`Constant::Ref`] and return the innermost value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "removing all references to return the contained expression, e.g. &&T → T"?

}
}

/// Attempts to evaluate the given [pattern expression](PatExpr) as a [`Constant`].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? I think it is.

/// - If `val` is a [`ConstValue::Indirect`] and `ty` is an [`Array`](ty::Array) of
/// [`Float`](ty::Float), returns a [`Constant::Vec`]
///
/// Otherwise, returns `None`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed the Bool and RawPtr cases.

}

/// Dealing with string comparison can be complicated, this struct ensures that both the
/// character and byte count are provided for correct indexing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we already have a note at the beginning of the file, that shouldn't be necessary.

}
}

/// Convert this suggestion into a [`String`] to be displayed to the user.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Convert/Format/, otherwise I agree.

.is_some()
}

/// Checks whether the given expression contains `return`, `break`, `continue`, or a macro call.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably because of panic! et al.

@@ -1,3 +1,5 @@
//! Contains utility functions for checking expression usage.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more about variable usage, IIRC.

@llogiq
Copy link
Contributor

llogiq commented Nov 14, 2025

Ping? Are you still working on this?

@rustbot author

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Nov 14, 2025
@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label Nov 14, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 14, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

- `is_potentially_mutated()`
- `is_potentially_local_place()`
- `ParamBindingIdCollector`
- `BindingUsageFinder`
- `contains_return_break_continue_macro()`
- `local_used_in()`
- `local_used_after_expr()`
- `IfLetOrMatch::scrutinee()`
- `While.label`
- `WhileLet.label`
- module
- `MacroCall::is_local()`
- `PanicExpn`
- `PanicExpn::parse()`
- `HirNode::hir_id()`
- `HirNode::span()`
I'm not really sure how to document the `PathLookup` statics,
so I'm skipping those for now.
- module
- `HasHirId::hir_id()`
- `MaybeTypeckRes`
- `MaybeDef::opt_def_id()`
- `HasSession`
- `HasSession::sess()`
- `SpanRange::into_range()`
- `IntoSpan::into_span()`
- `IntoSpan::with_ctxt()`
- `SpanRangeExt`
  - May want to be more specific with this one.
- `SourceFileRange` and its fields
- `is_present_in_source()`
  - This one feels a bit clunky to me; might want to rephrase.
- `snippet_block_with_context()`
- module
- fields of `StrIndex`
- `StrIndex::new()`
- fields of `StrCount`
- `StrCount::new()`

`StrIndex` and `StrCount` don't seem to guarantee that their fields are
internally consistent; should this be documented?
- `Sugg::into_string()`

I'm not sure that this is correct, but it does seem to be how its used
elsewhere.
- module
- `Descend::{Yes, No}`
- `find_all_ret_expressions()`
- `for_each_unconsumed_temporary()`
  - this one was mostly just reformatting the non-doc comment that was
    already there
- `any_temporaries_need_ordered_drop()`
- `contains_break_or_continue()`
- `Constant::Adt`
- `Constant::partial_cmp()`
- `Constant::peel_refs()`
- `Constant::new_numeric_min()`
- `Constant::new_numeric_max()`
- `Constant::is_numeric_min()`
- `Constant::is_numeric_max()`
- `Constant::is_pos_infinity()`
- `Constant::is_neg_infinity()`
- `ConstantSource::is_local()`
- `FullInt` and its variants
- `ConstEvalCtxt::eval_pat_expr()`
- `mir_to_const()`
@rustbot
Copy link
Collaborator

rustbot commented Nov 18, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@SignalWalker
Copy link
Author

Ping? Are you still working on this?

@rustbot author

Woops, sorry, thanks for pinging me.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

SignalWalker and others added 2 commits November 18, 2025 14:13
Co-authored-by: llogiq <bogusandre@gmail.com>
- Clarify:
  - `consts::peel_refs()`
  - `consts::mir_to_const()`
  - `source::snippet_block_with_context()`
  - `str_utils::StrIndex`
  - `str_utils::StrCount`
  - `sugg::Sugg::into_string()`
  - `usage`
  - `usage::contains_return_break_continue_macro()`
- Fix:
  - `macros::PanicExpn`
@SignalWalker
Copy link
Author

Applied your suggestions; thanks!

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants