Skip to content

Commit 2446c32

Browse files
committed
propagate spans of registries down to hir and remove placeholder type errors
1 parent d252f6d commit 2446c32

File tree

19 files changed

+79
-41
lines changed

19 files changed

+79
-41
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_ast::*;
55
use rustc_errors::ErrorGuaranteed;
66
use rustc_hir::def::{DefKind, Res};
77
use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId};
8-
use rustc_hir::{self as hir, HirId, LifetimeSource, PredicateOrigin};
8+
use rustc_hir::{self as hir, DistributedSlice, HirId, LifetimeSource, PredicateOrigin};
99
use rustc_index::{IndexSlice, IndexVec};
1010
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
1111
use rustc_span::edit_distance::find_best_match_for_name;
@@ -148,6 +148,22 @@ impl<'hir> LoweringContext<'_, 'hir> {
148148
self.arena.alloc(item)
149149
}
150150

151+
fn lower_distributed_slice(
152+
&mut self,
153+
distributed_slice: &ast::DistributedSlice,
154+
) -> DistributedSlice<'hir> {
155+
match distributed_slice {
156+
ast::DistributedSlice::None => DistributedSlice::None,
157+
ast::DistributedSlice::Declaration(span) => {
158+
DistributedSlice::Declaration(self.lower_span(*span))
159+
}
160+
ast::DistributedSlice::Addition { declaration } => {
161+
// DistributedSlice::Addition(self.lower_qpath(id, qself, p, param_mode, allow_return_type_notation, itctx, modifiers))
162+
todo!()
163+
}
164+
}
165+
}
166+
151167
fn lower_item_kind(
152168
&mut self,
153169
span: Span,
@@ -181,14 +197,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
181197
let (ty, body_id) =
182198
self.lower_const_item(t, span, e.as_deref(), ImplTraitPosition::StaticTy);
183199
self.lower_define_opaque(hir_id, define_opaque);
184-
hir::ItemKind::Static(*m, ident, ty, body_id)
200+
hir::ItemKind::Static(
201+
*m,
202+
ident,
203+
ty,
204+
body_id,
205+
self.lower_distributed_slice(distributed_slice),
206+
)
185207
}
186208
ItemKind::Const(box ast::ConstItem {
187209
ident,
188210
generics,
189211
ty,
190212
expr,
191213
define_opaque,
214+
distributed_slice,
192215
..
193216
}) => {
194217
let ident = self.lower_ident(*ident);
@@ -201,7 +224,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
201224
},
202225
);
203226
self.lower_define_opaque(hir_id, &define_opaque);
204-
hir::ItemKind::Const(ident, generics, ty, body_id)
227+
hir::ItemKind::Const(
228+
ident,
229+
generics,
230+
ty,
231+
body_id,
232+
self.lower_distributed_slice(distributed_slice),
233+
)
205234
}
206235
ItemKind::Fn(box Fn {
207236
sig: FnSig { decl, header, span: fn_sig_span },

compiler/rustc_hir/src/hir.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4106,11 +4106,11 @@ impl<'hir> Item<'hir> {
41064106

41074107
expect_use, (&'hir UsePath<'hir>, UseKind), ItemKind::Use(p, uk), (p, *uk);
41084108

4109-
expect_static, (Mutability, Ident, &'hir Ty<'hir>, BodyId),
4110-
ItemKind::Static(mutbl, ident, ty, body), (*mutbl, *ident, ty, *body);
4109+
expect_static, (Mutability, Ident, &'hir Ty<'hir>, BodyId, DistributedSlice<'hir>),
4110+
ItemKind::Static(mutbl, ident, ty, body, distributed_slice), (*mutbl, *ident, *ty, *body, *distributed_slice);
41114111

4112-
expect_const, (Ident, &'hir Generics<'hir>, &'hir Ty<'hir>, BodyId),
4113-
ItemKind::Const(ident, generics, ty, body), (*ident, generics, ty, *body);
4112+
expect_const, (Ident, &'hir Generics<'hir>, &'hir Ty<'hir>, BodyId, DistributedSlice<'hir>),
4113+
ItemKind::Const(ident, generics, ty, body, distributed_slice), (*ident, generics, *ty, *body, *distributed_slice);
41144114

41154115
expect_fn, (Ident, &FnSig<'hir>, &'hir Generics<'hir>, BodyId),
41164116
ItemKind::Fn { ident, sig, generics, body, .. }, (*ident, sig, generics, *body);
@@ -4263,6 +4263,14 @@ impl FnHeader {
42634263
}
42644264
}
42654265

4266+
#[derive(Debug, Clone, Copy, HashStable_Generic, Default)]
4267+
pub enum DistributedSlice<'hir> {
4268+
#[default]
4269+
None,
4270+
Declaration(Span),
4271+
Addition(QPath<'hir>),
4272+
}
4273+
42664274
#[derive(Debug, Clone, Copy, HashStable_Generic)]
42674275
pub enum ItemKind<'hir> {
42684276
/// An `extern crate` item, with optional *original* crate name if the crate was renamed.
@@ -4278,9 +4286,9 @@ pub enum ItemKind<'hir> {
42784286
Use(&'hir UsePath<'hir>, UseKind),
42794287

42804288
/// A `static` item.
4281-
Static(Mutability, Ident, &'hir Ty<'hir>, BodyId),
4289+
Static(Mutability, Ident, &'hir Ty<'hir>, BodyId, DistributedSlice<'hir>),
42824290
/// A `const` item.
4283-
Const(Ident, &'hir Generics<'hir>, &'hir Ty<'hir>, BodyId),
4291+
Const(Ident, &'hir Generics<'hir>, &'hir Ty<'hir>, BodyId, DistributedSlice<'hir>),
42844292
/// A function declaration.
42854293
Fn {
42864294
sig: FnSig<'hir>,
@@ -4375,7 +4383,7 @@ impl ItemKind<'_> {
43754383
Some(match self {
43764384
ItemKind::Fn { generics, .. }
43774385
| ItemKind::TyAlias(_, generics, _)
4378-
| ItemKind::Const(_, generics, _, _)
4386+
| ItemKind::Const(_, generics, _, _, _)
43794387
| ItemKind::Enum(_, generics, _)
43804388
| ItemKind::Struct(_, generics, _)
43814389
| ItemKind::Union(_, generics, _)
@@ -4577,8 +4585,8 @@ impl<'hir> OwnerNode<'hir> {
45774585
match self {
45784586
OwnerNode::Item(Item {
45794587
kind:
4580-
ItemKind::Static(_, _, _, body)
4581-
| ItemKind::Const(_, _, _, body)
4588+
ItemKind::Static(_, _, _, body, _)
4589+
| ItemKind::Const(_, _, _, body, _)
45824590
| ItemKind::Fn { body, .. },
45834591
..
45844592
})
@@ -4803,8 +4811,8 @@ impl<'hir> Node<'hir> {
48034811
match self {
48044812
Node::Item(it) => match it.kind {
48054813
ItemKind::TyAlias(_, _, ty)
4806-
| ItemKind::Static(_, _, ty, _)
4807-
| ItemKind::Const(_, _, ty, _) => Some(ty),
4814+
| ItemKind::Static(_, _, ty, _, _)
4815+
| ItemKind::Const(_, _, ty, _, _) => Some(ty),
48084816
ItemKind::Impl(impl_item) => Some(&impl_item.self_ty),
48094817
_ => None,
48104818
},
@@ -4835,8 +4843,8 @@ impl<'hir> Node<'hir> {
48354843
Node::Item(Item {
48364844
owner_id,
48374845
kind:
4838-
ItemKind::Const(_, _, _, body)
4839-
| ItemKind::Static(.., body)
4846+
ItemKind::Const(_, _, _, body, _)
4847+
| ItemKind::Static(.., body, _)
48404848
| ItemKind::Fn { body, .. },
48414849
..
48424850
})

compiler/rustc_hir/src/intravisit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,12 +545,12 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
545545
UseKind::Glob | UseKind::ListStem => {}
546546
}
547547
}
548-
ItemKind::Static(_, ident, ref typ, body) => {
548+
ItemKind::Static(_, ident, ref typ, body, _ds) => {
549549
try_visit!(visitor.visit_ident(ident));
550550
try_visit!(visitor.visit_ty_unambig(typ));
551551
try_visit!(visitor.visit_nested_body(body));
552552
}
553-
ItemKind::Const(ident, ref generics, ref typ, body) => {
553+
ItemKind::Const(ident, ref generics, ref typ, body, _ds) => {
554554
try_visit!(visitor.visit_ident(ident));
555555
try_visit!(visitor.visit_generics(generics));
556556
try_visit!(visitor.visit_ty_unambig(typ));

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,10 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
297297
hir::ItemKind::Fn { ident, sig, .. } => {
298298
check_item_fn(tcx, def_id, ident, item.span, sig.decl)
299299
}
300-
hir::ItemKind::Static(_, _, ty, _) => {
300+
hir::ItemKind::Static(_, _, ty, _, _) => {
301301
check_static_item(tcx, def_id, ty.span, UnsizedHandling::Forbid)
302302
}
303-
hir::ItemKind::Const(_, _, ty, _) => check_const_item(tcx, def_id, ty.span, item.span),
303+
hir::ItemKind::Const(_, _, ty, _, _) => check_const_item(tcx, def_id, ty.span, item.span),
304304
hir::ItemKind::Struct(_, generics, _) => {
305305
let res = check_type_defn(tcx, item, false);
306306
check_variances_for_type_defn(tcx, item, generics);

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
762762
tcx.ensure_ok().predicates_of(def_id);
763763
}
764764

765-
hir::ItemKind::Static(_, _, ty, _) | hir::ItemKind::Const(_, _, ty, _) => {
765+
hir::ItemKind::Static(_, _, ty, _, _) | hir::ItemKind::Const(_, _, ty, _, _) => {
766766
tcx.ensure_ok().generics_of(def_id);
767767
tcx.ensure_ok().type_of(def_id);
768768
tcx.ensure_ok().predicates_of(def_id);

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
635635
intravisit::walk_item(self, item);
636636
}
637637
hir::ItemKind::TyAlias(_, generics, _)
638-
| hir::ItemKind::Const(_, generics, _, _)
638+
| hir::ItemKind::Const(_, generics, _, _, _)
639639
| hir::ItemKind::Enum(_, generics, _)
640640
| hir::ItemKind::Struct(_, generics, _)
641641
| hir::ItemKind::Union(_, generics, _)

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
206206
},
207207

208208
Node::Item(item) => match item.kind {
209-
ItemKind::Static(_, ident, ty, body_id) => {
209+
ItemKind::Static(_, ident, ty, body_id, distributed_slice) => {
210210
if ty.is_suggestable_infer_ty() {
211211
infer_placeholder_type(
212212
icx.lowerer(),
@@ -220,7 +220,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
220220
icx.lower_ty(ty)
221221
}
222222
}
223-
ItemKind::Const(ident, _, ty, body_id) => {
223+
ItemKind::Const(ident, _, ty, body_id, distributed_slice) => {
224224
if ty.is_suggestable_infer_ty() {
225225
infer_placeholder_type(
226226
icx.lowerer(),

compiler/rustc_hir_analysis/src/hir_wf_check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ fn diagnostic_hir_wf_check<'tcx>(
146146
},
147147
hir::Node::Item(item) => match item.kind {
148148
hir::ItemKind::TyAlias(_, _, ty)
149-
| hir::ItemKind::Static(_, _, ty, _)
150-
| hir::ItemKind::Const(_, _, ty, _) => vec![ty],
149+
| hir::ItemKind::Static(_, _, ty, _, _)
150+
| hir::ItemKind::Const(_, _, ty, _, _) => vec![ty],
151151
hir::ItemKind::Impl(impl_) => match &impl_.of_trait {
152152
Some(t) => t
153153
.path

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ impl<'a> State<'a> {
593593
self.end(ib);
594594
self.end(cb);
595595
}
596-
hir::ItemKind::Static(m, ident, ty, expr) => {
596+
hir::ItemKind::Static(m, ident, ty, expr, distributed_slice) => {
597597
let (cb, ib) = self.head("static");
598598
if m.is_mut() {
599599
self.word_space("mut");
@@ -609,7 +609,7 @@ impl<'a> State<'a> {
609609
self.word(";");
610610
self.end(cb);
611611
}
612-
hir::ItemKind::Const(ident, generics, ty, expr) => {
612+
hir::ItemKind::Const(ident, generics, ty, expr, distributed_slice) => {
613613
let (cb, ib) = self.head("const");
614614
self.print_ident(ident);
615615
self.print_generic_params(generics.params);

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
722722
)) => {
723723
if let Some(hir::Node::Item(hir::Item {
724724
kind:
725-
hir::ItemKind::Static(_, ident, ty, _)
726-
| hir::ItemKind::Const(ident, _, ty, _),
725+
hir::ItemKind::Static(_, ident, ty, _, _)
726+
| hir::ItemKind::Const(ident, _, ty, _, _),
727727
..
728728
})) = self.tcx.hir_get_if_local(*def_id)
729729
{

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14921492
match opt_def_id {
14931493
Some(def_id) => match self.tcx.hir_get_if_local(def_id) {
14941494
Some(hir::Node::Item(hir::Item {
1495-
kind: hir::ItemKind::Const(_, _, _, body_id),
1495+
kind: hir::ItemKind::Const(_, _, _, body_id, _),
14961496
..
14971497
})) => match self.tcx.hir_node(body_id.hir_id) {
14981498
hir::Node::Expr(expr) => {

compiler/rustc_lint/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,8 @@ impl<'tcx> LateContext<'tcx> {
932932
..
933933
}) => *init,
934934
hir::Node::Item(item) => match item.kind {
935-
hir::ItemKind::Const(.., body_id) | hir::ItemKind::Static(.., body_id) => {
935+
hir::ItemKind::Const(.., body_id, _)
936+
| hir::ItemKind::Static(.., body_id, _) => {
936937
Some(self.tcx.hir_body(body_id).value)
937938
}
938939
_ => None,

compiler/rustc_lint/src/non_local_def.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
183183
&& parent_opt_item_name != Some(kw::Underscore)
184184
&& let Some(parent) = parent.as_local()
185185
&& let Node::Item(item) = cx.tcx.hir_node_by_def_id(parent)
186-
&& let ItemKind::Const(ident, _, ty, _) = item.kind
186+
&& let ItemKind::Const(ident, _, ty, _, _) = item.kind
187187
&& let TyKind::Tup(&[]) = ty.kind
188188
{
189189
Some(ident.span)

compiler/rustc_lint/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,8 +1735,8 @@ impl ImproperCTypesDefinitions {
17351735
impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDefinitions {
17361736
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
17371737
match item.kind {
1738-
hir::ItemKind::Static(_, _, ty, _)
1739-
| hir::ItemKind::Const(_, _, ty, _)
1738+
hir::ItemKind::Static(_, _, ty, _, _)
1739+
| hir::ItemKind::Const(_, _, ty, _, _)
17401740
| hir::ItemKind::TyAlias(_, _, ty) => {
17411741
self.check_ty_maybe_containing_foreign_fnptr(
17421742
cx,

compiler/rustc_middle/src/hir/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ impl<'tcx> TyCtxt<'tcx> {
920920
}) => until_within(*outer_span, generics.where_clause_span),
921921
// Constants and Statics.
922922
Node::Item(Item {
923-
kind: ItemKind::Const(_, _, ty, _) | ItemKind::Static(_, _, ty, _),
923+
kind: ItemKind::Const(_, _, ty, _, _) | ItemKind::Static(_, _, ty, _, _),
924924
span: outer_span,
925925
..
926926
})

compiler/rustc_mir_build/src/builder/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ fn construct_const<'a, 'tcx>(
558558
// Figure out what primary body this item has.
559559
let (span, const_ty_span) = match tcx.hir_node(hir_id) {
560560
Node::Item(hir::Item {
561-
kind: hir::ItemKind::Static(_, _, ty, _) | hir::ItemKind::Const(_, _, ty, _),
561+
kind: hir::ItemKind::Static(_, _, ty, _, _) | hir::ItemKind::Const(_, _, ty, _, _),
562562
span,
563563
..
564564
})

compiler/rustc_passes/src/reachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<'tcx> ReachableContext<'tcx> {
204204
}
205205
}
206206

207-
hir::ItemKind::Const(_, _, _, init) => {
207+
hir::ItemKind::Const(_, _, _, init, distributed_slice) => {
208208
// Only things actually ending up in the final constant value are reachable
209209
// for codegen. Everything else is only needed during const-eval, so even if
210210
// const-eval happens in a downstream crate, all they need is

compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2026,7 +2026,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
20262026
}
20272027
LetVisitor { span }.visit_body(body).break_value()
20282028
}
2029-
hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(_, _, ty, _), .. }) => {
2029+
hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(_, _, ty, _, _), .. }) => {
20302030
Some(&ty.peel_refs().kind)
20312031
}
20322032
_ => None,

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
358358
| hir::ItemKind::Impl(hir::Impl { generics, .. })
359359
| hir::ItemKind::Fn { generics, .. }
360360
| hir::ItemKind::TyAlias(_, generics, _)
361-
| hir::ItemKind::Const(_, generics, _, _)
361+
| hir::ItemKind::Const(_, generics, _, _, _)
362362
| hir::ItemKind::TraitAlias(_, generics, _),
363363
..
364364
})
@@ -418,7 +418,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
418418
| hir::ItemKind::Impl(hir::Impl { generics, .. })
419419
| hir::ItemKind::Fn { generics, .. }
420420
| hir::ItemKind::TyAlias(_, generics, _)
421-
| hir::ItemKind::Const(_, generics, _, _)
421+
| hir::ItemKind::Const(_, generics, _, _, _)
422422
| hir::ItemKind::TraitAlias(_, generics, _),
423423
..
424424
}) if !param_ty => {

0 commit comments

Comments
 (0)