Skip to content

Commit 2783fc4

Browse files
committed
Auto merge of #143621 - matthiaskrgr:rollup-p1ce8l7, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #142098 (Implement `int_format_into` feature) - #143567 (Point to correct argument in Func Call when Self type fails trait bound) - #143570 (consider nested cases for duplicate RPITIT) - #143571 (remove `has_nested` from builtin candidates) - #143586 (Fix wrong cache event query key) - #143589 (const-block-as-pattern: do not refer to no-longer-existing nightly feature) - #143608 (Fix in std::String docs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 688ea65 + fd05071 commit 2783fc4

28 files changed

+598
-176
lines changed

compiler/rustc_data_structures/src/profiling.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const EVENT_FILTERS_BY_NAME: &[(&str, EventFilter)] = &[
142142
("generic-activity", EventFilter::GENERIC_ACTIVITIES),
143143
("query-provider", EventFilter::QUERY_PROVIDERS),
144144
("query-cache-hit", EventFilter::QUERY_CACHE_HITS),
145-
("query-cache-hit-count", EventFilter::QUERY_CACHE_HITS),
145+
("query-cache-hit-count", EventFilter::QUERY_CACHE_HIT_COUNTS),
146146
("query-blocked", EventFilter::QUERY_BLOCKED),
147147
("incr-cache-load", EventFilter::INCR_CACHE_LOADS),
148148
("query-keys", EventFilter::QUERY_KEYS),

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
184184
return true;
185185
}
186186

187-
for param in [param_to_point_at, fallback_param_to_point_at, self_param_to_point_at]
188-
.into_iter()
189-
.flatten()
187+
for param in [
188+
predicate_self_type_to_point_at,
189+
param_to_point_at,
190+
fallback_param_to_point_at,
191+
self_param_to_point_at,
192+
]
193+
.into_iter()
194+
.flatten()
190195
{
191196
if self.blame_specific_arg_if_possible(
192197
error,

compiler/rustc_middle/src/traits/select.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,15 @@ pub type EvaluationCache<'tcx, ENV> = Cache<(ENV, ty::PolyTraitPredicate<'tcx>),
9797
pub enum SelectionCandidate<'tcx> {
9898
/// A built-in implementation for the `Sized` trait. This is preferred
9999
/// over all other candidates.
100-
SizedCandidate {
101-
has_nested: bool,
102-
},
100+
SizedCandidate,
103101

104102
/// A builtin implementation for some specific traits, used in cases
105103
/// where we cannot rely an ordinary library implementations.
106104
///
107105
/// The most notable examples are `Copy` and `Clone`. This is also
108106
/// used for the `DiscriminantKind` and `Pointee` trait, both of which have
109107
/// an associated type.
110-
BuiltinCandidate {
111-
/// `false` if there are no *further* obligations.
112-
has_nested: bool,
113-
},
108+
BuiltinCandidate,
114109

115110
/// Implementation of transmutability trait.
116111
TransmutabilityCandidate,

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,10 @@ impl<'a> Parser<'a> {
12931293
let kind = if pat {
12941294
let guar = self
12951295
.dcx()
1296-
.struct_span_err(blk_span, "`inline_const_pat` has been removed")
1297-
.with_help("use a named `const`-item or an `if`-guard instead")
1296+
.struct_span_err(blk_span, "const blocks cannot be used as patterns")
1297+
.with_help(
1298+
"use a named `const`-item or an `if`-guard (`x if x == const { ... }`) instead",
1299+
)
12981300
.emit();
12991301
ExprKind::Err(guar)
13001302
} else {

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
8080
}
8181
Some(LangItem::DiscriminantKind) => {
8282
// `DiscriminantKind` is automatically implemented for every type.
83-
candidates.vec.push(BuiltinCandidate { has_nested: false });
83+
candidates.vec.push(BuiltinCandidate);
8484
}
8585
Some(LangItem::PointeeTrait) => {
8686
// `Pointee` is automatically implemented for every type.
87-
candidates.vec.push(BuiltinCandidate { has_nested: false });
87+
candidates.vec.push(BuiltinCandidate);
8888
}
8989
Some(LangItem::Sized) => {
9090
self.assemble_builtin_sized_candidate(
@@ -365,7 +365,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
365365
{
366366
debug!(?self_ty, ?obligation, "assemble_fused_iterator_candidates",);
367367

368-
candidates.vec.push(BuiltinCandidate { has_nested: false });
368+
candidates.vec.push(BuiltinCandidate);
369369
}
370370
}
371371

@@ -810,7 +810,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
810810
hir::Movability::Movable => {
811811
// Movable coroutines are always `Unpin`, so add an
812812
// unconditional builtin candidate.
813-
candidates.vec.push(BuiltinCandidate { has_nested: false });
813+
candidates.vec.push(BuiltinCandidate);
814814
}
815815
}
816816
}
@@ -1122,10 +1122,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11221122
sizedness: SizedTraitKind,
11231123
) {
11241124
match self.sizedness_conditions(obligation, sizedness) {
1125-
BuiltinImplConditions::Where(nested) => {
1126-
candidates
1127-
.vec
1128-
.push(SizedCandidate { has_nested: !nested.skip_binder().is_empty() });
1125+
BuiltinImplConditions::Where(_nested) => {
1126+
candidates.vec.push(SizedCandidate);
11291127
}
11301128
BuiltinImplConditions::None => {}
11311129
BuiltinImplConditions::Ambiguous => {
@@ -1143,10 +1141,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11431141
candidates: &mut SelectionCandidateSet<'tcx>,
11441142
) {
11451143
match conditions {
1146-
BuiltinImplConditions::Where(nested) => {
1147-
candidates
1148-
.vec
1149-
.push(BuiltinCandidate { has_nested: !nested.skip_binder().is_empty() });
1144+
BuiltinImplConditions::Where(_) => {
1145+
candidates.vec.push(BuiltinCandidate);
11501146
}
11511147
BuiltinImplConditions::None => {}
11521148
BuiltinImplConditions::Ambiguous => {
@@ -1160,7 +1156,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11601156
_obligation: &PolyTraitObligation<'tcx>,
11611157
candidates: &mut SelectionCandidateSet<'tcx>,
11621158
) {
1163-
candidates.vec.push(BuiltinCandidate { has_nested: false });
1159+
candidates.vec.push(BuiltinCandidate);
11641160
}
11651161

11661162
fn assemble_candidate_for_tuple(
@@ -1171,7 +1167,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11711167
let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder());
11721168
match self_ty.kind() {
11731169
ty::Tuple(_) => {
1174-
candidates.vec.push(BuiltinCandidate { has_nested: false });
1170+
candidates.vec.push(BuiltinCandidate);
11751171
}
11761172
ty::Infer(ty::TyVar(_)) => {
11771173
candidates.ambiguous = true;
@@ -1215,7 +1211,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12151211
let self_ty = self.infcx.resolve_vars_if_possible(obligation.self_ty());
12161212

12171213
match self_ty.skip_binder().kind() {
1218-
ty::FnPtr(..) => candidates.vec.push(BuiltinCandidate { has_nested: false }),
1214+
ty::FnPtr(..) => candidates.vec.push(BuiltinCandidate),
12191215
ty::Bool
12201216
| ty::Char
12211217
| ty::Int(_)

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
3737
candidate: SelectionCandidate<'tcx>,
3838
) -> Result<Selection<'tcx>, SelectionError<'tcx>> {
3939
Ok(match candidate {
40-
SizedCandidate { has_nested } => {
41-
let data = self.confirm_builtin_candidate(obligation, has_nested);
40+
SizedCandidate => {
41+
let data = self.confirm_builtin_candidate(obligation);
4242
ImplSource::Builtin(BuiltinImplSource::Misc, data)
4343
}
4444

45-
BuiltinCandidate { has_nested } => {
46-
let data = self.confirm_builtin_candidate(obligation, has_nested);
45+
BuiltinCandidate => {
46+
let data = self.confirm_builtin_candidate(obligation);
4747
ImplSource::Builtin(BuiltinImplSource::Misc, data)
4848
}
4949

@@ -249,50 +249,47 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
249249
}
250250
}
251251

252+
#[instrument(level = "debug", skip(self), ret)]
252253
fn confirm_builtin_candidate(
253254
&mut self,
254255
obligation: &PolyTraitObligation<'tcx>,
255-
has_nested: bool,
256256
) -> PredicateObligations<'tcx> {
257-
debug!(?obligation, ?has_nested, "confirm_builtin_candidate");
258-
257+
debug!(?obligation, "confirm_builtin_candidate");
259258
let tcx = self.tcx();
260-
let obligations = if has_nested {
261-
let trait_def = obligation.predicate.def_id();
262-
let conditions = match tcx.as_lang_item(trait_def) {
263-
Some(LangItem::Sized) => {
264-
self.sizedness_conditions(obligation, SizedTraitKind::Sized)
265-
}
266-
Some(LangItem::MetaSized) => {
267-
self.sizedness_conditions(obligation, SizedTraitKind::MetaSized)
268-
}
269-
Some(LangItem::PointeeSized) => {
270-
bug!("`PointeeSized` is removing during lowering");
271-
}
272-
Some(LangItem::Copy | LangItem::Clone) => self.copy_clone_conditions(obligation),
273-
Some(LangItem::FusedIterator) => self.fused_iterator_conditions(obligation),
274-
other => bug!("unexpected builtin trait {trait_def:?} ({other:?})"),
275-
};
276-
let BuiltinImplConditions::Where(types) = conditions else {
277-
bug!("obligation {:?} had matched a builtin impl but now doesn't", obligation);
278-
};
279-
let types = self.infcx.enter_forall_and_leak_universe(types);
280-
281-
let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
282-
self.collect_predicates_for_types(
283-
obligation.param_env,
284-
cause,
285-
obligation.recursion_depth + 1,
286-
trait_def,
287-
types,
288-
)
289-
} else {
290-
PredicateObligations::new()
259+
let trait_def = obligation.predicate.def_id();
260+
let conditions = match tcx.as_lang_item(trait_def) {
261+
Some(LangItem::Sized) => self.sizedness_conditions(obligation, SizedTraitKind::Sized),
262+
Some(LangItem::MetaSized) => {
263+
self.sizedness_conditions(obligation, SizedTraitKind::MetaSized)
264+
}
265+
Some(LangItem::PointeeSized) => {
266+
bug!("`PointeeSized` is removing during lowering");
267+
}
268+
Some(LangItem::Copy | LangItem::Clone) => self.copy_clone_conditions(obligation),
269+
Some(LangItem::FusedIterator) => self.fused_iterator_conditions(obligation),
270+
Some(
271+
LangItem::Destruct
272+
| LangItem::DiscriminantKind
273+
| LangItem::FnPtrTrait
274+
| LangItem::PointeeTrait
275+
| LangItem::Tuple
276+
| LangItem::Unpin,
277+
) => BuiltinImplConditions::Where(ty::Binder::dummy(vec![])),
278+
other => bug!("unexpected builtin trait {trait_def:?} ({other:?})"),
291279
};
280+
let BuiltinImplConditions::Where(types) = conditions else {
281+
bug!("obligation {:?} had matched a builtin impl but now doesn't", obligation);
282+
};
283+
let types = self.infcx.enter_forall_and_leak_universe(types);
292284

293-
debug!(?obligations);
294-
295-
obligations
285+
let cause = obligation.derived_cause(ObligationCauseCode::BuiltinDerived);
286+
self.collect_predicates_for_types(
287+
obligation.param_env,
288+
cause,
289+
obligation.recursion_depth + 1,
290+
trait_def,
291+
types,
292+
)
296293
}
297294

298295
#[instrument(level = "debug", skip(self))]

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,7 +1834,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
18341834

18351835
// We prefer `Sized` candidates over everything.
18361836
let mut sized_candidates =
1837-
candidates.iter().filter(|c| matches!(c.candidate, SizedCandidate { has_nested: _ }));
1837+
candidates.iter().filter(|c| matches!(c.candidate, SizedCandidate));
18381838
if let Some(sized_candidate) = sized_candidates.next() {
18391839
// There should only ever be a single sized candidate
18401840
// as they would otherwise overlap.
@@ -1986,8 +1986,8 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
19861986
// Don't use impl candidates which overlap with other candidates.
19871987
// This should pretty much only ever happen with malformed impls.
19881988
if candidates.iter().all(|c| match c.candidate {
1989-
SizedCandidate { has_nested: _ }
1990-
| BuiltinCandidate { has_nested: _ }
1989+
SizedCandidate
1990+
| BuiltinCandidate
19911991
| TransmutabilityCandidate
19921992
| AutoImplCandidate
19931993
| ClosureCandidate { .. }

compiler/rustc_ty_utils/src/assoc.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,17 @@ impl<'tcx> Visitor<'tcx> for RPITVisitor<'tcx> {
177177
}
178178
}
179179

180+
struct DisambiguatorIdxVisitor {
181+
depth: u32,
182+
}
183+
184+
impl<'tcx> Visitor<'tcx> for DisambiguatorIdxVisitor {
185+
fn visit_opaque_ty(&mut self, opaque: &'tcx hir::OpaqueTy<'tcx>) -> Self::Result {
186+
self.depth += 1;
187+
intravisit::walk_opaque_ty(self, opaque)
188+
}
189+
}
190+
180191
/// Given an `fn_def_id` of a trait or a trait implementation:
181192
///
182193
/// if `fn_def_id` is a function defined inside a trait, then it synthesizes
@@ -211,16 +222,19 @@ fn associated_types_for_impl_traits_in_associated_fn(
211222
let disambiguator_idx = trait_item_refs
212223
.iter()
213224
.take_while(|item| item.id.owner_id.def_id != fn_def_id)
214-
.fold(0, |acc, item| {
215-
if !matches!(item.kind, hir::AssocItemKind::Fn { .. }) {
216-
acc
217-
} else if def_path_id(item.id.owner_id.def_id) == def_path_data {
218-
tcx.def_key(item.id.owner_id.def_id).disambiguated_data.disambiguator
219-
+ 1
220-
} else {
221-
acc
222-
}
223-
});
225+
.filter(|item| {
226+
matches!(item.kind, hir::AssocItemKind::Fn { .. })
227+
&& def_path_id(item.id.owner_id.def_id) == def_path_data
228+
})
229+
.last()
230+
.map(|item| {
231+
let output = tcx.hir_get_fn_output(item.id.owner_id.def_id).unwrap();
232+
let mut visitor = DisambiguatorIdxVisitor { depth: 0 };
233+
visitor.visit_fn_ret_ty(output);
234+
tcx.def_key(item.id.owner_id.def_id).disambiguated_data.disambiguator
235+
+ visitor.depth
236+
})
237+
.unwrap_or_default();
224238

225239
let data = DefPathData::AnonAssocTy(def_path_data);
226240
let mut visitor = RPITVisitor {

library/alloc/src/string.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ use crate::vec::{self, Vec};
156156
/// ```
157157
///
158158
/// Next, what should `s[i]` return? Because indexing returns a reference
159-
/// to underlying data it could be `&u8`, `&[u8]`, or something else similar.
159+
/// to underlying data it could be `&u8`, `&[u8]`, or something similar.
160160
/// Since we're only providing one index, `&u8` makes the most sense but that
161161
/// might not be what the user expects and can be explicitly achieved with
162162
/// [`as_bytes()`]:
@@ -2875,7 +2875,8 @@ macro_rules! impl_to_string {
28752875
out = String::with_capacity(SIZE);
28762876
}
28772877

2878-
out.push_str(self.unsigned_abs()._fmt(&mut buf));
2878+
// SAFETY: `buf` is always big enough to contain all the digits.
2879+
unsafe { out.push_str(self.unsigned_abs()._fmt(&mut buf)); }
28792880
out
28802881
}
28812882
}
@@ -2887,7 +2888,8 @@ macro_rules! impl_to_string {
28872888
const SIZE: usize = $unsigned::MAX.ilog10() as usize + 1;
28882889
let mut buf = [core::mem::MaybeUninit::<u8>::uninit(); SIZE];
28892890

2890-
self._fmt(&mut buf).to_string()
2891+
// SAFETY: `buf` is always big enough to contain all the digits.
2892+
unsafe { self._fmt(&mut buf).to_string() }
28912893
}
28922894
}
28932895
)*

library/alloctests/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#![feature(downcast_unchecked)]
1010
#![feature(exact_size_is_empty)]
1111
#![feature(hashmap_internals)]
12+
#![feature(int_format_into)]
1213
#![feature(linked_list_cursors)]
1314
#![feature(map_try_insert)]
1415
#![feature(pattern)]

0 commit comments

Comments
 (0)