Skip to content

Commit 0469e82

Browse files
committed
update description of the lint
1 parent edb95d0 commit 0469e82

File tree

1 file changed

+19
-7
lines changed
  • clippy_lints/src/methods

1 file changed

+19
-7
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4531,21 +4531,33 @@ declare_clippy_lint! {
45314531

45324532
declare_clippy_lint! {
45334533
/// ### What it does
4534-
/// Detects hardcoded localhost IP addresses using `Ipv4Addr::new(127, 0, 0, 1)`.
4534+
/// Checks for IP addresses that could be replaced with predefined constants such as
4535+
/// `Ipv4Addr::new(127, 0, 0, 1)` instead of using the appropriate constants.
45354536
///
45364537
/// ### Why is this bad?
4537-
/// Using a hardcoded IP address `(127.0.0.1)` is less clear and maintainable than using the
4538-
/// `Ipv4Addr::LOCALHOST` constant.
4538+
/// Using specific IP addresses like `127.0.0.1` or `::1` is less clear and less maintainable than using the
4539+
/// predefined constants `Ipv4Addr::LOCALHOST` or `Ipv6Addr::LOCALHOST`. These constants improve code
4540+
/// readability, make the intent explicit, and are less error-prone.
45394541
///
45404542
/// ### Example
45414543
/// ```no_run
4542-
/// use std::net::Ipv4Addr;
4543-
/// let addr = Ipv4Addr::new(127, 0, 0, 1);
4544+
/// use std::net::{Ipv4Addr, Ipv6Addr};
4545+
///
4546+
/// // IPv4 loopback
4547+
/// let addr_v4 = Ipv4Addr::new(127, 0, 0, 1);
4548+
///
4549+
/// // IPv6 loopback
4550+
/// let addr_v6 = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1);
45444551
/// ```
45454552
/// Use instead:
45464553
/// ```no_run
4547-
/// use std::net::Ipv4Addr;
4548-
/// let addr = Ipv4Addr::LOCALHOST;
4554+
/// use std::net::{Ipv4Addr, Ipv6Addr};
4555+
///
4556+
/// // IPv4 loopback
4557+
/// let addr_v4 = Ipv4Addr::LOCALHOST;
4558+
///
4559+
/// // IPv6 loopback
4560+
/// let addr_v6 = Ipv6Addr::LOCALHOST;
45494561
/// ```
45504562
#[clippy::version = "1.89.0"]
45514563
pub IP_CONSTANT,

0 commit comments

Comments
 (0)