Skip to content

Commit 540a50d

Browse files
committed
Auto merge of rust-lang#109941 - compiler-errors:rollup-5lsst2u, r=compiler-errors
Rollup of 9 pull requests Successful merges: - rust-lang#109723 (Pull some tuple variant fields out into their own struct) - rust-lang#109838 (Fix `non_exhaustive_omitted_patterns` lint span) - rust-lang#109901 (Enforce VarDebugInfo::Place in MIR validation.) - rust-lang#109913 (Doc-comment `IndexVec::from_elem` and use it in a few more places) - rust-lang#109914 (Emit feature error for parenthesized generics in associated type bounds) - rust-lang#109919 (rustdoc: escape GAT args in more cases) - rust-lang#109937 (Don't collect return-position impl traits for documentation) - rust-lang#109938 (Move a const-prop-lint specific hack from mir interpret to const-prop-lint and make it fallible) - rust-lang#109940 (Add regression test for rust-lang#93911) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents be8e5ba + 678d7c5 commit 540a50d

File tree

44 files changed

+533
-235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+533
-235
lines changed

Diff for: compiler/rustc_ast/src/ast.rs

+28-10
Original file line numberDiff line numberDiff line change
@@ -2890,6 +2890,20 @@ pub struct Fn {
28902890
pub body: Option<P<Block>>,
28912891
}
28922892

2893+
#[derive(Clone, Encodable, Decodable, Debug)]
2894+
pub struct StaticItem {
2895+
pub ty: P<Ty>,
2896+
pub mutability: Mutability,
2897+
pub expr: Option<P<Expr>>,
2898+
}
2899+
2900+
#[derive(Clone, Encodable, Decodable, Debug)]
2901+
pub struct ConstItem {
2902+
pub defaultness: Defaultness,
2903+
pub ty: P<Ty>,
2904+
pub expr: Option<P<Expr>>,
2905+
}
2906+
28932907
#[derive(Clone, Encodable, Decodable, Debug)]
28942908
pub enum ItemKind {
28952909
/// An `extern crate` item, with the optional *original* crate name if the crate was renamed.
@@ -2903,11 +2917,11 @@ pub enum ItemKind {
29032917
/// A static item (`static`).
29042918
///
29052919
/// E.g., `static FOO: i32 = 42;` or `static FOO: &'static str = "bar";`.
2906-
Static(P<Ty>, Mutability, Option<P<Expr>>),
2920+
Static(Box<StaticItem>),
29072921
/// A constant item (`const`).
29082922
///
29092923
/// E.g., `const FOO: i32 = 42;`.
2910-
Const(Defaultness, P<Ty>, Option<P<Expr>>),
2924+
Const(Box<ConstItem>),
29112925
/// A function declaration (`fn`).
29122926
///
29132927
/// E.g., `fn foo(bar: usize) -> usize { .. }`.
@@ -3023,7 +3037,7 @@ pub type AssocItem = Item<AssocItemKind>;
30233037
pub enum AssocItemKind {
30243038
/// An associated constant, `const $ident: $ty $def?;` where `def ::= "=" $expr? ;`.
30253039
/// If `def` is parsed, then the constant is provided, and otherwise required.
3026-
Const(Defaultness, P<Ty>, Option<P<Expr>>),
3040+
Const(Box<ConstItem>),
30273041
/// An associated function.
30283042
Fn(Box<Fn>),
30293043
/// An associated type.
@@ -3035,7 +3049,7 @@ pub enum AssocItemKind {
30353049
impl AssocItemKind {
30363050
pub fn defaultness(&self) -> Defaultness {
30373051
match *self {
3038-
Self::Const(defaultness, ..)
3052+
Self::Const(box ConstItem { defaultness, .. })
30393053
| Self::Fn(box Fn { defaultness, .. })
30403054
| Self::Type(box TyAlias { defaultness, .. }) => defaultness,
30413055
Self::MacCall(..) => Defaultness::Final,
@@ -3046,7 +3060,7 @@ impl AssocItemKind {
30463060
impl From<AssocItemKind> for ItemKind {
30473061
fn from(assoc_item_kind: AssocItemKind) -> ItemKind {
30483062
match assoc_item_kind {
3049-
AssocItemKind::Const(a, b, c) => ItemKind::Const(a, b, c),
3063+
AssocItemKind::Const(item) => ItemKind::Const(item),
30503064
AssocItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind),
30513065
AssocItemKind::Type(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind),
30523066
AssocItemKind::MacCall(a) => ItemKind::MacCall(a),
@@ -3059,7 +3073,7 @@ impl TryFrom<ItemKind> for AssocItemKind {
30593073

30603074
fn try_from(item_kind: ItemKind) -> Result<AssocItemKind, ItemKind> {
30613075
Ok(match item_kind {
3062-
ItemKind::Const(a, b, c) => AssocItemKind::Const(a, b, c),
3076+
ItemKind::Const(item) => AssocItemKind::Const(item),
30633077
ItemKind::Fn(fn_kind) => AssocItemKind::Fn(fn_kind),
30643078
ItemKind::TyAlias(ty_kind) => AssocItemKind::Type(ty_kind),
30653079
ItemKind::MacCall(a) => AssocItemKind::MacCall(a),
@@ -3084,7 +3098,9 @@ pub enum ForeignItemKind {
30843098
impl From<ForeignItemKind> for ItemKind {
30853099
fn from(foreign_item_kind: ForeignItemKind) -> ItemKind {
30863100
match foreign_item_kind {
3087-
ForeignItemKind::Static(a, b, c) => ItemKind::Static(a, b, c),
3101+
ForeignItemKind::Static(a, b, c) => {
3102+
ItemKind::Static(StaticItem { ty: a, mutability: b, expr: c }.into())
3103+
}
30883104
ForeignItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind),
30893105
ForeignItemKind::TyAlias(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind),
30903106
ForeignItemKind::MacCall(a) => ItemKind::MacCall(a),
@@ -3097,7 +3113,9 @@ impl TryFrom<ItemKind> for ForeignItemKind {
30973113

30983114
fn try_from(item_kind: ItemKind) -> Result<ForeignItemKind, ItemKind> {
30993115
Ok(match item_kind {
3100-
ItemKind::Static(a, b, c) => ForeignItemKind::Static(a, b, c),
3116+
ItemKind::Static(box StaticItem { ty: a, mutability: b, expr: c }) => {
3117+
ForeignItemKind::Static(a, b, c)
3118+
}
31013119
ItemKind::Fn(fn_kind) => ForeignItemKind::Fn(fn_kind),
31023120
ItemKind::TyAlias(ty_alias_kind) => ForeignItemKind::TyAlias(ty_alias_kind),
31033121
ItemKind::MacCall(a) => ForeignItemKind::MacCall(a),
@@ -3114,8 +3132,8 @@ mod size_asserts {
31143132
use super::*;
31153133
use rustc_data_structures::static_assert_size;
31163134
// tidy-alphabetical-start
3117-
static_assert_size!(AssocItem, 104);
3118-
static_assert_size!(AssocItemKind, 32);
3135+
static_assert_size!(AssocItem, 88);
3136+
static_assert_size!(AssocItemKind, 16);
31193137
static_assert_size!(Attribute, 32);
31203138
static_assert_size!(Block, 32);
31213139
static_assert_size!(Expr, 72);

Diff for: compiler/rustc_ast/src/mut_visit.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
//! a `MutVisitor` renaming item names in a module will miss all of those
88
//! that are created by the expansion of a macro.
99
10-
use crate::ast::*;
1110
use crate::ptr::P;
1211
use crate::token::{self, Token};
1312
use crate::tokenstream::*;
13+
use crate::{ast::*, StaticItem};
1414

1515
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
1616
use rustc_data_structures::sync::Lrc;
@@ -1030,14 +1030,12 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
10301030
match kind {
10311031
ItemKind::ExternCrate(_orig_name) => {}
10321032
ItemKind::Use(use_tree) => vis.visit_use_tree(use_tree),
1033-
ItemKind::Static(ty, _, expr) => {
1033+
ItemKind::Static(box StaticItem { ty, mutability: _, expr }) => {
10341034
vis.visit_ty(ty);
10351035
visit_opt(expr, |expr| vis.visit_expr(expr));
10361036
}
1037-
ItemKind::Const(defaultness, ty, expr) => {
1038-
visit_defaultness(defaultness, vis);
1039-
vis.visit_ty(ty);
1040-
visit_opt(expr, |expr| vis.visit_expr(expr));
1037+
ItemKind::Const(item) => {
1038+
visit_const_item(item, vis);
10411039
}
10421040
ItemKind::Fn(box Fn { defaultness, generics, sig, body }) => {
10431041
visit_defaultness(defaultness, vis);
@@ -1120,10 +1118,8 @@ pub fn noop_flat_map_assoc_item<T: MutVisitor>(
11201118
visitor.visit_vis(vis);
11211119
visit_attrs(attrs, visitor);
11221120
match kind {
1123-
AssocItemKind::Const(defaultness, ty, expr) => {
1124-
visit_defaultness(defaultness, visitor);
1125-
visitor.visit_ty(ty);
1126-
visit_opt(expr, |expr| visitor.visit_expr(expr));
1121+
AssocItemKind::Const(item) => {
1122+
visit_const_item(item, visitor);
11271123
}
11281124
AssocItemKind::Fn(box Fn { defaultness, generics, sig, body }) => {
11291125
visit_defaultness(defaultness, visitor);
@@ -1153,6 +1149,15 @@ pub fn noop_flat_map_assoc_item<T: MutVisitor>(
11531149
smallvec![item]
11541150
}
11551151

1152+
fn visit_const_item<T: MutVisitor>(
1153+
ConstItem { defaultness, ty, expr }: &mut ConstItem,
1154+
visitor: &mut T,
1155+
) {
1156+
visit_defaultness(defaultness, visitor);
1157+
visitor.visit_ty(ty);
1158+
visit_opt(expr, |expr| visitor.visit_expr(expr));
1159+
}
1160+
11561161
pub fn noop_visit_fn_header<T: MutVisitor>(header: &mut FnHeader, vis: &mut T) {
11571162
let FnHeader { unsafety, asyncness, constness, ext: _ } = header;
11581163
visit_constness(constness, vis);

Diff for: compiler/rustc_ast/src/visit.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! instance, a walker looking for item names in a module will miss all of
1414
//! those that are created by the expansion of a macro.
1515
16-
use crate::ast::*;
16+
use crate::{ast::*, StaticItem};
1717

1818
use rustc_span::symbol::Ident;
1919
use rustc_span::Span;
@@ -305,8 +305,9 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
305305
match &item.kind {
306306
ItemKind::ExternCrate(_) => {}
307307
ItemKind::Use(use_tree) => visitor.visit_use_tree(use_tree, item.id, false),
308-
ItemKind::Static(typ, _, expr) | ItemKind::Const(_, typ, expr) => {
309-
visitor.visit_ty(typ);
308+
ItemKind::Static(box StaticItem { ty, mutability: _, expr })
309+
| ItemKind::Const(box ConstItem { ty, expr, .. }) => {
310+
visitor.visit_ty(ty);
310311
walk_list!(visitor, visit_expr, expr);
311312
}
312313
ItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
@@ -674,7 +675,7 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem,
674675
visitor.visit_ident(ident);
675676
walk_list!(visitor, visit_attribute, attrs);
676677
match kind {
677-
AssocItemKind::Const(_, ty, expr) => {
678+
AssocItemKind::Const(box ConstItem { ty, expr, .. }) => {
678679
visitor.visit_ty(ty);
679680
walk_list!(visitor, visit_expr, expr);
680681
}

Diff for: compiler/rustc_ast_lowering/src/item.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
229229

230230
self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs)
231231
}
232-
ItemKind::Static(t, m, e) => {
232+
ItemKind::Static(box ast::StaticItem { ty: t, mutability: m, expr: e }) => {
233233
let (ty, body_id) = self.lower_const_item(t, span, e.as_deref());
234234
hir::ItemKind::Static(ty, *m, body_id)
235235
}
236-
ItemKind::Const(_, t, e) => {
237-
let (ty, body_id) = self.lower_const_item(t, span, e.as_deref());
236+
ItemKind::Const(box ast::ConstItem { ty, expr, .. }) => {
237+
let (ty, body_id) = self.lower_const_item(ty, span, expr.as_deref());
238238
hir::ItemKind::Const(ty, body_id)
239239
}
240240
ItemKind::Fn(box Fn {
@@ -708,10 +708,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
708708
let trait_item_def_id = hir_id.expect_owner();
709709

710710
let (generics, kind, has_default) = match &i.kind {
711-
AssocItemKind::Const(_, ty, default) => {
711+
AssocItemKind::Const(box ConstItem { ty, expr, .. }) => {
712712
let ty =
713713
self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
714-
let body = default.as_ref().map(|x| self.lower_const_body(i.span, Some(x)));
714+
let body = expr.as_ref().map(|x| self.lower_const_body(i.span, Some(x)));
715715
(hir::Generics::empty(), hir::TraitItemKind::Const(ty, body), body.is_some())
716716
}
717717
AssocItemKind::Fn(box Fn { sig, generics, body: None, .. }) => {
@@ -809,7 +809,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
809809
self.lower_attrs(hir_id, &i.attrs);
810810

811811
let (generics, kind) = match &i.kind {
812-
AssocItemKind::Const(_, ty, expr) => {
812+
AssocItemKind::Const(box ConstItem { ty, expr, .. }) => {
813813
let ty =
814814
self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
815815
(

Diff for: compiler/rustc_ast_passes/src/ast_validation.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use itertools::{Either, Itertools};
1010
use rustc_ast::ptr::P;
1111
use rustc_ast::visit::{self, AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor};
12-
use rustc_ast::walk_list;
1312
use rustc_ast::*;
13+
use rustc_ast::{walk_list, StaticItem};
1414
use rustc_ast_pretty::pprust::{self, State};
1515
use rustc_data_structures::fx::FxIndexMap;
1616
use rustc_macros::Subdiagnostic;
@@ -983,14 +983,14 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
983983
self.err_handler().emit_err(errors::FieldlessUnion { span: item.span });
984984
}
985985
}
986-
ItemKind::Const(def, .., None) => {
987-
self.check_defaultness(item.span, *def);
986+
ItemKind::Const(box ConstItem { defaultness, expr: None, .. }) => {
987+
self.check_defaultness(item.span, *defaultness);
988988
self.session.emit_err(errors::ConstWithoutBody {
989989
span: item.span,
990990
replace_span: self.ending_semi_or_hi(item.span),
991991
});
992992
}
993-
ItemKind::Static(.., None) => {
993+
ItemKind::Static(box StaticItem { expr: None, .. }) => {
994994
self.session.emit_err(errors::StaticWithoutBody {
995995
span: item.span,
996996
replace_span: self.ending_semi_or_hi(item.span),
@@ -1259,13 +1259,11 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12591259

12601260
if ctxt == AssocCtxt::Impl {
12611261
match &item.kind {
1262-
AssocItemKind::Const(_, _, body) => {
1263-
if body.is_none() {
1264-
self.session.emit_err(errors::AssocConstWithoutBody {
1265-
span: item.span,
1266-
replace_span: self.ending_semi_or_hi(item.span),
1267-
});
1268-
}
1262+
AssocItemKind::Const(box ConstItem { expr: None, .. }) => {
1263+
self.session.emit_err(errors::AssocConstWithoutBody {
1264+
span: item.span,
1265+
replace_span: self.ending_semi_or_hi(item.span),
1266+
});
12691267
}
12701268
AssocItemKind::Fn(box Fn { body, .. }) => {
12711269
if body.is_none() {

Diff for: compiler/rustc_ast_passes/src/feature_gate.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -485,17 +485,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
485485
if let Some(args) = constraint.gen_args.as_ref()
486486
&& matches!(
487487
args,
488-
ast::GenericArgs::ReturnTypeNotation(..) | ast::GenericArgs::Parenthesized(..)
488+
ast::GenericArgs::ReturnTypeNotation(..)
489489
)
490490
{
491-
// RTN is gated elsewhere, and parenthesized args will turn into
492-
// another error.
493-
if matches!(args, ast::GenericArgs::Parenthesized(..)) {
494-
self.sess.delay_span_bug(
495-
constraint.span,
496-
"should have emitted a parenthesized generics error",
497-
);
498-
}
491+
// RTN is gated below with a `gate_all`.
499492
} else {
500493
gate_feature_post!(
501494
&self,

Diff for: compiler/rustc_ast_pretty/src/pprust/state/item.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::pp::Breaks::Inconsistent;
22
use crate::pprust::state::delimited::IterDelimited;
33
use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};
44

5+
use ast::StaticItem;
56
use rustc_ast as ast;
67
use rustc_ast::GenericBound;
78
use rustc_ast::ModKind;
@@ -156,7 +157,7 @@ impl<'a> State<'a> {
156157
self.print_use_tree(tree);
157158
self.word(";");
158159
}
159-
ast::ItemKind::Static(ty, mutbl, body) => {
160+
ast::ItemKind::Static(box StaticItem { ty, mutability: mutbl, expr: body }) => {
160161
let def = ast::Defaultness::Final;
161162
self.print_item_const(
162163
item.ident,
@@ -167,8 +168,15 @@ impl<'a> State<'a> {
167168
def,
168169
);
169170
}
170-
ast::ItemKind::Const(def, ty, body) => {
171-
self.print_item_const(item.ident, None, ty, body.as_deref(), &item.vis, *def);
171+
ast::ItemKind::Const(box ast::ConstItem { defaultness, ty, expr }) => {
172+
self.print_item_const(
173+
item.ident,
174+
None,
175+
ty,
176+
expr.as_deref(),
177+
&item.vis,
178+
*defaultness,
179+
);
172180
}
173181
ast::ItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => {
174182
self.print_fn_full(
@@ -507,8 +515,8 @@ impl<'a> State<'a> {
507515
ast::AssocItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => {
508516
self.print_fn_full(sig, ident, generics, vis, *defaultness, body.as_deref(), attrs);
509517
}
510-
ast::AssocItemKind::Const(def, ty, body) => {
511-
self.print_item_const(ident, None, ty, body.as_deref(), vis, *def);
518+
ast::AssocItemKind::Const(box ast::ConstItem { defaultness, ty, expr }) => {
519+
self.print_item_const(ident, None, ty, expr.as_deref(), vis, *defaultness);
512520
}
513521
ast::AssocItemKind::Type(box ast::TyAlias {
514522
defaultness,

Diff for: compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl LocalUseMap {
6363
elements: &RegionValueElements,
6464
body: &Body<'_>,
6565
) -> Self {
66-
let nones = IndexVec::from_elem_n(None, body.local_decls.len());
66+
let nones = IndexVec::from_elem(None, &body.local_decls);
6767
let mut local_use_map = LocalUseMap {
6868
first_def_at: nones.clone(),
6969
first_use_at: nones.clone(),
@@ -76,7 +76,7 @@ impl LocalUseMap {
7676
}
7777

7878
let mut locals_with_use_data: IndexVec<Local, bool> =
79-
IndexVec::from_elem_n(false, body.local_decls.len());
79+
IndexVec::from_elem(false, &body.local_decls);
8080
live_locals.iter().for_each(|&local| locals_with_use_data[local] = true);
8181

8282
LocalUseMapBuild { local_use_map: &mut local_use_map, elements, locals_with_use_data }

Diff for: compiler/rustc_builtin_macros/src/global_allocator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ pub fn expand(
2525
// FIXME - if we get deref patterns, use them to reduce duplication here
2626
let (item, is_stmt, ty_span) =
2727
if let Annotatable::Item(item) = &item
28-
&& let ItemKind::Static(ty, ..) = &item.kind
28+
&& let ItemKind::Static(box ast::StaticItem { ty, ..}) = &item.kind
2929
{
3030
(item, false, ecx.with_def_site_ctxt(ty.span))
3131
} else if let Annotatable::Stmt(stmt) = &item
3232
&& let StmtKind::Item(item) = &stmt.kind
33-
&& let ItemKind::Static(ty, ..) = &item.kind
33+
&& let ItemKind::Static(box ast::StaticItem { ty, ..}) = &item.kind
3434
{
3535
(item, true, ecx.with_def_site_ctxt(ty.span))
3636
} else {

0 commit comments

Comments
 (0)