diff --git a/book/src/lint_configuration.md b/book/src/lint_configuration.md index f323d7040d26..b99ae21eaace 100644 --- a/book/src/lint_configuration.md +++ b/book/src/lint_configuration.md @@ -640,7 +640,7 @@ default configuration of Clippy. By default, any configuration will replace the * `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`. * `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list. -**Default Value:** `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "MHz", "GHz", "THz", "AccessKit", "CoAP", "CoreFoundation", "CoreGraphics", "CoreText", "DevOps", "Direct2D", "Direct3D", "DirectWrite", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "InfiniBand", "RoCE", "ClojureScript", "CoffeeScript", "JavaScript", "PostScript", "PureScript", "TypeScript", "PowerPC", "PowerShell", "WebAssembly", "NaN", "NaNs", "OAuth", "GraphQL", "SQLite", "MySQL", "PostgreSQL", "MariaDB", "MongoDB", "OCaml", "OpenAL", "OpenDNS", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenTelemetry", "OpenType", "WebAuthn", "WebGL", "WebGL2", "WebGPU", "WebRTC", "WebSocket", "WebTransport", "WebP", "OpenExr", "YCbCr", "sRGB", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "NetBSD", "OpenBSD", "NixOS", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]` +**Default Value:** `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "MHz", "GHz", "THz", "AccessKit", "CoAP", "CoreFoundation", "CoreGraphics", "CoreText", "DevOps", "Direct2D", "Direct3D", "DirectWrite", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "InfiniBand", "RoCE", "ClojureScript", "CoffeeScript", "JavaScript", "PostScript", "PureScript", "TypeScript", "PowerPC", "PowerShell", "WebAssembly", "NaN", "NaNs", "OAuth", "GraphQL", "SQLite", "MySQL", "PostgreSQL", "MariaDB", "MongoDB", "OCaml", "OpenAL", "OpenDNS", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenTelemetry", "OpenType", "WebAuthn", "WebGL", "WebGL2", "WebGPU", "WebRTC", "WebSocket", "WebTransport", "WebP", "OpenExr", "YCbCr", "sRGB", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "NetBSD", "OpenBSD", "NixOS", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase", "x86_64", "CommonMark", "IntelliJ"]` --- **Affected lints:** diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index d547eb294f6a..ab809997abc6 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -45,6 +45,8 @@ static DEFAULT_DOC_VALID_IDENTS: &[&str] = &[ "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase", + "x86_64", + "CommonMark", "IntelliJ", ]; static DEFAULT_DISALLOWED_NAMES: &[&str] = &["foo", "baz", "quux"]; static DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS: &[&str] = &["i", "j", "x", "y", "z", "w", "n"]; diff --git a/clippy_lints/src/arbitrary_source_item_ordering.rs b/clippy_lints/src/arbitrary_source_item_ordering.rs index c85ffa98936c..f6388a43a8c8 100644 --- a/clippy_lints/src/arbitrary_source_item_ordering.rs +++ b/clippy_lints/src/arbitrary_source_item_ordering.rs @@ -58,13 +58,13 @@ declare_clippy_lint! { /// /// | Group | Item Kinds | /// |--------------------|----------------------| - /// | `modules` | "mod", "foreign_mod" | - /// | `use` | "use" | - /// | `macros` | "macro" | - /// | `global_asm` | "global_asm" | - /// | `UPPER_SNAKE_CASE` | "static", "const" | - /// | `PascalCase` | "ty_alias", "opaque_ty", "enum", "struct", "union", "trait", "trait_alias", "impl" | - /// | `lower_snake_case` | "fn" | + /// | `modules` | `mod`, `foreign_mod` | + /// | `use` | `use` | + /// | `macros` | `macro` | + /// | `global_asm` | `global_asm` | + /// | `UPPER_SNAKE_CASE` | `static`, `const` | + /// | `PascalCase` | `ty_alias`, `opaque_ty`, `enum`, `struct`, `union`, `trait`, `trait_alias`, `impl` | + /// | `lower_snake_case` | `fn` | /// /// The groups' names are arbitrary and can be changed to suit the /// conventions that should be enforced for a specific project. diff --git a/clippy_lints/src/attrs/mod.rs b/clippy_lints/src/attrs/mod.rs index 23d5adfb201a..071b3b1df078 100644 --- a/clippy_lints/src/attrs/mod.rs +++ b/clippy_lints/src/attrs/mod.rs @@ -83,7 +83,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Checks for `warn`/`deny`/`forbid` attributes targeting the whole clippy::restriction category. + /// Checks for `warn`/`deny`/`forbid` attributes targeting the whole `clippy::restriction` category. /// /// ### Why is this bad? /// Restriction lints sometimes are in contrast with other lints or even go against idiomatic rust. @@ -110,12 +110,12 @@ declare_clippy_lint! { /// with `#[rustfmt::skip]`. /// /// ### Why is this bad? - /// Since tool_attributes ([rust-lang/rust#44690](https://github.com/rust-lang/rust/issues/44690)) + /// Since `tool_attributes` ([rust-lang/rust#44690](https://github.com/rust-lang/rust/issues/44690)) /// are stable now, they should be used instead of the old `cfg_attr(rustfmt)` attributes. /// /// ### Known problems /// This lint doesn't detect crate level inner attributes, because they get - /// processed before the PreExpansionPass lints get executed. See + /// processed before the pre-expansion pass lints get executed. See /// [#3123](https://github.com/rust-lang/rust-clippy/pull/3123#issuecomment-422321765) /// /// ### Example @@ -432,22 +432,22 @@ declare_clippy_lint! { /// /// This lint permits lint attributes for lints emitted on the items themself. /// For `use` items these lints are: - /// * ambiguous_glob_reexports - /// * dead_code - /// * deprecated - /// * hidden_glob_reexports - /// * unreachable_pub - /// * unused - /// * unused_braces - /// * unused_import_braces - /// * clippy::disallowed_types - /// * clippy::enum_glob_use - /// * clippy::macro_use_imports - /// * clippy::module_name_repetitions - /// * clippy::redundant_pub_crate - /// * clippy::single_component_path_imports - /// * clippy::unsafe_removed_from_name - /// * clippy::wildcard_imports + /// * `ambiguous_glob_reexports` + /// * `dead_code` + /// * `deprecated` + /// * `hidden_glob_reexports` + /// * `unreachable_pub` + /// * `unused` + /// * `unused_braces` + /// * `unused_import_braces` + /// * `clippy::disallowed_types` + /// * `clippy::enum_glob_use` + /// * `clippy::macro_use_imports` + /// * `clippy::module_name_repetitions` + /// * `clippy::redundant_pub_crate` + /// * `clippy::single_component_path_imports` + /// * `clippy::unsafe_removed_from_name` + /// * `clippy::wildcard_imports` /// /// For `extern crate` items these lints are: /// * `unused_imports` on items with `#[macro_use]` diff --git a/clippy_lints/src/bool_to_int_with_if.rs b/clippy_lints/src/bool_to_int_with_if.rs index ecddefe25a26..c1ce1211ddfc 100644 --- a/clippy_lints/src/bool_to_int_with_if.rs +++ b/clippy_lints/src/bool_to_int_with_if.rs @@ -15,7 +15,7 @@ declare_clippy_lint! { /// Coercion or `from()` is another way to convert bool to a number. /// Both methods are guaranteed to return 1 for true, and 0 for false. /// - /// See https://doc.rust-lang.org/std/primitive.bool.html#impl-From%3Cbool%3E + /// See /// /// ### Example /// ```no_run diff --git a/clippy_lints/src/crate_in_macro_def.rs b/clippy_lints/src/crate_in_macro_def.rs index ddd666477612..0a9bb452a0a7 100644 --- a/clippy_lints/src/crate_in_macro_def.rs +++ b/clippy_lints/src/crate_in_macro_def.rs @@ -14,7 +14,7 @@ declare_clippy_lint! { /// ### Why is this bad? /// `crate` refers to the macro call's crate, whereas `$crate` refers to the macro definition's /// crate. Rarely is the former intended. See: - /// https://doc.rust-lang.org/reference/macros-by-example.html#hygiene + /// /// /// ### Example /// ```no_run diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs index d6812cc29173..d6db2c570e61 100644 --- a/clippy_lints/src/default.rs +++ b/clippy_lints/src/default.rs @@ -37,7 +37,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does /// Checks for immediate reassignment of fields initialized - /// with Default::default(). + /// with `Default::default()`. /// /// ### Why is this bad? ///It's more idiomatic to use the [functional update syntax](https://doc.rust-lang.org/reference/expressions/struct-expr.html#functional-update-syntax). diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 8d2eb01e8743..7fde6fcf4dd3 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -1,7 +1,9 @@ use clippy_config::Conf; use clippy_utils::attrs::is_doc_hidden; use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_then}; -use clippy_utils::{is_entrypoint_fn, is_trait_impl_item}; +use clippy_utils::macros::root_macro_call; +use clippy_utils::{is_entrypoint_fn, is_trait_impl_item, sym}; +use rustc_ast::token::DocFragmentKind; use rustc_attr_ir::Attribute; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; @@ -263,7 +265,7 @@ declare_clippy_lint! { /// /// Consume the array and return the inner /// /// [`SmallVec<[T; INLINE_CAPACITY]>`][SmallVec]. /// /// [SmallVec]: SmallVec - /// fn main() {} + /// fn foo() {} /// ``` #[clippy::version = "pre 1.29.0"] pub DOC_MARKDOWN, @@ -878,11 +880,15 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ let (fragments, _) = attrs_to_doc_fragments( attrs.iter().filter_map(|attr| { - if attr.doc_str_and_fragment_kind().is_none() || attr.span().in_external_macro(cx.sess().source_map()) { - None - } else { - Some((attr, None)) - } + let (_, kind) = attr.doc_str_and_fragment_kind()?; + let (is_raw, doc_str_span) = match kind { + DocFragmentKind::Sugared(_) => (false, attr.span()), + DocFragmentKind::Raw(span) => (true, span), + }; + let from_include_str_macro = is_raw + && !attr.span().in_external_macro(cx.sess().source_map()) + && originated_from_include_str_macro(cx, doc_str_span); + (from_include_str_macro || !doc_str_span.in_external_macro(cx.sess().source_map())).then_some((attr, None)) }), true, ); @@ -963,6 +969,10 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet, attrs: &[ )) } +fn originated_from_include_str_macro(cx: &LateContext<'_>, span: Span) -> bool { + root_macro_call(span).is_some_and(|macro_call| cx.tcx.is_diagnostic_item(sym::include_str_macro, macro_call.def_id)) +} + enum Container { Blockquote, List(usize), diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs index a4d3fe9e2296..5ce0e919fbd3 100644 --- a/clippy_lints/src/loops/mod.rs +++ b/clippy_lints/src/loops/mod.rs @@ -333,7 +333,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Checks for manual implementations of Iterator::find + /// Checks for manual implementations of `Iterator::find` /// /// ### Why is this bad? /// It doesn't affect performance, but using `find` is shorter and easier to read. diff --git a/clippy_lints/src/main_recursion.rs b/clippy_lints/src/main_recursion.rs index 26576693a072..23f00352bbc6 100644 --- a/clippy_lints/src/main_recursion.rs +++ b/clippy_lints/src/main_recursion.rs @@ -1,3 +1,5 @@ +#![expect(clippy::needless_doctest_main)] + use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::source::snippet; use clippy_utils::{is_entrypoint_fn, is_no_std_crate}; @@ -9,8 +11,8 @@ declare_clippy_lint! { /// Checks for recursion using the entrypoint. /// /// ### Why is this bad? - /// Apart from special setups (which we could detect following attributes like #![no_std]), - /// recursing into main() seems like an unintuitive anti-pattern we should be able to detect. + /// Apart from special setups (which we could detect following attributes like `#![no_std]`), + /// recursing into `main()` seems like an unintuitive anti-pattern we should be able to detect. /// /// ### Example /// ```no_run diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 53f8d839787c..ee10735de41d 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -997,7 +997,7 @@ declare_clippy_lint! { /// `x.last()`. Indexing into the array will panic on out-of-bounds /// accesses, while `x.get()` and `x.last()` will return `None`. /// - /// There is another lint (get_unwrap) that covers the case of using + /// There is another lint (`get_unwrap`) that covers the case of using /// `x.get(index).unwrap()` instead of `x[index]`. /// /// ### Example @@ -2907,7 +2907,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Checks for usage of `_.as_ref().map(Deref::deref)` or its aliases (such as String::as_str). + /// Checks for usage of `_.as_ref().map(Deref::deref)` or its aliases (such as `String::as_str`). /// /// ### Why is this bad? /// Readability, this can be written more concisely as @@ -3923,9 +3923,8 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Checks for calls to [`splitn`] - /// (https://doc.rust-lang.org/std/primitive.str.html#method.splitn) and - /// related functions with either zero or one splits. + /// Checks for calls to [`splitn`](https://doc.rust-lang.org/std/primitive.str.html#method.splitn) + /// and related functions with either zero or one splits. /// /// ### Why is this bad? /// These calls don't actually split the value and are @@ -4501,7 +4500,7 @@ declare_clippy_lint! { /// ### What it does /// Checks for unnecessary calls to `min()` or `max()` in the following cases /// - Either both side is constant - /// - One side is clearly larger than the other, like i32::MIN and an i32 variable + /// - One side is clearly larger than the other, like `i32::MIN` and an `i32` variable /// /// ### Why is this bad? /// @@ -4830,7 +4829,7 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Checks for usage of File::read_to_end and File::read_to_string. + /// Checks for usage of ``File::read_to_end`` and `File::read_to_string`. /// /// ### Why restrict this? /// `fs::{read, read_to_string}` provide the same functionality when `buf` is empty with fewer imports and no intermediate values. @@ -4903,7 +4902,7 @@ declare_clippy_lint! { /// Clippy allows `Pin<&Self>` and `Pin<&mut Self>` if `&self` and `&mut self` is required. /// /// Please find more info here: - /// https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv + /// /// /// ### Why is this bad? /// Consistency breeds readability. If you follow the diff --git a/clippy_lints/src/misc_early/mod.rs b/clippy_lints/src/misc_early/mod.rs index c47402f72add..072a8e935479 100644 --- a/clippy_lints/src/misc_early/mod.rs +++ b/clippy_lints/src/misc_early/mod.rs @@ -277,21 +277,15 @@ declare_clippy_lint! { /// /// In Rust: /// ```no_run - /// fn main() { - /// let a = 0123; - /// println!("{}", a); - /// } + /// let a = 0123; + /// println!("{}", a); /// ``` /// /// prints `123`, while in C: /// /// ```c - /// #include - /// - /// int main() { - /// int a = 0123; - /// printf("%d\n", a); - /// } + /// int a = 0123; + /// printf("%d\n", a); /// ``` /// /// prints `83` (as `83 == 0o123` while `123 == 0o173`). diff --git a/clippy_lints/src/missing_const_for_thread_local.rs b/clippy_lints/src/missing_const_for_thread_local.rs index 81a48f9a92a1..ddc23a11c976 100644 --- a/clippy_lints/src/missing_const_for_thread_local.rs +++ b/clippy_lints/src/missing_const_for_thread_local.rs @@ -21,7 +21,7 @@ declare_clippy_lint! { /// need to be dropped, this can enable an even more efficient implementation that /// does not need to track any additional state. /// - /// https://doc.rust-lang.org/std/macro.thread_local.html + /// /// /// ### Example /// ```no_run diff --git a/clippy_lints/src/strlen_on_c_strings.rs b/clippy_lints/src/strlen_on_c_strings.rs index e21f1663c87e..dc9e682f26b5 100644 --- a/clippy_lints/src/strlen_on_c_strings.rs +++ b/clippy_lints/src/strlen_on_c_strings.rs @@ -16,7 +16,7 @@ declare_clippy_lint! { /// and suggest calling `count_bytes()` instead. /// /// ### Why is this bad? - /// libc::strlen is an unsafe function, which we don't need to call + /// `libc::strlen` is an unsafe function, which we don't need to call /// if all we want to know is the length of the c-string. /// /// ### Example diff --git a/clippy_lints/src/suspicious_trait_impl.rs b/clippy_lints/src/suspicious_trait_impl.rs index 74cd87c7cc93..0ba88b8ae904 100644 --- a/clippy_lints/src/suspicious_trait_impl.rs +++ b/clippy_lints/src/suspicious_trait_impl.rs @@ -32,8 +32,8 @@ declare_clippy_lint! { declare_clippy_lint! { /// ### What it does - /// Lints for suspicious operations in impls of OpAssign, e.g. - /// subtracting elements in an AddAssign impl. + /// Lints for suspicious operations in impls of `OpAssign`, e.g. + /// subtracting elements in an `AddAssign` impl. /// /// ### Why is this bad? /// This is probably a typo or copy-and-paste error and not intended. diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index abcc81c3c236..938fe464b78a 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -63,7 +63,7 @@ declare_clippy_lint! { /// b = a; /// a = t; /// ``` - /// Use std::mem::swap(): + /// Use `std::mem::swap()`: /// ```no_run /// let mut a = 1; /// let mut b = 2; diff --git a/clippy_lints/src/transmute/mod.rs b/clippy_lints/src/transmute/mod.rs index 89beedcfe362..a3b6b1d34853 100644 --- a/clippy_lints/src/transmute/mod.rs +++ b/clippy_lints/src/transmute/mod.rs @@ -241,7 +241,7 @@ declare_clippy_lint! { /// ### Why is this bad? /// Creating a null function pointer is undefined behavior. /// - /// More info: https://doc.rust-lang.org/nomicon/ffi.html#the-nullable-pointer-optimization + /// More info: /// /// ### Known problems /// Not all cases can be detected at the moment of this writing. diff --git a/clippy_lints/src/unit_return_expecting_ord.rs b/clippy_lints/src/unit_return_expecting_ord.rs index 2225a85b0948..4784fd5713c8 100644 --- a/clippy_lints/src/unit_return_expecting_ord.rs +++ b/clippy_lints/src/unit_return_expecting_ord.rs @@ -9,18 +9,18 @@ use rustc_span::{BytePos, Span, Symbol, sym}; declare_clippy_lint! { /// ### What it does /// Checks for functions that expect closures of type - /// Fn(...) -> Ord where the implemented closure returns the unit type. + /// `Fn(...) -> Ord` where the implemented closure returns the unit type. /// The lint also suggests to remove the semi-colon at the end of the statement if present. /// /// ### Why is this bad? /// Likely, returning the unit type is unintentional, and - /// could simply be caused by an extra semi-colon. Since () implements Ord + /// could simply be caused by an extra semi-colon. Since `()` implements `Ord` /// it doesn't cause a compilation error. - /// This is the same reasoning behind the unit_cmp lint. + /// This is the same reasoning behind the `unit_cmp` lint. /// /// ### Known problems /// If returning unit is intentional, then there is no - /// way of specifying this without triggering needless_return lint + /// way of specifying this without triggering `needless_return` lint /// /// ### Example /// ```no_run diff --git a/clippy_lints/src/unnecessary_self_imports.rs b/clippy_lints/src/unnecessary_self_imports.rs index 677a459a03c7..6f5098cdda56 100644 --- a/clippy_lints/src/unnecessary_self_imports.rs +++ b/clippy_lints/src/unnecessary_self_imports.rs @@ -13,7 +13,7 @@ declare_clippy_lint! { /// /// ### Known problems /// Removing `::{self}` will cause any non-module items at the same path to also be imported. - /// This might cause a naming conflict (https://github.com/rust-lang/rustfmt/issues/3568). This lint makes no attempt + /// This might cause a [naming conflict](https://github.com/rust-lang/rustfmt/issues/3568). This lint makes no attempt /// to detect this scenario and that is why it is a restriction lint. /// /// ### Example diff --git a/clippy_lints/src/write/mod.rs b/clippy_lints/src/write/mod.rs index ac8ddd3653e5..86f4920b5b7f 100644 --- a/clippy_lints/src/write/mod.rs +++ b/clippy_lints/src/write/mod.rs @@ -15,8 +15,7 @@ declare_clippy_lint! { /// This lint warns about the use of literals as `print!`/`println!` args. /// /// ### Why is this bad? - /// Using literals as `println!` args is inefficient - /// (c.f., https://github.com/matthiaskrgr/rust-str-bench) and unnecessary + /// Using literals as `println!` args is [inefficient] and unnecessary /// (i.e., just put the literal in the format string) /// /// ### Example @@ -27,6 +26,8 @@ declare_clippy_lint! { /// ```no_run /// println!("foo"); /// ``` + /// + /// [inefficient]: https://github.com/matthiaskrgr/rust-str-bench #[clippy::version = "pre 1.29.0"] pub PRINT_LITERAL, style, @@ -153,8 +154,7 @@ declare_clippy_lint! { /// This lint warns about the use of literals as `write!`/`writeln!` args. /// /// ### Why is this bad? - /// Using literals as `writeln!` args is inefficient - /// (c.f., https://github.com/matthiaskrgr/rust-str-bench) and unnecessary + /// Using literals as `writeln!` args is [inefficient] and unnecessary /// (i.e., just put the literal in the format string) /// /// ### Example @@ -170,6 +170,8 @@ declare_clippy_lint! { /// # let mut buf = String::new(); /// writeln!(buf, "foo"); /// ``` + /// + /// [inefficient]: https://github.com/matthiaskrgr/rust-str-bench #[clippy::version = "pre 1.29.0"] pub WRITE_LITERAL, style, diff --git a/clippy_lints_internal/src/collapsible_span_lint_calls.rs b/clippy_lints_internal/src/collapsible_span_lint_calls.rs index 14fb62e467db..0cd10da70a0b 100644 --- a/clippy_lints_internal/src/collapsible_span_lint_calls.rs +++ b/clippy_lints_internal/src/collapsible_span_lint_calls.rs @@ -18,7 +18,7 @@ declare_tool_lint! { /// span), `help` or `note`. /// /// These usages of `span_lint_and_then` should be replaced with one of the - /// wrapper functions `span_lint_and_sugg`, span_lint_and_help`, or + /// wrapper functions `span_lint_and_sugg`, `span_lint_and_help`, or /// `span_lint_and_note`. /// /// ### Why is this bad? diff --git a/clippy_lints_internal/src/unsorted_clippy_utils_paths.rs b/clippy_lints_internal/src/unsorted_clippy_utils_paths.rs index 8e4a83b7be4e..badb106bd8c3 100644 --- a/clippy_lints_internal/src/unsorted_clippy_utils_paths.rs +++ b/clippy_lints_internal/src/unsorted_clippy_utils_paths.rs @@ -11,7 +11,7 @@ declare_tool_lint! { /// We like to pretend we're an example of tidy code. /// /// ### Example - /// Wrong ordering of the util::paths constants. + /// Wrong ordering of the `util::paths` constants. pub clippy::UNSORTED_CLIPPY_UTILS_PATHS, Warn, "various things that will negatively affect your clippy experience", diff --git a/tests/ui/doc_unsafe.rs b/tests/ui/doc_unsafe.rs index e6180f7c62e8..3946147bfd0b 100644 --- a/tests/ui/doc_unsafe.rs +++ b/tests/ui/doc_unsafe.rs @@ -183,3 +183,21 @@ pub mod __macro { pub unsafe trait DocumentedUnsafeTraitWithImplementationHeader { fn method(); } + +pub mod issue_16317 { + use super::external; + + external! { + #[doc = $("# Safety")] + $( + pub unsafe fn expanded_unsafe_fn_with_safety() {} + ) + } + external! { + #[doc = $("No safety comment")] + $( + pub unsafe fn expanded_unsafe_fn_without_safety() {} + //~^ missing_safety_doc + ) + } +} diff --git a/tests/ui/doc_unsafe.stderr b/tests/ui/doc_unsafe.stderr index efac6cd64c87..84c62a9e0589 100644 --- a/tests/ui/doc_unsafe.stderr +++ b/tests/ui/doc_unsafe.stderr @@ -89,5 +89,11 @@ LL | very_unsafe!(); | = note: this error originates in the macro `very_unsafe` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 12 previous errors +error: unsafe function's docs are missing a `# Safety` section + --> tests/ui/doc_unsafe.rs:199:13 + | +LL | pub unsafe fn expanded_unsafe_fn_without_safety() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 13 previous errors diff --git a/tests/ui/empty_docs.rs b/tests/ui/empty_docs.rs index b6134324d675..f91bba7e7204 100644 --- a/tests/ui/empty_docs.rs +++ b/tests/ui/empty_docs.rs @@ -4,6 +4,9 @@ #![expect(clippy::mixed_attributes_style)] #![feature(extern_types)] +extern crate proc_macros; +use proc_macros::external; + mod outer { //! //~^ empty_docs @@ -92,3 +95,11 @@ mod issue_12377 { a: u8, } } + +external! { + #[doc = $("")] + //~^ empty_docs + $( + fn issue_16382() {} + ) +} diff --git a/tests/ui/empty_docs.stderr b/tests/ui/empty_docs.stderr index 75f57442843e..3a131e4a5505 100644 --- a/tests/ui/empty_docs.stderr +++ b/tests/ui/empty_docs.stderr @@ -1,5 +1,5 @@ error: empty doc comment - --> tests/ui/empty_docs.rs:8:5 + --> tests/ui/empty_docs.rs:11:5 | LL | //! | ^^^ @@ -9,7 +9,7 @@ LL | //! = help: to override `-D warnings` add `#[allow(clippy::empty_docs)]` error: empty doc comment - --> tests/ui/empty_docs.rs:17:5 + --> tests/ui/empty_docs.rs:20:5 | LL | /// | ^^^ @@ -17,7 +17,7 @@ LL | /// = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:20:9 + --> tests/ui/empty_docs.rs:23:9 | LL | /// | ^^^ @@ -25,7 +25,7 @@ LL | /// = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:32:13 + --> tests/ui/empty_docs.rs:35:13 | LL | #[doc = ""] | ^^ @@ -33,7 +33,7 @@ LL | #[doc = ""] = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:36:13 + --> tests/ui/empty_docs.rs:39:13 | LL | #[doc = ""] | _____________^ @@ -43,7 +43,7 @@ LL | | #[doc = ""] = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:44:5 + --> tests/ui/empty_docs.rs:47:5 | LL | /// | ^^^ @@ -51,7 +51,7 @@ LL | /// = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:58:13 + --> tests/ui/empty_docs.rs:61:13 | LL | /*! */ | ^^^^^^ @@ -59,7 +59,7 @@ LL | /*! */ = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:67:13 + --> tests/ui/empty_docs.rs:70:13 | LL | /// | ^^^ @@ -67,12 +67,21 @@ LL | /// = help: consider removing or filling it error: empty doc comment - --> tests/ui/empty_docs.rs:76:9 + --> tests/ui/empty_docs.rs:79:9 | LL | /// | ^^^ | = help: consider removing or filling it -error: aborting due to 9 previous errors +error: empty doc comment + --> tests/ui/empty_docs.rs:100:15 + | +LL | #[doc = $("")] + | ^^ + | + = help: consider removing or filling it + = note: this error originates in the macro `external` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 10 previous errors diff --git a/tests/ui/missing_panics_doc.rs b/tests/ui/missing_panics_doc.rs index 63e84ffaab63..d561c726a557 100644 --- a/tests/ui/missing_panics_doc.rs +++ b/tests/ui/missing_panics_doc.rs @@ -4,8 +4,10 @@ #[macro_use] extern crate macro_rules; +extern crate proc_macros; use macro_rules::macro_with_panic; +use proc_macros::external; fn main() {} @@ -278,3 +280,33 @@ pub const fn in_const_fn(n: usize) { //~^ missing_panics_doc assert!(N > n); } + +pub mod doc_with_original_span { + use super::external; + external! { + #[doc = $("# Panics ")] + $( + pub fn foo() { panic!() } + ) + } + + external! { + #[doc = $("missing panics doc")] + $( + pub fn foo1() { panic!() } + //~^ missing_panics_doc + ) + } + + pub struct Bar; + + impl Bar { + external! { + #[doc = $("missing panics doc")] + $( + pub fn foo() { panic!() } + //~^ missing_panics_doc + ) + } + } +} diff --git a/tests/ui/missing_panics_doc.stderr b/tests/ui/missing_panics_doc.stderr index 85a009144273..5d5d99d2baa9 100644 --- a/tests/ui/missing_panics_doc.stderr +++ b/tests/ui/missing_panics_doc.stderr @@ -1,11 +1,11 @@ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:13:1 + --> tests/ui/missing_panics_doc.rs:15:1 | LL | pub fn unwrap() { | ^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:16:5 + --> tests/ui/missing_panics_doc.rs:18:5 | LL | result.unwrap() | ^^^^^^^^^^^^^^^ @@ -13,208 +13,232 @@ LL | result.unwrap() = help: to override `-D warnings` add `#[allow(clippy::missing_panics_doc)]` error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:20:1 + --> tests/ui/missing_panics_doc.rs:22:1 | LL | pub fn panic() { | ^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:22:5 + --> tests/ui/missing_panics_doc.rs:24:5 | LL | panic!("This function panics") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:26:1 + --> tests/ui/missing_panics_doc.rs:28:1 | LL | pub fn inner_body(opt: Option) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:30:13 + --> tests/ui/missing_panics_doc.rs:32:13 | LL | panic!() | ^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:36:1 + --> tests/ui/missing_panics_doc.rs:38:1 | LL | pub fn unreachable_and_panic() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:38:39 + --> tests/ui/missing_panics_doc.rs:40:39 | LL | if true { unreachable!() } else { panic!() } | ^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:42:1 + --> tests/ui/missing_panics_doc.rs:44:1 | LL | pub fn assert_eq() { | ^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:45:5 + --> tests/ui/missing_panics_doc.rs:47:5 | LL | assert_eq!(x, 0); | ^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:49:1 + --> tests/ui/missing_panics_doc.rs:51:1 | LL | pub fn assert_ne() { | ^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:52:5 + --> tests/ui/missing_panics_doc.rs:54:5 | LL | assert_ne!(x, 0); | ^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:154:1 + --> tests/ui/missing_panics_doc.rs:156:1 | LL | pub fn partially_const(n: usize) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:161:5 + --> tests/ui/missing_panics_doc.rs:163:5 | LL | assert!(N > n); | ^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:172:1 + --> tests/ui/missing_panics_doc.rs:174:1 | LL | pub fn expect_allow_with_error(i: Option) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:181:5 + --> tests/ui/missing_panics_doc.rs:183:5 | LL | i.unwrap(); | ^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:184:1 + --> tests/ui/missing_panics_doc.rs:186:1 | LL | pub fn expect_after_error(x: Option, y: Option) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:187:13 + --> tests/ui/missing_panics_doc.rs:189:13 | LL | let x = x.unwrap(); | ^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:196:5 + --> tests/ui/missing_panics_doc.rs:198:5 | LL | pub fn option_unwrap(v: &[T]) -> &T { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:199:9 + --> tests/ui/missing_panics_doc.rs:201:9 | LL | o.unwrap() | ^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:202:5 + --> tests/ui/missing_panics_doc.rs:204:5 | LL | pub fn option_expect(v: &[T]) -> &T { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:205:9 + --> tests/ui/missing_panics_doc.rs:207:9 | LL | o.expect("passed an empty thing") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:208:5 + --> tests/ui/missing_panics_doc.rs:210:5 | LL | pub fn result_unwrap(v: &[T]) -> &T { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:211:9 + --> tests/ui/missing_panics_doc.rs:213:9 | LL | res.unwrap() | ^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:214:5 + --> tests/ui/missing_panics_doc.rs:216:5 | LL | pub fn result_expect(v: &[T]) -> &T { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:217:9 + --> tests/ui/missing_panics_doc.rs:219:9 | LL | res.expect("passed an empty thing") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:220:5 + --> tests/ui/missing_panics_doc.rs:222:5 | LL | pub fn last_unwrap(v: &[u32]) -> u32 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:222:10 + --> tests/ui/missing_panics_doc.rs:224:10 | LL | *v.last().unwrap() | ^^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:225:5 + --> tests/ui/missing_panics_doc.rs:227:5 | LL | pub fn last_expect(v: &[u32]) -> u32 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:227:10 + --> tests/ui/missing_panics_doc.rs:229:10 | LL | *v.last().expect("passed an empty thing") | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:262:1 + --> tests/ui/missing_panics_doc.rs:264:1 | LL | pub const fn unwrap_expect_etc_in_const_fn_fails() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:264:13 + --> tests/ui/missing_panics_doc.rs:266:13 | LL | let a = std::num::NonZeroUsize::new(1).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:268:1 + --> tests/ui/missing_panics_doc.rs:270:1 | LL | pub const fn assert_in_const_fn_fails() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:272:9 + --> tests/ui/missing_panics_doc.rs:274:9 | LL | panic!(); | ^^^^^^^^ error: docs for function which may panic missing `# Panics` section - --> tests/ui/missing_panics_doc.rs:277:1 + --> tests/ui/missing_panics_doc.rs:279:1 | LL | pub const fn in_const_fn(n: usize) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first possible panic found here - --> tests/ui/missing_panics_doc.rs:279:5 + --> tests/ui/missing_panics_doc.rs:281:5 | LL | assert!(N > n); | ^^^^^^^^^^^^^^ -error: aborting due to 18 previous errors +error: docs for function which may panic missing `# Panics` section + --> tests/ui/missing_panics_doc.rs:296:13 + | +LL | pub fn foo1() { panic!() } + | ^^^^^^^^^^^^^ + | +note: first possible panic found here + --> tests/ui/missing_panics_doc.rs:296:29 + | +LL | pub fn foo1() { panic!() } + | ^^^^^^^^ + +error: docs for function which may panic missing `# Panics` section + --> tests/ui/missing_panics_doc.rs:307:17 + | +LL | pub fn foo() { panic!() } + | ^^^^^^^^^^^^ + | +note: first possible panic found here + --> tests/ui/missing_panics_doc.rs:307:32 + | +LL | pub fn foo() { panic!() } + | ^^^^^^^^ + +error: aborting due to 20 previous errors