Skip to content

Commit 6c76ed5

Browse files
committed
Auto merge of rust-lang#133694 - matthiaskrgr:rollup-s6xj4rf, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#128184 (std: refactor `pthread`-based synchronization) - rust-lang#132047 (Robustify and genericize return-type-notation resolution in `resolve_bound_vars`) - rust-lang#133515 (fix: hurd build, stat64.st_fsid was renamed to st_dev) - rust-lang#133602 (fix: fix codeblocks in `PathBuf` example) - rust-lang#133622 (update link to "C++ Exceptions under the hood" blog) - rust-lang#133660 (Do not create trait object type if missing associated types) - rust-lang#133686 (Add diagnostic item for `std::ops::ControlFlow`) - rust-lang#133689 (Fixed typos by changing `happend` to `happened`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8ac313b + c0fa0ec commit 6c76ed5

40 files changed

+670
-699
lines changed

Diff for: compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+110-35
Original file line numberDiff line numberDiff line change
@@ -2060,48 +2060,37 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
20602060
};
20612061
match path.res {
20622062
Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { trait_: _ } => {
2063-
// Get the generics of this type's hir owner. This is *different*
2064-
// from the generics of the parameter's definition, since we want
2065-
// to be able to resolve an RTN path on a nested body (e.g. method
2066-
// inside an impl) using the where clauses on the method.
2067-
// FIXME(return_type_notation): Think of some better way of doing this.
2068-
let Some(generics) = self.tcx.hir_owner_node(hir_id.owner).generics()
2069-
else {
2070-
return;
2071-
};
2072-
2073-
// Look for the first bound that contains an associated type that
2074-
// matches the segment that we're looking for. We ignore any subsequent
2075-
// bounds since we'll be emitting a hard error in HIR lowering, so this
2076-
// is purely speculative.
2077-
let one_bound = generics.predicates.iter().find_map(|predicate| {
2078-
let hir::WherePredicateKind::BoundPredicate(predicate) = predicate.kind
2079-
else {
2080-
return None;
2081-
};
2082-
let hir::TyKind::Path(hir::QPath::Resolved(None, bounded_path)) =
2083-
predicate.bounded_ty.kind
2084-
else {
2085-
return None;
2086-
};
2087-
if bounded_path.res != path.res {
2088-
return None;
2089-
}
2090-
predicate.bounds.iter().find_map(|bound| {
2091-
let hir::GenericBound::Trait(trait_) = bound else {
2092-
return None;
2093-
};
2063+
let mut bounds =
2064+
self.for_each_trait_bound_on_res(path.res).filter_map(|trait_def_id| {
20942065
BoundVarContext::supertrait_hrtb_vars(
20952066
self.tcx,
2096-
trait_.trait_ref.trait_def_id()?,
2067+
trait_def_id,
20972068
item_segment.ident,
20982069
ty::AssocKind::Fn,
20992070
)
2100-
})
2101-
});
2102-
let Some((bound_vars, assoc_item)) = one_bound else {
2071+
});
2072+
2073+
let Some((bound_vars, assoc_item)) = bounds.next() else {
2074+
// This will error in HIR lowering.
2075+
self.tcx
2076+
.dcx()
2077+
.span_delayed_bug(path.span, "no resolution for RTN path");
21032078
return;
21042079
};
2080+
2081+
// Don't bail if we have identical bounds, which may be collected from
2082+
// something like `T: Bound + Bound`, or via elaborating supertraits.
2083+
for (second_vars, second_assoc_item) in bounds {
2084+
if second_vars != bound_vars || second_assoc_item != assoc_item {
2085+
// This will error in HIR lowering.
2086+
self.tcx.dcx().span_delayed_bug(
2087+
path.span,
2088+
"ambiguous resolution for RTN path",
2089+
);
2090+
return;
2091+
}
2092+
}
2093+
21052094
(bound_vars, assoc_item.def_id, item_segment)
21062095
}
21072096
// If we have a self type alias (in an impl), try to resolve an
@@ -2167,6 +2156,92 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
21672156
existing_bound_vars.extend(bound_vars);
21682157
self.record_late_bound_vars(item_segment.hir_id, existing_bound_vars_saved);
21692158
}
2159+
2160+
/// Walk the generics of the item for a trait bound whose self type
2161+
/// corresponds to the expected res, and return the trait def id.
2162+
fn for_each_trait_bound_on_res(
2163+
&self,
2164+
expected_res: Res,
2165+
) -> impl Iterator<Item = DefId> + use<'tcx, '_> {
2166+
std::iter::from_coroutine(
2167+
#[coroutine]
2168+
move || {
2169+
let mut scope = self.scope;
2170+
loop {
2171+
let hir_id = match *scope {
2172+
Scope::Binder { hir_id, .. } => Some(hir_id),
2173+
Scope::Root { opt_parent_item: Some(parent_def_id) } => {
2174+
Some(self.tcx.local_def_id_to_hir_id(parent_def_id))
2175+
}
2176+
Scope::Body { .. }
2177+
| Scope::ObjectLifetimeDefault { .. }
2178+
| Scope::Supertrait { .. }
2179+
| Scope::TraitRefBoundary { .. }
2180+
| Scope::LateBoundary { .. }
2181+
| Scope::Opaque { .. }
2182+
| Scope::Root { opt_parent_item: None } => None,
2183+
};
2184+
2185+
if let Some(hir_id) = hir_id {
2186+
let node = self.tcx.hir_node(hir_id);
2187+
// If this is a `Self` bound in a trait, yield the trait itself.
2188+
// Specifically, we don't need to look at any supertraits since
2189+
// we already do that in `BoundVarContext::supertrait_hrtb_vars`.
2190+
if let Res::SelfTyParam { trait_: _ } = expected_res
2191+
&& let hir::Node::Item(item) = node
2192+
&& let hir::ItemKind::Trait(..) = item.kind
2193+
{
2194+
// Yield the trait's def id. Supertraits will be
2195+
// elaborated from that.
2196+
yield item.owner_id.def_id.to_def_id();
2197+
} else if let Some(generics) = node.generics() {
2198+
for pred in generics.predicates {
2199+
let hir::WherePredicateKind::BoundPredicate(pred) = pred.kind
2200+
else {
2201+
continue;
2202+
};
2203+
let hir::TyKind::Path(hir::QPath::Resolved(None, bounded_path)) =
2204+
pred.bounded_ty.kind
2205+
else {
2206+
continue;
2207+
};
2208+
// Match the expected res.
2209+
if bounded_path.res != expected_res {
2210+
continue;
2211+
}
2212+
for pred in pred.bounds {
2213+
match pred {
2214+
hir::GenericBound::Trait(poly_trait_ref) => {
2215+
if let Some(def_id) =
2216+
poly_trait_ref.trait_ref.trait_def_id()
2217+
{
2218+
yield def_id;
2219+
}
2220+
}
2221+
hir::GenericBound::Outlives(_)
2222+
| hir::GenericBound::Use(_, _) => {}
2223+
}
2224+
}
2225+
}
2226+
}
2227+
}
2228+
2229+
match *scope {
2230+
Scope::Binder { s, .. }
2231+
| Scope::Body { s, .. }
2232+
| Scope::ObjectLifetimeDefault { s, .. }
2233+
| Scope::Supertrait { s, .. }
2234+
| Scope::TraitRefBoundary { s }
2235+
| Scope::LateBoundary { s, .. }
2236+
| Scope::Opaque { s, .. } => {
2237+
scope = s;
2238+
}
2239+
Scope::Root { .. } => break,
2240+
}
2241+
}
2242+
},
2243+
)
2244+
}
21702245
}
21712246

21722247
/// Detects late-bound lifetimes and inserts them into

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
219219
def_ids.retain(|def_id| !tcx.generics_require_sized_self(def_id));
220220
}
221221

222-
self.complain_about_missing_assoc_tys(
222+
if let Err(guar) = self.check_for_required_assoc_tys(
223223
associated_types,
224224
potential_assoc_types,
225225
hir_trait_bounds,
226-
);
226+
) {
227+
return Ty::new_error(tcx, guar);
228+
}
227229

228230
// De-duplicate auto traits so that, e.g., `dyn Trait + Send + Send` is the same as
229231
// `dyn Trait + Send`.

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -714,14 +714,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
714714
/// reasonable suggestion on how to write it. For the case of multiple associated types in the
715715
/// same trait bound have the same name (as they come from different supertraits), we instead
716716
/// emit a generic note suggesting using a `where` clause to constraint instead.
717-
pub(crate) fn complain_about_missing_assoc_tys(
717+
pub(crate) fn check_for_required_assoc_tys(
718718
&self,
719719
associated_types: FxIndexMap<Span, FxIndexSet<DefId>>,
720720
potential_assoc_types: Vec<usize>,
721721
trait_bounds: &[hir::PolyTraitRef<'_>],
722-
) {
722+
) -> Result<(), ErrorGuaranteed> {
723723
if associated_types.values().all(|v| v.is_empty()) {
724-
return;
724+
return Ok(());
725725
}
726726

727727
let tcx = self.tcx();
@@ -739,7 +739,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
739739
// Account for things like `dyn Foo + 'a`, like in tests `issue-22434.rs` and
740740
// `issue-22560.rs`.
741741
let mut trait_bound_spans: Vec<Span> = vec![];
742-
let mut dyn_compatibility_violations = false;
742+
let mut dyn_compatibility_violations = Ok(());
743743
for (span, items) in &associated_types {
744744
if !items.is_empty() {
745745
trait_bound_spans.push(*span);
@@ -752,13 +752,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
752752
let violations =
753753
dyn_compatibility_violations_for_assoc_item(tcx, trait_def_id, *assoc_item);
754754
if !violations.is_empty() {
755-
report_dyn_incompatibility(tcx, *span, None, trait_def_id, &violations).emit();
756-
dyn_compatibility_violations = true;
755+
dyn_compatibility_violations = Err(report_dyn_incompatibility(
756+
tcx,
757+
*span,
758+
None,
759+
trait_def_id,
760+
&violations,
761+
)
762+
.emit());
757763
}
758764
}
759765
}
760-
if dyn_compatibility_violations {
761-
return;
766+
767+
if let Err(guar) = dyn_compatibility_violations {
768+
return Err(guar);
762769
}
763770

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

968-
err.emit();
975+
Err(err.emit())
969976
}
970977

971978
/// On ambiguous associated type, look for an associated function whose name matches the

Diff for: compiler/rustc_hir_analysis/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ This API is completely unstable and subject to change.
6262
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
6363
#![doc(rust_logo)]
6464
#![feature(assert_matches)]
65+
#![feature(coroutines)]
6566
#![feature(if_let_guard)]
67+
#![feature(iter_from_coroutine)]
6668
#![feature(iter_intersperse)]
6769
#![feature(let_chains)]
6870
#![feature(never_type)]

Diff for: compiler/rustc_lint/messages.ftl

+3-3
Original file line numberDiff line numberDiff line change
@@ -450,15 +450,15 @@ lint_invalid_nan_comparisons_eq_ne = incorrect NaN comparison, NaN cannot be dir
450450
lint_invalid_nan_comparisons_lt_le_gt_ge = incorrect NaN comparison, NaN is not orderable
451451
452452
lint_invalid_reference_casting_assign_to_ref = assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
453-
.label = casting happend here
453+
.label = casting happened here
454454
455455
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
456-
.label = casting happend here
456+
.label = casting happened here
457457
.alloc = backing allocation comes from here
458458
.layout = casting from `{$from_ty}` ({$from_size} bytes) to `{$to_ty}` ({$to_size} bytes)
459459
460460
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`
461-
.label = casting happend here
461+
.label = casting happened here
462462
463463
lint_invalid_reference_casting_note_book = for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
464464

Diff for: compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ symbols! {
182182
ConstParamTy_,
183183
Context,
184184
Continue,
185+
ControlFlow,
185186
Copy,
186187
Cow,
187188
Debug,

Diff for: library/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ dependencies = [
158158

159159
[[package]]
160160
name = "libc"
161-
version = "0.2.162"
161+
version = "0.2.167"
162162
source = "registry+https://github.com/rust-lang/crates.io-index"
163-
checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398"
163+
checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc"
164164
dependencies = [
165165
"rustc-std-workspace-core",
166166
]

Diff for: library/core/src/ops/control_flow.rs

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ use crate::{convert, ops};
7979
/// [`Break`]: ControlFlow::Break
8080
/// [`Continue`]: ControlFlow::Continue
8181
#[stable(feature = "control_flow_enum_type", since = "1.55.0")]
82+
#[cfg_attr(not(test), rustc_diagnostic_item = "ControlFlow")]
8283
// ControlFlow should not implement PartialOrd or Ord, per RFC 3058:
8384
// https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#traits-for-controlflow
8485
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

Diff for: library/panic_unwind/src/gcc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! documents linked from it.
66
//! These are also good reads:
77
//! * <https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html>
8-
//! * <https://monoinfinito.wordpress.com/series/exception-handling-in-c/>
8+
//! * <https://nicolasbrailo.github.io/blog/projects_texts/13exceptionsunderthehood.html>
99
//! * <https://www.airs.com/blog/index.php?s=exception+frames>
1010
//!
1111
//! ## A brief summary

Diff for: library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ miniz_oxide = { version = "0.7.0", optional = true, default-features = false }
3434
addr2line = { version = "0.22.0", optional = true, default-features = false }
3535

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

Diff for: library/std/src/os/hurd/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ pub trait MetadataExt {
298298
#[stable(feature = "metadata_ext", since = "1.1.0")]
299299
impl MetadataExt for Metadata {
300300
fn st_dev(&self) -> u64 {
301-
self.as_inner().as_inner().st_fsid as u64
301+
self.as_inner().as_inner().st_dev as u64
302302
}
303303
fn st_ino(&self) -> u64 {
304304
self.as_inner().as_inner().st_ino as u64

Diff for: library/std/src/path.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,7 @@ impl FusedIterator for Ancestors<'_> {}
11581158
/// Note that `PathBuf` does not always sanitize arguments, for example
11591159
/// [`push`] allows paths built from strings which include separators:
11601160
///
1161+
/// ```
11611162
/// use std::path::PathBuf;
11621163
///
11631164
/// let mut path = PathBuf::new();
@@ -1166,6 +1167,7 @@ impl FusedIterator for Ancestors<'_> {}
11661167
/// path.push("windows");
11671168
/// path.push(r"..\otherdir");
11681169
/// path.push("system32");
1170+
/// ```
11691171
///
11701172
/// The behavior of `PathBuf` may be changed to a panic on such inputs
11711173
/// in the future. [`Extend::extend`] should be used to add multi-part paths.

Diff for: library/std/src/sys/pal/teeos/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ pub mod thread;
2727
#[path = "../unix/time.rs"]
2828
pub mod time;
2929

30+
#[path = "../unix/sync"]
31+
pub mod sync {
32+
mod condvar;
33+
mod mutex;
34+
pub use condvar::Condvar;
35+
pub use mutex::Mutex;
36+
}
37+
3038
use crate::io::ErrorKind;
3139

3240
pub fn abort_internal() -> ! {

Diff for: library/std/src/sys/pal/unix/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub mod pipe;
2727
pub mod process;
2828
pub mod stack_overflow;
2929
pub mod stdio;
30+
pub mod sync;
3031
pub mod thread;
3132
pub mod thread_parking;
3233
pub mod time;

Diff for: library/std/src/sys/pal/unix/os.rs

+2
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,13 @@ pub fn current_exe() -> io::Result<PathBuf> {
427427
pub fn current_exe() -> io::Result<PathBuf> {
428428
unsafe {
429429
let mut sz: u32 = 0;
430+
#[expect(deprecated)]
430431
libc::_NSGetExecutablePath(ptr::null_mut(), &mut sz);
431432
if sz == 0 {
432433
return Err(io::Error::last_os_error());
433434
}
434435
let mut v: Vec<u8> = Vec::with_capacity(sz as usize);
436+
#[expect(deprecated)]
435437
let err = libc::_NSGetExecutablePath(v.as_mut_ptr() as *mut i8, &mut sz);
436438
if err != 0 {
437439
return Err(io::Error::last_os_error());

0 commit comments

Comments
 (0)