Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
123 changes: 2 additions & 121 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::unord::UnordSet;
use rustc_errors::codes::*;
use rustc_errors::{
Applicability, Diag, DiagStyledString, MultiSpan, StashKey, pluralize, struct_span_code_err,
};
use rustc_errors::{Applicability, Diag, MultiSpan, StashKey, pluralize, struct_span_code_err};
use rustc_hir::attrs::AttributeKind;
use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::def_id::DefId;
Expand Down Expand Up @@ -1572,11 +1570,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
}

if rcvr_ty.is_numeric() && rcvr_ty.is_fresh()
|| restrict_type_params
|| suggested_derive
|| self.lookup_alternative_tuple_impls(&mut err, &unsatisfied_predicates)
{
if rcvr_ty.is_numeric() && rcvr_ty.is_fresh() || restrict_type_params || suggested_derive {
} else {
self.suggest_traits_to_import(
&mut err,
Expand Down Expand Up @@ -1753,119 +1747,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.emit()
}

/// If the predicate failure is caused by an unmet bound on a tuple, recheck if the bound would
/// succeed if all the types on the tuple had no borrows. This is a common problem for libraries
/// like Bevy and ORMs, which rely heavily on traits being implemented on tuples.
fn lookup_alternative_tuple_impls(
&self,
err: &mut Diag<'_>,
unsatisfied_predicates: &[(
ty::Predicate<'tcx>,
Option<ty::Predicate<'tcx>>,
Option<ObligationCause<'tcx>>,
)],
) -> bool {
let mut found_tuple = false;
for (pred, root, _ob) in unsatisfied_predicates {
let mut preds = vec![pred];
if let Some(root) = root {
// We will look at both the current predicate and the root predicate that caused it
// to be needed. If calling something like `<(A, &B)>::default()`, then `pred` is
// `&B: Default` and `root` is `(A, &B): Default`, which is the one we are checking
// for further down, so we check both.
preds.push(root);
}
for pred in preds {
if let Some(clause) = pred.as_clause()
&& let Some(clause) = clause.as_trait_clause()
&& let ty = clause.self_ty().skip_binder()
&& let ty::Tuple(types) = ty.kind()
{
let path = clause.skip_binder().trait_ref.print_only_trait_path();
let def_id = clause.def_id();
let ty = Ty::new_tup(
self.tcx,
self.tcx.mk_type_list_from_iter(types.iter().map(|ty| ty.peel_refs())),
);
let args = ty::GenericArgs::for_item(self.tcx, def_id, |param, _| {
if param.index == 0 {
ty.into()
} else {
self.infcx.var_for_def(DUMMY_SP, param)
}
});
if self
.infcx
.type_implements_trait(def_id, args, self.param_env)
.must_apply_modulo_regions()
{
// "`Trait` is implemented for `(A, B)` but not for `(A, &B)`"
let mut msg = DiagStyledString::normal(format!("`{path}` "));
msg.push_highlighted("is");
msg.push_normal(" implemented for `(");
let len = types.len();
for (i, t) in types.iter().enumerate() {
msg.push(
format!("{}", with_forced_trimmed_paths!(t.peel_refs())),
t.peel_refs() != t,
);
if i < len - 1 {
msg.push_normal(", ");
}
}
msg.push_normal(")` but ");
msg.push_highlighted("not");
msg.push_normal(" for `(");
for (i, t) in types.iter().enumerate() {
msg.push(
format!("{}", with_forced_trimmed_paths!(t)),
t.peel_refs() != t,
);
if i < len - 1 {
msg.push_normal(", ");
}
}
msg.push_normal(")`");

// Find the span corresponding to the impl that was found to point at it.
if let Some(impl_span) = self
.tcx
.all_impls(def_id)
.filter(|&impl_def_id| {
let header = self.tcx.impl_trait_header(impl_def_id).unwrap();
let trait_ref = header.trait_ref.instantiate(
self.tcx,
self.infcx.fresh_args_for_item(DUMMY_SP, impl_def_id),
);

let value = ty::fold_regions(self.tcx, ty, |_, _| {
self.tcx.lifetimes.re_erased
});
// FIXME: Don't bother dealing with non-lifetime binders here...
if value.has_escaping_bound_vars() {
return false;
}
self.infcx.can_eq(ty::ParamEnv::empty(), trait_ref.self_ty(), value)
&& header.polarity == ty::ImplPolarity::Positive
})
.map(|impl_def_id| self.tcx.def_span(impl_def_id))
.next()
{
err.highlighted_span_note(impl_span, msg.0);
} else {
err.highlighted_note(msg.0);
}
found_tuple = true;
}
// If `pred` was already on the tuple, we don't need to look at the root
// obligation too.
break;
}
}
}
found_tuple
}

/// If an appropriate error source is not found, check method chain for possible candidates
fn lookup_segments_chain_for_no_match_method(
&self,
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_trait_selection/src/traits/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ fn prepare_vtable_segments_inner<'tcx, T>(

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

segment_visitor(VtblSegment::TraitOwnEntries {
trait_ref: inner_most_trait_ref,
Expand Down
10 changes: 10 additions & 0 deletions library/std/src/sys/fs/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,7 @@ impl File {
target_os = "fuchsia",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_vendor = "apple",
))]
pub fn lock(&self) -> io::Result<()> {
Expand All @@ -1275,6 +1276,7 @@ impl File {
target_os = "fuchsia",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_vendor = "apple",
)))]
pub fn lock(&self) -> io::Result<()> {
Expand All @@ -1286,6 +1288,7 @@ impl File {
target_os = "fuchsia",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_vendor = "apple",
))]
pub fn lock_shared(&self) -> io::Result<()> {
Expand All @@ -1298,6 +1301,7 @@ impl File {
target_os = "fuchsia",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_vendor = "apple",
)))]
pub fn lock_shared(&self) -> io::Result<()> {
Expand All @@ -1309,6 +1313,7 @@ impl File {
target_os = "fuchsia",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_vendor = "apple",
))]
pub fn try_lock(&self) -> Result<(), TryLockError> {
Expand All @@ -1329,6 +1334,7 @@ impl File {
target_os = "fuchsia",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_vendor = "apple",
)))]
pub fn try_lock(&self) -> Result<(), TryLockError> {
Expand All @@ -1343,6 +1349,7 @@ impl File {
target_os = "fuchsia",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_vendor = "apple",
))]
pub fn try_lock_shared(&self) -> Result<(), TryLockError> {
Expand All @@ -1363,6 +1370,7 @@ impl File {
target_os = "fuchsia",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_vendor = "apple",
)))]
pub fn try_lock_shared(&self) -> Result<(), TryLockError> {
Expand All @@ -1377,6 +1385,7 @@ impl File {
target_os = "fuchsia",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_vendor = "apple",
))]
pub fn unlock(&self) -> io::Result<()> {
Expand All @@ -1389,6 +1398,7 @@ impl File {
target_os = "fuchsia",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_vendor = "apple",
)))]
pub fn unlock(&self) -> io::Result<()> {
Expand Down
52 changes: 45 additions & 7 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,8 +1416,8 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
if builder.config.llvm_enzyme {
cargo.env("LLVM_ENZYME", "1");
}
let llvm::LlvmResult { llvm_config, .. } = builder.ensure(llvm::Llvm { target });
cargo.env("LLVM_CONFIG", &llvm_config);
let llvm::LlvmResult { host_llvm_config, .. } = builder.ensure(llvm::Llvm { target });
cargo.env("LLVM_CONFIG", &host_llvm_config);

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

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

let llvm_bin_dir =
command(llvm_config).arg("--bindir").run_capture_stdout(builder).stdout();
let llvm_bin_dir = Path::new(llvm_bin_dir.trim());
let host_llvm_bin_dir = command(&host_llvm_config)
.arg("--bindir")
.run_capture_stdout(builder)
.stdout()
.trim()
.to_string();

let llvm_bin_dir = if target == builder.host_target {
PathBuf::from(host_llvm_bin_dir)
} else {
// If we're cross-compiling, we cannot run the target llvm-config in order to
// figure out where binaries are located. We thus have to guess.
let external_llvm_config = builder
.config
.target_config
.get(&target)
.and_then(|t| t.llvm_config.clone());
if let Some(external_llvm_config) = external_llvm_config {
// If we have an external LLVM, just hope that the bindir is the directory
// where the LLVM config is located
external_llvm_config.parent().unwrap().to_path_buf()
} else {
// If we have built LLVM locally, then take the path of the host bindir
// relative to its output build directory, and then apply it to the target
// LLVM output build directory.
let host_llvm_out = builder.llvm_out(builder.host_target);
let target_llvm_out = builder.llvm_out(target);
if let Ok(relative_path) =
Path::new(&host_llvm_bin_dir).strip_prefix(host_llvm_out)
{
target_llvm_out.join(relative_path)
} else {
// This is the most desperate option, just replace the host target with
// the actual target in the directory path...
PathBuf::from(
host_llvm_bin_dir
.replace(&*builder.host_target.triple, &target.triple),
)
}
}
};

// Since we've already built the LLVM tools, install them to the sysroot.
// This is the equivalent of installing the `llvm-tools-preview` component via
Expand Down
7 changes: 4 additions & 3 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2176,11 +2176,12 @@ fn maybe_install_llvm(
builder.install(&llvm_dylib_path, dst_libdir, FileType::NativeLibrary);
}
!builder.config.dry_run()
} else if let llvm::LlvmBuildStatus::AlreadyBuilt(llvm::LlvmResult { llvm_config, .. }) =
llvm::prebuilt_llvm_config(builder, target, true)
} else if let llvm::LlvmBuildStatus::AlreadyBuilt(llvm::LlvmResult {
host_llvm_config, ..
}) = llvm::prebuilt_llvm_config(builder, target, true)
{
trace!("LLVM already built, installing LLVM files");
let mut cmd = command(llvm_config);
let mut cmd = command(host_llvm_config);
cmd.arg("--libfiles");
builder.verbose(|| println!("running {cmd:?}"));
let files = cmd.run_capture_stdout(builder).stdout();
Expand Down
Loading
Loading