Commit Graph

10210 Commits

Author SHA1 Message Date
Michael Goulet
8568f44fe1 suggest deref/unboxing before wrapping variant 2022-01-12 12:01:01 -08:00
Michael Goulet
40f33a7a4c Deduplicate box deref and regular deref suggestions 2022-01-11 21:13:45 -08:00
bors
72e74d7b9c Auto merge of #92533 - Aaron1011:variant-symbol, r=petrochenkov
Store a `Symbol` instead of an `Ident` in `VariantDef`/`FieldDef`

The field is also renamed from `ident` to `name`. In most cases,
we don't actually need the `Span`. A new `ident` method is added
to `VariantDef` and `FieldDef`, which constructs the full `Ident`
using `tcx.def_ident_span()`. This method is used in the cases
where we actually need an `Ident`.

This makes incremental compilation properly track changes
to the `Span`, without all of the invalidations caused by storing
a `Span` directly via an `Ident`.
2022-01-11 21:02:01 +00:00
bors
1409c015b4 Auto merge of #90948 - oli-obk:🧹, r=nikomatsakis
Actually instantiate the opaque type when checking bounds

Before this change, `instantiate_opaque_types` was a no-op, because it only works relative to the defined opaque type inference anchor. If it is a no-op, the for loop will not actually have anything to iterate over, and thus nothing is checked at all.
2022-01-11 17:31:07 +00:00
Aaron Hill
450ef8613c
Store a Symbol instead of an Ident in VariantDef/FieldDef
The field is also renamed from `ident` to `name. In most cases,
we don't actually need the `Span`. A new `ident` method is added
to `VariantDef` and `FieldDef`, which constructs the full `Ident`
using `tcx.def_ident_span()`. This method is used in the cases
where we actually need an `Ident`.

This makes incremental compilation properly track changes
to the `Span`, without all of the invalidations caused by storing
a `Span` directly via an `Ident`.
2022-01-11 10:16:22 -05:00
bors
2e2c86eba2 Auto merge of #92070 - rukai:replace_vec_into_iter_with_array_into_iter, r=Mark-Simulacrum
Replace usages of vec![].into_iter with [].into_iter

`[].into_iter` is idiomatic over `vec![].into_iter` because its simpler and faster (unless the vec is optimized away in which case it would be the same)

So we should change all the implementation, documentation and tests to use it.

I skipped:
* `src/tools` - Those are copied in from upstream
* `src/test/ui` - Hard to tell if `vec![].into_iter` was used intentionally or not here and not much benefit to changing it.
*  any case where `vec![].into_iter` was used because we specifically needed a `Vec::IntoIter<T>`
*  any case where it looked like we were intentionally using `vec![].into_iter` to test it.
2022-01-11 14:23:24 +00:00
bors
e4b1d58414 Auto merge of #92012 - llogiq:repr-c-def-id, r=michaelwoerister
Make `DefId` `repr(C)`, optimize big-endian field order

r? `@michaelwoerister`
2022-01-11 08:09:00 +00:00
bors
89b9f7b284 Auto merge of #92719 - matthiaskrgr:rollup-tc7oqys, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #92248 (Normalize struct tail type when checking Pointee trait)
 - #92357 (Fix invalid removal of newlines from doc comments)
 - #92602 (Make source links look cleaner)
 - #92636 (Normalize generator-local types with unevaluated constants)
 - #92693 (Release notes: add `Result::unwrap_{,err_}unchecked`)
 - #92702 (Clean up lang_items::extract)
 - #92717 (update miri)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-10 11:53:15 +00:00
Matthias Krüger
6719e3eb18
Rollup merge of #92702 - ehuss:clean-lang_items-extract, r=petrochenkov
Clean up lang_items::extract

Noted in https://github.com/rust-lang/rust/pull/87739#pullrequestreview-740497194,
lang_items::extract no longer needs to take a closure.
2022-01-10 11:03:11 +01:00
Matthias Krüger
ca9fc28f0b
Rollup merge of #92636 - compiler-errors:normalize-generator-const-expr, r=oli-obk
Normalize generator-local types with unevaluated constants

Normalize generator-interior types in addition to (i.e. instead of just) erasing regions, since sometimes we collect types with unevaluated const exprs.

Fixes #84737
Fixes #88171
Fixes #92091
Fixes #92634
Probably also fixes #73114, but that one has no code I could test. It looks like it's the same issue, though.
2022-01-10 11:03:07 +01:00
Matthias Krüger
d20affbf8d
Rollup merge of #92357 - GuillaumeGomez:fix-doc-comment-backline-removal, r=camelid
Fix invalid removal of newlines from doc comments

Fixes https://github.com/rust-lang/rust/issues/91201.

Before:

![Screenshot from 2021-12-28 17-02-11](https://user-images.githubusercontent.com/3050060/147585187-c8e67531-c1b4-457d-9d30-d5b44bf91fea.png)

After:

![Screenshot from 2021-12-28 17-02-25](https://user-images.githubusercontent.com/3050060/147585190-30aa0398-1fc7-4fe7-9e8b-5c475d4f9613.png)

r? `@camelid`
2022-01-10 11:03:05 +01:00
Matthias Krüger
6466f89fc5
Rollup merge of #92248 - compiler-errors:normalize-type-for-pointee, r=jackh726
Normalize struct tail type when checking Pointee trait

Let's go ahead and implement the FIXMEs by properly normalizing the struct-tail type when satisfying a Pointee obligation. This should fix the ICE when we try to calculate a layout depending on `<Ty as Pointee>::Metadata` later.
Fixes #92128
Fixes #92577

Additionally, mark the obligation as ambiguous if there are any infer types in that struct-tail type. This has the effect of causing `<_ as Pointee>::Metadata` to be properly replaced with an infer variable ([here](https://github.com/rust-lang/rust/blob/master/compiler/rustc_trait_selection/src/traits/project.rs#L813)) and registered as an obligation... this turns out to be very important in unifying function parameters with formals that are assoc types.

Fixes #91446
2022-01-10 11:03:03 +01:00
bors
df035a33b2 Auto merge of #87487 - lambinoo:I-64762_unreachable_pub_lint, r=petrochenkov
Fixes wrong unreachable_pub lints on nested and glob public reexport

Linked issues: #64762 & #82064
2022-01-10 08:55:53 +00:00
bors
d63a8d965e Auto merge of #92278 - Aaron1011:fix-fingerprint-caching, r=michaelwoerister
Ensure that `Fingerprint` caching respects hashing configuration

Fixes #92266

In some `HashStable` impls, we use a cache to avoid re-computing
the same `Fingerprint` from the same structure (e.g. an `AdtDef`).
However, the `StableHashingContext` used can be configured to
perform hashing in different ways (e.g. skipping `Span`s). This
configuration information is not included in the cache key,
which will cause an incorrect `Fingerprint` to be used if
we hash the same structure with different `StableHashingContext`
settings.

To fix this, the configuration settings of `StableHashingContext`
are split out into a separate `HashingControls` struct. This
struct is used as part of the cache key, ensuring that our caches
always produce the correct result for the given settings.

With this in place, we now turn off `Span` hashing during the
entire process of computing the hash included in legacy symbols.
This current has no effect, but will matter when a future PR
starts hashing more `Span`s that we currently skip.
2022-01-10 00:26:07 +00:00
Eric Huss
2b7572092c Clean up lang_items::extract
Noted in https://github.com/rust-lang/rust/pull/87739#pullrequestreview-740497194,
lang_items::extract no longer needs to take a closure.
2022-01-09 13:41:04 -08:00
Lamb
3a77bb86ff Compute most of Public/Exported access level in rustc_resolve
Mak DefId to AccessLevel map in resolve for export

hir_id to accesslevel in resolve and applied in privacy
using local def id
removing tracing probes
making function not recursive and adding comments

Move most of Exported/Public res to rustc_resolve

moving public/export res to resolve

fix missing stability attributes in core, std and alloc

move code to access_levels.rs

return for some kinds instead of going through them

Export correctness, macro changes, comments

add comment for import binding

add comment for import binding

renmae to access level visitor, remove comments, move fn as closure, remove new_key

fmt

fix rebase

fix rebase

fmt

fmt

fix: move macro def to rustc_resolve

fix: reachable AccessLevel for enum variants

fmt

fix: missing stability attributes for other architectures

allow unreachable pub in rustfmt

fix: missing impl access level + renaming export to reexport

Missing impl access level was found thanks to a test in clippy
2022-01-09 21:33:14 +00:00
bors
092e1c9d23 Auto merge of #92534 - Aaron1011:hash-hir, r=petrochenkov
Hash `Ident` spans in all HIR structures

This PR removes all of the `#[stable_hasher(project(name))]`
attributes used in HIR structs. While these attributes are not known
to be causing any issues in practice, we need to hash these in
order for the incremental system to work correctly -
a query could be otherwise be incorrectly marked green
when a change occures in one of the `Span`s that it uses.
2022-01-09 16:03:41 +00:00
bors
f7bb8e3677 Auto merge of #92690 - matthiaskrgr:rollup-rw0oz05, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #92055 (Add release notes for 1.58)
 - #92490 (Move crate drop-down to search results page)
 - #92510 (Don't resolve blocks in foreign functions)
 - #92573 (expand: Refactor InvocationCollector visitor for better code reuse)
 - #92608 (rustdoc: Introduce a resolver cache for sharing data between early doc link resolution and later passes)
 - #92657 (Implemented const casts of raw pointers)
 - #92671 (Make `Atomic*::from_mut` return `&mut Atomic*`)
 - #92673 (Remove useless collapse toggle on "all items" page)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-09 12:43:37 +00:00
Matthias Krüger
51001b35bd
Rollup merge of #92608 - petrochenkov:doctrscope3, r=CraftSpider
rustdoc: Introduce a resolver cache for sharing data between early doc link resolution and later passes

The refactoring parts of https://github.com/rust-lang/rust/pull/88679, shouldn't cause any slowdowns.
r? `@jyn514`
2022-01-09 13:38:32 +01:00
Matthias Krüger
b681dc2af4
Rollup merge of #92573 - petrochenkov:ltrattr3, r=Aaron1011
expand: Refactor InvocationCollector visitor for better code reuse

The refactoring part of https://github.com/rust-lang/rust/pull/92473.

Invocation collector visitor logic now lives in two main functions:
- `fn flat_map_node`, corresponding to "one to many" expansions
- `fn visit_node`, corresponding to "one to one" expansions

All specific mut visitor methods now use one of these functions.

The new `InvocationCollectorNode` trait implemented for all `AstFragment` nodes provides the necessary small pieces of functionality required to implement the `(flat_map,visit)_node` functions.
r? `@Aaron1011`
2022-01-09 13:38:31 +01:00
Matthias Krüger
464a0813d1
Rollup merge of #92510 - inquisitivecrystal:foreign-block, r=cjgillot
Don't resolve blocks in foreign functions

Although it is an error for a foreign function to have a block, it is still possible at the level of the AST. #74204 made AST lowering skip over blocks belonging to foreign functions, since they're invalid. However, resolve still treated these blocks normally, resulting in a mismatch between the HIR and resolve, which could cause an ICE under certain circumstances. This PR changes resolve to skip over blocks belonging to foreign functions, as AST lowering does.

Fixes #91370.

r? ``@cjgillot``
2022-01-09 13:38:30 +01:00
bors
e19ca1d946 Auto merge of #92086 - petrochenkov:modchild, r=jackh726
rustc_metadata: Optimize and document module children decoding

The first commit limits the item in the `item_children`/`each_child_of_item` query to modules (in name resolution sense) and adds a corresponding assertion.
The `associated_item_def_ids` query collecting children of traits and impls specifically now uses a simplified implementation not decoding unnecessary data instead of `each_child_of_item`, this gives a nice performance improvement.

The second commit does some renaming that clarifies the terminology used for all items in a module vs `use` items only.
2022-01-09 10:02:49 +00:00
Lucas Kent
08829853d3 eplace usages of vec![].into_iter with [].into_iter 2022-01-09 14:09:25 +11:00
bors
02fe61b381 Auto merge of #92497 - bjorn3:remove_lazy_meta_min_size, r=eddyb
Remove LazyMeta::min_size

It is extremely conservative and as such barely reduces the size of encoded Lazy distances, but does increase complexity.
2022-01-09 01:29:22 +00:00
Vadim Petrochenkov
4b03fd910c rustc_middle: Rename Export to ModChild and add some comments
Also rename `module_exports`/`export_map` to `module_reexports`/`reexport_map` for clarity.
2022-01-09 09:22:07 +08:00
Vadim Petrochenkov
3051f6e9c4 rustc_metadata: Rename item_children(_untracked) to module_children(_untracked)
And `each_child_of_item` to `for_each_module_child`
2022-01-09 09:22:06 +08:00
Vadim Petrochenkov
96c6a50e96 rustc_metadata: Optimize and document module children decoding 2022-01-09 09:22:04 +08:00
bors
a7e2e33960 Auto merge of #91919 - Aaron1011:query-recursive-read, r=michaelwoerister
Don't perform any new queries while reading a query result on disk

In addition to being very confusing, this can cause us to add dep node edges between two queries that would not otherwise have an edge.

We now panic if any new dep node edges are created during the deserialization of a query result. This requires serializing the full `AdtDef` to disk, instead of just serializing the `DefId` and invoking the `adt_def` query during deserialization.

I'll probably split this up into several smaller PRs for perf runs.
2022-01-08 18:32:31 +00:00
bors
488acf86a7 Auto merge of #90639 - matthewjasper:leaf-def-cache, r=cjgillot
Add a query for resolving an impl item from the trait item

This makes finding the item in an impl that implements a given trait item a query. This is for a few reasons:

- To slightly improve performance
- To avoid having to do name resolution during monomorphisation
- To make it easier to implement potential future features that create anonymous associated items
2022-01-08 15:20:33 +00:00
bjorn3
717d4b35f8 Remove LazyMeta::min_size
It is extremely conservative and as such barely reduces the size of
encoded Lazy distances, but does increase complexity.
2022-01-08 13:55:33 +01:00
Eric Huss
05cfc4f4a9
Rollup merge of #92650 - pierwill:patch-2, r=michaelwoerister
Fix typo in `StableCrateId` docs
2022-01-07 20:21:02 -08:00
Eric Huss
5cddd24daa
Rollup merge of #92375 - wesleywiser:consolidate_debuginfo_msvc_check, r=michaelwoerister
Consolidate checking for msvc when generating debuginfo

If the target we're generating code for is msvc, then we do two main
things differently: we generate type names in a C++ style instead of a
Rust style and we generate debuginfo for enums differently.

I've refactored the code so that there is one function
(`cpp_like_debuginfo`) which determines if we should use the C++ style
of naming types and other debuginfo generation or the regular Rust one.

r? ``@michaelwoerister``

This PR is not urgent so please don't let it interrupt your holidays! 🎄 🎁
2022-01-07 20:20:58 -08:00
Eric Huss
81c515bf77
Rollup merge of #92336 - dtolnay:printstateself, r=michaelwoerister
Remove &self from PrintState::to_string

The point of `PrintState::to_string` is to create a `State` and evaluate the caller's closure on it:

e9fbe79292/compiler/rustc_ast_pretty/src/pprust/state.rs (L868-L872)

Making the caller *also* construct and pass in a `State`, which is then ignored, was confusing.
2022-01-07 20:20:56 -08:00
Noah Lev
9d625bc972 Fix accidental undo of 5e1972eba7 2022-01-07 14:16:56 -08:00
Matthew Jasper
3b7d496f72 Add query to avoid name comparison in leaf_def 2022-01-07 13:31:36 -08:00
Matthew Jasper
1b057a33bd Move associated_item* providers to their own module 2022-01-07 13:23:35 -08:00
Matthew Jasper
d7595853a2 Add trait_item_def_id to AssocItem
This allows avoiding some lookups by name
2022-01-07 12:28:12 -08:00
Matthew Jasper
0b1ab91d66 Deserialization less in associated_item_def_ids 2022-01-07 11:50:42 -08:00
Wesley Wiser
836addcbc4 Consolidate checking for msvc when generating debuginfo
If the target we're generating code for is msvc, then we do two main
things differently: we generate type names in a C++ style instead of a
Rust style and we generate debuginfo for enums differently.

I've refactored the code so that there is one function
(`cpp_like_debuginfo`) which determines if we should use the C++ style
of naming types and other debuginfo generation or the regular Rust one.
2022-01-07 12:36:09 -05:00
pierwill
130ba4718e
Fix typo in StableCrateId docs 2022-01-07 10:26:26 -06:00
Vadim Petrochenkov
5acd1f91a0 rustdoc: Introduce a resolver cache for sharing data between early doc link resolution and later passes 2022-01-07 16:21:53 +08:00
Vadim Petrochenkov
4523466770 expand: Import more AST enums 2022-01-07 14:54:16 +08:00
Vadim Petrochenkov
800ba8f8e8 expand: Refactor InvocationCollector visitor for better code reuse 2022-01-07 14:41:22 +08:00
Vadim Petrochenkov
4fd23350cd expand: Remove some unnecessary self mutability 2022-01-07 13:50:03 +08:00
Vadim Petrochenkov
dc7e771155 expand: Rename some AstFragments to match AST structures 2022-01-07 13:50:03 +08:00
Michael Goulet
d35b23ecd8 Normalize generator-local types with unevaluated constants 2022-01-06 19:08:04 -08:00
Matthias Krüger
140b6cb1ba
Rollup merge of #92607 - petrochenkov:doctrscope2, r=cjgillot
rustc_metadata: Some minor cleanups and optimizations

Mostly extracted from https://github.com/rust-lang/rust/pull/88679 (which is otherwise a rustdoc PR).
r? ``@cjgillot``
2022-01-06 23:15:21 +01:00
Matthias Krüger
1591dcb659
Rollup merge of #92559 - durin42:llvm-14-attributemask, r=nikic
RustWrapper: adapt to new AttributeMask API

Upstream LLVM change 9290ccc3c1a1 migrated attribute removal to use
AttributeMask instead of AttrBuilder, so we need to follow suit here.

r? ``@nagisa`` cc ``@nikic``
2022-01-06 23:15:18 +01:00
Matthias Krüger
844a657bb8
Rollup merge of #92504 - dtolnay:wall, r=jackh726
Exit nonzero on rustc -Wall

Previously `rustc -Wall /dev/null` would print a paragraph explaining that `-Wall` is not a thing in Rust, but would then exit 0. I believe exiting 0 is not the right behavior. For something like `rustc --version` or `rustc --help` or `rustc -C help` the user is requesting rustc to print some information; rustc prints that information and exits 0 because what the user requested has been accomplished. In the case of `rustc -Wall path/to/main.rs`, I don't find it correct to conceptualize this as "the user requested rustc to print information about the fact that Wall doesn't exist". The user requested a particular thing, and despite rustc knowing what they probably meant and informing them about that, the thing they requested has *not* been accomplished. Thus a nonzero exit code is needed.
2022-01-06 23:15:17 +01:00
Matthias Krüger
1a8f69826c
Rollup merge of #92417 - dtolnay:printimpl, r=jackh726
Fix spacing and ordering of words in pretty printed Impl

Follow-up to #92238 fixing one of the FIXMEs.

```rust
macro_rules! repro {
    ($item:item) => {
        stringify!($item)
    };
}

fn main() {
    println!("{}", repro!(impl<T> Struct<T> {}));
    println!("{}", repro!(impl<T> const Trait for T {}));
}
```

Before:&ensp;`impl <T> Struct<T> {}`
After:&ensp;`impl<T> Struct<T> {}`

Before:&ensp;`impl const <T> Trait for T {}` 😿
After:&ensp;`impl<T> const Trait for T {}`
2022-01-06 23:15:16 +01:00