Update comments and variable names
This commit is contained in:
parent
405b22f1a3
commit
f62a695572
2 changed files with 39 additions and 34 deletions
|
@ -390,14 +390,12 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
{
|
{
|
||||||
alias_ty
|
alias_ty
|
||||||
} else {
|
} else {
|
||||||
return Err(self.tcx().dcx().emit_err(
|
return Err(tcx.dcx().emit_err(crate::errors::ReturnTypeNotationOnNonRpitit {
|
||||||
crate::errors::ReturnTypeNotationOnNonRpitit {
|
span: binding.span,
|
||||||
span: binding.span,
|
ty: tcx.liberate_late_bound_regions(assoc_item.def_id, output),
|
||||||
ty: tcx.liberate_late_bound_regions(assoc_item.def_id, output),
|
fn_span: tcx.hir().span_if_local(assoc_item.def_id),
|
||||||
fn_span: tcx.hir().span_if_local(assoc_item.def_id),
|
note: (),
|
||||||
note: (),
|
}));
|
||||||
},
|
|
||||||
));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Finally, move the fn return type's bound vars over to account for the early bound
|
// 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> + '_ {
|
||||||
let bound_vars = tcx.late_bound_vars(binding.hir_id);
|
let bound_vars = tcx.late_bound_vars(binding.hir_id);
|
||||||
ty::Binder::bind_with_vars(instantiation_output, bound_vars)
|
ty::Binder::bind_with_vars(instantiation_output, bound_vars)
|
||||||
} else {
|
} else {
|
||||||
// Append the generic arguments of the associated type to the `trait_ref`.
|
// Create the generic arguments for the associated type or constant by joining the
|
||||||
|
// parent arguments (the arguments of the trait) and the own arguments (the ones of
|
||||||
|
// the associated item itself) and construct an alias type using them.
|
||||||
candidate.map_bound(|trait_ref| {
|
candidate.map_bound(|trait_ref| {
|
||||||
let ident = Ident::new(assoc_item.name, binding.item_name.span);
|
let ident = Ident::new(assoc_item.name, binding.item_name.span);
|
||||||
let item_segment = hir::PathSegment {
|
let item_segment = hir::PathSegment {
|
||||||
|
@ -421,16 +421,18 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
infer_args: false,
|
infer_args: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let args_trait_ref_and_assoc_item = self.create_args_for_associated_item(
|
let alias_args = self.create_args_for_associated_item(
|
||||||
path_span,
|
path_span,
|
||||||
assoc_item.def_id,
|
assoc_item.def_id,
|
||||||
&item_segment,
|
&item_segment,
|
||||||
trait_ref.args,
|
trait_ref.args,
|
||||||
);
|
);
|
||||||
|
debug!(?alias_args);
|
||||||
|
|
||||||
debug!(?args_trait_ref_and_assoc_item);
|
// Note that we're indeed also using `AliasTy` (alias *type*) for associated
|
||||||
|
// *constants* to represent *const projections*. Alias *term* would be a more
|
||||||
ty::AliasTy::new(tcx, assoc_item.def_id, args_trait_ref_and_assoc_item)
|
// appropriate name but alas.
|
||||||
|
ty::AliasTy::new(tcx, assoc_item.def_id, alias_args)
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -442,20 +444,22 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
//
|
//
|
||||||
// for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
|
// for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
|
||||||
// for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
|
// for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
|
||||||
if let ConvertedBindingKind::Equality(ty) = binding.kind {
|
if let ConvertedBindingKind::Equality(term) = binding.kind {
|
||||||
let late_bound_in_trait_ref =
|
let late_bound_in_projection_ty =
|
||||||
tcx.collect_constrained_late_bound_regions(&projection_ty);
|
tcx.collect_constrained_late_bound_regions(&projection_ty);
|
||||||
let late_bound_in_ty =
|
let late_bound_in_term =
|
||||||
tcx.collect_referenced_late_bound_regions(&trait_ref.rebind(ty.node));
|
tcx.collect_referenced_late_bound_regions(&trait_ref.rebind(term.node));
|
||||||
debug!(?late_bound_in_trait_ref);
|
debug!(?late_bound_in_projection_ty);
|
||||||
debug!(?late_bound_in_ty);
|
debug!(?late_bound_in_term);
|
||||||
|
|
||||||
|
// NOTE(associated_const_equality): This error should be impossible to trigger
|
||||||
|
// with associated const equality bounds.
|
||||||
// FIXME: point at the type params that don't have appropriate lifetimes:
|
// FIXME: point at the type params that don't have appropriate lifetimes:
|
||||||
// struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
|
// struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
|
||||||
// ---- ---- ^^^^^^^
|
// ---- ---- ^^^^^^^
|
||||||
self.validate_late_bound_regions(
|
self.validate_late_bound_regions(
|
||||||
late_bound_in_trait_ref,
|
late_bound_in_projection_ty,
|
||||||
late_bound_in_ty,
|
late_bound_in_term,
|
||||||
|br_name| {
|
|br_name| {
|
||||||
struct_span_code_err!(
|
struct_span_code_err!(
|
||||||
tcx.dcx(),
|
tcx.dcx(),
|
||||||
|
@ -473,9 +477,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
||||||
|
|
||||||
match binding.kind {
|
match binding.kind {
|
||||||
ConvertedBindingKind::Equality(..) if let ty::AssocKind::Fn = assoc_kind => {
|
ConvertedBindingKind::Equality(..) if let ty::AssocKind::Fn = assoc_kind => {
|
||||||
return Err(self.tcx().dcx().emit_err(
|
return Err(tcx.dcx().emit_err(crate::errors::ReturnTypeNotationEqualityBound {
|
||||||
crate::errors::ReturnTypeNotationEqualityBound { span: binding.span },
|
span: binding.span,
|
||||||
));
|
}));
|
||||||
}
|
}
|
||||||
ConvertedBindingKind::Equality(term) => {
|
ConvertedBindingKind::Equality(term) => {
|
||||||
// "Desugar" a constraint like `T: Iterator<Item = u32>` this to
|
// "Desugar" a constraint like `T: Iterator<Item = u32>` this to
|
||||||
|
|
|
@ -243,7 +243,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
None,
|
None,
|
||||||
) && suggested_name != assoc_name.name
|
) && suggested_name != assoc_name.name
|
||||||
{
|
{
|
||||||
// We suggested constraining a type parameter, but the associated type on it
|
// We suggested constraining a type parameter, but the associated item on it
|
||||||
// was also not an exact match, so we also suggest changing it.
|
// was also not an exact match, so we also suggest changing it.
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
assoc_name.span,
|
assoc_name.span,
|
||||||
|
@ -258,16 +258,17 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we still couldn't find any associated type, and only one associated type exists,
|
// If we still couldn't find any associated item, and only one associated item exists,
|
||||||
// suggests using it.
|
// suggests using it.
|
||||||
if let [candidate_name] = all_candidate_names.as_slice() {
|
if let [candidate_name] = all_candidate_names.as_slice() {
|
||||||
// this should still compile, except on `#![feature(associated_type_defaults)]`
|
// This should still compile, except on `#![feature(associated_type_defaults)]`
|
||||||
// where it could suggests `type A = Self::A`, thus recursing infinitely
|
// where it could suggests `type A = Self::A`, thus recursing infinitely.
|
||||||
let applicability = if tcx.features().associated_type_defaults {
|
let applicability =
|
||||||
Applicability::Unspecified
|
if assoc_kind == ty::AssocKind::Type && tcx.features().associated_type_defaults {
|
||||||
} else {
|
Applicability::Unspecified
|
||||||
Applicability::MaybeIncorrect
|
} else {
|
||||||
};
|
Applicability::MaybeIncorrect
|
||||||
|
};
|
||||||
|
|
||||||
err.sugg = Some(errors::AssocItemNotFoundSugg::Other {
|
err.sugg = Some(errors::AssocItemNotFoundSugg::Other {
|
||||||
span: assoc_name.span,
|
span: assoc_name.span,
|
||||||
|
@ -323,7 +324,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
};
|
};
|
||||||
|
|
||||||
// For equality bounds, we want to blame the term (RHS) instead of the item (LHS) since
|
// For equality bounds, we want to blame the term (RHS) instead of the item (LHS) since
|
||||||
// one can argue that that's more “untuitive” to the user.
|
// one can argue that that's more “intuitive” to the user.
|
||||||
let (span, expected_because_label, expected, got) = if let Some(binding) = binding
|
let (span, expected_because_label, expected, got) = if let Some(binding) = binding
|
||||||
&& let ConvertedBindingKind::Equality(term) = binding.kind
|
&& let ConvertedBindingKind::Equality(term) = binding.kind
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue