Skip to content

Commit f62a695

Browse files
committed
Update comments and variable names
1 parent 405b22f commit f62a695

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

compiler/rustc_hir_analysis/src/astconv/bounds.rs

+28-24
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,12 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
390390
{
391391
alias_ty
392392
} else {
393-
return Err(self.tcx().dcx().emit_err(
394-
crate::errors::ReturnTypeNotationOnNonRpitit {
395-
span: binding.span,
396-
ty: tcx.liberate_late_bound_regions(assoc_item.def_id, output),
397-
fn_span: tcx.hir().span_if_local(assoc_item.def_id),
398-
note: (),
399-
},
400-
));
393+
return Err(tcx.dcx().emit_err(crate::errors::ReturnTypeNotationOnNonRpitit {
394+
span: binding.span,
395+
ty: tcx.liberate_late_bound_regions(assoc_item.def_id, output),
396+
fn_span: tcx.hir().span_if_local(assoc_item.def_id),
397+
note: (),
398+
}));
401399
};
402400

403401
// Finally, move the fn return type's bound vars over to account for the early bound
@@ -410,7 +408,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
410408
let bound_vars = tcx.late_bound_vars(binding.hir_id);
411409
ty::Binder::bind_with_vars(instantiation_output, bound_vars)
412410
} else {
413-
// Append the generic arguments of the associated type to the `trait_ref`.
411+
// Create the generic arguments for the associated type or constant by joining the
412+
// parent arguments (the arguments of the trait) and the own arguments (the ones of
413+
// the associated item itself) and construct an alias type using them.
414414
candidate.map_bound(|trait_ref| {
415415
let ident = Ident::new(assoc_item.name, binding.item_name.span);
416416
let item_segment = hir::PathSegment {
@@ -421,16 +421,18 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
421421
infer_args: false,
422422
};
423423

424-
let args_trait_ref_and_assoc_item = self.create_args_for_associated_item(
424+
let alias_args = self.create_args_for_associated_item(
425425
path_span,
426426
assoc_item.def_id,
427427
&item_segment,
428428
trait_ref.args,
429429
);
430+
debug!(?alias_args);
430431

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

@@ -442,20 +444,22 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
442444
//
443445
// for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
444446
// for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
445-
if let ConvertedBindingKind::Equality(ty) = binding.kind {
446-
let late_bound_in_trait_ref =
447+
if let ConvertedBindingKind::Equality(term) = binding.kind {
448+
let late_bound_in_projection_ty =
447449
tcx.collect_constrained_late_bound_regions(&projection_ty);
448-
let late_bound_in_ty =
449-
tcx.collect_referenced_late_bound_regions(&trait_ref.rebind(ty.node));
450-
debug!(?late_bound_in_trait_ref);
451-
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);
452454

455+
// NOTE(associated_const_equality): This error should be impossible to trigger
456+
// with associated const equality bounds.
453457
// FIXME: point at the type params that don't have appropriate lifetimes:
454458
// struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
455459
// ---- ---- ^^^^^^^
456460
self.validate_late_bound_regions(
457-
late_bound_in_trait_ref,
458-
late_bound_in_ty,
461+
late_bound_in_projection_ty,
462+
late_bound_in_term,
459463
|br_name| {
460464
struct_span_code_err!(
461465
tcx.dcx(),
@@ -473,9 +477,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
473477

474478
match binding.kind {
475479
ConvertedBindingKind::Equality(..) if let ty::AssocKind::Fn = assoc_kind => {
476-
return Err(self.tcx().dcx().emit_err(
477-
crate::errors::ReturnTypeNotationEqualityBound { span: binding.span },
478-
));
480+
return Err(tcx.dcx().emit_err(crate::errors::ReturnTypeNotationEqualityBound {
481+
span: binding.span,
482+
}));
479483
}
480484
ConvertedBindingKind::Equality(term) => {
481485
// "Desugar" a constraint like `T: Iterator<Item = u32>` this to

compiler/rustc_hir_analysis/src/astconv/errors.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
243243
None,
244244
) && suggested_name != assoc_name.name
245245
{
246-
// We suggested constraining a type parameter, but the associated type on it
246+
// We suggested constraining a type parameter, but the associated item on it
247247
// was also not an exact match, so we also suggest changing it.
248248
err.span_suggestion_verbose(
249249
assoc_name.span,
@@ -258,16 +258,17 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
258258
}
259259
}
260260

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

272273
err.sugg = Some(errors::AssocItemNotFoundSugg::Other {
273274
span: assoc_name.span,
@@ -323,7 +324,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
323324
};
324325

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

0 commit comments

Comments
 (0)