Commit Graph

2260 Commits

Author SHA1 Message Date
Nadrieril
5687c16279 overlapping_range_endpoints does not belong in the unused lint group 2020-11-29 21:29:19 +00:00
Nadrieril
94ad5e1672 Improve error message 2020-11-29 21:29:19 +00:00
Nadrieril
c89d439bb5 Be consistent about linting singletons 2020-11-29 21:29:19 +00:00
Nadrieril
d1a50ffb7c Rename the overlapping_patterns lint to overlapping_range_endpoints 2020-11-29 21:29:19 +00:00
bors
b776d1c3e3 Auto merge of #79523 - Nadrieril:fix-usize-ranges, r=varkor
Fix overlap detection of `usize`/`isize` range patterns

`usize` and `isize` are a bit of a special case in the match usefulness algorithm, because the range of values they contain depends on the platform. Specifically, we don't want `0..usize::MAX` to count as an exhaustive match (see also [`precise_pointer_size_matching`](https://github.com/rust-lang/rust/issues/56354)). The way this was initially implemented is by treating those ranges like float ranges, i.e. with limited cleverness. This means we didn't catch the following as unreachable:
```rust
match 0usize {
    0..10 => {},
    10..20 => {},
    5..15 => {}, // oops, should be detected as unreachable
    _ => {},
}
```
This PRs fixes this oversight. Now the only difference between `usize` and `u64` range patterns is in what ranges count as exhaustive.

r? `@varkor`
`@rustbot` label +A-exhaustiveness-checking
2020-11-29 18:50:19 +00:00
bors
2e5723137b Auto merge of #77616 - jyn514:no-normalize, r=lcnr
Don't run `resolve_vars_if_possible` in `normalize_erasing_regions`

Neither `@eddyb` nor I could figure out what this was for. I changed it to `assert_eq!(normalized_value, infcx.resolve_vars_if_possible(&normalized_value));` and it passed the UI test suite.

<details><summary>

Outdated, I figured out the issue - `needs_infer()` needs to come _after_ erasing the lifetimes

</summary>

Strangely, if I change it to `assert!(!normalized_value.needs_infer())` it panics almost immediately:

```
query stack during panic:
#0 [normalize_generic_arg_after_erasing_regions] normalizing `<str::IsWhitespace as str::pattern::Pattern>::Searcher`
#1 [needs_drop_raw] computing whether `str::iter::Split<str::IsWhitespace>` needs drop
#2 [mir_built] building MIR for `str::<impl str>::split_whitespace`
#3 [unsafety_check_result] unsafety-checking `str::<impl str>::split_whitespace`
#4 [mir_const] processing MIR for `str::<impl str>::split_whitespace`
#5 [mir_promoted] processing `str::<impl str>::split_whitespace`
#6 [mir_borrowck] borrow-checking `str::<impl str>::split_whitespace`
#7 [analysis] running analysis passes on this crate
end of query stack
```

I'm not entirely sure what's going on - maybe the two disagree?

</details>

For context, this came up while reviewing https://github.com/rust-lang/rust/pull/77467/ (cc `@lcnr).`

Possibly this needs a crater run?

r? `@nikomatsakis`
cc `@matthewjasper`
2020-11-29 11:37:44 +00:00
bors
760430e6fd Auto merge of #78863 - KodrAus:feat/simd-array, r=oli-obk
Support repr(simd) on ADTs containing a single array field

This is a squash and rebase of `@gnzlbg's` #63531

I've never actually written code in the compiler before so just fumbled my way around until it would build 😅

I imagine there'll be some work we need to do in `rustc_codegen_cranelift` too for this now, but might need some input from `@bjorn3` to know what that is.

cc `@rust-lang/project-portable-simd`

-----

This PR allows using `#[repr(simd)]` on ADTs containing a single array field:

```rust
 #[repr(simd)] struct S0([f32; 4]);
 #[repr(simd)] struct S1<const N: usize>([f32; N]);
 #[repr(simd)] struct S2<T, const N: usize>([T; N]);
```

This should allow experimenting with portable packed SIMD abstractions on nightly that make use of const generics.
2020-11-29 09:28:09 +00:00
Dylan DPC
47e74a9a51
Rollup merge of #79516 - jyn514:cleanup-trait-solver, r=Aaron1011
Remove unnecessary `mut` binding

Found while fiddling around with https://github.com/rust-lang/rust/issues/77459.
2020-11-29 03:14:27 +01:00
Dylan DPC
6eb5245555
Rollup merge of #79505 - matklad:cleanup, r=jonas-schievink
Cleanup: shorter and faster code
2020-11-29 03:14:24 +01:00
Dylan DPC
ca8a1b05c6
Rollup merge of #79464 - GuillaumeGomez:doc-keyword-ident, r=jyn514
Extend doc keyword feature by allowing any ident

Part of #51315.

As suggested by ``@danielhenrymantilla`` in [this comment](https://github.com/rust-lang/rust/issues/51315#issuecomment-733879934), this PR extends `#[doc(keyword = "...")]` to allow any ident to be used as keyword. The final goal is to allow (proc-)macro crates' owners to write documentation of the keywords they might introduce.

r? ``@jyn514``
2020-11-29 03:14:21 +01:00
bors
914d07ae5f Auto merge of #79511 - cjgillot:fitem-2, r=lcnr
Do not visit ForeignItemRef for HIR indexing and validation.

Similarly to what is done for ImplItemRef and TraitItemRef.

Fixes #79487

r? `@lcnr`
2020-11-28 22:52:18 +00:00
Nadrieril
bdd2bdb53b Don't store ty and span in IntRange
We prefer to grab `ty` and `span` from `pcx`. This makes it consistent
with other constructors.
2020-11-28 22:07:15 +00:00
Nadrieril
d8983655c1 Correctly detect usize/isize range overlaps 2020-11-28 21:23:38 +00:00
Joshua Nelson
870a041262 Remove unnecessary mut binding 2020-11-28 14:52:25 -05:00
Camille GILLOT
5bd197921a Do not visit ForeignItemRef for HIR indexing and validation.
Similarly to what is done for ImplItemRef and TraitItemRef.

Fixes #79487
2020-11-28 18:08:17 +01:00
Jonas Schievink
208d680f77
Rollup merge of #79486 - camelid:E0591-code-cleanup, r=lcnr
Slightly improve code samples in E0591

* Improve formatting
* Don't hide `unsafe` block - it's important!
2020-11-28 15:58:30 +01:00
Jonas Schievink
dd0f953378
Rollup merge of #79476 - bjorn3:sync_cg_clif-2020-11-27, r=bjorn3
Sync rustc_codegen_cranelift

This implements a few extra simd intrinsics, fixes yet another 128bit bug and updates a few dependencies. It also fixes an cg_clif subtree update that did compile, but that caused a panic when compiling libcore. Other than that this is mostly cleanups.

`@rustbot` modify labels: +A-codegen +A-cranelift +T-compiler
2020-11-28 15:58:26 +01:00
Jonas Schievink
afc5542a9b
Rollup merge of #79474 - jyn514:query-mode, r=Aaron1011
Change comments on types to doc-comments

Found while investigating https://github.com/rust-lang/rust/issues/79459.

r? `@Aaron1011`
2020-11-28 15:58:25 +01:00
Jonas Schievink
fe9a02c211
Rollup merge of #79460 - bugadani:simplify, r=jonas-schievink
Remove intermediate vectors from `add_bounds`

This PR removes two short lived vectors that don't serve any obvious purpose.
2020-11-28 15:58:23 +01:00
Jonas Schievink
a732c3a369
Rollup merge of #78853 - calebcartwright:fix-const-block-expr-span, r=spastorino
rustc_parse: fix ConstBlock expr span

The span for a ConstBlock expression should presumably run through the end of the block it contains and not stop at the keyword, just like is done with similar block-containing expression kinds, such as a TryBlock
2020-11-28 15:58:15 +01:00
Aleksey Kladov
30d331ffb6 Cleanup: shorter and faster code 2020-11-28 17:47:34 +03:00
bors
4ae328bef4 Auto merge of #78296 - Aaron1011:fix/stmt-tokens, r=petrochenkov
Properly handle attributes on statements

We now collect tokens for the underlying node wrapped by `StmtKind`
nstead of storing tokens directly in `Stmt`.

`LazyTokenStream` now supports capturing a trailing semicolon after it
is initially constructed. This allows us to avoid refactoring statement
parsing to wrap the parsing of the semicolon in `parse_tokens`.

Attributes on item statements
(e.g. `fn foo() { #[bar] struct MyStruct; }`) are now treated as
item attributes, not statement attributes, which is consistent with how
we handle attributes on other kinds of statements. The feature-gating
code is adjusted so that proc-macro attributes are still allowed on item
statements on stable.

Two built-in macros (`#[global_allocator]` and `#[test]`) needed to be
adjusted to support being passed `Annotatable::Stmt`.
2020-11-28 07:48:56 +00:00
bors
f8e5209a21 Auto merge of #79353 - cjgillot:procmacro, r=petrochenkov
Setup proc-macro metadata at encoding instead of decoding

This should improve the common non-proc-macro case for metadata decoding.
2020-11-28 03:20:09 +00:00
Camelid
1b846bfbcc Slightly improve code samples in E0591
* Improve formatting
* Don't hide `unsafe` block - it's important!
2020-11-27 19:07:14 -08:00
bors
fd6b5376b7 Auto merge of #79284 - Nadrieril:constructor-module, r=varkor
Split match exhaustiveness into two files

I feel the constructor-related things in the `_match` module make enough sense on their own so I split them off. It makes `_match` feel less like a complicated mess. I'm not aware of PRs in progress against this module apart from my own so hopefully I'm not annoying too many people.
I have a lot of questions about the conventions in naming and modules around the compiler. Like, why is the module named `_match`? Could I rename it to `usefulness` maybe? Should `deconstruct_pat` be a submodule of `_match` since only `_match` uses it? Is it ok to move big piles of code around even if it makes git blame more difficult?

r? `@varkor`
`@rustbot` modify labels: +A-exhaustiveness-checking
2020-11-27 22:34:59 +00:00
Aaron Hill
92bfa05b07
Bump recursion_limit in rustc_ast_passes
When cfg(parallel_compiler) is enabled, we end up trying to prove
Send/Sync bounds for some deeply nested types (at least when rustdoc is
run).
2020-11-27 15:47:58 -05:00
bjorn3
477aa67802 Merge commit '5988bbd24aa87732bfa1d111ba00bcdaa22c481a' into sync_cg_clif-2020-11-27 2020-11-27 20:48:53 +01:00
Camille GILLOT
9dd32e177e Encode proc_macro directly.
Encode proc_macro name directly.

Do not store None values.
2020-11-27 20:39:49 +01:00
Joshua Nelson
2d39c09cc2 Change comments on types to doc-comments 2020-11-27 14:17:25 -05:00
Nadrieril
941c6ac1a2 Rename _match to usefulness 2020-11-27 18:43:28 +00:00
Nadrieril
2de0475826 Rename pat_constructor to Constructor::from_pat 2020-11-27 18:22:19 +00:00
Nadrieril
ba3c419a43 Move the definitions of the two Ctxts to the top 2020-11-27 18:22:19 +00:00
Nadrieril
2184a1444c Extract everything related to pattern deconstruction to a new module 2020-11-27 18:22:17 +00:00
Nadrieril
3715f1ed00 No need to expose Matrix internals 2020-11-27 18:20:30 +00:00
Nadrieril
d447bdff9b Disentangle Fields and PatStack 2020-11-27 18:20:30 +00:00
Nadrieril
b59792128c Move Constructor::apply to Fields 2020-11-27 18:20:30 +00:00
Guillaume Gomez
482b3accdd Remove unused is_doc_keyword function 2020-11-27 17:54:28 +01:00
bors
774bce7f5e Auto merge of #77484 - terhechte:support-ios-catalyst-macabi-arm64-target-triple, r=nikomatsakis
Add support for Arm64 Catalyst on ARM Macs

This is an iteration on https://github.com/rust-lang/rust/pull/63467 which was merged a while ago. In the aforementioned PR, I added support for the `X86_64-apple-ios-macabi` target triple, which is Catalyst, iOS apps running on macOS.

Very soon, Apple will launch ARM64 based Macs which will introduce `aarch64_apple_darwin.rs`, macOS apps using the Darwin ABI running on ARM. This PR adds support for Catalyst apps on ARM Macs: iOS apps compiled for the darwin ABI.

I don't have access to a Apple Developer Transition Kit (DTK), so I can't really test if the generated binaries work correctly. I'm vaguely hopeful that somebody with access to a DTK could give this a spin.
2020-11-27 15:58:26 +00:00
Aaron Hill
772292fa51
Don't lint on redundant semicolons after item statements
This preserves the current lint behavior for now.

Linting after item statements currently prevents the compiler from bootstrapping.
Fixing this is blocked on fixing this upstream in Cargo, and bumping the Cargo
submodule.
2020-11-27 09:37:49 -05:00
bors
c922857066 Auto merge of #79318 - cjgillot:fitem, r=lcnr
Store HIR ForeignItem in a side table

In a similar fashion to Item, ImplItem and TraitItem.
2020-11-27 13:45:22 +00:00
Dániel Buga
d212ea792e Remove intermediate vectors from add_bounds 2020-11-27 12:36:14 +01:00
bors
361543d776 Auto merge of #79433 - calebcartwright:parse-attr-vis, r=petrochenkov
rustc_parse: restore public visibility on parse_attribute

Make `parse_attribute` public as rustfmt is a downstream consumer. Refs https://github.com/rust-lang/rust/pull/78782#discussion_r530658904

r? `@petrochenkov`
2020-11-27 11:23:11 +00:00
bors
72d2a7cd35 Auto merge of #78194 - bugadani:generic, r=varkor
Skip most of `create_substs_for_ast_path` if type is not generic
2020-11-27 06:53:47 +00:00
bors
cfed9184f4 Auto merge of #79266 - b-naber:gat_trait_path_parser, r=petrochenkov
Generic Associated Types in Trait Paths - Ast part

The Ast part of https://github.com/rust-lang/rust/pull/78978

r? `@petrochenkov`
2020-11-27 00:18:24 +00:00
Camille GILLOT
d6b22fa534 Rebase fallout. 2020-11-26 23:56:15 +01:00
Dániel Buga
aebea52263 Skip most of create_substs_for_ast_path if type is not generic
Co-authored-by: varkor <github@varkor.com>
2020-11-26 23:14:38 +01:00
Aaron Hill
6f91c32da6
Fix new 'unnecessary trailing semicolon' warnings 2020-11-26 17:08:36 -05:00
Aaron Hill
758834d3e2
Only eat semicolons for statements that need them
When parsing a statement (e.g. inside a function body),
we now consider `struct Foo {};` and `$stmt;` to each consist
of two statements: `struct Foo {}` and `;`, and `$stmt` and `;`.

As a result, an attribute macro invoke as
`fn foo() { #[attr] struct Bar{}; }` will see `struct Bar{}` as its
input. Additionally, the 'unused semicolon' lint now fires in more
places.
2020-11-26 17:08:35 -05:00
Aaron Hill
de88bf148b
Properly handle attributes on statements
We now collect tokens for the underlying node wrapped by `StmtKind`
instead of storing tokens directly in `Stmt`.

`LazyTokenStream` now supports capturing a trailing semicolon after it
is initially constructed. This allows us to avoid refactoring statement
parsing to wrap the parsing of the semicolon in `parse_tokens`.

Attributes on item statements
(e.g. `fn foo() { #[bar] struct MyStruct; }`) are now treated as
item attributes, not statement attributes, which is consistent with how
we handle attributes on other kinds of statements. The feature-gating
code is adjusted so that proc-macro attributes are still allowed on item
statements on stable.

Two built-in macros (`#[global_allocator]` and `#[test]`) needed to be
adjusted to support being passed `Annotatable::Stmt`.
2020-11-26 17:08:35 -05:00
bors
cb56a4420c Auto merge of #79338 - Aaron1011:fix/token-reparse-cache, r=petrochenkov
Cache pretty-print/retokenize result to avoid compile time blowup

Fixes #79242

If a `macro_rules!` recursively builds up a nested nonterminal
(passing it to a proc-macro at each step), we will end up repeatedly
pretty-printing/retokenizing the same nonterminals. Unfortunately, the
'probable equality' check we do has a non-trivial cost, which leads to a
blowup in compilation time.

As a workaround, we cache the result of the 'probable equality' check,
which eliminates the compilation time blowup for the linked issue. This
commit only touches a single file (other than adding tests), so it
should be easy to backport.

The proper solution is to remove the pretty-print/retokenize hack
entirely. However, this will almost certainly break a large number of
crates that were relying on hygiene bugs created by using the reparsed
`TokenStream`. As a result, we will definitely not want to backport
such a change.
2020-11-26 22:02:45 +00:00