Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify dyn/impl parsing enabled by Punctuated improvements #1248

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,24 +925,20 @@ pub mod parsing {
) -> Result<Punctuated<TypeParamBound, Token![+]>> {
let bounds = TypeParamBound::parse_multiple(input, allow_plus)?;
let mut last_lifetime_span = None;
let mut at_least_one_trait = false;
for bound in &bounds {
match bound {
TypeParamBound::Trait(_) => {
at_least_one_trait = true;
break;
}
TypeParamBound::Trait(_) => return Ok(bounds),
TypeParamBound::Lifetime(lifetime) => {
last_lifetime_span = Some(lifetime.ident.span());
}
}
}
// Just lifetimes like `'a + 'b` is not a TraitObject.
if !at_least_one_trait {
let msg = "at least one trait is required for an object type";
return Err(error::new2(dyn_span, last_lifetime_span.unwrap(), msg));
}
Ok(bounds)
Err(error::new2(
dyn_span,
last_lifetime_span.unwrap(),
"at least one trait is required for an object type",
))
}
}

Expand All @@ -965,27 +961,19 @@ pub mod parsing {
let impl_token: Token![impl] = input.parse()?;
let bounds = TypeParamBound::parse_multiple(input, allow_plus)?;
let mut last_lifetime_span = None;
let mut at_least_one_trait = false;
for bound in &bounds {
match bound {
TypeParamBound::Trait(_) => {
at_least_one_trait = true;
break;
}
TypeParamBound::Trait(_) => return Ok(TypeImplTrait { impl_token, bounds }),
TypeParamBound::Lifetime(lifetime) => {
last_lifetime_span = Some(lifetime.ident.span());
}
}
}
if !at_least_one_trait {
let msg = "at least one trait must be specified";
return Err(error::new2(
impl_token.span,
last_lifetime_span.unwrap(),
msg,
));
}
Ok(TypeImplTrait { impl_token, bounds })
Err(error::new2(
impl_token.span,
last_lifetime_span.unwrap(),
"at least one trait must be specified",
))
}
}

Expand Down