Skip to content

Commit d7e942e

Browse files
authored
Merge pull request #4151 from rust-lang/rustup-2025-01-26
Automatic Rustup
2 parents 57eabac + c688ecf commit d7e942e

File tree

284 files changed

+2794
-1515
lines changed

Some content is hidden

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

284 files changed

+2794
-1515
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3537,6 +3537,7 @@ dependencies = [
35373537
"ar_archive_writer",
35383538
"arrayvec",
35393539
"bitflags",
3540+
"bstr",
35403541
"cc",
35413542
"either",
35423543
"itertools",

RELEASES.md

+1
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ Libraries
573573
- [Replace sort implementations with stable `driftsort` and unstable `ipnsort`.](https://github.com/rust-lang/rust/pull/124032/) All `slice::sort*` and `slice::select_nth*` methods are expected to see significant performance improvements. See the [research project](https://github.com/Voultapher/sort-research-rs) for more details.
574574
- [Document behavior of `create_dir_all` with respect to empty paths.](https://github.com/rust-lang/rust/pull/125112/)
575575
- [Fix interleaved output in the default panic hook when multiple threads panic simultaneously.](https://github.com/rust-lang/rust/pull/127397/)
576+
- Fix `Command`'s batch files argument escaping not working when file name has trailing whitespace or periods (CVE-2024-43402).
576577

577578
<a id="1.81.0-Stabilized-APIs"></a>
578579

compiler/rustc_attr_data_structures/src/attributes.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,25 @@ pub enum InstructionSetAttr {
3535
ArmT32,
3636
}
3737

38-
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)]
38+
#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, HashStable_Generic, Default)]
3939
pub enum OptimizeAttr {
40-
None,
40+
/// No `#[optimize(..)]` attribute
41+
#[default]
42+
Default,
43+
/// `#[optimize(none)]`
44+
DoNotOptimize,
45+
/// `#[optimize(speed)]`
4146
Speed,
47+
/// `#[optimize(size)]`
4248
Size,
4349
}
4450

51+
impl OptimizeAttr {
52+
pub fn do_not_optimize(&self) -> bool {
53+
matches!(self, Self::DoNotOptimize)
54+
}
55+
}
56+
4557
#[derive(Clone, Debug, Encodable, Decodable)]
4658
pub enum DiagnosticAttribute {
4759
// tidy-alphabetical-start

compiler/rustc_borrowck/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ borrowck_lifetime_constraints_error =
9292
borrowck_limitations_implies_static =
9393
due to current limitations in the borrow checker, this implies a `'static` lifetime
9494
95+
borrowck_long_type_consider_verbose = consider using `--verbose` to print the full type name to the console
96+
borrowck_long_type_full_path = the full type name has been written to '{$path}'
97+
9598
borrowck_move_closure_suggestion =
9699
consider adding 'move' keyword before the nested closure
97100

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
289289
None => "value".to_owned(),
290290
};
291291
if needs_note {
292+
let mut path = None;
293+
let ty = self.infcx.tcx.short_ty_string(ty, &mut path);
292294
if let Some(local) = place.as_local() {
293295
let span = self.body.local_decls[local].source_info.span;
294296
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
@@ -304,6 +306,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
304306
place: &note_msg,
305307
});
306308
};
309+
if let Some(path) = path {
310+
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
311+
path: path.display().to_string(),
312+
});
313+
}
307314
}
308315

309316
if let UseSpans::FnSelfUse {

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
596596
self.suggest_cloning(err, place_ty, expr, None);
597597
}
598598

599+
let mut path = None;
600+
let ty = self.infcx.tcx.short_ty_string(place_ty, &mut path);
599601
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
600602
is_partial_move: false,
601-
ty: place_ty,
603+
ty,
602604
place: &place_desc,
603605
span,
604606
});
607+
if let Some(path) = path {
608+
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
609+
path: path.display().to_string(),
610+
});
611+
}
605612
} else {
606613
binds_to.sort();
607614
binds_to.dedup();
@@ -628,12 +635,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
628635
self.suggest_cloning(err, place_ty, expr, Some(use_spans));
629636
}
630637

638+
let mut path = None;
639+
let ty = self.infcx.tcx.short_ty_string(place_ty, &mut path);
631640
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
632641
is_partial_move: false,
633-
ty: place_ty,
642+
ty,
634643
place: &place_desc,
635644
span: use_span,
636645
});
646+
if let Some(path) = path {
647+
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
648+
path: path.display().to_string(),
649+
});
650+
}
637651

638652
use_spans.args_subdiag(err, |args_span| {
639653
crate::session_diagnostics::CaptureArgLabel::MoveOutPlace {
@@ -831,12 +845,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
831845
self.suggest_cloning(err, bind_to.ty, expr, None);
832846
}
833847

848+
let mut path = None;
849+
let ty = self.infcx.tcx.short_ty_string(bind_to.ty, &mut path);
834850
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
835851
is_partial_move: false,
836-
ty: bind_to.ty,
852+
ty,
837853
place: place_desc,
838854
span: binding_span,
839855
});
856+
if let Some(path) = path {
857+
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
858+
path: path.display().to_string(),
859+
});
860+
}
840861
}
841862
}
842863

compiler/rustc_borrowck/src/session_diagnostics.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -459,17 +459,24 @@ pub(crate) enum OnClosureNote<'a> {
459459
}
460460

461461
#[derive(Subdiagnostic)]
462-
pub(crate) enum TypeNoCopy<'a, 'tcx> {
462+
#[note(borrowck_long_type_full_path)]
463+
#[note(borrowck_long_type_consider_verbose)]
464+
pub(crate) struct LongTypePath {
465+
pub(crate) path: String,
466+
}
467+
468+
#[derive(Subdiagnostic)]
469+
pub(crate) enum TypeNoCopy<'a> {
463470
#[label(borrowck_ty_no_impl_copy)]
464471
Label {
465472
is_partial_move: bool,
466-
ty: Ty<'tcx>,
473+
ty: String,
467474
place: &'a str,
468475
#[primary_span]
469476
span: Span,
470477
},
471478
#[note(borrowck_ty_no_impl_copy)]
472-
Note { is_partial_move: bool, ty: Ty<'tcx>, place: &'a str },
479+
Note { is_partial_move: bool, ty: String, place: &'a str },
473480
}
474481

475482
#[derive(Diagnostic)]

compiler/rustc_codegen_llvm/src/attributes.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -333,22 +333,25 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
333333
let mut to_add = SmallVec::<[_; 16]>::new();
334334

335335
match codegen_fn_attrs.optimize {
336-
OptimizeAttr::None => {
336+
OptimizeAttr::Default => {
337337
to_add.extend(default_optimisation_attrs(cx));
338338
}
339+
OptimizeAttr::DoNotOptimize => {
340+
to_add.push(llvm::AttributeKind::OptimizeNone.create_attr(cx.llcx));
341+
}
339342
OptimizeAttr::Size => {
340343
to_add.push(llvm::AttributeKind::MinSize.create_attr(cx.llcx));
341344
to_add.push(llvm::AttributeKind::OptimizeForSize.create_attr(cx.llcx));
342345
}
343346
OptimizeAttr::Speed => {}
344347
}
345348

346-
let inline =
347-
if codegen_fn_attrs.inline == InlineAttr::None && instance.def.requires_inline(cx.tcx) {
348-
InlineAttr::Hint
349-
} else {
350-
codegen_fn_attrs.inline
351-
};
349+
// `optnone` requires `noinline`
350+
let inline = match (codegen_fn_attrs.inline, &codegen_fn_attrs.optimize) {
351+
(_, OptimizeAttr::DoNotOptimize) => InlineAttr::Never,
352+
(InlineAttr::None, _) if instance.def.requires_inline(cx.tcx) => InlineAttr::Hint,
353+
(inline, _) => inline,
354+
};
352355
to_add.extend(inline_attr(cx, inline));
353356

354357
// The `uwtable` attribute according to LLVM is:

compiler/rustc_codegen_ssa/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition = "2021"
88
ar_archive_writer = "0.4.2"
99
arrayvec = { version = "0.7", default-features = false }
1010
bitflags = "2.4.1"
11+
bstr = "1.11.3"
1112
# Pinned so `cargo update` bumps don't cause breakage. Please also update the
1213
# `cc` in `rustc_llvm` if you update the `cc` here.
1314
cc = "=1.2.7"

compiler/rustc_codegen_ssa/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ codegen_ssa_linker_file_stem = couldn't extract file stem from specified linker
183183
codegen_ssa_linker_not_found = linker `{$linker_path}` not found
184184
.note = {$error}
185185
186+
codegen_ssa_linker_output = {$inner}
187+
186188
codegen_ssa_linker_unsupported_modifier = `as-needed` modifier not supported for current linker
187189
188190
codegen_ssa_linking_failed = linking with `{$linker_path}` failed: {$exit_status}

compiler/rustc_codegen_ssa/src/back/command.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub(crate) struct Command {
1313
args: Vec<OsString>,
1414
env: Vec<(OsString, OsString)>,
1515
env_remove: Vec<OsString>,
16+
env_clear: bool,
1617
}
1718

1819
#[derive(Clone)]
@@ -36,7 +37,13 @@ impl Command {
3637
}
3738

3839
fn _new(program: Program) -> Command {
39-
Command { program, args: Vec::new(), env: Vec::new(), env_remove: Vec::new() }
40+
Command {
41+
program,
42+
args: Vec::new(),
43+
env: Vec::new(),
44+
env_remove: Vec::new(),
45+
env_clear: false,
46+
}
4047
}
4148

4249
pub(crate) fn arg<P: AsRef<OsStr>>(&mut self, arg: P) -> &mut Command {
@@ -79,6 +86,11 @@ impl Command {
7986
self
8087
}
8188

89+
pub(crate) fn env_clear(&mut self) -> &mut Command {
90+
self.env_clear = true;
91+
self
92+
}
93+
8294
fn _env_remove(&mut self, key: &OsStr) {
8395
self.env_remove.push(key.to_owned());
8496
}
@@ -106,6 +118,9 @@ impl Command {
106118
for k in &self.env_remove {
107119
ret.env_remove(k);
108120
}
121+
if self.env_clear {
122+
ret.env_clear();
123+
}
109124
ret
110125
}
111126

compiler/rustc_codegen_ssa/src/back/link.rs

+64-13
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ use rustc_ast::CRATE_NODE_ID;
1515
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
1616
use rustc_data_structures::memmap::Mmap;
1717
use rustc_data_structures::temp_dir::MaybeTempDir;
18-
use rustc_errors::DiagCtxtHandle;
18+
use rustc_errors::{DiagCtxtHandle, LintDiagnostic};
1919
use rustc_fs_util::{fix_windows_verbatim_for_gcc, try_canonicalize};
2020
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
21+
use rustc_macros::LintDiagnostic;
2122
use rustc_metadata::fs::{METADATA_FILENAME, copy_to_stdout, emit_wrapper_file};
2223
use rustc_metadata::{find_native_static_library, walk_native_lib_search_dirs};
2324
use rustc_middle::bug;
25+
use rustc_middle::lint::lint_level;
2426
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
2527
use rustc_middle::middle::dependency_format::Linkage;
2628
use rustc_middle::middle::exported_symbols::SymbolExportKind;
@@ -29,6 +31,7 @@ use rustc_session::config::{
2931
OutputType, PrintKind, SplitDwarfKind, Strip,
3032
};
3133
use rustc_session::cstore::DllImport;
34+
use rustc_session::lint::builtin::LINKER_MESSAGES;
3235
use rustc_session::output::{check_file_is_writeable, invalid_output_for_target, out_filename};
3336
use rustc_session::search_paths::PathKind;
3437
use rustc_session::utils::NativeLibKind;
@@ -749,6 +752,14 @@ fn link_dwarf_object(sess: &Session, cg_results: &CodegenResults, executable_out
749752
}
750753
}
751754

755+
#[derive(LintDiagnostic)]
756+
#[diag(codegen_ssa_linker_output)]
757+
/// Translating this is kind of useless. We don't pass translation flags to the linker, so we'd just
758+
/// end up with inconsistent languages within the same diagnostic.
759+
struct LinkerOutput {
760+
inner: String,
761+
}
762+
752763
/// Create a dynamic library or executable.
753764
///
754765
/// This will invoke the system linker/cc to create the resulting file. This links to all upstream
@@ -981,6 +992,11 @@ fn link_natively(
981992

982993
match prog {
983994
Ok(prog) => {
995+
let is_msvc_link_exe = sess.target.is_like_msvc
996+
&& flavor == LinkerFlavor::Msvc(Lld::No)
997+
// Match exactly "link.exe"
998+
&& linker_path.to_str() == Some("link.exe");
999+
9841000
if !prog.status.success() {
9851001
let mut output = prog.stderr.clone();
9861002
output.extend_from_slice(&prog.stdout);
@@ -991,22 +1007,16 @@ fn link_natively(
9911007
command: cmd,
9921008
escaped_output,
9931009
verbose: sess.opts.verbose,
1010+
sysroot_dir: sess.sysroot.clone(),
9941011
};
9951012
sess.dcx().emit_err(err);
9961013
// If MSVC's `link.exe` was expected but the return code
9971014
// is not a Microsoft LNK error then suggest a way to fix or
9981015
// install the Visual Studio build tools.
9991016
if let Some(code) = prog.status.code() {
1000-
if sess.target.is_like_msvc
1001-
&& flavor == LinkerFlavor::Msvc(Lld::No)
1002-
// Respect the command line override
1003-
&& sess.opts.cg.linker.is_none()
1004-
// Match exactly "link.exe"
1005-
&& linker_path.to_str() == Some("link.exe")
1006-
// All Microsoft `link.exe` linking error codes are
1007-
// four digit numbers in the range 1000 to 9999 inclusive
1008-
&& (code < 1000 || code > 9999)
1009-
{
1017+
// All Microsoft `link.exe` linking ror codes are
1018+
// four digit numbers in the range 1000 to 9999 inclusive
1019+
if is_msvc_link_exe && (code < 1000 || code > 9999) {
10101020
let is_vs_installed = windows_registry::find_vs_version().is_ok();
10111021
let has_linker =
10121022
windows_registry::find_tool(&sess.target.arch, "link.exe").is_some();
@@ -1028,8 +1038,49 @@ fn link_natively(
10281038

10291039
sess.dcx().abort_if_errors();
10301040
}
1031-
info!("linker stderr:\n{}", escape_string(&prog.stderr));
1032-
info!("linker stdout:\n{}", escape_string(&prog.stdout));
1041+
1042+
let stderr = escape_string(&prog.stderr);
1043+
let mut stdout = escape_string(&prog.stdout);
1044+
info!("linker stderr:\n{}", &stderr);
1045+
info!("linker stdout:\n{}", &stdout);
1046+
1047+
// Hide some progress messages from link.exe that we don't care about.
1048+
// See https://github.com/chromium/chromium/blob/bfa41e41145ffc85f041384280caf2949bb7bd72/build/toolchain/win/tool_wrapper.py#L144-L146
1049+
if is_msvc_link_exe {
1050+
if let Ok(str) = str::from_utf8(&prog.stdout) {
1051+
let mut output = String::with_capacity(str.len());
1052+
for line in stdout.lines() {
1053+
if line.starts_with(" Creating library")
1054+
|| line.starts_with("Generating code")
1055+
|| line.starts_with("Finished generating code")
1056+
{
1057+
continue;
1058+
}
1059+
output += line;
1060+
output += "\r\n"
1061+
}
1062+
stdout = escape_string(output.trim().as_bytes())
1063+
}
1064+
}
1065+
1066+
let (level, src) = codegen_results.crate_info.lint_levels.linker_messages;
1067+
let lint = |msg| {
1068+
lint_level(sess, LINKER_MESSAGES, level, src, None, |diag| {
1069+
LinkerOutput { inner: msg }.decorate_lint(diag)
1070+
})
1071+
};
1072+
1073+
if !prog.stderr.is_empty() {
1074+
// We already print `warning:` at the start of the diagnostic. Remove it from the linker output if present.
1075+
let stderr = stderr
1076+
.strip_prefix("warning: ")
1077+
.unwrap_or(&stderr)
1078+
.replace(": warning: ", ": ");
1079+
lint(format!("linker stderr: {stderr}"));
1080+
}
1081+
if !stdout.is_empty() {
1082+
lint(format!("linker stdout: {}", stdout))
1083+
}
10331084
}
10341085
Err(e) => {
10351086
let linker_not_found = e.kind() == io::ErrorKind::NotFound;

0 commit comments

Comments
 (0)