Rollup merge of #120428 - petrochenkov:somehir2, r=compiler-errors
hir: Two preparatory changes for #120206 cc https://github.com/rust-lang/rust/pull/120206 r? ```@compiler-errors```
This commit is contained in:
commit
eaa100204e
@ -153,7 +153,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
}
|
||||
ExprKind::Let(pat, scrutinee, span, is_recovered) => {
|
||||
hir::ExprKind::Let(self.arena.alloc(hir::Let {
|
||||
hir_id: self.next_id(),
|
||||
span: self.lower_span(*span),
|
||||
pat: self.lower_pat(pat),
|
||||
ty: None,
|
||||
|
@ -2305,7 +2305,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
match c.value.kind {
|
||||
ExprKind::Underscore => {
|
||||
if self.tcx.features().generic_arg_infer {
|
||||
hir::ArrayLen::Infer(self.lower_node_id(c.id), self.lower_span(c.value.span))
|
||||
hir::ArrayLen::Infer(hir::InferArg {
|
||||
hir_id: self.lower_node_id(c.id),
|
||||
span: self.lower_span(c.value.span),
|
||||
})
|
||||
} else {
|
||||
feature_err(
|
||||
&self.tcx.sess,
|
||||
|
@ -1273,7 +1273,6 @@ pub struct Arm<'hir> {
|
||||
/// desugaring to if-let. Only let-else supports the type annotation at present.
|
||||
#[derive(Debug, Clone, Copy, HashStable_Generic)]
|
||||
pub struct Let<'hir> {
|
||||
pub hir_id: HirId,
|
||||
pub span: Span,
|
||||
pub pat: &'hir Pat<'hir>,
|
||||
pub ty: Option<&'hir Ty<'hir>>,
|
||||
@ -1532,14 +1531,16 @@ pub type Lit = Spanned<LitKind>;
|
||||
|
||||
#[derive(Copy, Clone, Debug, HashStable_Generic)]
|
||||
pub enum ArrayLen {
|
||||
Infer(HirId, Span),
|
||||
Infer(InferArg),
|
||||
Body(AnonConst),
|
||||
}
|
||||
|
||||
impl ArrayLen {
|
||||
pub fn hir_id(&self) -> HirId {
|
||||
match self {
|
||||
&ArrayLen::Infer(hir_id, _) | &ArrayLen::Body(AnonConst { hir_id, .. }) => hir_id,
|
||||
ArrayLen::Infer(InferArg { hir_id, .. }) | ArrayLen::Body(AnonConst { hir_id, .. }) => {
|
||||
*hir_id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2424,7 +2425,7 @@ impl<'hir> Ty<'hir> {
|
||||
TyKind::Infer => true,
|
||||
TyKind::Slice(ty) => ty.is_suggestable_infer_ty(),
|
||||
TyKind::Array(ty, length) => {
|
||||
ty.is_suggestable_infer_ty() || matches!(length, ArrayLen::Infer(_, _))
|
||||
ty.is_suggestable_infer_ty() || matches!(length, ArrayLen::Infer(..))
|
||||
}
|
||||
TyKind::Tup(tys) => tys.iter().any(Self::is_suggestable_infer_ty),
|
||||
TyKind::Ptr(mut_ty) | TyKind::Ref(_, mut_ty) => mut_ty.ty.is_suggestable_infer_ty(),
|
||||
|
@ -341,9 +341,6 @@ pub trait Visitor<'v>: Sized {
|
||||
fn visit_expr(&mut self, ex: &'v Expr<'v>) {
|
||||
walk_expr(self, ex)
|
||||
}
|
||||
fn visit_let_expr(&mut self, lex: &'v Let<'v>) {
|
||||
walk_let_expr(self, lex)
|
||||
}
|
||||
fn visit_expr_field(&mut self, field: &'v ExprField<'v>) {
|
||||
walk_expr_field(self, field)
|
||||
}
|
||||
@ -672,7 +669,7 @@ pub fn walk_pat_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v PatField<'
|
||||
|
||||
pub fn walk_array_len<'v, V: Visitor<'v>>(visitor: &mut V, len: &'v ArrayLen) {
|
||||
match len {
|
||||
&ArrayLen::Infer(hir_id, _span) => visitor.visit_id(hir_id),
|
||||
ArrayLen::Infer(InferArg { hir_id, span: _ }) => visitor.visit_id(*hir_id),
|
||||
ArrayLen::Body(c) => visitor.visit_anon_const(c),
|
||||
}
|
||||
}
|
||||
@ -729,7 +726,12 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
|
||||
ExprKind::DropTemps(ref subexpression) => {
|
||||
visitor.visit_expr(subexpression);
|
||||
}
|
||||
ExprKind::Let(ref let_expr) => visitor.visit_let_expr(let_expr),
|
||||
ExprKind::Let(Let { span: _, pat, ty, init, is_recovered: _ }) => {
|
||||
// match the visit order in walk_local
|
||||
visitor.visit_expr(init);
|
||||
visitor.visit_pat(pat);
|
||||
walk_list!(visitor, visit_ty, ty);
|
||||
}
|
||||
ExprKind::If(ref cond, ref then, ref else_opt) => {
|
||||
visitor.visit_expr(cond);
|
||||
visitor.visit_expr(then);
|
||||
@ -806,14 +808,6 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_let_expr<'v, V: Visitor<'v>>(visitor: &mut V, let_expr: &'v Let<'v>) {
|
||||
// match the visit order in walk_local
|
||||
visitor.visit_expr(let_expr.init);
|
||||
visitor.visit_id(let_expr.hir_id);
|
||||
visitor.visit_pat(let_expr.pat);
|
||||
walk_list!(visitor, visit_ty, let_expr.ty);
|
||||
}
|
||||
|
||||
pub fn walk_expr_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v ExprField<'v>) {
|
||||
visitor.visit_id(field.hir_id);
|
||||
visitor.visit_ident(field.ident);
|
||||
|
@ -2529,7 +2529,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
}
|
||||
hir::TyKind::Array(ty, length) => {
|
||||
let length = match length {
|
||||
&hir::ArrayLen::Infer(_, span) => self.ct_infer(tcx.types.usize, None, span),
|
||||
hir::ArrayLen::Infer(inf) => self.ct_infer(tcx.types.usize, None, inf.span),
|
||||
hir::ArrayLen::Body(constant) => {
|
||||
ty::Const::from_anon_const(tcx, constant.def_id)
|
||||
}
|
||||
|
@ -146,8 +146,8 @@ impl<'v> Visitor<'v> for HirPlaceholderCollector {
|
||||
}
|
||||
}
|
||||
fn visit_array_length(&mut self, length: &'v hir::ArrayLen) {
|
||||
if let &hir::ArrayLen::Infer(_, span) = length {
|
||||
self.0.push(span);
|
||||
if let hir::ArrayLen::Infer(inf) = length {
|
||||
self.0.push(inf.span);
|
||||
}
|
||||
intravisit::walk_array_len(self, length)
|
||||
}
|
||||
|
@ -956,7 +956,7 @@ impl<'a> State<'a> {
|
||||
|
||||
fn print_array_length(&mut self, len: &hir::ArrayLen) {
|
||||
match len {
|
||||
hir::ArrayLen::Infer(_, _) => self.word("_"),
|
||||
hir::ArrayLen::Infer(..) => self.word("_"),
|
||||
hir::ArrayLen::Body(ct) => self.print_anon_const(ct),
|
||||
}
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
ExprKind::Ret(ref expr_opt) => self.check_expr_return(expr_opt.as_deref(), expr),
|
||||
ExprKind::Become(call) => self.check_expr_become(call, expr),
|
||||
ExprKind::Let(let_expr) => self.check_expr_let(let_expr),
|
||||
ExprKind::Let(let_expr) => self.check_expr_let(let_expr, expr.hir_id),
|
||||
ExprKind::Loop(body, _, source, _) => {
|
||||
self.check_expr_loop(body, source, expected, expr)
|
||||
}
|
||||
@ -1259,12 +1259,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn check_expr_let(&self, let_expr: &'tcx hir::Let<'tcx>) -> Ty<'tcx> {
|
||||
pub(super) fn check_expr_let(&self, let_expr: &'tcx hir::Let<'tcx>, hir_id: HirId) -> Ty<'tcx> {
|
||||
// for let statements, this is done in check_stmt
|
||||
let init = let_expr.init;
|
||||
self.warn_if_unreachable(init.hir_id, init.span, "block in `let` expression");
|
||||
// otherwise check exactly as a let statement
|
||||
self.check_decl(let_expr.into());
|
||||
self.check_decl((let_expr, hir_id).into());
|
||||
// but return a bool, for this is a boolean expression
|
||||
if let Some(error_guaranteed) = let_expr.is_recovered {
|
||||
self.set_tainted_by_errors(error_guaranteed);
|
||||
|
@ -405,7 +405,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub fn array_length_to_const(&self, length: &hir::ArrayLen) -> ty::Const<'tcx> {
|
||||
match length {
|
||||
&hir::ArrayLen::Infer(_, span) => self.ct_infer(self.tcx.types.usize, None, span),
|
||||
hir::ArrayLen::Infer(inf) => self.ct_infer(self.tcx.types.usize, None, inf.span),
|
||||
hir::ArrayLen::Body(anon_const) => {
|
||||
let span = self.tcx.def_span(anon_const.def_id);
|
||||
let c = ty::Const::from_anon_const(self.tcx, anon_const.def_id);
|
||||
|
@ -48,9 +48,9 @@ impl<'a> From<&'a hir::Local<'a>> for Declaration<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a hir::Let<'a>> for Declaration<'a> {
|
||||
fn from(let_expr: &'a hir::Let<'a>) -> Self {
|
||||
let hir::Let { hir_id, pat, ty, span, init, is_recovered: _ } = *let_expr;
|
||||
impl<'a> From<(&'a hir::Let<'a>, hir::HirId)> for Declaration<'a> {
|
||||
fn from((let_expr, hir_id): (&'a hir::Let<'a>, hir::HirId)) -> Self {
|
||||
let hir::Let { pat, ty, span, init, is_recovered: _ } = *let_expr;
|
||||
Declaration { hir_id, pat, ty, span, init: Some(init), origin: DeclOrigin::LetExpr }
|
||||
}
|
||||
}
|
||||
@ -125,9 +125,11 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
|
||||
intravisit::walk_local(self, local)
|
||||
}
|
||||
|
||||
fn visit_let_expr(&mut self, let_expr: &'tcx hir::Let<'tcx>) {
|
||||
self.declare(let_expr.into());
|
||||
intravisit::walk_let_expr(self, let_expr);
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
|
||||
if let hir::ExprKind::Let(let_expr) = expr.kind {
|
||||
self.declare((let_expr, expr.hir_id).into());
|
||||
}
|
||||
intravisit::walk_expr(self, expr)
|
||||
}
|
||||
|
||||
fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
|
||||
|
@ -328,11 +328,6 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
|
||||
hir_visit::walk_expr(self, e)
|
||||
}
|
||||
|
||||
fn visit_let_expr(&mut self, lex: &'v hir::Let<'v>) {
|
||||
self.record("Let", Id::Node(lex.hir_id), lex);
|
||||
hir_visit::walk_let_expr(self, lex)
|
||||
}
|
||||
|
||||
fn visit_expr_field(&mut self, f: &'v hir::ExprField<'v>) {
|
||||
self.record("ExprField", Id::Node(f.hir_id), f);
|
||||
hir_visit::walk_expr_field(self, f)
|
||||
|
@ -1836,7 +1836,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
|
||||
TyKind::Slice(ty) => Slice(Box::new(clean_ty(ty, cx))),
|
||||
TyKind::Array(ty, ref length) => {
|
||||
let length = match length {
|
||||
hir::ArrayLen::Infer(_, _) => "_".to_string(),
|
||||
hir::ArrayLen::Infer(..) => "_".to_string(),
|
||||
hir::ArrayLen::Body(anon_const) => {
|
||||
// NOTE(min_const_generics): We can't use `const_eval_poly` for constants
|
||||
// as we currently do not supply the parent generics to anonymous constants
|
||||
|
Loading…
x
Reference in New Issue
Block a user