Skip to content

Commit 8ccc89b

Browse files
committed
Auto merge of rust-lang#82777 - GuillaumeGomez:rollup-etcsupl, r=GuillaumeGomez
Rollup of 5 pull requests Successful merges: - rust-lang#76716 (Don't warn for `missing_doc_examples` when item is #[doc(hidden)]) - rust-lang#82088 (Shorten html::render) - rust-lang#82690 (Update rustdoc documentation) - rust-lang#82752 (Add a regression test for issue-81712) - rust-lang#82765 (Fix polymorphization ICE on associated types in trait decls using const generics in bounds) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents a0d66b5 + f74231f commit 8ccc89b

19 files changed

+2939
-2863
lines changed

compiler/rustc_middle/src/mir/query.rs

-12
Original file line numberDiff line numberDiff line change
@@ -438,18 +438,6 @@ impl<'tcx> TyCtxt<'tcx> {
438438
}
439439
}
440440

441-
#[inline]
442-
pub fn optimized_mir_or_const_arg_mir(
443-
self,
444-
def: ty::WithOptConstParam<DefId>,
445-
) -> &'tcx Body<'tcx> {
446-
if let Some((did, param_did)) = def.as_const_arg() {
447-
self.mir_for_ctfe_of_const_arg((did, param_did))
448-
} else {
449-
self.optimized_mir(def.did)
450-
}
451-
}
452-
453441
#[inline]
454442
pub fn mir_for_ctfe_opt_const_arg(self, def: ty::WithOptConstParam<DefId>) -> &'tcx Body<'tcx> {
455443
if let Some((did, param_did)) = def.as_const_arg() {

compiler/rustc_middle/src/ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ impl<'tcx> Instance<'tcx> {
499499
}
500500

501501
/// Returns a new `Instance` where generic parameters in `instance.substs` are replaced by
502-
/// identify parameters if they are determined to be unused in `instance.def`.
502+
/// identity parameters if they are determined to be unused in `instance.def`.
503503
pub fn polymorphize(self, tcx: TyCtxt<'tcx>) -> Self {
504504
debug!("polymorphize: running polymorphization analysis");
505505
if !tcx.sess.opts.debugging_opts.polymorphize {

compiler/rustc_middle/src/ty/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2963,7 +2963,10 @@ impl<'tcx> TyCtxt<'tcx> {
29632963
| DefKind::AnonConst => self.mir_for_ctfe_opt_const_arg(def),
29642964
// If the caller wants `mir_for_ctfe` of a function they should not be using
29652965
// `instance_mir`, so we'll assume const fn also wants the optimized version.
2966-
_ => self.optimized_mir_or_const_arg_mir(def),
2966+
_ => {
2967+
assert_eq!(def.const_param_did, None);
2968+
self.optimized_mir(def.did)
2969+
}
29672970
},
29682971
ty::InstanceDef::VtableShim(..)
29692972
| ty::InstanceDef::ReifyShim(..)

compiler/rustc_mir/src/monomorphize/polymorphize.rs

+64-40
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ pub fn provide(providers: &mut Providers) {
3030
/// Determine which generic parameters are used by the function/method/closure represented by
3131
/// `def_id`. Returns a bitset where bits representing unused parameters are set (`is_empty`
3232
/// indicates all parameters are used).
33+
#[instrument(skip(tcx))]
3334
fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
34-
debug!("unused_generic_params({:?})", def_id);
35-
3635
if !tcx.sess.opts.debugging_opts.polymorphize {
3736
// If polymorphization disabled, then all parameters are used.
3837
return FiniteBitSet::new_empty();
@@ -46,7 +45,7 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
4645
}
4746

4847
let generics = tcx.generics_of(def_id);
49-
debug!("unused_generic_params: generics={:?}", generics);
48+
debug!(?generics);
5049

5150
// Exit early when there are no parameters to be unused.
5251
if generics.count() == 0 {
@@ -57,11 +56,11 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
5756
let context = tcx.hir().body_const_context(def_id.expect_local());
5857
match context {
5958
Some(ConstContext::ConstFn) | None if !tcx.is_mir_available(def_id) => {
60-
debug!("unused_generic_params: (no mir available) def_id={:?}", def_id);
59+
debug!("no mir available");
6160
return FiniteBitSet::new_empty();
6261
}
6362
Some(_) if !tcx.is_ctfe_mir_available(def_id) => {
64-
debug!("unused_generic_params: (no ctfe mir available) def_id={:?}", def_id);
63+
debug!("no ctfe mir available");
6564
return FiniteBitSet::new_empty();
6665
}
6766
_ => {}
@@ -72,9 +71,9 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
7271
generics.count().try_into().expect("more generic parameters than can fit into a `u32`");
7372
let mut unused_parameters = FiniteBitSet::<u32>::new_empty();
7473
unused_parameters.set_range(0..generics_count);
75-
debug!("unused_generic_params: (start) unused_parameters={:?}", unused_parameters);
74+
debug!(?unused_parameters, "(start)");
7675
mark_used_by_default_parameters(tcx, def_id, generics, &mut unused_parameters);
77-
debug!("unused_generic_params: (after default) unused_parameters={:?}", unused_parameters);
76+
debug!(?unused_parameters, "(after default)");
7877

7978
// Visit MIR and accumululate used generic parameters.
8079
let body = match context {
@@ -85,10 +84,10 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
8584
};
8685
let mut vis = MarkUsedGenericParams { tcx, def_id, unused_parameters: &mut unused_parameters };
8786
vis.visit_body(body);
88-
debug!("unused_generic_params: (after visitor) unused_parameters={:?}", unused_parameters);
87+
debug!(?unused_parameters, "(after visitor)");
8988

9089
mark_used_by_predicates(tcx, def_id, &mut unused_parameters);
91-
debug!("unused_generic_params: (end) unused_parameters={:?}", unused_parameters);
90+
debug!(?unused_parameters, "(end)");
9291

9392
// Emit errors for debugging and testing if enabled.
9493
if !unused_parameters.is_empty() {
@@ -101,24 +100,55 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet<u32> {
101100
/// Some parameters are considered used-by-default, such as non-generic parameters and the dummy
102101
/// generic parameters from closures, this function marks them as used. `leaf_is_closure` should
103102
/// be `true` if the item that `unused_generic_params` was invoked on is a closure.
103+
#[instrument(skip(tcx, def_id, generics, unused_parameters))]
104104
fn mark_used_by_default_parameters<'tcx>(
105105
tcx: TyCtxt<'tcx>,
106106
def_id: DefId,
107107
generics: &'tcx ty::Generics,
108108
unused_parameters: &mut FiniteBitSet<u32>,
109109
) {
110-
if !tcx.is_trait(def_id) && (tcx.is_closure(def_id) || tcx.type_of(def_id).is_generator()) {
111-
for param in &generics.params {
112-
debug!("mark_used_by_default_parameters: (closure/gen) param={:?}", param);
113-
unused_parameters.clear(param.index);
114-
}
115-
} else {
116-
for param in &generics.params {
117-
debug!("mark_used_by_default_parameters: (other) param={:?}", param);
118-
if let ty::GenericParamDefKind::Lifetime = param.kind {
110+
match tcx.def_kind(def_id) {
111+
DefKind::Closure | DefKind::Generator => {
112+
for param in &generics.params {
113+
debug!(?param, "(closure/gen)");
119114
unused_parameters.clear(param.index);
120115
}
121116
}
117+
DefKind::Mod
118+
| DefKind::Struct
119+
| DefKind::Union
120+
| DefKind::Enum
121+
| DefKind::Variant
122+
| DefKind::Trait
123+
| DefKind::TyAlias
124+
| DefKind::ForeignTy
125+
| DefKind::TraitAlias
126+
| DefKind::AssocTy
127+
| DefKind::TyParam
128+
| DefKind::Fn
129+
| DefKind::Const
130+
| DefKind::ConstParam
131+
| DefKind::Static
132+
| DefKind::Ctor(_, _)
133+
| DefKind::AssocFn
134+
| DefKind::AssocConst
135+
| DefKind::Macro(_)
136+
| DefKind::ExternCrate
137+
| DefKind::Use
138+
| DefKind::ForeignMod
139+
| DefKind::AnonConst
140+
| DefKind::OpaqueTy
141+
| DefKind::Field
142+
| DefKind::LifetimeParam
143+
| DefKind::GlobalAsm
144+
| DefKind::Impl => {
145+
for param in &generics.params {
146+
debug!(?param, "(other)");
147+
if let ty::GenericParamDefKind::Lifetime = param.kind {
148+
unused_parameters.clear(param.index);
149+
}
150+
}
151+
}
122152
}
123153

124154
if let Some(parent) = generics.parent {
@@ -128,23 +158,20 @@ fn mark_used_by_default_parameters<'tcx>(
128158

129159
/// Search the predicates on used generic parameters for any unused generic parameters, and mark
130160
/// those as used.
161+
#[instrument(skip(tcx, def_id))]
131162
fn mark_used_by_predicates<'tcx>(
132163
tcx: TyCtxt<'tcx>,
133164
def_id: DefId,
134165
unused_parameters: &mut FiniteBitSet<u32>,
135166
) {
136167
let def_id = tcx.closure_base_def_id(def_id);
137168
let predicates = tcx.explicit_predicates_of(def_id);
138-
debug!("mark_used_by_predicates: predicates_of={:?}", predicates);
139169

140170
let mut current_unused_parameters = FiniteBitSet::new_empty();
141171
// Run to a fixed point to support `where T: Trait<U>, U: Trait<V>`, starting with an empty
142172
// bit set so that this is skipped if all parameters are already used.
143173
while current_unused_parameters != *unused_parameters {
144-
debug!(
145-
"mark_used_by_predicates: current_unused_parameters={:?} = unused_parameters={:?}",
146-
current_unused_parameters, unused_parameters
147-
);
174+
debug!(?current_unused_parameters, ?unused_parameters);
148175
current_unused_parameters = *unused_parameters;
149176

150177
for (predicate, _) in predicates.predicates {
@@ -169,13 +196,13 @@ fn mark_used_by_predicates<'tcx>(
169196

170197
/// Emit errors for the function annotated by `#[rustc_polymorphize_error]`, labelling each generic
171198
/// parameter which was unused.
199+
#[instrument(skip(tcx, generics))]
172200
fn emit_unused_generic_params_error<'tcx>(
173201
tcx: TyCtxt<'tcx>,
174202
def_id: DefId,
175203
generics: &'tcx ty::Generics,
176204
unused_parameters: &FiniteBitSet<u32>,
177205
) {
178-
debug!("emit_unused_generic_params_error: def_id={:?}", def_id);
179206
let base_def_id = tcx.closure_base_def_id(def_id);
180207
if !tcx
181208
.get_attrs(base_def_id)
@@ -185,7 +212,6 @@ fn emit_unused_generic_params_error<'tcx>(
185212
return;
186213
}
187214

188-
debug!("emit_unused_generic_params_error: unused_parameters={:?}", unused_parameters);
189215
let fn_span = match tcx.opt_item_name(def_id) {
190216
Some(ident) => ident.span,
191217
_ => tcx.def_span(def_id),
@@ -197,7 +223,7 @@ fn emit_unused_generic_params_error<'tcx>(
197223
while let Some(generics) = next_generics {
198224
for param in &generics.params {
199225
if unused_parameters.contains(param.index).unwrap_or(false) {
200-
debug!("emit_unused_generic_params_error: param={:?}", param);
226+
debug!(?param);
201227
let def_span = tcx.def_span(param.def_id);
202228
err.span_label(def_span, &format!("generic parameter `{}` is unused", param.name));
203229
}
@@ -219,33 +245,31 @@ struct MarkUsedGenericParams<'a, 'tcx> {
219245
impl<'a, 'tcx> MarkUsedGenericParams<'a, 'tcx> {
220246
/// Invoke `unused_generic_params` on a body contained within the current item (e.g.
221247
/// a closure, generator or constant).
248+
#[instrument(skip(self, def_id, substs))]
222249
fn visit_child_body(&mut self, def_id: DefId, substs: SubstsRef<'tcx>) {
223250
let unused = self.tcx.unused_generic_params(def_id);
224-
debug!(
225-
"visit_child_body: unused_parameters={:?} unused={:?}",
226-
self.unused_parameters, unused
227-
);
251+
debug!(?self.unused_parameters, ?unused);
228252
for (i, arg) in substs.iter().enumerate() {
229253
let i = i.try_into().unwrap();
230254
if !unused.contains(i).unwrap_or(false) {
231255
arg.visit_with(self);
232256
}
233257
}
234-
debug!("visit_child_body: unused_parameters={:?}", self.unused_parameters);
258+
debug!(?self.unused_parameters);
235259
}
236260
}
237261

238262
impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
263+
#[instrument(skip(self, local))]
239264
fn visit_local_decl(&mut self, local: Local, local_decl: &LocalDecl<'tcx>) {
240-
debug!("visit_local_decl: local_decl={:?}", local_decl);
241265
if local == Local::from_usize(1) {
242266
let def_kind = self.tcx.def_kind(self.def_id);
243267
if matches!(def_kind, DefKind::Closure | DefKind::Generator) {
244268
// Skip visiting the closure/generator that is currently being processed. This only
245269
// happens because the first argument to the closure is a reference to itself and
246270
// that will call `visit_substs`, resulting in each generic parameter captured being
247271
// considered used by default.
248-
debug!("visit_local_decl: skipping closure substs");
272+
debug!("skipping closure substs");
249273
return;
250274
}
251275
}
@@ -263,15 +287,15 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
263287
}
264288

265289
impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
290+
#[instrument(skip(self))]
266291
fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow<Self::BreakTy> {
267-
debug!("visit_const: c={:?}", c);
268292
if !c.has_param_types_or_consts() {
269293
return ControlFlow::CONTINUE;
270294
}
271295

272296
match c.val {
273297
ty::ConstKind::Param(param) => {
274-
debug!("visit_const: param={:?}", param);
298+
debug!(?param);
275299
self.unused_parameters.clear(param.index);
276300
ControlFlow::CONTINUE
277301
}
@@ -296,15 +320,15 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
296320
}
297321
}
298322

323+
#[instrument(skip(self))]
299324
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
300-
debug!("visit_ty: ty={:?}", ty);
301325
if !ty.has_param_types_or_consts() {
302326
return ControlFlow::CONTINUE;
303327
}
304328

305329
match *ty.kind() {
306330
ty::Closure(def_id, substs) | ty::Generator(def_id, substs, ..) => {
307-
debug!("visit_ty: def_id={:?}", def_id);
331+
debug!(?def_id);
308332
// Avoid cycle errors with generators.
309333
if def_id == self.def_id {
310334
return ControlFlow::CONTINUE;
@@ -316,7 +340,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
316340
ControlFlow::CONTINUE
317341
}
318342
ty::Param(param) => {
319-
debug!("visit_ty: param={:?}", param);
343+
debug!(?param);
320344
self.unused_parameters.clear(param.index);
321345
ControlFlow::CONTINUE
322346
}
@@ -333,8 +357,8 @@ struct HasUsedGenericParams<'a> {
333357
impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a> {
334358
type BreakTy = ();
335359

360+
#[instrument(skip(self))]
336361
fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow<Self::BreakTy> {
337-
debug!("visit_const: c={:?}", c);
338362
if !c.has_param_types_or_consts() {
339363
return ControlFlow::CONTINUE;
340364
}
@@ -351,8 +375,8 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a> {
351375
}
352376
}
353377

378+
#[instrument(skip(self))]
354379
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
355-
debug!("visit_ty: ty={:?}", ty);
356380
if !ty.has_param_types_or_consts() {
357381
return ControlFlow::CONTINUE;
358382
}

src/doc/rustdoc/src/SUMMARY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- [Documentation tests](documentation-tests.md)
99
- [Linking to items by name](linking-to-items-by-name.md)
1010
- [Lints](lints.md)
11-
- [Passes](passes.md)
1211
- [Advanced features](advanced-features.md)
1312
- [Unstable features](unstable-features.md)
13+
- [Passes](passes.md)
1414
- [References](references.md)

0 commit comments

Comments
 (0)