about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJason Newcomb <jsnewcomb@pm.me>2022-09-02 13:40:35 -0400
committerJason Newcomb <jsnewcomb@pm.me>2022-09-02 13:40:35 -0400
commitbd70ccf915482503b193d8d53e00dcdc6197676a (patch)
tree9118c109fea2b4d8f911ce092807be663255d02d
parent291f75e1fbf364561eabaa13c0ef6c6290122c65 (diff)
downloadrust-bd70ccf915482503b193d8d53e00dcdc6197676a.tar.gz
rust-bd70ccf915482503b193d8d53e00dcdc6197676a.zip
Don't use `hir_ty_to_ty` in `result_large_err` as it sometimes leaves late-bound lifetimes.
-rw-r--r--clippy_lints/src/functions/result.rs10
-rw-r--r--tests/ui/crashes/ice-9414.rs8
2 files changed, 13 insertions, 5 deletions
diff --git a/clippy_lints/src/functions/result.rs b/clippy_lints/src/functions/result.rs
index af520a493ed..9591405cb06 100644
--- a/clippy_lints/src/functions/result.rs
+++ b/clippy_lints/src/functions/result.rs
@@ -4,7 +4,6 @@ use rustc_lint::{LateContext, LintContext};
 use rustc_middle::lint::in_external_macro;
 use rustc_middle::ty::{self, Ty};
 use rustc_span::{sym, Span};
-use rustc_typeck::hir_ty_to_ty;
 
 use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
 use clippy_utils::trait_ref_of_method;
@@ -17,11 +16,12 @@ use super::{RESULT_LARGE_ERR, RESULT_UNIT_ERR};
 fn result_err_ty<'tcx>(
     cx: &LateContext<'tcx>,
     decl: &hir::FnDecl<'tcx>,
+    id: hir::def_id::LocalDefId,
     item_span: Span,
 ) -> Option<(&'tcx hir::Ty<'tcx>, Ty<'tcx>)> {
     if !in_external_macro(cx.sess(), item_span)
         && let hir::FnRetTy::Return(hir_ty) = decl.output
-        && let ty = hir_ty_to_ty(cx.tcx, hir_ty)
+        && let ty = cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).output())
         && is_type_diagnostic_item(cx, ty, sym::Result)
         && let ty::Adt(_, substs) = ty.kind()
     {
@@ -34,7 +34,7 @@ fn result_err_ty<'tcx>(
 
 pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, large_err_threshold: u64) {
     if let hir::ItemKind::Fn(ref sig, _generics, _) = item.kind
-        && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.span)
+        && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id, item.span)
     {
         if cx.access_levels.is_exported(item.def_id) {
             let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
@@ -47,7 +47,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, l
 pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::ImplItem<'tcx>, large_err_threshold: u64) {
     // Don't lint if method is a trait's implementation, we can't do anything about those
     if let hir::ImplItemKind::Fn(ref sig, _) = item.kind
-        && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.span)
+        && let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id, item.span)
         && trait_ref_of_method(cx, item.def_id).is_none()
     {
         if cx.access_levels.is_exported(item.def_id) {
@@ -61,7 +61,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::ImplItem
 pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::TraitItem<'tcx>, large_err_threshold: u64) {
     if let hir::TraitItemKind::Fn(ref sig, _) = item.kind {
         let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
-        if let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.span) {
+        if let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id, item.span) {
             if cx.access_levels.is_exported(item.def_id) {
                 check_result_unit_err(cx, err_ty, fn_header_span);
             }
diff --git a/tests/ui/crashes/ice-9414.rs b/tests/ui/crashes/ice-9414.rs
new file mode 100644
index 00000000000..02cf5d5c240
--- /dev/null
+++ b/tests/ui/crashes/ice-9414.rs
@@ -0,0 +1,8 @@
+#![warn(clippy::result_large_err)]
+
+trait T {}
+fn f(_: &u32) -> Result<(), *const (dyn '_ + T)> {
+    Ok(())
+}
+
+fn main() {}