Start handling pattern types at the HIR -> Ty conversion boundary
This commit is contained in:
parent
c4efc25bfa
commit
1d6cd8daf0
6 changed files with 36 additions and 7 deletions
|
@ -7,6 +7,8 @@ use rustc_errors::{
|
|||
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
||||
use rustc_middle::ty::Ty;
|
||||
use rustc_span::{symbol::Ident, Span, Symbol};
|
||||
mod pattern_types;
|
||||
pub use pattern_types::*;
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(hir_analysis_ambiguous_assoc_item)]
|
||||
|
|
9
compiler/rustc_hir_analysis/src/errors/pattern_types.rs
Normal file
9
compiler/rustc_hir_analysis/src/errors/pattern_types.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
use rustc_macros::Diagnostic;
|
||||
use rustc_span::Span;
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(hir_analysis_pattern_type_wild_pat)]
|
||||
pub struct WildPatTy {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
|
@ -21,7 +21,7 @@ mod object_safety;
|
|||
|
||||
use crate::bounds::Bounds;
|
||||
use crate::collect::HirPlaceholderCollector;
|
||||
use crate::errors::AmbiguousLifetimeBound;
|
||||
use crate::errors::{AmbiguousLifetimeBound, WildPatTy};
|
||||
use crate::hir_ty_lowering::errors::{prohibit_assoc_item_binding, GenericsArgsErrExtend};
|
||||
use crate::hir_ty_lowering::generics::{check_generic_arg_count, lower_generic_args};
|
||||
use crate::middle::resolve_bound_vars as rbv;
|
||||
|
@ -2195,7 +2195,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
// handled specially and will not descend into this routine.
|
||||
self.ty_infer(None, hir_ty.span)
|
||||
}
|
||||
hir::TyKind::Pat(..) => span_bug!(hir_ty.span, "{hir_ty:#?}"),
|
||||
hir::TyKind::Pat(_ty, pat) => match pat.kind {
|
||||
hir::PatKind::Wild => {
|
||||
let err = tcx.dcx().emit_err(WildPatTy { span: pat.span });
|
||||
Ty::new_error(tcx, err)
|
||||
}
|
||||
hir::PatKind::Range(_, _, _) => Ty::new_misc_error(tcx),
|
||||
hir::PatKind::Err(e) => Ty::new_error(tcx, e),
|
||||
_ => span_bug!(pat.span, "unsupported pattern for pattern type: {pat:#?}"),
|
||||
},
|
||||
hir::TyKind::Err(guar) => Ty::new_error(tcx, *guar),
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue