Skip to content

Commit bdef683

Browse files
committed
Auto merge of rust-lang#126446 - workingjubilee:rollup-esdbgdw, r=workingjubilee
Rollup of 8 pull requests Successful merges: - rust-lang#121216 (Always emit `native-static-libs` note, even if it is empty) - rust-lang#123726 (Clarify `Command::new` behavior for programs with arguments) - rust-lang#125722 (Indicate in `non_local_defs` lint that the macro needs to change) - rust-lang#126088 ([1/2] clean-up / general improvements) - rust-lang#126390 (Fix wording in {checked_}next_power_of_two) - rust-lang#126392 (Small style improvement in `gvn.rs`) - rust-lang#126402 (Fix wrong `assert_unsafe_precondition` message for `core::ptr::copy`) - rust-lang#126445 (Remove failing GUI test to stop blocking CI until it is fixed) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f158600 + b7c8b09 commit bdef683

File tree

40 files changed

+209
-249
lines changed

40 files changed

+209
-249
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -1561,17 +1561,13 @@ fn print_native_static_libs(
15611561
match out {
15621562
OutFileName::Real(path) => {
15631563
out.overwrite(&lib_args.join(" "), sess);
1564-
if !lib_args.is_empty() {
1565-
sess.dcx().emit_note(errors::StaticLibraryNativeArtifactsToFile { path });
1566-
}
1564+
sess.dcx().emit_note(errors::StaticLibraryNativeArtifactsToFile { path });
15671565
}
15681566
OutFileName::Stdout => {
1569-
if !lib_args.is_empty() {
1570-
sess.dcx().emit_note(errors::StaticLibraryNativeArtifacts);
1571-
// Prefix for greppability
1572-
// Note: This must not be translated as tools are allowed to depend on this exact string.
1573-
sess.dcx().note(format!("native-static-libs: {}", &lib_args.join(" ")));
1574-
}
1567+
sess.dcx().emit_note(errors::StaticLibraryNativeArtifacts);
1568+
// Prefix for greppability
1569+
// Note: This must not be translated as tools are allowed to depend on this exact string.
1570+
sess.dcx().note(format!("native-static-libs: {}", &lib_args.join(" ")));
15751571
}
15761572
}
15771573
}

compiler/rustc_lint/messages.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ lint_non_local_definitions_impl = non-local `impl` definition, `impl` blocks sho
550550
.bounds = `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
551551
.exception = items in an anonymous const item (`const _: () = {"{"} ... {"}"}`) are treated as in the same scope as the anonymous const's declaration
552552
.const_anon = use a const-anon item to suppress this lint
553+
.macro_to_change = the {$macro_kind} `{$macro_to_change}` defines the non-local `impl`, and may need to be changed
553554
554555
lint_non_local_definitions_impl_move_help =
555556
move the `impl` block outside of this {$body_kind_descr} {$depth ->

compiler/rustc_lint/src/lints.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,7 @@ pub enum NonLocalDefinitionsDiag {
13621362
has_trait: bool,
13631363
self_ty_str: String,
13641364
of_trait_str: Option<String>,
1365+
macro_to_change: Option<(String, &'static str)>,
13651366
},
13661367
MacroRules {
13671368
depth: u32,
@@ -1387,6 +1388,7 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
13871388
has_trait,
13881389
self_ty_str,
13891390
of_trait_str,
1391+
macro_to_change,
13901392
} => {
13911393
diag.primary_message(fluent::lint_non_local_definitions_impl);
13921394
diag.arg("depth", depth);
@@ -1397,6 +1399,15 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
13971399
diag.arg("of_trait_str", of_trait_str);
13981400
}
13991401

1402+
if let Some((macro_to_change, macro_kind)) = macro_to_change {
1403+
diag.arg("macro_to_change", macro_to_change);
1404+
diag.arg("macro_kind", macro_kind);
1405+
diag.note(fluent::lint_macro_to_change);
1406+
}
1407+
if let Some(cargo_update) = cargo_update {
1408+
diag.subdiagnostic(&diag.dcx, cargo_update);
1409+
}
1410+
14001411
if has_trait {
14011412
diag.note(fluent::lint_bounds);
14021413
diag.note(fluent::lint_with_trait);
@@ -1422,9 +1433,6 @@ impl<'a> LintDiagnostic<'a, ()> for NonLocalDefinitionsDiag {
14221433
);
14231434
}
14241435

1425-
if let Some(cargo_update) = cargo_update {
1426-
diag.subdiagnostic(&diag.dcx, cargo_update);
1427-
}
14281436
if let Some(const_anon) = const_anon {
14291437
diag.note(fluent::lint_exception);
14301438
if let Some(const_anon) = const_anon {

compiler/rustc_lint/src/non_local_def.rs

+8
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
258258
Some((cx.tcx.def_span(parent), may_move))
259259
};
260260

261+
let macro_to_change =
262+
if let ExpnKind::Macro(kind, name) = item.span.ctxt().outer_expn_data().kind {
263+
Some((name.to_string(), kind.descr()))
264+
} else {
265+
None
266+
};
267+
261268
cx.emit_span_lint(
262269
NON_LOCAL_DEFINITIONS,
263270
ms,
@@ -274,6 +281,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
274281
move_to,
275282
may_remove,
276283
has_trait: impl_.of_trait.is_some(),
284+
macro_to_change,
277285
},
278286
)
279287
}

compiler/rustc_mir_transform/src/gvn.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
330330
let is_sized = !self.feature_unsized_locals
331331
|| self.local_decls[local].ty.is_sized(self.tcx, self.param_env);
332332
if is_sized {
333-
self.rev_locals.ensure_contains_elem(value, SmallVec::new);
334-
self.rev_locals[value].push(local);
333+
self.rev_locals.ensure_contains_elem(value, SmallVec::new).push(local);
335334
}
336335
}
337336

library/core/src/intrinsics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3043,8 +3043,7 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
30433043
unsafe {
30443044
ub_checks::assert_unsafe_precondition!(
30453045
check_language_ub,
3046-
"ptr::copy_nonoverlapping requires that both pointer arguments are aligned and non-null \
3047-
and the specified memory ranges do not overlap",
3046+
"ptr::copy requires that both pointer arguments are aligned and non-null",
30483047
(
30493048
src: *const () = src as *const (),
30503049
dst: *mut () = dst as *mut (),

library/core/src/num/nonzero.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
10591059
unsafe { Self::new_unchecked(self.get().unchecked_add(other)) }
10601060
}
10611061

1062-
/// Returns the smallest power of two greater than or equal to n.
1062+
/// Returns the smallest power of two greater than or equal to `self`.
10631063
/// Checks for overflow and returns [`None`]
10641064
/// if the next power of two is greater than the type’s maximum value.
10651065
/// As a consequence, the result cannot wrap to zero.

library/core/src/num/uint_macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2830,7 +2830,7 @@ macro_rules! uint_impl {
28302830
///
28312831
/// When return value overflows (i.e., `self > (1 << (N-1))` for type
28322832
/// `uN`), it panics in debug mode and the return value is wrapped to 0 in
2833-
/// release mode (the only situation in which method can return 0).
2833+
/// release mode (the only situation in which this method can return 0).
28342834
///
28352835
/// # Examples
28362836
///
@@ -2851,7 +2851,7 @@ macro_rules! uint_impl {
28512851
self.one_less_than_next_power_of_two() + 1
28522852
}
28532853

2854-
/// Returns the smallest power of two greater than or equal to `n`. If
2854+
/// Returns the smallest power of two greater than or equal to `self`. If
28552855
/// the next power of two is greater than the type's maximum value,
28562856
/// `None` is returned, otherwise the power of two is wrapped in `Some`.
28572857
///

library/std/src/process.rs

+19
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,25 @@ impl Command {
629629
/// .spawn()
630630
/// .expect("sh command failed to start");
631631
/// ```
632+
///
633+
/// # Caveats
634+
///
635+
/// [`Command::new`] is only intended to accept the path of the program. If you pass a program
636+
/// path along with arguments like `Command::new("ls -l").spawn()`, it will try to search for
637+
/// `ls -l` literally. The arguments need to be passed separately, such as via [`arg`] or
638+
/// [`args`].
639+
///
640+
/// ```no_run
641+
/// use std::process::Command;
642+
///
643+
/// Command::new("ls")
644+
/// .arg("-l") // arg passed separately
645+
/// .spawn()
646+
/// .expect("ls command failed to start");
647+
/// ```
648+
///
649+
/// [`arg`]: Self::arg
650+
/// [`args`]: Self::args
632651
#[stable(feature = "process", since = "1.0.0")]
633652
pub fn new<S: AsRef<OsStr>>(program: S) -> Command {
634653
Command { inner: imp::Command::new(program.as_ref()) }

src/bootstrap/src/core/build_steps/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn get_modified_rs_files(build: &Builder<'_>) -> Result<Option<Vec<String>>, Str
9393
return Ok(None);
9494
}
9595

96-
get_git_modified_files(&build.config.git_config(), Some(&build.config.src), &vec!["rs"])
96+
get_git_modified_files(&build.config.git_config(), Some(&build.config.src), &["rs"])
9797
}
9898

9999
#[derive(serde_derive::Deserialize)]

src/tools/build-manifest/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl Builder {
495495
Some(p) => p,
496496
None => return false,
497497
};
498-
pkg.target.get(&c.target).is_some()
498+
pkg.target.contains_key(&c.target)
499499
};
500500
extensions.retain(&has_component);
501501
components.retain(&has_component);

src/tools/build_helper/src/git.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn output_result(cmd: &mut Command) -> Result<String, String> {
2121
String::from_utf8(output.stderr).map_err(|err| format!("{err:?}"))?
2222
));
2323
}
24-
Ok(String::from_utf8(output.stdout).map_err(|err| format!("{err:?}"))?)
24+
String::from_utf8(output.stdout).map_err(|err| format!("{err:?}"))
2525
}
2626

2727
/// Finds the remote for rust-lang/rust.
@@ -64,18 +64,14 @@ pub fn rev_exists(rev: &str, git_dir: Option<&Path>) -> Result<bool, String> {
6464
match output.status.code() {
6565
Some(0) => Ok(true),
6666
Some(128) => Ok(false),
67-
None => {
68-
return Err(format!(
69-
"git didn't exit properly: {}",
70-
String::from_utf8(output.stderr).map_err(|err| format!("{err:?}"))?
71-
));
72-
}
73-
Some(code) => {
74-
return Err(format!(
75-
"git command exited with status code: {code}: {}",
76-
String::from_utf8(output.stderr).map_err(|err| format!("{err:?}"))?
77-
));
78-
}
67+
None => Err(format!(
68+
"git didn't exit properly: {}",
69+
String::from_utf8(output.stderr).map_err(|err| format!("{err:?}"))?
70+
)),
71+
Some(code) => Err(format!(
72+
"git command exited with status code: {code}: {}",
73+
String::from_utf8(output.stderr).map_err(|err| format!("{err:?}"))?
74+
)),
7975
}
8076
}
8177

@@ -96,7 +92,7 @@ pub fn updated_master_branch(
9692
}
9793
}
9894

99-
Err(format!("Cannot find any suitable upstream master branch"))
95+
Err("Cannot find any suitable upstream master branch".to_owned())
10096
}
10197

10298
pub fn get_git_merge_base(
@@ -118,7 +114,7 @@ pub fn get_git_merge_base(
118114
pub fn get_git_modified_files(
119115
config: &GitConfig<'_>,
120116
git_dir: Option<&Path>,
121-
extensions: &Vec<&str>,
117+
extensions: &[&str],
122118
) -> Result<Option<Vec<String>>, String> {
123119
let merge_base = get_git_merge_base(config, git_dir)?;
124120

src/tools/compiletest/src/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ impl TargetCfgs {
582582
name,
583583
Some(
584584
value
585-
.strip_suffix("\"")
585+
.strip_suffix('\"')
586586
.expect("key-value pair should be properly quoted"),
587587
),
588588
)

src/tools/compiletest/src/header.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl EarlyProps {
8282
panic!("errors encountered during EarlyProps parsing");
8383
}
8484

85-
return props;
85+
props
8686
}
8787
}
8888

@@ -382,7 +382,7 @@ impl TestProps {
382382
// Individual flags can be single-quoted to preserve spaces; see
383383
// <https://github.com/rust-lang/rust/pull/115948/commits/957c5db6>.
384384
flags
385-
.split("'")
385+
.split('\'')
386386
.enumerate()
387387
.flat_map(|(i, f)| {
388388
if i % 2 == 1 { vec![f] } else { f.split_whitespace().collect() }
@@ -613,7 +613,7 @@ impl TestProps {
613613

614614
for key in &["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
615615
if let Ok(val) = env::var(key) {
616-
if self.exec_env.iter().find(|&&(ref x, _)| x == key).is_none() {
616+
if !self.exec_env.iter().any(|&(ref x, _)| x == key) {
617617
self.exec_env.push(((*key).to_owned(), val))
618618
}
619619
}
@@ -991,7 +991,7 @@ pub(crate) fn check_directive(directive_ln: &str) -> CheckDirectiveResult<'_> {
991991
let trailing = post.trim().split_once(' ').map(|(pre, _)| pre).unwrap_or(post);
992992
let trailing_directive = {
993993
// 1. is the directive name followed by a space? (to exclude `:`)
994-
matches!(directive_ln.get(directive_name.len()..), Some(s) if s.starts_with(" "))
994+
matches!(directive_ln.get(directive_name.len()..), Some(s) if s.starts_with(' '))
995995
// 2. is what is after that directive also a directive (ex: "only-x86 only-arm")
996996
&& KNOWN_DIRECTIVE_NAMES.contains(&trailing)
997997
}
@@ -1363,7 +1363,7 @@ pub fn extract_llvm_version_from_binary(binary_path: &str) -> Option<u32> {
13631363
}
13641364
let version = String::from_utf8(output.stdout).ok()?;
13651365
for line in version.lines() {
1366-
if let Some(version) = line.split("LLVM version ").skip(1).next() {
1366+
if let Some(version) = line.split("LLVM version ").nth(1) {
13671367
return extract_llvm_version(version);
13681368
}
13691369
}
@@ -1394,7 +1394,7 @@ where
13941394

13951395
let min = parse(min)?;
13961396
let max = match max {
1397-
Some(max) if max.is_empty() => return None,
1397+
Some("") => return None,
13981398
Some(max) => parse(max)?,
13991399
_ => min,
14001400
};
@@ -1466,12 +1466,12 @@ pub fn make_test_description<R: Read>(
14661466
decision!(ignore_gdb(config, ln));
14671467
decision!(ignore_lldb(config, ln));
14681468

1469-
if config.target == "wasm32-unknown-unknown" {
1470-
if config.parse_name_directive(ln, directives::CHECK_RUN_RESULTS) {
1471-
decision!(IgnoreDecision::Ignore {
1472-
reason: "ignored on WASM as the run results cannot be checked there".into(),
1473-
});
1474-
}
1469+
if config.target == "wasm32-unknown-unknown"
1470+
&& config.parse_name_directive(ln, directives::CHECK_RUN_RESULTS)
1471+
{
1472+
decision!(IgnoreDecision::Ignore {
1473+
reason: "ignored on WASM as the run results cannot be checked there".into(),
1474+
});
14751475
}
14761476

14771477
should_fail |= config.parse_name_directive(ln, "should-fail");

src/tools/compiletest/src/header/cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(super) fn parse_cfg_name_directive<'a>(
5858

5959
// Some of the matchers might be "" depending on what the target information is. To avoid
6060
// problems we outright reject empty directives.
61-
if name == "" {
61+
if name.is_empty() {
6262
return ParsedNameDirective::not_a_directive();
6363
}
6464

src/tools/compiletest/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ fn extract_lldb_version(full_version_line: &str) -> Option<(u32, bool)> {
11471147
}
11481148

11491149
fn not_a_digit(c: char) -> bool {
1150-
!c.is_digit(10)
1150+
!c.is_ascii_digit()
11511151
}
11521152

11531153
fn check_overlapping_tests(found_paths: &HashSet<PathBuf>) {

src/tools/compiletest/src/read2.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ mod tests;
66

77
pub use self::imp::read2;
88
use std::io::{self, Write};
9-
use std::mem::replace;
109
use std::process::{Child, Output};
1110

1211
#[derive(Copy, Clone, Debug)]
@@ -101,10 +100,10 @@ impl ProcOutput {
101100
return;
102101
}
103102

104-
let mut head = replace(bytes, Vec::new());
103+
let mut head = std::mem::take(bytes);
105104
// Don't truncate if this as a whole line.
106105
// That should make it less likely that we cut a JSON line in half.
107-
if head.last() != Some(&('\n' as u8)) {
106+
if head.last() != Some(&b'\n') {
108107
head.truncate(MAX_OUT_LEN);
109108
}
110109
let skipped = new_len - head.len();

src/tools/compiletest/src/read2/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ fn test_abbreviate_filterss_are_detected() {
6464
#[test]
6565
fn test_abbreviate_filters_avoid_abbreviations() {
6666
let mut out = ProcOutput::new();
67-
let filters = &[std::iter::repeat('a').take(64).collect::<String>()];
67+
let filters = &["a".repeat(64)];
6868

69-
let mut expected = vec![b'.'; MAX_OUT_LEN - FILTERED_PATHS_PLACEHOLDER_LEN as usize];
69+
let mut expected = vec![b'.'; MAX_OUT_LEN - FILTERED_PATHS_PLACEHOLDER_LEN];
7070
expected.extend_from_slice(filters[0].as_bytes());
7171

7272
out.extend(&expected, filters);
@@ -81,7 +81,7 @@ fn test_abbreviate_filters_avoid_abbreviations() {
8181
#[test]
8282
fn test_abbreviate_filters_can_still_cause_abbreviations() {
8383
let mut out = ProcOutput::new();
84-
let filters = &[std::iter::repeat('a').take(64).collect::<String>()];
84+
let filters = &["a".repeat(64)];
8585

8686
let mut input = vec![b'.'; MAX_OUT_LEN];
8787
input.extend_from_slice(filters[0].as_bytes());

0 commit comments

Comments
 (0)