Add span field for ConstArg
This commit is contained in:
parent
af76a2456d
commit
d572e6d415
20 changed files with 111 additions and 78 deletions
|
|
@ -312,7 +312,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
|
||||
fn visit_const_arg(&mut self, const_arg: &'hir ConstArg<'hir, AmbigArg>) {
|
||||
self.insert(
|
||||
const_arg.as_unambig_ct().span(),
|
||||
const_arg.as_unambig_ct().span,
|
||||
const_arg.hir_id,
|
||||
Node::ConstArg(const_arg.as_unambig_ct()),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -2285,8 +2285,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
// `ExprKind::Paren(ExprKind::Underscore)` and should also be lowered to `GenericArg::Infer`
|
||||
match c.value.peel_parens().kind {
|
||||
ExprKind::Underscore => {
|
||||
let ct_kind = hir::ConstArgKind::Infer(self.lower_span(c.value.span), ());
|
||||
self.arena.alloc(hir::ConstArg { hir_id: self.lower_node_id(c.id), kind: ct_kind })
|
||||
let ct_kind = hir::ConstArgKind::Infer(());
|
||||
self.arena.alloc(hir::ConstArg {
|
||||
hir_id: self.lower_node_id(c.id),
|
||||
kind: ct_kind,
|
||||
span: self.lower_span(c.value.span),
|
||||
})
|
||||
}
|
||||
_ => self.lower_anon_const_to_const_arg_and_alloc(c),
|
||||
}
|
||||
|
|
@ -2356,7 +2360,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
hir::ConstArgKind::Anon(ct)
|
||||
};
|
||||
|
||||
self.arena.alloc(hir::ConstArg { hir_id: self.next_id(), kind: ct_kind })
|
||||
self.arena.alloc(hir::ConstArg {
|
||||
hir_id: self.next_id(),
|
||||
kind: ct_kind,
|
||||
span: self.lower_span(span),
|
||||
})
|
||||
}
|
||||
|
||||
fn lower_const_item_rhs(
|
||||
|
|
@ -2373,9 +2381,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
let const_arg = ConstArg {
|
||||
hir_id: self.next_id(),
|
||||
kind: hir::ConstArgKind::Error(
|
||||
DUMMY_SP,
|
||||
self.dcx().span_delayed_bug(DUMMY_SP, "no block"),
|
||||
),
|
||||
span: DUMMY_SP,
|
||||
};
|
||||
hir::ConstItemRhs::TypeConst(self.arena.alloc(const_arg))
|
||||
}
|
||||
|
|
@ -2388,13 +2396,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
|
||||
#[instrument(level = "debug", skip(self), ret)]
|
||||
fn lower_expr_to_const_arg_direct(&mut self, expr: &Expr) -> hir::ConstArg<'hir> {
|
||||
let span = self.lower_span(expr.span);
|
||||
|
||||
let overly_complex_const = |this: &mut Self| {
|
||||
let e = this.dcx().struct_span_err(
|
||||
expr.span,
|
||||
"complex const arguments must be placed inside of a `const` block",
|
||||
);
|
||||
|
||||
ConstArg { hir_id: this.next_id(), kind: hir::ConstArgKind::Error(expr.span, e.emit()) }
|
||||
ConstArg { hir_id: this.next_id(), kind: hir::ConstArgKind::Error(e.emit()), span }
|
||||
};
|
||||
|
||||
match &expr.kind {
|
||||
|
|
@ -2425,6 +2435,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
ConstArg {
|
||||
hir_id: self.next_id(),
|
||||
kind: hir::ConstArgKind::TupleCall(qpath, lowered_args),
|
||||
span,
|
||||
}
|
||||
}
|
||||
ExprKind::Tup(exprs) => {
|
||||
|
|
@ -2442,7 +2453,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
&*self.arena.alloc(expr)
|
||||
}));
|
||||
|
||||
ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Tup(expr.span, exprs) }
|
||||
ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Tup(exprs), span }
|
||||
}
|
||||
ExprKind::Path(qself, path) => {
|
||||
let qpath = self.lower_qpath(
|
||||
|
|
@ -2456,7 +2467,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
None,
|
||||
);
|
||||
|
||||
ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Path(qpath) }
|
||||
ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Path(qpath), span }
|
||||
}
|
||||
ExprKind::Struct(se) => {
|
||||
let path = self.lower_qpath(
|
||||
|
|
@ -2497,11 +2508,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
})
|
||||
}));
|
||||
|
||||
ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Struct(path, fields) }
|
||||
ConstArg {
|
||||
hir_id: self.next_id(),
|
||||
kind: hir::ConstArgKind::Struct(path, fields),
|
||||
span,
|
||||
}
|
||||
}
|
||||
ExprKind::Underscore => ConstArg {
|
||||
hir_id: self.lower_node_id(expr.id),
|
||||
kind: hir::ConstArgKind::Infer(expr.span, ()),
|
||||
kind: hir::ConstArgKind::Infer(()),
|
||||
span,
|
||||
},
|
||||
ExprKind::Block(block, _) => {
|
||||
if let [stmt] = block.stmts.as_slice()
|
||||
|
|
@ -2546,7 +2562,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
return match anon.mgca_disambiguation {
|
||||
MgcaDisambiguation::AnonConst => {
|
||||
let lowered_anon = self.lower_anon_const_to_anon_const(anon);
|
||||
ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Anon(lowered_anon) }
|
||||
ConstArg {
|
||||
hir_id: self.next_id(),
|
||||
kind: hir::ConstArgKind::Anon(lowered_anon),
|
||||
span: lowered_anon.span,
|
||||
}
|
||||
}
|
||||
MgcaDisambiguation::Direct => self.lower_expr_to_const_arg_direct(&anon.value),
|
||||
};
|
||||
|
|
@ -2583,11 +2603,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
return ConstArg {
|
||||
hir_id: self.lower_node_id(anon.id),
|
||||
kind: hir::ConstArgKind::Path(qpath),
|
||||
span: self.lower_span(expr.span),
|
||||
};
|
||||
}
|
||||
|
||||
let lowered_anon = self.lower_anon_const_to_anon_const(anon);
|
||||
ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Anon(lowered_anon) }
|
||||
ConstArg {
|
||||
hir_id: self.next_id(),
|
||||
kind: hir::ConstArgKind::Anon(lowered_anon),
|
||||
span: self.lower_span(expr.span),
|
||||
}
|
||||
}
|
||||
|
||||
/// See [`hir::ConstArg`] for when to use this function vs
|
||||
|
|
|
|||
|
|
@ -513,6 +513,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
self.arena.alloc(hir::ConstArg {
|
||||
hir_id: self.next_id(),
|
||||
kind: hir::ConstArgKind::Anon(self.arena.alloc(anon_const)),
|
||||
span,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -557,6 +558,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
})
|
||||
});
|
||||
let hir_id = self.next_id();
|
||||
self.arena.alloc(hir::ConstArg { kind: hir::ConstArgKind::Anon(ct), hir_id })
|
||||
self.arena.alloc(hir::ConstArg { kind: hir::ConstArgKind::Anon(ct), hir_id, span })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -423,7 +423,7 @@ impl<'hir> ConstItemRhs<'hir> {
|
|||
pub fn span<'tcx>(&self, tcx: impl crate::intravisit::HirTyCtxt<'tcx>) -> Span {
|
||||
match self {
|
||||
ConstItemRhs::Body(body_id) => tcx.hir_body(*body_id).value.span,
|
||||
ConstItemRhs::TypeConst(ct_arg) => ct_arg.span(),
|
||||
ConstItemRhs::TypeConst(ct_arg) => ct_arg.span,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -447,6 +447,7 @@ pub struct ConstArg<'hir, Unambig = ()> {
|
|||
#[stable_hasher(ignore)]
|
||||
pub hir_id: HirId,
|
||||
pub kind: ConstArgKind<'hir, Unambig>,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
impl<'hir> ConstArg<'hir, AmbigArg> {
|
||||
|
|
@ -475,7 +476,7 @@ impl<'hir> ConstArg<'hir> {
|
|||
/// Functions accepting ambiguous consts will not handle the [`ConstArgKind::Infer`] variant, if
|
||||
/// infer consts are relevant to you then care should be taken to handle them separately.
|
||||
pub fn try_as_ambig_ct(&self) -> Option<&ConstArg<'hir, AmbigArg>> {
|
||||
if let ConstArgKind::Infer(_, ()) = self.kind {
|
||||
if let ConstArgKind::Infer(()) = self.kind {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
@ -494,25 +495,13 @@ impl<'hir, Unambig> ConstArg<'hir, Unambig> {
|
|||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn span(&self) -> Span {
|
||||
match self.kind {
|
||||
ConstArgKind::Tup(span, ..) => span,
|
||||
ConstArgKind::Struct(path, _) => path.span(),
|
||||
ConstArgKind::Path(path) => path.span(),
|
||||
ConstArgKind::TupleCall(path, _) => path.span(),
|
||||
ConstArgKind::Anon(anon) => anon.span,
|
||||
ConstArgKind::Error(span, _) => span,
|
||||
ConstArgKind::Infer(span, _) => span,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// See [`ConstArg`].
|
||||
#[derive(Clone, Copy, Debug, HashStable_Generic)]
|
||||
#[repr(u8, C)]
|
||||
pub enum ConstArgKind<'hir, Unambig = ()> {
|
||||
Tup(Span, &'hir [&'hir ConstArg<'hir, Unambig>]),
|
||||
Tup(&'hir [&'hir ConstArg<'hir, Unambig>]),
|
||||
/// **Note:** Currently this is only used for bare const params
|
||||
/// (`N` where `fn foo<const N: usize>(...)`),
|
||||
/// not paths to any const (`N` where `const N: usize = ...`).
|
||||
|
|
@ -525,10 +514,10 @@ pub enum ConstArgKind<'hir, Unambig = ()> {
|
|||
/// Tuple constructor variant
|
||||
TupleCall(QPath<'hir>, &'hir [&'hir ConstArg<'hir>]),
|
||||
/// Error const
|
||||
Error(Span, ErrorGuaranteed),
|
||||
Error(ErrorGuaranteed),
|
||||
/// This variant is not always used to represent inference consts, sometimes
|
||||
/// [`GenericArg::Infer`] is used instead.
|
||||
Infer(Span, Unambig),
|
||||
Infer(Unambig),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, HashStable_Generic)]
|
||||
|
|
@ -574,7 +563,7 @@ impl GenericArg<'_> {
|
|||
match self {
|
||||
GenericArg::Lifetime(l) => l.ident.span,
|
||||
GenericArg::Type(t) => t.span,
|
||||
GenericArg::Const(c) => c.span(),
|
||||
GenericArg::Const(c) => c.span,
|
||||
GenericArg::Infer(i) => i.span,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,16 @@ define_tests! {
|
|||
cast_ptr TyKind Ptr { 0: MutTy { ty: &Ty { span: DUMMY_SP, hir_id: HirId::INVALID, kind: TyKind::Never }, mutbl: Mutability::Not }}
|
||||
cast_array TyKind Array {
|
||||
0: &Ty { span: DUMMY_SP, hir_id: HirId::INVALID, kind: TyKind::Never },
|
||||
1: &ConstArg { hir_id: HirId::INVALID, kind: ConstArgKind::Anon(&AnonConst {
|
||||
1: &ConstArg {
|
||||
hir_id: HirId::INVALID,
|
||||
def_id: LocalDefId { local_def_index: DefIndex::ZERO },
|
||||
body: BodyId { hir_id: HirId::INVALID },
|
||||
kind: ConstArgKind::Anon(&AnonConst {
|
||||
hir_id: HirId::INVALID,
|
||||
def_id: LocalDefId { local_def_index: DefIndex::ZERO },
|
||||
body: BodyId { hir_id: HirId::INVALID },
|
||||
span: DUMMY_SP,
|
||||
}),
|
||||
span: DUMMY_SP,
|
||||
})}
|
||||
},
|
||||
}
|
||||
|
||||
cast_anon ConstArgKind Anon {
|
||||
|
|
|
|||
|
|
@ -1068,8 +1068,8 @@ pub fn walk_unambig_const_arg<'v, V: Visitor<'v>>(
|
|||
match const_arg.try_as_ambig_ct() {
|
||||
Some(ambig_ct) => visitor.visit_const_arg(ambig_ct),
|
||||
None => {
|
||||
let ConstArg { hir_id, kind: _ } = const_arg;
|
||||
visitor.visit_infer(*hir_id, const_arg.span(), InferKind::Const(const_arg))
|
||||
let ConstArg { hir_id, kind: _, span } = const_arg;
|
||||
visitor.visit_infer(*hir_id, *span, InferKind::Const(const_arg))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1078,10 +1078,10 @@ pub fn walk_const_arg<'v, V: Visitor<'v>>(
|
|||
visitor: &mut V,
|
||||
const_arg: &'v ConstArg<'v, AmbigArg>,
|
||||
) -> V::Result {
|
||||
let ConstArg { hir_id, kind } = const_arg;
|
||||
let ConstArg { hir_id, kind, span: _ } = const_arg;
|
||||
try_visit!(visitor.visit_id(*hir_id));
|
||||
match kind {
|
||||
ConstArgKind::Tup(_, exprs) => {
|
||||
ConstArgKind::Tup(exprs) => {
|
||||
walk_list!(visitor, visit_const_arg, *exprs);
|
||||
V::Result::output()
|
||||
}
|
||||
|
|
@ -1103,7 +1103,7 @@ pub fn walk_const_arg<'v, V: Visitor<'v>>(
|
|||
}
|
||||
ConstArgKind::Path(qpath) => visitor.visit_qpath(qpath, *hir_id, qpath.span()),
|
||||
ConstArgKind::Anon(anon) => visitor.visit_anon_const(*anon),
|
||||
ConstArgKind::Error(_, _) => V::Result::output(), // errors and spans are not important
|
||||
ConstArgKind::Error(_) => V::Result::output(), // errors and spans are not important
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -381,7 +381,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
{
|
||||
let span = match term {
|
||||
hir::Term::Ty(ty) => ty.span,
|
||||
hir::Term::Const(ct) => ct.span(),
|
||||
hir::Term::Const(ct) => ct.span,
|
||||
};
|
||||
(span, Some(ident.span), assoc_item.as_tag(), assoc_tag)
|
||||
} else {
|
||||
|
|
@ -1466,7 +1466,7 @@ pub fn prohibit_assoc_item_constraint(
|
|||
hir::AssocItemConstraintKind::Equality { term: hir::Term::Const(c) },
|
||||
GenericParamDefKind::Const { .. },
|
||||
) => {
|
||||
suggest_direct_use(&mut err, c.span());
|
||||
suggest_direct_use(&mut err, c.span);
|
||||
}
|
||||
(hir::AssocItemConstraintKind::Bound { bounds }, _) => {
|
||||
// Suggest `impl<T: Bound> Trait<T> for Foo` when finding
|
||||
|
|
|
|||
|
|
@ -2331,7 +2331,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
&& (anon_const_type.has_free_regions() || anon_const_type.has_erased_regions())
|
||||
{
|
||||
let e = self.dcx().span_err(
|
||||
const_arg.span(),
|
||||
const_arg.span,
|
||||
"anonymous constants with lifetimes in their type are not yet supported",
|
||||
);
|
||||
tcx.feed_anon_const_type(anon.def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, e)));
|
||||
|
|
@ -2342,7 +2342,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
// variables otherwise we will ICE.
|
||||
if anon_const_type.has_non_region_infer() {
|
||||
let e = self.dcx().span_err(
|
||||
const_arg.span(),
|
||||
const_arg.span,
|
||||
"anonymous constants with inferred types are not yet supported",
|
||||
);
|
||||
tcx.feed_anon_const_type(anon.def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, e)));
|
||||
|
|
@ -2352,7 +2352,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
// give the anon const any of the generics from the parent.
|
||||
if anon_const_type.has_non_region_param() {
|
||||
let e = self.dcx().span_err(
|
||||
const_arg.span(),
|
||||
const_arg.span,
|
||||
"anonymous constants referencing generics are not yet supported",
|
||||
);
|
||||
tcx.feed_anon_const_type(anon.def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, e)));
|
||||
|
|
@ -2364,7 +2364,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
|
||||
let hir_id = const_arg.hir_id;
|
||||
match const_arg.kind {
|
||||
hir::ConstArgKind::Tup(span, exprs) => self.lower_const_arg_tup(exprs, feed, span),
|
||||
hir::ConstArgKind::Tup(exprs) => self.lower_const_arg_tup(exprs, feed, const_arg.span),
|
||||
hir::ConstArgKind::Path(hir::QPath::Resolved(maybe_qself, path)) => {
|
||||
debug!(?maybe_qself, ?path);
|
||||
let opt_self_ty = maybe_qself.as_ref().map(|qself| self.lower_ty(qself));
|
||||
|
|
@ -2378,19 +2378,19 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
hir_self_ty,
|
||||
segment,
|
||||
hir_id,
|
||||
const_arg.span(),
|
||||
const_arg.span,
|
||||
)
|
||||
.unwrap_or_else(|guar| Const::new_error(tcx, guar))
|
||||
}
|
||||
hir::ConstArgKind::Struct(qpath, inits) => {
|
||||
self.lower_const_arg_struct(hir_id, qpath, inits, const_arg.span())
|
||||
self.lower_const_arg_struct(hir_id, qpath, inits, const_arg.span)
|
||||
}
|
||||
hir::ConstArgKind::TupleCall(qpath, args) => {
|
||||
self.lower_const_arg_tuple_call(hir_id, qpath, args, const_arg.span())
|
||||
self.lower_const_arg_tuple_call(hir_id, qpath, args, const_arg.span)
|
||||
}
|
||||
hir::ConstArgKind::Anon(anon) => self.lower_const_arg_anon(anon),
|
||||
hir::ConstArgKind::Infer(span, ()) => self.ct_infer(None, span),
|
||||
hir::ConstArgKind::Error(_, e) => ty::Const::new_error(tcx, e),
|
||||
hir::ConstArgKind::Infer(()) => self.ct_infer(None, const_arg.span),
|
||||
hir::ConstArgKind::Error(e) => ty::Const::new_error(tcx, e),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1141,13 +1141,13 @@ impl<'a> State<'a> {
|
|||
|
||||
fn print_const_arg(&mut self, const_arg: &hir::ConstArg<'_>) {
|
||||
match &const_arg.kind {
|
||||
ConstArgKind::Tup(_, exprs) => {
|
||||
ConstArgKind::Tup(exprs) => {
|
||||
self.popen();
|
||||
self.commasep_cmnt(
|
||||
Inconsistent,
|
||||
exprs,
|
||||
|s, arg| s.print_const_arg(arg),
|
||||
|arg| arg.span(),
|
||||
|arg| arg.span,
|
||||
);
|
||||
self.pclose();
|
||||
}
|
||||
|
|
@ -1155,7 +1155,7 @@ impl<'a> State<'a> {
|
|||
ConstArgKind::TupleCall(qpath, args) => self.print_const_ctor(qpath, args),
|
||||
ConstArgKind::Path(qpath) => self.print_qpath(qpath, true),
|
||||
ConstArgKind::Anon(anon) => self.print_anon_const(anon),
|
||||
ConstArgKind::Error(_, _) => self.word("/*ERROR*/"),
|
||||
ConstArgKind::Error(_) => self.word("/*ERROR*/"),
|
||||
ConstArgKind::Infer(..) => self.word("_"),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1705,7 +1705,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
return;
|
||||
};
|
||||
if let hir::TyKind::Array(_, ct) = ty.peel_refs().kind {
|
||||
let span = ct.span();
|
||||
let span = ct.span;
|
||||
self.dcx().try_steal_modify_and_emit_err(
|
||||
span,
|
||||
StashKey::UnderscoreForArrayLengths,
|
||||
|
|
@ -1746,7 +1746,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
expr: &'tcx hir::Expr<'tcx>,
|
||||
) -> Ty<'tcx> {
|
||||
let tcx = self.tcx;
|
||||
let count_span = count.span();
|
||||
let count_span = count.span;
|
||||
let count = self.try_structurally_resolve_const(
|
||||
count_span,
|
||||
self.normalize(count_span, self.lower_const_arg(count, FeedConstTy::No)),
|
||||
|
|
|
|||
|
|
@ -74,12 +74,9 @@ fn gen_args(cx: &LateContext<'_>, segment: &PathSegment<'_>) -> String {
|
|||
GenericArg::Type(ty) => {
|
||||
cx.tcx.sess.source_map().span_to_snippet(ty.span).unwrap_or_else(|_| "_".into())
|
||||
}
|
||||
GenericArg::Const(c) => cx
|
||||
.tcx
|
||||
.sess
|
||||
.source_map()
|
||||
.span_to_snippet(c.span())
|
||||
.unwrap_or_else(|_| "_".into()),
|
||||
GenericArg::Const(c) => {
|
||||
cx.tcx.sess.source_map().span_to_snippet(c.span).unwrap_or_else(|_| "_".into())
|
||||
}
|
||||
GenericArg::Infer(_) => String::from("_"),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
|
|
|||
|
|
@ -1003,7 +1003,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
Node::Field(field) => field.span,
|
||||
Node::AnonConst(constant) => constant.span,
|
||||
Node::ConstBlock(constant) => self.hir_body(constant.body).value.span,
|
||||
Node::ConstArg(const_arg) => const_arg.span(),
|
||||
Node::ConstArg(const_arg) => const_arg.span,
|
||||
Node::Expr(expr) => expr.span,
|
||||
Node::ExprField(field) => field.span,
|
||||
Node::ConstArgExprField(field) => field.span,
|
||||
|
|
|
|||
|
|
@ -1879,7 +1879,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
&& let Some(length_val) = sz.found.try_to_target_usize(self.tcx)
|
||||
{
|
||||
Some(TypeErrorAdditionalDiags::ConsiderSpecifyingLength {
|
||||
span: length_arg.span(),
|
||||
span: length_arg.span,
|
||||
length: length_val,
|
||||
})
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ fn might_be_expanded<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> bool {
|
|||
let ExprKind::Repeat(_, len_ct) = expr.kind else {
|
||||
return false;
|
||||
};
|
||||
!expr.span.contains(len_ct.span())
|
||||
!expr.span.contains(len_ct.span)
|
||||
}
|
||||
|
||||
expr.span.from_expansion() || is_from_proc_macro(cx, expr) || repeat_expr_might_be_expanded(expr)
|
||||
|
|
|
|||
|
|
@ -321,6 +321,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
|
|||
},
|
||||
ConstArgKind::Struct(..) => chain!(self, "let ConstArgKind::Struct(..) = {const_arg}.kind"),
|
||||
ConstArgKind::TupleCall(..) => chain!(self, "let ConstArgKind::TupleCall(..) = {const_arg}.kind"),
|
||||
ConstArgKind::Tup(..) => chain!(self, "let ConstArgKind::Tup(..) = {const_arg}.kind"),
|
||||
ConstArgKind::Infer(..) => chain!(self, "let ConstArgKind::Infer(..) = {const_arg}.kind"),
|
||||
ConstArgKind::Error(..) => chain!(self, "let ConstArgKind::Error(..) = {const_arg}.kind"),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1140,7 +1140,7 @@ pub fn const_item_rhs_to_expr<'tcx>(tcx: TyCtxt<'tcx>, ct_rhs: ConstItemRhs<'tcx
|
|||
ConstItemRhs::Body(body_id) => Some(tcx.hir_body(body_id).value),
|
||||
ConstItemRhs::TypeConst(const_arg) => match const_arg.kind {
|
||||
ConstArgKind::Anon(anon) => Some(tcx.hir_body(anon.body).value),
|
||||
ConstArgKind::Struct(..) | ConstArgKind::TupleCall(..) | ConstArgKind::Path(_) | ConstArgKind::Error(..) | ConstArgKind::Infer(..) => {
|
||||
ConstArgKind::Struct(..) | ConstArgKind::TupleCall(..) | ConstArgKind::Tup(..) | ConstArgKind::Path(_) | ConstArgKind::Error(..) | ConstArgKind::Infer(..) => {
|
||||
None
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -661,6 +661,10 @@ impl HirEqInterExpr<'_, '_, '_> {
|
|||
}
|
||||
|
||||
fn eq_const_arg(&mut self, left: &ConstArg<'_>, right: &ConstArg<'_>) -> bool {
|
||||
if !self.check_ctxt(left.span.ctxt(), right.span.ctxt()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
match (&left.kind, &right.kind) {
|
||||
(ConstArgKind::Path(l_p), ConstArgKind::Path(r_p)) => self.eq_qpath(l_p, r_p),
|
||||
(ConstArgKind::Anon(l_an), ConstArgKind::Anon(r_an)) => self.eq_body(l_an.body, r_an.body),
|
||||
|
|
@ -679,11 +683,18 @@ impl HirEqInterExpr<'_, '_, '_> {
|
|||
.zip(*args_b)
|
||||
.all(|(arg_a, arg_b)| self.eq_const_arg(arg_a, arg_b))
|
||||
}
|
||||
(ConstArgKind::Tup(args_a), ConstArgKind::Tup(args_b)) => {
|
||||
args_a
|
||||
.iter()
|
||||
.zip(*args_b)
|
||||
.all(|(arg_a, arg_b)| self.eq_const_arg(arg_a, arg_b))
|
||||
}
|
||||
// Use explicit match for now since ConstArg is undergoing flux.
|
||||
(
|
||||
ConstArgKind::Path(..)
|
||||
| ConstArgKind::Anon(..)
|
||||
| ConstArgKind::TupleCall(..)
|
||||
| ConstArgKind::Tup(..)
|
||||
| ConstArgKind::Infer(..)
|
||||
| ConstArgKind::Struct(..)
|
||||
| ConstArgKind::Error(..),
|
||||
|
|
@ -1560,6 +1571,11 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
|||
self.hash_const_arg(arg);
|
||||
}
|
||||
},
|
||||
ConstArgKind::Tup(args) => {
|
||||
for arg in *args {
|
||||
self.hash_const_arg(arg);
|
||||
}
|
||||
},
|
||||
ConstArgKind::Infer(..) | ConstArgKind::Error(..) => {},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ error: struct expression with missing field initialiser for `field`
|
|||
--> $DIR/adt_expr_erroneuous_inits.rs:16:17
|
||||
|
|
||||
LL | accepts::<{ Foo::<u8> { }}>();
|
||||
| ^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: struct expression with multiple initialisers for `field`
|
||||
--> $DIR/adt_expr_erroneuous_inits.rs:18:49
|
||||
|
|
@ -35,13 +35,13 @@ error: struct expression with invalid base path
|
|||
--> $DIR/adt_expr_erroneuous_inits.rs:20:17
|
||||
|
|
||||
LL | accepts::<{ Fooo::<u8> { field: const { 1 } }}>();
|
||||
| ^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: struct expression with invalid base path
|
||||
--> $DIR/adt_expr_erroneuous_inits.rs:23:17
|
||||
|
|
||||
LL | accepts::<{ NonStruct { }}>();
|
||||
| ^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ error: the constant `Option::<u32>::Some(N)` is not of type `Foo`
|
|||
--> $DIR/printing_valtrees_supports_non_values.rs:18:13
|
||||
|
|
||||
LL | foo::<{ Option::Some::<u32> { 0: N } }>;
|
||||
| ^^^^^^^^^^^^^^^^^^^ expected `Foo`, found `Option<u32>`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Foo`, found `Option<u32>`
|
||||
|
|
||||
note: required by a const generic parameter in `foo`
|
||||
--> $DIR/printing_valtrees_supports_non_values.rs:15:8
|
||||
|
|
@ -14,7 +14,7 @@ error: the constant `Option::<u32>::Some(<T as Trait>::ASSOC)` is not of type `F
|
|||
--> $DIR/printing_valtrees_supports_non_values.rs:23:13
|
||||
|
|
||||
LL | foo::<{ Option::Some::<u32> { 0: <T as Trait>::ASSOC } }>();
|
||||
| ^^^^^^^^^^^^^^^^^^^ expected `Foo`, found `Option<u32>`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Foo`, found `Option<u32>`
|
||||
|
|
||||
note: required by a const generic parameter in `foo`
|
||||
--> $DIR/printing_valtrees_supports_non_values.rs:15:8
|
||||
|
|
@ -37,7 +37,7 @@ error: the constant `Option::<u32>::Some(_)` is not of type `Foo`
|
|||
--> $DIR/printing_valtrees_supports_non_values.rs:30:12
|
||||
|
|
||||
LL | foo::<{Option::Some::<u32>{0: <T as Trait>::ASSOC}}>();
|
||||
| ^^^^^^^^^^^^^^^^^^^ expected `Foo`, found `Option<u32>`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Foo`, found `Option<u32>`
|
||||
|
|
||||
note: required by a const generic parameter in `foo`
|
||||
--> $DIR/printing_valtrees_supports_non_values.rs:15:8
|
||||
|
|
@ -49,7 +49,7 @@ error: the constant `Option::<u32>::Some(_)` is not of type `Foo`
|
|||
--> $DIR/printing_valtrees_supports_non_values.rs:36:13
|
||||
|
|
||||
LL | foo::<{ Option::Some::<u32> { 0: _ } }>();
|
||||
| ^^^^^^^^^^^^^^^^^^^ expected `Foo`, found `Option<u32>`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Foo`, found `Option<u32>`
|
||||
|
|
||||
note: required by a const generic parameter in `foo`
|
||||
--> $DIR/printing_valtrees_supports_non_values.rs:15:8
|
||||
|
|
|
|||
|
|
@ -13,31 +13,31 @@ error: tuple constructor has 2 arguments but 1 were provided
|
|||
--> $DIR/tuple_ctor_erroneous.rs:23:23
|
||||
|
|
||||
LL | accepts_point::<{ Point(N) }>();
|
||||
| ^^^^^
|
||||
| ^^^^^^^^
|
||||
|
||||
error: tuple constructor has 2 arguments but 3 were provided
|
||||
--> $DIR/tuple_ctor_erroneous.rs:26:23
|
||||
|
|
||||
LL | accepts_point::<{ Point(N, N, N) }>();
|
||||
| ^^^^^
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: tuple constructor with invalid base path
|
||||
--> $DIR/tuple_ctor_erroneous.rs:29:23
|
||||
|
|
||||
LL | accepts_point::<{ UnresolvedIdent(N, N) }>();
|
||||
| ^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: tuple constructor with invalid base path
|
||||
--> $DIR/tuple_ctor_erroneous.rs:33:23
|
||||
|
|
||||
LL | accepts_point::<{ non_ctor(N, N) }>();
|
||||
| ^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: tuple constructor with invalid base path
|
||||
--> $DIR/tuple_ctor_erroneous.rs:36:23
|
||||
|
|
||||
LL | accepts_point::<{ CONST_ITEM(N, N) }>();
|
||||
| ^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: the constant `Point` is not of type `Point`
|
||||
--> $DIR/tuple_ctor_erroneous.rs:39:23
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue