Skip to content
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

Rollup of 6 pull requests #127646

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a1ad634
Add fn allocator method to rc/sync::Weak. Relax Rc<T>/Arc<T>::allocat…
zachs18 May 10, 2024
5c46aca
document the cvt methods
the8472 Jun 22, 2024
6687a3f
use pidfd_spawn for faster process creation when pidfds are requested
the8472 Jun 22, 2024
0ce3619
document safety properties of the internal Process::new constructor
the8472 Jun 24, 2024
3e4e31b
more fine-grained feature-detection for pidfd spawning
the8472 Jun 24, 2024
ec0c755
Check that we get somewhat sane PIDs when spawning with pidfds
the8472 Jun 24, 2024
53d3e62
Stabilize const_cstr_from_ptr (CStr::from_ptr, CStr::count_bytes)
dtolnay Jul 6, 2024
55256c5
Update dist-riscv64-linux to binutils 2.40
nikic Jul 10, 2024
ec05c4e
Add the feature gate and target-features
sayantn Jun 23, 2024
eb70788
Maintain highlighting in `note` and `help` even when they have a span
estebank May 9, 2024
c997e71
On trait bound mismatch, detect multiple crate versions in dep tree
estebank May 9, 2024
2fbb9e6
Add test for mixing types from two incompatible crate versions
estebank May 13, 2024
d55bf26
Add `help` about using `cargo tree`
estebank May 13, 2024
5099d71
fix rebase
estebank Jul 12, 2024
a0f5dee
Change test to be only-linux and ignore-wasm32
estebank Jul 12, 2024
7f1518b
Add instability attribute on private const_strlen function
dtolnay Jul 12, 2024
ca0aee4
Rollup merge of #124944 - estebank:multiple-crate-versions, r=fee1-dead
matthiaskrgr Jul 12, 2024
5361791
Rollup merge of #124980 - zachs18:rc-allocator, r=Amanieu
matthiaskrgr Jul 12, 2024
4d1e87d
Rollup merge of #126639 - sayantn:amx, r=Amanieu
matthiaskrgr Jul 12, 2024
8392cac
Rollup merge of #126827 - the8472:pidfd-spawn, r=workingjubilee
matthiaskrgr Jul 12, 2024
73ee1a9
Rollup merge of #127433 - dtolnay:conststrlen, r=workingjubilee
matthiaskrgr Jul 12, 2024
0d3fdbc
Rollup merge of #127613 - nikic:riscv-update, r=cuviper
matthiaskrgr Jul 12, 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
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub fn from_target_feature(
Some(sym::loongarch_target_feature) => rust_features.loongarch_target_feature,
Some(sym::lahfsahf_target_feature) => rust_features.lahfsahf_target_feature,
Some(sym::prfchw_target_feature) => rust_features.prfchw_target_feature,
Some(sym::x86_amx_intrinsics) => rust_features.x86_amx_intrinsics,
Some(name) => bug!("unknown target feature gate {}", name),
None => true,
};
Expand Down
21 changes: 21 additions & 0 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,16 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
self
}

#[rustc_lint_diagnostics]
pub fn highlighted_span_note(
&mut self,
span: impl Into<MultiSpan>,
msg: Vec<StringPart>,
) -> &mut Self {
self.sub_with_highlights(Level::Note, msg, span.into());
self
}

/// This is like [`Diag::note()`], but it's only printed once.
#[rustc_lint_diagnostics]
pub fn note_once(&mut self, msg: impl Into<SubdiagMessage>) -> &mut Self {
Expand Down Expand Up @@ -814,6 +824,17 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
self
}

/// Add a help message attached to this diagnostic with a customizable highlighted message.
#[rustc_lint_diagnostics]
pub fn highlighted_span_help(
&mut self,
span: impl Into<MultiSpan>,
msg: Vec<StringPart>,
) -> &mut Self {
self.sub_with_highlights(Level::Help, msg, span.into());
self
}

/// Prints the span with some help above it.
/// This is like [`Diag::help()`], but it gets its own span.
#[rustc_lint_diagnostics]
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ impl HumanEmitter {
buffer.append(0, ": ", header_style);
label_width += 2;
}
for (text, _) in msgs.iter() {
for (text, style) in msgs.iter() {
let text = self.translate_message(text, args).map_err(Report::new).unwrap();
// Account for newlines to align output to its label.
for (line, text) in normalize_whitespace(&text).lines().enumerate() {
Expand All @@ -1364,7 +1364,10 @@ impl HumanEmitter {
if line == 0 { String::new() } else { " ".repeat(label_width) },
text
),
header_style,
match style {
Style::Highlight => *style,
_ => header_style,
},
);
}
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,8 @@ declare_features! (
(unstable, unsized_tuple_coercion, "1.20.0", Some(42877)),
/// Allows using the `#[used(linker)]` (or `#[used(compiler)]`) attribute.
(unstable, used_with_arg, "1.60.0", Some(93798)),
/// Allows use of x86 `AMX` target-feature attributes and intrinsics
(unstable, x86_amx_intrinsics, "CURRENT_RUSTC_VERSION", Some(126622)),
/// Allows `do yeet` expressions
(unstable, yeet_expr, "1.62.0", Some(96373)),
// !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!! !!!!
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,7 @@ symbols! {
write_str,
write_via_move,
writeln_macro,
x86_amx_intrinsics,
x87_reg,
xer,
xmm_reg,
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ const X86_ALLOWED_FEATURES: &[(&str, Stability)] = &[
// tidy-alphabetical-start
("adx", Stable),
("aes", Stable),
("amx-bf16", Unstable(sym::x86_amx_intrinsics)),
("amx-complex", Unstable(sym::x86_amx_intrinsics)),
("amx-fp16", Unstable(sym::x86_amx_intrinsics)),
("amx-int8", Unstable(sym::x86_amx_intrinsics)),
("amx-tile", Unstable(sym::x86_amx_intrinsics)),
("avx", Stable),
("avx2", Stable),
("avx512bf16", Unstable(sym::avx512_target_feature)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ use core::ops::ControlFlow;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::unord::UnordSet;
use rustc_errors::codes::*;
use rustc_errors::{pluralize, struct_span_code_err, Applicability, StringPart};
use rustc_errors::{Diag, ErrorGuaranteed, StashKey};
use rustc_errors::{
pluralize, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, MultiSpan, StashKey,
StringPart,
};
use rustc_hir::def::Namespace;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
use rustc_hir::intravisit::Visitor;
use rustc_hir::Node;
use rustc_hir::{self as hir, LangItem};
Expand Down Expand Up @@ -1624,9 +1626,131 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
other: bool,
param_env: ty::ParamEnv<'tcx>,
) -> bool {
// If we have a single implementation, try to unify it with the trait ref
// that failed. This should uncover a better hint for what *is* implemented.
let alternative_candidates = |def_id: DefId| {
let mut impl_candidates: Vec<_> = self
.tcx
.all_impls(def_id)
// ignore `do_not_recommend` items
.filter(|def_id| {
!self
.tcx
.has_attrs_with_path(*def_id, &[sym::diagnostic, sym::do_not_recommend])
})
// Ignore automatically derived impls and `!Trait` impls.
.filter_map(|def_id| self.tcx.impl_trait_header(def_id))
.filter_map(|header| {
(header.polarity != ty::ImplPolarity::Negative
|| self.tcx.is_automatically_derived(def_id))
.then(|| header.trait_ref.instantiate_identity())
})
.filter(|trait_ref| {
let self_ty = trait_ref.self_ty();
// Avoid mentioning type parameters.
if let ty::Param(_) = self_ty.kind() {
false
}
// Avoid mentioning types that are private to another crate
else if let ty::Adt(def, _) = self_ty.peel_refs().kind() {
// FIXME(compiler-errors): This could be generalized, both to
// be more granular, and probably look past other `#[fundamental]`
// types, too.
self.tcx.visibility(def.did()).is_accessible_from(body_def_id, self.tcx)
} else {
true
}
})
.collect();

impl_candidates.sort_by_key(|tr| tr.to_string());
impl_candidates.dedup();
impl_candidates
};

// We'll check for the case where the reason for the mismatch is that the trait comes from
// one crate version and the type comes from another crate version, even though they both
// are from the same crate.
let trait_def_id = trait_ref.def_id();
if let ty::Adt(def, _) = trait_ref.self_ty().skip_binder().peel_refs().kind()
&& let found_type = def.did()
&& trait_def_id.krate != found_type.krate
&& self.tcx.crate_name(trait_def_id.krate) == self.tcx.crate_name(found_type.krate)
{
let name = self.tcx.crate_name(trait_def_id.krate);
let spans: Vec<_> = [trait_def_id, found_type]
.into_iter()
.filter_map(|def_id| self.tcx.extern_crate(def_id))
.map(|data| {
let dependency = if data.dependency_of == LOCAL_CRATE {
"direct dependency of the current crate".to_string()
} else {
let dep = self.tcx.crate_name(data.dependency_of);
format!("dependency of crate `{dep}`")
};
(
data.span,
format!("one version of crate `{name}` is used here, as a {dependency}"),
)
})
.collect();
let mut span: MultiSpan = spans.iter().map(|(sp, _)| *sp).collect::<Vec<Span>>().into();
for (sp, label) in spans.into_iter() {
span.push_span_label(sp, label);
}
err.highlighted_span_help(
span,
vec![
StringPart::normal("you have ".to_string()),
StringPart::highlighted("multiple different versions".to_string()),
StringPart::normal(" of crate `".to_string()),
StringPart::highlighted(format!("{name}")),
StringPart::normal("` in your dependency graph".to_string()),
],
);
let candidates = if impl_candidates.is_empty() {
alternative_candidates(trait_def_id)
} else {
impl_candidates.into_iter().map(|cand| cand.trait_ref).collect()
};
if let Some((sp_candidate, sp_found)) = candidates.iter().find_map(|trait_ref| {
if let ty::Adt(def, _) = trait_ref.self_ty().peel_refs().kind()
&& let candidate_def_id = def.did()
&& let Some(name) = self.tcx.opt_item_name(candidate_def_id)
&& let Some(found) = self.tcx.opt_item_name(found_type)
&& name == found
&& candidate_def_id.krate != found_type.krate
&& self.tcx.crate_name(candidate_def_id.krate)
== self.tcx.crate_name(found_type.krate)
{
// A candidate was found of an item with the same name, from two separate
// versions of the same crate, let's clarify.
Some((self.tcx.def_span(candidate_def_id), self.tcx.def_span(found_type)))
} else {
None
}
}) {
let mut span: MultiSpan = vec![sp_candidate, sp_found].into();
span.push_span_label(self.tcx.def_span(trait_def_id), "this is the required trait");
span.push_span_label(sp_candidate, "this type implements the required trait");
span.push_span_label(sp_found, "this type doesn't implement the required trait");
err.highlighted_span_note(
span,
vec![
StringPart::normal(
"two types coming from two different versions of the same crate are \
different types "
.to_string(),
),
StringPart::highlighted("even if they look the same".to_string()),
],
);
}
err.help("you can use `cargo tree` to explore your dependency tree");
return true;
}

if let [single] = &impl_candidates {
// If we have a single implementation, try to unify it with the trait ref
// that failed. This should uncover a better hint for what *is* implemented.
if self.probe(|_| {
let ocx = ObligationCtxt::new(self);

Expand Down Expand Up @@ -1798,43 +1922,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// Mentioning implementers of `Copy`, `Debug` and friends is not useful.
return false;
}
let mut impl_candidates: Vec<_> = self
.tcx
.all_impls(def_id)
// ignore `do_not_recommend` items
.filter(|def_id| {
!self
.tcx
.has_attrs_with_path(*def_id, &[sym::diagnostic, sym::do_not_recommend])
})
// Ignore automatically derived impls and `!Trait` impls.
.filter_map(|def_id| self.tcx.impl_trait_header(def_id))
.filter_map(|header| {
(header.polarity != ty::ImplPolarity::Negative
|| self.tcx.is_automatically_derived(def_id))
.then(|| header.trait_ref.instantiate_identity())
})
.filter(|trait_ref| {
let self_ty = trait_ref.self_ty();
// Avoid mentioning type parameters.
if let ty::Param(_) = self_ty.kind() {
false
}
// Avoid mentioning types that are private to another crate
else if let ty::Adt(def, _) = self_ty.peel_refs().kind() {
// FIXME(compiler-errors): This could be generalized, both to
// be more granular, and probably look past other `#[fundamental]`
// types, too.
self.tcx.visibility(def.did()).is_accessible_from(body_def_id, self.tcx)
} else {
true
}
})
.collect();

impl_candidates.sort_by_key(|tr| tr.to_string());
impl_candidates.dedup();
return report(impl_candidates, err);
return report(alternative_candidates(def_id), err);
}

// Sort impl candidates so that ordering is consistent for UI tests.
Expand Down
28 changes: 18 additions & 10 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,16 +665,6 @@ impl<T> Rc<T> {
}

impl<T, A: Allocator> Rc<T, A> {
/// Returns a reference to the underlying allocator.
///
/// Note: this is an associated function, which means that you have
/// to call it as `Rc::allocator(&r)` instead of `r.allocator()`. This
/// is so that there is no conflict with a method on the inner type.
#[inline]
#[unstable(feature = "allocator_api", issue = "32838")]
pub fn allocator(this: &Self) -> &A {
&this.alloc
}
/// Constructs a new `Rc` in the provided allocator.
///
/// # Examples
Expand Down Expand Up @@ -1331,6 +1321,17 @@ impl<T: ?Sized> Rc<T> {
}

impl<T: ?Sized, A: Allocator> Rc<T, A> {
/// Returns a reference to the underlying allocator.
///
/// Note: this is an associated function, which means that you have
/// to call it as `Rc::allocator(&r)` instead of `r.allocator()`. This
/// is so that there is no conflict with a method on the inner type.
#[inline]
#[unstable(feature = "allocator_api", issue = "32838")]
pub fn allocator(this: &Self) -> &A {
&this.alloc
}

/// Consumes the `Rc`, returning the wrapped pointer.
///
/// To avoid a memory leak the pointer must be converted back to an `Rc` using
Expand Down Expand Up @@ -2994,6 +2995,13 @@ impl<T: ?Sized> Weak<T> {
}

impl<T: ?Sized, A: Allocator> Weak<T, A> {
/// Returns a reference to the underlying allocator.
#[inline]
#[unstable(feature = "allocator_api", issue = "32838")]
pub fn allocator(&self) -> &A {
&self.alloc
}

/// Returns a raw pointer to the object `T` pointed to by this `Weak<T>`.
///
/// The pointer is valid only if there are some strong references. The pointer may be dangling,
Expand Down
28 changes: 18 additions & 10 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,16 +677,6 @@ impl<T> Arc<T> {
}

impl<T, A: Allocator> Arc<T, A> {
/// Returns a reference to the underlying allocator.
///
/// Note: this is an associated function, which means that you have
/// to call it as `Arc::allocator(&a)` instead of `a.allocator()`. This
/// is so that there is no conflict with a method on the inner type.
#[inline]
#[unstable(feature = "allocator_api", issue = "32838")]
pub fn allocator(this: &Self) -> &A {
&this.alloc
}
/// Constructs a new `Arc<T>` in the provided allocator.
///
/// # Examples
Expand Down Expand Up @@ -1470,6 +1460,17 @@ impl<T: ?Sized> Arc<T> {
}

impl<T: ?Sized, A: Allocator> Arc<T, A> {
/// Returns a reference to the underlying allocator.
///
/// Note: this is an associated function, which means that you have
/// to call it as `Arc::allocator(&a)` instead of `a.allocator()`. This
/// is so that there is no conflict with a method on the inner type.
#[inline]
#[unstable(feature = "allocator_api", issue = "32838")]
pub fn allocator(this: &Self) -> &A {
&this.alloc
}

/// Consumes the `Arc`, returning the wrapped pointer.
///
/// To avoid a memory leak the pointer must be converted back to an `Arc` using
Expand Down Expand Up @@ -2715,6 +2716,13 @@ impl<T: ?Sized> Weak<T> {
}

impl<T: ?Sized, A: Allocator> Weak<T, A> {
/// Returns a reference to the underlying allocator.
#[inline]
#[unstable(feature = "allocator_api", issue = "32838")]
pub fn allocator(&self) -> &A {
&self.alloc
}

/// Returns a raw pointer to the object `T` pointed to by this `Weak<T>`.
///
/// The pointer is valid only if there are some strong references. The pointer may be dangling,
Expand Down
Loading
Loading