diff options
| author | Sean Patrick Santos <SeanPatrickSantos@gmail.com> | 2015-05-04 02:33:59 -0600 |
|---|---|---|
| committer | Sean Patrick Santos <SeanPatrickSantos@gmail.com> | 2015-05-17 15:30:32 -0600 |
| commit | 98f41ff3555dba80b47ebee6f6bc8a7df697240c (patch) | |
| tree | e10fe06a9a79a5bec2cc2f0502c123b7df632e05 /src | |
| parent | 666575861405712d302fe32cbe563ced8d98b8ad (diff) | |
| download | rust-98f41ff3555dba80b47ebee6f6bc8a7df697240c.tar.gz rust-98f41ff3555dba80b47ebee6f6bc8a7df697240c.zip | |
Tidy the code that checks for type parameters in associated const paths.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_typeck/check/mod.rs | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 7c270bf4a30..c9ef9351959 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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() |
