Skip to content

Commit c745b63

Browse files
committed
Auto merge of #146350 - cuviper:beta-next, r=cuviper
[beta] backports - Rust build fails on OpenBSD after using file_lock feature #145511 - Revert suggestions for missing methods in tuples #145765 - When determining if a trait has no entries for the purposes of omitting vptrs from subtrait vtables, consider its transitive supertraits' entries, instead of just its own entries. #145807 - Ship LLVM tools for the correct target when cross-compiling #145763 - bootstrap: vendor `clippy_test_deps` too #145861 r? cuviper
2 parents fb918ce + b630713 commit c745b63

File tree

18 files changed

+373
-258
lines changed

18 files changed

+373
-258
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 2 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
1313
use rustc_data_structures::sorted_map::SortedMap;
1414
use rustc_data_structures::unord::UnordSet;
1515
use rustc_errors::codes::*;
16-
use rustc_errors::{
17-
Applicability, Diag, DiagStyledString, MultiSpan, StashKey, pluralize, struct_span_code_err,
18-
};
16+
use rustc_errors::{Applicability, Diag, MultiSpan, StashKey, pluralize, struct_span_code_err};
1917
use rustc_hir::attrs::AttributeKind;
2018
use rustc_hir::def::{CtorKind, DefKind, Res};
2119
use rustc_hir::def_id::DefId;
@@ -1572,11 +1570,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15721570
);
15731571
}
15741572

1575-
if rcvr_ty.is_numeric() && rcvr_ty.is_fresh()
1576-
|| restrict_type_params
1577-
|| suggested_derive
1578-
|| self.lookup_alternative_tuple_impls(&mut err, &unsatisfied_predicates)
1579-
{
1573+
if rcvr_ty.is_numeric() && rcvr_ty.is_fresh() || restrict_type_params || suggested_derive {
15801574
} else {
15811575
self.suggest_traits_to_import(
15821576
&mut err,
@@ -1753,119 +1747,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17531747
err.emit()
17541748
}
17551749

1756-
/// If the predicate failure is caused by an unmet bound on a tuple, recheck if the bound would
1757-
/// succeed if all the types on the tuple had no borrows. This is a common problem for libraries
1758-
/// like Bevy and ORMs, which rely heavily on traits being implemented on tuples.
1759-
fn lookup_alternative_tuple_impls(
1760-
&self,
1761-
err: &mut Diag<'_>,
1762-
unsatisfied_predicates: &[(
1763-
ty::Predicate<'tcx>,
1764-
Option<ty::Predicate<'tcx>>,
1765-
Option<ObligationCause<'tcx>>,
1766-
)],
1767-
) -> bool {
1768-
let mut found_tuple = false;
1769-
for (pred, root, _ob) in unsatisfied_predicates {
1770-
let mut preds = vec![pred];
1771-
if let Some(root) = root {
1772-
// We will look at both the current predicate and the root predicate that caused it
1773-
// to be needed. If calling something like `<(A, &B)>::default()`, then `pred` is
1774-
// `&B: Default` and `root` is `(A, &B): Default`, which is the one we are checking
1775-
// for further down, so we check both.
1776-
preds.push(root);
1777-
}
1778-
for pred in preds {
1779-
if let Some(clause) = pred.as_clause()
1780-
&& let Some(clause) = clause.as_trait_clause()
1781-
&& let ty = clause.self_ty().skip_binder()
1782-
&& let ty::Tuple(types) = ty.kind()
1783-
{
1784-
let path = clause.skip_binder().trait_ref.print_only_trait_path();
1785-
let def_id = clause.def_id();
1786-
let ty = Ty::new_tup(
1787-
self.tcx,
1788-
self.tcx.mk_type_list_from_iter(types.iter().map(|ty| ty.peel_refs())),
1789-
);
1790-
let args = ty::GenericArgs::for_item(self.tcx, def_id, |param, _| {
1791-
if param.index == 0 {
1792-
ty.into()
1793-
} else {
1794-
self.infcx.var_for_def(DUMMY_SP, param)
1795-
}
1796-
});
1797-
if self
1798-
.infcx
1799-
.type_implements_trait(def_id, args, self.param_env)
1800-
.must_apply_modulo_regions()
1801-
{
1802-
// "`Trait` is implemented for `(A, B)` but not for `(A, &B)`"
1803-
let mut msg = DiagStyledString::normal(format!("`{path}` "));
1804-
msg.push_highlighted("is");
1805-
msg.push_normal(" implemented for `(");
1806-
let len = types.len();
1807-
for (i, t) in types.iter().enumerate() {
1808-
msg.push(
1809-
format!("{}", with_forced_trimmed_paths!(t.peel_refs())),
1810-
t.peel_refs() != t,
1811-
);
1812-
if i < len - 1 {
1813-
msg.push_normal(", ");
1814-
}
1815-
}
1816-
msg.push_normal(")` but ");
1817-
msg.push_highlighted("not");
1818-
msg.push_normal(" for `(");
1819-
for (i, t) in types.iter().enumerate() {
1820-
msg.push(
1821-
format!("{}", with_forced_trimmed_paths!(t)),
1822-
t.peel_refs() != t,
1823-
);
1824-
if i < len - 1 {
1825-
msg.push_normal(", ");
1826-
}
1827-
}
1828-
msg.push_normal(")`");
1829-
1830-
// Find the span corresponding to the impl that was found to point at it.
1831-
if let Some(impl_span) = self
1832-
.tcx
1833-
.all_impls(def_id)
1834-
.filter(|&impl_def_id| {
1835-
let header = self.tcx.impl_trait_header(impl_def_id).unwrap();
1836-
let trait_ref = header.trait_ref.instantiate(
1837-
self.tcx,
1838-
self.infcx.fresh_args_for_item(DUMMY_SP, impl_def_id),
1839-
);
1840-
1841-
let value = ty::fold_regions(self.tcx, ty, |_, _| {
1842-
self.tcx.lifetimes.re_erased
1843-
});
1844-
// FIXME: Don't bother dealing with non-lifetime binders here...
1845-
if value.has_escaping_bound_vars() {
1846-
return false;
1847-
}
1848-
self.infcx.can_eq(ty::ParamEnv::empty(), trait_ref.self_ty(), value)
1849-
&& header.polarity == ty::ImplPolarity::Positive
1850-
})
1851-
.map(|impl_def_id| self.tcx.def_span(impl_def_id))
1852-
.next()
1853-
{
1854-
err.highlighted_span_note(impl_span, msg.0);
1855-
} else {
1856-
err.highlighted_note(msg.0);
1857-
}
1858-
found_tuple = true;
1859-
}
1860-
// If `pred` was already on the tuple, we don't need to look at the root
1861-
// obligation too.
1862-
break;
1863-
}
1864-
}
1865-
}
1866-
found_tuple
1867-
}
1868-
18691750
/// If an appropriate error source is not found, check method chain for possible candidates
18701751
fn lookup_segments_chain_for_no_match_method(
18711752
&self,

compiler/rustc_trait_selection/src/traits/vtable.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@ fn prepare_vtable_segments_inner<'tcx, T>(
153153

154154
// emit innermost item, move to next sibling and stop there if possible, otherwise jump to outer level.
155155
while let Some((inner_most_trait_ref, emit_vptr, mut siblings)) = stack.pop() {
156-
let has_entries = has_own_existential_vtable_entries(tcx, inner_most_trait_ref.def_id);
156+
// We don't need to emit a vptr for "truly-empty" supertraits, but we *do* need to emit a
157+
// vptr for supertraits that have no methods, but that themselves have supertraits
158+
// with methods, so we check if any transitive supertrait has entries here (this includes
159+
// the trait itself).
160+
let has_entries = ty::elaborate::supertrait_def_ids(tcx, inner_most_trait_ref.def_id)
161+
.any(|def_id| has_own_existential_vtable_entries(tcx, def_id));
157162

158163
segment_visitor(VtblSegment::TraitOwnEntries {
159164
trait_ref: inner_most_trait_ref,

library/std/src/sys/fs/unix.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,7 @@ impl File {
12631263
target_os = "fuchsia",
12641264
target_os = "linux",
12651265
target_os = "netbsd",
1266+
target_os = "openbsd",
12661267
target_vendor = "apple",
12671268
))]
12681269
pub fn lock(&self) -> io::Result<()> {
@@ -1275,6 +1276,7 @@ impl File {
12751276
target_os = "fuchsia",
12761277
target_os = "linux",
12771278
target_os = "netbsd",
1279+
target_os = "openbsd",
12781280
target_vendor = "apple",
12791281
)))]
12801282
pub fn lock(&self) -> io::Result<()> {
@@ -1286,6 +1288,7 @@ impl File {
12861288
target_os = "fuchsia",
12871289
target_os = "linux",
12881290
target_os = "netbsd",
1291+
target_os = "openbsd",
12891292
target_vendor = "apple",
12901293
))]
12911294
pub fn lock_shared(&self) -> io::Result<()> {
@@ -1298,6 +1301,7 @@ impl File {
12981301
target_os = "fuchsia",
12991302
target_os = "linux",
13001303
target_os = "netbsd",
1304+
target_os = "openbsd",
13011305
target_vendor = "apple",
13021306
)))]
13031307
pub fn lock_shared(&self) -> io::Result<()> {
@@ -1309,6 +1313,7 @@ impl File {
13091313
target_os = "fuchsia",
13101314
target_os = "linux",
13111315
target_os = "netbsd",
1316+
target_os = "openbsd",
13121317
target_vendor = "apple",
13131318
))]
13141319
pub fn try_lock(&self) -> Result<(), TryLockError> {
@@ -1329,6 +1334,7 @@ impl File {
13291334
target_os = "fuchsia",
13301335
target_os = "linux",
13311336
target_os = "netbsd",
1337+
target_os = "openbsd",
13321338
target_vendor = "apple",
13331339
)))]
13341340
pub fn try_lock(&self) -> Result<(), TryLockError> {
@@ -1343,6 +1349,7 @@ impl File {
13431349
target_os = "fuchsia",
13441350
target_os = "linux",
13451351
target_os = "netbsd",
1352+
target_os = "openbsd",
13461353
target_vendor = "apple",
13471354
))]
13481355
pub fn try_lock_shared(&self) -> Result<(), TryLockError> {
@@ -1363,6 +1370,7 @@ impl File {
13631370
target_os = "fuchsia",
13641371
target_os = "linux",
13651372
target_os = "netbsd",
1373+
target_os = "openbsd",
13661374
target_vendor = "apple",
13671375
)))]
13681376
pub fn try_lock_shared(&self) -> Result<(), TryLockError> {
@@ -1377,6 +1385,7 @@ impl File {
13771385
target_os = "fuchsia",
13781386
target_os = "linux",
13791387
target_os = "netbsd",
1388+
target_os = "openbsd",
13801389
target_vendor = "apple",
13811390
))]
13821391
pub fn unlock(&self) -> io::Result<()> {
@@ -1389,6 +1398,7 @@ impl File {
13891398
target_os = "fuchsia",
13901399
target_os = "linux",
13911400
target_os = "netbsd",
1401+
target_os = "openbsd",
13921402
target_vendor = "apple",
13931403
)))]
13941404
pub fn unlock(&self) -> io::Result<()> {

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,8 +1416,8 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
14161416
if builder.config.llvm_enzyme {
14171417
cargo.env("LLVM_ENZYME", "1");
14181418
}
1419-
let llvm::LlvmResult { llvm_config, .. } = builder.ensure(llvm::Llvm { target });
1420-
cargo.env("LLVM_CONFIG", &llvm_config);
1419+
let llvm::LlvmResult { host_llvm_config, .. } = builder.ensure(llvm::Llvm { target });
1420+
cargo.env("LLVM_CONFIG", &host_llvm_config);
14211421

14221422
// Some LLVM linker flags (-L and -l) may be needed to link `rustc_llvm`. Its build script
14231423
// expects these to be passed via the `LLVM_LINKER_FLAGS` env variable, separated by
@@ -2012,14 +2012,52 @@ impl Step for Assemble {
20122012
if builder.config.llvm_enabled(target_compiler.host) {
20132013
trace!("target_compiler.host" = ?target_compiler.host, "LLVM enabled");
20142014

2015-
let llvm::LlvmResult { llvm_config, .. } =
2016-
builder.ensure(llvm::Llvm { target: target_compiler.host });
2015+
let target = target_compiler.host;
2016+
let llvm::LlvmResult { host_llvm_config, .. } = builder.ensure(llvm::Llvm { target });
20172017
if !builder.config.dry_run() && builder.config.llvm_tools_enabled {
20182018
trace!("LLVM tools enabled");
20192019

2020-
let llvm_bin_dir =
2021-
command(llvm_config).arg("--bindir").run_capture_stdout(builder).stdout();
2022-
let llvm_bin_dir = Path::new(llvm_bin_dir.trim());
2020+
let host_llvm_bin_dir = command(&host_llvm_config)
2021+
.arg("--bindir")
2022+
.run_capture_stdout(builder)
2023+
.stdout()
2024+
.trim()
2025+
.to_string();
2026+
2027+
let llvm_bin_dir = if target == builder.host_target {
2028+
PathBuf::from(host_llvm_bin_dir)
2029+
} else {
2030+
// If we're cross-compiling, we cannot run the target llvm-config in order to
2031+
// figure out where binaries are located. We thus have to guess.
2032+
let external_llvm_config = builder
2033+
.config
2034+
.target_config
2035+
.get(&target)
2036+
.and_then(|t| t.llvm_config.clone());
2037+
if let Some(external_llvm_config) = external_llvm_config {
2038+
// If we have an external LLVM, just hope that the bindir is the directory
2039+
// where the LLVM config is located
2040+
external_llvm_config.parent().unwrap().to_path_buf()
2041+
} else {
2042+
// If we have built LLVM locally, then take the path of the host bindir
2043+
// relative to its output build directory, and then apply it to the target
2044+
// LLVM output build directory.
2045+
let host_llvm_out = builder.llvm_out(builder.host_target);
2046+
let target_llvm_out = builder.llvm_out(target);
2047+
if let Ok(relative_path) =
2048+
Path::new(&host_llvm_bin_dir).strip_prefix(host_llvm_out)
2049+
{
2050+
target_llvm_out.join(relative_path)
2051+
} else {
2052+
// This is the most desperate option, just replace the host target with
2053+
// the actual target in the directory path...
2054+
PathBuf::from(
2055+
host_llvm_bin_dir
2056+
.replace(&*builder.host_target.triple, &target.triple),
2057+
)
2058+
}
2059+
}
2060+
};
20232061

20242062
// Since we've already built the LLVM tools, install them to the sysroot.
20252063
// This is the equivalent of installing the `llvm-tools-preview` component via

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,11 +2176,12 @@ fn maybe_install_llvm(
21762176
builder.install(&llvm_dylib_path, dst_libdir, FileType::NativeLibrary);
21772177
}
21782178
!builder.config.dry_run()
2179-
} else if let llvm::LlvmBuildStatus::AlreadyBuilt(llvm::LlvmResult { llvm_config, .. }) =
2180-
llvm::prebuilt_llvm_config(builder, target, true)
2179+
} else if let llvm::LlvmBuildStatus::AlreadyBuilt(llvm::LlvmResult {
2180+
host_llvm_config, ..
2181+
}) = llvm::prebuilt_llvm_config(builder, target, true)
21812182
{
21822183
trace!("LLVM already built, installing LLVM files");
2183-
let mut cmd = command(llvm_config);
2184+
let mut cmd = command(host_llvm_config);
21842185
cmd.arg("--libfiles");
21852186
builder.verbose(|| println!("running {cmd:?}"));
21862187
let files = cmd.run_capture_stdout(builder).stdout();

0 commit comments

Comments
 (0)