Skip to content

Commit c8ba3e1

Browse files
authored
use the correct ParamEnv when checking future's output type (#13863)
Fixes #13862 `missing_headers::check` is sometimes called from outside of a body (specifically, from `check_attributes`, where the LateContext's ParamEnv is not yet properly initialized for that item). Using that empty ParamEnv for trait solving things from within the body can then lead to various ICEs, like the linked issue where we have a const generic parameter `DMA_INST` without a `ConstArgHasType` bound in the ParamEnv so the const parameter has no type, which is normally not supposed to happen. We have the item's DefId so we can just get its ParamEnv/TypingEnv from there, and using that one for trait solving should be safe. changelog: none
2 parents aef4772 + 15ab2ff commit c8ba3e1

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

clippy_lints/src/doc/missing_headers.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{DocHeaders, MISSING_ERRORS_DOC, MISSING_PANICS_DOC, MISSING_SAFETY_DOC, UNNECESSARY_SAFETY_DOC};
22
use clippy_utils::diagnostics::{span_lint, span_lint_and_note};
3-
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
3+
use clippy_utils::ty::{implements_trait_with_env, is_type_diagnostic_item};
44
use clippy_utils::{is_doc_hidden, return_ty};
55
use rustc_hir::{BodyId, FnSig, OwnerId, Safety};
66
use rustc_lint::LateContext;
@@ -70,7 +70,14 @@ pub fn check(
7070
&& let typeck = cx.tcx.typeck_body(body_id)
7171
&& let body = cx.tcx.hir().body(body_id)
7272
&& let ret_ty = typeck.expr_ty(body.value)
73-
&& implements_trait(cx, ret_ty, future, &[])
73+
&& implements_trait_with_env(
74+
cx.tcx,
75+
ty::TypingEnv::non_body_analysis(cx.tcx, owner_id.def_id),
76+
ret_ty,
77+
future,
78+
Some(owner_id.def_id.to_def_id()),
79+
&[],
80+
)
7481
&& let ty::Coroutine(_, subs) = ret_ty.kind()
7582
&& is_type_diagnostic_item(cx, subs.as_coroutine().return_ty(), sym::Result)
7683
{

tests/ui/crashes/ice-13862.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![crate_type = "lib"]
2+
#![no_std]
3+
4+
use core::future::Future;
5+
use core::pin::Pin;
6+
use core::task::{Context, Poll};
7+
8+
pub struct S<const N: u8>;
9+
10+
impl<const N: u8> Future for S<N> {
11+
type Output = ();
12+
fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
13+
todo!()
14+
}
15+
}
16+
17+
pub fn f<const N: u8>() -> S<N> {
18+
S
19+
}

0 commit comments

Comments
 (0)