1
Fork 0

Add inferred args to typeck

This commit is contained in:
kadmin 2021-04-26 18:19:23 +00:00
parent 417b098cfc
commit 3605675bb1
18 changed files with 132 additions and 52 deletions

View file

@ -18,23 +18,6 @@ use rustc_session::lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS;
use rustc_span::{symbol::kw, MultiSpan, Span};
use smallvec::SmallVec;
/*
pub fn generic_arg_for_infer_arg<'tcx>(tcx: TyCtxt<'tcx>, did: LocalDefId) -> GenericArg<'tcx> {
todo!()
let hir_id = tcx.hir().local_def_id_to_hir_id(did);
let arg = match tcx.hir().get(hir_id) {
hir::Node::GenericParam(hir::GenericParam {
kind: hir::GenericParamKind::Const { ty: _, default: _ },
..
}) => todo!(),
_ => bug!("Expected GenericParam for generic_arg_for_infer_arg"),
};
assert!(!matches!(arg, GenericArg::Infer(_)));
arg
}
*/
impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// Report an error that a generic argument did not match the generic parameter that was
/// expected.

View file

@ -479,6 +479,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
param.def_id,
Some(arg.id()),
arg.span(),
None,
|_, _| {
// Default generic parameters may not be marked
// with stability attributes, i.e. when the

View file

@ -581,6 +581,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
pub fn node_ty_opt(&self, id: hir::HirId) -> Option<Ty<'tcx>> {
match self.typeck_results.borrow().node_types().get(id) {
Some(&t) => Some(t),
None if self.is_tainted_by_errors() => Some(self.tcx.ty_error()),
None => None,
}
}
/// Registers an obligation for checking later, during regionck, that `arg` is well-formed.
pub fn register_wf_obligation(
&self,

View file

@ -331,6 +331,15 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
let ty = self.resolve(ty, &hir_ty.span);
self.write_ty_to_typeck_results(hir_ty.hir_id, ty);
}
fn visit_infer(&mut self, inf: &'tcx hir::InferArg) {
intravisit::walk_inf(self, inf);
// Ignore cases where the inference is a const.
if let Some(ty) = self.fcx.node_ty_opt(inf.hir_id) {
let ty = self.resolve(ty, &inf.span);
self.write_ty_to_typeck_results(inf.hir_id, ty);
}
}
}
impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {

View file

@ -133,6 +133,7 @@ impl<'v> Visitor<'v> for PlaceholderHirTyCollector {
match generic_arg {
hir::GenericArg::Infer(inf) => {
self.0.push(inf.span);
intravisit::walk_inf(self, inf);
}
hir::GenericArg::Type(t) => self.visit_ty(t),
_ => {}