Skip to content

Commit 989dfb1

Browse files
committed
Auto merge of rust-lang#3656 - RalfJung:rustup, r=RalfJung
Rustup for `Scalar::from_i128`
2 parents 1f1dd65 + 5367235 commit 989dfb1

File tree

325 files changed

+4412
-3161
lines changed

Some content is hidden

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

325 files changed

+4412
-3161
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,6 @@ jobs:
156156

157157
- name: checkout submodules
158158
run: src/ci/scripts/checkout-submodules.sh
159-
160-
- name: Setup Python
161-
uses: actions/setup-python@v5
162-
with:
163-
python-version: '3.x'
164-
if: runner.environment == 'github-hosted'
165159

166160
- name: install MinGW
167161
run: src/ci/scripts/install-mingw.sh

Cargo.lock

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,14 +2652,11 @@ version = "0.32.2"
26522652
source = "registry+https://github.com/rust-lang/crates.io-index"
26532653
checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
26542654
dependencies = [
2655-
"compiler_builtins",
26562655
"crc32fast",
26572656
"flate2",
26582657
"hashbrown",
26592658
"indexmap",
26602659
"memchr",
2661-
"rustc-std-workspace-alloc",
2662-
"rustc-std-workspace-core",
26632660
"ruzstd 0.5.0",
26642661
"wasmparser",
26652662
]
@@ -2675,6 +2672,18 @@ dependencies = [
26752672
"ruzstd 0.6.0",
26762673
]
26772674

2675+
[[package]]
2676+
name = "object"
2677+
version = "0.36.0"
2678+
source = "registry+https://github.com/rust-lang/crates.io-index"
2679+
checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434"
2680+
dependencies = [
2681+
"compiler_builtins",
2682+
"memchr",
2683+
"rustc-std-workspace-alloc",
2684+
"rustc-std-workspace-core",
2685+
]
2686+
26782687
[[package]]
26792688
name = "odht"
26802689
version = "0.3.1"
@@ -4201,6 +4210,7 @@ dependencies = [
42014210
"rustc_middle",
42024211
"rustc_span",
42034212
"rustc_target",
4213+
"rustc_type_ir",
42044214
"smallvec",
42054215
"tracing",
42064216
]
@@ -4392,7 +4402,6 @@ dependencies = [
43924402
"rustc_hir_pretty",
43934403
"rustc_index",
43944404
"rustc_macros",
4395-
"rustc_next_trait_solver",
43964405
"rustc_query_system",
43974406
"rustc_serialize",
43984407
"rustc_session",
@@ -4509,6 +4518,7 @@ dependencies = [
45094518
"rustc_serialize",
45104519
"rustc_type_ir",
45114520
"rustc_type_ir_macros",
4521+
"tracing",
45124522
]
45134523

45144524
[[package]]
@@ -5356,7 +5366,7 @@ dependencies = [
53565366
"hermit-abi",
53575367
"libc",
53585368
"miniz_oxide",
5359-
"object 0.32.2",
5369+
"object 0.36.0",
53605370
"panic_abort",
53615371
"panic_unwind",
53625372
"profiler_builtins",

compiler/rustc_ast/src/ast.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ pub struct Crate {
488488
/// E.g., `#[test]`, `#[derive(..)]`, `#[rustfmt::skip]` or `#[feature = "foo"]`.
489489
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)]
490490
pub struct MetaItem {
491+
pub unsafety: Safety,
491492
pub path: Path,
492493
pub kind: MetaItemKind,
493494
pub span: Span,
@@ -1392,7 +1393,7 @@ pub enum ExprKind {
13921393
/// An array (e.g, `[a, b, c, d]`).
13931394
Array(ThinVec<P<Expr>>),
13941395
/// Allow anonymous constants from an inline `const` block
1395-
ConstBlock(P<Expr>),
1396+
ConstBlock(AnonConst),
13961397
/// A function call
13971398
///
13981399
/// The first field resolves to the function itself,
@@ -2823,14 +2824,20 @@ pub struct NormalAttr {
28232824
impl NormalAttr {
28242825
pub fn from_ident(ident: Ident) -> Self {
28252826
Self {
2826-
item: AttrItem { path: Path::from_ident(ident), args: AttrArgs::Empty, tokens: None },
2827+
item: AttrItem {
2828+
unsafety: Safety::Default,
2829+
path: Path::from_ident(ident),
2830+
args: AttrArgs::Empty,
2831+
tokens: None,
2832+
},
28272833
tokens: None,
28282834
}
28292835
}
28302836
}
28312837

28322838
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)]
28332839
pub struct AttrItem {
2840+
pub unsafety: Safety,
28342841
pub path: Path,
28352842
pub args: AttrArgs,
28362843
// Tokens for the meta item, e.g. just the `foo` within `#[foo]` or `#![foo]`.

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Functions dealing with attributes and meta items.
22
3-
use crate::ast::{AttrArgs, AttrArgsEq, AttrId, AttrItem, AttrKind, AttrStyle, AttrVec, Attribute};
3+
use crate::ast::{
4+
AttrArgs, AttrArgsEq, AttrId, AttrItem, AttrKind, AttrStyle, AttrVec, Attribute, Safety,
5+
};
46
use crate::ast::{DelimArgs, Expr, ExprKind, LitKind, MetaItemLit};
57
use crate::ast::{MetaItem, MetaItemKind, NestedMetaItem, NormalAttr};
68
use crate::ast::{Path, PathSegment, DUMMY_NODE_ID};
@@ -238,7 +240,12 @@ impl AttrItem {
238240
}
239241

240242
pub fn meta(&self, span: Span) -> Option<MetaItem> {
241-
Some(MetaItem { path: self.path.clone(), kind: self.meta_kind()?, span })
243+
Some(MetaItem {
244+
unsafety: Safety::Default,
245+
path: self.path.clone(),
246+
kind: self.meta_kind()?,
247+
span,
248+
})
242249
}
243250

244251
pub fn meta_kind(&self) -> Option<MetaItemKind> {
@@ -371,7 +378,10 @@ impl MetaItem {
371378
_ => path.span.hi(),
372379
};
373380
let span = path.span.with_hi(hi);
374-
Some(MetaItem { path, kind, span })
381+
// FIXME: This parses `unsafe()` not as unsafe attribute syntax in `MetaItem`,
382+
// but as a parenthesized list. This (and likely `MetaItem`) should be changed in
383+
// such a way that builtin macros don't accept extraneous `unsafe()`.
384+
Some(MetaItem { unsafety: Safety::Default, path, kind, span })
375385
}
376386
}
377387

@@ -555,11 +565,12 @@ pub fn mk_doc_comment(
555565
pub fn mk_attr(
556566
g: &AttrIdGenerator,
557567
style: AttrStyle,
568+
unsafety: Safety,
558569
path: Path,
559570
args: AttrArgs,
560571
span: Span,
561572
) -> Attribute {
562-
mk_attr_from_item(g, AttrItem { path, args, tokens: None }, None, style, span)
573+
mk_attr_from_item(g, AttrItem { unsafety, path, args, tokens: None }, None, style, span)
563574
}
564575

565576
pub fn mk_attr_from_item(
@@ -577,15 +588,22 @@ pub fn mk_attr_from_item(
577588
}
578589
}
579590

580-
pub fn mk_attr_word(g: &AttrIdGenerator, style: AttrStyle, name: Symbol, span: Span) -> Attribute {
591+
pub fn mk_attr_word(
592+
g: &AttrIdGenerator,
593+
style: AttrStyle,
594+
unsafety: Safety,
595+
name: Symbol,
596+
span: Span,
597+
) -> Attribute {
581598
let path = Path::from_ident(Ident::new(name, span));
582599
let args = AttrArgs::Empty;
583-
mk_attr(g, style, path, args, span)
600+
mk_attr(g, style, unsafety, path, args, span)
584601
}
585602

586603
pub fn mk_attr_nested_word(
587604
g: &AttrIdGenerator,
588605
style: AttrStyle,
606+
unsafety: Safety,
589607
outer: Symbol,
590608
inner: Symbol,
591609
span: Span,
@@ -601,12 +619,13 @@ pub fn mk_attr_nested_word(
601619
delim: Delimiter::Parenthesis,
602620
tokens: inner_tokens,
603621
});
604-
mk_attr(g, style, path, attr_args, span)
622+
mk_attr(g, style, unsafety, path, attr_args, span)
605623
}
606624

607625
pub fn mk_attr_name_value_str(
608626
g: &AttrIdGenerator,
609627
style: AttrStyle,
628+
unsafety: Safety,
610629
name: Symbol,
611630
val: Symbol,
612631
span: Span,
@@ -621,7 +640,7 @@ pub fn mk_attr_name_value_str(
621640
});
622641
let path = Path::from_ident(Ident::new(name, span));
623642
let args = AttrArgs::Eq(span, AttrArgsEq::Ast(expr));
624-
mk_attr(g, style, path, args, span)
643+
mk_attr(g, style, unsafety, path, args, span)
625644
}
626645

627646
pub fn filter_by_name(attrs: &[Attribute], name: Symbol) -> impl Iterator<Item = &Attribute> {

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,10 @@ fn noop_visit_attribute<T: MutVisitor>(attr: &mut Attribute, vis: &mut T) {
647647
let Attribute { kind, id: _, style: _, span } = attr;
648648
match kind {
649649
AttrKind::Normal(normal) => {
650-
let NormalAttr { item: AttrItem { path, args, tokens }, tokens: attr_tokens } =
651-
&mut **normal;
650+
let NormalAttr {
651+
item: AttrItem { unsafety: _, path, args, tokens },
652+
tokens: attr_tokens,
653+
} = &mut **normal;
652654
vis.visit_path(path);
653655
visit_attr_args(args, vis);
654656
visit_lazy_tts(tokens, vis);
@@ -678,7 +680,7 @@ fn noop_visit_meta_list_item<T: MutVisitor>(li: &mut NestedMetaItem, vis: &mut T
678680
}
679681

680682
fn noop_visit_meta_item<T: MutVisitor>(mi: &mut MetaItem, vis: &mut T) {
681-
let MetaItem { path: _, kind, span } = mi;
683+
let MetaItem { unsafety: _, path: _, kind, span } = mi;
682684
match kind {
683685
MetaItemKind::Word => {}
684686
MetaItemKind::List(mis) => visit_thin_vec(mis, |mi| vis.visit_meta_list_item(mi)),
@@ -840,7 +842,7 @@ fn visit_nonterminal<T: MutVisitor>(nt: &mut token::Nonterminal, vis: &mut T) {
840842
token::NtTy(ty) => vis.visit_ty(ty),
841843
token::NtLiteral(expr) => vis.visit_expr(expr),
842844
token::NtMeta(item) => {
843-
let AttrItem { path, args, tokens } = item.deref_mut();
845+
let AttrItem { unsafety: _, path, args, tokens } = item.deref_mut();
844846
vis.visit_path(path);
845847
visit_attr_args(args, vis);
846848
visit_lazy_tts(tokens, vis);
@@ -1417,7 +1419,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
14171419
match kind {
14181420
ExprKind::Array(exprs) => visit_thin_exprs(exprs, vis),
14191421
ExprKind::ConstBlock(anon_const) => {
1420-
vis.visit_expr(anon_const);
1422+
vis.visit_anon_const(anon_const);
14211423
}
14221424
ExprKind::Repeat(expr, count) => {
14231425
vis.visit_expr(expr);

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V
959959
ExprKind::Array(subexpressions) => {
960960
walk_list!(visitor, visit_expr, subexpressions);
961961
}
962-
ExprKind::ConstBlock(anon_const) => try_visit!(visitor.visit_expr(anon_const)),
962+
ExprKind::ConstBlock(anon_const) => try_visit!(visitor.visit_anon_const(anon_const)),
963963
ExprKind::Repeat(element, count) => {
964964
try_visit!(visitor.visit_expr(element));
965965
try_visit!(visitor.visit_anon_const(count));

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
7575
let kind = match &e.kind {
7676
ExprKind::Array(exprs) => hir::ExprKind::Array(self.lower_exprs(exprs)),
7777
ExprKind::ConstBlock(c) => {
78-
self.has_inline_consts = true;
79-
hir::ExprKind::ConstBlock(self.lower_expr(c))
78+
let c = self.with_new_scopes(c.value.span, |this| hir::ConstBlock {
79+
def_id: this.local_def_id(c.id),
80+
hir_id: this.lower_node_id(c.id),
81+
body: this.lower_const_body(c.value.span, Some(&c.value)),
82+
});
83+
hir::ExprKind::ConstBlock(c)
8084
}
8185
ExprKind::Repeat(expr, count) => {
8286
let expr = self.lower_expr(expr);
@@ -1801,6 +1805,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18011805
let attr = attr::mk_attr_nested_word(
18021806
&self.tcx.sess.psess.attr_id_generator,
18031807
AttrStyle::Outer,
1808+
Safety::Default,
18041809
sym::allow,
18051810
sym::unreachable_code,
18061811
self.lower_span(span),

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
236236
});
237237
}
238238

239+
fn visit_inline_const(&mut self, constant: &'hir ConstBlock) {
240+
self.insert(DUMMY_SP, constant.hir_id, Node::ConstBlock(constant));
241+
242+
self.with_parent(constant.hir_id, |this| {
243+
intravisit::walk_inline_const(this, constant);
244+
});
245+
}
246+
239247
fn visit_expr(&mut self, expr: &'hir Expr<'hir>) {
240248
self.insert(expr.span, expr.hir_id, Node::Expr(expr));
241249

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ struct LoweringContext<'a, 'hir> {
9696

9797
/// Bodies inside the owner being lowered.
9898
bodies: Vec<(hir::ItemLocalId, &'hir hir::Body<'hir>)>,
99-
/// Whether there were inline consts that typeck will split out into bodies
100-
has_inline_consts: bool,
10199
/// Attributes inside the owner being lowered.
102100
attrs: SortedMap<hir::ItemLocalId, &'hir [Attribute]>,
103101
/// Collect items that were created by lowering the current owner.
@@ -160,7 +158,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
160158
item_local_id_counter: hir::ItemLocalId::ZERO,
161159
node_id_to_local_id: Default::default(),
162160
trait_map: Default::default(),
163-
has_inline_consts: false,
164161

165162
// Lowering state.
166163
catch_scope: None,
@@ -570,7 +567,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
570567

571568
let current_attrs = std::mem::take(&mut self.attrs);
572569
let current_bodies = std::mem::take(&mut self.bodies);
573-
let current_has_inline_consts = std::mem::take(&mut self.has_inline_consts);
574570
let current_node_ids = std::mem::take(&mut self.node_id_to_local_id);
575571
let current_trait_map = std::mem::take(&mut self.trait_map);
576572
let current_owner =
@@ -597,7 +593,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
597593

598594
self.attrs = current_attrs;
599595
self.bodies = current_bodies;
600-
self.has_inline_consts = current_has_inline_consts;
601596
self.node_id_to_local_id = current_node_ids;
602597
self.trait_map = current_trait_map;
603598
self.current_hir_id_owner = current_owner;
@@ -634,7 +629,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
634629
let attrs = std::mem::take(&mut self.attrs);
635630
let mut bodies = std::mem::take(&mut self.bodies);
636631
let trait_map = std::mem::take(&mut self.trait_map);
637-
let has_inline_consts = std::mem::take(&mut self.has_inline_consts);
638632

639633
#[cfg(debug_assertions)]
640634
for (id, attrs) in attrs.iter() {
@@ -652,7 +646,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
652646
self.tcx.hash_owner_nodes(node, &bodies, &attrs);
653647
let num_nodes = self.item_local_id_counter.as_usize();
654648
let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies, num_nodes);
655-
let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies, has_inline_consts };
649+
let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies };
656650
let attrs = hir::AttributeMap { map: attrs, opt_hash: attrs_hash };
657651

658652
self.arena.alloc(hir::OwnerInfo { nodes, parenting, attrs, trait_map })
@@ -911,6 +905,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
911905
let kind = match attr.kind {
912906
AttrKind::Normal(ref normal) => AttrKind::Normal(P(NormalAttr {
913907
item: AttrItem {
908+
unsafety: normal.item.unsafety,
914909
path: normal.item.path.clone(),
915910
args: self.lower_attr_args(&normal.item.args),
916911
tokens: None,

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
561561
gate_all!(mut_ref, "mutable by-reference bindings are experimental");
562562
gate_all!(precise_capturing, "precise captures on `impl Trait` are experimental");
563563
gate_all!(global_registration, "global registration is experimental");
564+
gate_all!(unsafe_attributes, "`#[unsafe()]` markers for attributes are experimental");
564565

565566
if !visitor.features.never_patterns {
566567
if let Some(spans) = spans.get(&sym::never_patterns) {

0 commit comments

Comments
 (0)