Skip to content

Commit cf32b9d

Browse files
committed
Auto merge of rust-lang#109720 - Dylan-DPC:rollup-u564m8s, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - rust-lang#108335 (rustdoc + rustdoc-json support for `feature(non_lifetime_binders)`) - rust-lang#109534 (rustdoc: Unsupport importing `doc(primitive)` and `doc(keyword)` modules) - rust-lang#109659 (llvm-wrapper: adapt for LLVM API change) - rust-lang#109664 (Use span of placeholders in format_args!() expansion.) - rust-lang#109683 (Check for overflow in `assemble_candidates_after_normalizing_self_ty`) - rust-lang#109713 (Fix mismatched punctuation in Debug impl of AttrId) - rust-lang#109718 (Rename `IndexVec::last` → `last_index`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents f346fb0 + 1415756 commit cf32b9d

File tree

28 files changed

+348
-138
lines changed

28 files changed

+348
-138
lines changed

compiler/rustc_ast/src/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2570,7 +2570,7 @@ pub enum AttrStyle {
25702570

25712571
rustc_index::newtype_index! {
25722572
#[custom_encodable]
2573-
#[debug_format = "AttrId({})]"]
2573+
#[debug_format = "AttrId({})"]
25742574
pub struct AttrId {}
25752575
}
25762576

compiler/rustc_ast_lowering/src/format.rs

+43-23
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::LoweringContext;
22
use rustc_ast as ast;
33
use rustc_ast::visit::{self, Visitor};
44
use rustc_ast::*;
5-
use rustc_data_structures::fx::FxIndexSet;
5+
use rustc_data_structures::fx::FxIndexMap;
66
use rustc_hir as hir;
77
use rustc_span::{
88
sym,
@@ -238,7 +238,7 @@ fn make_count<'hir>(
238238
ctx: &mut LoweringContext<'_, 'hir>,
239239
sp: Span,
240240
count: &Option<FormatCount>,
241-
argmap: &mut FxIndexSet<(usize, ArgumentType)>,
241+
argmap: &mut FxIndexMap<(usize, ArgumentType), Option<Span>>,
242242
) -> hir::Expr<'hir> {
243243
match count {
244244
Some(FormatCount::Literal(n)) => {
@@ -252,7 +252,7 @@ fn make_count<'hir>(
252252
}
253253
Some(FormatCount::Argument(arg)) => {
254254
if let Ok(arg_index) = arg.index {
255-
let (i, _) = argmap.insert_full((arg_index, ArgumentType::Usize));
255+
let (i, _) = argmap.insert_full((arg_index, ArgumentType::Usize), arg.span);
256256
let count_param = ctx.arena.alloc(ctx.expr_lang_item_type_relative(
257257
sp,
258258
hir::LangItem::FormatCount,
@@ -291,12 +291,14 @@ fn make_format_spec<'hir>(
291291
ctx: &mut LoweringContext<'_, 'hir>,
292292
sp: Span,
293293
placeholder: &FormatPlaceholder,
294-
argmap: &mut FxIndexSet<(usize, ArgumentType)>,
294+
argmap: &mut FxIndexMap<(usize, ArgumentType), Option<Span>>,
295295
) -> hir::Expr<'hir> {
296296
let position = match placeholder.argument.index {
297297
Ok(arg_index) => {
298-
let (i, _) =
299-
argmap.insert_full((arg_index, ArgumentType::Format(placeholder.format_trait)));
298+
let (i, _) = argmap.insert_full(
299+
(arg_index, ArgumentType::Format(placeholder.format_trait)),
300+
placeholder.span,
301+
);
300302
ctx.expr_usize(sp, i)
301303
}
302304
Err(_) => ctx.expr(
@@ -386,15 +388,18 @@ fn expand_format_args<'hir>(
386388

387389
// Create a list of all _unique_ (argument, format trait) combinations.
388390
// E.g. "{0} {0:x} {0} {1}" -> [(0, Display), (0, LowerHex), (1, Display)]
389-
let mut argmap = FxIndexSet::default();
391+
let mut argmap = FxIndexMap::default();
390392
for piece in &fmt.template {
391393
let FormatArgsPiece::Placeholder(placeholder) = piece else { continue };
392394
if placeholder.format_options != Default::default() {
393395
// Can't use basic form if there's any formatting options.
394396
use_format_options = true;
395397
}
396398
if let Ok(index) = placeholder.argument.index {
397-
if !argmap.insert((index, ArgumentType::Format(placeholder.format_trait))) {
399+
if argmap
400+
.insert((index, ArgumentType::Format(placeholder.format_trait)), placeholder.span)
401+
.is_some()
402+
{
398403
// Duplicate (argument, format trait) combination,
399404
// which we'll only put once in the args array.
400405
use_format_options = true;
@@ -438,7 +443,7 @@ fn expand_format_args<'hir>(
438443
// This is an optimization, speeding up compilation about 1-2% in some cases.
439444
// See https://github.com/rust-lang/rust/pull/106770#issuecomment-1380790609
440445
let use_simple_array = argmap.len() == arguments.len()
441-
&& argmap.iter().enumerate().all(|(i, &(j, _))| i == j)
446+
&& argmap.iter().enumerate().all(|(i, (&(j, _), _))| i == j)
442447
&& arguments.iter().skip(1).all(|arg| !may_contain_yield_point(&arg.expr));
443448

444449
let args = if use_simple_array {
@@ -452,14 +457,19 @@ fn expand_format_args<'hir>(
452457
let elements: Vec<_> = arguments
453458
.iter()
454459
.zip(argmap)
455-
.map(|(arg, (_, ty))| {
456-
let sp = arg.expr.span.with_ctxt(macsp.ctxt());
460+
.map(|(arg, ((_, ty), placeholder_span))| {
461+
let placeholder_span =
462+
placeholder_span.unwrap_or(arg.expr.span).with_ctxt(macsp.ctxt());
463+
let arg_span = match arg.kind {
464+
FormatArgumentKind::Captured(_) => placeholder_span,
465+
_ => arg.expr.span.with_ctxt(macsp.ctxt()),
466+
};
457467
let arg = ctx.lower_expr(&arg.expr);
458468
let ref_arg = ctx.arena.alloc(ctx.expr(
459-
sp,
469+
arg_span,
460470
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Not, arg),
461471
));
462-
make_argument(ctx, sp, ref_arg, ty)
472+
make_argument(ctx, placeholder_span, ref_arg, ty)
463473
})
464474
.collect();
465475
ctx.expr_array_ref(macsp, ctx.arena.alloc_from_iter(elements))
@@ -475,16 +485,26 @@ fn expand_format_args<'hir>(
475485
// }
476486
let args_ident = Ident::new(sym::args, macsp);
477487
let (args_pat, args_hir_id) = ctx.pat_ident(macsp, args_ident);
478-
let args = ctx.arena.alloc_from_iter(argmap.iter().map(|&(arg_index, ty)| {
479-
let arg = &arguments[arg_index];
480-
let sp = arg.expr.span.with_ctxt(macsp.ctxt());
481-
let args_ident_expr = ctx.expr_ident(macsp, args_ident, args_hir_id);
482-
let arg = ctx.arena.alloc(ctx.expr(
483-
sp,
484-
hir::ExprKind::Field(args_ident_expr, Ident::new(sym::integer(arg_index), macsp)),
485-
));
486-
make_argument(ctx, sp, arg, ty)
487-
}));
488+
let args = ctx.arena.alloc_from_iter(argmap.iter().map(
489+
|(&(arg_index, ty), &placeholder_span)| {
490+
let arg = &arguments[arg_index];
491+
let placeholder_span =
492+
placeholder_span.unwrap_or(arg.expr.span).with_ctxt(macsp.ctxt());
493+
let arg_span = match arg.kind {
494+
FormatArgumentKind::Captured(_) => placeholder_span,
495+
_ => arg.expr.span.with_ctxt(macsp.ctxt()),
496+
};
497+
let args_ident_expr = ctx.expr_ident(macsp, args_ident, args_hir_id);
498+
let arg = ctx.arena.alloc(ctx.expr(
499+
arg_span,
500+
hir::ExprKind::Field(
501+
args_ident_expr,
502+
Ident::new(sym::integer(arg_index), macsp),
503+
),
504+
));
505+
make_argument(ctx, placeholder_span, arg, ty)
506+
},
507+
));
488508
let elements: Vec<_> = arguments
489509
.iter()
490510
.map(|arg| {

compiler/rustc_const_eval/src/transform/promote_consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
707707
}
708708

709709
fn assign(&mut self, dest: Local, rvalue: Rvalue<'tcx>, span: Span) {
710-
let last = self.promoted.basic_blocks.last().unwrap();
710+
let last = self.promoted.basic_blocks.last_index().unwrap();
711711
let data = &mut self.promoted[last];
712712
data.statements.push(Statement {
713713
source_info: SourceInfo::outermost(span),
@@ -800,7 +800,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
800800
self.visit_operand(arg, loc);
801801
}
802802

803-
let last = self.promoted.basic_blocks.last().unwrap();
803+
let last = self.promoted.basic_blocks.last_index().unwrap();
804804
let new_target = self.new_block();
805805

806806
*self.promoted[last].terminator_mut() = Terminator {

compiler/rustc_index/src/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl<I: Idx, T> IndexVec<I, T> {
216216
}
217217

218218
#[inline]
219-
pub fn last(&self) -> Option<I> {
219+
pub fn last_index(&self) -> Option<I> {
220220
self.len().checked_sub(1).map(I::new)
221221
}
222222

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -1163,13 +1163,6 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
11631163
// Otherwise, we sometimes lose `static` values -- see #60184.
11641164
computeDeadSymbolsWithConstProp(Ret->Index, Ret->GUIDPreservedSymbols,
11651165
deadIsPrevailing, /* ImportEnabled = */ false);
1166-
ComputeCrossModuleImport(
1167-
Ret->Index,
1168-
Ret->ModuleToDefinedGVSummaries,
1169-
Ret->ImportLists,
1170-
Ret->ExportLists
1171-
);
1172-
11731166
// Resolve LinkOnce/Weak symbols, this has to be computed early be cause it
11741167
// impacts the caching.
11751168
//
@@ -1186,6 +1179,16 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
11861179
return true;
11871180
return Prevailing->second == S;
11881181
};
1182+
ComputeCrossModuleImport(
1183+
Ret->Index,
1184+
Ret->ModuleToDefinedGVSummaries,
1185+
#if LLVM_VERSION_GE(17, 0)
1186+
isPrevailing,
1187+
#endif
1188+
Ret->ImportLists,
1189+
Ret->ExportLists
1190+
);
1191+
11891192
auto recordNewLinkage = [&](StringRef ModuleIdentifier,
11901193
GlobalValue::GUID GUID,
11911194
GlobalValue::LinkageTypes NewLinkage) {

compiler/rustc_mir_transform/src/coverage/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'tcx> MockBlocks<'tcx> {
6565
}
6666

6767
fn push(&mut self, kind: TerminatorKind<'tcx>) -> BasicBlock {
68-
let next_lo = if let Some(last) = self.blocks.last() {
68+
let next_lo = if let Some(last) = self.blocks.last_index() {
6969
self.blocks[last].terminator().source_info.span.hi()
7070
} else {
7171
BytePos(1)

compiler/rustc_trait_selection/src/solve/assembly.rs

+32-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Code shared by trait and projection goals for candidate assembly.
22
3+
use super::search_graph::OverflowHandler;
34
#[cfg(doc)]
45
use super::trait_goals::structural_traits::*;
56
use super::{EvalCtxt, SolverMode};
@@ -279,25 +280,38 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
279280
return
280281
};
281282

282-
self.probe(|ecx| {
283-
let normalized_ty = ecx.next_ty_infer();
284-
let normalizes_to_goal = goal.with(
285-
tcx,
286-
ty::Binder::dummy(ty::ProjectionPredicate {
287-
projection_ty,
288-
term: normalized_ty.into(),
289-
}),
290-
);
291-
ecx.add_goal(normalizes_to_goal);
292-
if let Ok(_) = ecx.try_evaluate_added_goals() {
293-
let normalized_ty = ecx.resolve_vars_if_possible(normalized_ty);
294-
295-
// NOTE: Alternatively we could call `evaluate_goal` here and only have a `Normalized` candidate.
296-
// This doesn't work as long as we use `CandidateSource` in winnowing.
297-
let goal = goal.with(tcx, goal.predicate.with_self_ty(tcx, normalized_ty));
298-
candidates.extend(ecx.assemble_and_evaluate_candidates(goal));
299-
}
283+
let normalized_self_candidates: Result<_, NoSolution> = self.probe(|ecx| {
284+
ecx.with_incremented_depth(
285+
|ecx| {
286+
let result = ecx.evaluate_added_goals_and_make_canonical_response(
287+
Certainty::Maybe(MaybeCause::Overflow),
288+
)?;
289+
Ok(vec![Candidate { source: CandidateSource::BuiltinImpl, result }])
290+
},
291+
|ecx| {
292+
let normalized_ty = ecx.next_ty_infer();
293+
let normalizes_to_goal = goal.with(
294+
tcx,
295+
ty::Binder::dummy(ty::ProjectionPredicate {
296+
projection_ty,
297+
term: normalized_ty.into(),
298+
}),
299+
);
300+
ecx.add_goal(normalizes_to_goal);
301+
let _ = ecx.try_evaluate_added_goals()?;
302+
let normalized_ty = ecx.resolve_vars_if_possible(normalized_ty);
303+
// NOTE: Alternatively we could call `evaluate_goal` here and only
304+
// have a `Normalized` candidate. This doesn't work as long as we
305+
// use `CandidateSource` in winnowing.
306+
let goal = goal.with(tcx, goal.predicate.with_self_ty(tcx, normalized_ty));
307+
Ok(ecx.assemble_and_evaluate_candidates(goal))
308+
},
309+
)
300310
});
311+
312+
if let Ok(normalized_self_candidates) = normalized_self_candidates {
313+
candidates.extend(normalized_self_candidates);
314+
}
301315
}
302316

303317
fn assemble_impl_candidates<G: GoalKind<'tcx>>(

compiler/rustc_trait_selection/src/solve/search_graph/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<'tcx> SearchGraph<'tcx> {
7070
/// Whether we're currently in a cycle. This should only be used
7171
/// for debug assertions.
7272
pub(super) fn in_cycle(&self) -> bool {
73-
if let Some(stack_depth) = self.stack.last() {
73+
if let Some(stack_depth) = self.stack.last_index() {
7474
// Either the current goal on the stack is the root of a cycle...
7575
if self.stack[stack_depth].has_been_used {
7676
return true;

compiler/rustc_trait_selection/src/solve/search_graph/overflow.rs

+21
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,27 @@ pub(in crate::solve) trait OverflowHandler<'tcx> {
7373
self.search_graph().overflow_data.deal_with_overflow();
7474
on_overflow(self)
7575
}
76+
77+
// Increment the `additional_depth` by one and evaluate `body`, or `on_overflow`
78+
// if the depth is overflown.
79+
fn with_incremented_depth<T>(
80+
&mut self,
81+
on_overflow: impl FnOnce(&mut Self) -> T,
82+
body: impl FnOnce(&mut Self) -> T,
83+
) -> T {
84+
let depth = self.search_graph().stack.len();
85+
self.search_graph().overflow_data.additional_depth += 1;
86+
87+
let result = if self.search_graph().overflow_data.has_overflow(depth) {
88+
self.search_graph().overflow_data.deal_with_overflow();
89+
on_overflow(self)
90+
} else {
91+
body(self)
92+
};
93+
94+
self.search_graph().overflow_data.additional_depth -= 1;
95+
result
96+
}
7697
}
7798

7899
impl<'tcx> OverflowHandler<'tcx> for EvalCtxt<'_, 'tcx> {

src/librustdoc/clean/mod.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use rustc_span::hygiene::{AstPass, MacroKind};
3131
use rustc_span::symbol::{kw, sym, Ident, Symbol};
3232
use rustc_span::{self, ExpnKind};
3333

34-
use std::assert_matches::assert_matches;
3534
use std::borrow::Cow;
3635
use std::collections::hash_map::Entry;
3736
use std::collections::BTreeMap;
@@ -270,15 +269,7 @@ fn clean_where_predicate<'tcx>(
270269
let bound_params = wbp
271270
.bound_generic_params
272271
.iter()
273-
.map(|param| {
274-
// Higher-ranked params must be lifetimes.
275-
// Higher-ranked lifetimes can't have bounds.
276-
assert_matches!(
277-
param,
278-
hir::GenericParam { kind: hir::GenericParamKind::Lifetime { .. }, .. }
279-
);
280-
Lifetime(param.name.ident().name)
281-
})
272+
.map(|param| clean_generic_param(cx, None, param))
282273
.collect();
283274
WherePredicate::BoundPredicate {
284275
ty: clean_ty(wbp.bounded_ty, cx),
@@ -410,7 +401,7 @@ fn clean_projection_predicate<'tcx>(
410401
.collect_referenced_late_bound_regions(&pred)
411402
.into_iter()
412403
.filter_map(|br| match br {
413-
ty::BrNamed(_, name) if br.is_named() => Some(Lifetime(name)),
404+
ty::BrNamed(_, name) if br.is_named() => Some(GenericParamDef::lifetime(name)),
414405
_ => None,
415406
})
416407
.collect();
@@ -508,7 +499,6 @@ fn clean_generic_param_def<'tcx>(
508499
ty::GenericParamDefKind::Const { has_default } => (
509500
def.name,
510501
GenericParamDefKind::Const {
511-
did: def.def_id,
512502
ty: Box::new(clean_middle_ty(
513503
ty::Binder::dummy(
514504
cx.tcx
@@ -578,7 +568,6 @@ fn clean_generic_param<'tcx>(
578568
hir::GenericParamKind::Const { ty, default } => (
579569
param.name.ident().name,
580570
GenericParamDefKind::Const {
581-
did: param.def_id.to_def_id(),
582571
ty: Box::new(clean_ty(ty, cx)),
583572
default: default
584573
.map(|ct| Box::new(ty::Const::from_anon_const(cx.tcx, ct.def_id).to_string())),
@@ -831,7 +820,7 @@ fn clean_ty_generics<'tcx>(
831820
p.get_bound_params()
832821
.into_iter()
833822
.flatten()
834-
.map(|param| GenericParamDef::lifetime(param.0))
823+
.cloned()
835824
.collect(),
836825
));
837826
}

src/librustdoc/clean/simplify.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ pub(crate) fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> ThinVec<WP
4949
equalities.retain(|(lhs, rhs, bound_params)| {
5050
let Some((ty, trait_did, name)) = lhs.projection() else { return true; };
5151
let Some((bounds, _)) = tybounds.get_mut(ty) else { return true };
52-
let bound_params = bound_params
53-
.into_iter()
54-
.map(|param| clean::GenericParamDef::lifetime(param.0))
55-
.collect();
56-
merge_bounds(cx, bounds, bound_params, trait_did, name, rhs)
52+
merge_bounds(cx, bounds, bound_params.clone(), trait_did, name, rhs)
5753
});
5854

5955
// And finally, let's reassemble everything

0 commit comments

Comments
 (0)