about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md65
-rw-r--r--Cargo.toml11
-rw-r--r--clippy_lints/src/dereference.rs5
-rw-r--r--clippy_lints/src/items_after_test_module.rs2
-rw-r--r--clippy_lints/src/loops/mod.rs2
-rw-r--r--clippy_lints/src/methods/mod.rs2
-rw-r--r--clippy_lints/src/methods/unnecessary_literal_unwrap.rs16
-rw-r--r--clippy_lints/src/needless_bool.rs2
-rw-r--r--clippy_lints/src/panic_in_result_fn.rs10
-rw-r--r--clippy_test_deps/Cargo.toml23
-rw-r--r--clippy_test_deps/src/lib.rs14
-rw-r--r--tests/compile-test.rs118
-rw-r--r--tests/ui/panic_in_result_fn.stderr74
-rw-r--r--tests/ui/panic_in_result_fn_assertions.stderr12
-rw-r--r--tests/ui/unnecessary_literal_unwrap.fixed11
-rw-r--r--tests/ui/unnecessary_literal_unwrap.rs11
-rw-r--r--tests/ui/unnecessary_literal_unwrap.stderr86
17 files changed, 331 insertions, 133 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 038fe32e587..b3b6e3b865f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,11 +6,72 @@ document.
 
 ## Unreleased / Beta / In Rust Nightly
 
-[83e42a23...master](https://github.com/rust-lang/rust-clippy/compare/83e42a23...master)
+[435a8ad8...master](https://github.com/rust-lang/rust-clippy/compare/435a8ad8...master)
+
+## Rust 1.71
+
+Current stable, released 2023-07-13
+
+<!-- FIXME: Remove the request for feedback, with the next changelog -->
+
+We're trying out a new shorter changelog format, that only contains significant changes.
+You can check out the list of merged pull requests for a list of all changes.
+If you have any feedback related to the new format, please share it in 
+[#10847](https://github.com/rust-lang/rust-clippy/issues/10847)
+
+[View all 78 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-04-11T20%3A05%3A26Z..2023-05-20T13%3A48%3A17Z+base%3Amaster)
+
+### New Lints
+
+* [`non_minimal_cfg`]
+  [#10763](https://github.com/rust-lang/rust-clippy/pull/10763)
+* [`manual_next_back`]
+  [#10769](https://github.com/rust-lang/rust-clippy/pull/10769)
+* [`ref_patterns`]
+  [#10736](https://github.com/rust-lang/rust-clippy/pull/10736)
+* [`default_constructed_unit_structs`]
+  [#10716](https://github.com/rust-lang/rust-clippy/pull/10716)
+* [`manual_while_let_some`]
+  [#10647](https://github.com/rust-lang/rust-clippy/pull/10647)
+* [`needless_bool_assign`]
+  [#10432](https://github.com/rust-lang/rust-clippy/pull/10432)
+* [`items_after_test_module`]
+  [#10578](https://github.com/rust-lang/rust-clippy/pull/10578)
+
+### Moves and Deprecations
+
+* Rename `integer_arithmetic` to `arithmetic_side_effects`
+  [#10674](https://github.com/rust-lang/rust-clippy/pull/10674)
+* Moved [`redundant_clone`] to `nursery` (Now allow-by-default)
+  [#10873](https://github.com/rust-lang/rust-clippy/pull/10873)
+
+### Enhancements
+
+* [`invalid_regex`]: Now supports the new syntax introduced after regex v1.8.0
+  [#10682](https://github.com/rust-lang/rust-clippy/pull/10682)
+* [`semicolon_outside_block`]: Added [`semicolon-outside-block-ignore-multiline`] as a new config value.
+  [#10656](https://github.com/rust-lang/rust-clippy/pull/10656)
+* [`semicolon_inside_block`]: Added [`semicolon-inside-block-ignore-singleline`] as a new config value.
+  [#10656](https://github.com/rust-lang/rust-clippy/pull/10656)
+* [`unnecessary_box_returns`]: Added [`unnecessary-box-size`] as a new config value to set the maximum
+  size of `T` in `Box<T>` to be linted.
+  [#10651](https://github.com/rust-lang/rust-clippy/pull/10651)
+
+### Documentation Improvements
+
+* `cargo clippy --explain LINT` now shows possible configuration options for the explained lint
+  [#10751](https://github.com/rust-lang/rust-clippy/pull/10751)
+* New config values mentioned in this changelog will now be linked.
+  [#10889](https://github.com/rust-lang/rust-clippy/pull/10889)
+* Several sections of [Clippy's book] have been reworked
+  [#10652](https://github.com/rust-lang/rust-clippy/pull/10652)
+  [#10622](https://github.com/rust-lang/rust-clippy/pull/10622)
+
+[Clippy's book]: https://doc.rust-lang.org/clippy/
 
 ## Rust 1.70
 
-Current stable, released 2023-06-01
+Released 2023-06-01
 
 [View all 91 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-02-26T01%3A05%3A43Z..2023-04-11T13%3A27%3A30Z+base%3Amaster)
 
diff --git a/Cargo.toml b/Cargo.toml
index 76c804f935e..e7a5dbe030d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -36,6 +36,17 @@ walkdir = "2.3"
 filetime = "0.2"
 itertools = "0.10.1"
 
+# UI test dependencies
+clippy_utils = { path = "clippy_utils" }
+derive-new = "0.5"
+if_chain = "1.0"
+quote = "1.0"
+serde = { version = "1.0.125", features = ["derive"] }
+syn = { version = "2.0", features = ["full"] }
+futures = "0.3"
+parking_lot = "0.12"
+tokio = { version = "1", features = ["io-util"] }
+
 [build-dependencies]
 rustc_tools_util = "0.3.0"
 
diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs
index 3af552e5016..cdf64b96036 100644
--- a/clippy_lints/src/dereference.rs
+++ b/clippy_lints/src/dereference.rs
@@ -77,6 +77,11 @@ declare_clippy_lint! {
     /// Suggests that the receiver of the expression borrows
     /// the expression.
     ///
+    /// ### Known problems
+    /// The lint cannot tell when the implementation of a trait
+    /// for `&T` and `T` do different things. Removing a borrow
+    /// in such a case can change the semantics of the code.
+    ///
     /// ### Example
     /// ```rust
     /// fn fun(_a: &i32) {}
diff --git a/clippy_lints/src/items_after_test_module.rs b/clippy_lints/src/items_after_test_module.rs
index 40378ee8205..f684847c0c2 100644
--- a/clippy_lints/src/items_after_test_module.rs
+++ b/clippy_lints/src/items_after_test_module.rs
@@ -32,7 +32,7 @@ declare_clippy_lint! {
     ///     // [...]
     /// }
     /// ```
-    #[clippy::version = "1.70.0"]
+    #[clippy::version = "1.71.0"]
     pub ITEMS_AFTER_TEST_MODULE,
     style,
     "An item was found after the testing module `tests`"
diff --git a/clippy_lints/src/loops/mod.rs b/clippy_lints/src/loops/mod.rs
index 529189b52ac..ffd29ab7630 100644
--- a/clippy_lints/src/loops/mod.rs
+++ b/clippy_lints/src/loops/mod.rs
@@ -601,7 +601,7 @@ declare_clippy_lint! {
     ///     // use `number`
     /// }
     /// ```
-    #[clippy::version = "1.70.0"]
+    #[clippy::version = "1.71.0"]
     pub MANUAL_WHILE_LET_SOME,
     style,
     "checking for emptiness of a `Vec` in the loop condition and popping an element in the body"
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index c99f7c1fdd9..d6057ce45f6 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -4019,7 +4019,7 @@ impl Methods {
                     }
                     unnecessary_literal_unwrap::check(cx, expr, recv, name, args);
                 },
-                ("unwrap_or_default", []) => {
+                ("unwrap_or_default" | "unwrap_unchecked" | "unwrap_err_unchecked", []) => {
                     unnecessary_literal_unwrap::check(cx, expr, recv, name, args);
                 }
                 ("unwrap_or_else", [u_arg]) => {
diff --git a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
index ce93d7c3eb3..54de300e6bc 100644
--- a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
+++ b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
@@ -67,6 +67,22 @@ pub(super) fn check(
                 (expr.span.with_hi(args[0].span.lo()), "panic!(".to_string()),
                 (expr.span.with_lo(args[0].span.hi()), ")".to_string()),
             ]),
+            ("Some" | "Ok", "unwrap_unchecked", _) | ("Err", "unwrap_err_unchecked", _) => {
+                let mut suggs = vec![
+                    (recv.span.with_hi(call_args[0].span.lo()), String::new()),
+                    (expr.span.with_lo(call_args[0].span.hi()), String::new()),
+                ];
+                // try to also remove the unsafe block if present
+                if let hir::Node::Block(block) = cx.tcx.hir().get_parent(expr.hir_id)
+                    && let hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::UserProvided) = block.rules
+                {
+                    suggs.extend([
+                        (block.span.shrink_to_lo().to(expr.span.shrink_to_lo()), String::new()),
+                        (expr.span.shrink_to_hi().to(block.span.shrink_to_hi()), String::new())
+                    ]);
+                }
+                Some(suggs)
+            },
             (_, _, Some(_)) => None,
             ("Ok", "unwrap_err", None) | ("Err", "unwrap", None) => Some(vec![
                 (
diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs
index 62af42a3961..34b74e180cb 100644
--- a/clippy_lints/src/needless_bool.rs
+++ b/clippy_lints/src/needless_bool.rs
@@ -106,7 +106,7 @@ declare_clippy_lint! {
     /// # let mut skip: bool;
     /// skip = !must_keep(x, y);
     /// ```
-    #[clippy::version = "1.69.0"]
+    #[clippy::version = "1.71.0"]
     pub NEEDLESS_BOOL_ASSIGN,
     complexity,
     "setting the same boolean variable in both branches of an if-statement"
diff --git a/clippy_lints/src/panic_in_result_fn.rs b/clippy_lints/src/panic_in_result_fn.rs
index 849cd03dd7b..a049427d85d 100644
--- a/clippy_lints/src/panic_in_result_fn.rs
+++ b/clippy_lints/src/panic_in_result_fn.rs
@@ -13,7 +13,7 @@ use rustc_span::{sym, Span};
 
 declare_clippy_lint! {
     /// ### What it does
-    /// Checks for usage of `panic!`, `unimplemented!`, `todo!`, `unreachable!` or assertions in a function of type result.
+    /// Checks for usage of `panic!` or assertions in a function of type result.
     ///
     /// ### Why is this bad?
     /// For some codebases, it is desirable for functions of type result to return an error instead of crashing. Hence panicking macros should be avoided.
@@ -37,7 +37,7 @@ declare_clippy_lint! {
     #[clippy::version = "1.48.0"]
     pub PANIC_IN_RESULT_FN,
     restriction,
-    "functions of type `Result<..>` that contain `panic!()`, `todo!()`, `unreachable()`, `unimplemented()` or assertion"
+    "functions of type `Result<..>` that contain `panic!()` or assertion"
 }
 
 declare_lint_pass!(PanicInResultFn  => [PANIC_IN_RESULT_FN]);
@@ -70,7 +70,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, body: &'tcx hir
         };
         if matches!(
             cx.tcx.item_name(macro_call.def_id).as_str(),
-            "unimplemented" | "unreachable" | "panic" | "todo" | "assert" | "assert_eq" | "assert_ne"
+            "panic" | "assert" | "assert_eq" | "assert_ne"
         ) {
             panics.push(macro_call.span);
             ControlFlow::Continue(Descend::No)
@@ -83,10 +83,10 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, body: &'tcx hir
             cx,
             PANIC_IN_RESULT_FN,
             impl_span,
-            "used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`",
+            "used `panic!()` or assertion in a function that returns `Result`",
             move |diag| {
                 diag.help(
-                    "`unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing",
+                    "`panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing",
                 );
                 diag.span_note(panics, "return Err() instead of panicking");
             },
diff --git a/clippy_test_deps/Cargo.toml b/clippy_test_deps/Cargo.toml
deleted file mode 100644
index 362c08e0d77..00000000000
--- a/clippy_test_deps/Cargo.toml
+++ /dev/null
@@ -1,23 +0,0 @@
-[package]
-name = "clippy_test_deps"
-version = "0.1.0"
-edition = "2021"
-
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
-[dependencies]
-clippy_utils = { path = "../clippy_utils" }
-derive-new = "0.5"
-if_chain = "1.0"
-itertools = "0.10.1"
-quote = "1.0"
-serde = { version = "1.0.125", features = ["derive"] }
-syn = { version = "2.0", features = ["full"] }
-futures = "0.3"
-parking_lot = "0.12"
-tokio = { version = "1", features = ["io-util"] }
-regex = "1.5"
-clippy_lints = { path = "../clippy_lints" }
-
-[features]
-internal = ["clippy_lints/internal"]
diff --git a/clippy_test_deps/src/lib.rs b/clippy_test_deps/src/lib.rs
deleted file mode 100644
index 7d12d9af819..00000000000
--- a/clippy_test_deps/src/lib.rs
+++ /dev/null
@@ -1,14 +0,0 @@
-pub fn add(left: usize, right: usize) -> usize {
-    left + right
-}
-
-#[cfg(test)]
-mod tests {
-    use super::*;
-
-    #[test]
-    fn it_works() {
-        let result = add(2, 2);
-        assert_eq!(result, 4);
-    }
-}
diff --git a/tests/compile-test.rs b/tests/compile-test.rs
index d37151b19b6..b86e6849d26 100644
--- a/tests/compile-test.rs
+++ b/tests/compile-test.rs
@@ -3,17 +3,108 @@
 #![feature(is_sorted)]
 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
 #![warn(rust_2018_idioms, unused_lifetimes)]
+#![allow(unused_extern_crates)]
 
 use compiletest::{status_emitter, CommandBuilder};
 use ui_test as compiletest;
 use ui_test::Mode as TestMode;
 
+use std::collections::BTreeMap;
 use std::env::{self, remove_var, set_var, var_os};
 use std::ffi::{OsStr, OsString};
 use std::fs;
 use std::path::{Path, PathBuf};
+use std::sync::LazyLock;
 use test_utils::IS_RUSTC_TEST_SUITE;
 
+// Test dependencies may need an `extern crate` here to ensure that they show up
+// in the depinfo file (otherwise cargo thinks they are unused)
+extern crate clippy_lints;
+extern crate clippy_utils;
+extern crate derive_new;
+extern crate futures;
+extern crate if_chain;
+extern crate itertools;
+extern crate parking_lot;
+extern crate quote;
+extern crate syn;
+extern crate tokio;
+
+/// All crates used in UI tests are listed here
+static TEST_DEPENDENCIES: &[&str] = &[
+    "clippy_lints",
+    "clippy_utils",
+    "derive_new",
+    "futures",
+    "if_chain",
+    "itertools",
+    "parking_lot",
+    "quote",
+    "regex",
+    "serde_derive",
+    "serde",
+    "syn",
+    "tokio",
+];
+
+/// Produces a string with an `--extern` flag for all UI test crate
+/// dependencies.
+///
+/// The dependency files are located by parsing the depinfo file for this test
+/// module. This assumes the `-Z binary-dep-depinfo` flag is enabled. All test
+/// dependencies must be added to Cargo.toml at the project root. Test
+/// dependencies that are not *directly* used by this test module require an
+/// `extern crate` declaration.
+static EXTERN_FLAGS: LazyLock<Vec<String>> = LazyLock::new(|| {
+    let current_exe_depinfo = {
+        let mut path = env::current_exe().unwrap();
+        path.set_extension("d");
+        fs::read_to_string(path).unwrap()
+    };
+    let mut crates = BTreeMap::<&str, &str>::new();
+    for line in current_exe_depinfo.lines() {
+        // each dependency is expected to have a Makefile rule like `/path/to/crate-hash.rlib:`
+        let parse_name_path = || {
+            if line.starts_with(char::is_whitespace) {
+                return None;
+            }
+            let path_str = line.strip_suffix(':')?;
+            let path = Path::new(path_str);
+            if !matches!(path.extension()?.to_str()?, "rlib" | "so" | "dylib" | "dll") {
+                return None;
+            }
+            let (name, _hash) = path.file_stem()?.to_str()?.rsplit_once('-')?;
+            // the "lib" prefix is not present for dll files
+            let name = name.strip_prefix("lib").unwrap_or(name);
+            Some((name, path_str))
+        };
+        if let Some((name, path)) = parse_name_path() {
+            if TEST_DEPENDENCIES.contains(&name) {
+                // A dependency may be listed twice if it is available in sysroot,
+                // and the sysroot dependencies are listed first. As of the writing,
+                // this only seems to apply to if_chain.
+                crates.insert(name, path);
+            }
+        }
+    }
+    let not_found: Vec<&str> = TEST_DEPENDENCIES
+        .iter()
+        .copied()
+        .filter(|n| !crates.contains_key(n))
+        .collect();
+    assert!(
+        not_found.is_empty(),
+        "dependencies not found in depinfo: {not_found:?}\n\
+        help: Make sure the `-Z binary-dep-depinfo` rust flag is enabled\n\
+        help: Try adding to dev-dependencies in Cargo.toml\n\
+        help: Be sure to also add `extern crate ...;` to tests/compile-test.rs",
+    );
+    crates
+        .into_iter()
+        .map(|(name, path)| format!("--extern={name}={path}"))
+        .collect()
+});
+
 mod test_utils;
 
 // whether to run internal tests or not
@@ -29,7 +120,6 @@ fn base_config(test_dir: &str) -> compiletest::Config {
         } else {
             compiletest::OutputConflictHandling::Error("cargo test -- -- --bless".into())
         },
-        dependencies_crate_manifest_path: Some("clippy_test_deps/Cargo.toml".into()),
         target: None,
         out_dir: "target/ui_test".into(),
         ..compiletest::Config::rustc(Path::new("tests").join(test_dir))
@@ -44,10 +134,23 @@ fn base_config(test_dir: &str) -> compiletest::Config {
     let deps_path = current_exe_path.parent().unwrap();
     let profile_path = deps_path.parent().unwrap();
 
-    config.program.args.push("--emit=metadata".into());
-    config.program.args.push("-Aunused".into());
-    config.program.args.push("-Zui-testing".into());
-    config.program.args.push("-Dwarnings".into());
+    config.program.args.extend(
+        [
+            "--emit=metadata",
+            "-Aunused",
+            "-Zui-testing",
+            "-Dwarnings",
+            &format!("-Ldependency={}", deps_path.display()),
+        ]
+        .map(OsString::from),
+    );
+
+    config.program.args.extend(EXTERN_FLAGS.iter().map(OsString::from));
+
+    if let Some(host_libs) = option_env!("HOST_LIBS") {
+        let dep = format!("-Ldependency={}", Path::new(host_libs).join("deps").display());
+        config.program.args.push(dep.into());
+    }
 
     // Normalize away slashes in windows paths.
     config.stderr_filter(r"\\", "/");
@@ -105,9 +208,7 @@ fn run_internal_tests() {
     if !RUN_INTERNAL_TESTS {
         return;
     }
-    let mut config = base_config("ui-internal");
-    config.dependency_builder.args.push("--features".into());
-    config.dependency_builder.args.push("internal".into());
+    let config = base_config("ui-internal");
     compiletest::run_tests(config).unwrap();
 }
 
@@ -165,7 +266,6 @@ fn run_ui_cargo() {
         .push(("RUSTFLAGS".into(), Some("-Dwarnings".into())));
     // We need to do this while we still have a rustc in the `program` field.
     config.fill_host_and_target().unwrap();
-    config.dependencies_crate_manifest_path = None;
     config.program.program.set_file_name(if cfg!(windows) {
         "cargo-clippy.exe"
     } else {
diff --git a/tests/ui/panic_in_result_fn.stderr b/tests/ui/panic_in_result_fn.stderr
index 97787bc84e2..b758fc23812 100644
--- a/tests/ui/panic_in_result_fn.stderr
+++ b/tests/ui/panic_in_result_fn.stderr
@@ -1,4 +1,4 @@
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
+error: used `panic!()` or assertion in a function that returns `Result`
   --> $DIR/panic_in_result_fn.rs:6:5
    |
 LL | /     fn result_with_panic() -> Result<bool, String> // should emit lint
@@ -7,7 +7,7 @@ LL | |         panic!("error");
 LL | |     }
    | |_____^
    |
-   = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
+   = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
 note: return Err() instead of panicking
   --> $DIR/panic_in_result_fn.rs:8:9
    |
@@ -15,55 +15,7 @@ LL |         panic!("error");
    |         ^^^^^^^^^^^^^^^
    = note: `-D clippy::panic-in-result-fn` implied by `-D warnings`
 
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
-  --> $DIR/panic_in_result_fn.rs:11:5
-   |
-LL | /     fn result_with_unimplemented() -> Result<bool, String> // should emit lint
-LL | |     {
-LL | |         unimplemented!();
-LL | |     }
-   | |_____^
-   |
-   = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
-note: return Err() instead of panicking
-  --> $DIR/panic_in_result_fn.rs:13:9
-   |
-LL |         unimplemented!();
-   |         ^^^^^^^^^^^^^^^^
-
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
-  --> $DIR/panic_in_result_fn.rs:16:5
-   |
-LL | /     fn result_with_unreachable() -> Result<bool, String> // should emit lint
-LL | |     {
-LL | |         unreachable!();
-LL | |     }
-   | |_____^
-   |
-   = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
-note: return Err() instead of panicking
-  --> $DIR/panic_in_result_fn.rs:18:9
-   |
-LL |         unreachable!();
-   |         ^^^^^^^^^^^^^^
-
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
-  --> $DIR/panic_in_result_fn.rs:21:5
-   |
-LL | /     fn result_with_todo() -> Result<bool, String> // should emit lint
-LL | |     {
-LL | |         todo!("Finish this");
-LL | |     }
-   | |_____^
-   |
-   = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
-note: return Err() instead of panicking
-  --> $DIR/panic_in_result_fn.rs:23:9
-   |
-LL |         todo!("Finish this");
-   |         ^^^^^^^^^^^^^^^^^^^^
-
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
+error: used `panic!()` or assertion in a function that returns `Result`
   --> $DIR/panic_in_result_fn.rs:52:1
    |
 LL | / fn function_result_with_panic() -> Result<bool, String> // should emit lint
@@ -72,28 +24,12 @@ LL | |     panic!("error");
 LL | | }
    | |_^
    |
-   = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
+   = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
 note: return Err() instead of panicking
   --> $DIR/panic_in_result_fn.rs:54:5
    |
 LL |     panic!("error");
    |     ^^^^^^^^^^^^^^^
 
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
-  --> $DIR/panic_in_result_fn.rs:67:1
-   |
-LL | / fn main() -> Result<(), String> {
-LL | |     todo!("finish main method");
-LL | |     Ok(())
-LL | | }
-   | |_^
-   |
-   = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
-note: return Err() instead of panicking
-  --> $DIR/panic_in_result_fn.rs:68:5
-   |
-LL |     todo!("finish main method");
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to 6 previous errors
+error: aborting due to 2 previous errors
 
diff --git a/tests/ui/panic_in_result_fn_assertions.stderr b/tests/ui/panic_in_result_fn_assertions.stderr
index eb0aacbb6a4..0dd213a7eed 100644
--- a/tests/ui/panic_in_result_fn_assertions.stderr
+++ b/tests/ui/panic_in_result_fn_assertions.stderr
@@ -1,4 +1,4 @@
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
+error: used `panic!()` or assertion in a function that returns `Result`
   --> $DIR/panic_in_result_fn_assertions.rs:7:5
    |
 LL | /     fn result_with_assert_with_message(x: i32) -> Result<bool, String> // should emit lint
@@ -8,7 +8,7 @@ LL | |         Ok(true)
 LL | |     }
    | |_____^
    |
-   = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
+   = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
 note: return Err() instead of panicking
   --> $DIR/panic_in_result_fn_assertions.rs:9:9
    |
@@ -16,7 +16,7 @@ LL |         assert!(x == 5, "wrong argument");
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: `-D clippy::panic-in-result-fn` implied by `-D warnings`
 
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
+error: used `panic!()` or assertion in a function that returns `Result`
   --> $DIR/panic_in_result_fn_assertions.rs:13:5
    |
 LL | /     fn result_with_assert_eq(x: i32) -> Result<bool, String> // should emit lint
@@ -26,14 +26,14 @@ LL | |         Ok(true)
 LL | |     }
    | |_____^
    |
-   = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
+   = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
 note: return Err() instead of panicking
   --> $DIR/panic_in_result_fn_assertions.rs:15:9
    |
 LL |         assert_eq!(x, 5);
    |         ^^^^^^^^^^^^^^^^
 
-error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
+error: used `panic!()` or assertion in a function that returns `Result`
   --> $DIR/panic_in_result_fn_assertions.rs:19:5
    |
 LL | /     fn result_with_assert_ne(x: i32) -> Result<bool, String> // should emit lint
@@ -43,7 +43,7 @@ LL | |         Ok(true)
 LL | |     }
    | |_____^
    |
-   = help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
+   = help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
 note: return Err() instead of panicking
   --> $DIR/panic_in_result_fn_assertions.rs:21:9
    |
diff --git a/tests/ui/unnecessary_literal_unwrap.fixed b/tests/ui/unnecessary_literal_unwrap.fixed
index 092bf78feab..276cd800b89 100644
--- a/tests/ui/unnecessary_literal_unwrap.fixed
+++ b/tests/ui/unnecessary_literal_unwrap.fixed
@@ -78,6 +78,16 @@ fn unwrap_from_binding() {
     let _ = val.unwrap_or("");
 }
 
+fn unwrap_unchecked() {
+    let _ = 1;
+    let _ = unsafe { 1 + *(&1 as *const i32) }; // needs to keep the unsafe block
+    let _ = 1 + 1;
+    let _ = 1;
+    let _ = unsafe { 1 + *(&1 as *const i32) };
+    let _ = 1 + 1;
+    let _ = 123;
+}
+
 fn main() {
     unwrap_option_some();
     unwrap_option_none();
@@ -85,4 +95,5 @@ fn main() {
     unwrap_result_err();
     unwrap_methods_option();
     unwrap_methods_result();
+    unwrap_unchecked();
 }
diff --git a/tests/ui/unnecessary_literal_unwrap.rs b/tests/ui/unnecessary_literal_unwrap.rs
index b9df893d1d2..3065778d779 100644
--- a/tests/ui/unnecessary_literal_unwrap.rs
+++ b/tests/ui/unnecessary_literal_unwrap.rs
@@ -78,6 +78,16 @@ fn unwrap_from_binding() {
     let _ = val.unwrap_or("");
 }
 
+fn unwrap_unchecked() {
+    let _ = unsafe { Some(1).unwrap_unchecked() };
+    let _ = unsafe { Some(1).unwrap_unchecked() + *(&1 as *const i32) }; // needs to keep the unsafe block
+    let _ = unsafe { Some(1).unwrap_unchecked() } + 1;
+    let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() };
+    let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() + *(&1 as *const i32) };
+    let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() } + 1;
+    let _ = unsafe { Err::<(), i32>(123).unwrap_err_unchecked() };
+}
+
 fn main() {
     unwrap_option_some();
     unwrap_option_none();
@@ -85,4 +95,5 @@ fn main() {
     unwrap_result_err();
     unwrap_methods_option();
     unwrap_methods_result();
+    unwrap_unchecked();
 }
diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr
index 0c71ee05323..5823313b736 100644
--- a/tests/ui/unnecessary_literal_unwrap.stderr
+++ b/tests/ui/unnecessary_literal_unwrap.stderr
@@ -409,5 +409,89 @@ LL -     Ok::<_, ()>(1).unwrap_or_else(|_| 2);
 LL +     1;
    |
 
-error: aborting due to 36 previous errors
+error: used `unwrap_unchecked()` on `Some` value
+  --> $DIR/unnecessary_literal_unwrap.rs:82:22
+   |
+LL |     let _ = unsafe { Some(1).unwrap_unchecked() };
+   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: remove the `Some` and `unwrap_unchecked()`
+   |
+LL -     let _ = unsafe { Some(1).unwrap_unchecked() };
+LL +     let _ = 1;
+   |
+
+error: used `unwrap_unchecked()` on `Some` value
+  --> $DIR/unnecessary_literal_unwrap.rs:83:22
+   |
+LL |     let _ = unsafe { Some(1).unwrap_unchecked() + *(&1 as *const i32) }; // needs to keep the unsafe block
+   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: remove the `Some` and `unwrap_unchecked()`
+   |
+LL -     let _ = unsafe { Some(1).unwrap_unchecked() + *(&1 as *const i32) }; // needs to keep the unsafe block
+LL +     let _ = unsafe { 1 + *(&1 as *const i32) }; // needs to keep the unsafe block
+   |
+
+error: used `unwrap_unchecked()` on `Some` value
+  --> $DIR/unnecessary_literal_unwrap.rs:84:22
+   |
+LL |     let _ = unsafe { Some(1).unwrap_unchecked() } + 1;
+   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: remove the `Some` and `unwrap_unchecked()`
+   |
+LL -     let _ = unsafe { Some(1).unwrap_unchecked() } + 1;
+LL +     let _ = 1 + 1;
+   |
+
+error: used `unwrap_unchecked()` on `Ok` value
+  --> $DIR/unnecessary_literal_unwrap.rs:85:22
+   |
+LL |     let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() };
+   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: remove the `Ok` and `unwrap_unchecked()`
+   |
+LL -     let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() };
+LL +     let _ = 1;
+   |
+
+error: used `unwrap_unchecked()` on `Ok` value
+  --> $DIR/unnecessary_literal_unwrap.rs:86:22
+   |
+LL |     let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() + *(&1 as *const i32) };
+   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: remove the `Ok` and `unwrap_unchecked()`
+   |
+LL -     let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() + *(&1 as *const i32) };
+LL +     let _ = unsafe { 1 + *(&1 as *const i32) };
+   |
+
+error: used `unwrap_unchecked()` on `Ok` value
+  --> $DIR/unnecessary_literal_unwrap.rs:87:22
+   |
+LL |     let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() } + 1;
+   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: remove the `Ok` and `unwrap_unchecked()`
+   |
+LL -     let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() } + 1;
+LL +     let _ = 1 + 1;
+   |
+
+error: used `unwrap_err_unchecked()` on `Err` value
+  --> $DIR/unnecessary_literal_unwrap.rs:88:22
+   |
+LL |     let _ = unsafe { Err::<(), i32>(123).unwrap_err_unchecked() };
+   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: remove the `Err` and `unwrap_err_unchecked()`
+   |
+LL -     let _ = unsafe { Err::<(), i32>(123).unwrap_err_unchecked() };
+LL +     let _ = 123;
+   |
+
+error: aborting due to 43 previous errors