Skip to content

Commit 32b17d5

Browse files
committed
Auto merge of #132244 - jyn514:linker-refactors, r=bjorn3
fix various linker warnings separated out from #119286; this doesn't have anything user-facing, i just want to land these changes so i can stop rebasing them. r? `@bjorn3`
2 parents 66701c4 + 675f447 commit 32b17d5

File tree

12 files changed

+194
-181
lines changed

12 files changed

+194
-181
lines changed

Diff for: compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ impl DiagnosticDeriveVariantBuilder {
253253
let mut field_binding = binding_info.binding.clone();
254254
field_binding.set_span(field.ty.span());
255255

256-
let ident = field.ident.as_ref().unwrap();
256+
let Some(ident) = field.ident.as_ref() else {
257+
span_err(field.span().unwrap(), "tuple structs are not supported").emit();
258+
return TokenStream::new();
259+
};
257260
let ident = format_ident!("{}", ident); // strip `r#` prefix, if present
258261

259262
quote! {

Diff for: compiler/rustc_macros/src/diagnostics/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn path_to_string(path: &syn::Path) -> String {
5656
/// Returns an error diagnostic on span `span` with msg `msg`.
5757
#[must_use]
5858
pub(crate) fn span_err<T: Into<String>>(span: impl MultiSpan, msg: T) -> Diagnostic {
59-
Diagnostic::spanned(span, Level::Error, msg)
59+
Diagnostic::spanned(span, Level::Error, format!("derive(Diagnostic): {}", msg.into()))
6060
}
6161

6262
/// Emit a diagnostic on span `$span` with msg `$msg` (optionally performing additional decoration

Diff for: compiler/rustc_macros/src/diagnostics/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl<T> SetOnce<T> for SpannedOption<T> {
243243
*self = Some((value, span));
244244
}
245245
Some((_, prev_span)) => {
246-
span_err(span, "specified multiple times")
246+
span_err(span, "attribute specified multiple times")
247247
.span_note(*prev_span, "previously specified here")
248248
.emit();
249249
}

Diff for: src/etc/cat-and-grep.sh

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ while getopts ':vieh' OPTION; do
3333
case "$OPTION" in
3434
v)
3535
INVERT=1
36-
ERROR_MSG='should not be found'
3736
;;
3837
i)
3938
GREPFLAGS="i$GREPFLAGS"

Diff for: src/tools/compiletest/src/runtest.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,10 @@ impl<'test> TestCx<'test> {
10961096
self.config.target.contains("vxworks") && !self.is_vxworks_pure_static()
10971097
}
10981098

1099+
fn has_aux_dir(&self) -> bool {
1100+
!self.props.aux.builds.is_empty() || !self.props.aux.crates.is_empty()
1101+
}
1102+
10991103
fn aux_output_dir(&self) -> PathBuf {
11001104
let aux_dir = self.aux_output_dir_name();
11011105

@@ -1649,7 +1653,11 @@ impl<'test> TestCx<'test> {
16491653
}
16501654

16511655
if let LinkToAux::Yes = link_to_aux {
1652-
rustc.arg("-L").arg(self.aux_output_dir_name());
1656+
// if we pass an `-L` argument to a directory that doesn't exist,
1657+
// macOS ld emits warnings which disrupt the .stderr files
1658+
if self.has_aux_dir() {
1659+
rustc.arg("-L").arg(self.aux_output_dir_name());
1660+
}
16531661
}
16541662

16551663
rustc.args(&self.props.compile_flags);

Diff for: tests/run-make/linkage-attr-framework/main.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![cfg_attr(any(weak, both), feature(link_arg_attribute))]
2+
3+
#[cfg_attr(any(link, both), link(name = "CoreFoundation", kind = "framework"))]
4+
#[cfg_attr(
5+
any(weak, both),
6+
link(name = "-weak_framework", kind = "link-arg", modifiers = "+verbatim"),
7+
link(name = "CoreFoundation", kind = "link-arg", modifiers = "+verbatim")
8+
)]
9+
extern "C" {
10+
fn CFRunLoopGetTypeID() -> core::ffi::c_ulong;
11+
}
12+
13+
fn main() {
14+
unsafe {
15+
CFRunLoopGetTypeID();
16+
}
17+
}

Diff for: tests/run-make/linkage-attr-framework/rmake.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//! Check that linking frameworks on Apple platforms works.
2+
3+
//@ only-apple
4+
5+
use run_make_support::{Rustc, run, rustc};
6+
7+
fn compile(cfg: &str) -> Rustc {
8+
let mut rustc = rustc();
9+
rustc.cfg(cfg).input("main.rs");
10+
rustc
11+
}
12+
13+
fn main() {
14+
for cfg in ["link", "weak", "both"] {
15+
compile(cfg).run();
16+
run("main");
17+
}
18+
19+
let errs = compile("omit").run_fail();
20+
// The linker's exact error output changes between Xcode versions, depends on
21+
// linker invocation details, and the linker sometimes outputs more warnings.
22+
errs.assert_stderr_contains_regex(r"error: linking with `.*` failed");
23+
errs.assert_stderr_contains_regex(r"(Undefined symbols|ld: symbol[^\s]* not found)");
24+
errs.assert_stderr_contains_regex(r".?_CFRunLoopGetTypeID.?, referenced from:");
25+
errs.assert_stderr_contains("clang: error: linker command failed with exit code 1");
26+
}

0 commit comments

Comments
 (0)