[2/n] rustc_metadata: move is_extern_item to trans.
*This is part of a series ([prev](https://github.com/rust-lang/rust/pull/37400) | [next](https://github.com/rust-lang/rust/pull/37402)) of patches designed to rework rustc into an out-of-order on-demand pipeline model for both better feature support (e.g. [MIR-based](https://github.com/solson/miri) early constant evaluation) and incremental execution of compiler passes (e.g. type-checking), with beneficial consequences to IDE support as well.
If any motivation is unclear, please ask for additional PR description clarifications or code comments.*
<hr>
Minor cleanup missed by #36551: `is_extern_item` is one of, if not the only `CrateStore` method who takes a `TyCtxt` but doesn't produce something cached in it, and such methods are going away.
[1/n] Move the MIR map into the type context.
*This is part of a series ([prev]() | [next](https://github.com/rust-lang/rust/pull/37401)) of patches designed to rework rustc into an out-of-order on-demand pipeline model for both better feature support (e.g. [MIR-based](https://github.com/solson/miri) early constant evaluation) and incremental execution of compiler passes (e.g. type-checking), with beneficial consequences to IDE support as well.
If any motivation is unclear, please ask for additional PR description clarifications or code comments.*
<hr>
The first commit reorganizes the `rustc::mir` module to contain the MIR types directly without an extraneous `repr` module which serves no practical purpose but is rather an eyesore.
The second commit performs the actual move of the MIR map into the type context, for the purposes of future integration with requesting analysis/lowering by-products through `TyCtxt`.
Local `Mir` bodies need to be mutated by passes (hence `RefCell`), and at least one pass (`qualify_consts`) needs simultaneous access to multiple `Mir` bodies (hence arena-allocation).
`Mir` bodies loaded from other crates appear as if immutably borrowed (by `.borrow()`-ing one `Ref` and subsequently "leaking" it) to avoid, at least dynamically, *any* possibility of their local mutation.
One caveat is that lint passes can now snoop at the MIR (helpful) or even mutate it (dangerous).
However, lints are unstable anyway and we can find a way to deal with this in due time.
Future work will result in a tighter API, potentially hiding mutation *completely* outside of MIR passes.
Print out the error when HeapFree failures do occur
cc https://github.com/rust-lang/rust/issues/37395
I'd prefer to use `assert!` instead of `debug_assert!` if the cost is acceptable.
r? @alexcrichton
rustc_typeck: Allow reification from fn item to unsafe ptr
See https://github.com/rust-lang/rfcs/issues/1762.
I've never contributed to the compiler internals before-- apologies if I'm not going about this the right way.
Do not intern filemap to entry w/ mismatched length.
Do not intern filemap to entry w/ mismatched length.
Fix#37274 (I think).
Beta-nominated; note that only the second commit needs to be cherry picked to beta branch. (The first just adds some debug instrumentation that I wish had been present.)
Support for aarch64 architecture on Fuchsia
This patch adds support for the aarch64-unknown-fuchsia target. Also
updates src/liblibc submodule to include required libc change.
Avoid more allocations when compiling html5ever
These three commits reduce the number of allocations performed when compiling html5ever from 13.2M to 10.8M, which speeds up compilation by about 2%.
r? @nrc
Give variant spans used in derives the correct expansion id
This fixes a problem in save-analysis where it mistakes a path to a variant as the variant itself.
r? @petrochenkov
Add semicolon to "Maybe a missing `extern crate foo`" message
I had it a couple of times that I was missing the "extern crate" line
after I introduced a new dependency. So I copied the text from the
message and inserted it into the beginning of my code, only to find the
compiler complaining that I was missing the semicolon. (I forgot to add
it after the text that I had pasted.)
There's a similar message which does include the semicolon, namely
"help: you can import it into scope: `use foo::Bar;`". I think the two
messages should be consistent, so this change adds it for "extern
crate".
Add documentation for Read, Write impls for slices and Vec
The Write imps for &[u8] and Vec<u8> are quite different, and we need this to
be reflected in the docs.
These documentation comments will be visible on the respective type's
page in the trait impls section.
Fix bad error message with `::<` in types
Fix#36116.
Before:
```rust
error: expected identifier, found `<`
--> src/test/compile-fail/issue-36116.rs:16:52
|
16 | let f = Some(Foo { _a: 42 }).map(|a| a as Foo::<i32>);
| ^
error: chained comparison operators require parentheses
--> src/test/compile-fail/issue-36116.rs:16:52
|
16 | let f = Some(Foo { _a: 42 }).map(|a| a as Foo::<i32>);
| ^^^^^^
|
= help: use `::<...>` instead of `<...>` if you meant to specify type arguments
error: expected expression, found `)`
--> src/test/compile-fail/issue-36116.rs:16:57
|
16 | let f = Some(Foo { _a: 42 }).map(|a| a as Foo::<i32>);
| ^
error: expected identifier, found `<`
--> src/test/compile-fail/issue-36116.rs:20:17
|
20 | let g: Foo::<i32> = Foo { _a: 42 };
| ^
error: aborting due to 5 previous errors
```
After:
```rust
error: unexpected token: `::`
--> src/test/compile-fail/issue-36116.rs:16:50
|
16 | let f = Some(Foo { _a: 42 }).map(|a| a as Foo::<i32>);
| ^^
|
= help: use `<...>` instead of `::<...>` if you meant to specify type arguments
error: unexpected token: `::`
--> src/test/compile-fail/issue-36116.rs:20:15
|
20 | let g: Foo::<i32> = Foo { _a: 42 };
| ^^
|
= help: use `<...>` instead of `::<...>` if you meant to specify type arguments
error: aborting due to 2 previous errors
```
tidy/features: fix checking of lang features
r? @brson
See the commit messages - the actual "fixes" here are strawmen; I'm happy to adjust them if you have suggestions.
Split up libproc_macro_plugin
Separate the plugin code from non-plugin code to break a potential cycle in crates.
This will allow us to merge the new libproc_macro_tokens into libproc_macro.
r? @alexcrichton
Removes the `STATUSES` static which duplicates truth from the pattern
match in `collect_lang_features`.
Fixes existing duplicates by renaming:
- never_type{,_impls} on `impl`s on `!`
- concat_idents{,_macro} on `macro_rules! concat_idents`
Fixes#37013.
`git ls-files` now exits zero when called with a missing file; check
that the file is included in the output before reporting a checked-in
binary. Observed with git 2.10.1 and tripped by a symlink created by
tests:
src/test/run-make/issue-26006/out/time/deps/liblibc.rlib -> out/libc/liblibc.rlib
Support `Self` in struct expressions and patterns
Struct expressions and patterns generally support type aliases `Alias { field: 10 }` i.e. they already have to work with `ty::Ty` to do their job. `Self` is a type alias (when it's not a type parameter) => struct expressions and patterns should support `Self`.
Typical example:
```
impl MyStruct {
fn new() -> Self {
Self { a: 10, b: "Hello" }
}
}
```
The first commit does some preparations and cleanups, see the commit message for details.
This also fixes couple of bugs related to aliases in struct paths (fixes https://github.com/rust-lang/rust/issues/36286).
EDIT:
Since struct expressions and patterns always work with `ty::Ty` now, associated paths in them are also supported. If associated type `A::B` successfully resolves to a struct (or union) type, then `A::B { /* fields */ }` is a valid expression/pattern. This will become more important when enum variants are treated as [associated items](https://github.com/rust-lang/rust/issues/26264#issuecomment-250603946).
r? @eddyb
Separate the plugin code from non-plugin code to break a potential cycle in crates.
This will allow us to merge the new libproc_macro_tokens into libproc_macro.
Diagnostics for struct path resolution errors in resolve and typeck are unified.
Self type is treated as a type alias in few places (not reachable yet).
Unsafe cell is seen in constants even through type aliases.
All checks for struct paths in typeck work on type level.
Recover out of an enum or struct's braced block.
If we encounter a syntax error inside of a braced block, then we should
fail by consuming the rest of the block if possible.
This implements such recovery for enums and structs.
Fixes#37113.
The Write impls for &[u8] and Vec<u8> are quite different, and we need this to
be reflected in the docs.
These documentation comments will be visible on the respective type's
page in the trait impls section.
Make sufficiently old or low-impact compatibility lints deny-by-default
Tracking issues are updated/created when necessary.
Needs crater run before proceeding.
r? @nikomatsakis
Implement field shorthands in struct literal expressions.
Implements #37340 in a straight-forward way: `Foo { x, y: f() }` parses as `Foo { x: x, y: f() }`.
Because of the added `is_shorthand` to `ast::Field`, this is `[syntax-breaking]` (cc @Manishearth).
* [x] Mark the fields as being a shorthand (the exact same way we do it in patterns), for pretty-printing.
* [x] Gate the shorthand syntax with `#![feature(field_init_shorthand)]`.
* [x] Don't parse numeric field as identifiers.
* [x] Arbitrary field order tests.
I had it a couple of times that I was missing the "extern crate" line
after I introduced a new dependency. So I copied the text from the
message and inserted it into the beginning of my code, only to find the
compiler complaining that I was missing the semicolon. (I forgot to add
it after the text that I had pasted.)
There's a similar message which does include the semicolon, namely
"help: you can import it into scope: `use foo::Bar;`". I think the two
messages should be consistent, so this change adds it for "extern
crate".
If we encounter a syntax error inside of a braced block, then we should
fail by consuming the rest of the block if possible.
This implements such recovery for enums and structs.
Fixes#37113.