Skip to content

Commit f1fac09

Browse files
committed
Auto merge of #156601 - JonathanBrouwer:rollup-mxAF8YC, r=<try>
Rollup of 7 pull requests try-job: dist-various-1 try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple try-job: x86_64-mingw-1 try-job: i686-msvc-2
2 parents 7c3c88f + 580430a commit f1fac09

47 files changed

Lines changed: 361 additions & 258 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/rustc_hir_analysis/src/delegation.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_middle::ty::{
1414
use rustc_span::{ErrorGuaranteed, Span, kw};
1515

1616
use crate::collect::ItemCtxt;
17+
use crate::errors::DelegationSelfTypeNotSpecified;
1718
use crate::hir_ty_lowering::HirTyLowerer;
1819

1920
type RemapTable = FxHashMap<u32, u32>;
@@ -284,6 +285,12 @@ fn get_delegation_self_ty_or_err(tcx: TyCtxt<'_>, delegation_id: LocalDefId) ->
284285
ctx.lower_ty(tcx.hir_node(id).expect_ty())
285286
})
286287
.unwrap_or_else(|| {
288+
// It is possible to attempt to get self type when it is used in signature
289+
// (i.e., `fn default() -> Self`), so emit error here in addition to possible
290+
// `mismatched types` error (see #156388).
291+
let err = DelegationSelfTypeNotSpecified { span: tcx.def_span(delegation_id) };
292+
tcx.dcx().emit_err(err);
293+
287294
Ty::new_error_with_message(
288295
tcx,
289296
tcx.def_span(delegation_id),

‎compiler/rustc_hir_analysis/src/errors.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,14 @@ pub(crate) struct UnsupportedDelegation<'a> {
16701670
pub callee_span: Span,
16711671
}
16721672

1673+
#[derive(Diagnostic)]
1674+
#[diag("delegation self type is not specified")]
1675+
#[help("consider explicitly specifying self type: `reuse </* Type */ as Trait>::function`")]
1676+
pub(crate) struct DelegationSelfTypeNotSpecified {
1677+
#[primary_span]
1678+
pub span: Span,
1679+
}
1680+
16731681
#[derive(Diagnostic)]
16741682
#[diag("method should be `async` or return a future, but it is synchronous")]
16751683
pub(crate) struct MethodShouldReturnFuture {

0 commit comments

Comments
 (0)