Skip to content

Commit ba512c4

Browse files
committed
Update comments and variable names
1 parent e927184 commit ba512c4

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

compiler/rustc_hir_analysis/src/astconv/bounds.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
415415
let bound_vars = tcx.late_bound_vars(binding.hir_id);
416416
ty::Binder::bind_with_vars(subst_output, bound_vars)
417417
} else {
418-
// Append the generic arguments of the associated type to the `trait_ref`.
418+
// Create the generic arguments for the associated type or constant by joining the
419+
// parent arguments (the arguments of the trait) and the own arguments (the ones of
420+
// the associated item itself) and construct an alias type using them.
419421
candidate.map_bound(|trait_ref| {
420422
let ident = Ident::new(assoc_item.name, binding.item_name.span);
421423
let item_segment = hir::PathSegment {
@@ -426,19 +428,22 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
426428
infer_args: false,
427429
};
428430

429-
let args_trait_ref_and_assoc_item = self.create_args_for_associated_item(
431+
let alias_args = self.create_args_for_associated_item(
430432
path_span,
431433
assoc_item.def_id,
432434
&item_segment,
433435
trait_ref.args,
434436
);
437+
debug!(?alias_args);
435438

436-
debug!(?args_trait_ref_and_assoc_item);
437-
438-
ty::AliasTy::new(tcx, assoc_item.def_id, args_trait_ref_and_assoc_item)
439+
// Note that we're indeed also using `AliasTy` (alias *type*) for associated
440+
// *constants* to represent *const projections*. Alias *term* would be a more
441+
// appropriate name but alas.
442+
ty::AliasTy::new(tcx, assoc_item.def_id, alias_args)
439443
})
440444
};
441445

446+
// FIXME(associated_const_equality): Can this actually ever fail with assoc consts?
442447
if !speculative {
443448
// Find any late-bound regions declared in `ty` that are not
444449
// declared in the trait-ref or assoc_item. These are not well-formed.
@@ -447,20 +452,20 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
447452
//
448453
// for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
449454
// for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
450-
if let ConvertedBindingKind::Equality(ty) = binding.kind {
451-
let late_bound_in_trait_ref =
455+
if let ConvertedBindingKind::Equality(term) = binding.kind {
456+
let late_bound_in_projection_ty =
452457
tcx.collect_constrained_late_bound_regions(&projection_ty);
453-
let late_bound_in_ty =
454-
tcx.collect_referenced_late_bound_regions(&trait_ref.rebind(ty.node));
455-
debug!(?late_bound_in_trait_ref);
456-
debug!(?late_bound_in_ty);
458+
let late_bound_in_term =
459+
tcx.collect_referenced_late_bound_regions(&trait_ref.rebind(term.node));
460+
debug!(?late_bound_in_projection_ty);
461+
debug!(?late_bound_in_term);
457462

458463
// FIXME: point at the type params that don't have appropriate lifetimes:
459464
// struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
460465
// ---- ---- ^^^^^^^
461466
self.validate_late_bound_regions(
462-
late_bound_in_trait_ref,
463-
late_bound_in_ty,
467+
late_bound_in_projection_ty,
468+
late_bound_in_term,
464469
|br_name| {
465470
struct_span_err!(
466471
tcx.dcx(),

compiler/rustc_hir_analysis/src/astconv/errors.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
239239
None,
240240
) && suggested_name != assoc_name.name
241241
{
242-
// We suggested constraining a type parameter, but the associated type on it
242+
// We suggested constraining a type parameter, but the associated item on it
243243
// was also not an exact match, so we also suggest changing it.
244244
err.span_suggestion_verbose(
245245
assoc_name.span,
@@ -254,16 +254,17 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
254254
}
255255
}
256256

257-
// If we still couldn't find any associated type, and only one associated type exists,
257+
// If we still couldn't find any associated item, and only one associated item exists,
258258
// suggests using it.
259259
if let [candidate_name] = all_candidate_names.as_slice() {
260-
// this should still compile, except on `#![feature(associated_type_defaults)]`
261-
// where it could suggests `type A = Self::A`, thus recursing infinitely
262-
let applicability = if tcx.features().associated_type_defaults {
263-
Applicability::Unspecified
264-
} else {
265-
Applicability::MaybeIncorrect
266-
};
260+
// This should still compile, except on `#![feature(associated_type_defaults)]`
261+
// where it could suggests `type A = Self::A`, thus recursing infinitely.
262+
let applicability =
263+
if assoc_kind == ty::AssocKind::Type && tcx.features().associated_type_defaults {
264+
Applicability::Unspecified
265+
} else {
266+
Applicability::MaybeIncorrect
267+
};
267268

268269
err.sugg = Some(errors::AssocItemNotFoundSugg::Other {
269270
span: assoc_name.span,
@@ -319,7 +320,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
319320
};
320321

321322
// For equality bounds, we want to blame the term (RHS) instead of the item (LHS) since
322-
// one can argue that that's more “untuitive” to the user.
323+
// one can argue that that's more “intuitive” to the user.
323324
let (span, expected_because_label, expected, got) = if let Some(binding) = binding
324325
&& let ConvertedBindingKind::Equality(term) = binding.kind
325326
{

0 commit comments

Comments
 (0)