Skip to content

Commit 245e65c

Browse files
committed
Auto merge of rust-lang#139888 - Zalathar:rollup-j1o05ae, r=Zalathar
Rollup of 8 pull requests Successful merges: - rust-lang#136926 (Stabilize `-Zdwarf-version` as `-Cdwarf-version`) - rust-lang#139647 (Add unstable parsing of `--extern foo::bar=libbar.rlib` command line options) - rust-lang#139853 (Disable combining LLD with external llvm-config) - rust-lang#139867 (Fix some tidy paper cuts) - rust-lang#139871 (Fix wrong "move keyword" suggestion for async gen block) - rust-lang#139880 (Don't compute name of associated item if it's an RPITIT) - rust-lang#139884 (Update books) - rust-lang#139886 (`borrowck_graphviz_*` attribute tweaks) r? `@ghost` `@rustbot` modify labels: rollup
2 parents efb1e3d + de14c03 commit 245e65c

File tree

43 files changed

+479
-160
lines changed

Some content is hidden

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

43 files changed

+479
-160
lines changed

Diff for: compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -3376,10 +3376,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
33763376

33773377
let (sugg_span, suggestion) = match tcx.sess.source_map().span_to_snippet(args_span) {
33783378
Ok(string) => {
3379-
let coro_prefix = if string.starts_with("async") {
3380-
// `async` is 5 chars long. Not using `.len()` to avoid the cast from `usize`
3381-
// to `u32`.
3382-
Some(5)
3379+
let coro_prefix = if let Some(sub) = string.strip_prefix("async") {
3380+
let trimmed_sub = sub.trim_end();
3381+
if trimmed_sub.ends_with("gen") {
3382+
// `async` is 5 chars long.
3383+
Some((trimmed_sub.len() + 5) as _)
3384+
} else {
3385+
// `async` is 5 chars long.
3386+
Some(5)
3387+
}
33833388
} else if string.starts_with("gen") {
33843389
// `gen` is 3 chars long
33853390
Some(3)

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
204204
.iter()
205205
.flat_map(|trait_def_id| tcx.associated_items(*trait_def_id).in_definition_order())
206206
.filter_map(|item| {
207-
(!item.is_impl_trait_in_trait() && item.as_tag() == assoc_tag)
208-
.then_some(item.name())
207+
(!item.is_impl_trait_in_trait() && item.as_tag() == assoc_tag).then(|| item.name())
209208
})
210209
.collect();
211210

Diff for: compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ fn test_codegen_options_tracking_hash() {
614614
tracked!(control_flow_guard, CFGuard::Checks);
615615
tracked!(debug_assertions, Some(true));
616616
tracked!(debuginfo, DebugInfo::Limited);
617+
tracked!(dwarf_version, Some(5));
617618
tracked!(embed_bitcode, false);
618619
tracked!(force_frame_pointers, FramePointer::Always);
619620
tracked!(force_unwind_tables, Some(true));

Diff for: compiler/rustc_mir_dataflow/src/framework/graphviz.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl RustcMirAttrs {
122122
})
123123
} else if attr.has_name(sym::borrowck_graphviz_format) {
124124
Self::set_field(&mut ret.formatter, tcx, &attr, |s| match s {
125-
sym::gen_kill | sym::two_phase => Ok(s),
125+
sym::two_phase => Ok(s),
126126
_ => {
127127
tcx.dcx().emit_err(UnknownFormatter { span: attr.span() });
128128
Err(())

Diff for: compiler/rustc_session/src/config.rs

+5-34
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::str::{self, FromStr};
1414
use std::sync::LazyLock;
1515
use std::{cmp, fmt, fs, iter};
1616

17+
use externs::{ExternOpt, split_extern_opt};
1718
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
1819
use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey};
1920
use rustc_errors::emitter::HumanReadableErrorType;
@@ -39,6 +40,7 @@ use crate::utils::CanonicalizedPath;
3940
use crate::{EarlyDiagCtxt, HashStableContext, Session, filesearch, lint};
4041

4142
mod cfg;
43+
mod externs;
4244
mod native_libs;
4345
pub mod sigpipe;
4446

@@ -2205,44 +2207,13 @@ pub fn parse_externs(
22052207
matches: &getopts::Matches,
22062208
unstable_opts: &UnstableOptions,
22072209
) -> Externs {
2208-
fn is_ascii_ident(string: &str) -> bool {
2209-
let mut chars = string.chars();
2210-
if let Some(start) = chars.next()
2211-
&& (start.is_ascii_alphabetic() || start == '_')
2212-
{
2213-
chars.all(|char| char.is_ascii_alphanumeric() || char == '_')
2214-
} else {
2215-
false
2216-
}
2217-
}
2218-
22192210
let is_unstable_enabled = unstable_opts.unstable_options;
22202211
let mut externs: BTreeMap<String, ExternEntry> = BTreeMap::new();
22212212
for arg in matches.opt_strs("extern") {
2222-
let (name, path) = match arg.split_once('=') {
2223-
None => (arg, None),
2224-
Some((name, path)) => (name.to_string(), Some(Path::new(path))),
2225-
};
2226-
let (options, name) = match name.split_once(':') {
2227-
None => (None, name),
2228-
Some((opts, name)) => (Some(opts), name.to_string()),
2229-
};
2230-
2231-
if !is_ascii_ident(&name) {
2232-
let mut error = early_dcx.early_struct_fatal(format!(
2233-
"crate name `{name}` passed to `--extern` is not a valid ASCII identifier"
2234-
));
2235-
let adjusted_name = name.replace('-', "_");
2236-
if is_ascii_ident(&adjusted_name) {
2237-
#[allow(rustc::diagnostic_outside_of_impl)] // FIXME
2238-
error.help(format!(
2239-
"consider replacing the dashes with underscores: `{adjusted_name}`"
2240-
));
2241-
}
2242-
error.emit();
2243-
}
2213+
let ExternOpt { crate_name: name, path, options } =
2214+
split_extern_opt(early_dcx, unstable_opts, &arg).unwrap_or_else(|e| e.emit());
22442215

2245-
let path = path.map(|p| CanonicalizedPath::new(p));
2216+
let path = path.map(|p| CanonicalizedPath::new(p.as_path()));
22462217

22472218
let entry = externs.entry(name.to_owned());
22482219

Diff for: compiler/rustc_session/src/config/externs.rs

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//! This module contains code to help parse and manipulate `--extern` arguments.
2+
3+
use std::path::PathBuf;
4+
5+
use rustc_errors::{Diag, FatalAbort};
6+
7+
use super::UnstableOptions;
8+
use crate::EarlyDiagCtxt;
9+
10+
#[cfg(test)]
11+
mod tests;
12+
13+
/// Represents the pieces of an `--extern` argument.
14+
pub(crate) struct ExternOpt {
15+
pub(crate) crate_name: String,
16+
pub(crate) path: Option<PathBuf>,
17+
pub(crate) options: Option<String>,
18+
}
19+
20+
/// Breaks out the major components of an `--extern` argument.
21+
///
22+
/// The options field will be a string containing comma-separated options that will need further
23+
/// parsing and processing.
24+
pub(crate) fn split_extern_opt<'a>(
25+
early_dcx: &'a EarlyDiagCtxt,
26+
unstable_opts: &UnstableOptions,
27+
extern_opt: &str,
28+
) -> Result<ExternOpt, Diag<'a, FatalAbort>> {
29+
let (name, path) = match extern_opt.split_once('=') {
30+
None => (extern_opt.to_string(), None),
31+
Some((name, path)) => (name.to_string(), Some(PathBuf::from(path))),
32+
};
33+
let (options, crate_name) = match name.split_once(':') {
34+
None => (None, name),
35+
Some((opts, crate_name)) => {
36+
if unstable_opts.namespaced_crates && crate_name.starts_with(':') {
37+
// If the name starts with `:`, we know this was actually something like `foo::bar` and
38+
// not a set of options. We can just use the original name as the crate name.
39+
(None, name)
40+
} else {
41+
(Some(opts.to_string()), crate_name.to_string())
42+
}
43+
}
44+
};
45+
46+
if !valid_crate_name(&crate_name, unstable_opts) {
47+
let mut error = early_dcx.early_struct_fatal(format!(
48+
"crate name `{crate_name}` passed to `--extern` is not a valid ASCII identifier"
49+
));
50+
let adjusted_name = crate_name.replace('-', "_");
51+
if is_ascii_ident(&adjusted_name) {
52+
#[allow(rustc::diagnostic_outside_of_impl)] // FIXME
53+
error
54+
.help(format!("consider replacing the dashes with underscores: `{adjusted_name}`"));
55+
}
56+
return Err(error);
57+
}
58+
59+
Ok(ExternOpt { crate_name, path, options })
60+
}
61+
62+
fn valid_crate_name(name: &str, unstable_opts: &UnstableOptions) -> bool {
63+
match name.split_once("::") {
64+
Some((a, b)) if unstable_opts.namespaced_crates => is_ascii_ident(a) && is_ascii_ident(b),
65+
Some(_) => false,
66+
None => is_ascii_ident(name),
67+
}
68+
}
69+
70+
fn is_ascii_ident(string: &str) -> bool {
71+
let mut chars = string.chars();
72+
if let Some(start) = chars.next()
73+
&& (start.is_ascii_alphabetic() || start == '_')
74+
{
75+
chars.all(|char| char.is_ascii_alphanumeric() || char == '_')
76+
} else {
77+
false
78+
}
79+
}

Diff for: compiler/rustc_session/src/config/externs/tests.rs

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
use std::path::PathBuf;
2+
3+
use super::split_extern_opt;
4+
use crate::EarlyDiagCtxt;
5+
use crate::config::UnstableOptions;
6+
7+
/// Verifies split_extern_opt handles the supported cases.
8+
#[test]
9+
fn test_split_extern_opt() {
10+
let early_dcx = EarlyDiagCtxt::new(<_>::default());
11+
let unstable_opts = &UnstableOptions::default();
12+
13+
let extern_opt =
14+
split_extern_opt(&early_dcx, unstable_opts, "priv,noprelude:foo=libbar.rlib").unwrap();
15+
assert_eq!(extern_opt.crate_name, "foo");
16+
assert_eq!(extern_opt.path, Some(PathBuf::from("libbar.rlib")));
17+
assert_eq!(extern_opt.options, Some("priv,noprelude".to_string()));
18+
19+
let extern_opt = split_extern_opt(&early_dcx, unstable_opts, "priv,noprelude:foo").unwrap();
20+
assert_eq!(extern_opt.crate_name, "foo");
21+
assert_eq!(extern_opt.path, None);
22+
assert_eq!(extern_opt.options, Some("priv,noprelude".to_string()));
23+
24+
let extern_opt = split_extern_opt(&early_dcx, unstable_opts, "foo=libbar.rlib").unwrap();
25+
assert_eq!(extern_opt.crate_name, "foo");
26+
assert_eq!(extern_opt.path, Some(PathBuf::from("libbar.rlib")));
27+
assert_eq!(extern_opt.options, None);
28+
29+
let extern_opt = split_extern_opt(&early_dcx, unstable_opts, "foo").unwrap();
30+
assert_eq!(extern_opt.crate_name, "foo");
31+
assert_eq!(extern_opt.path, None);
32+
assert_eq!(extern_opt.options, None);
33+
}
34+
35+
/// Tests some invalid cases for split_extern_opt.
36+
#[test]
37+
fn test_split_extern_opt_invalid() {
38+
let early_dcx = EarlyDiagCtxt::new(<_>::default());
39+
let unstable_opts = &UnstableOptions::default();
40+
41+
// too many `:`s
42+
let result = split_extern_opt(&early_dcx, unstable_opts, "priv:noprelude:foo=libbar.rlib");
43+
assert!(result.is_err());
44+
let _ = result.map_err(|e| e.cancel());
45+
46+
// can't nest externs without the unstable flag
47+
let result = split_extern_opt(&early_dcx, unstable_opts, "noprelude:foo::bar=libbar.rlib");
48+
assert!(result.is_err());
49+
let _ = result.map_err(|e| e.cancel());
50+
}
51+
52+
/// Tests some cases for split_extern_opt with nested crates like `foo::bar`.
53+
#[test]
54+
fn test_split_extern_opt_nested() {
55+
let early_dcx = EarlyDiagCtxt::new(<_>::default());
56+
let unstable_opts = &UnstableOptions { namespaced_crates: true, ..Default::default() };
57+
58+
let extern_opt =
59+
split_extern_opt(&early_dcx, unstable_opts, "priv,noprelude:foo::bar=libbar.rlib").unwrap();
60+
assert_eq!(extern_opt.crate_name, "foo::bar");
61+
assert_eq!(extern_opt.path, Some(PathBuf::from("libbar.rlib")));
62+
assert_eq!(extern_opt.options, Some("priv,noprelude".to_string()));
63+
64+
let extern_opt =
65+
split_extern_opt(&early_dcx, unstable_opts, "priv,noprelude:foo::bar").unwrap();
66+
assert_eq!(extern_opt.crate_name, "foo::bar");
67+
assert_eq!(extern_opt.path, None);
68+
assert_eq!(extern_opt.options, Some("priv,noprelude".to_string()));
69+
70+
let extern_opt = split_extern_opt(&early_dcx, unstable_opts, "foo::bar=libbar.rlib").unwrap();
71+
assert_eq!(extern_opt.crate_name, "foo::bar");
72+
assert_eq!(extern_opt.path, Some(PathBuf::from("libbar.rlib")));
73+
assert_eq!(extern_opt.options, None);
74+
75+
let extern_opt = split_extern_opt(&early_dcx, unstable_opts, "foo::bar").unwrap();
76+
assert_eq!(extern_opt.crate_name, "foo::bar");
77+
assert_eq!(extern_opt.path, None);
78+
assert_eq!(extern_opt.options, None);
79+
}
80+
81+
/// Tests some invalid cases for split_extern_opt with nested crates like `foo::bar`.
82+
#[test]
83+
fn test_split_extern_opt_nested_invalid() {
84+
let early_dcx = EarlyDiagCtxt::new(<_>::default());
85+
let unstable_opts = &UnstableOptions { namespaced_crates: true, ..Default::default() };
86+
87+
// crates can only be nested one deep.
88+
let result =
89+
split_extern_opt(&early_dcx, unstable_opts, "priv,noprelude:foo::bar::baz=libbar.rlib");
90+
assert!(result.is_err());
91+
let _ = result.map_err(|e| e.cancel());
92+
}

Diff for: compiler/rustc_session/src/options.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,9 @@ options! {
19561956
"allow the linker to link its default libraries (default: no)"),
19571957
dlltool: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
19581958
"import library generation tool (ignored except when targeting windows-gnu)"),
1959+
#[rustc_lint_opt_deny_field_access("use `Session::dwarf_version` instead of this field")]
1960+
dwarf_version: Option<u32> = (None, parse_opt_number, [TRACKED],
1961+
"version of DWARF debug information to emit (default: 2 or 4, depending on platform)"),
19591962
embed_bitcode: bool = (true, parse_bool, [TRACKED],
19601963
"emit bitcode in rlibs (default: yes)"),
19611964
extra_filename: String = (String::new(), parse_string, [UNTRACKED],
@@ -2331,6 +2334,8 @@ options! {
23312334
"the size at which the `large_assignments` lint starts to be emitted"),
23322335
mutable_noalias: bool = (true, parse_bool, [TRACKED],
23332336
"emit noalias metadata for mutable references (default: yes)"),
2337+
namespaced_crates: bool = (false, parse_bool, [TRACKED],
2338+
"allow crates to be namespaced by other crates (default: no)"),
23342339
next_solver: NextSolverConfig = (NextSolverConfig::default(), parse_next_solver_config, [TRACKED],
23352340
"enable and configure the next generation trait solver used by rustc"),
23362341
nll_facts: bool = (false, parse_bool, [UNTRACKED],

Diff for: compiler/rustc_session/src/session.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,11 @@ impl Session {
764764

765765
/// Returns the DWARF version passed on the CLI or the default for the target.
766766
pub fn dwarf_version(&self) -> u32 {
767-
self.opts.unstable_opts.dwarf_version.unwrap_or(self.target.default_dwarf_version)
767+
self.opts
768+
.cg
769+
.dwarf_version
770+
.or(self.opts.unstable_opts.dwarf_version)
771+
.unwrap_or(self.target.default_dwarf_version)
768772
}
769773

770774
pub fn stack_protector(&self) -> StackProtector {
@@ -1327,7 +1331,9 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
13271331
sess.dcx().emit_err(errors::BranchProtectionRequiresAArch64);
13281332
}
13291333

1330-
if let Some(dwarf_version) = sess.opts.unstable_opts.dwarf_version {
1334+
if let Some(dwarf_version) =
1335+
sess.opts.cg.dwarf_version.or(sess.opts.unstable_opts.dwarf_version)
1336+
{
13311337
// DWARF 1 is not supported by LLVM and DWARF 6 is not yet finalized.
13321338
if dwarf_version < 2 || dwarf_version > 5 {
13331339
sess.dcx().emit_err(errors::UnsupportedDwarfVersion { dwarf_version });

Diff for: compiler/rustc_span/src/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,6 @@ symbols! {
10681068
ge,
10691069
gen_blocks,
10701070
gen_future,
1071-
gen_kill,
10721071
generator_clone,
10731072
generators,
10741073
generic_arg_infer,

Diff for: src/bootstrap/src/core/build_steps/compile.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl Step for Std {
155155

156156
// When using `download-rustc`, we already have artifacts for the host available. Don't
157157
// recompile them.
158-
if builder.download_rustc() && builder.is_builder_target(target)
158+
if builder.download_rustc() && builder.config.is_host_target(target)
159159
// NOTE: the beta compiler may generate different artifacts than the downloaded compiler, so
160160
// its artifacts can't be reused.
161161
&& compiler.stage != 0
@@ -229,7 +229,7 @@ impl Step for Std {
229229
// The LLD wrappers and `rust-lld` are self-contained linking components that can be
230230
// necessary to link the stdlib on some targets. We'll also need to copy these binaries to
231231
// the `stage0-sysroot` to ensure the linker is found when bootstrapping on such a target.
232-
if compiler.stage == 0 && builder.is_builder_target(compiler.host) {
232+
if compiler.stage == 0 && builder.config.is_host_target(compiler.host) {
233233
trace!(
234234
"(build == host) copying linking components to `stage0-sysroot` for bootstrapping"
235235
);
@@ -1374,7 +1374,7 @@ pub fn rustc_cargo_env(
13741374
/// Pass down configuration from the LLVM build into the build of
13751375
/// rustc_llvm and rustc_codegen_llvm.
13761376
fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelection) {
1377-
if builder.is_rust_llvm(target) {
1377+
if builder.config.is_rust_llvm(target) {
13781378
cargo.env("LLVM_RUSTLLVM", "1");
13791379
}
13801380
if builder.config.llvm_enzyme {
@@ -2182,7 +2182,7 @@ impl Step for Assemble {
21822182
debug!("copying codegen backends to sysroot");
21832183
copy_codegen_backends_to_sysroot(builder, build_compiler, target_compiler);
21842184

2185-
if builder.config.lld_enabled {
2185+
if builder.config.lld_enabled && !builder.config.is_system_llvm(target_compiler.host) {
21862186
builder.ensure(crate::core::build_steps::tool::LldWrapper {
21872187
build_compiler,
21882188
target_compiler,
@@ -2532,7 +2532,9 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
25322532
// FIXME: to make things simpler for now, limit this to the host and target where we know
25332533
// `strip -g` is both available and will fix the issue, i.e. on a x64 linux host that is not
25342534
// cross-compiling. Expand this to other appropriate targets in the future.
2535-
if target != "x86_64-unknown-linux-gnu" || !builder.is_builder_target(target) || !path.exists()
2535+
if target != "x86_64-unknown-linux-gnu"
2536+
|| !builder.config.is_host_target(target)
2537+
|| !path.exists()
25362538
{
25372539
return;
25382540
}

0 commit comments

Comments
 (0)