Skip to content

Rollup of 8 pull requests #133694

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 19 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
528b37a
std: refactor `pthread`-based synchronization
joboet Oct 28, 2024
87c045e
Robustify and genericize RTN resolution in RBV
compiler-errors Oct 22, 2024
959801f
Handle bounds that come from the trait itself
compiler-errors Nov 7, 2024
0f5759a
Address review comments
compiler-errors Nov 26, 2024
d599d5a
fix: fix codeblocks in `PathBuf` example
SanchithHegde Nov 28, 2024
27c4c3a
update link to "C++ Exceptions under the hood" blog
mkroening Nov 29, 2024
43ae473
fix: hurd build, stat64.st_fsid was renamed to st_dev
SteveLauC Nov 30, 2024
8b2ff49
std: clarify comments about initialization
joboet Nov 30, 2024
fa7449d
Do not create trait object type if missing associated types
compiler-errors Nov 30, 2024
484c561
Add diagnostic item for `std::ops::ControlFlow`
samueltardieu Nov 30, 2024
4cb1582
Fixed typos by changing `happend` to `happened`
HomelikeBrick42 Nov 30, 2024
fe4c6e8
Rollup merge of #128184 - joboet:refactor_pthread_sync, r=workingjubilee
matthiaskrgr Dec 1, 2024
20af878
Rollup merge of #132047 - compiler-errors:rbv-rtn-cleanup, r=cjgillot
matthiaskrgr Dec 1, 2024
ec7caab
Rollup merge of #133515 - SteveLauC:fix/hurd, r=ChrisDenton
matthiaskrgr Dec 1, 2024
61d50fd
Rollup merge of #133602 - SanchithHegde:fix-pathbuf-example-codeblock…
matthiaskrgr Dec 1, 2024
5d87be3
Rollup merge of #133622 - mkroening:exception-blog, r=cuviper
matthiaskrgr Dec 1, 2024
4d5ad19
Rollup merge of #133660 - compiler-errors:trait-obj-missing-assoc, r=…
matthiaskrgr Dec 1, 2024
3d36579
Rollup merge of #133686 - samueltardieu:push-xkxwxzxqokuu, r=compiler…
matthiaskrgr Dec 1, 2024
c0fa0ec
Rollup merge of #133689 - HomelikeBrick42:master, r=jieyouxu
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
145 changes: 110 additions & 35 deletions compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2060,48 +2060,37 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
};
match path.res {
Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { trait_: _ } => {
// Get the generics of this type's hir owner. This is *different*
// from the generics of the parameter's definition, since we want
// to be able to resolve an RTN path on a nested body (e.g. method
// inside an impl) using the where clauses on the method.
// FIXME(return_type_notation): Think of some better way of doing this.
let Some(generics) = self.tcx.hir_owner_node(hir_id.owner).generics()
else {
return;
};

// Look for the first bound that contains an associated type that
// matches the segment that we're looking for. We ignore any subsequent
// bounds since we'll be emitting a hard error in HIR lowering, so this
// is purely speculative.
let one_bound = generics.predicates.iter().find_map(|predicate| {
let hir::WherePredicateKind::BoundPredicate(predicate) = predicate.kind
else {
return None;
};
let hir::TyKind::Path(hir::QPath::Resolved(None, bounded_path)) =
predicate.bounded_ty.kind
else {
return None;
};
if bounded_path.res != path.res {
return None;
}
predicate.bounds.iter().find_map(|bound| {
let hir::GenericBound::Trait(trait_) = bound else {
return None;
};
let mut bounds =
self.for_each_trait_bound_on_res(path.res).filter_map(|trait_def_id| {
BoundVarContext::supertrait_hrtb_vars(
self.tcx,
trait_.trait_ref.trait_def_id()?,
trait_def_id,
item_segment.ident,
ty::AssocKind::Fn,
)
})
});
let Some((bound_vars, assoc_item)) = one_bound else {
});

let Some((bound_vars, assoc_item)) = bounds.next() else {
// This will error in HIR lowering.
self.tcx
.dcx()
.span_delayed_bug(path.span, "no resolution for RTN path");
return;
};

// Don't bail if we have identical bounds, which may be collected from
// something like `T: Bound + Bound`, or via elaborating supertraits.
for (second_vars, second_assoc_item) in bounds {
if second_vars != bound_vars || second_assoc_item != assoc_item {
// This will error in HIR lowering.
self.tcx.dcx().span_delayed_bug(
path.span,
"ambiguous resolution for RTN path",
);
return;
}
}

(bound_vars, assoc_item.def_id, item_segment)
}
// If we have a self type alias (in an impl), try to resolve an
Expand Down Expand Up @@ -2167,6 +2156,92 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
existing_bound_vars.extend(bound_vars);
self.record_late_bound_vars(item_segment.hir_id, existing_bound_vars_saved);
}

/// Walk the generics of the item for a trait bound whose self type
/// corresponds to the expected res, and return the trait def id.
fn for_each_trait_bound_on_res(
&self,
expected_res: Res,
) -> impl Iterator<Item = DefId> + use<'tcx, '_> {
std::iter::from_coroutine(
#[coroutine]
move || {
let mut scope = self.scope;
loop {
let hir_id = match *scope {
Scope::Binder { hir_id, .. } => Some(hir_id),
Scope::Root { opt_parent_item: Some(parent_def_id) } => {
Some(self.tcx.local_def_id_to_hir_id(parent_def_id))
}
Scope::Body { .. }
| Scope::ObjectLifetimeDefault { .. }
| Scope::Supertrait { .. }
| Scope::TraitRefBoundary { .. }
| Scope::LateBoundary { .. }
| Scope::Opaque { .. }
| Scope::Root { opt_parent_item: None } => None,
};

if let Some(hir_id) = hir_id {
let node = self.tcx.hir_node(hir_id);
// If this is a `Self` bound in a trait, yield the trait itself.
// Specifically, we don't need to look at any supertraits since
// we already do that in `BoundVarContext::supertrait_hrtb_vars`.
if let Res::SelfTyParam { trait_: _ } = expected_res
&& let hir::Node::Item(item) = node
&& let hir::ItemKind::Trait(..) = item.kind
{
// Yield the trait's def id. Supertraits will be
// elaborated from that.
yield item.owner_id.def_id.to_def_id();
} else if let Some(generics) = node.generics() {
for pred in generics.predicates {
let hir::WherePredicateKind::BoundPredicate(pred) = pred.kind
else {
continue;
};
let hir::TyKind::Path(hir::QPath::Resolved(None, bounded_path)) =
pred.bounded_ty.kind
else {
continue;
};
// Match the expected res.
if bounded_path.res != expected_res {
continue;
}
for pred in pred.bounds {
match pred {
hir::GenericBound::Trait(poly_trait_ref) => {
if let Some(def_id) =
poly_trait_ref.trait_ref.trait_def_id()
{
yield def_id;
}
}
hir::GenericBound::Outlives(_)
| hir::GenericBound::Use(_, _) => {}
}
}
}
}
}

match *scope {
Scope::Binder { s, .. }
| Scope::Body { s, .. }
| Scope::ObjectLifetimeDefault { s, .. }
| Scope::Supertrait { s, .. }
| Scope::TraitRefBoundary { s }
| Scope::LateBoundary { s, .. }
| Scope::Opaque { s, .. } => {
scope = s;
}
Scope::Root { .. } => break,
}
}
},
)
}
}

/// Detects late-bound lifetimes and inserts them into
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
def_ids.retain(|def_id| !tcx.generics_require_sized_self(def_id));
}

self.complain_about_missing_assoc_tys(
if let Err(guar) = self.check_for_required_assoc_tys(
associated_types,
potential_assoc_types,
hir_trait_bounds,
);
) {
return Ty::new_error(tcx, guar);
}

// De-duplicate auto traits so that, e.g., `dyn Trait + Send + Send` is the same as
// `dyn Trait + Send`.
Expand Down
25 changes: 16 additions & 9 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,14 +714,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
/// reasonable suggestion on how to write it. For the case of multiple associated types in the
/// same trait bound have the same name (as they come from different supertraits), we instead
/// emit a generic note suggesting using a `where` clause to constraint instead.
pub(crate) fn complain_about_missing_assoc_tys(
pub(crate) fn check_for_required_assoc_tys(
&self,
associated_types: FxIndexMap<Span, FxIndexSet<DefId>>,
potential_assoc_types: Vec<usize>,
trait_bounds: &[hir::PolyTraitRef<'_>],
) {
) -> Result<(), ErrorGuaranteed> {
if associated_types.values().all(|v| v.is_empty()) {
return;
return Ok(());
}

let tcx = self.tcx();
Expand All @@ -739,7 +739,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// Account for things like `dyn Foo + 'a`, like in tests `issue-22434.rs` and
// `issue-22560.rs`.
let mut trait_bound_spans: Vec<Span> = vec![];
let mut dyn_compatibility_violations = false;
let mut dyn_compatibility_violations = Ok(());
for (span, items) in &associated_types {
if !items.is_empty() {
trait_bound_spans.push(*span);
Expand All @@ -752,13 +752,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let violations =
dyn_compatibility_violations_for_assoc_item(tcx, trait_def_id, *assoc_item);
if !violations.is_empty() {
report_dyn_incompatibility(tcx, *span, None, trait_def_id, &violations).emit();
dyn_compatibility_violations = true;
dyn_compatibility_violations = Err(report_dyn_incompatibility(
tcx,
*span,
None,
trait_def_id,
&violations,
)
.emit());
}
}
}
if dyn_compatibility_violations {
return;

if let Err(guar) = dyn_compatibility_violations {
return Err(guar);
}

// related to issue #91997, turbofishes added only when in an expr or pat
Expand Down Expand Up @@ -965,7 +972,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
}
}

err.emit();
Err(err.emit())
}

/// On ambiguous associated type, look for an associated function whose name matches the
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ This API is completely unstable and subject to change.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
#![feature(assert_matches)]
#![feature(coroutines)]
#![feature(if_let_guard)]
#![feature(iter_from_coroutine)]
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(never_type)]
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -450,15 +450,15 @@ lint_invalid_nan_comparisons_eq_ne = incorrect NaN comparison, NaN cannot be dir
lint_invalid_nan_comparisons_lt_le_gt_ge = incorrect NaN comparison, NaN is not orderable

lint_invalid_reference_casting_assign_to_ref = assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
.label = casting happend here
.label = casting happened here

lint_invalid_reference_casting_bigger_layout = casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
.label = casting happend here
.label = casting happened here
.alloc = backing allocation comes from here
.layout = casting from `{$from_ty}` ({$from_size} bytes) to `{$to_ty}` ({$to_size} bytes)

lint_invalid_reference_casting_borrow_as_mut = casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
.label = casting happend here
.label = casting happened here

lint_invalid_reference_casting_note_book = for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>

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 @@ -182,6 +182,7 @@ symbols! {
ConstParamTy_,
Context,
Continue,
ControlFlow,
Copy,
Cow,
Debug,
Expand Down
4 changes: 2 additions & 2 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ dependencies = [

[[package]]
name = "libc"
version = "0.2.162"
version = "0.2.167"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398"
checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc"
dependencies = [
"rustc-std-workspace-core",
]
Expand Down
1 change: 1 addition & 0 deletions library/core/src/ops/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ use crate::{convert, ops};
/// [`Break`]: ControlFlow::Break
/// [`Continue`]: ControlFlow::Continue
#[stable(feature = "control_flow_enum_type", since = "1.55.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "ControlFlow")]
// ControlFlow should not implement PartialOrd or Ord, per RFC 3058:
// https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#traits-for-controlflow
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand Down
2 changes: 1 addition & 1 deletion library/panic_unwind/src/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! documents linked from it.
//! These are also good reads:
//! * <https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html>
//! * <https://monoinfinito.wordpress.com/series/exception-handling-in-c/>
//! * <https://nicolasbrailo.github.io/blog/projects_texts/13exceptionsunderthehood.html>
//! * <https://www.airs.com/blog/index.php?s=exception+frames>
//!
//! ## A brief summary
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ miniz_oxide = { version = "0.7.0", optional = true, default-features = false }
addr2line = { version = "0.22.0", optional = true, default-features = false }

[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
libc = { version = "0.2.162", default-features = false, features = [
libc = { version = "0.2.167", default-features = false, features = [
'rustc-dep-of-std',
], public = true }

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/os/hurd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ pub trait MetadataExt {
#[stable(feature = "metadata_ext", since = "1.1.0")]
impl MetadataExt for Metadata {
fn st_dev(&self) -> u64 {
self.as_inner().as_inner().st_fsid as u64
self.as_inner().as_inner().st_dev as u64
}
fn st_ino(&self) -> u64 {
self.as_inner().as_inner().st_ino as u64
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,7 @@ impl FusedIterator for Ancestors<'_> {}
/// Note that `PathBuf` does not always sanitize arguments, for example
/// [`push`] allows paths built from strings which include separators:
///
/// ```
/// use std::path::PathBuf;
///
/// let mut path = PathBuf::new();
Expand All @@ -1166,6 +1167,7 @@ impl FusedIterator for Ancestors<'_> {}
/// path.push("windows");
/// path.push(r"..\otherdir");
/// path.push("system32");
/// ```
///
/// The behavior of `PathBuf` may be changed to a panic on such inputs
/// in the future. [`Extend::extend`] should be used to add multi-part paths.
Expand Down
8 changes: 8 additions & 0 deletions library/std/src/sys/pal/teeos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ pub mod thread;
#[path = "../unix/time.rs"]
pub mod time;

#[path = "../unix/sync"]
pub mod sync {
mod condvar;
mod mutex;
pub use condvar::Condvar;
pub use mutex::Mutex;
}

use crate::io::ErrorKind;

pub fn abort_internal() -> ! {
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/pal/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub mod pipe;
pub mod process;
pub mod stack_overflow;
pub mod stdio;
pub mod sync;
pub mod thread;
pub mod thread_parking;
pub mod time;
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/sys/pal/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,13 @@ pub fn current_exe() -> io::Result<PathBuf> {
pub fn current_exe() -> io::Result<PathBuf> {
unsafe {
let mut sz: u32 = 0;
#[expect(deprecated)]
libc::_NSGetExecutablePath(ptr::null_mut(), &mut sz);
if sz == 0 {
return Err(io::Error::last_os_error());
}
let mut v: Vec<u8> = Vec::with_capacity(sz as usize);
#[expect(deprecated)]
let err = libc::_NSGetExecutablePath(v.as_mut_ptr() as *mut i8, &mut sz);
if err != 0 {
return Err(io::Error::last_os_error());
Expand Down
Loading
Loading