Skip to content

Commit a39ac5a

Browse files
committed
Auto merge of rust-lang#95501 - Dylan-DPC:rollup-arx6sdc, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#93901 (Stabilize native library modifier syntax and the `whole-archive` modifier specifically) - rust-lang#94806 (Fix `cargo run tidy`) - rust-lang#94869 (Add the generic_associated_types_extended feature) - rust-lang#95011 (async: Give predictable name to binding generated from .await expressions.) - rust-lang#95251 (Reduce max hash in raw strings from u16 to u8) - rust-lang#95298 (Fix double drop of allocator in IntoIter impl of Vec) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents a40c595 + d6c959c commit a39ac5a

File tree

58 files changed

+632
-238
lines changed

Some content is hidden

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

58 files changed

+632
-238
lines changed

compiler/rustc_ast/src/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ pub enum StrStyle {
16161616
/// A raw string, like `r##"foo"##`.
16171617
///
16181618
/// The value is the number of `#` symbols used.
1619-
Raw(u16),
1619+
Raw(u8),
16201620
}
16211621

16221622
/// An AST literal.

compiler/rustc_ast/src/token.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ pub enum LitKind {
5959
Integer,
6060
Float,
6161
Str,
62-
StrRaw(u16), // raw string delimited by `n` hash symbols
62+
StrRaw(u8), // raw string delimited by `n` hash symbols
6363
ByteStr,
64-
ByteStrRaw(u16), // raw byte string delimited by `n` hash symbols
64+
ByteStrRaw(u8), // raw byte string delimited by `n` hash symbols
6565
Err,
6666
}
6767

compiler/rustc_ast_lowering/src/expr.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
618618
/// Desugar `<expr>.await` into:
619619
/// ```rust
620620
/// match ::std::future::IntoFuture::into_future(<expr>) {
621-
/// mut pinned => loop {
621+
/// mut __awaitee => loop {
622622
/// match unsafe { ::std::future::Future::poll(
623-
/// <::std::pin::Pin>::new_unchecked(&mut pinned),
623+
/// <::std::pin::Pin>::new_unchecked(&mut __awaitee),
624624
/// ::std::future::get_context(task_context),
625625
/// ) } {
626626
/// ::std::task::Poll::Ready(result) => break result,
@@ -657,21 +657,24 @@ impl<'hir> LoweringContext<'_, 'hir> {
657657
let expr = self.lower_expr_mut(expr);
658658
let expr_hir_id = expr.hir_id;
659659

660-
let pinned_ident = Ident::with_dummy_span(sym::pinned);
661-
let (pinned_pat, pinned_pat_hid) =
662-
self.pat_ident_binding_mode(span, pinned_ident, hir::BindingAnnotation::Mutable);
660+
// Note that the name of this binding must not be changed to something else because
661+
// debuggers and debugger extensions expect it to be called `__awaitee`. They use
662+
// this name to identify what is being awaited by a suspended async functions.
663+
let awaitee_ident = Ident::with_dummy_span(sym::__awaitee);
664+
let (awaitee_pat, awaitee_pat_hid) =
665+
self.pat_ident_binding_mode(span, awaitee_ident, hir::BindingAnnotation::Mutable);
663666

664667
let task_context_ident = Ident::with_dummy_span(sym::_task_context);
665668

666669
// unsafe {
667670
// ::std::future::Future::poll(
668-
// ::std::pin::Pin::new_unchecked(&mut pinned),
671+
// ::std::pin::Pin::new_unchecked(&mut __awaitee),
669672
// ::std::future::get_context(task_context),
670673
// )
671674
// }
672675
let poll_expr = {
673-
let pinned = self.expr_ident(span, pinned_ident, pinned_pat_hid);
674-
let ref_mut_pinned = self.expr_mut_addr_of(span, pinned);
676+
let awaitee = self.expr_ident(span, awaitee_ident, awaitee_pat_hid);
677+
let ref_mut_awaitee = self.expr_mut_addr_of(span, awaitee);
675678
let task_context = if let Some(task_context_hid) = self.task_context {
676679
self.expr_ident_mut(span, task_context_ident, task_context_hid)
677680
} else {
@@ -681,7 +684,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
681684
let new_unchecked = self.expr_call_lang_item_fn_mut(
682685
span,
683686
hir::LangItem::PinNewUnchecked,
684-
arena_vec![self; ref_mut_pinned],
687+
arena_vec![self; ref_mut_awaitee],
685688
Some(expr_hir_id),
686689
);
687690
let get_context = self.expr_call_lang_item_fn_mut(
@@ -782,8 +785,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
782785
span: self.lower_span(span),
783786
});
784787

785-
// mut pinned => loop { ... }
786-
let pinned_arm = self.arm(pinned_pat, loop_expr);
788+
// mut __awaitee => loop { ... }
789+
let awaitee_arm = self.arm(awaitee_pat, loop_expr);
787790

788791
// `match ::std::future::IntoFuture::into_future(<expr>) { ... }`
789792
let into_future_span = self.mark_span_with_reason(
@@ -799,11 +802,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
799802
);
800803

801804
// match <into_future_expr> {
802-
// mut pinned => loop { .. }
805+
// mut __awaitee => loop { .. }
803806
// }
804807
hir::ExprKind::Match(
805808
into_future_expr,
806-
arena_vec![self; pinned_arm],
809+
arena_vec![self; awaitee_arm],
807810
hir::MatchSource::AwaitDesugar,
808811
)
809812
}

compiler/rustc_ast_passes/src/feature_gate.rs

-8
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
387387
if attr.has_name(sym::link) {
388388
for nested_meta in attr.meta_item_list().unwrap_or_default() {
389389
if nested_meta.has_name(sym::modifiers) {
390-
gate_feature_post!(
391-
self,
392-
native_link_modifiers,
393-
nested_meta.span(),
394-
"native link modifiers are experimental"
395-
);
396-
397390
if let Some(modifiers) = nested_meta.value_str() {
398391
for modifier in modifiers.as_str().split(',') {
399392
if let Some(modifier) = modifier.strip_prefix(&['+', '-']) {
@@ -412,7 +405,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
412405
gate_modifier!(
413406
"bundle" => native_link_modifiers_bundle
414407
"verbatim" => native_link_modifiers_verbatim
415-
"whole-archive" => native_link_modifiers_whole_archive
416408
"as-needed" => native_link_modifiers_as_needed
417409
);
418410
}

compiler/rustc_codegen_ssa/src/back/link.rs

+62-41
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
18441844
// This change is somewhat breaking in practice due to local static libraries being linked
18451845
// as whole-archive (#85144), so removing whole-archive may be a pre-requisite.
18461846
if sess.opts.debugging_opts.link_native_libraries {
1847-
add_local_native_libraries(cmd, sess, codegen_results);
1847+
add_local_native_libraries(cmd, sess, codegen_results, crate_type);
18481848
}
18491849

18501850
// Upstream rust libraries and their nobundle static libraries
@@ -2016,6 +2016,16 @@ fn add_order_independent_options(
20162016
add_rpath_args(cmd, sess, codegen_results, out_filename);
20172017
}
20182018

2019+
// A dylib may reexport symbols from the linked rlib or native static library.
2020+
// Even if some symbol is reexported it's still not necessarily counted as used and may be
2021+
// dropped, at least with `ld`-like ELF linkers. So we have to link some rlibs and static
2022+
// libraries as whole-archive to avoid losing reexported symbols.
2023+
// FIXME: Find a way to mark reexported symbols as used and avoid this use of whole-archive.
2024+
fn default_to_whole_archive(sess: &Session, crate_type: CrateType, cmd: &dyn Linker) -> bool {
2025+
crate_type == CrateType::Dylib
2026+
&& !(sess.target.limit_rdylib_exports && cmd.exported_symbol_means_used_symbol())
2027+
}
2028+
20192029
/// # Native library linking
20202030
///
20212031
/// User-supplied library search paths (-L on the command line). These are the same paths used to
@@ -2029,6 +2039,7 @@ fn add_local_native_libraries(
20292039
cmd: &mut dyn Linker,
20302040
sess: &Session,
20312041
codegen_results: &CodegenResults,
2042+
crate_type: CrateType,
20322043
) {
20332044
let filesearch = sess.target_filesearch(PathKind::All);
20342045
for search_path in filesearch.search_paths() {
@@ -2046,14 +2057,18 @@ fn add_local_native_libraries(
20462057
codegen_results.crate_info.used_libraries.iter().filter(|l| relevant_lib(sess, l));
20472058

20482059
let search_path = OnceCell::new();
2049-
let mut last = (NativeLibKind::Unspecified, None);
2060+
let mut last = (None, NativeLibKind::Unspecified, None);
20502061
for lib in relevant_libs {
20512062
let Some(name) = lib.name else {
20522063
continue;
20532064
};
20542065

20552066
// Skip if this library is the same as the last.
2056-
last = if (lib.kind, lib.name) == last { continue } else { (lib.kind, lib.name) };
2067+
last = if (lib.name, lib.kind, lib.verbatim) == last {
2068+
continue;
2069+
} else {
2070+
(lib.name, lib.kind, lib.verbatim)
2071+
};
20572072

20582073
let verbatim = lib.verbatim.unwrap_or(false);
20592074
match lib.kind {
@@ -2064,15 +2079,19 @@ fn add_local_native_libraries(
20642079
NativeLibKind::Framework { as_needed } => {
20652080
cmd.link_framework(name, as_needed.unwrap_or(true))
20662081
}
2067-
NativeLibKind::Static { bundle: None | Some(true), .. }
2068-
| NativeLibKind::Static { whole_archive: Some(true), .. } => {
2069-
cmd.link_whole_staticlib(
2070-
name,
2071-
verbatim,
2072-
&search_path.get_or_init(|| archive_search_paths(sess)),
2073-
);
2082+
NativeLibKind::Static { whole_archive, .. } => {
2083+
if whole_archive == Some(true)
2084+
|| (whole_archive == None && default_to_whole_archive(sess, crate_type, cmd))
2085+
{
2086+
cmd.link_whole_staticlib(
2087+
name,
2088+
verbatim,
2089+
&search_path.get_or_init(|| archive_search_paths(sess)),
2090+
);
2091+
} else {
2092+
cmd.link_staticlib(name, verbatim)
2093+
}
20742094
}
2075-
NativeLibKind::Static { .. } => cmd.link_staticlib(name, verbatim),
20762095
NativeLibKind::RawDylib => {
20772096
// FIXME(#58713): Proper handling for raw dylibs.
20782097
bug!("raw_dylib feature not yet implemented");
@@ -2197,34 +2216,37 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
21972216
// external build system already has the native dependencies defined, and it
21982217
// will provide them to the linker itself.
21992218
if sess.opts.debugging_opts.link_native_libraries {
2200-
let mut last = None;
2219+
let mut last = (None, NativeLibKind::Unspecified, None);
22012220
for lib in &codegen_results.crate_info.native_libraries[&cnum] {
2221+
let Some(name) = lib.name else {
2222+
continue;
2223+
};
22022224
if !relevant_lib(sess, lib) {
2203-
// Skip libraries if they are disabled by `#[link(cfg=...)]`
22042225
continue;
22052226
}
22062227

22072228
// Skip if this library is the same as the last.
2208-
if last == lib.name {
2229+
last = if (lib.name, lib.kind, lib.verbatim) == last {
22092230
continue;
2210-
}
2211-
2212-
if let Some(static_lib_name) = lib.name {
2213-
if let NativeLibKind::Static { bundle: Some(false), whole_archive } =
2214-
lib.kind
2231+
} else {
2232+
(lib.name, lib.kind, lib.verbatim)
2233+
};
2234+
2235+
if let NativeLibKind::Static { bundle: Some(false), whole_archive } =
2236+
lib.kind
2237+
{
2238+
let verbatim = lib.verbatim.unwrap_or(false);
2239+
if whole_archive == Some(true)
2240+
|| (whole_archive == None
2241+
&& default_to_whole_archive(sess, crate_type, cmd))
22152242
{
2216-
let verbatim = lib.verbatim.unwrap_or(false);
2217-
if whole_archive == Some(true) {
2218-
cmd.link_whole_staticlib(
2219-
static_lib_name,
2220-
verbatim,
2221-
search_path.get_or_init(|| archive_search_paths(sess)),
2222-
);
2223-
} else {
2224-
cmd.link_staticlib(static_lib_name, verbatim);
2225-
}
2226-
2227-
last = lib.name;
2243+
cmd.link_whole_staticlib(
2244+
name,
2245+
verbatim,
2246+
search_path.get_or_init(|| archive_search_paths(sess)),
2247+
);
2248+
} else {
2249+
cmd.link_staticlib(name, verbatim);
22282250
}
22292251
}
22302252
}
@@ -2282,15 +2304,10 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
22822304
let cratepath = &src.rlib.as_ref().unwrap().0;
22832305

22842306
let mut link_upstream = |path: &Path| {
2285-
// If we're creating a dylib, then we need to include the
2286-
// whole of each object in our archive into that artifact. This is
2287-
// because a `dylib` can be reused as an intermediate artifact.
2288-
//
2289-
// Note, though, that we don't want to include the whole of a
2290-
// compiler-builtins crate (e.g., compiler-rt) because it'll get
2291-
// repeatedly linked anyway.
2307+
// We don't want to include the whole compiler-builtins crate (e.g., compiler-rt)
2308+
// regardless of the default because it'll get repeatedly linked anyway.
22922309
let path = fix_windows_verbatim_for_gcc(path);
2293-
if crate_type == CrateType::Dylib
2310+
if default_to_whole_archive(sess, crate_type, cmd)
22942311
&& codegen_results.crate_info.compiler_builtins != Some(cnum)
22952312
{
22962313
cmd.link_whole_rlib(&path);
@@ -2401,7 +2418,7 @@ fn add_upstream_native_libraries(
24012418
sess: &Session,
24022419
codegen_results: &CodegenResults,
24032420
) {
2404-
let mut last = (NativeLibKind::Unspecified, None);
2421+
let mut last = (None, NativeLibKind::Unspecified, None);
24052422
for &cnum in &codegen_results.crate_info.used_crates {
24062423
for lib in codegen_results.crate_info.native_libraries[&cnum].iter() {
24072424
let Some(name) = lib.name else {
@@ -2412,7 +2429,11 @@ fn add_upstream_native_libraries(
24122429
}
24132430

24142431
// Skip if this library is the same as the last.
2415-
last = if (lib.kind, lib.name) == last { continue } else { (lib.kind, lib.name) };
2432+
last = if (lib.name, lib.kind, lib.verbatim) == last {
2433+
continue;
2434+
} else {
2435+
(lib.name, lib.kind, lib.verbatim)
2436+
};
24162437

24172438
let verbatim = lib.verbatim.unwrap_or(false);
24182439
match lib.kind {

compiler/rustc_codegen_ssa/src/back/linker.rs

+11
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ pub trait Linker {
186186
fn no_crt_objects(&mut self);
187187
fn no_default_libraries(&mut self);
188188
fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType, symbols: &[String]);
189+
fn exported_symbol_means_used_symbol(&self) -> bool {
190+
true
191+
}
189192
fn subsystem(&mut self, subsystem: &str);
190193
fn group_start(&mut self);
191194
fn group_end(&mut self);
@@ -724,6 +727,10 @@ impl<'a> Linker for GccLinker<'a> {
724727
}
725728
}
726729

730+
fn exported_symbol_means_used_symbol(&self) -> bool {
731+
self.sess.target.is_like_windows || self.sess.target.is_like_osx
732+
}
733+
727734
fn subsystem(&mut self, subsystem: &str) {
728735
self.linker_arg("--subsystem");
729736
self.linker_arg(&subsystem);
@@ -1471,6 +1478,10 @@ impl<'a> Linker for L4Bender<'a> {
14711478
return;
14721479
}
14731480

1481+
fn exported_symbol_means_used_symbol(&self) -> bool {
1482+
false
1483+
}
1484+
14741485
fn subsystem(&mut self, subsystem: &str) {
14751486
self.cmd.arg(&format!("--subsystem {}", subsystem));
14761487
}

compiler/rustc_feature/src/accepted.rs

+4
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ declare_features! (
215215
/// Allows patterns with concurrent by-move and by-ref bindings.
216216
/// For example, you can write `Foo(a, ref b)` where `a` is by-move and `b` is by-ref.
217217
(accepted, move_ref_pattern, "1.49.0", Some(68354), None),
218+
/// Allows specifying modifiers in the link attribute: `#[link(modifiers = "...")]`
219+
(accepted, native_link_modifiers, "1.61.0", Some(81490), None),
220+
/// Allows specifying the whole-archive link modifier
221+
(accepted, native_link_modifiers_whole_archive, "1.61.0", Some(81490), None),
218222
/// Allows using `#![no_std]`.
219223
(accepted, no_std, "1.6.0", None, None),
220224
/// Allows defining identifiers beyond ASCII.

compiler/rustc_feature/src/active.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ declare_features! (
400400
(active, generic_arg_infer, "1.55.0", Some(85077), None),
401401
/// Allows associated types to be generic, e.g., `type Foo<T>;` (RFC 1598).
402402
(active, generic_associated_types, "1.23.0", Some(44265), None),
403+
/// An extension to the `generic_associated_types` feature, allowing incomplete features.
404+
(incomplete, generic_associated_types_extended, "1.61.0", Some(95451), None),
403405
/// Allows non-trivial generic constants which have to have wfness manually propagated to callers
404406
(incomplete, generic_const_exprs, "1.56.0", Some(76560), None),
405407
/// Allows using `..X`, `..=X`, `...X`, and `X..` as a pattern.
@@ -446,16 +448,12 @@ declare_features! (
446448
(active, must_not_suspend, "1.57.0", Some(83310), None),
447449
/// Allows using `#[naked]` on functions.
448450
(active, naked_functions, "1.9.0", Some(32408), None),
449-
/// Allows specifying modifiers in the link attribute: `#[link(modifiers = "...")]`
450-
(active, native_link_modifiers, "1.53.0", Some(81490), None),
451451
/// Allows specifying the as-needed link modifier
452452
(active, native_link_modifiers_as_needed, "1.53.0", Some(81490), None),
453453
/// Allows specifying the bundle link modifier
454454
(active, native_link_modifiers_bundle, "1.53.0", Some(81490), None),
455455
/// Allows specifying the verbatim link modifier
456456
(active, native_link_modifiers_verbatim, "1.53.0", Some(81490), None),
457-
/// Allows specifying the whole-archive link modifier
458-
(active, native_link_modifiers_whole_archive, "1.53.0", Some(81490), None),
459457
/// Allow negative trait implementations.
460458
(active, negative_impls, "1.44.0", Some(68318), None),
461459
/// Allows the `!` type. Does not imply 'exhaustive_patterns' (below) any more.

0 commit comments

Comments
 (0)