Skip to content

Commit

Permalink
Fix issue with path segment lowering with const args
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Jun 7, 2019
1 parent 7bb0a16 commit f11e6f7
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2230,17 +2230,17 @@ impl<'a> LoweringContext<'a> {
.collect();
if expected_lifetimes > 0 && param_mode == ParamMode::Explicit {
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 (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
// bindings, our suggestion includes the angle brackets.
(true, path_span.shrink_to_hi(), format!("<{}>", anon_lt_suggestion))
} else {
// Otherwise (sorry, this is kind of gross) we need to infer the
// place to splice in the `'_, ` from the generics that do exist.
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))
};
match self.anonymous_lifetime_mode {
Expand All @@ -2263,7 +2263,7 @@ impl<'a> LoweringContext<'a> {
expected_lifetimes,
path_span,
incl_angl_brckt,
insertion_span,
insertion_sp,
suggestion,
);
err.emit();
Expand All @@ -2280,7 +2280,7 @@ impl<'a> LoweringContext<'a> {
expected_lifetimes,
path_span,
incl_angl_brckt,
insertion_span,
insertion_sp,
suggestion,
)
);
Expand Down Expand Up @@ -2316,9 +2316,10 @@ impl<'a> LoweringContext<'a> {
mut itctx: ImplTraitContext<'_>,
) -> (hir::GenericArgs, bool) {
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,
_ => false,
ast::GenericArg::Const(_) => true,
});
(
hir::GenericArgs {
Expand All @@ -2328,7 +2329,7 @@ impl<'a> LoweringContext<'a> {
.collect(),
parenthesized: false,
},
!has_types && param_mode == ParamMode::Optional
!has_non_lt_args && param_mode == ParamMode::Optional
)
}

Expand Down

0 comments on commit f11e6f7

Please sign in to comment.