Skip to content

Rollup of 7 pull requests #133703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Dec 1, 2024
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
45791dd
Support linker arguments that contain commas
madsmtm Nov 24, 2024
cb6f8fa
Support rpath with -Clinker-flavor=ld
madsmtm Nov 12, 2024
6bbf832
Remove unnecessary 0 link args optimization
madsmtm Nov 24, 2024
7cf3f8b
Do not emit `missing_doc_code_examples` rustdoc lint on module and a …
GuillaumeGomez Nov 28, 2024
23d9741
move slice::swap_unchecked constness to slice_swap_unchecked feature …
RalfJung Nov 30, 2024
ede5f01
move swap_nonoverlapping constness to separate feature gate
RalfJung Nov 30, 2024
2a05e5b
add test for bytewise ptr::swap of a pointer
RalfJung Nov 30, 2024
9836196
Fix chaining `carrying_add`s
scottmcm Nov 30, 2024
b118d05
Extend documentation for `missing_doc_code_examples` rustdoc lint in …
GuillaumeGomez Nov 30, 2024
805649b
Check let source before suggesting annotation
compiler-errors Dec 1, 2024
17c6efa
Disentangle hir node match logic in adjust_fulfillment_errors
compiler-errors Nov 24, 2024
30afeb0
Adjust HostEffect error spans correctly to point at args
compiler-errors Nov 24, 2024
d5c5d58
Pull out expr handling
compiler-errors Dec 1, 2024
b87e935
Revert "Reject raw lifetime followed by \' as well"
compiler-errors Nov 26, 2024
d878fd8
Only error raw lifetime followed by \' in edition 2021+
compiler-errors Nov 26, 2024
ae6a7db
Rollup merge of #132974 - madsmtm:linker-arguments-with-commas, r=pet…
matthiaskrgr Dec 1, 2024
b574158
Rollup merge of #133403 - compiler-errors:adjust-host-effect-preds, r…
matthiaskrgr Dec 1, 2024
337c48c
Rollup merge of #133482 - compiler-errors:raw-lt-tick, r=estebank
matthiaskrgr Dec 1, 2024
2713dc2
Rollup merge of #133595 - GuillaumeGomez:missing_doc_code_examples, r…
matthiaskrgr Dec 1, 2024
3d18c3c
Rollup merge of #133669 - RalfJung:const_swap_splitup, r=dtolnay
matthiaskrgr Dec 1, 2024
2f00feb
Rollup merge of #133674 - scottmcm:chain-carrying-add, r=Amanieu
matthiaskrgr Dec 1, 2024
78dad1e
Rollup merge of #133691 - compiler-errors:let-source, r=lqd
matthiaskrgr Dec 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
@@ -1386,7 +1386,7 @@ fn link_sanitizer_runtime(
let filename = format!("rustc{channel}_rt.{name}");
let path = find_sanitizer_runtime(sess, &filename);
let rpath = path.to_str().expect("non-utf8 component in path");
linker.cc_args(&["-Wl,-rpath", "-Xlinker", rpath]);
linker.link_args(&["-rpath", rpath]);
linker.link_dylib_by_name(&filename, false, true);
} else if sess.target.is_like_msvc && flavor == LinkerFlavor::Msvc(Lld::No) && name == "asan" {
// MSVC provides the `/INFERASANLIBS` argument to automatically find the
@@ -2210,7 +2210,7 @@ fn add_rpath_args(
is_like_osx: sess.target.is_like_osx,
linker_is_gnu: sess.target.linker_flavor.is_gnu(),
};
cmd.cc_args(&rpath::get_rpath_flags(&rpath_config));
cmd.link_args(&rpath::get_rpath_linker_args(&rpath_config));
}
}

50 changes: 36 additions & 14 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
@@ -24,6 +24,9 @@ use super::command::Command;
use super::symbol_export;
use crate::errors;

#[cfg(test)]
mod tests;

/// Disables non-English messages from localized linkers.
/// Such messages may cause issues with text encoding on Windows (#35785)
/// and prevent inspection of linker output in case of errors, which we occasionally do.
@@ -178,23 +181,42 @@ fn verbatim_args<L: Linker + ?Sized>(
}
l
}
/// Add underlying linker arguments to C compiler command, by wrapping them in
/// `-Wl` or `-Xlinker`.
fn convert_link_args_to_cc_args(cmd: &mut Command, args: impl IntoIterator<Item: AsRef<OsStr>>) {
let mut combined_arg = OsString::from("-Wl");
for arg in args {
// If the argument itself contains a comma, we need to emit it
// as `-Xlinker`, otherwise we can use `-Wl`.
if arg.as_ref().as_encoded_bytes().contains(&b',') {
// Emit current `-Wl` argument, if any has been built.
if combined_arg != OsStr::new("-Wl") {
cmd.arg(combined_arg);
// Begin next `-Wl` argument.
combined_arg = OsString::from("-Wl");
}

// Emit `-Xlinker` argument.
cmd.arg("-Xlinker");
cmd.arg(arg);
} else {
// Append to `-Wl` argument.
combined_arg.push(",");
combined_arg.push(arg);
}
}
// Emit final `-Wl` argument.
if combined_arg != OsStr::new("-Wl") {
cmd.arg(combined_arg);
}
}
/// Arguments for the underlying linker.
/// Add options to pass them through cc wrapper if `Linker` is a cc wrapper.
fn link_args<L: Linker + ?Sized>(
l: &mut L,
args: impl IntoIterator<Item: AsRef<OsStr>, IntoIter: ExactSizeIterator>,
) -> &mut L {
let args = args.into_iter();
fn link_args<L: Linker + ?Sized>(l: &mut L, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut L {
if !l.is_cc() {
verbatim_args(l, args);
} else if args.len() != 0 {
// FIXME: Support arguments with commas, see `rpaths_to_flags` for the example.
let mut combined_arg = OsString::from("-Wl");
for arg in args {
combined_arg.push(",");
combined_arg.push(arg);
}
l.cmd().arg(combined_arg);
} else {
convert_link_args_to_cc_args(l.cmd(), args);
}
l
}
@@ -224,7 +246,7 @@ macro_rules! generate_arg_methods {
verbatim_args(self, iter::once(arg))
}
#[allow(unused)]
pub(crate) fn link_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>, IntoIter: ExactSizeIterator>) -> &mut Self {
pub(crate) fn link_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut Self {
link_args(self, args)
}
#[allow(unused)]
32 changes: 32 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/linker/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use super::*;

#[test]
fn test_rpaths_to_args() {
let mut cmd = Command::new("foo");
convert_link_args_to_cc_args(&mut cmd, &["-rpath", "path1", "-rpath", "path2"]);
assert_eq!(cmd.get_args(), [OsStr::new("-Wl,-rpath,path1,-rpath,path2")]);
}

#[test]
fn test_xlinker() {
let mut cmd = Command::new("foo");
convert_link_args_to_cc_args(&mut cmd, &[
"arg1",
"arg2",
"arg3,with,comma",
"arg4,with,comma",
"arg5",
"arg6,with,comma",
]);

assert_eq!(cmd.get_args(), [
OsStr::new("-Wl,arg1,arg2"),
OsStr::new("-Xlinker"),
OsStr::new("arg3,with,comma"),
OsStr::new("-Xlinker"),
OsStr::new("arg4,with,comma"),
OsStr::new("-Wl,arg5"),
OsStr::new("-Xlinker"),
OsStr::new("arg6,with,comma"),
]);
}
34 changes: 11 additions & 23 deletions compiler/rustc_codegen_ssa/src/back/rpath.rs
Original file line number Diff line number Diff line change
@@ -13,39 +13,27 @@ pub(super) struct RPathConfig<'a> {
pub linker_is_gnu: bool,
}

pub(super) fn get_rpath_flags(config: &RPathConfig<'_>) -> Vec<OsString> {
pub(super) fn get_rpath_linker_args(config: &RPathConfig<'_>) -> Vec<OsString> {
debug!("preparing the RPATH!");

let rpaths = get_rpaths(config);
let mut flags = rpaths_to_flags(rpaths);
let mut args = Vec::with_capacity(rpaths.len() * 2); // the minimum needed capacity

for rpath in rpaths {
args.push("-rpath".into());
args.push(rpath);
}

if config.linker_is_gnu {
// Use DT_RUNPATH instead of DT_RPATH if available
flags.push("-Wl,--enable-new-dtags".into());
args.push("--enable-new-dtags".into());

// Set DF_ORIGIN for substitute $ORIGIN
flags.push("-Wl,-z,origin".into());
}

flags
}

fn rpaths_to_flags(rpaths: Vec<OsString>) -> Vec<OsString> {
let mut ret = Vec::with_capacity(rpaths.len()); // the minimum needed capacity

for rpath in rpaths {
if rpath.to_string_lossy().contains(',') {
ret.push("-Wl,-rpath".into());
ret.push("-Xlinker".into());
ret.push(rpath);
} else {
let mut single_arg = OsString::from("-Wl,-rpath,");
single_arg.push(rpath);
ret.push(single_arg);
}
args.push("-z".into());
args.push("origin".into());
}

ret
args
}

fn get_rpaths(config: &RPathConfig<'_>) -> Vec<OsString> {
23 changes: 1 addition & 22 deletions compiler/rustc_codegen_ssa/src/back/rpath/tests.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
use std::ffi::OsString;
use std::path::{Path, PathBuf};

use super::{RPathConfig, get_rpath_relative_to_output, minimize_rpaths, rpaths_to_flags};

#[test]
fn test_rpaths_to_flags() {
let flags = rpaths_to_flags(vec!["path1".into(), "path2".into()]);
assert_eq!(flags, ["-Wl,-rpath,path1", "-Wl,-rpath,path2"]);
}
use super::*;

#[test]
fn test_minimize1() {
@@ -69,15 +60,3 @@ fn test_rpath_relative_issue_119571() {
// Should not panic when lib only contains filename.
let _ = get_rpath_relative_to_output(config, Path::new("libstd.so"));
}

#[test]
fn test_xlinker() {
let args = rpaths_to_flags(vec!["a/normal/path".into(), "a,comma,path".into()]);

assert_eq!(args, vec![
OsString::from("-Wl,-rpath,a/normal/path"),
OsString::from("-Wl,-rpath"),
OsString::from("-Xlinker"),
OsString::from("a,comma,path")
]);
}
19 changes: 15 additions & 4 deletions compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ use rustc_ast::util::parser::PREC_UNAMBIGUOUS;
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, StashKey};
use rustc_hir::def::{self, CtorKind, Namespace, Res};
use rustc_hir::def_id::DefId;
use rustc_hir::{self as hir, LangItem};
use rustc_hir::{self as hir, HirId, LangItem};
use rustc_hir_analysis::autoderef::Autoderef;
use rustc_infer::infer;
use rustc_infer::traits::{self, Obligation, ObligationCause, ObligationCauseCode};
@@ -428,7 +428,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) -> Ty<'tcx> {
let (fn_sig, def_id) = match *callee_ty.kind() {
ty::FnDef(def_id, args) => {
self.enforce_context_effects(call_expr.span, def_id, args);
self.enforce_context_effects(Some(call_expr.hir_id), call_expr.span, def_id, args);
let fn_sig = self.tcx.fn_sig(def_id).instantiate(self.tcx, args);

// Unit testing: function items annotated with
@@ -837,6 +837,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
#[tracing::instrument(level = "debug", skip(self, span))]
pub(super) fn enforce_context_effects(
&self,
call_hir_id: Option<HirId>,
span: Span,
callee_did: DefId,
callee_args: GenericArgsRef<'tcx>,
@@ -867,10 +868,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if self.tcx.is_conditionally_const(callee_did) {
let q = self.tcx.const_conditions(callee_did);
// FIXME(const_trait_impl): Use this span with a better cause code.
for (cond, _) in q.instantiate(self.tcx, callee_args) {
for (idx, (cond, pred_span)) in
q.instantiate(self.tcx, callee_args).into_iter().enumerate()
{
let cause = self.cause(
span,
if let Some(hir_id) = call_hir_id {
ObligationCauseCode::HostEffectInExpr(callee_did, pred_span, hir_id, idx)
} else {
ObligationCauseCode::WhereClause(callee_did, pred_span)
},
);
self.register_predicate(Obligation::new(
self.tcx,
self.misc(span),
cause,
self.param_env,
cond.to_host_effect_clause(self.tcx, host),
));
3 changes: 2 additions & 1 deletion compiler/rustc_hir_typeck/src/fallback.rs
Original file line number Diff line number Diff line change
@@ -705,7 +705,8 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {

fn visit_local(&mut self, local: &'tcx hir::LetStmt<'tcx>) -> Self::Result {
// For a local, try suggest annotating the type if it's missing.
if let None = local.ty
if let hir::LocalSource::Normal = local.source
&& let None = local.ty
&& let Some(ty) = self.fcx.typeck_results.borrow().node_type_opt(local.hir_id)
&& let Some(vid) = self.fcx.root_vid(ty)
&& self.reachable_vids.contains(&vid)
3 changes: 2 additions & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
@@ -185,7 +185,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span: Span,
method: MethodCallee<'tcx>,
) {
self.enforce_context_effects(span, method.def_id, method.args);
self.enforce_context_effects(Some(hir_id), span, method.def_id, method.args);
self.write_resolution(hir_id, Ok((DefKind::AssocFn, method.def_id)));
self.write_args(hir_id, method.args);
}
@@ -263,6 +263,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
Adjust::Deref(Some(overloaded_deref)) => {
self.enforce_context_effects(
None,
expr.span,
overloaded_deref.method_call(self.tcx),
self.tcx.mk_args(&[a.target.into()]),
Loading