Skip to content

Commit

Permalink
Auto merge of #132244 - jyn514:linker-refactors, r=bjorn3
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
bors committed Oct 28, 2024
2 parents 66701c4 + 675f447 commit 32b17d5
Show file tree
Hide file tree
Showing 12 changed files with 194 additions and 181 deletions.
5 changes: 4 additions & 1 deletion compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ impl DiagnosticDeriveVariantBuilder {
let mut field_binding = binding_info.binding.clone();
field_binding.set_span(field.ty.span());

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

quote! {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/diagnostics/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn path_to_string(path: &syn::Path) -> String {
/// Returns an error diagnostic on span `span` with msg `msg`.
#[must_use]
pub(crate) fn span_err<T: Into<String>>(span: impl MultiSpan, msg: T) -> Diagnostic {
Diagnostic::spanned(span, Level::Error, msg)
Diagnostic::spanned(span, Level::Error, format!("derive(Diagnostic): {}", msg.into()))
}

/// Emit a diagnostic on span `$span` with msg `$msg` (optionally performing additional decoration
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/diagnostics/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl<T> SetOnce<T> for SpannedOption<T> {
*self = Some((value, span));
}
Some((_, prev_span)) => {
span_err(span, "specified multiple times")
span_err(span, "attribute specified multiple times")
.span_note(*prev_span, "previously specified here")
.emit();
}
Expand Down
1 change: 0 additions & 1 deletion src/etc/cat-and-grep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ while getopts ':vieh' OPTION; do
case "$OPTION" in
v)
INVERT=1
ERROR_MSG='should not be found'
;;
i)
GREPFLAGS="i$GREPFLAGS"
Expand Down
10 changes: 9 additions & 1 deletion src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,10 @@ impl<'test> TestCx<'test> {
self.config.target.contains("vxworks") && !self.is_vxworks_pure_static()
}

fn has_aux_dir(&self) -> bool {
!self.props.aux.builds.is_empty() || !self.props.aux.crates.is_empty()
}

fn aux_output_dir(&self) -> PathBuf {
let aux_dir = self.aux_output_dir_name();

Expand Down Expand Up @@ -1649,7 +1653,11 @@ impl<'test> TestCx<'test> {
}

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

rustc.args(&self.props.compile_flags);
Expand Down
17 changes: 17 additions & 0 deletions tests/run-make/linkage-attr-framework/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![cfg_attr(any(weak, both), feature(link_arg_attribute))]

#[cfg_attr(any(link, both), link(name = "CoreFoundation", kind = "framework"))]
#[cfg_attr(
any(weak, both),
link(name = "-weak_framework", kind = "link-arg", modifiers = "+verbatim"),
link(name = "CoreFoundation", kind = "link-arg", modifiers = "+verbatim")
)]
extern "C" {
fn CFRunLoopGetTypeID() -> core::ffi::c_ulong;
}

fn main() {
unsafe {
CFRunLoopGetTypeID();
}
}
26 changes: 26 additions & 0 deletions tests/run-make/linkage-attr-framework/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! Check that linking frameworks on Apple platforms works.

//@ only-apple

use run_make_support::{Rustc, run, rustc};

fn compile(cfg: &str) -> Rustc {
let mut rustc = rustc();
rustc.cfg(cfg).input("main.rs");
rustc
}

fn main() {
for cfg in ["link", "weak", "both"] {
compile(cfg).run();
run("main");
}

let errs = compile("omit").run_fail();
// The linker's exact error output changes between Xcode versions, depends on
// linker invocation details, and the linker sometimes outputs more warnings.
errs.assert_stderr_contains_regex(r"error: linking with `.*` failed");
errs.assert_stderr_contains_regex(r"(Undefined symbols|ld: symbol[^\s]* not found)");
errs.assert_stderr_contains_regex(r".?_CFRunLoopGetTypeID.?, referenced from:");
errs.assert_stderr_contains("clang: error: linker command failed with exit code 1");
}
Loading

0 comments on commit 32b17d5

Please sign in to comment.