Skip to content
Draft
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion src/lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#![feature(deref_patterns)]
#![feature(derive_const)]
#![feature(gen_blocks)]
#![feature(generic_const_items)]
#![feature(import_trait_associated_functions)]
#![feature(macro_metavar_expr)]
#![feature(mut_ref)]
Expand Down
12 changes: 8 additions & 4 deletions src/lib/parser/test/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,18 @@ fn bare_trait_object_tys() {
Ok(ast::Ty::DynTrait(ast::DynKind::Bare, [ast::Bound::Use(_)]))
);

// Indeed, even though you can't parenthesize precise-capturing lists
// in "normal" bounds, you can do so in bare trait object type bounds.
// If find it a bit janky. Might report upstream.
// Context: <https://github.com/rust-lang/rust/pull/162652>
t!(
parse_ty,
Rust2015,
"(use<>)+",
Ok(ast::Ty::DynTrait(ast::DynKind::Bare, [ast::Bound::Use(_)]))
Err([Error {
kind: ErrorKind::UnexpectedToken(
TokenKind::SinglePlus,
[Fragment::Token(TokenKind::EndOfInput)],
),
..
}])
);

// It's easy to accidentally accept the following code while trying to support the form above.
Expand Down
31 changes: 11 additions & 20 deletions src/lib/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,31 +302,22 @@ impl<'src> super::Parser<'_, '_, 'src> {
inner_ty: &mut ast::Ty<'src>,
p_policy: PlusPolicy,
) -> Result<Option<ast::Ty<'src>>> {
const EMPTY<'src>: ast::Path<'src, ast::UnambiguousGenericArgs> =
ast::Path { segs: Vec::new() };

let bound = match inner_ty {
let mut bounds = vec![match inner_ty {
ast::Ty::Path(ast::ExtPath { ext: None, path }) => {
ast::Bound::from(mem::replace(path, EMPTY))
}
ast::Ty::DynTrait(ast::DynKind::Bare, [bound]) => {
match bound {
ast::Bound::Outlives(_) => return Ok(None),
// NOTE: I'm not happy about this since use-bounds can't be parenthesized "normally".
ast::Bound::Use(captures) => ast::Bound::Use(mem::take(captures)),
ast::Bound::Trait { bound_vars, modifiers, path } => ast::Bound::Trait {
bound_vars: mem::take(bound_vars),
modifiers: *modifiers,
path: mem::replace(path, EMPTY),
},
}
ast::Bound::from(mem::replace(path, ast::Path { segs: Vec::new() }))
}
ast::Ty::DynTrait(
ast::DynKind::Bare,
[ast::Bound::Trait { bound_vars, modifiers, path }],
) => ast::Bound::Trait {
bound_vars: mem::take(bound_vars),
modifiers: *modifiers,
path: mem::replace(path, ast::Path { segs: Vec::new() }),
},
_ => return Ok(None),
};
}];

self.parse_unchecked(TokenPrefix::Plus);

let mut bounds = vec![bound];
self.parse_bounds_into(p_policy.maintain(), &mut bounds)?;

Ok(Some(ast::Ty::DynTrait(ast::DynKind::Bare, bounds)))
Expand Down