Skip to content

Commit 083f2c8

Browse files
committed
Auto merge of #130247 - workingjubilee:rollup-fjyvh47, r=workingjubilee
Rollup of 11 pull requests Successful merges: - #119286 (show linker output even if the linker succeeds) - #129103 (Don't warn empty branches unreachable for now) - #129696 (update stdarch) - #129835 (enable const-float-classify test, and test_next_up/down on 32bit x86) - #129992 (Update compiler-builtins to 0.1.125) - #130052 (Don't leave debug locations for constants sitting on the builder indefinitely) - #130077 (Fix linking error when compiling for 32-bit watchOS) - #130114 (Remove needless returns detected by clippy in the compiler) - #130156 (Add test for S_OBJNAME & update test for LF_BUILDINFO cl and cmd) - #130168 (maint: update docs for change_time ext and doc links) - #130239 (miri: fix overflow detection for unsigned pointer offset) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8d6b88b + b867f89 commit 083f2c8

File tree

112 files changed

+903
-1039
lines changed

Some content is hidden

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

112 files changed

+903
-1039
lines changed

compiler/rustc_ast/src/ast_traits.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl HasTokens for StmtKind {
153153
StmtKind::Let(local) => local.tokens.as_ref(),
154154
StmtKind::Item(item) => item.tokens(),
155155
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.tokens(),
156-
StmtKind::Empty => return None,
156+
StmtKind::Empty => None,
157157
StmtKind::MacCall(mac) => mac.tokens.as_ref(),
158158
}
159159
}
@@ -162,7 +162,7 @@ impl HasTokens for StmtKind {
162162
StmtKind::Let(local) => Some(&mut local.tokens),
163163
StmtKind::Item(item) => item.tokens_mut(),
164164
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.tokens_mut(),
165-
StmtKind::Empty => return None,
165+
StmtKind::Empty => None,
166166
StmtKind::MacCall(mac) => Some(&mut mac.tokens),
167167
}
168168
}

compiler/rustc_attr/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1240,5 +1240,5 @@ pub fn parse_confusables(attr: &Attribute) -> Option<Vec<Symbol>> {
12401240
candidates.push(meta_lit.symbol);
12411241
}
12421242

1243-
return Some(candidates);
1243+
Some(candidates)
12441244
}

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3669,7 +3669,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
36693669
reinits.push(location);
36703670
return true;
36713671
}
3672-
return false;
3672+
false
36733673
};
36743674

36753675
while let Some(location) = stack.pop() {

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
214214
let delegate = FnMutDelegate {
215215
regions: &mut |br: ty::BoundRegion| {
216216
if let Some(ex_reg_var) = reg_map.get(&br) {
217-
return *ex_reg_var;
217+
*ex_reg_var
218218
} else {
219219
let ex_reg_var = self.next_existential_region_var(true, br.kind.get_name());
220220
debug!(?ex_reg_var);

compiler/rustc_codegen_gcc/src/debuginfo.rs

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> {
4848
fn set_dbg_loc(&mut self, dbg_loc: Self::DILocation) {
4949
self.location = Some(dbg_loc);
5050
}
51+
52+
fn clear_dbg_loc(&mut self) {
53+
self.location = None;
54+
}
5155
}
5256

5357
/// Generate the `debug_context` in an MIR Body.

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![doc = include_str!("doc.md")]
22

33
use std::cell::{OnceCell, RefCell};
4-
use std::iter;
54
use std::ops::Range;
5+
use std::{iter, ptr};
66

77
use libc::c_uint;
88
use rustc_codegen_ssa::debuginfo::type_names;
@@ -209,6 +209,12 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
209209
}
210210
}
211211

212+
fn clear_dbg_loc(&mut self) {
213+
unsafe {
214+
llvm::LLVMSetCurrentDebugLocation2(self.llbuilder, ptr::null());
215+
}
216+
}
217+
212218
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {
213219
gdb::insert_reference_to_gdb_debug_scripts_section_global(self)
214220
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ unsafe extern "C" {
10411041
pub fn LLVMDisposeBuilder<'a>(Builder: &'a mut Builder<'a>);
10421042

10431043
// Metadata
1044-
pub fn LLVMSetCurrentDebugLocation2<'a>(Builder: &Builder<'a>, Loc: &'a Metadata);
1044+
pub fn LLVMSetCurrentDebugLocation2<'a>(Builder: &Builder<'a>, Loc: *const Metadata);
10451045

10461046
// Terminators
10471047
pub fn LLVMBuildRetVoid<'a>(B: &Builder<'a>) -> &'a Value;

compiler/rustc_codegen_llvm/src/llvm_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ pub(crate) fn check_tied_features(
290290
}
291291
}
292292
}
293-
return None;
293+
None
294294
}
295295

296296
/// Used to generate cfg variables and apply features

compiler/rustc_codegen_ssa/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ codegen_ssa_linker_file_stem = couldn't extract file stem from specified linker
172172
codegen_ssa_linker_not_found = linker `{$linker_path}` not found
173173
.note = {$error}
174174
175+
codegen_ssa_linker_output = {$inner}
176+
175177
codegen_ssa_linker_unsupported_modifier = `as-needed` modifier not supported for current linker
176178
177179
codegen_ssa_linking_failed = linking with `{$linker_path}` failed: {$exit_status}

compiler/rustc_codegen_ssa/src/back/link.rs

+29-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc_data_structures::temp_dir::MaybeTempDir;
1818
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed, FatalError};
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::Diagnostic;
2122
use rustc_metadata::fs::{copy_to_stdout, emit_wrapper_file, METADATA_FILENAME};
2223
use rustc_metadata::{find_native_static_library, walk_native_lib_search_dirs};
2324
use rustc_middle::bug;
@@ -438,7 +439,7 @@ fn link_rlib<'a>(
438439
ab.add_file(&lib)
439440
}
440441

441-
return Ok(ab);
442+
Ok(ab)
442443
}
443444

444445
/// Extract all symbols defined in raw-dylib libraries, collated by library name.
@@ -750,6 +751,14 @@ fn link_dwarf_object(sess: &Session, cg_results: &CodegenResults, executable_out
750751
}
751752
}
752753

754+
#[derive(Diagnostic)]
755+
#[diag(codegen_ssa_linker_output)]
756+
/// Translating this is kind of useless. We don't pass translation flags to the linker, so we'd just
757+
/// end up with inconsistent languages within the same diagnostic.
758+
struct LinkerOutput {
759+
inner: String,
760+
}
761+
753762
/// Create a dynamic library or executable.
754763
///
755764
/// This will invoke the system linker/cc to create the resulting file. This links to all upstream
@@ -976,12 +985,12 @@ fn link_natively(
976985
let mut output = prog.stderr.clone();
977986
output.extend_from_slice(&prog.stdout);
978987
let escaped_output = escape_linker_output(&output, flavor);
979-
// FIXME: Add UI tests for this error.
980988
let err = errors::LinkingFailed {
981989
linker_path: &linker_path,
982990
exit_status: prog.status,
983991
command: &cmd,
984992
escaped_output,
993+
verbose: sess.opts.verbose,
985994
};
986995
sess.dcx().emit_err(err);
987996
// If MSVC's `link.exe` was expected but the return code
@@ -1022,8 +1031,22 @@ fn link_natively(
10221031

10231032
sess.dcx().abort_if_errors();
10241033
}
1025-
info!("linker stderr:\n{}", escape_string(&prog.stderr));
1026-
info!("linker stdout:\n{}", escape_string(&prog.stdout));
1034+
1035+
if !prog.stderr.is_empty() {
1036+
// We already print `warning:` at the start of the diagnostic. Remove it from the linker output if present.
1037+
let stderr = escape_string(&prog.stderr);
1038+
debug!("original stderr: {stderr}");
1039+
let stderr = stderr
1040+
.strip_prefix("warning: ")
1041+
.unwrap_or(&stderr)
1042+
.replace(": warning: ", ": ");
1043+
sess.dcx().emit_warn(LinkerOutput { inner: format!("linker stderr: {stderr}") });
1044+
}
1045+
if !prog.stdout.is_empty() && sess.opts.verbose {
1046+
sess.dcx().emit_warn(LinkerOutput {
1047+
inner: format!("linker stdout: {}", escape_string(&prog.stdout)),
1048+
});
1049+
}
10271050
}
10281051
Err(e) => {
10291052
let linker_not_found = e.kind() == io::ErrorKind::NotFound;
@@ -1319,15 +1342,15 @@ fn link_sanitizer_runtime(
13191342
fn find_sanitizer_runtime(sess: &Session, filename: &str) -> PathBuf {
13201343
let path = sess.target_tlib_path.dir.join(filename);
13211344
if path.exists() {
1322-
return sess.target_tlib_path.dir.clone();
1345+
sess.target_tlib_path.dir.clone()
13231346
} else {
13241347
let default_sysroot =
13251348
filesearch::get_or_default_sysroot().expect("Failed finding sysroot");
13261349
let default_tlib = filesearch::make_target_lib_path(
13271350
&default_sysroot,
13281351
sess.opts.target_triple.triple(),
13291352
);
1330-
return default_tlib;
1353+
default_tlib
13311354
}
13321355
}
13331356

compiler/rustc_codegen_ssa/src/back/linker.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,6 @@ impl<'a> Linker for L4Bender<'a> {
14841484
fn export_symbols(&mut self, _: &Path, _: CrateType, _: &[String]) {
14851485
// ToDo, not implemented, copy from GCC
14861486
self.sess.dcx().emit_warn(errors::L4BenderExportingSymbolsUnimplemented);
1487-
return;
14881487
}
14891488

14901489
fn subsystem(&mut self, subsystem: &str) {

compiler/rustc_codegen_ssa/src/back/metadata.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ pub(super) fn get_metadata_xcoff<'a>(path: &Path, data: &'a [u8]) -> Result<&'a
171171
"Metadata at offset {offset} with size {len} is beyond .info section"
172172
));
173173
}
174-
return Ok(&info_data[offset..(offset + len)]);
174+
Ok(&info_data[offset..(offset + len)])
175175
} else {
176-
return Err(format!("Unable to find symbol {AIX_METADATA_SYMBOL_NAME}"));
177-
};
176+
Err(format!("Unable to find symbol {AIX_METADATA_SYMBOL_NAME}"))
177+
}
178178
}
179179

180180
pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static>> {
@@ -413,7 +413,7 @@ fn macho_object_build_version_for_target(target: &Target) -> object::write::Mach
413413

414414
/// Is Apple's CPU subtype `arm64e`s
415415
fn macho_is_arm64e(target: &Target) -> bool {
416-
return target.llvm_target.starts_with("arm64e");
416+
target.llvm_target.starts_with("arm64e")
417417
}
418418

419419
pub enum MetadataPosition {

compiler/rustc_codegen_ssa/src/errors.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ pub struct LinkingFailed<'a> {
348348
pub exit_status: ExitStatus,
349349
pub command: &'a Command,
350350
pub escaped_output: String,
351+
pub verbose: bool,
351352
}
352353

353354
impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
@@ -358,7 +359,13 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
358359

359360
let contains_undefined_ref = self.escaped_output.contains("undefined reference to");
360361

361-
diag.note(format!("{:?}", self.command)).note(self.escaped_output);
362+
if self.verbose {
363+
diag.note(format!("{:?}", self.command));
364+
} else {
365+
diag.note("use `--verbose` to show all linker arguments");
366+
}
367+
368+
diag.note(self.escaped_output);
362369

363370
// Trying to match an error from OS linkers
364371
// which by now we have no way to translate.

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

+1
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
547547
self.set_debug_loc(bx, var.source_info);
548548
let base =
549549
Self::spill_operand_to_stack(operand, Some(var.name.to_string()), bx);
550+
bx.clear_dbg_loc();
550551

551552
bx.dbg_var_addr(
552553
dbg_var,

compiler/rustc_codegen_ssa/src/traits/debuginfo.rs

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub trait DebugInfoBuilderMethods: BackendTypes {
8080
fragment: Option<Range<Size>>,
8181
);
8282
fn set_dbg_loc(&mut self, dbg_loc: Self::DILocation);
83+
fn clear_dbg_loc(&mut self);
8384
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self);
8485
fn set_var_name(&mut self, value: Self::Value, name: &str);
8586
}

compiler/rustc_const_eval/src/interpret/call.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
235235
if self.layout_compat(caller_abi.layout, callee_abi.layout)? {
236236
// Ensure that our checks imply actual ABI compatibility for this concrete call.
237237
assert!(caller_abi.eq_abi(callee_abi));
238-
return Ok(true);
238+
Ok(true)
239239
} else {
240240
trace!(
241241
"check_argument_compat: incompatible ABIs:\ncaller: {:?}\ncallee: {:?}",
242242
caller_abi, callee_abi
243243
);
244-
return Ok(false);
244+
Ok(false)
245245
}
246246
}
247247

compiler/rustc_const_eval/src/interpret/operator.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
303303
let pointee_layout = self.layout_of(pointee_ty)?;
304304
assert!(pointee_layout.abi.is_sized());
305305

306-
// We cannot overflow i64 as a type's size must be <= isize::MAX.
306+
// The size always fits in `i64` as it can be at most `isize::MAX`.
307307
let pointee_size = i64::try_from(pointee_layout.size.bytes()).unwrap();
308+
// This uses the same type as `right`, which can be `isize` or `usize`.
309+
// `pointee_size` is guaranteed to fit into both types.
308310
let pointee_size = ImmTy::from_int(pointee_size, right.layout);
309311
// Multiply element size and element count.
310312
let (val, overflowed) = self
@@ -316,6 +318,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
316318
}
317319

318320
let offset_bytes = val.to_target_isize(self)?;
321+
if !right.layout.abi.is_signed() && offset_bytes < 0 {
322+
// We were supposed to do an unsigned offset but the result is negative -- this
323+
// can only mean that the cast wrapped around.
324+
throw_ub!(PointerArithOverflow)
325+
}
319326
let offset_ptr = self.ptr_offset_inbounds(ptr, offset_bytes)?;
320327
Ok(ImmTy::from_scalar(Scalar::from_maybe_pointer(offset_ptr, self), left.layout))
321328
}

compiler/rustc_expand/src/mbe/transcribe.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -773,34 +773,34 @@ fn extract_symbol_from_pnr<'a>(
773773
match pnr {
774774
ParseNtResult::Ident(nt_ident, is_raw) => {
775775
if let IdentIsRaw::Yes = is_raw {
776-
return Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR));
776+
Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR))
777+
} else {
778+
Ok(nt_ident.name)
777779
}
778-
return Ok(nt_ident.name);
779780
}
780781
ParseNtResult::Tt(TokenTree::Token(
781782
Token { kind: TokenKind::Ident(symbol, is_raw), .. },
782783
_,
783784
)) => {
784785
if let IdentIsRaw::Yes = is_raw {
785-
return Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR));
786+
Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR))
787+
} else {
788+
Ok(*symbol)
786789
}
787-
return Ok(*symbol);
788790
}
789791
ParseNtResult::Tt(TokenTree::Token(
790792
Token {
791793
kind: TokenKind::Literal(Lit { kind: LitKind::Str, symbol, suffix: None }),
792794
..
793795
},
794796
_,
795-
)) => {
796-
return Ok(*symbol);
797-
}
797+
)) => Ok(*symbol),
798798
ParseNtResult::Nt(nt)
799799
if let Nonterminal::NtLiteral(expr) = &**nt
800800
&& let ExprKind::Lit(Lit { kind: LitKind::Str, symbol, suffix: None }) =
801801
&expr.kind =>
802802
{
803-
return Ok(*symbol);
803+
Ok(*symbol)
804804
}
805805
_ => Err(dcx
806806
.struct_err(

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ fn report_trait_method_mismatch<'tcx>(
10381038
false,
10391039
);
10401040

1041-
return diag.emit();
1041+
diag.emit()
10421042
}
10431043

10441044
fn check_region_bounds_on_impl_item<'tcx>(

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
274274
return false;
275275
}
276276

277-
return true;
277+
true
278278
})
279279
.collect::<Vec<_>>();
280280

compiler/rustc_hir_typeck/src/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
605605
Abi::Rust,
606606
));
607607

608-
return Some(ExpectedSig { cause_span, sig });
608+
Some(ExpectedSig { cause_span, sig })
609609
}
610610

611611
fn sig_of_closure(

compiler/rustc_hir_typeck/src/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10421042
return true;
10431043
}
10441044
}
1045-
return false;
1045+
false
10461046
}
10471047

10481048
fn explain_self_literal(

compiler/rustc_hir_typeck/src/fn_ctxt/arg_matrix.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ impl<'tcx> ArgMatrix<'tcx> {
307307
permutation.into_iter().map(|x| x.unwrap()).collect();
308308
return Some(Issue::Permutation(final_permutation));
309309
}
310-
return None;
310+
None
311311
}
312312

313313
// Obviously, detecting exact user intention is impossible, so the goal here is to
@@ -410,6 +410,6 @@ impl<'tcx> ArgMatrix<'tcx> {
410410
// sort errors with same type by the order they appear in the source
411411
// so that suggestion will be handled properly, see #112507
412412
errors.sort();
413-
return (errors, matched_inputs);
413+
(errors, matched_inputs)
414414
}
415415
}

0 commit comments

Comments
 (0)