Tidy the code that checks for type parameters in associated const paths.
This commit is contained in:
parent
6665758614
commit
98f41ff355
1 changed files with 27 additions and 24 deletions
|
|
@ -3763,21 +3763,34 @@ pub fn resolve_ty_and_def_ufcs<'a, 'b, 'tcx>(fcx: &FnCtxt<'b, 'tcx>,
|
|||
&'a [ast::PathSegment],
|
||||
def::Def)>
|
||||
{
|
||||
|
||||
// Associated constants can't depend on generic types.
|
||||
fn have_disallowed_generic_consts<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
def: def::Def,
|
||||
ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
node_id: ast::NodeId) -> bool {
|
||||
match def {
|
||||
def::DefAssociatedConst(..) => {
|
||||
if ty::type_has_params(ty) || ty::type_has_self(ty) {
|
||||
fcx.sess().span_err(span,
|
||||
"Associated consts cannot depend \
|
||||
on type parameters or Self.");
|
||||
fcx.write_error(node_id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
// If fully resolved already, we don't have to do anything.
|
||||
if path_res.depth == 0 {
|
||||
// Associated constants can't depend on generic types.
|
||||
if let Some(ty) = opt_self_ty {
|
||||
match path_res.full_def() {
|
||||
def::DefAssociatedConst(..) => {
|
||||
if ty::type_has_params(ty) || ty::type_has_self(ty) {
|
||||
fcx.sess().span_err(span,
|
||||
"Associated consts cannot depend \
|
||||
on type parameters or Self.");
|
||||
fcx.write_error(node_id);
|
||||
return None;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
if have_disallowed_generic_consts(fcx, path_res.full_def(), ty,
|
||||
span, node_id) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Some((opt_self_ty, &path.segments, path_res.base_def))
|
||||
|
|
@ -3795,18 +3808,8 @@ pub fn resolve_ty_and_def_ufcs<'a, 'b, 'tcx>(fcx: &FnCtxt<'b, 'tcx>,
|
|||
let item_name = item_segment.identifier.name;
|
||||
match method::resolve_ufcs(fcx, span, item_name, ty, node_id) {
|
||||
Ok((def, lp)) => {
|
||||
// Associated constants can't depend on generic types.
|
||||
match def {
|
||||
def::DefAssociatedConst(..) => {
|
||||
if ty::type_has_params(ty) || ty::type_has_self(ty) {
|
||||
fcx.sess().span_err(span,
|
||||
"Associated consts cannot depend \
|
||||
on type parameters or Self.");
|
||||
fcx.write_error(node_id);
|
||||
return None;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
if have_disallowed_generic_consts(fcx, def, ty, span, node_id) {
|
||||
return None;
|
||||
}
|
||||
// Write back the new resolution.
|
||||
fcx.ccx.tcx.def_map.borrow_mut()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue