Don't fire OPAQUE_HIDDEN_INFERRED_BOUND on sized return of AFIT

This commit is contained in:
Michael Goulet 2024-01-25 04:41:38 +00:00
parent cd6d8f2a04
commit 2aa746913b
2 changed files with 30 additions and 1 deletions

View File

@ -4,7 +4,7 @@
use rustc_middle::ty::{ use rustc_middle::ty::{
self, fold::BottomUpFolder, print::TraitPredPrintModifiersAndPath, Ty, TypeFoldable, self, fold::BottomUpFolder, print::TraitPredPrintModifiersAndPath, Ty, TypeFoldable,
}; };
use rustc_span::Span; use rustc_span::{symbol::kw, Span};
use rustc_trait_selection::traits; use rustc_trait_selection::traits;
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
@ -96,6 +96,17 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
continue; continue;
} }
// HACK: `async fn() -> Self` in traits is "ok"...
// This is not really that great, but it's similar to why the `-> Self`
// return type is well-formed in traits even when `Self` isn't sized.
if let ty::Param(param_ty) = *proj_term.kind()
&& param_ty.name == kw::SelfUpper
&& matches!(opaque.origin, hir::OpaqueTyOrigin::AsyncFn(_))
&& opaque.in_trait
{
continue;
}
let proj_ty = let proj_ty =
Ty::new_projection(cx.tcx, proj.projection_ty.def_id, proj.projection_ty.args); Ty::new_projection(cx.tcx, proj.projection_ty.def_id, proj.projection_ty.args);
// For every instance of the projection type in the bounds, // For every instance of the projection type in the bounds,

View File

@ -0,0 +1,18 @@
// check-pass
// edition:2021
#![deny(opaque_hidden_inferred_bound)]
trait Repository /* : ?Sized */ {
async fn new() -> Self;
}
struct MyRepository {}
impl Repository for MyRepository {
async fn new() -> Self {
todo!()
}
}
fn main() {}