Skip to content

Commit c904698

Browse files
committed
[comment fixes]
1 parent 8d39ec1 commit c904698

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
@@ -407,7 +407,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
407407
let bound_vars = tcx.late_bound_vars(binding.hir_id);
408408
ty::Binder::bind_with_vars(subst_output, bound_vars)
409409
} else {
410-
// Append the generic arguments of the associated type to the `trait_ref`.
410+
// Append the generic arguments of the associated type or const to the `trait_ref`.
411411
candidate.map_bound(|trait_ref| {
412412
let ident = Ident::new(assoc_item.name, binding.item_name.span);
413413
let item_segment = hir::PathSegment {
@@ -418,19 +418,24 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
418418
infer_args: false,
419419
};
420420

421-
let args_trait_ref_and_assoc_item = self.create_args_for_associated_item(
421+
let alias_args = self.create_args_for_associated_item(
422422
path_span,
423423
assoc_item.def_id,
424424
&item_segment,
425425
trait_ref.args,
426426
);
427+
debug!(?alias_args);
427428

428-
debug!(?args_trait_ref_and_assoc_item);
429-
430-
ty::AliasTy::new(tcx, assoc_item.def_id, args_trait_ref_and_assoc_item)
429+
// Note that we're indeed also using `AliasTy` (alias *type*) for associated
430+
// *constants* to represent *const projections*. Alias *term* would be a more
431+
// appropriate name but alas.
432+
ty::AliasTy::new(tcx, assoc_item.def_id, alias_args)
431433
})
432434
};
433435

436+
// FIXME(fmease): This doesn't check actually seem to work for assoc consts.
437+
// We want to deny escaping late-bound vars in general anyways for assoc consts.
438+
// If the diagnostic *is* reachable, update it (“type” → “term” or similar).
434439
if !speculative {
435440
// Find any late-bound regions declared in `ty` that are not
436441
// declared in the trait-ref or assoc_item. These are not well-formed.
@@ -439,20 +444,20 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
439444
//
440445
// for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
441446
// for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
442-
if let ConvertedBindingKind::Equality(ty) = binding.kind {
443-
let late_bound_in_trait_ref =
447+
if let ConvertedBindingKind::Equality(term) = binding.kind {
448+
let late_bound_in_projection_ty =
444449
tcx.collect_constrained_late_bound_regions(&projection_ty);
445-
let late_bound_in_ty =
446-
tcx.collect_referenced_late_bound_regions(&trait_ref.rebind(ty.node));
447-
debug!(?late_bound_in_trait_ref);
448-
debug!(?late_bound_in_ty);
450+
let late_bound_in_term =
451+
tcx.collect_referenced_late_bound_regions(&trait_ref.rebind(term.node));
452+
debug!(?late_bound_in_projection_ty);
453+
debug!(?late_bound_in_term);
449454

450455
// FIXME: point at the type params that don't have appropriate lifetimes:
451456
// struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
452457
// ---- ---- ^^^^^^^
453458
self.validate_late_bound_regions(
454-
late_bound_in_trait_ref,
455-
late_bound_in_ty,
459+
late_bound_in_projection_ty,
460+
late_bound_in_term,
456461
|br_name| {
457462
struct_span_err!(
458463
tcx.dcx(),

compiler/rustc_hir_analysis/src/astconv/errors.rs

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

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

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

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

0 commit comments

Comments
 (0)