Skip to content

Commit 958a9cf

Browse files
committed
Auto merge of #9417 - Jarcho:ice_9414, r=Alexendoo
Don't use `hir_ty_to_ty` in `result_large_err` fixes #9414 This occurs starting with 2022-09-01. I checked that this does fix the ICE on rust-lang/rust@9353538. Not sure which pr caused the late-bound region to leak through `hir_ty_to_ty`. changelog: None
2 parents 334be18 + bd70ccf commit 958a9cf

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

clippy_lints/src/functions/result.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_lint::{LateContext, LintContext};
44
use rustc_middle::lint::in_external_macro;
55
use rustc_middle::ty::{self, Ty};
66
use rustc_span::{sym, Span};
7-
use rustc_typeck::hir_ty_to_ty;
87

98
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
109
use clippy_utils::trait_ref_of_method;
@@ -17,11 +16,12 @@ use super::{RESULT_LARGE_ERR, RESULT_UNIT_ERR};
1716
fn result_err_ty<'tcx>(
1817
cx: &LateContext<'tcx>,
1918
decl: &hir::FnDecl<'tcx>,
19+
id: hir::def_id::LocalDefId,
2020
item_span: Span,
2121
) -> Option<(&'tcx hir::Ty<'tcx>, Ty<'tcx>)> {
2222
if !in_external_macro(cx.sess(), item_span)
2323
&& let hir::FnRetTy::Return(hir_ty) = decl.output
24-
&& let ty = hir_ty_to_ty(cx.tcx, hir_ty)
24+
&& let ty = cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).output())
2525
&& is_type_diagnostic_item(cx, ty, sym::Result)
2626
&& let ty::Adt(_, substs) = ty.kind()
2727
{
@@ -34,7 +34,7 @@ fn result_err_ty<'tcx>(
3434

3535
pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::Item<'tcx>, large_err_threshold: u64) {
3636
if let hir::ItemKind::Fn(ref sig, _generics, _) = item.kind
37-
&& let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.span)
37+
&& let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id, item.span)
3838
{
3939
if cx.access_levels.is_exported(item.def_id) {
4040
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
4747
pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::ImplItem<'tcx>, large_err_threshold: u64) {
4848
// Don't lint if method is a trait's implementation, we can't do anything about those
4949
if let hir::ImplItemKind::Fn(ref sig, _) = item.kind
50-
&& let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.span)
50+
&& let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id, item.span)
5151
&& trait_ref_of_method(cx, item.def_id).is_none()
5252
{
5353
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
6161
pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &hir::TraitItem<'tcx>, large_err_threshold: u64) {
6262
if let hir::TraitItemKind::Fn(ref sig, _) = item.kind {
6363
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
64-
if let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.span) {
64+
if let Some((hir_ty, err_ty)) = result_err_ty(cx, sig.decl, item.def_id, item.span) {
6565
if cx.access_levels.is_exported(item.def_id) {
6666
check_result_unit_err(cx, err_ty, fn_header_span);
6767
}

tests/ui/crashes/ice-9414.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![warn(clippy::result_large_err)]
2+
3+
trait T {}
4+
fn f(_: &u32) -> Result<(), *const (dyn '_ + T)> {
5+
Ok(())
6+
}
7+
8+
fn main() {}

0 commit comments

Comments
 (0)