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

Commit f3996f6

Browse files
committed
review
1 parent bc0156b commit f3996f6

File tree

21 files changed

+62
-40
lines changed

21 files changed

+62
-40
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
499499
ty::Adt(def, ..) if !def.is_box() => {
500500
// Again, only create type information if full debuginfo is enabled
501501
if cx.sess().opts.debuginfo == DebugInfo::Full
502-
&& !impl_self_ty.needs_subst(cx.tcx)
502+
&& !impl_self_ty.definitely_needs_subst(cx.tcx)
503503
{
504504
Some(type_metadata(cx, impl_self_ty, rustc_span::DUMMY_SP))
505505
} else {

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
470470
{
471471
let needs_canonical_flags = if canonicalize_region_mode.any() {
472472
TypeFlags::NEEDS_INFER |
473-
TypeFlags::HAS_POTENTIAL_FREE_REGIONS | // `HAS_RE_PLACEHOLDER` implies `HAS_xxx_FREE_REGIONS`
473+
TypeFlags::HAS_POTENTIAL_FREE_REGIONS | // `HAS_RE_PLACEHOLDER` implies `HAS_POTENTIAL_FREE_REGIONS`
474474
TypeFlags::HAS_TY_PLACEHOLDER |
475475
TypeFlags::HAS_CT_PLACEHOLDER
476476
} else {

compiler/rustc_lint/src/noop_method_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
6262
_ => return,
6363
};
6464
let substs = cx.typeck_results().node_substs(expr.hir_id);
65-
if substs.needs_subst(cx.tcx) {
65+
if substs.definitely_needs_subst(cx.tcx) {
6666
// We can't resolve on types that require monomorphization, so we don't handle them if
6767
// we need to perfom substitution.
6868
return;

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl<'tcx> Body<'tcx> {
285285
predecessor_cache: PredecessorCache::new(),
286286
is_cyclic: GraphIsCyclicCache::new(),
287287
};
288-
body.is_polymorphic = body.has_param_types_or_consts(tcx);
288+
body.is_polymorphic = body.definitely_has_param_types_or_consts(tcx);
289289
body
290290
}
291291

compiler/rustc_middle/src/ty/flags.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,20 @@ impl FlagComputation {
311311
}
312312

313313
fn add_unevaluated_const<P>(&mut self, ct: ty::Unevaluated<'tcx, P>) {
314+
// The generic arguments of unevaluated consts are a bit special,
315+
// see the `rustc-dev-guide` for more information.
316+
//
317+
// FIXME(@lcnr): Actually add a link here.
314318
if let Some(substs) = ct.substs_ {
319+
// If they are available, we treat them as ordinary generic arguments.
315320
self.add_substs(substs);
316321
} else {
322+
// Otherwise, we add `HAS_UNKNOWN_DEFAULT_CONST_SUBSTS` to signify
323+
// that our const may potentially refer to generic parameters.
324+
//
325+
// Note that depending on which generic parameters are actually
326+
// used in this constant, we may not actually refer to any generic
327+
// parameters at all.
317328
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
318329
self.add_flags(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS);
319330
}

compiler/rustc_middle/src/ty/fold.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
9292
fn references_error(&self) -> bool {
9393
self.has_type_flags(TypeFlags::HAS_ERROR)
9494
}
95-
fn has_potential_param_types_or_consts(&self) -> bool {
95+
fn potentially_has_param_types_or_consts(&self) -> bool {
9696
self.has_type_flags(
9797
TypeFlags::HAS_KNOWN_TY_PARAM
9898
| TypeFlags::HAS_KNOWN_CT_PARAM
9999
| TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS,
100100
)
101101
}
102-
fn has_param_types_or_consts(&self, tcx: TyCtxt<'tcx>) -> bool {
102+
fn definitely_has_param_types_or_consts(&self, tcx: TyCtxt<'tcx>) -> bool {
103103
self.definitely_has_type_flags(
104104
tcx,
105105
TypeFlags::HAS_KNOWN_TY_PARAM | TypeFlags::HAS_KNOWN_CT_PARAM,
@@ -129,7 +129,7 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
129129
TypeFlags::KNOWN_NEEDS_SUBST | TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS,
130130
)
131131
}
132-
fn needs_subst(&self, tcx: TyCtxt<'tcx>) -> bool {
132+
fn definitely_needs_subst(&self, tcx: TyCtxt<'tcx>) -> bool {
133133
self.definitely_has_type_flags(tcx, TypeFlags::KNOWN_NEEDS_SUBST)
134134
}
135135
/// "Free" regions in this context means that it has any region
@@ -227,10 +227,13 @@ pub trait TypeVisitor<'tcx>: Sized {
227227
/// Supplies the `tcx` for an unevaluated anonymous constant in case its default substs
228228
/// are not yet supplied.
229229
///
230-
/// Visitors which do not look into these substs may return `None` here, in which case
231-
/// `super_visit_with` completely skips the default substs. Incorrectly returning
232-
/// `None` can very quickly lead to ICE or other critical bugs, so be careful and
233-
/// try to return an actual `tcx` if at all possible.
230+
/// Returning `None` for this method is only recommended if the `TypeVisitor`
231+
/// does not care about default anon const substs, as it ignores generic parameters,
232+
/// and fetching the default substs would cause a query cycle.
233+
///
234+
/// For visitors which return `None` we completely skip the default substs in `ty::Unevaluated::super_visit_with`.
235+
/// This means that incorrectly returning `None` can very quickly lead to ICE or other critical bugs, so be careful and
236+
/// try to return an actual `tcx` if possible.
234237
fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>>;
235238

236239
fn visit_binder<T: TypeFoldable<'tcx>>(

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
17271727
// Ignore layouts that are done with non-empty environments or
17281728
// non-monomorphic layouts, as the user only wants to see the stuff
17291729
// resulting from the final codegen session.
1730-
if layout.ty.has_param_types_or_consts(self.tcx)
1730+
if layout.ty.definitely_has_param_types_or_consts(self.tcx)
17311731
|| !self.param_env.caller_bounds().is_empty()
17321732
{
17331733
return;
@@ -1896,7 +1896,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
18961896
let tail = tcx.struct_tail_erasing_lifetimes(pointee, param_env);
18971897
match tail.kind() {
18981898
ty::Param(_) | ty::Projection(_) => {
1899-
debug_assert!(tail.has_param_types_or_consts(tcx));
1899+
debug_assert!(tail.definitely_has_param_types_or_consts(tcx));
19001900
Ok(SizeSkeleton::Pointer { non_zero, tail: tcx.erase_regions(tail) })
19011901
}
19021902
_ => bug!(

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ pub trait PrettyPrinter<'tcx>:
11931193

11941194
// Aggregates, printed as array/tuple/struct/variant construction syntax.
11951195
//
1196-
// NB: the `has_param_types_or_consts` check ensures that we can use
1196+
// NB: the `potentially_has_param_types_or_consts` check ensures that we can use
11971197
// the `destructure_const` query with an empty `ty::ParamEnv` without
11981198
// introducing ICEs (e.g. via `layout_of`) from missing bounds.
11991199
// E.g. `transmute([0usize; 2]): (u8, *mut T)` needs to know `T: Sized`
@@ -1202,7 +1202,7 @@ pub trait PrettyPrinter<'tcx>:
12021202
// FIXME(eddyb) for `--emit=mir`/`-Z dump-mir`, we should provide the
12031203
// correct `ty::ParamEnv` to allow printing *all* constant values.
12041204
(_, ty::Array(..) | ty::Tuple(..) | ty::Adt(..))
1205-
if !ty.has_potential_param_types_or_consts() =>
1205+
if !ty.potentially_has_param_types_or_consts() =>
12061206
{
12071207
let contents = self.tcx().destructure_const(
12081208
ty::ParamEnv::reveal_all()

compiler/rustc_mir/src/interpret/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ where
4343
let is_used = unused_params.contains(index).map_or(true, |unused| !unused);
4444
// Only recurse when generic parameters in fns, closures and generators
4545
// are used and require substitution.
46-
match (is_used, subst.needs_subst(self.tcx)) {
46+
match (is_used, subst.definitely_needs_subst(self.tcx)) {
4747
// Just in case there are closures or generators within this subst,
4848
// recurse.
4949
(true, true) => return subst.super_visit_with(self),

compiler/rustc_mir/src/monomorphize/polymorphize.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
288288
}
289289
#[instrument(skip(self))]
290290
fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow<Self::BreakTy> {
291-
if !c.has_potential_param_types_or_consts() {
291+
if !c.potentially_has_param_types_or_consts() {
292292
return ControlFlow::CONTINUE;
293293
}
294294

@@ -321,7 +321,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
321321

322322
#[instrument(skip(self))]
323323
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
324-
if !ty.has_potential_param_types_or_consts() {
324+
if !ty.potentially_has_param_types_or_consts() {
325325
return ControlFlow::CONTINUE;
326326
}
327327

@@ -363,7 +363,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a, 'tcx> {
363363

364364
#[instrument(skip(self))]
365365
fn visit_const(&mut self, c: &'tcx Const<'tcx>) -> ControlFlow<Self::BreakTy> {
366-
if !c.has_potential_param_types_or_consts() {
366+
if !c.potentially_has_param_types_or_consts() {
367367
return ControlFlow::CONTINUE;
368368
}
369369

@@ -381,7 +381,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a, 'tcx> {
381381

382382
#[instrument(skip(self))]
383383
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
384-
if !ty.has_potential_param_types_or_consts() {
384+
if !ty.potentially_has_param_types_or_consts() {
385385
return ControlFlow::CONTINUE;
386386
}
387387

0 commit comments

Comments
 (0)