Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b8e8193

Browse files
committed
Auto merge of rust-lang#123801 - cuviper:beta-next, r=cuviper
[beta] backports - fix attribute validation on associated items in traits rust-lang#121545 - Only inspect user-written predicates for privacy concerns rust-lang#123377 - Check def id before calling `match_projection_projections` rust-lang#123471 - Restore `pred_known_to_hold_modulo_regions` rust-lang#123578 - Beta revert "Use OS thread name by default" rust-lang#123533 r? cuviper
2 parents 27011d5 + 3e37631 commit b8e8193

File tree

22 files changed

+402
-138
lines changed

22 files changed

+402
-138
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
15271527
generics,
15281528
body.as_deref(),
15291529
);
1530+
walk_list!(self, visit_attribute, &item.attrs);
15301531
self.visit_fn(kind, item.span, item.id);
15311532
}
15321533
AssocItemKind::Type(_) => {

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,60 @@ pub fn predicates_for_generics<'tcx>(
119119

120120
/// Determines whether the type `ty` is known to meet `bound` and
121121
/// returns true if so. Returns false if `ty` either does not meet
122-
/// `bound` or is not known to meet bound.
122+
/// `bound` or is not known to meet bound (note that this is
123+
/// conservative towards *no impl*, which is the opposite of the
124+
/// `evaluate` methods).
123125
pub fn type_known_to_meet_bound_modulo_regions<'tcx>(
124126
infcx: &InferCtxt<'tcx>,
125127
param_env: ty::ParamEnv<'tcx>,
126128
ty: Ty<'tcx>,
127129
def_id: DefId,
128130
) -> bool {
129131
let trait_ref = ty::TraitRef::new(infcx.tcx, def_id, [ty]);
130-
let obligation = Obligation::new(infcx.tcx, ObligationCause::dummy(), param_env, trait_ref);
131-
infcx.predicate_must_hold_modulo_regions(&obligation)
132+
pred_known_to_hold_modulo_regions(infcx, param_env, trait_ref)
133+
}
134+
135+
/// FIXME(@lcnr): this function doesn't seem right and shouldn't exist?
136+
///
137+
/// Ping me on zulip if you want to use this method and need help with finding
138+
/// an appropriate replacement.
139+
#[instrument(level = "debug", skip(infcx, param_env, pred), ret)]
140+
fn pred_known_to_hold_modulo_regions<'tcx>(
141+
infcx: &InferCtxt<'tcx>,
142+
param_env: ty::ParamEnv<'tcx>,
143+
pred: impl ToPredicate<'tcx>,
144+
) -> bool {
145+
let obligation = Obligation::new(infcx.tcx, ObligationCause::dummy(), param_env, pred);
146+
147+
let result = infcx.evaluate_obligation_no_overflow(&obligation);
148+
debug!(?result);
149+
150+
if result.must_apply_modulo_regions() {
151+
true
152+
} else if result.may_apply() {
153+
// Sometimes obligations are ambiguous because the recursive evaluator
154+
// is not smart enough, so we fall back to fulfillment when we're not certain
155+
// that an obligation holds or not. Even still, we must make sure that
156+
// the we do no inference in the process of checking this obligation.
157+
let goal = infcx.resolve_vars_if_possible((obligation.predicate, obligation.param_env));
158+
infcx.probe(|_| {
159+
let ocx = ObligationCtxt::new(infcx);
160+
ocx.register_obligation(obligation);
161+
162+
let errors = ocx.select_all_or_error();
163+
match errors.as_slice() {
164+
// Only known to hold if we did no inference.
165+
[] => infcx.shallow_resolve(goal) == goal,
166+
167+
errors => {
168+
debug!(?errors);
169+
false
170+
}
171+
}
172+
})
173+
} else {
174+
false
175+
}
132176
}
133177

134178
#[instrument(level = "debug", skip(tcx, elaborated_env))]

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,9 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
794794
let Some(clause) = clause.as_projection_clause() else {
795795
return ControlFlow::Continue(());
796796
};
797+
if clause.projection_def_id() != obligation.predicate.def_id {
798+
return ControlFlow::Continue(());
799+
}
797800

798801
let is_match =
799802
selcx.infcx.probe(|_| selcx.match_projection_projections(obligation, clause, true));

compiler/rustc_ty_utils/src/sig_types.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub trait SpannedTypeVisitor<'tcx> {
1313
fn visit(&mut self, span: Span, value: impl TypeVisitable<TyCtxt<'tcx>>) -> Self::Result;
1414
}
1515

16+
#[instrument(level = "trace", skip(tcx, visitor))]
1617
pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
1718
tcx: TyCtxt<'tcx>,
1819
item: LocalDefId,
@@ -36,7 +37,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
3637
for (hir, ty) in hir_sig.inputs.iter().zip(ty_sig.inputs().iter()) {
3738
try_visit!(visitor.visit(hir.span, ty.map_bound(|x| *x)));
3839
}
39-
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
40+
for (pred, span) in tcx.explicit_predicates_of(item).instantiate_identity(tcx) {
4041
try_visit!(visitor.visit(span, pred));
4142
}
4243
}
@@ -54,7 +55,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
5455
// Associated types in traits don't necessarily have a type that we can visit
5556
try_visit!(visitor.visit(ty.span, tcx.type_of(item).instantiate_identity()));
5657
}
57-
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
58+
for (pred, span) in tcx.explicit_predicates_of(item).instantiate_identity(tcx) {
5859
try_visit!(visitor.visit(span, pred));
5960
}
6061
}
@@ -76,7 +77,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
7677
let ty = field.ty(tcx, args);
7778
try_visit!(visitor.visit(span, ty));
7879
}
79-
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
80+
for (pred, span) in tcx.explicit_predicates_of(item).instantiate_identity(tcx) {
8081
try_visit!(visitor.visit(span, pred));
8182
}
8283
}
@@ -95,12 +96,12 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
9596
_ => tcx.def_span(item),
9697
};
9798
try_visit!(visitor.visit(span, tcx.type_of(item).instantiate_identity()));
98-
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
99+
for (pred, span) in tcx.explicit_predicates_of(item).instantiate_identity(tcx) {
99100
try_visit!(visitor.visit(span, pred));
100101
}
101102
}
102103
DefKind::TraitAlias | DefKind::Trait => {
103-
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
104+
for (pred, span) in tcx.explicit_predicates_of(item).instantiate_identity(tcx) {
104105
try_visit!(visitor.visit(span, pred));
105106
}
106107
}

library/std/src/sys/pal/hermit/thread.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use super::abi;
44
use super::thread_local_dtor::run_dtors;
5-
use crate::ffi::{CStr, CString};
5+
use crate::ffi::CStr;
66
use crate::io;
77
use crate::mem;
88
use crate::num::NonZero;
@@ -71,10 +71,6 @@ impl Thread {
7171
// nope
7272
}
7373

74-
pub fn get_name() -> Option<CString> {
75-
None
76-
}
77-
7874
#[inline]
7975
pub fn sleep(dur: Duration) {
8076
unsafe {

library/std/src/sys/pal/itron/thread.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use super::{
88
};
99
use crate::{
1010
cell::UnsafeCell,
11-
ffi::{CStr, CString},
11+
ffi::CStr,
1212
hint, io,
1313
mem::ManuallyDrop,
1414
num::NonZero,
@@ -204,10 +204,6 @@ impl Thread {
204204
// nope
205205
}
206206

207-
pub fn get_name() -> Option<CString> {
208-
None
209-
}
210-
211207
pub fn sleep(dur: Duration) {
212208
for timeout in dur2reltims(dur) {
213209
expect_success(unsafe { abi::dly_tsk(timeout) }, &"dly_tsk");

library/std/src/sys/pal/sgx/thread.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![cfg_attr(test, allow(dead_code))] // why is this necessary?
22
use super::unsupported;
3-
use crate::ffi::{CStr, CString};
3+
use crate::ffi::CStr;
44
use crate::io;
55
use crate::num::NonZero;
66
use crate::time::Duration;
@@ -133,10 +133,6 @@ impl Thread {
133133
// which succeeds as-is with the SGX target.
134134
}
135135

136-
pub fn get_name() -> Option<CString> {
137-
None
138-
}
139-
140136
pub fn sleep(dur: Duration) {
141137
usercalls::wait_timeout(0, dur, || true);
142138
}

library/std/src/sys/pal/teeos/thread.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::convert::TryInto;
22

33
use crate::cmp;
4-
use crate::ffi::{CStr, CString};
4+
use crate::ffi::CStr;
55
use crate::io;
66
use crate::mem;
77
use crate::num::NonZero;
@@ -101,10 +101,6 @@ impl Thread {
101101
// contact the teeos rustzone team.
102102
}
103103

104-
pub fn get_name() -> Option<CString> {
105-
None
106-
}
107-
108104
/// only main thread could wait for sometime in teeos
109105
pub fn sleep(dur: Duration) {
110106
let sleep_millis = dur.as_millis();

library/std/src/sys/pal/uefi/thread.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::unsupported;
2-
use crate::ffi::{CStr, CString};
2+
use crate::ffi::CStr;
33
use crate::io;
44
use crate::num::NonZero;
55
use crate::ptr::NonNull;
@@ -23,10 +23,6 @@ impl Thread {
2323
// nope
2424
}
2525

26-
pub fn get_name() -> Option<CString> {
27-
None
28-
}
29-
3026
pub fn sleep(dur: Duration) {
3127
let boot_services: NonNull<r_efi::efi::BootServices> =
3228
crate::os::uefi::env::boot_services().expect("can't sleep").cast();

library/std/src/sys/pal/unix/thread.rs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::cmp;
2-
use crate::ffi::{CStr, CString};
2+
use crate::ffi::CStr;
33
use crate::io;
44
use crate::mem;
55
use crate::num::NonZero;
@@ -225,44 +225,6 @@ impl Thread {
225225
// Newlib, Emscripten, and VxWorks have no way to set a thread name.
226226
}
227227

228-
#[cfg(target_os = "linux")]
229-
pub fn get_name() -> Option<CString> {
230-
const TASK_COMM_LEN: usize = 16;
231-
let mut name = vec![0u8; TASK_COMM_LEN];
232-
let res = unsafe {
233-
libc::pthread_getname_np(libc::pthread_self(), name.as_mut_ptr().cast(), name.len())
234-
};
235-
if res != 0 {
236-
return None;
237-
}
238-
name.truncate(name.iter().position(|&c| c == 0)?);
239-
CString::new(name).ok()
240-
}
241-
242-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))]
243-
pub fn get_name() -> Option<CString> {
244-
let mut name = vec![0u8; libc::MAXTHREADNAMESIZE];
245-
let res = unsafe {
246-
libc::pthread_getname_np(libc::pthread_self(), name.as_mut_ptr().cast(), name.len())
247-
};
248-
if res != 0 {
249-
return None;
250-
}
251-
name.truncate(name.iter().position(|&c| c == 0)?);
252-
CString::new(name).ok()
253-
}
254-
255-
#[cfg(not(any(
256-
target_os = "linux",
257-
target_os = "macos",
258-
target_os = "ios",
259-
target_os = "tvos",
260-
target_os = "watchos"
261-
)))]
262-
pub fn get_name() -> Option<CString> {
263-
None
264-
}
265-
266228
#[cfg(not(target_os = "espidf"))]
267229
pub fn sleep(dur: Duration) {
268230
let mut secs = dur.as_secs();

0 commit comments

Comments
 (0)