1
Fork 0

Fix issue with path segment lowering with const args

This commit is contained in:
varkor 2019-06-07 00:21:16 +01:00
parent 7bb0a16ad7
commit f11e6f7fa7

View file

@ -2230,9 +2230,9 @@ impl<'a> LoweringContext<'a> {
.collect(); .collect();
if expected_lifetimes > 0 && param_mode == ParamMode::Explicit { if expected_lifetimes > 0 && param_mode == ParamMode::Explicit {
let anon_lt_suggestion = vec!["'_"; expected_lifetimes].join(", "); let anon_lt_suggestion = vec!["'_"; expected_lifetimes].join(", ");
let no_ty_args = generic_args.args.len() == expected_lifetimes; let no_non_lt_args = generic_args.args.len() == expected_lifetimes;
let no_bindings = generic_args.bindings.is_empty(); let no_bindings = generic_args.bindings.is_empty();
let (incl_angl_brckt, insertion_span, suggestion) = if no_ty_args && no_bindings { let (incl_angl_brckt, insertion_sp, suggestion) = if no_non_lt_args && no_bindings {
// If there are no (non-implicit) generic args or associated type // If there are no (non-implicit) generic args or associated type
// bindings, our suggestion includes the angle brackets. // bindings, our suggestion includes the angle brackets.
(true, path_span.shrink_to_hi(), format!("<{}>", anon_lt_suggestion)) (true, path_span.shrink_to_hi(), format!("<{}>", anon_lt_suggestion))
@ -2240,7 +2240,7 @@ impl<'a> LoweringContext<'a> {
// Otherwise (sorry, this is kind of gross) we need to infer the // Otherwise (sorry, this is kind of gross) we need to infer the
// place to splice in the `'_, ` from the generics that do exist. // place to splice in the `'_, ` from the generics that do exist.
let first_generic_span = first_generic_span let first_generic_span = first_generic_span
.expect("already checked that type args or bindings exist"); .expect("already checked that non-lifetime args or bindings exist");
(false, first_generic_span.shrink_to_lo(), format!("{}, ", anon_lt_suggestion)) (false, first_generic_span.shrink_to_lo(), format!("{}, ", anon_lt_suggestion))
}; };
match self.anonymous_lifetime_mode { match self.anonymous_lifetime_mode {
@ -2263,7 +2263,7 @@ impl<'a> LoweringContext<'a> {
expected_lifetimes, expected_lifetimes,
path_span, path_span,
incl_angl_brckt, incl_angl_brckt,
insertion_span, insertion_sp,
suggestion, suggestion,
); );
err.emit(); err.emit();
@ -2280,7 +2280,7 @@ impl<'a> LoweringContext<'a> {
expected_lifetimes, expected_lifetimes,
path_span, path_span,
incl_angl_brckt, incl_angl_brckt,
insertion_span, insertion_sp,
suggestion, suggestion,
) )
); );
@ -2316,9 +2316,10 @@ impl<'a> LoweringContext<'a> {
mut itctx: ImplTraitContext<'_>, mut itctx: ImplTraitContext<'_>,
) -> (hir::GenericArgs, bool) { ) -> (hir::GenericArgs, bool) {
let &AngleBracketedArgs { ref args, ref constraints, .. } = data; let &AngleBracketedArgs { ref args, ref constraints, .. } = data;
let has_types = args.iter().any(|arg| match arg { let has_non_lt_args = args.iter().any(|arg| match arg {
ast::GenericArg::Lifetime(_) => false,
ast::GenericArg::Type(_) => true, ast::GenericArg::Type(_) => true,
_ => false, ast::GenericArg::Const(_) => true,
}); });
( (
hir::GenericArgs { hir::GenericArgs {
@ -2328,7 +2329,7 @@ impl<'a> LoweringContext<'a> {
.collect(), .collect(),
parenthesized: false, parenthesized: false,
}, },
!has_types && param_mode == ParamMode::Optional !has_non_lt_args && param_mode == ParamMode::Optional
) )
} }