Skip to content

Commit a60d5fa

Browse files
authored
Merge pull request #21143 from rust-lang/rustc-pull
minor: sync from downstream
2 parents f7970fd + fc4db45 commit a60d5fa

File tree

717 files changed

+20146
-11217
lines changed

Some content is hidden

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

717 files changed

+20146
-11217
lines changed

Cargo.lock

Lines changed: 566 additions & 554 deletions
Large diffs are not rendered by default.

bootstrap.example.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,12 @@
708708
# desired in distributions, for example.
709709
#rust.rpath = true
710710

711+
# Additional flags to pass to `rustc`.
712+
# Takes precedence over bootstrap's own flags but not over per target rustflags nor env. vars. like RUSTFLAGS.
713+
# Applies to all stages and targets.
714+
#
715+
#rust.rustflags = []
716+
711717
# Indicates whether symbols should be stripped using `-Cstrip=symbols`.
712718
#rust.strip = false
713719

@@ -1013,6 +1019,12 @@
10131019
# and will override the same option under [rust] section. It only works on Unix platforms
10141020
#rpath = rust.rpath (bool)
10151021

1022+
# Additional flags to pass to `rustc`.
1023+
# Takes precedence over bootstrap's own flags and `rust.rustflags` but not over env. vars. like RUSTFLAGS.
1024+
# Applies to all stages.
1025+
#
1026+
#rustflags = rust.rustflags
1027+
10161028
# Force static or dynamic linkage of the standard library for this target. If
10171029
# this target is a host for rustc, this will also affect the linkage of the
10181030
# compiler itself. This is useful for building rustc on targets that normally

compiler/rustc/Cargo.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,25 @@ rustc_public = { path = "../rustc_public" }
2020
rustc_public_bridge = { path = "../rustc_public_bridge" }
2121
# tidy-alphabetical-end
2222

23+
# Pin these to avoid pulling in a package with a binary blob
24+
# <https://github.com/rust-lang/rust/pull/136395#issuecomment-2692769062>
25+
[target.'cfg(target_os = "wasi")'.dependencies]
26+
getrandom = "=0.3.3"
27+
wasi = "=0.14.2"
28+
29+
2330
[dependencies.tikv-jemalloc-sys]
24-
version = "0.6.0"
31+
version = "0.6.1"
2532
optional = true
26-
features = ['unprefixed_malloc_on_supported_platforms']
33+
features = ['override_allocator_on_supported_platforms']
2734

2835
[features]
2936
# tidy-alphabetical-start
3037
check_only = ['rustc_driver_impl/check_only']
3138
jemalloc = ['dep:tikv-jemalloc-sys']
3239
llvm = ['rustc_driver_impl/llvm']
3340
llvm_enzyme = ['rustc_driver_impl/llvm_enzyme']
41+
llvm_offload = ['rustc_driver_impl/llvm_offload']
3442
max_level_info = ['rustc_driver_impl/max_level_info']
3543
rustc_randomized_layouts = ['rustc_driver_impl/rustc_randomized_layouts']
3644
# tidy-alphabetical-end

compiler/rustc/src/main.rs

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,25 @@
77
// distribution. The obvious way to do this is with the `#[global_allocator]`
88
// mechanism. However, for complicated reasons (see
99
// https://github.com/rust-lang/rust/pull/81782#issuecomment-784438001 for some
10-
// details) that mechanism doesn't work here. Also, we must use a consistent
11-
// allocator across the rustc <-> llvm boundary, and `#[global_allocator]`
12-
// wouldn't provide that.
10+
// details) that mechanism doesn't work here. Also, we'd like to use a
11+
// consistent allocator across the rustc <-> llvm boundary, and
12+
// `#[global_allocator]` wouldn't provide that.
1313
//
14-
// Instead, we use a lower-level mechanism. rustc is linked with jemalloc in a
15-
// way such that jemalloc's implementation of `malloc`, `free`, etc., override
16-
// the libc allocator's implementation. This means that Rust's `System`
17-
// allocator, which calls `libc::malloc()` et al., is actually calling into
18-
// jemalloc.
14+
// Instead, we use a lower-level mechanism, namely the
15+
// `"override_allocator_on_supported_platforms"` Cargo feature of jemalloc-sys.
16+
//
17+
// This makes jemalloc-sys override the libc/system allocator's implementation
18+
// of `malloc`, `free`, etc.. This means that Rust's `System` allocator, which
19+
// calls `libc::malloc()` et al., is actually calling into jemalloc.
1920
//
2021
// A consequence of not using `GlobalAlloc` (and the `tikv-jemallocator` crate
2122
// provides an impl of that trait, which is called `Jemalloc`) is that we
2223
// cannot use the sized deallocation APIs (`sdallocx`) that jemalloc provides.
2324
// It's unclear how much performance is lost because of this.
2425
//
25-
// As for the symbol overrides in `main` below: we're pulling in a static copy
26-
// of jemalloc. We need to actually reference its symbols for it to get linked.
27-
// The two crates we link to here, `std` and `rustc_driver`, are both dynamic
28-
// libraries. So we must reference jemalloc symbols one way or another, because
29-
// this file is the only object code in the rustc executable.
26+
// NOTE: Even though Cargo passes `--extern` with `tikv_jemalloc_sys`, we still need to `use` the
27+
// crate for the compiler to see the `#[used]`, see https://github.com/rust-lang/rust/issues/64402.
28+
// This is similarly required if we used a crate with `#[global_allocator]`.
3029
//
3130
// NOTE: if you are reading this comment because you want to set a custom `global_allocator` for
3231
// benchmarking, consider using the benchmarks in the `rustc-perf` collector suite instead:
@@ -36,43 +35,9 @@
3635
// to compare their performance, see
3736
// https://github.com/rust-lang/rust/commit/b90cfc887c31c3e7a9e6d462e2464db1fe506175#diff-43914724af6e464c1da2171e4a9b6c7e607d5bc1203fa95c0ab85be4122605ef
3837
// for an example of how to do so.
38+
#[cfg(feature = "jemalloc")]
39+
use tikv_jemalloc_sys as _;
3940

4041
fn main() {
41-
// See the comment at the top of this file for an explanation of this.
42-
#[cfg(feature = "jemalloc")]
43-
{
44-
use std::os::raw::{c_int, c_void};
45-
46-
use tikv_jemalloc_sys as jemalloc_sys;
47-
48-
#[used]
49-
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
50-
#[used]
51-
static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int =
52-
jemalloc_sys::posix_memalign;
53-
#[used]
54-
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
55-
#[used]
56-
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
57-
#[used]
58-
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
59-
#[used]
60-
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
61-
62-
// On OSX, jemalloc doesn't directly override malloc/free, but instead
63-
// registers itself with the allocator's zone APIs in a ctor. However,
64-
// the linker doesn't seem to consider ctors as "used" when statically
65-
// linking, so we need to explicitly depend on the function.
66-
#[cfg(target_os = "macos")]
67-
{
68-
unsafe extern "C" {
69-
fn _rjem_je_zone_register();
70-
}
71-
72-
#[used]
73-
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
74-
}
75-
}
76-
7742
rustc_driver::main()
7843
}

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -857,15 +857,15 @@ impl BindingMode {
857857
}
858858
}
859859

860-
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
860+
#[derive(Clone, Copy, Encodable, Decodable, Debug, Walkable)]
861861
pub enum RangeEnd {
862862
/// `..=` or `...`
863863
Included(RangeSyntax),
864864
/// `..`
865865
Excluded,
866866
}
867867

868-
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
868+
#[derive(Clone, Copy, Encodable, Decodable, Debug, Walkable)]
869869
pub enum RangeSyntax {
870870
/// `...`
871871
DotDotDot,
@@ -1915,7 +1915,7 @@ pub enum ForLoopKind {
19151915
}
19161916

19171917
/// Used to differentiate between `async {}` blocks and `gen {}` blocks.
1918-
#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, Walkable)]
1918+
#[derive(Clone, Copy, Encodable, Decodable, Debug, PartialEq, Eq, Walkable)]
19191919
pub enum GenBlockKind {
19201920
Async,
19211921
Gen,

compiler/rustc_ast_passes/messages.ftl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ ast_passes_assoc_type_without_body =
3737
.suggestion = provide a definition for the type
3838
3939
ast_passes_async_fn_in_const_trait_or_trait_impl =
40-
async functions are not allowed in `const` {$in_impl ->
41-
[true] trait impls
42-
*[false] traits
40+
async functions are not allowed in `const` {$context ->
41+
[trait_impl] trait impls
42+
[impl] impls
43+
*[trait] traits
4344
}
4445
.label = associated functions of `const` cannot be declared `async`
4546
@@ -88,6 +89,9 @@ ast_passes_const_and_coroutine = functions cannot be both `const` and `{$corouti
8889
.coroutine = `{$coroutine_kind}` because of this
8990
.label = {""}
9091
92+
ast_passes_const_auto_trait = auto traits cannot be const
93+
.help = remove the `const` keyword
94+
9195
ast_passes_const_bound_trait_object = const trait bounds are not allowed in trait object types
9296
9397
ast_passes_const_without_body =

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,15 @@ impl<'a> AstValidator<'a> {
312312
return;
313313
};
314314

315+
let context = match parent {
316+
TraitOrImpl::Trait { .. } => "trait",
317+
TraitOrImpl::TraitImpl { .. } => "trait_impl",
318+
TraitOrImpl::Impl { .. } => "impl",
319+
};
320+
315321
self.dcx().emit_err(errors::AsyncFnInConstTraitOrTraitImpl {
316322
async_keyword,
317-
in_impl: matches!(parent, TraitOrImpl::TraitImpl { .. }),
323+
context,
318324
const_keyword,
319325
});
320326
}
@@ -814,6 +820,12 @@ impl<'a> AstValidator<'a> {
814820
self.dcx().emit_err(errors::ModuleNonAscii { span: ident.span, name: ident.name });
815821
}
816822

823+
fn deny_const_auto_traits(&self, constness: Const) {
824+
if let Const::Yes(span) = constness {
825+
self.dcx().emit_err(errors::ConstAutoTrait { span });
826+
}
827+
}
828+
817829
fn deny_generic_params(&self, generics: &Generics, ident_span: Span) {
818830
if !generics.params.is_empty() {
819831
self.dcx()
@@ -1251,6 +1263,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12511263
}) => {
12521264
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
12531265
if *is_auto == IsAuto::Yes {
1266+
// For why we reject `const auto trait`, see rust-lang/rust#149285.
1267+
self.deny_const_auto_traits(*constness);
12541268
// Auto traits cannot have generics, super traits nor contain items.
12551269
self.deny_generic_params(generics, ident.span);
12561270
self.deny_super_traits(bounds, ident.span);
@@ -1714,9 +1728,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
17141728
self.check_async_fn_in_const_trait_or_impl(sig, parent);
17151729
}
17161730
}
1717-
Some(TraitOrImpl::Impl { constness }) => {
1731+
Some(parent @ TraitOrImpl::Impl { constness }) => {
17181732
if let AssocItemKind::Fn(box Fn { sig, .. }) = &item.kind {
17191733
self.check_impl_fn_not_const(sig.header.constness, *constness);
1734+
self.check_async_fn_in_const_trait_or_impl(sig, parent);
17201735
}
17211736
}
17221737
None => {}

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub(crate) struct TraitFnConst {
7676
pub(crate) struct AsyncFnInConstTraitOrTraitImpl {
7777
#[primary_span]
7878
pub async_keyword: Span,
79-
pub in_impl: bool,
79+
pub context: &'static str,
8080
#[label]
8181
pub const_keyword: Span,
8282
}
@@ -429,6 +429,14 @@ pub(crate) struct AutoTraitItems {
429429
pub ident: Span,
430430
}
431431

432+
#[derive(Diagnostic)]
433+
#[diag(ast_passes_const_auto_trait)]
434+
#[help]
435+
pub(crate) struct ConstAutoTrait {
436+
#[primary_span]
437+
pub span: Span,
438+
}
439+
432440
#[derive(Diagnostic)]
433441
#[diag(ast_passes_generic_before_constraints)]
434442
pub(crate) struct ArgsBeforeConstraint {

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ pub fn parse_cfg_entry<S: Stage>(
8282
}
8383
},
8484
a @ (ArgParser::NoArgs | ArgParser::NameValue(_)) => {
85-
let Some(name) = meta.path().word_sym() else {
85+
let Some(name) = meta.path().word_sym().filter(|s| !s.is_path_segment_keyword())
86+
else {
8687
return Err(cx.expected_identifier(meta.path().span()));
8788
};
8889
parse_name_value(name, meta.path().span(), a.name_value(), meta.span(), cx)?
@@ -158,7 +159,7 @@ fn parse_cfg_entry_target<S: Stage>(
158159
};
159160

160161
// Then, parse it as a name-value item
161-
let Some(name) = sub_item.path().word_sym() else {
162+
let Some(name) = sub_item.path().word_sym().filter(|s| !s.is_path_segment_keyword()) else {
162163
return Err(cx.expected_identifier(sub_item.path().span()));
163164
};
164165
let name = Symbol::intern(&format!("target_{name}"));

compiler/rustc_attr_parsing/src/attributes/cfg_old.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ pub fn eval_condition(
220220
}
221221
}
222222
}
223-
MetaItemKind::Word | MetaItemKind::NameValue(..) if cfg.path.segments.len() != 1 => {
223+
MetaItemKind::Word | MetaItemKind::NameValue(..)
224+
if cfg.path.segments.len() != 1
225+
|| cfg.path.segments[0].ident.is_path_segment_keyword() =>
226+
{
224227
dcx.emit_err(session_diagnostics::CfgPredicateIdentifier { span: cfg.path.span });
225228
true
226229
}

0 commit comments

Comments
 (0)