Skip to content

Commit 53dc1c1

Browse files
authored
Unrolled build for rust-lang#120360
Rollup merge of rust-lang#120360 - compiler-errors:afit-sized-lol, r=lcnr Don't fire `OPAQUE_HIDDEN_INFERRED_BOUND` on sized return of AFIT Conceptually, we should probably not fire `OPAQUE_HIDDEN_INFERRED_BOUND` for methods like: ``` trait Foo { async fn bar() -> Self; } ``` Even though we technically cannot prove that `Self: Sized`, which is one of the item bounds of the `Output` type in the `-> impl Future<Output = Sized>` from the async desugaring. This is somewhat justifiable along the same lines as how we allow regular methods to return `-> Self` even though `Self` isn't sized. Fixes rust-lang#113538 (side-note: some days i wonder if we should just remove the `OPAQUE_HIDDEN_INFERRED_BOUND` lint... it does make me sad that we have non-well-formed types in signatures, though.)
2 parents cdd4ff8 + 2aa7469 commit 53dc1c1

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_macros::{LintDiagnostic, Subdiagnostic};
44
use rustc_middle::ty::{
55
self, fold::BottomUpFolder, print::TraitPredPrintModifiersAndPath, Ty, TypeFoldable,
66
};
7-
use rustc_span::Span;
7+
use rustc_span::{symbol::kw, Span};
88
use rustc_trait_selection::traits;
99
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
1010

@@ -96,6 +96,17 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
9696
continue;
9797
}
9898

99+
// HACK: `async fn() -> Self` in traits is "ok"...
100+
// This is not really that great, but it's similar to why the `-> Self`
101+
// return type is well-formed in traits even when `Self` isn't sized.
102+
if let ty::Param(param_ty) = *proj_term.kind()
103+
&& param_ty.name == kw::SelfUpper
104+
&& matches!(opaque.origin, hir::OpaqueTyOrigin::AsyncFn(_))
105+
&& opaque.in_trait
106+
{
107+
continue;
108+
}
109+
99110
let proj_ty =
100111
Ty::new_projection(cx.tcx, proj.projection_ty.def_id, proj.projection_ty.args);
101112
// For every instance of the projection type in the bounds,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// check-pass
2+
// edition:2021
3+
4+
#![deny(opaque_hidden_inferred_bound)]
5+
6+
trait Repository /* : ?Sized */ {
7+
async fn new() -> Self;
8+
}
9+
10+
struct MyRepository {}
11+
12+
impl Repository for MyRepository {
13+
async fn new() -> Self {
14+
todo!()
15+
}
16+
}
17+
18+
fn main() {}

0 commit comments

Comments
 (0)