rust/xtask/src
bors[bot] 95e8766db6
Merge #4178
4178: Validate the location of `crate` in paths r=matklad a=djrenren

**This solution does not fully handle `use` statements. See below**

This pull requests implements simple validation of usages of the `crate` keyword in `Path`s. Specifically it validates that:

- If a `PathSegment` is starts with the `crate` keyword, it is also the first segment of the `Path`
- All other usages of `crate` in `Path`s are considered errors.

This aligns with `rustc`'s rules. Unlike rustc this implementation does not issue a special error message in the case of `::crate` but it does catch the error.

Furthermore, this change does not cover all error cases. Specifically the following is not caught:

```rust
use foo::{crate}
```

This is because this check is context sensitive. From an AST perspective, `crate` is the root of the `Path`. Only by inspecting the full `UseItem` do we see that it is not in fact the root. This problem becomes worse because `UseTree`s are allowed to be arbitrarily nested:

```rust
use {crate, {{crate, foo::{crate}}}
```

So this is a hard problem to solve without essentially a breadth-first search. In a traditional compiler, I'd say this error is most easily found during the AST -> HIR conversion pass but within rust-analyzer I'm not sure where it belongs.  

Under the implementation in this PR, such errors are ignored so we're *more correct* just not *entirely correct*. 

Co-authored-by: John Renner <john@jrenner.net>
2020-04-30 10:17:40 +00:00
..
codegen Group generated ast boilerplate apart from the interesting part 2020-04-18 23:51:13 +03:00
ast_src.rs Validate the location of crate in paths 2020-04-29 11:06:51 -07:00
codegen.rs Refucktor codegen 2020-04-18 21:46:24 +03:00
dist.rs Use x86_64-unknown-linux-gnu for releases 2020-04-28 20:47:13 +03:00
install.rs Bump required rust to 1.43 2020-04-23 11:56:32 -04:00
lib.rs More compact generated code 2020-04-09 18:07:16 +02:00
main.rs Don't strip nightly releases 2020-04-08 11:47:40 +02:00
not_bash.rs Don't strip nightly releases 2020-04-08 11:47:40 +02:00
pre_commit.rs Replace Cmd with not-bash 2020-02-14 16:47:09 +01:00