syntax: fold: use move semantics for efficient folding.
syntax: ast_map: use borrowed references into the AST.
syntax: fix fallout from using ptr::P.
syntax: tests: fix fallout from using ptr::P.
auto merge of #17189 : bkoropoff/rust/extern-existing-crate, r=alexcrichton

When checking for an existing crate, compare against the `crate_metadata::name` field, which is the crate name which was requested during resolution, rather than the result of the `crate_metadata::name()` method, which is the crate name within the crate metadata, as these may not match when using the --extern option to `rustc`.

This fixes spurious "multiple crate version" warnings under the following scenario:

- The crate `foo`, is referenced multiple times
- `--extern foo=./path/to/libbar.rlib` is specified to rustc
- The internal crate name of `libbar.rlib` is not `foo`

The behavior surrounding `Context::should_match_name` and the comments in `loader.rs` both lead me to believe that this scenario is intended to work.

Fixes #17186
rustc: fix fallout from using ptr::P.
rustdoc: fix fallout from using ptr::P.
fourcc: fix fallout from using ptr::P.
hexfloat: fix fallout from using ptr::P.
regex_macros: fix fallout from using ptr::P.
syntax: implement in-place folding of P<T> and Vec<T>.
syntax: document the ptr module.
Fix fallout in macro_crate/quote tests.
`rustc main.rs` generates main binary file
Add regression test for issue #17216
Display the doc-block toggle on everything again.

This needs a clone otherwise each successive insertion detaches `toggle`
from the previous position.

Fixes #17125.
auto merge of #13316 : eddyb/rust/ast-ptr, r=brson

Replaces Gc<T> in the AST with a custom owned smart pointer, P<T>. Fixes #7929.

## Benefits
* **Identity** (affinity?): sharing AST nodes is bad for the various analysis passes (e.g. one could bypass borrowck with a shared `ExprAddrOf` node taking a mutable borrow), the only reason we haven't hit any serious issues with it is because of inefficient folding passes which will always deduplicate any such shared nodes. Even if we were to switch to an arena, this would still hold, i.e. we wouldn't just use `&'a T` in the AST, but rather an wrapper (`P<'a, T>`?).

* **Immutability**: `P<T>` disallows mutating its inner `T` (unless that contains an `Unsafe` interior, which won't happen in the AST), unlike `~T`.

* **Efficiency**: folding can reuse allocation space for `P<T>` and `Vec<T>`, the latter even when the input and output types differ (as it would be the case with arenas or an AST with type parameters to toggle macro support). Also, various algorithms have been changed from copying `Gc<T>` to using `&T` and iterators.

* **Maintainability**: there is another reason I didn't just replace `Gc<T>` with `~T`: `P<T>` provides a fixed interface (`Deref`, `and_then` and `map`) which can remain fully functional even if the implementation changes (using a special thread-local heap, for example). Moreover, switching to, e.g. `P<'a, T>` (for a contextual arena) is easy and mostly automated.
auto merge of #17130 : jakub-/rust/issue-17033, r=pcwalton

Fixes #17033.
Fixes #15965.

cc @nikomatsakis
Add help diagnostic messages

This adds ‘help’ diagnostic messages to rustc. This is used for anything that
provides help to the user, particularly the `--explain` messages that were
previously integrated into the relevant error message.
auto merge of #17163 : pcwalton/rust/impls-next-to-struct, r=alexcrichton

type they provide an implementation for.

This breaks code like:

    mod foo {
        struct Foo { ... }
    }

    impl foo::Foo {
        ...
    }

Change this code to:

    mod foo {
        struct Foo { ... }

        impl Foo {
            ...
        }
    }

Closes #17059.

RFC #155.

[breaking-change]

r? @brson