Rollup merge of #103609 - BoxyUwU:fix_impl_self_cycle, r=compiler-errors
Emit a nicer error on `impl Self {` currently it emits a "cycle detected error" but this PR makes it emit a more user friendly error specifically saying that `Self` is disallowed in that position. this is a pretty hacky fix so i dont expect this to be merged (I basically only made this PR because i wanted to see if CI passes) r? ``@compiler-errors``
This commit is contained in:
commit
ab0d9dfefe
8 changed files with 75 additions and 77 deletions
|
@ -319,7 +319,15 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
|||
}
|
||||
}
|
||||
ItemKind::TyAlias(self_ty, _) => icx.to_ty(self_ty),
|
||||
ItemKind::Impl(hir::Impl { self_ty, .. }) => icx.to_ty(*self_ty),
|
||||
ItemKind::Impl(hir::Impl { self_ty, .. }) => {
|
||||
match self_ty.find_self_aliases() {
|
||||
spans if spans.len() > 0 => {
|
||||
tcx.sess.emit_err(crate::errors::SelfInImplSelf { span: spans.into(), note: (), });
|
||||
tcx.ty_error()
|
||||
},
|
||||
_ => icx.to_ty(*self_ty),
|
||||
}
|
||||
},
|
||||
ItemKind::Fn(..) => {
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
|
||||
tcx.mk_fn_def(def_id.to_def_id(), substs)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Errors emitted by `rustc_hir_analysis`.
|
||||
|
||||
use rustc_errors::IntoDiagnostic;
|
||||
use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler};
|
||||
use rustc_errors::{IntoDiagnostic, MultiSpan};
|
||||
use rustc_macros::{Diagnostic, LintDiagnostic};
|
||||
use rustc_middle::ty::Ty;
|
||||
use rustc_span::{symbol::Ident, Span, Symbol};
|
||||
|
@ -270,3 +270,12 @@ pub struct ConstBoundForNonConstTrait {
|
|||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(hir_analysis_self_in_impl_self)]
|
||||
pub struct SelfInImplSelf {
|
||||
#[primary_span]
|
||||
pub span: MultiSpan,
|
||||
#[note]
|
||||
pub note: (),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue