Skip to content

Commit df90ba0

Browse files
committed
Clean up comments and formatting.
Mostly by reflowing overly long comment lines.
1 parent f21ce91 commit df90ba0

File tree

21 files changed

+189
-143
lines changed

21 files changed

+189
-143
lines changed

Diff for: compiler/rustc_hir_analysis/src/bounds.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ impl<'tcx> Bounds<'tcx> {
7575
pub(crate) fn push_sized(&mut self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) {
7676
let sized_def_id = tcx.require_lang_item(LangItem::Sized, Some(span));
7777
let trait_ref = ty::TraitRef::new(tcx, sized_def_id, [ty]);
78-
// Preferable to put this obligation first, since we report better errors for sized ambiguity.
78+
// Preferable to put this obligation first, since we report better errors for sized
79+
// ambiguity.
7980
self.clauses.insert(0, (trait_ref.upcast(tcx), span));
8081
}
8182

Diff for: compiler/rustc_hir_analysis/src/check/check.rs

+22-16
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ fn check_opaque(tcx: TyCtxt<'_>, def_id: LocalDefId) {
233233

234234
// HACK(jynelson): trying to infer the type of `impl trait` breaks documenting
235235
// `async-std` (and `pub async fn` in general).
236-
// Since rustdoc doesn't care about the concrete type behind `impl Trait`, just don't look at it!
237-
// See https://github.com/rust-lang/rust/issues/75100
236+
// Since rustdoc doesn't care about the concrete type behind `impl Trait`, just don't look at
237+
// it! See https://github.com/rust-lang/rust/issues/75100
238238
if tcx.sess.opts.actually_rustdoc {
239239
return;
240240
}
@@ -322,7 +322,8 @@ fn check_opaque_meets_bounds<'tcx>(
322322
};
323323
let param_env = tcx.param_env(defining_use_anchor);
324324

325-
// FIXME(#132279): Once `PostBorrowckAnalysis` is supported in the old solver, this branch should be removed.
325+
// FIXME(#132279): Once `PostBorrowckAnalysis` is supported in the old solver, this branch
326+
// should be removed.
326327
let infcx = tcx.infer_ctxt().build(if tcx.next_trait_solver_globally() {
327328
TypingMode::post_borrowck_analysis(tcx, defining_use_anchor)
328329
} else {
@@ -401,9 +402,9 @@ fn check_opaque_meets_bounds<'tcx>(
401402
}
402403
}
403404

404-
// Additionally require the hidden type to be well-formed with only the generics of the opaque type.
405-
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the
406-
// hidden type is well formed even without those bounds.
405+
// Additionally require the hidden type to be well-formed with only the generics of the opaque
406+
// type. Defining use functions may have more bounds than the opaque type, which is ok, as long
407+
// as the hidden type is well formed even without those bounds.
407408
let predicate =
408409
ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(hidden_ty.into())));
409410
ocx.register_obligation(Obligation::new(tcx, misc_cause.clone(), param_env, predicate));
@@ -434,7 +435,8 @@ fn check_opaque_meets_bounds<'tcx>(
434435
let _ = infcx.take_opaque_types();
435436
Ok(())
436437
} else {
437-
// Check that any hidden types found during wf checking match the hidden types that `type_of` sees.
438+
// Check that any hidden types found during wf checking match the hidden types that
439+
// `type_of` sees.
438440
for (mut key, mut ty) in infcx.take_opaque_types() {
439441
ty.ty = infcx.resolve_vars_if_possible(ty.ty);
440442
key = infcx.resolve_vars_if_possible(key);
@@ -686,7 +688,8 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe
686688
ty::GenericParamDefKind::Lifetime => {
687689
let use_span = tcx.def_span(param.def_id);
688690
let opaque_span = tcx.def_span(opaque_def_id);
689-
// Check if the lifetime param was captured but isn't named in the precise captures list.
691+
// Check if the lifetime param was captured but isn't named in the precise
692+
// captures list.
690693
if variances[param.index as usize] == ty::Invariant {
691694
if let DefKind::OpaqueTy = tcx.def_kind(tcx.parent(param.def_id))
692695
&& let Some(def_id) = tcx
@@ -1519,15 +1522,17 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {
15191522
check_unsafe_fields(tcx, def_id);
15201523
}
15211524

1522-
/// Part of enum check. Given the discriminants of an enum, errors if two or more discriminants are equal
1525+
/// Part of enum check. Given the discriminants of an enum, errors if two or more discriminants are
1526+
/// equal.
15231527
fn detect_discriminant_duplicate<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>) {
15241528
// Helper closure to reduce duplicate code. This gets called everytime we detect a duplicate.
15251529
// Here `idx` refers to the order of which the discriminant appears, and its index in `vs`
15261530
let report = |dis: Discr<'tcx>, idx, err: &mut Diag<'_>| {
15271531
let var = adt.variant(idx); // HIR for the duplicate discriminant
15281532
let (span, display_discr) = match var.discr {
15291533
ty::VariantDiscr::Explicit(discr_def_id) => {
1530-
// In the case the discriminant is both a duplicate and overflowed, let the user know
1534+
// In the case the discriminant is both a duplicate and overflowed, let the user
1535+
// know.
15311536
if let hir::Node::AnonConst(expr) =
15321537
tcx.hir_node_by_def_id(discr_def_id.expect_local())
15331538
&& let hir::ExprKind::Lit(lit) = &tcx.hir().body(expr.body).value.kind
@@ -1546,7 +1551,7 @@ fn detect_discriminant_duplicate<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
15461551
// At this point we know this discriminant is a duplicate, and was not explicitly
15471552
// assigned by the user. Here we iterate backwards to fetch the HIR for the last
15481553
// explicitly assigned discriminant, and letting the user know that this was the
1549-
// increment startpoint, and how many steps from there leading to the duplicate
1554+
// increment startpoint, and how many steps from there leading to the duplicate.
15501555
if let Some(explicit_idx) =
15511556
idx.as_u32().checked_sub(distance_to_explicit).map(VariantIdx::from_u32)
15521557
{
@@ -1657,11 +1662,12 @@ fn check_type_alias_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalD
16571662
None
16581663
}
16591664
})
1660-
// FIXME: This assumes that elaborated `Sized` bounds come first (which does hold at the
1661-
// time of writing). This is a bit fragile since we later use the span to detect elaborated
1662-
// `Sized` bounds. If they came last for example, this would break `Trait + /*elab*/Sized`
1663-
// since it would overwrite the span of the user-written bound. This could be fixed by
1664-
// folding the spans with `Span::to` which requires a bit of effort I think.
1665+
// FIXME: This assumes that elaborated `Sized` bounds come first (which does hold at
1666+
// the time of writing). This is a bit fragile since we later use the span to detect
1667+
// elaborated `Sized` bounds. If they came last for example, this would break `Trait +
1668+
// /*elab*/Sized` since it would overwrite the span of the user-written bound. This
1669+
// could be fixed by folding the spans with `Span::to` which requires a bit of effort I
1670+
// think.
16651671
.collect::<FxIndexMap<_, _>>()
16661672
});
16671673

Diff for: compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ fn compare_method_predicate_entailment<'tcx>(
388388
match obligation.predicate.kind().skip_binder() {
389389
// We need to register Projection oblgiations too, because we may end up with
390390
// an implied `X::Item: 'a`, which gets desugared into `X::Item = ?0`, `?0: 'a`.
391-
// If we only register the region outlives obligation, this leads to an unconstrained var.
392-
// See `implied_bounds_entailment_alias_var.rs` test.
391+
// If we only register the region outlives obligation, this leads to an
392+
// unconstrained var. See `implied_bounds_entailment_alias_var.rs` test.
393393
ty::PredicateKind::Clause(
394394
ty::ClauseKind::RegionOutlives(..)
395395
| ty::ClauseKind::TypeOutlives(..)
@@ -673,10 +673,10 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
673673
match ocx.eq(&cause, param_env, trait_sig, impl_sig) {
674674
Ok(()) => {}
675675
Err(terr) => {
676-
// This function gets called during `compare_method_predicate_entailment` when normalizing a
677-
// signature that contains RPITIT. When the method signatures don't match, we have to
678-
// emit an error now because `compare_method_predicate_entailment` will not report the error
679-
// when normalization fails.
676+
// This function gets called during `compare_method_predicate_entailment` when
677+
// normalizing a signature that contains RPITIT. When the method signatures don't
678+
// match, we have to emit an error now because `compare_method_predicate_entailment`
679+
// will not report the error when normalization fails.
680680
let emitted = report_trait_method_mismatch(
681681
infcx,
682682
cause,

Diff for: compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
101101
if !tcx.hir().get_if_local(impl_opaque.def_id).is_some_and(|node| {
102102
matches!(
103103
node.expect_opaque_ty().origin,
104-
hir::OpaqueTyOrigin::AsyncFn { parent, .. } | hir::OpaqueTyOrigin::FnReturn { parent, .. }
104+
hir::OpaqueTyOrigin::AsyncFn { parent, .. } | hir::OpaqueTyOrigin::FnReturn { parent, .. }
105105
if parent == impl_m.def_id.expect_local()
106106
)
107107
}) {

Diff for: compiler/rustc_hir_analysis/src/check/wfcheck.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ where
127127

128128
let infcx_compat = infcx.fork();
129129

130-
// We specifically want to call the non-compat version of `implied_bounds_tys`; we do this always.
130+
// We specifically want to call the non-compat version of `implied_bounds_tys`; we do this
131+
// always.
131132
let implied_bounds =
132133
infcx.implied_bounds_tys_compat(param_env, body_def_id, &assumed_wf_types, false);
133134
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);
@@ -323,8 +324,8 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
323324
hir::ItemKind::ForeignMod { .. } => Ok(()),
324325
hir::ItemKind::TyAlias(hir_ty, hir_generics) => {
325326
if tcx.type_alias_is_lazy(item.owner_id) {
326-
// Bounds of lazy type aliases and of eager ones that contain opaque types are respected.
327-
// E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`.
327+
// Bounds of lazy type aliases and of eager ones that contain opaque types are
328+
// respected. E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`.
328329
let res = check_item_type(tcx, def_id, hir_ty.span, UnsizedHandling::Allow);
329330
check_variances_for_type_defn(tcx, item, hir_generics);
330331
res
@@ -448,7 +449,8 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, trait_def_id: LocalDefId) {
448449
ty::AssocKind::Fn => {
449450
// For methods, we check the function signature's return type for any GATs
450451
// to constrain. In the `into_iter` case, we see that the return type
451-
// `Self::Iter<'a>` is a GAT we want to gather any potential missing bounds from.
452+
// `Self::Iter<'a>` is a GAT we want to gather any potential missing bounds
453+
// from.
452454
let sig: ty::FnSig<'_> = tcx.liberate_late_bound_regions(
453455
item_def_id.to_def_id(),
454456
tcx.fn_sig(item_def_id).instantiate_identity(),
@@ -1007,7 +1009,8 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
10071009
// `&mut` are not supported.
10081010
ty::Ref(_, ty, ast::Mutability::Not) => ty_is_local(*ty),
10091011
// Say that a tuple is local if any of its components are local.
1010-
// This is not strictly correct, but it's likely that the user can fix the local component.
1012+
// This is not strictly correct, but it's likely that the user can
1013+
// fix the local component.
10111014
ty::Tuple(tys) => tys.iter().any(|ty| ty_is_local(ty)),
10121015
_ => false,
10131016
}
@@ -1350,8 +1353,8 @@ fn check_impl<'tcx>(
13501353
// therefore don't need to be WF (the trait's `Self: Trait` predicate
13511354
// won't hold).
13521355
let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap().instantiate_identity();
1353-
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
1354-
// other `Foo` impls are incoherent.
1356+
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in
1357+
// case other `Foo` impls are incoherent.
13551358
tcx.ensure().coherent_trait(trait_ref.def_id)?;
13561359
let trait_span = hir_trait_ref.path.span;
13571360
let trait_ref = wfcx.normalize(
@@ -1825,7 +1828,8 @@ fn receiver_is_valid<'tcx>(
18251828
let cause =
18261829
ObligationCause::new(span, wfcx.body_def_id, traits::ObligationCauseCode::MethodReceiver);
18271830

1828-
// Special case `receiver == self_ty`, which doesn't necessarily require the `Receiver` lang item.
1831+
// Special case `receiver == self_ty`, which doesn't necessarily require the `Receiver` lang
1832+
// item.
18291833
if let Ok(()) = wfcx.infcx.commit_if_ok(|_| {
18301834
let ocx = ObligationCtxt::new(wfcx.infcx);
18311835
ocx.eq(&cause, wfcx.param_env, self_ty, receiver_ty)?;
@@ -1845,7 +1849,8 @@ fn receiver_is_valid<'tcx>(
18451849
autoderef = autoderef.use_receiver_trait();
18461850
}
18471851

1848-
// The `arbitrary_self_types_pointers` feature allows raw pointer receivers like `self: *const Self`.
1852+
// The `arbitrary_self_types_pointers` feature allows raw pointer receivers like `self: *const
1853+
// Self`.
18491854
if arbitrary_self_types_enabled == Some(ArbitrarySelfTypesLevel::WithPointers) {
18501855
autoderef = autoderef.include_raw_pointers();
18511856
}

Diff for: compiler/rustc_hir_analysis/src/coherence/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ pub(crate) fn provide(providers: &mut Providers) {
146146
}
147147

148148
fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Result<(), ErrorGuaranteed> {
149-
// If there are no impls for the trait, then "all impls" are trivially coherent and we won't check anything
150-
// anyway. Thus we bail out even before the specialization graph, avoiding the dep_graph edge.
149+
// If there are no impls for the trait, then "all impls" are trivially coherent and we won't
150+
// check anything anyway. Thus we bail out even before the specialization graph, avoiding the
151+
// dep_graph edge.
151152
let Some(impls) = tcx.all_local_trait_impls(()).get(&def_id) else { return Ok(()) };
152153
// Trigger building the specialization graph for the trait. This will detect and report any
153154
// overlap errors.

Diff for: compiler/rustc_hir_analysis/src/coherence/orphan.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ pub(crate) fn orphan_check_impl(
201201
// }
202202
// impl<T: ?Sized> AutoTrait for S<T>::This {}
203203
// ```
204-
// FIXME(inherent_associated_types): The example code above currently leads to a cycle
204+
// FIXME(inherent_associated_types): The example code above currently leads to
205+
// a cycle.
205206
ty::Inherent => "associated type",
206207
};
207208
(LocalImpl::Disallow { problematic_kind }, NonlocalImpl::DisallowOther)

Diff for: compiler/rustc_hir_analysis/src/collect/generics_of.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
105105
}
106106

107107
if in_param_ty {
108-
// We do not allow generic parameters in anon consts if we are inside
109-
// of a const parameter type, e.g. `struct Foo<const N: usize, const M: [u8; N]>` is not allowed.
108+
// We do not allow generic parameters in anon consts if we are inside of a const
109+
// parameter type, e.g. `struct Foo<const N: usize, const M: [u8; N]>` is not
110+
// allowed.
110111
None
111112
} else if tcx.features().generic_const_exprs() {
112113
let parent_node = tcx.parent_hir_node(hir_id);
@@ -126,23 +127,27 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
126127
// ^ ^ param_id
127128
// ^ parent_def_id
128129
//
129-
// then we only want to return generics for params to the left of `N`. If we don't do that we
130-
// end up with that const looking like: `ty::ConstKind::Unevaluated(def_id, args: [N#0])`.
130+
// then we only want to return generics for params to the left of `N`. If we
131+
// don't do that we end up with that const looking like:
132+
// `ty::ConstKind::Unevaluated(def_id, args: [N#0])`.
131133
//
132-
// This causes ICEs (#86580) when building the args for Foo in `fn foo() -> Foo { .. }` as
133-
// we instantiate the defaults with the partially built args when we build the args. Instantiating
134-
// the `N#0` on the unevaluated const indexes into the empty args we're in the process of building.
134+
// This causes ICEs (#86580) when building the args for Foo in `fn foo() -> Foo
135+
// { .. }` as we instantiate the defaults with the partially built args when we
136+
// build the args. Instantiating the `N#0` on the unevaluated const indexes
137+
// into the empty args we're in the process of building.
135138
//
136-
// We fix this by having this function return the parent's generics ourselves and truncating the
137-
// generics to only include non-forward declared params (with the exception of the `Self` ty)
139+
// We fix this by having this function return the parent's generics ourselves
140+
// and truncating the generics to only include non-forward declared params
141+
// (with the exception of the `Self` ty)
142+
//
143+
// For the above code example that means we want `args: []`.
144+
// For the following struct def we want `args: [N#0]` when generics_of is
145+
// called on the def id of the `{ N + 1 }` anon const
138146
//
139-
// For the above code example that means we want `args: []`
140-
// For the following struct def we want `args: [N#0]` when generics_of is called on
141-
// the def id of the `{ N + 1 }` anon const
142147
// struct Foo<const N: usize, const M: usize = { N + 1 }>;
143148
//
144-
// This has some implications for how we get the predicates available to the anon const
145-
// see `explicit_predicates_of` for more information on this
149+
// This has some implications for how we get the predicates available to the
150+
// anon const see `explicit_predicates_of` for more information on this.
146151
let generics = tcx.generics_of(parent_did);
147152
let param_def_idx = generics.param_def_id_to_index[&param_id.to_def_id()];
148153
// In the above example this would be .params[..N#0]
@@ -152,8 +157,8 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
152157

153158
return ty::Generics {
154159
// we set the parent of these generics to be our parent's parent so that we
155-
// dont end up with args: [N, M, N] for the const default on a struct like this:
156-
// struct Foo<const N: usize, const M: usize = { ... }>;
160+
// dont end up with args: [N, M, N] for the const default on a struct like
161+
// this: struct Foo<const N: usize, const M: usize = { ... }>;
157162
parent: generics.parent,
158163
parent_count: generics.parent_count,
159164
own_params,

0 commit comments

Comments
 (0)