Skip to content

Commit

Permalink
Parse crate root in nested use-trees
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jun 20, 2023
1 parent ed8dcbd commit 782fd24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
16 changes: 11 additions & 5 deletions src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1340,22 +1340,28 @@ pub(crate) mod parsing {
let content;
let brace_token = braced!(content in input);
let mut items = Punctuated::new();
let mut has_crate_root_in_path = false;
let mut has_any_crate_root_in_path = false;
loop {
if content.is_empty() {
break;
}
has_crate_root_in_path |=
let this_tree_starts_with_crate_root =
allow_crate_root_in_path && content.parse::<Option<Token![::]>>()?.is_some();
let tree: UseTree = content.parse()?;
items.push_value(tree);
has_any_crate_root_in_path |= this_tree_starts_with_crate_root;
match parse_use_tree(
&content,
allow_crate_root_in_path && !this_tree_starts_with_crate_root,
)? {
Some(tree) => items.push_value(tree),
None => has_any_crate_root_in_path = true,
}
if content.is_empty() {
break;
}
let comma: Token![,] = content.parse()?;
items.push_punct(comma);
}
if has_crate_root_in_path {
if has_any_crate_root_in_path {
Ok(None)
} else {
Ok(Some(UseTree::Group(UseGroup { brace_token, items })))
Expand Down
3 changes: 0 additions & 3 deletions tests/repo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ static EXCLUDE_FILES: &[&str] = &[
"tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs",
"tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs",

// TODO: `use {{::{core}}};`
"tests/ui/weird-exprs.rs",

// TODO: non-lifetime binders: `where for<'a, T> &'a Struct<T>: Trait`
// https://github.com/dtolnay/syn/issues/1435
"tests/rustdoc-json/non_lifetime_binders.rs",
Expand Down

0 comments on commit 782fd24

Please sign in to comment.