Commit Graph

2035 Commits

Author SHA1 Message Date
Dhruv Jauhar
1f53754236 Provide diagnostic suggestion in ExprUseVisitor Delegate
The [Delegate
trait](981346fc07/compiler/rustc_typeck/src/expr_use_visitor.rs (L28-L38))
currently use `PlaceWithHirId` which is composed of Hir `Place` and the
corresponding expression id.

Even though this is an accurate way of expressing how a Place is used,
it can cause confusion during diagnostics.

Eg:

```
let arr : [String; 5];

let [a, ...]     =   arr;
 ^^^ E1 ^^^      =  ^^E2^^
 ```

 Here `arr` is moved because of the binding created E1. However, when we
 point to E1 in diagnostics with the message `arr` was moved, it can be
 confusing.  Rather we would like to report E2 to the user.

 Closes: https://github.com/rust-lang/project-rfc-2229/issues/20
2020-11-02 01:31:34 -05:00
Yuki Okushi
61305d5ab4
Rollup merge of #78610 - petrochenkov:nostriptok, r=Aaron1011
Do not remove tokens before AST json serialization

`TokenStripper` is error-prone and introduces one more use of `MutVisitor`.
It's much simpler to treat serialization as just one more place that wants lazy token stream to turn into a real token stream.
Also, no code is better than more code, in general.
r? @Aaron1011

(I also merged tests for `TokenStripper` ICEs into one.)
2020-11-02 14:14:34 +09:00
bors
3e93027557 Auto merge of #78592 - fpoli:nll-facts-dir, r=matthewjasper
Add option to customize the nll-facts' folder location

This PR adds a `nll-facts-dir` option to specify the location of the directory in which NLL facts are dumped into. It works the same way `dump-mir-dir` controls the location used by the `dump-mir` option.
2020-11-02 04:39:05 +00:00
Ayrton
ace02c40f0 Corrected suggestion for generic parameters in function_item_references lint
This lint was incorrectly suggesting casting a function to a pointer without
specifying generic type parameters or const generics. This would cause a
compiler error since the missing parameters couldn't be inferred. This commit
fixed the suggestion and added a few tests with generics.
2020-11-01 23:50:17 -04:00
bors
d8ef0d7757 Auto merge of #78645 - JulianKnodt:i78622, r=estebank
Add delay_span_bug to no longer ICE

Fixes #78622

r? `@matthewjasper`
2020-11-02 02:18:36 +00:00
bors
3d0682b97a Auto merge of #78605 - nox:relax-elf-relocations, r=nagisa
Implement -Z relax-elf-relocations=yes|no

This lets rustc users tweak whether the linker should relax ELF relocations without recompiling a whole new target with its own libcore etc.
2020-11-02 00:12:32 +00:00
Tomasz Miąsko
c0cbf6368d inliner: Remove redundant loop
No functional changes intended.
2020-11-02 00:00:00 +00:00
kadmin
ab946dd3e7 Add delay_span_bug to no longer ICE 2020-11-01 22:31:19 +00:00
Mara Bos
6f1992a7d6 Turn 'useless #[deprecated]' error into a lint. 2020-11-01 20:48:58 +01:00
Mara Bos
706bc33651 Use the right span for errors about #[deprecated] attributes. 2020-11-01 20:48:58 +01:00
Mara Bos
0e2337a5d6 Deny #[deprecated] on trait impl blocks.
They have no effect there, but were silently accepted.
2020-11-01 20:48:58 +01:00
Vishnunarayan K I
c93d25b6af reverse binding order in matches ...
... to allow the subbinding of copyable fields in bindings after `@`

Fixes #69971
2020-11-02 00:05:55 +05:30
bors
b202532608 Auto merge of #75534 - Aaron1011:feature/new-future-breakage, r=pnkfelix
Implement rustc side of report-future-incompat

cc https://github.com/rust-lang/rust/issues/71249

This is an alternative to `@pnkfelix's` initial implementation in https://github.com/pnkfelix/rust/commits/prototype-rustc-side-of-report-future-incompat (mainly because I started working before seeing that branch 😄 ).

My approach outputs the entire original `Diagnostic`, in a way that is compatible with incremental compilation. This is not yet integrated with compiletest, but can be used manually by passing `-Z emit-future-incompat-report` to `rustc`.

Several changes are made to support this feature:
* The `librustc_session/lint` module is moved to a new crate `librustc_lint_defs` (name bikesheddable). This allows accessing lint definitions from `librustc_errors`.
* The `Lint` struct is extended with an `Option<FutureBreakage>`. When present, it indicates that we should display a lint in the future-compat report. `FutureBreakage` contains additional information that we may want to display in the report (currently, a `date` field indicating when the crate will stop compiling).
* A new variant `rustc_error::Level::Allow` is added. This is used when constructing a diagnostic for a future-breakage lint that is marked as allowed (via `#[allow]` or `--cap-lints`). This allows us to capture any future-breakage diagnostics in one place, while still discarding them before they are passed to the `Emitter`.
* `DiagnosticId::Lint` is extended with a `has_future_breakage` field, indicating whether or not the `Lint` has future breakage information (and should therefore show up in the report).
* `Session` is given access to the `LintStore` via a new `SessionLintStore` trait (since `librustc_session` cannot directly reference `LintStore` without a cyclic dependency). We use this to turn a string `DiagnosticId::Lint` back into a `Lint`, to retrieve the `FutureBreakage` data.

Currently, `FutureBreakage.date` is always set to `None`. However, this could potentially be interpreted by Cargo in the future.

I've enabled the future-breakage report for the `ARRAY_INTO_ITER` lint, which can be used to test out this PR. The intent is to use the field to allow Cargo to determine the date of future breakage (as described in [RFC 2834](https://github.com/rust-lang/rfcs/blob/master/text/2834-cargo-report-future-incompat.md)) without needing to parse the diagnostic itself.

cc `@pnkfelix`
2020-11-01 16:52:28 +00:00
bors
1899c489d4 Auto merge of #78553 - Nadrieril:fix-78549, r=varkor
Fix #78549

Before #78430, this worked because `specialize_constructor` didn't actually care too much which constructor was passed to it unless needed. That PR however handles `&str` as a special case, and I did not anticipate patterns for the `&str` type other than string literals.
I am not very confident there are not other similar oversights left, but hopefully only `&str` was different enough to break my assumptions.

Fixes https://github.com/rust-lang/rust/issues/78549
2020-11-01 14:37:50 +00:00
bors
e8cbaf2ae7 Auto merge of #78623 - m-ou-se:rollup-m6y5j0m, r=m-ou-se
Rollup of 6 pull requests

Successful merges:

 - #78073 (Add #[inline] to some functions in core::str.)
 - #78596 (Fix doc links to std::fmt)
 - #78599 (Add note to process::arg[s] that args shouldn't be escaped or quoted)
 - #78602 (fix various aliasing issues in the standard library)
 - #78603 (expand: Tweak a comment in implementation of `macro_rules`)
 - #78621 (Inline Default::default() for atomics)

Failed merges:

r? `@ghost`
2020-11-01 11:54:58 +00:00
Mara Bos
540d4743cc
Rollup merge of #78603 - petrochenkov:fourdigits, r=matthewjasper
expand: Tweak a comment in implementation of `macro_rules`

The answer to the removed FIXME is that we don't apply mark to the span `sp` just because that span is no longer used. We could apply it, but that would just be unnecessary extra work.

The comments in code tell why the span is unused, it's a span of `$var` literally, which is lost for `tt` variables because their tokens are outputted directly, but kept for other variables which are outputted as [groups](https://doc.rust-lang.org/nightly/proc_macro/struct.Group.html) and `sp` is kept as the group's span.

Closes https://github.com/rust-lang/rust/issues/2887
2020-11-01 11:53:37 +01:00
bors
1e37ba76d4 Auto merge of #78531 - cuviper:unwrap-metadata, r=tmandry
rustc_llvm: unwrap LLVMMetadataRef before casting

Directly casting the opaque pointer was [reported] to cause an
"incomplete type" error with GCC 9.3:

```
llvm-wrapper/RustWrapper.cpp:939:31:   required from here
/usr/include/c++/9.3/type_traits:1301:12: error: invalid use of incomplete type 'struct LLVMOpaqueMetadata'
 1301 |     struct is_base_of
      |            ^~~~~~~~~~
In file included from [...]/rust/src/llvm-project/llvm/include/llvm-c/BitReader.h:23,
                 from llvm-wrapper/LLVMWrapper.h:1,
                 from llvm-wrapper/RustWrapper.cpp:1:
[...]/rust/src/llvm-project/llvm/include/llvm-c/Types.h:89:16: note: forward declaration of 'struct LLVMOpaqueMetadata'
   89 | typedef struct LLVMOpaqueMetadata *LLVMMetadataRef;
      |                ^~~~~~~~~~~~~~~~~~
```

[reported]: https://zulip-archive.rust-lang.org/182449tcompilerhelp/12215halprustcllvmbuildfail.html#214915124

A simple `unwrap` fixes the issue.

r? `@eddyb`
2020-11-01 09:30:11 +00:00
bors
1d5b7c3c96 Auto merge of #78420 - estebank:suggest-assoc-fn, r=petrochenkov
Suggest calling associated `fn` inside `trait`s

When calling a function that doesn't exist inside of a trait's
associated `fn`, and another associated `fn` in that trait has that
name, suggest calling it with the appropriate fully-qualified path.

Expand the label to be more descriptive.

Prompted by the following user experience:
https://users.rust-lang.org/t/cannot-find-function/50663
2020-11-01 06:49:16 +00:00
Nadrieril
1bdcd02a70 The need for Single to cover Unlistable was a hack
It is now unneeded, since we handle `&str` patterns in a consistent way.
2020-11-01 02:05:58 +00:00
Nadrieril
4cd30197eb Fix #78549
Before #78430, string literals worked because `specialize_constructor`
didn't actually care too much which constructor was passed to it unless
needed. Since then, string literals are special cased and a bit hacky. I
did not anticipate patterns for the `&str` type other than string
literals, hence this bug. This makes string literals less hacky.
2020-11-01 02:04:42 +00:00
Vadim Petrochenkov
6b63e9b990 Do not remove tokens before AST json serialization 2020-11-01 00:03:35 +03:00
Tomasz Miąsko
3b7157dc1a Assert that locals have storage when used
The validator in visit_local asserts that local has a stroage when used,
but visit_local is never called so validation is ineffective.

Use super_statement and super_terminator to ensure that locals are visited.
2020-10-31 21:06:29 +01:00
Andreas Molzer
af72a70ee2 Move post order walk to iterative approach
The previous recursive approach might overflow the stack when walking a
particularly deep, list-like, graph. In particular, dominator
calculation for borrow checking does such a traversal and very long
functions might lead to a region dependency graph with in this
problematic structure.
2020-10-31 18:52:00 +01:00
Anthony Ramine
6febaf2419 Implement -Z relax-elf-relocations=yes|no
This lets rustc users tweak whether the linker should relax ELF relocations,
namely whether it should emit R_X86_64_GOTPCRELX relocations instead of
R_X86_64_GOTPCREL, as the former is allowed by the ABI to be further
optimised. The default value is whatever the target defines.
2020-10-31 17:16:56 +01:00
Vadim Petrochenkov
7652bc3f68 expand: Tweak a comment in implementation of macro_rules 2020-10-31 18:13:46 +03:00
Ralf Jung
289c0d8489 Retagging: do not retag 'raw reborrows' 2020-10-31 15:31:27 +01:00
Mara Bos
1873ca55b3
Rollup merge of #78587 - petrochenkov:lazytok, r=Aaron1011
parser: Cleanup `LazyTokenStream` and avoid some clones

by using a named struct instead of a closure.

r? @Aaron1011
2020-10-31 09:49:41 +01:00
Mara Bos
841f0e7f2c
Rollup merge of #78577 - tmiasko:validate-aliasing, r=jonas-schievink
validator: Extend aliasing check to a call terminator
2020-10-31 09:49:38 +01:00
Mara Bos
89aea55a7d
Rollup merge of #78526 - Aaron1011:fix/assoc-tokens, r=estebank
Strip tokens from trait and impl items before printing AST JSON

Fixes #78510
2020-10-31 09:49:34 +01:00
Aaron Hill
ac12e6fd0e
Fix test 2020-10-30 20:02:15 -04:00
Aaron Hill
6bdb4e3206
Some work 2020-10-30 20:02:14 -04:00
Aaron Hill
23018a55d9
Implement rustc side of report-future-incompat 2020-10-30 20:02:14 -04:00
Vadim Petrochenkov
d0c63bccc5 parser: Cleanup LazyTokenStream and avoid some clones
by using a named struct instead of a closure.
2020-10-31 01:56:34 +03:00
bors
0d033dee3e Auto merge of #78182 - LeSeulArtichaut:ty-visitor-contolflow, r=lcnr,oli-obk
TypeVisitor: use `std::ops::ControlFlow` instead of `bool`

Implements MCP rust-lang/compiler-team#374.

Blocked on FCP in rust-lang/compiler-team#374.
r? `@lcnr` cc `@jonas-schievink`
2020-10-30 22:53:55 +00:00
Federico Poli
97a65b6f81 Add option to customize the nll-facts' folder location 2020-10-30 21:33:08 +01:00
Matthew Jasper
4d60a80713 Address review comment and update chalk to 0.36.0 2020-10-30 19:39:33 +00:00
Matthew Jasper
acb6a06123 Fix various Chalk lowering bugs
- Add more well-known traits
- Use the correct binders when lowering trait objects
- Use correct substs when lowering trait objects
- Use the correct binders for opaque_ty_data
- Lower negative impls with the correct polarity
- Supply associated type values
- Use `predicates_defined_on` for where clauses
2020-10-30 19:39:33 +00:00
Matthew Jasper
299a65ff71 Update chalk 0.32.0 -> 0.35.0 2020-10-30 19:39:30 +00:00
Matthew Jasper
1f5c655d0c Fix query cycle when tracing explicit_item_bounds 2020-10-30 19:38:46 +00:00
Joshua Nelson
5339bd1ebe Add back missing comments 2020-10-30 10:13:41 -04:00
Joshua Nelson
57c6ed0c07 Fix even more clippy warnings 2020-10-30 10:13:39 -04:00
Joshua Nelson
bfecb18771 Fix some more clippy warnings 2020-10-30 10:12:56 -04:00
LeSeulArtichaut
9433eb83fe Remove implicit Continue type 2020-10-30 12:27:47 +01:00
LeSeulArtichaut
24e1a7e656 Use ControlFlow::is{break,continue} 2020-10-30 12:27:46 +01:00
LeSeulArtichaut
61f8182cec TypeVisitor: use ControlFlow in rustc_{mir,privacy,traits,typeck} 2020-10-30 12:27:44 +01:00
LeSeulArtichaut
4fe735b320 TypeVisitor: use ControlFlow in rustc_{infer,lint,trait_selection} 2020-10-30 12:27:34 +01:00
LeSeulArtichaut
2c85b6fae0 TypeVisitor: use std::ops::ControlFlow instead of bool 2020-10-30 12:25:24 +01:00
bors
388ef34904 Auto merge of #78562 - JohnTitor:rollup-otg906u, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #77334 (Reorder benches const variable)
 - #77888 (Simplify a nested bool match)
 - #77921 (f64: Refactor collapsible_if)
 - #78523 (Revert invalid `fn` return type parsing change)
 - #78524 (Avoid BorrowMutError with RUSTC_LOG=debug)
 - #78545 (Make anonymous binders start at 0)
 - #78554 (Improve wording of `core::ptr::drop_in_place` docs)
 - #78556 (Link to pass docs from NRVO module docs)

Failed merges:

 - #78424 (Fix some more clippy warnings)

r? `@ghost`
2020-10-30 10:01:49 +00:00
Yuki Okushi
2471a7cdaa
Rollup merge of #78556 - camelid:mir-opt-nrvo-docs, r=jyn514
Link to pass docs from NRVO module docs

It can be easy to miss that this is documented on the pass's struct if you are
looking at the module docs.

Cc https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/what.20is.20NRVO.3F
2020-10-30 18:00:58 +09:00
Yuki Okushi
05f80f03a9
Rollup merge of #78545 - jackh726:anonymous, r=oli-obk
Make anonymous binders start at 0

A few changes to some test outputs, but these actually look *more* correct to me.
2020-10-30 18:00:56 +09:00
Yuki Okushi
f8539221d0
Rollup merge of #78524 - tmiasko:source-files-borrow, r=Aaron1011
Avoid BorrowMutError with RUSTC_LOG=debug

```console
$ touch empty.rs
$ env RUSTC_LOG=debug rustc +stage1 --crate-type=lib empty.rs
```

Fails with a `BorrowMutError` because source map files are already
borrowed while `features_query` attempts to format a log message
containing a span.

Release the borrow before the query to avoid the issue.
2020-10-30 18:00:54 +09:00
Yuki Okushi
8111706c18
Rollup merge of #78523 - estebank:fix-return-type-parse-regression, r=dtolnay
Revert invalid `fn` return type parsing change

Revert one of the changes in #78379.

Fix #78507.
2020-10-30 18:00:53 +09:00
Yuki Okushi
439ea4b621
Rollup merge of #77888 - LingMan:ast_pretty_tt_prepend_space, r=jyn514
Simplify a nested bool match

Logically this first eliminates the innermost match by merging the patterns.
Then, in a second step, turns the newly innermost match into a `matches!` call.
2020-10-30 18:00:45 +09:00
bors
8df58ae03a Auto merge of #78393 - SNCPlay42:match-if-guard, r=tmandry
Always record reference to binding in match if guards

When encountering a binding from a `match` pattern in its `if` guard when computing a generator's interior types, we must always record the type of a reference to the binding because of how `if` guards are lowered to MIR. This was missed in #75213 because the binding in that test case was autorefed and we recorded that adjusted type anyway.

Fixes #78366
2020-10-30 07:05:57 +00:00
Camelid
f558d96253 Link to pass docs from NRVO module docs 2020-10-29 23:05:45 -07:00
bors
0d33ab7af4 Auto merge of #78432 - sexxi-goose:fix-77993-take3, r=nikomatsakis
Handle type errors in closure/generator upvar_tys

Fixes #77993
2020-10-30 03:00:13 +00:00
Tomasz Miąsko
b816e5dfb4 validator: Extend aliasing check to a call terminator 2020-10-30 00:00:00 +00:00
Jack Huey
41ce397990 Make anonymous binders start at 0 2020-10-29 18:50:23 -04:00
bors
a3d7a5e945 Auto merge of #78528 - jonas-schievink:rollup-e70g9zk, r=jonas-schievink
Rollup of 11 pull requests

Successful merges:

 - #75078 (Improve documentation for slice strip_* functions)
 - #76138 (Explain fully qualified syntax for `Rc` and `Arc`)
 - #78244 (Dogfood {exclusive,half-open} ranges in compiler (nfc))
 - #78422 (Do not ICE on invalid input)
 - #78423 (rustc_span: improve bounds checks in byte_pos_to_line_and_col)
 - #78431 (Prefer new associated numeric consts in float error messages)
 - #78462 (Use unwrapDIPtr because the Scope may be null.)
 - #78493 (Update cargo)
 - #78499 (Prevent String::retain from creating non-utf8 strings when abusing panic)
 - #78505 (Update Clippy - temporary_cstring_as_ptr deprecation)
 - #78527 (Fix some more typos)

Failed merges:

r? `@ghost`
2020-10-29 20:56:25 +00:00
bors
6bdae9edd0 Auto merge of #78508 - wesleywiser:optimize_visit_scopes, r=petrochenkov
[resolve] Use `unwrap_or_else` instead of `unwrap_or` in a hot path

This improves the performance of the `resolve_crate` function by 30% for
a very large single file crate with auto-generated C bindings.

cc `@rylev`
2020-10-29 18:34:59 +00:00
Josh Stone
dcbf2f324f rustc_llvm: unwrap LLVMMetadataRef before casting
Directly casting the opaque pointer was [reported] to cause an
"incomplete type" error with GCC 9.3:

```
llvm-wrapper/RustWrapper.cpp:939:31:   required from here
/usr/include/c++/9.3/type_traits:1301:12: error: invalid use of incomplete type 'struct LLVMOpaqueMetadata'
 1301 |     struct is_base_of
      |            ^~~~~~~~~~
In file included from [...]/rust/src/llvm-project/llvm/include/llvm-c/BitReader.h:23,
                 from llvm-wrapper/LLVMWrapper.h:1,
                 from llvm-wrapper/RustWrapper.cpp:1:
[...]/rust/src/llvm-project/llvm/include/llvm-c/Types.h:89:16: note: forward declaration of 'struct LLVMOpaqueMetadata'
   89 | typedef struct LLVMOpaqueMetadata *LLVMMetadataRef;
      |                ^~~~~~~~~~~~~~~~~~
```

[reported]: https://zulip-archive.rust-lang.org/182449tcompilerhelp/12215halprustcllvmbuildfail.html#214915124

A simple `unwrap` fixes the issue.
2020-10-29 09:45:15 -07:00
Jonas Schievink
e656e609ba
Rollup merge of #78527 - bugadani:typo3, r=jonas-schievink
Fix some more typos
2020-10-29 17:05:31 +01:00
Jonas Schievink
38c34098b1
Rollup merge of #78462 - danielframpton:fixnullisa, r=nagisa
Use unwrapDIPtr because the Scope may be null.

I ran into an assertion when using debug information on Windows with LLVM assertions enabled.

It seems like we are using unwrap here (which in turn calls isa and requires the pointer to be non-null) but we expect the value to be null because that is what we are passing from rustc.

This change uses unwrapDIPtr which explicitly allows nullptr.

The FFI prototype for this method on the rust side has the `LLVMMetadataRef` parameter as `Scope: Option<&'a DIScope>`, and we always pass `None` when `msvc_like_names` is true.
2020-10-29 17:05:23 +01:00
Jonas Schievink
31cfe63fb9
Rollup merge of #78431 - Rustin-Liu:rustin-patch-lint, r=estebank
Prefer new associated numeric consts in float error messages

Fix https://github.com/rust-lang/rust/issues/78382
2020-10-29 17:05:21 +01:00
Jonas Schievink
151db25599
Rollup merge of #78423 - tgnottingham:caching_source_map_bounds_check, r=oli-obk
rustc_span: improve bounds checks in byte_pos_to_line_and_col

The effect of this change is to consider edge-case spans that start or
end at the position one past the end of a file to be valid during span
hashing and encoding. This change means that these spans will be
preserved across incremental compilation sessions when they are part of
a serialized query result, instead of causing the dummy span to be used.
2020-10-29 17:05:17 +01:00
Jonas Schievink
7fa9e39682
Rollup merge of #78422 - estebank:fix-78372, r=pnkfelix
Do not ICE on invalid input

Fix #78372.
2020-10-29 17:05:14 +01:00
Jonas Schievink
9867e54bea
Rollup merge of #78244 - workingjubilee:dogfood-fancy-ranges, r=varkor
Dogfood {exclusive,half-open} ranges in compiler (nfc)

In particular, this allows us to write more explicit matches that
avoid the pitfalls of using a fully general fall-through case, yet
remain fairly ergonomic. Less logic is in guard cases, more is in
the actual exhaustive case analysis.

No functional changes.
2020-10-29 17:05:11 +01:00
Dániel Buga
3fba948510 Fix typos 2020-10-29 16:51:46 +01:00
Aaron Hill
4ba57aa703
Strip tokens from trait and impl items before printing AST JSON
Fixes #78510
2020-10-29 11:39:38 -04:00
Esteban Küber
f9a26643ec Revert invalid fn return type parsing change
Fix #78507.
2020-10-29 08:26:42 -07:00
bors
49720d2b9a Auto merge of #78512 - JohnTitor:rollup-a7qwjah, r=JohnTitor
Rollup of 11 pull requests

Successful merges:

 - #77213 (rustdoc options to set default theme (and other settings))
 - #78224 (min_const_generics: allow ty param in repeat expr)
 - #78428 (MinConstGenerics UI test for invalid values for bool & char)
 - #78460 (Adjust turbofish help message for const generics)
 - #78470 (Clean up intra-doc links in `std::path`)
 - #78475 (fix a comment in validity check)
 - #78478 (Add const generics tests for supertraits + dyn traits.)
 - #78487 (Fix typo "compiltest")
 - #78491 (Inline NonZeroN::from(n))
 - #78492 (Update books)
 - #78494 (Fix typos)

Failed merges:

r? `@ghost`
2020-10-29 03:57:54 +00:00
Jubilee Young
0e88db7db4 Dogfood {exclusive,half-open} ranges in compiler (nfc)
In particular, this allows us to write more explicit matches that
avoid the pitfalls of using a fully general fall-through case, yet
remain fairly ergonomic. Less logic is in guard cases, more is in
the actual exhaustive case analysis.

No functional changes.
2020-10-28 20:09:20 -07:00
Yuki Okushi
30d1d8f5da
Rollup merge of #78494 - bugadani:typo2, r=jonas-schievink
Fix typos
2020-10-29 12:09:03 +09:00
Yuki Okushi
5e3cc6e913
Rollup merge of #78475 - RalfJung:validity-comment, r=oli-obk
fix a comment in validity check

A few things changed since that comment was written; update it to the current reality.

r? @oli-obk
2020-10-29 12:08:55 +09:00
Yuki Okushi
a7a0538802
Rollup merge of #78460 - varkor:turbofish-string-generic, r=lcnr
Adjust turbofish help message for const generics

Types are no longer special. (This message arguably only makes sense with `min_const_generics` or more, but we'll be there soon.)

r? @lcnr
2020-10-29 12:08:50 +09:00
Yuki Okushi
270d2e0c2e
Rollup merge of #78224 - lcnr:repeat-expr, r=varkor
min_const_generics: allow ty param in repeat expr

implements https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/repeat.20expressions

Even with `min_const_generics` active, now keeps resulting in future compat warnings instead of hard errors.
Const parameters, for example `[0; N + 1]`, still result in hard errors during resolve.
```rust
#![allow(dead_code)]

fn foo<T>() {
    [0; std::mem::size_of::<*mut T>()];
}

struct Foo<T>(T);

impl<T> Foo<T> {
    const ASSOC: usize = 4;

    fn test() {
        [0; Self::ASSOC];
    }
}
```

r? @varkor cc @petrochenkov
2020-10-29 12:08:40 +09:00
Wesley Wiser
1c1c591c81 [resolve] Use unwrap_or_else instead of unwrap_or in a hot path
This improves the performance of the `resolve_crate` function by 30% for
a very large single file crate with auto-generated C bindings.
2020-10-28 21:53:25 -04:00
bors
f9187adaef Auto merge of #78430 - Nadrieril:taking-constructors-seriously2, r=varkor
Clarify main code paths in exhaustiveness checking

This PR massively clarifies the main code paths of exhaustiveness checking, by using the `Constructor` enum to a fuller extent. I've been itching to write it for more than a year, but the complexity of matching consts had prevented me. Behold a massive simplification :D.
This in particular removes a fair amount of duplication between various parts, localizes code into methods of relevant types when applicable, makes some implicit assumptions explicit, and overall improves legibility a lot (or so I hope). Additionally, after my changes undoing #76918 turned out to be a noticeable perf gain.

As usual I tried my best to make the commits self-contained and easy to follow. I've also tried to keep the code well-commented, but I tend to forget how complex this file is; I'm happy to clarify things as needed.
My measurements show good perf improvements on the two match-heavy benchmarks (-18.0% on `unicode_normalization-check`! :D); I'd like a perf run to check the overall impact.

r? `@varkor`
`@rustbot` modify labels: +A-exhaustiveness-checking
2020-10-29 01:37:49 +00:00
Tomasz Miąsko
79cc5099b1 Use RwLock instead of Lock for SourceMap::files 2020-10-29 18:09:53 +01:00
Tomasz Miąsko
2661a4edb9 Avoid BorrowMutError with RUSTC_LOG=debug
$ touch empty.rs
$ env RUSTC_LOG=debug rustc +stage1 --crate-type=lib empty.rs

Fails with a `BorrowMutError` because source map files are already
borrowed while `features_query` attempts to format a log message
containing a span.

Release the borrow before the query to avoid the issue.
2020-10-29 18:09:53 +01:00
bors
31ee872db5 Auto merge of #78415 - tgnottingham:expn_id_tag_hash, r=Aaron1011
rustc_span: avoid hashing ExpnId tag when using cached hash
2020-10-28 20:03:55 +00:00
Nadrieril
41a74ace4a Apply suggestions from code review
Co-authored-by: Who? Me?! <mark-i-m@users.noreply.github.com>
Co-authored-by: varkor <github@varkor.com>
2020-10-28 19:08:01 +00:00
Dániel Buga
0fabbf9713 Fix typos 2020-10-28 19:32:28 +01:00
bors
3dddf6ac1e Auto merge of #78414 - nox:function-sections, r=nagisa,bjorn3
Implement -Z function-sections=yes|no

This lets rustc users tweak whether all functions should be put in their own TEXT section, using whatever default value the target defines if the flag is missing.

I'm having fun experimenting with musl libc and trying to implement the start symbol in Rust, that means avoiding code that requires relocations, and AFAIK putting everything in its own section makes the toolchain generate `GOTPCREL` relocations for symbols that could use plain old PC-relative addressing (at least on `x86_64`) if they were all in the same section.
2020-10-28 17:47:36 +00:00
Dániel Buga
a8803d3c04 Delete files immediately, instead of collecting into vector 2020-10-28 17:22:10 +01:00
Dániel Buga
2fa359814a Avoid reallocating cgu_path_components 2020-10-28 17:22:10 +01:00
Dániel Buga
5248b20d9a Reuse memory 2020-10-28 17:22:10 +01:00
Dániel Buga
a21f3a76a9 Clean up encode_dep_graph 2020-10-28 17:22:05 +01:00
Dániel Buga
f3e6d882fe Fix typos and replace static vector with slice 2020-10-28 16:42:28 +01:00
varkor
a6d01da716 Remove irrelevant FIXME 2020-10-28 10:47:27 +00:00
varkor
6c73adf324 Adjust turbofish help message for const generics 2020-10-28 10:47:27 +00:00
Ralf Jung
c90ef979de fix a comment in validity check 2020-10-28 10:39:21 +01:00
bors
2eb4fc800a Auto merge of #78323 - est31:smaller_list_overlap, r=varkor
Iterate over the smaller list

If there are two lists of different sizes,
iterating over the smaller list and then
looking up in the larger list is cheaper
than vice versa, because lookups scale
sublinearly.
2020-10-28 03:58:32 +00:00
bors
db241bb0c8 Auto merge of #78458 - Dylan-DPC:rollup-tan044s, r=Dylan-DPC
Rollup of 10 pull requests

Successful merges:

 - #78152 (Separate unsized locals)
 - #78297 (Suggest calling await on method call and field access)
 - #78351 (Move "mutable thing in const" check from interning to validity)
 - #78365 (check object safety of generic constants)
 - #78379 (Tweak invalid `fn` header and body parsing)
 - #78391 (Add const_fn in generics test)
 - #78401 (resolve: private fields in tuple struct ctor diag)
 - #78408 (Remove tokens from foreign items in `TokenStripper`)
 - #78447 (Fix typo in  comment)
 - #78453 (Fix typo in comments)

Failed merges:

r? `@ghost`
2020-10-28 01:40:06 +00:00
Daniel Frampton
a3bff69134 Use unwrapDIPtr because the Scope may be passed as None 2020-10-27 18:05:16 -07:00
Dylan DPC
6967005e6e
Rollup merge of #78453 - Storyyeller:patch-1, r=jonas-schievink
Fix typo in comments
2020-10-28 01:21:39 +01:00
Dylan DPC
3349b6847f
Rollup merge of #78447 - bugadani:typo, r=matthewjasper
Fix typo in  comment

I hope I got all the typos in that word. :)
2020-10-28 01:21:37 +01:00
Dylan DPC
14b4ed20c7
Rollup merge of #78408 - Aaron1011:fix/remove-foreign-tokens, r=oli-obk
Remove tokens from foreign items in `TokenStripper`

Fixes #78398

I forgot to handle this case in #77255
2020-10-28 01:21:34 +01:00
Dylan DPC
c9279c845d
Rollup merge of #78401 - davidtwco:issue-75906-tuple-construct-private-field, r=estebank
resolve: private fields in tuple struct ctor diag

Fixes #75906.

This PR improves the diagnostic emitted when a tuple struct is being constructed which has private fields so that private fields are labelled and the message is improved.

r? @estebank
2020-10-28 01:21:31 +01:00
Dylan DPC
892ebe9afe
Rollup merge of #78379 - estebank:fn-signature-parse, r=varkor
Tweak invalid `fn` header and body parsing

* Rely on regular "expected"/"found" parser error for `fn`, fix #77115
* Recover empty `fn` bodies when encountering `}`
* Recover trailing `>` in return types
* Recover from non-type in array type `[<BAD TOKEN>; LEN]`
2020-10-28 01:21:24 +01:00
Dylan DPC
1a64e570c6
Rollup merge of #78365 - lcnr:const-eval-obj-safety, r=oli-obk
check object safety of generic constants

As `Self` can only be effectively used in constants with `const_evaluatable_checked` this should not matter outside of it.

Implements the first item of #72219

> Object safety interactions with constants

r? @oli-obk for now cc @nikomatsakis
2020-10-28 01:21:21 +01:00
Dylan DPC
54ea0f9ccd
Rollup merge of #78351 - RalfJung:validity-unsafe-cell, r=oli-obk
Move "mutable thing in const" check from interning to validity

This moves the check for mutable things (such as `UnsafeCell` or `&mut`) in a`const` from interning to validity. That means we can give more targeted error messages (pointing out *where* the problem lies), and we can simplify interning a bit.

Also fix the interning mode used for promoteds in statics.

r? @oli-obk
2020-10-28 01:21:18 +01:00
Dylan DPC
86a4a38177
Rollup merge of #78297 - estebank:match-semicolon-2, r=oli-obk
Suggest calling await on method call and field access

When encountering a failing method or field resolution on a `Future`,
look at the `Output` and try the same operation on it. If successful,
suggest calling `.await` on the `Future`.

This had already been introduced in #72784, but at some point they
stopped working.

Built on top of #78214, only last commit is relevant.

r? @oli-obk
2020-10-28 01:21:10 +01:00
Dylan DPC
346aeef496
Rollup merge of #78152 - spastorino:separate-unsized-locals, r=oli-obk
Separate unsized locals

Closes #71694

Takes over again #72029 and #74971

cc @RalfJung @oli-obk @pnkfelix @eddyb as they've participated in previous reviews of this PR.
2020-10-28 01:21:08 +01:00
Roxane
5229571a05 Address comments 2020-10-27 19:42:02 -04:00
bors
90e6d0d46b Auto merge of #75671 - nathanwhit:cstring-temp-lint, r=oli-obk
Uplift `temporary-cstring-as-ptr` lint from `clippy` into rustc

The general consensus seems to be that this lint covers a common enough mistake to warrant inclusion in rustc.
The diagnostic message might need some tweaking, as I'm not sure the use of second-person perspective matches the rest of rustc, but I'd like to hear others' thoughts on that.

(cc #53224).

r? `@oli-obk`
2020-10-27 22:59:13 +00:00
Tyson Nottingham
47dad31a04 rustc_span: represent line bounds with Range 2020-10-27 15:47:29 -07:00
Robert Grosse
710c1f4aca
Fix typo in comments 2020-10-27 14:23:58 -07:00
Ryan Levick
81444b2049 Remove some cruft from foreign_modules refactor 2020-10-27 20:17:48 +01:00
Santiago Pastorino
00fd703eb7
Use unsized_feature_enabled helper function 2020-10-27 14:45:42 -03:00
Santiago Pastorino
9584b00b1d
is -> are both 2020-10-27 14:45:41 -03:00
Santiago Pastorino
89eac50a87
Hide outermost_fn_param_pat, it's an internal detail 2020-10-27 14:45:40 -03:00
Santiago Pastorino
f0fe0a6eba
or -> and 2020-10-27 14:45:40 -03:00
Santiago Pastorino
497ee0e1ff
param -> parameter, pat -> pattern 2020-10-27 14:45:39 -03:00
Santiago Pastorino
bdd1b85f95
Rename within_fn_param to outermost_fn_param_pat 2020-10-27 14:45:39 -03:00
Santiago Pastorino
ca41681bf0
Do not use unsized_fn_params in patterns 2020-10-27 14:45:38 -03:00
Santiago Pastorino
58018d438b
Properly restore within_fn_param value to the previous state 2020-10-27 14:45:38 -03:00
Santiago Pastorino
953d7a64a5
Add unsized_locals to INCOMPLETE_FEATURES list 2020-10-27 14:45:28 -03:00
Santiago Pastorino
708fc3b1a2
Add unsized_fn_params feature 2020-10-27 14:45:02 -03:00
Dániel Buga
b01c74b73c Fix typo in vec_graph 2020-10-27 18:37:43 +01:00
Dániel Buga
99320b9404 Fix typos in arena comments 2020-10-27 18:14:21 +01:00
bors
07e968b640 Auto merge of #76269 - ayrtonm:function-reference-lint, r=oli-obk
added a lint against function references

this lint suggests casting function references to `*const ()`
closes #75239
r? `@RalfJung`
2020-10-27 16:32:23 +00:00
Dániel Buga
da64d07191 Fix typo in comment 2020-10-27 17:08:14 +01:00
Ryan Levick
69dc98161a Cache foreign_modules query 2020-10-27 16:21:55 +01:00
Ayrton
c791c64e84 Added suggestion to function_item_references lint and fixed warning message
Also updated tests accordingly and tweaked some wording in the lint declaration.
2020-10-27 11:04:04 -04:00
Ayrton
935fc3642a Added documentation for function_item_references lint
Added documentation for `function_item_references` lint to the rustc book and
fixed comments in the lint checker itself.
2020-10-27 11:04:04 -04:00
Ayrton
d6fa7e15d6 Fixed compiler error in lint checker triggered by associated types
When a function argument bound by `Pointer` is an associated type, we only
perform substitutions using the parameters from the callsite but don't attempt
to normalize since it may not succeed. A simplified version of the scenario that
triggered this error was added as a test case. Also fixed `Pointer::fmt` which
was being double-counted when called outside of macros and added a test case for
this.
2020-10-27 11:04:04 -04:00
Ayrton
432ebd57ef Removed test for unhandled case in function_item_references lint
Removed test for the unhandled case of calls to `fn f<T>(x: &T)` where `x` is a
function reference and is formatted as a pointer in `f`. This compiles since
`&T` implements `Pointer`, but is unlikely to occur in practice. Also tweaked
the lint's wording and modified tests accordingly.
2020-10-27 11:04:04 -04:00
Ayrton
511fe048b4 Changed lint to check for std::fmt::Pointer and transmute
The lint checks arguments in calls to `transmute` or functions that have
`Pointer` as a trait bound and displays a warning if the argument is a function
reference. Also checks for `std::fmt::Pointer::fmt` to handle formatting macros
although it doesn't depend on the exact expansion of the macro or formatting
internals. `std::fmt::Pointer` and `std::fmt::Pointer::fmt` were also added as
diagnostic items and symbols.
2020-10-27 11:04:04 -04:00
Ayrton
3214de7359 modified lint to work with MIR
Working with MIR let's us exclude expressions like `&fn_name as &dyn Something`
and `(&fn_name)()`. Also added ABI, unsafety and whether a function is variadic
in the lint suggestion, included the `&` in the span of the lint and updated the
test.
2020-10-27 11:04:04 -04:00
Ayrton
975547d475 changed lint to suggest casting to the proper function type and added a test 2020-10-27 11:04:03 -04:00
Ayrton
dd4d4e29c3 added a lint against function references
this lint suggests casting function references to `*const ()`
2020-10-27 11:04:03 -04:00
oli
888ef24c22 Address review comment 2020-10-27 14:16:23 +00:00
Oliver Scherer
c8a866ea17 Show the inline stack of MIR lints that only occur after inlining 2020-10-27 14:08:07 +00:00
bors
2a71e45411 Auto merge of #78434 - jonas-schievink:disable-miropt, r=wesleywiser
Disable "optimization to avoid load of address" in InstCombine

Same as #78195, fixes https://github.com/rust-lang/rust/issues/78192 (again).
2020-10-27 13:57:54 +00:00
bors
56d288fa46 Auto merge of #78227 - SergioBenitez:test-stdout-threading, r=m-ou-se
Capture output from threads spawned in tests

This is revival of #75172.

Original text:
> Fixes #42474.
>
> r? `@​dtolnay` since you expressed interest in this, but feel free to redirect if you aren't the right person anymore.

---

Closes #75172.
2020-10-27 11:43:18 +00:00
Jonas Schievink
0be35cf9c7 Disable "optimization to avoid load of address" in InstCombine 2020-10-27 10:59:28 +01:00
bors
20b1e05a8d Auto merge of #77502 - varkor:const-generics-suggest-enclosing-braces, r=petrochenkov
Suggest that expressions that look like const generic arguments should be enclosed in brackets

I pulled out the changes for const expressions from https://github.com/rust-lang/rust/pull/71592 (without the trait object diagnostic changes) and made some small changes; the implementation is `@estebank's.`

We're also going to want to make some changes separately to account for trait objects (they result in poor diagnostics, as is evident from one of the test cases here), such as an adaption of https://github.com/rust-lang/rust/pull/72273.

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

r? `@petrochenkov`
2020-10-27 09:25:54 +00:00
Dániel Buga
caf9131e65 Query span as late as possible 2020-10-27 10:17:01 +01:00
Aman Arora
f0ae24e100 Handle type errors in closure/generator upvar_tys
Co-authored-by: Roxane Fruytier <roxane.fruytier@hotmail.com>
2020-10-27 03:13:11 -04:00
bors
824f900a96 Auto merge of #77317 - varkor:break-diverging-value, r=nikomatsakis
Fix control flow check for breaking with diverging values

Fixes https://github.com/rust-lang/rust/issues/77156.
2020-10-27 07:10:55 +00:00
Rustin-Liu
650e3cb176 Prefer new associated numeric consts in float error messages 2020-10-27 14:14:08 +08:00
Nadrieril
766ab78a1c Simplify slice splitting a bit 2020-10-27 03:27:11 +00:00
Nadrieril
cd4c7144de Deduplicate work between splitting and subtraction
After splitting, subtraction becomes much simpler
2020-10-27 03:27:11 +00:00
Nadrieril
1fab669f8d Be honest about being able to list constructors
The test change is because we used to treat `&str` like other `&T`s, ie
as having a single constructor. That's not quite true though since we
consider `&str` constants as atomic instead of refs to `str` constants.
2020-10-27 03:09:55 +00:00
Nadrieril
db9a8480c4 Simplify specialize_constructor
Also removes the ugly caching that was introduced in #76918. It was
bolted on without deeper knowledge of the workings of the algorithm.
This commit manages to be more performant without any of the complexity.
It should be better on representative workloads too.
2020-10-27 03:08:38 +00:00
bors
28f03ac4c0 Auto merge of #78421 - JohnTitor:rollup-bq2d7fo, r=JohnTitor
Rollup of 16 pull requests

Successful merges:

 - #76635 (Add [T]::as_chunks(_mut))
 - #77703 (add system-llvm-libunwind config option)
 - #78219 (Prefer to use `print_def_path`)
 - #78298 (Add test for bad NLL higher-ranked subtype)
 - #78332 (Update description for error E0308)
 - #78342 (Use check-pass in single-use-lifetime ui tests)
 - #78347 (Add lexicographical comparison doc)
 - #78348 (Make some functions private that don't have to be public)
 - #78349 (Use its own `TypeckResults` to avoid ICE)
 - #78375 (Use ? in core/std macros)
 - #78377 (Fix typo in debug statement)
 - #78388 (Add some regression tests)
 - #78394 (fix(docs): typo in BufWriter documentation)
 - #78396 (Add compiler support for LLVM's x86_64 ERMSB feature)
 - #78405 (Fix typo in lint description)
 - #78412 (Improve formatting of hash collections docs)

Failed merges:

r? `@ghost`
2020-10-27 01:36:12 +00:00
Nadrieril
54fa70290d Unify the paths through is_useful 2020-10-27 00:49:32 +00:00
Nadrieril
c96bd28ab3 Recompute MissingConstructors when needed
This only happens in a slow (diagnostics) path, so the code clarity gain
is worth it.
2020-10-27 00:46:33 +00:00
Nadrieril
b49f90760d Pass more things through PatCtxt
This is even a perf improvement on the match-heavy benchmarks.
2020-10-27 00:46:33 +00:00
Nadrieril
cdafd1e1bd Let MissingConstructors handle the subtleties of missing constructors 2020-10-27 00:46:32 +00:00
Nadrieril
1190e7275c Cache head constructor in PatStack
Since the constructor is recomputed a lot, caching is worth it.
2020-10-27 00:46:32 +00:00
Nadrieril
833089fbc9 Unify the two kinds of specialization by adding a Wildcard ctor 2020-10-27 00:46:32 +00:00
Nadrieril
41e7ca499d Inline specialize_one_pattern 2020-10-27 00:46:32 +00:00
Nadrieril
c511955a9f Factor out the two specialization steps 2020-10-27 00:46:32 +00:00
Nadrieril
6ad9f44a50 Clarify specialization into two steps
First is checking for constructor overlap, second is extracting the
resulting fields.
2020-10-27 00:46:32 +00:00
Nadrieril
7c4f94be48 Use pat_constructor to simplify specialize_one_pattern 2020-10-27 00:46:32 +00:00
Nadrieril
feb1e13960 Split split_grouped_constructor into smaller functions 2020-10-27 00:46:32 +00:00
Esteban Küber
cd259dbd19 Do not ICE on invalid input 2020-10-26 17:42:46 -07:00
Yuki Okushi
7824d9abbd
Rollup merge of #78405 - notriddle:patch-3, r=lcnr
Fix typo in lint description
2020-10-27 08:45:27 +09:00
Yuki Okushi
46b8e46fe1
Rollup merge of #78396 - josephlr:ermsb, r=petrochenkov
Add compiler support for LLVM's x86_64 ERMSB feature

This change is needed for compiler-builtins to check for this feature
when implementing memcpy/memset. See:
  https://github.com/rust-lang/compiler-builtins/pull/365

Without this change, the following code compiles, but does nothing:
```rust
#[cfg(target_feature = "ermsb")]
pub unsafe fn ermsb_memcpy() { ... }
```

The change just does compile-time detection. I think that runtime
detection will have to come in a follow-up CL to std-detect.

Like all the CPU feature flags, this just references #44839

Signed-off-by: Joe Richey <joerichey@google.com>
2020-10-27 08:45:24 +09:00
Yuki Okushi
b72d70ef61
Rollup merge of #78377 - LeSeulArtichaut:patch-docs, r=jonas-schievink
Fix typo in debug statement
2020-10-27 08:45:14 +09:00
Yuki Okushi
6abd2a59e7
Rollup merge of #78349 - JohnTitor:issue-75962, r=davidtwco
Use its own `TypeckResults` to avoid ICE

Fixes #75962
2020-10-27 08:45:07 +09:00
Yuki Okushi
0b72ca6ea6
Rollup merge of #78332 - PoignardAzur:doc_E0308, r=camelid
Update description for error E0308

Fixes #76462

r? @camelid
2020-10-27 08:44:54 +09:00
Yuki Okushi
f3c94374b9
Rollup merge of #78219 - JohnTitor:print-def-path, r=estebank
Prefer to use `print_def_path`

Follow-up of https://github.com/rust-lang/rust/pull/71310#discussion_r415438577
2020-10-27 08:44:47 +09:00
Tyson Nottingham
df59a44fea rustc_span: improve bounds checks in byte_pos_to_line_and_col
The effect of this change is to consider edge-case spans that start or
end at the position one past the end of a file to be valid during span
hashing and encoding. This change means that these spans will be
preserved across incremental compilation sessions when they are part of
a serialized query result, instead of causing the dummy span to be used.
2020-10-26 16:34:04 -07:00
Esteban Küber
9e16213610 Suggest calling associated fn inside traits
When calling a function that doesn't exist inside of a trait's
associated `fn`, and another associated `fn` in that trait has that
name, suggest calling it with the appropriate fully-qualified path.

Expand the label to be more descriptive.

Prompted by the following user experience:
https://users.rust-lang.org/t/cannot-find-function/50663
2020-10-26 16:31:11 -07:00
bors
a4d30a7b49 Auto merge of #77876 - tmiasko:simplify-locals, r=wesleywiser
Remove unused set-discriminant statements and assignments regardless of rvalue

* Represent use counts with u32
* Unify use count visitors
* Change RemoveStatements visitor into a function
* Remove unused set-discriminant statements
* Use exhaustive match to clarify what is being optimized
* Remove unused assignments regardless of rvalue kind
2020-10-26 23:22:39 +00:00
Anthony Ramine
056942215c Implement -Z function-sections=yes|no
This lets rustc users tweak whether all functions should be put in their own
TEXT section, using whatever default value the target defines if the flag
is missing.
2020-10-26 23:26:43 +01:00
Nathan Whitaker
6ba127d3f0 Fix doctest 2020-10-26 18:19:49 -04:00
Nathan Whitaker
576eb2a30c Write docs for lint / fix review nit 2020-10-26 18:19:48 -04:00
Nathan Whitaker
1bcd2452fe Address review comments 2020-10-26 18:19:48 -04:00
Nathan Whitaker
737bfeffd2 Change to warn by default / fix typo 2020-10-26 18:19:48 -04:00
Nathan Whitaker
5643a0662a Tweak diagnostic 2020-10-26 18:19:47 -04:00
Nathan Whitaker
8b65df06ce Address review comments 2020-10-26 18:19:47 -04:00
Nathan Whitaker
8cf1b0e1ad Uplift temporary-cstring-as-ptr into rustc 2020-10-26 18:19:40 -04:00
varkor
ac1454001c Suggest expressions that look like const generic arguments should be enclosed in brackets
Co-Authored-By: Esteban Kuber <github@kuber.com.ar>
2020-10-26 21:54:45 +00:00
Tyson Nottingham
a3623e0542 rustc_span: avoid hashing ExpnId tag when using cached hash 2020-10-26 13:43:48 -07:00
Anthony Ramine
53fa22a6fb Fix some outdated comments 2020-10-26 20:57:05 +01:00
Aaron Hill
174ed0c23d
Remove tokens from foreign items in TokenStripper
Fixes #78398

I forgot to handle this case in #77255
2020-10-26 15:06:54 -04:00
bors
0da6d42f29 Auto merge of #68965 - eddyb:mir-inline-scope, r=nagisa,oli-obk
rustc_mir: track inlined callees in SourceScopeData.

We now record which MIR scopes are the roots of *other* (inlined) functions's scope trees, which allows us to generate the correct debuginfo in codegen, similar to what LLVM inlining generates.
This PR makes the `ui` test `backtrace-debuginfo` pass, if the MIR inliner is turned on by default.

Also, `#[track_caller]` is now correct in the face of MIR inlining (cc `@anp).`

Fixes #76997.

r? `@rust-lang/wg-mir-opt`
2020-10-26 18:50:22 +00:00
Michael Howell
74a9891235
Fix typo in lint description 2020-10-26 11:46:11 -07:00
Ethan Brierley
e750238404 Fix typo 2020-10-26 18:16:25 +00:00
Ethan Brierley
ad2d93da1f Apply suggested changes 2020-10-26 18:14:12 +00:00
bors
35debd4c11 Auto merge of #77975 - bjorn3:cg_clif_subtree3, r=Mark-Simulacrum
Add cg_clif as optional codegen backend

Rustc_codegen_cranelift is an alternative codegen backend for rustc based on Cranelift. It has the potential to improve compilation times in debug mode. In my experience the compile time improvements over debug mode LLVM for a clean build are about 20-30% in most cases.

This PR adds cg_clif as optional codegen backend. By default it is only enabled for `./x.py check`. It can be enabled for `./x.py build` too by adding `cranelift` to the `rust.codegen-backends` array in `config.toml`.

MCP: https://github.com/rust-lang/compiler-team/issues/270

r? `@Mark-Simulacrum`
2020-10-26 16:31:38 +00:00
Esteban Küber
28f02fbf3e Suggest calling await on method call and field access
When encountering a failing method or field resolution on a `Future`,
look at the `Output` and try the same operation on it. If successful,
suggest calling `.await` on the `Future`.

This had already been introduced in #72784, but at some point they
stopped working.
2020-10-26 08:11:43 -07:00
David Wood
27bb27f71c
resolve: private fields in tuple struct ctor diag
This commit improves the diagnostic emitted when a tuple struct is being
constructed which has private fields so that private fields are
labelled and the message is improved.

Signed-off-by: David Wood <david@davidtw.co>
2020-10-26 14:56:27 +00:00
Bastian Kauschke
60bcc58dce debug log AbstractConst::new 2020-10-26 14:56:58 +01:00
oli
7101ce9127 Deduplicate span and dbg_scope adjustment 2020-10-26 13:04:52 +00:00
oli
f8aae50469 Prefer bug! over unwrap() 2020-10-26 12:49:49 +00:00
Joe Richey
ad552bc17e
Add compiler support for LLVM's x86 ERMSB feature
This change is needed for compiler-builtins to check for this feature
when implementing memcpy/memset. See:
  https://github.com/rust-lang/compiler-builtins/pull/365

The change just does compile-time detection. I think that runtime
detection will have to come in a follow-up CL to std-detect.

Like all the CPU feature flags, this just references #44839

Signed-off-by: Joe Richey <joerichey@google.com>
2020-10-26 03:46:54 -07:00
Tomasz Miąsko
4c3e06a0ba simplify-locals: Remove unused assignments regardless of rvalue kind 2020-10-26 10:48:28 +01:00
Tomasz Miąsko
52d3782685 simplify-locals: Remove unused set-discriminant statements
Update affected ui & incremental tests to use a user declared variable
bindings instead of temporaries. The former are preserved because of
debuginfo, the latter are not.
2020-10-26 10:41:44 +01:00
Tomasz Miąsko
e1e48ae29b simplify-locals: Change RemoveStatements visitor into a function
No functionl changes intended.
2020-10-26 10:33:45 +01:00
Tomasz Miąsko
a6b64be8b5 simplify-locals: Unify use count visitors
The simplify locals implementation uses two different visitors to update
the locals use counts. The DeclMarker calculates the initial use counts.
The StatementDeclMarker updates the use counts as statements are being
removed from the block.

Replace them with a single visitor that can operate in either mode,
ensuring consistency of behaviour.

Additionally use exhaustive match to clarify what is being optimized.

No functional changes intended.
2020-10-26 10:33:39 +01:00
Tomasz Miąsko
11269536e2 simplify-locals: Represent use counts with u32 2020-10-26 10:33:31 +01:00
SNCPlay42
8bf9abbb7b always record reference to binding in match if guards 2020-10-26 09:29:50 +00:00
bors
b9a94c919b Auto merge of #78324 - RalfJung:uninhabited-statics, r=oli-obk
ensure that statics are inhabited

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

r? `@oli-obk`
2020-10-26 09:11:34 +00:00
bjorn3
ac4f7deb2f Add 'compiler/rustc_codegen_cranelift/' from commit '793d26047f994e23415f8f6bb5686ff25d3dda92'
git-subtree-dir: compiler/rustc_codegen_cranelift
git-subtree-mainline: cf798c1ec6
git-subtree-split: 793d26047f
2020-10-26 09:53:27 +01:00
bjorn3
cf798c1ec6 Add support for using cg_clif to bootstrap rustc 2020-10-26 09:52:59 +01:00
Ralf Jung
744dfd8847 explain why interning is not as trivial as it might seem 2020-10-26 08:56:54 +01:00
Ralf Jung
18fd58e9d1 interning cleanup: we no longer need to distinguish Const and ConstInner; we no longer need the ignore_interior_mut_in_const hack 2020-10-26 08:56:54 +01:00
Ralf Jung
9b501edf08 move &mut-in-const check from interning to validation 2020-10-26 08:56:54 +01:00
Ralf Jung
0e014be359 move UnsafeCell-in-const check from interning to validation 2020-10-26 08:56:54 +01:00
Ralf Jung
d0a23e613d ensure we intern all promoteds as InternKind::Promoted 2020-10-26 08:56:54 +01:00
DevJPM
3daa93f555 Updated documentation, x86 feature detection testing, and removed LLVM 9 exclusive features
Updated the added documentation in llvm_util.rs to note which copies of LLVM need to be inspected.
Removed avx512bf16 and avx512vp2intersect because they are unsupported before LLVM 9 with the build with external LLVM 8 being supported
Re-introduced detection testing previously removed for un-requestable features tsc and mmx
2020-10-26 08:36:14 +01:00
bors
1cd97cad6e Auto merge of #78387 - Dylan-DPC:rollup-ch0st6z, r=Dylan-DPC
Rollup of 10 pull requests

Successful merges:

 - #74477 (`#[deny(unsafe_op_in_unsafe_fn)]` in sys/wasm)
 - #77836 (transmute_copy: explain that alignment is handled correctly)
 - #78126 (Properly define va_arg and va_list for aarch64-apple-darwin)
 - #78137 (Initialize tracing subscriber in compiletest tool)
 - #78161 (Add issue template link to IRLO)
 - #78214 (Tweak match arm semicolon removal suggestion to account for futures)
 - #78247 (Fix #78192)
 - #78252 (Add codegen test for #45964)
 - #78268 (Do not try to report on closures to avoid ICE)
 - #78295 (Add some regression tests)

Failed merges:

r? `@ghost`
2020-10-26 04:34:46 +00:00
Dylan DPC
463b6cc0e1
Rollup merge of #78268 - JohnTitor:issue-78262, r=estebank
Do not try to report on closures to avoid ICE

Fixes #78262
2020-10-26 03:09:11 +01:00
Dylan DPC
8646c2a15b
Rollup merge of #78247 - simonvandel:fix-78192, r=oli-obk
Fix #78192

Check which places are marked dead.

Fixes #78192
2020-10-26 03:09:08 +01:00
Dylan DPC
083a5cd9a2
Rollup merge of #78214 - estebank:match-semicolon, r=oli-obk
Tweak match arm semicolon removal suggestion to account for futures

* Tweak and extend "use `.await`" suggestions
* Suggest removal of semicolon on prior match arm
* Account for `impl Future` when suggesting semicolon removal
* Silence some errors when encountering `await foo()?` as can't be certain what the intent was

*Thanks to https://twitter.com/a_hoverbear/status/1318960787105353728 for pointing this out!*
2020-10-26 03:09:06 +01:00
Dylan DPC
147a001fd3
Rollup merge of #78126 - shepmaster:aarch64-apple-darwin-valist, r=nagisa
Properly define va_arg and va_list for aarch64-apple-darwin

From [Apple][]:

> Because of these changes, the type `va_list` is an alias for `char*`,
> and not for the struct type in the generic procedure call standard.

With this change `/x.py test --stage 1 src/test/ui/abi/variadic-ffi`
passes.

Fixes #78092

[Apple]: https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms
2020-10-26 03:09:00 +01:00
bors
16e9ed0b1c Auto merge of #77283 - estebank:if-let-sugg, r=Mark-Simulacrum
Tweak `if let` suggestion to be more liberal with suggestion and to not ICE

Fix #77218. Fix #77238.
2020-10-26 01:53:51 +00:00
Jake Goulding
0a91755ff4 Properly define va_arg and va_list for aarch64-apple-darwin
From [Apple][]:

> Because of these changes, the type `va_list` is an alias for `char*`,
> and not for the struct type in the generic procedure call standard.

With this change `/x.py test --stage 1 src/test/ui/abi/variadic-ffi`
passes.

Fixes #78092

[Apple]: https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms
2020-10-25 21:37:01 -04:00
Esteban Küber
ff61949860 Tweak invalid fn header and body parsing
* Recover empty `fn` bodies when encountering `}`
* Recover trailing `>` in return types
* Recover from non-type in array type `[<BAD TOKEN>; LEN]`
2020-10-25 18:34:14 -07:00
Esteban Küber
cabf6d0523 Tweak if let suggestion to be more liberal with suggestion and to not ICE
Fix #77218. Fix #77238.
2020-10-25 15:21:14 -07:00
est31
6c9b8ada0c Precompute the associated items
The associated_items(def_id) call
allocates internally.
Previously, we'd have called it for
each pair, so we'd have had O(n^2)
many calls. By precomputing the
associated items, we avoid
repeating so many allocations.

The only instance where this precomputation
would be a regression is if there's only
one inherent impl block for the type,
as the inner loop then doesn't run.
In that instance, we just early return.

Also, use SmallVec to avoid doing an
allocation at all if the number is small
(the case for most impl blocks out there).
2020-10-25 22:50:48 +01:00
bors
4760b8fb88 Auto merge of #78179 - RalfJung:miri-comments, r=oli-obk
Miri engine: entirely skip interning of ZST, and improve some comments

r? `@oli-obk`
2020-10-25 20:15:44 +00:00
LeSeulArtichaut
9de15188b0 Fix typo in debug statement 2020-10-25 20:54:44 +01:00
Esteban Küber
040f568815 Rely on regular "expected"/"found" parser error for fn 2020-10-25 12:13:27 -07:00
Bastian Kauschke
0e419efb1c check for object safety violations in constants 2020-10-25 18:33:45 +01:00
Bastian Kauschke
9dadcf8370 warn -> debug in collect 2020-10-25 18:05:18 +01:00
DevJPM
9feb567399 Updated the list of white-listed target features for x86
This PR both adds in-source documentation on what to look out for
when adding a new (X86) feature set and adds all that are detectable at run-time in Rust stable
as of 1.27.0.

This should only enable the use of the corresponding LLVM intrinsics.
Actual intrinsics need to be added separately in rust-lang/stdarch.

It also re-orders the run-time-detect test statements to be more consistent
with the actual list of intrinsics whitelisted and removes underscores not present
in the actual names (which might be mistaken as being part of the name)
2020-10-25 17:06:40 +01:00
Yuki Okushi
3dd0a7d6eb Do not call unwrap with signatures option enabled 2020-10-25 20:52:33 +09:00
bors
f392479de6 Auto merge of #78350 - JohnTitor:rollup-vbbm5wf, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #77984 (Compute proper module parent during resolution)
 - #78085 (MIR validation should check `SwitchInt` values are valid for the type)
 - #78208 (replace `#[allow_internal_unstable]` with `#[rustc_allow_const_fn_unstable]` for `const fn`s)
 - #78209 (Update `compiler_builtins` to 0.1.36)
 - #78276 (Bump backtrace-rs to enable Mach-O support on iOS.)
 - #78320 (Link to cargo's `build-std` feature instead of `xargo` in custom target docs)
 - #78322 (BTreeMap: stop mistaking node::MIN_LEN for a node level constraint)
 - #78326 (Split out statement attributes changes from #78306)

Failed merges:

r? `@ghost`
2020-10-25 11:35:26 +00:00
Olivier FAURE
666afba684 Update description for error E0308
As per #76462
2020-10-25 12:20:25 +01:00
Yuki Okushi
0a26e4ba7e
Rollup merge of #78326 - Aaron1011:fix/min-stmt-lints, r=petrochenkov
Split out statement attributes changes from #78306

This is the same as PR https://github.com/rust-lang/rust/pull/78306, but `unused_doc_comments` is modified to explicitly ignore statement items (which preserves the current behavior).

This shouldn't have any user-visible effects, so it can be landed without lang team discussion.

---------
When the 'early' and 'late' visitors visit an attribute target, they
activate any lint attributes (e.g. `#[allow]`) that apply to it.
This can affect warnings emitted on sibiling attributes. For example,
the following code does not produce an `unused_attributes` for
`#[inline]`, since the sibiling `#[allow(unused_attributes)]` suppressed
the warning.

```rust
trait Foo {
    #[allow(unused_attributes)] #[inline] fn first();
    #[inline] #[allow(unused_attributes)] fn second();
}
```

However, we do not do this for statements - instead, the lint attributes
only become active when we visit the struct nested inside `StmtKind`
(e.g. `Item`).

Currently, this is difficult to observe due to another issue - the
`HasAttrs` impl for `StmtKind` ignores attributes for `StmtKind::Item`.
As a result, the `unused_doc_comments` lint will never see attributes on
item statements.

This commit makes two interrelated fixes to the handling of inert
(non-proc-macro) attributes on statements:

* The `HasAttr` impl for `StmtKind` now returns attributes for
  `StmtKind::Item`, treating it just like every other `StmtKind`
  variant. The only place relying on the old behavior was macro
  which has been updated to explicitly ignore attributes on item
  statements. This allows the `unused_doc_comments` lint to fire for
  item statements.
* The `early` and `late` lint visitors now activate lint attributes when
  invoking the callback for `Stmt`. This ensures that a lint
  attribute (e.g. `#[allow(unused_doc_comments)]`) can be applied to
  sibiling attributes on an item statement.

For now, the `unused_doc_comments` lint is explicitly disabled on item
statements, which preserves the current behavior. The exact locatiosn
where this lint should fire are being discussed in PR #78306
2020-10-25 18:43:49 +09:00
Yuki Okushi
72e02b015e
Rollup merge of #78208 - liketechnik:issue-69399, r=oli-obk
replace `#[allow_internal_unstable]` with `#[rustc_allow_const_fn_unstable]` for `const fn`s

`#[allow_internal_unstable]` is currently used to side-step feature gate and stability checks.
While it was originally only meant to be used only on macros, its use was expanded to `const fn`s.

This pr adds stricter checks for the usage of `#[allow_internal_unstable]` (only on macros) and introduces the `#[rustc_allow_const_fn_unstable]` attribute for usage on `const fn`s.

This pr does not change any of the functionality associated with the use of `#[allow_internal_unstable]` on macros or the usage of `#[rustc_allow_const_fn_unstable]` (instead of `#[allow_internal_unstable]`) on `const fn`s (see https://github.com/rust-lang/rust/issues/69399#issuecomment-712911540).

Note: The check for `#[rustc_allow_const_fn_unstable]` currently only validates that the attribute is used on a function, because I don't know how I would check if the function is a `const fn` at the place of the check. I therefore openend this as a 'draft pull request'.

Closes rust-lang/rust#69399

r? @oli-obk
2020-10-25 18:43:40 +09:00
Yuki Okushi
dbdc61f9f9
Rollup merge of #78085 - wesleywiser:mir_validation_switch_int, r=oli-obk
MIR validation should check `SwitchInt` values are valid for the type

Fixes #75440
2020-10-25 18:43:38 +09:00
Yuki Okushi
569d29d55c
Rollup merge of #77984 - Aaron1011:fix/macro-mod-weird-parent, r=petrochenkov
Compute proper module parent during resolution

Fixes #75982

The direct parent of a module may not be a module
(e.g. `const _: () =  { #[path = "foo.rs"] mod foo; };`).

To find the parent of a module for purposes of resolution, we need to
walk up the tree until we hit a module or a crate root.
2020-10-25 18:43:37 +09:00
Yuki Okushi
4f34537708 Fix small typos 2020-10-25 18:35:24 +09:00
Yuki Okushi
88d39673d7 Use its own TypeckResults to avoid ICE 2020-10-25 18:35:24 +09:00
bors
5171cc76c2 Auto merge of #77476 - tgnottingham:buffered_siphasher128, r=nnethercote
perf: buffer SipHasher128

This is an attempt to improve Siphasher128 performance by buffering input. Although it reduces instruction count, I'm not confident the effect on wall times, or lack-thereof, is worth the change.

---

Additional notes not reflected in source comments:

* Implementation choices were guided by a combination of results from rustc-perf and micro-benchmarks, mostly the former.
* ~~I tried a couple of different struct layouts that might be more cache friendly with no obvious effect.~~ Update: a particular struct layout was chosen, but it's not critical to performance. See comments in source and discussion below.
* I suspect that buffering would be important to a SIMD-accelerated algorithm, but from what I've read and my own tests, SipHash does not seem very amenable to SIMD acceleration, at least by SSE.
2020-10-25 09:23:45 +00:00
bors
3e0dd24a6c Auto merge of #77546 - lcnr:impl-trait-closure, r=eddyb
fix def collector for impl trait

fixes #77329

We now consistently make `impl Trait` a hir owner, requiring some special casing for synthetic generic params.

r? `@eddyb`
2020-10-25 07:03:58 +00:00
bors
17cc9b6256 Auto merge of #77398 - wesleywiser:measureme_0_8, r=Mark-Simulacrum
Upgrade to measureme 9.0.0

I believe I did this correctly but there's still a reference to `measureme@0.7.1` coming from `rustc-ap-rustc_data_structures` and I'm not sure how to resolve that.

r? `@Mark-Simulacrum`

We'll also need to deploy the new version of the tools on perf.rlo.
2020-10-25 04:48:37 +00:00
Wesley Wiser
5ac5556d63 Upgrade to measureme 9.0.0 2020-10-24 22:39:42 -04:00
bors
36a74944cb Auto merge of #77526 - RalfJung:dont-promote-unions, r=lcnr
stop promoting union field accesses in 'const'

Turns out that promotion of union field accesses is the only difference between "promotion in `const`/`static` bodies" and "explicit promotion". So if we can remove this, we have finally achieved what I thought to already be the case -- that the bodies of `const`/`static` initializers behave the same as explicit promotion contexts.

The reason we do not want to promote union field accesses is that they can introduce UB, i.e., they can go wrong. We want to [minimize the ways promoteds can fail to evaluate](https://github.com/rust-lang/const-eval/issues/53). Also this change makes things more consistent overall, removing a special case that was added without much consideration (as far as I can tell).

Cc `@rust-lang/wg-const-eval`
2020-10-25 02:27:09 +00:00
Yuki Okushi
7b4c397b73 Do not try to report on closures to avoid ICE 2020-10-25 11:19:49 +09:00
bors
f58ffc9381 Auto merge of #78334 - jonas-schievink:rollup-z0gzbmm, r=jonas-schievink
Rollup of 12 pull requests

Successful merges:

 - #75115 (`#[deny(unsafe_op_in_unsafe_fn)]` in sys/cloudabi)
 - #76614 (change the order of type arguments on ControlFlow)
 - #77610 (revise Hermit's mutex interface to support the behaviour of StaticMutex)
 - #77830 (Simplify query proc-macros)
 - #77930 (Do not ICE with TraitPredicates containing [type error])
 - #78069 (Fix const core::panic!(non_literal_str).)
 - #78072 (Cleanup constant matching in exhaustiveness checking)
 - #78119 (Throw core::panic!("message") as &str instead of String.)
 - #78191 (Introduce a temporary for discriminant value in MatchBranchSimplification)
 - #78272 (const_evaluatable_checked: deal with unused nodes + div)
 - #78318 (TyCtxt: generate single impl block with `slice_interners` macro)
 - #78327 (resolve: Relax macro resolution consistency check to account for any errors)

Failed merges:

r? `@ghost`
2020-10-24 21:42:39 +00:00
Jonas Schievink
58ae889779
Rollup merge of #78327 - petrochenkov:inconsist, r=Aaron1011
resolve: Relax macro resolution consistency check to account for any errors

The check was previously omitted only when ambiguity errors or `Res::Err` were encountered, but the "macro-expanded `extern crate` items cannot shadow..." error (at least) can cause same inconsistencies as well.

Fixes https://github.com/rust-lang/rust/issues/78325
2020-10-24 22:40:00 +02:00
Jonas Schievink
a8ff5a4e03
Rollup merge of #78318 - bugadani:tyctx-impl, r=petrochenkov
TyCtxt: generate single impl block with `slice_interners` macro

Reduces the work needed to check overlapping impls a bit.
2020-10-24 22:39:59 +02:00
Jonas Schievink
5ed8ac45d4
Rollup merge of #78272 - lcnr:abstract-const-unused-node, r=oli-obk
const_evaluatable_checked: deal with unused nodes + div

r? @oli-obk
2020-10-24 22:39:57 +02:00
Jonas Schievink
597b4c5bb4
Rollup merge of #78191 - tmiasko:temp-match-branch-simplification, r=oli-obk
Introduce a temporary for discriminant value in MatchBranchSimplification

The optimization introduces additional uses of the discriminant operand, but
does not ensure that it is still valid to evaluate it or that it still
evaluates to the same value.

Evaluate it once at original position, and store the result in a new temporary.

Follow up on #78151. The optimization remains disabled by default.

Closes #78239.
2020-10-24 22:39:55 +02:00
Jonas Schievink
e12e97223f
Rollup merge of #78072 - Nadrieril:cleanup-constant-matching, r=varkor
Cleanup constant matching in exhaustiveness checking

This supercedes https://github.com/rust-lang/rust/pull/77390. I made the `Opaque` constructor work.
I have opened two issues https://github.com/rust-lang/rust/issues/78071 and https://github.com/rust-lang/rust/issues/78057 from the discussion we had on the previous PR. They are not regressions nor directly related to the current PR so I thought we'd deal with them separately.

I left a FIXME somewhere because I didn't know how to compare string constants for equality. There might even be some unicode things that need to happen there. In the meantime I preserved previous behavior.

EDIT: I accidentally fixed #78071
2020-10-24 22:39:51 +02:00
Jonas Schievink
0a06d7344b
Rollup merge of #78069 - fusion-engineering-forks:core-const-panic-str, r=RalfJung
Fix const core::panic!(non_literal_str).

Invocations of `core::panic!(x)` where `x` is not a string literal expand to `panic!("{}", x)`, which is not understood by the const panic logic right now. This adds `panic_str` as a lang item, and modifies the const eval implementation to hook into this item as well.

This fixes the issue mentioned here: https://github.com/rust-lang/rust/issues/51999#issuecomment-687604248

r? `@RalfJung`

`@rustbot` modify labels: +A-const-eval
2020-10-24 22:39:49 +02:00
Jonas Schievink
7428de1583
Rollup merge of #77930 - estebank:ice-77919, r=eddyb
Do not ICE with TraitPredicates containing [type error]

Fix #77919.
2020-10-24 22:39:47 +02:00
Jonas Schievink
4d72939af1
Rollup merge of #77830 - cjgillot:remacro, r=oli-obk
Simplify query proc-macros

The query code generation is split between proc-macros and regular macros in `rustc_middle::ty::query`.

This PR removes unused capabilities of the proc-macros, and tend to use regular macros for the logic.
2020-10-24 22:39:46 +02:00
Jonas Schievink
a547055184
Rollup merge of #76614 - NoraCodes:nora/control_flow_enum, r=scottmcm
change the order of type arguments on ControlFlow

This allows ControlFlow<BreakType> which is much more ergonomic for common iterator combinator use cases.

Addresses one component of #75744
2020-10-24 22:39:41 +02:00
Wesley Wiser
dd683e5ab5 MIR validation should check SwitchInt values are valid for the type 2020-10-24 16:00:04 -04:00
bors
ffa2e7ae8f Auto merge of #77255 - Aaron1011:feature/collect-attr-tokens, r=petrochenkov
Unconditionally capture tokens for attributes.

This allows us to avoid synthesizing tokens in `prepend_attr`, since we
have the original tokens available.

We still need to synthesize tokens when expanding `cfg_attr`,
but this is an unavoidable consequence of the syntax of `cfg_attr` -
the user does not supply the `#` and `[]` tokens that a `cfg_attr`
expands to.

This is based on PR https://github.com/rust-lang/rust/pull/77250 - this PR exposes a bug in the current `collect_tokens` implementation, which is fixed by the rewrite.
2020-10-24 19:23:32 +00:00
Ralf Jung
5d624929cf
fix typo
Co-authored-by: BlackHoleFox <blackholefoxdev@gmail.com>
2020-10-24 20:39:04 +02:00
Aaron Hill
283053a742
Compute proper module parent during resolution
Fixes #75982

The direct parent of a module may not be a module
(e.g. `const _: () =  { #[path = "foo.rs"] mod foo; };`).

To find the parent of a module for purposes of resolution, we need to
walk up the tree until we hit a module or a crate root.
2020-10-24 14:28:13 -04:00
Vadim Petrochenkov
ef09ed2002 resolve: Relax macro resolution consistency check to account for any errors 2020-10-24 21:26:08 +03:00
Jake Goulding
c6ab758e54 Switch from tuple matching to match guards 2020-10-24 12:58:38 -04:00
Aaron Hill
ac384ac2db
Fix inconsistencies in handling of inert attributes on statements
When the 'early' and 'late' visitors visit an attribute target, they
activate any lint attributes (e.g. `#[allow]`) that apply to it.
This can affect warnings emitted on sibiling attributes. For example,
the following code does not produce an `unused_attributes` for
`#[inline]`, since the sibiling `#[allow(unused_attributes)]` suppressed
the warning.

```rust
trait Foo {
    #[allow(unused_attributes)] #[inline] fn first();
    #[inline] #[allow(unused_attributes)] fn second();
}
```

However, we do not do this for statements - instead, the lint attributes
only become active when we visit the struct nested inside `StmtKind`
(e.g. `Item`).

Currently, this is difficult to observe due to another issue - the
`HasAttrs` impl for `StmtKind` ignores attributes for `StmtKind::Item`.
As a result, the `unused_doc_comments` lint will never see attributes on
item statements.

This commit makes two interrelated fixes to the handling of inert
(non-proc-macro) attributes on statements:

* The `HasAttr` impl for `StmtKind` now returns attributes for
  `StmtKind::Item`, treating it just like every other `StmtKind`
  variant. The only place relying on the old behavior was macro
  which has been updated to explicitly ignore attributes on item
  statements. This allows the `unused_doc_comments` lint to fire for
  item statements.
* The `early` and `late` lint visitors now activate lint attributes when
  invoking the callback for `Stmt`. This ensures that a lint
  attribute (e.g. `#[allow(unused_doc_comments)]`) can be applied to
  sibiling attributes on an item statement.

For now, the `unused_doc_comments` lint is explicitly disabled on item
statements, which preserves the current behavior. The exact locatiosn
where this lint should fire are being discussed in PR #78306
2020-10-24 11:55:48 -04:00
Ralf Jung
1333206eb3 ensure that statics are inhabited 2020-10-24 16:15:42 +02:00
est31
a21c2eb121 Iterate over the smaller list
If there are two lists of different sizes,
iterating over the smaller list and then
looking up in the larger list is cheaper
than vice versa, because lookups scale
sublinearly.
2020-10-24 15:57:42 +02:00
Jonas Schievink
1ac137be93
Rollup merge of #78307 - rust-lang:revert-77961-embed-bitcode, r=tmandry
Revert "Set .llvmbc and .llvmcmd sections as allocatable"

Reverts rust-lang/rust#77961, see discussion starting from https://github.com/rust-lang/rust/pull/77961#issuecomment-712313902
2020-10-24 14:12:20 +02:00
Jonas Schievink
da486467d4
Rollup merge of #78300 - richkadel:coverage-cx, r=wesleywiser
Make codegen coverage_context optional, and check

Addresses Issue #78286

Libraries compiled with coverage and linked with out enabling coverage
would fail when attempting to add the library's coverage statements to
the codegen coverage context (None).

Now, if coverage statements are encountered while compiling / linking
with `-Z instrument-coverage` disabled, codegen will *not* attempt to
add code regions to a coverage map, and it will not inject the LLVM
instrprof_increment intrinsic calls.
2020-10-24 14:12:18 +02:00
Jonas Schievink
2362659b00
Rollup merge of #78292 - bugadani:recursion, r=nagisa
Loop instead of recursion

I saw the comment `// FIXME: consider not using recursion to lower this.` and considered not using recursion :)
2020-10-24 14:12:15 +02:00
Jonas Schievink
b6ae1fabee
Rollup merge of #78278 - lcnr:predicate-visit, r=matthewjasper
move `visit_predicate` into `TypeVisitor`

Seems easier than dealing with `PredicateVisitor` for me which I needed for object safety checks for `PredicateAtom::ConstEvaluatable`. Is there a reason I am missing for this split?

r? @matthewjasper
2020-10-24 14:12:13 +02:00
Jonas Schievink
77cd5b5485
Rollup merge of #78249 - lcnr:ct-infer-origin, r=varkor
improve const infer error

For type inference we probably have to be careful about subtyping and stuff but considering that subtyping shouldn't be relevant for constants I don't really see a reason why we may not want to reuse the const origin here.

r? `@varkor`
2020-10-24 14:12:06 +02:00
Jonas Schievink
86c07a4955
Rollup merge of #78198 - tmiasko:assert, r=davidtwco
Simplify assert terminator only if condition evaluates to expected value
2020-10-24 14:12:03 +02:00
Jonas Schievink
fb92b70f95
Rollup merge of #77716 - francesca64:revert-ios-dynamic-linking, r=jonas-schievink
Revert "Allow dynamic linking for iOS/tvOS targets."

This reverts PR #73516.

On macOS I compile static libs for iOS, automated using [cargo-mobile](https://github.com/BrainiumLLC/cargo-mobile), which has worked smoothly for the past 2 years. However, upon updating to Rust 1.46.0, I was no longer able to use Rust on iOS. I've bisected this to the PR referenced above.

For most projects tested, apps now immediately crash with a message like this:
```
dyld: Library not loaded: /Users/francesca/Projects/example/target/aarch64-apple-ios/debug/deps/libexample.dylib
  Referenced from: /private/var/containers/Bundle/Application/745912AF-A928-465C-B340-872BD1C9F368/example.app/example
  Reason: image not found
dyld: launch, loading dependent libraries
DYLD_LIBRARY_PATH=/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib:/Developer/Library/PrivateFrameworks/GPUTools.framework/libglInterpose.dylib:/usr/lib/libMTLCapture.dylib
```

This can be reproduced by using cargo-mobile to generate a winit example project, and then attempting to run it on an iOS device (`cargo mobile init && cargo apple open`).

In our projects that depend on DisplayLink, the build instead fails with a linker error:
```
= note: Undefined symbols for architecture arm64:
            "_CACurrentMediaTime", referenced from:
                display_link::ios::run_callback_ios10::hda81197ff46aedbd in libapp-4f0abc1d7684103f.rlib(app-4f0abc1d7684103f.40d4iro0yz1iy487.rcgu.o)
                display_link::ios::run_callback_pre_ios10::h91f085da19374320 in libapp-4f0abc1d7684103f.rlib(app-4f0abc1d7684103f.40d4iro0yz1iy487.rcgu.o)
          ld: symbol(s) not found for architecture arm64
```

After reverting the change to enable dynamic linking on iOS, everything works the same as it did on Rust 1.45.2 for me.

In the future, would it be possible for me to be pinged when iOS-related PRs are made? I work for a company that intends on using Rust on iOS in production, so I'd gladly provide testing.

cc @aspenluxxxy
2020-10-24 14:11:59 +02:00
Dániel Buga
6533d010cf Don't generate multiple impl blocks 2020-10-24 11:55:00 +02:00
Dániel Buga
f88d6e8437 Loop instead of recursion 2020-10-24 01:24:58 +02:00
Rich Kadel
f75a236fe0
Update compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Co-authored-by: Wesley Wiser <wwiser@gmail.com>
2020-10-23 14:58:08 -07:00
Bastian Kauschke
83ecbb4a29 add tests for self with const params 2020-10-23 22:10:44 +02:00
Tyler Mandry
6640a62e0e
Revert "Set .llvmbc and .llvmcmd sections as allocatable" 2020-10-23 12:54:00 -07:00
Esteban Küber
f71e9ed7f1 review comments 2020-10-23 12:51:06 -07:00
Esteban Küber
b334eef162 Do not ICE with TraitPredicates containing [type error]
Fix #77919.
2020-10-23 12:21:47 -07:00
Rich Kadel
a7bc1a2edf Make codegen coverage_context optional, and check
Addresses Issue #78286

Libraries compiled with coverage and linked with out enabling coverage
would fail when attempting to add the library's coverage statements to
the codegen coverage context (None).

Now, if coverage statements are encountered while compiling / linking
with `-Z instrument-coverage` disabled, codegen will *not* attempt to
add code regions to a coverage map, and it will not inject the LLVM
instrprof_increment intrinsic calls.
2020-10-23 12:00:30 -07:00
bors
7bade6ef73 Auto merge of #77015 - davidtwco:check-attr-variant-closure-expr, r=lcnr
passes: `check_attr` on more targets

This PR modifies `check_attr` so that:

- Enum variants are now checked (some attributes would not have been prohibited on variants previously).
- `check_expr_attributes` and `check_stmt_attributes` are removed as `check_attributes` can perform the same checks. This means that codegen attribute errors aren't shown if there are other errors first (e.g. from other attributes, as shown in `src/test/ui/macros/issue-68060.rs` changes below).
2020-10-23 17:32:04 +00:00
Florian Warzecha
ac2c599f23
fix validation for rustc_allow_const_fn_unstable targets
The validation was introduced in 3a63bf0299
without strict validation of functions, e. g. all function types were
allowed.
Now the validation only allows `const fn`s.
2020-10-23 17:54:48 +02:00
Florian Warzecha
13b481b247
rename allow_internal_unstable() to rustc_allow_const_fn_unstable() in rustc_mir
Followup rename from 05f4a9a42a,
which introduced `#[rustc_allow_const_fn_unstable]` for `const fn`s.
2020-10-23 17:14:57 +02:00
Esteban Küber
f5d7443a6b Suggest semicolon removal and boxing when appropriate 2020-10-23 08:06:41 -07:00
Esteban Küber
c5485115dc Add more .await suggestions on E0308 2020-10-23 08:06:41 -07:00
Esteban Küber
3a0227bc49 Silence unnecessary await foo? knock-down error 2020-10-23 08:06:41 -07:00
Esteban Küber
62ba365195 Review comments: use newtype instead of bool 2020-10-23 08:06:41 -07:00
Esteban Küber
671d7c4afb Account for possible boxable impl Future in semicolon removal suggestions 2020-10-23 08:06:13 -07:00
Esteban Küber
a4ee3ca1e4 Suggest semicolon removal on prior match arm 2020-10-23 08:02:58 -07:00
Esteban Küber
86df9039b2 Tweak "use .await" suggestion 2020-10-23 08:02:57 -07:00
Florian Warzecha
83fbdddc99
ignore #[rustc_allow_const_fn_unstable] for macro expansion
Recognition for `rustc_allow_const_fn_unstable` attribute was errorneously
added in 05f4a9a42a.
2020-10-23 16:54:25 +02:00
Bastian Kauschke
47cb871f14 review 2020-10-23 15:04:12 +02:00
Bastian Kauschke
972d9e886c move visit_predicate into TypeVisitor 2020-10-23 13:58:32 +02:00
Bastian Kauschke
6ad140ca19 const_eval_checked: deal with unused nodes + div 2020-10-23 12:16:58 +02:00
Yuki Okushi
7ba519ec50
Rollup merge of #78255 - dtolnay:match, r=lcnr
Reduce diagram mess in 'match arms have incompatible types' error

I noticed this wild diagram in https://twitter.com/a_hoverbear/status/1318960787105353728 which I think does not benefit from the big outer vertical span.

This PR shrinks the outer span to cover just the `match` keyword and scrutinee expression *if* at least one of the highlighted match arms involved in the error is multiline.

**Before:**

<pre>
<b>error[E0308]: `match` arms have incompatible types</b>
   <b>--&gt;</b> src/topology/builder.rs:141:35
    <b>|</b>
<b>120 |</b>             let transform = match transform {
    <b>|    _________________________-</b>
<b>121 |   |</b>             Transform::Function(t) =&gt; {
    <b>|  _|_______________________________________-</b>
<b>122 | | |</b>                 filter_event_type(input_rx, input_type).compat().flat_map(|v| {
<b>123 | | |</b>                     futures::stream::iter(match v {
<b>124 | | |</b>                         Err(e) =&gt; {
<b>...   | |</b>
<b>139 | | |</b>                 .compat();
<b>140 | | |</b>             }
    <b>| |_|_____________- this is found to be of type `()`</b>
<b>141 |   |</b>             Transform::Task(t) =&gt; t
    <b>|  _|___________________________________^</b>
<b>142 | | |</b>                 .transform(filter_event_type(input_rx, input_type))
<b>143 | | |</b>                 .forward(output)
<b>144 | | |</b>                 .map(|_| debug!("Finished"))
<b>145 | | |</b>                 .compat(),
    <b>| |_|_________________________^ expected `()`, found struct `futures::compat::Compat01As03`</b>
<b>146 |   |</b>         };
    <b>|   |_________- `match` arms have incompatible types</b>
    <b>|</b>
    <b>= note:</b> expected type `<b>()</b>`
             found struct `<b>futures::compat::Compat01As03&lt;futures::Map&lt;futures::stream::Forward&lt;std::boxed::Box&lt;dyn futures::Stream&lt;Error = (), Item = event::Event&gt; + std::marker::Send&gt;, topology::fanout::Fanout&gt;, [closure@src/topology/builder.rs:144:22: 144:44]&gt;&gt;</b>`
</pre>

**After:**

<pre>
<b>error[E0308]: `match` arms have incompatible types</b>
   <b>--&gt;</b> src/topology/builder.rs:141:35
    <b>|</b>
<b>120 |</b>             let transform = match transform {
    <b>|                             --------------- `match` arms have incompatible types</b>
<b>121 |</b>                 Transform::Function(t) =&gt; {
    <b>|  _________________________________________-</b>
<b>122 | |</b>                   filter_event_type(input_rx, input_type).compat().flat_map(|v| {
<b>123 | |</b>                       futures::stream::iter(match v {
<b>124 | |</b>                           Err(e) =&gt; {
<b>...   |</b>
<b>139 | |</b>                   .compat();
<b>140 | |</b>               }
    <b>| |_______________- this is found to be of type `()`</b>
<b>141 |</b>                 Transform::Task(t) =&gt; t
    <b>|  _____________________________________^</b>
<b>142 | |</b>                   .transform(filter_event_type(input_rx, input_type))
<b>143 | |</b>                   .forward(output)
<b>144 | |</b>                   .map(|_| debug!("Finished"))
<b>145 | |</b>                   .compat(),
    <b>| |___________________________^ expected `()`, found struct `futures::compat::Compat01As03`</b>
    <b>|</b>
    <b>= note:</b> expected type `<b>()</b>`
             found struct `<b>futures::compat::Compat01As03&lt;futures::Map&lt;futures::stream::Forward&lt;std::boxed::Box&lt;dyn futures::Stream&lt;Error = (), Item = event::Event&gt; + std::marker::Send&gt;, topology::fanout::Fanout&gt;, [closure@src/topology/builder.rs:144:22: 144:44]&gt;&gt;</b>`
</pre>

FYI @Hoverbear
2020-10-23 18:26:40 +09:00
Yuki Okushi
3f462c22b5
Rollup merge of #78235 - Aaron1011:closure-ret-infer, r=varkor
Explain where the closure return type was inferred

Fixes #78193
2020-10-23 18:26:39 +09:00
Yuki Okushi
00c4dcdbb4
Rollup merge of #78231 - LeSeulArtichaut:closure-target_feature, r=nikomatsakis
Make closures inherit the parent function's target features

r? @ghost
Closes #73631
2020-10-23 18:26:37 +09:00
Yuki Okushi
982c4b3081
Rollup merge of #78116 - spastorino:inline-const-in-range-pat, r=petrochenkov
Make inline const work in range patterns

Fixes #78108 which is a follow up of https://github.com/rust-lang/rust/pull/77124

r? @petrochenkov
2020-10-23 18:26:30 +09:00
Yuki Okushi
709de7817d
Rollup merge of #78098 - camelid:fixup-docs, r=steveklabnik
Clean up and improve some docs

* compiler docs
  * Don't format list as part of a code block
  * Clean up some other formatting
* rustdoc book
  * Update CommonMark spec version to latest (0.28 -> 0.29)
  * Clean up some various wording and formatting
2020-10-23 18:26:28 +09:00
Yuki Okushi
da3e41e8d3
Rollup merge of #77488 - varkor:repr128-incomplete_features, r=jonas-schievink
Mark `repr128` as `incomplete_features`

As mentioned in https://github.com/rust-lang/rust/issues/56071 and noticed in https://github.com/rust-lang/rust/issues/77457, `repr(u128)` and `repr(i128)` do not work properly due to lack of LLVM support. We should thus warn users trying to use the feature that they may encounter ICEs when using it.

Closes https://github.com/rust-lang/rust/issues/77457.
2020-10-23 18:26:18 +09:00
Bastian Kauschke
e1c524cd45 review 2020-10-23 09:52:04 +02:00
Tyler Mandry
d0d0e78208 Capture output from threads spawned in tests
Fixes #42474.
2020-10-22 18:15:44 -07:00
Leonora Tindall
bc2317915f Don't re-export std::ops::ControlFlow in the compiler. 2020-10-22 17:26:55 -07:00
Leonora Tindall
84daccc559 change the order of type arguments on ControlFlow
This allows ControlFlow<BreakType> which is much more ergonomic for
common iterator combinator use cases.
2020-10-22 17:26:48 -07:00
David Tolnay
b0059500f6
Reduce diagram mess in 'match arms have incompatible types' error 2020-10-22 16:16:02 -07:00
varkor
d1c2815d6a Use diverges instead of !-type 2020-10-22 23:12:46 +01:00
Bastian Kauschke
40ab18d97d improve const infer error 2020-10-22 23:07:48 +02:00
Camille GILLOT
57ba8edb9e Retire rustc_dep_node_try_load_from_on_disk_cache. 2020-10-22 23:04:46 +02:00
Camille GILLOT
e853cc0b28 Retire rustc_dep_node_force. 2020-10-22 22:57:19 +02:00
Camille GILLOT
de7da7fd3d Unify query name and node name. 2020-10-22 22:49:04 +02:00
Camille GILLOT
de763701e1 Remove unused category from macros. 2020-10-22 22:43:38 +02:00
Camille GILLOT
0a4d948b4a Remove unused ProfileCategory. 2020-10-22 22:35:32 +02:00
Simon Vandel Sillesen
57d01a9aee Check which places are dead
Fixes #78192
2020-10-22 22:23:56 +02:00
Aaron Hill
5c7d8d049c
Only call collect_tokens when we have an attribute to parse 2020-10-22 15:17:40 -04:00
Bastian Kauschke
567d55ef9e fix save-analysis 2020-10-22 21:11:50 +02:00
Mara Bos
4f7ffbf351 Fix const core::panic!(non_literal_str). 2020-10-22 18:41:35 +02:00
Santiago Pastorino
83abed9df6
Make inline const work for half open ranges 2020-10-22 13:22:12 -03:00
Santiago Pastorino
f8842b9bac
Make inline const work in range patterns 2020-10-22 13:21:18 -03:00
Santiago Pastorino
954b5a81b4
Rename parse_const_expr to parse_const_block 2020-10-22 13:21:18 -03:00
Aaron Hill
36a5244da3
Explain where the closure return type was inferred
Fixes #78193
2020-10-22 10:44:55 -04:00
bors
a9cd294cf2 Auto merge of #77720 - matthewjasper:fix-trait-ices, r=nikomatsakis
Fix trait solving ICEs

- Selection candidates that are known to be applicable are preferred
  over candidates that are not.
- Don't ICE if a projection/object candidate is no longer applicable
  (this can happen due to cycles in normalization)
- Normalize supertraits when finding trait object candidates

Closes #77653
Closes #77656

r? `@nikomatsakis`
2020-10-22 14:40:20 +00:00
Aaron Hill
920bed1213
Don't create an empty LazyTokenStream 2020-10-22 10:09:08 -04:00
bors
500ddc5efd Auto merge of #77871 - Julian-Wollersberger:less-query-context, r=oli-obk
Make fewer types generic over QueryContext

While trying to refactor `rustc_query_system::query::QueryContext` to make it dyn-safe, I noticed some smaller things:
* QueryConfig doesn't need to be generic over QueryContext
* ~~The `kind` field on QueryJobId is unused~~
* Some unnecessary where clauses
* Many types in `job.rs` where generic over `QueryContext` but only needed `QueryContext::Query`.
  If handle_cycle_error() could be refactored to not take `error: CycleError<CTX::Query>`, all those bounds could be removed as well.

Changing `find_cycle_in_stack()` in job.rs to not take a `tcx` argument is the only functional change here. Everything else is just updating type signatures. (aka compile-error driven development ^^)

~~Currently there is a weird bug where memory usage suddenly skyrockets when running UI tests. I'll investigate that tomorrow.
A perf run probably won't make sense before that is fixed.~~

EDIT: `kind` actually is used by `Eq`, and re-adding it fixed the memory issue.
2020-10-22 12:24:55 +00:00
LeSeulArtichaut
769b4108e2 Make closures inherit the parent function's target features 2020-10-22 13:55:19 +02:00
Bastian Kauschke
4a15a25662 min_const_generics: allow ty param in repeat expr 2020-10-22 10:43:28 +02:00
Matthew Jasper
50dde2e4d8 Normalize when finding trait object candidates 2020-10-22 08:18:29 +01:00
bors
6b9fbf212a Auto merge of #78134 - bugadani:arena-nodrop, r=lcnr
Use `DroplessArena` where we know the type doesn't need drop

This PR uses a single `DroplessArena` in resolve instead of three separate `TypedArena`s.

`DroplessArena` checks that the type indeed doesn't need drop, so in case the types change, this will result in visible failures.
2020-10-22 07:05:21 +00:00
Yuki Okushi
6fdd53b7de Prefer to use print_def_path 2020-10-22 14:40:09 +09:00
bors
ef3e386393 Auto merge of #78212 - JohnTitor:rollup-j5r6xuy, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #77420 (Unify const-checking structured errors for `&mut` and `&raw mut`)
 - #77554 (Support signed integers and `char` in v0 mangling)
 - #77976 (Mark inout asm! operands as used in liveness pass)
 - #78009 (Haiku: explicitly set CMAKE_SYSTEM_NAME when cross-compiling)
 - #78084 (Greatly improve display for small mobile devices screens)
 - #78155 (Fix two small issues in compiler/rustc_lint/src/types.rs)
 - #78156 (Fixed build failure of `rustfmt`)
 - #78172 (Add test case for #77062)
 - #78188 (Add tracking issue number for pin_static_ref)
 - #78200 (Add `ControlFlow::is_{break,continue}` methods)

Failed merges:

r? `@ghost`
2020-10-22 01:35:05 +00:00
Camelid
d725da129e Clean up and improve some docs
* compiler docs
  * Don't format list as part of a code block
  * Clean up some other formatting
* rustdoc book
  * Update CommonMark spec version to latest (0.28 -> 0.29)
  * Clean up some various wording and formatting
2020-10-21 18:01:04 -07:00
Yuki Okushi
513550cd1f
Rollup merge of #78156 - bishtpawan:bugfix/rustfmt-no-longer-builds, r=lcnr
Fixed build failure of `rustfmt`

Fixes #78079
r? @eddyb cc @bjorn3
2020-10-22 09:45:40 +09:00
Yuki Okushi
59ae7957b0
Rollup merge of #78155 - est31:rustc_lint_types_refactor, r=davidtwco
Fix two small issues in compiler/rustc_lint/src/types.rs

Two small improvements of `compiler/rustc_lint/src/types.rs`
2020-10-22 09:45:38 +09:00
Yuki Okushi
ae95005ecc
Rollup merge of #77976 - oliviacrain:issue-77915-fix, r=matthewjasper
Mark inout asm! operands as used in liveness pass

Variables used in `inout` operands in inline assembly (that is, they're used as both input and output to some arbitrary assembly instruction) are being marked as read and written, but are not marked as being used in the RWU table during the liveness pass. This can result in such expressions triggering an unused variable lint warning. This is incorrect behavior- reads without uses are currently only used for compound assignments. We conservatively assume that an `inout` operand is being read and used in the context of the assembly instruction.

Closes #77915
2020-10-22 09:45:33 +09:00
Yuki Okushi
813066c442
Rollup merge of #77554 - varkor:mangle-int-char, r=eddyb
Support signed integers and `char` in v0 mangling

Likely we want more tests, to check the output is correct too: however, I wasn't sure what kind of test we needed, so I just added one similar to that added in https://github.com/rust-lang/rust/pull/77452 for now.

r? @eddyb
2020-10-22 09:45:31 +09:00
Yuki Okushi
6245b951d5
Rollup merge of #77420 - ecstatic-morse:const-checking-raw-mut-ref, r=davidtwco
Unify const-checking structured errors for `&mut` and `&raw mut`

Resolves #77414 as well as a FIXME.
2020-10-22 09:45:25 +09:00
Aaron Hill
37b25e8a49
Strip tokens before printing AST JSON 2020-10-21 19:44:33 -04:00
bors
c4fe25d861 Auto merge of #78027 - lcnr:lift-by-value, r=varkor
Lift: take self by value

seems small enough to not warrant an MCP 🤷
2020-10-21 23:09:38 +00:00
Aaron Hill
b9b2546417
Unconditionally capture tokens for attributes.
This allows us to avoid synthesizing tokens in `prepend_attr`, since we
have the original tokens available.

We still need to synthesize tokens when expanding `cfg_attr`,
but this is an unavoidable consequence of the syntax of `cfg_attr` -
the user does not supply the `#` and `[]` tokens that a `cfg_attr`
expands to.
2020-10-21 18:57:29 -04:00
varkor
e0b61111f8 Mark repr128 as incomplete_features 2020-10-21 23:41:26 +01:00
Florian Warzecha
3a63bf0299
validate rustc_allow_const_fn_unstable targets
Adds a check to make sure `#[rustc_allow_const_fn_unstable]`
can be applied only to functions.
2020-10-22 00:02:26 +02:00
Bastian Kauschke
17825c93ff review 2020-10-21 23:59:35 +02:00
Bastian Kauschke
8752a560b9 Lift: take self by value 2020-10-21 23:59:35 +02:00
Florian Warzecha
7258740509
validate allow_internal_unstable target
Adds a check to make sure `#[allow_internal_unstable]`
can be applied only to macro definitions.
2020-10-21 22:49:08 +02:00
varkor
5a440f1bc2 Fix control flow check for breaking with diverging values 2020-10-21 21:46:03 +01:00
bors
1eaadebb3d Auto merge of #78077 - petrochenkov:qvis, r=davidtwco
Calculate visibilities once in resolve

Then use them through a query based on resolver outputs.

Item visibilities were previously calculated in three places - initially in `rustc_resolve`, then in `rustc_privacy` during type privacy checkin, and then in `rustc_metadata` during metadata encoding.
The visibility logic is not entirely trivial, especially for things like constructors or enum variants, and all of it was duplicated.

This PR deduplicates all the visibility calculations, visibilities are determined once during early name resolution and then stored in `ResolverOutputs` and are later available through `tcx` as a query `tcx.visibility(def_id)`.
(This query existed previously, but only worked for other crates.)

Some special cases (e.g. visibilities for closure types, which are needed for type privacy checking) are not processed in resolve, but deferred and performed directly in the query instead.
2020-10-21 20:23:26 +00:00
varkor
878c97e70c Update to rustc-demangle 0.1.18 2020-10-21 21:11:11 +01:00
varkor
2b9d22d3a9 Update rustc-demangle 2020-10-21 21:05:38 +01:00
varkor
37c00c41f8 Do not print type for placeholder values 2020-10-21 21:05:38 +01:00
varkor
6b52603a49 Support signed integers and char in v0 mangling 2020-10-21 21:05:38 +01:00
Nadrieril
faf87105db Explain the Opaque special case in specialization 2020-10-21 20:15:02 +01:00
Florian Warzecha
05f4a9a42a
switch allow_internal_unstable const fns to rustc_allow_const_fn_unstable 2020-10-21 20:54:20 +02:00
Matthew Jasper
6c43a64931 Fix ICE from projection cycle
Cycles in normalization can cause evaluations to change from Unknown to
Err. This means that some selection that were applicable no longer are.

To avoid this:
* Selection candidates that are known to be applicable are prefered
  over candidates that are not.
* We don't ICE if a candidate is no longer applicable.
2020-10-21 19:43:20 +01:00
bors
1d2726726f Auto merge of #78195 - tmiasko:instcombine, r=jonas-schievink
Disable "optimization to avoid load of address" in InstCombine

The transformation is incorrect #78192. Disable it.
2020-10-21 17:44:48 +00:00
Florian Warzecha
3948b054dc
add rustc_allow_const_fn_unstable attribute
allow_internal_unstable is currently used
to side-step feature gate and stability checks.
While it was originally only meant to be used
only on macros, its use was expanded to
const functions.

This commit prepares stricter checks for the usage of allow_internal_unstable (only on macros)
and introduces the rustc_allow_const_fn_unstable attribute for usage on functions.

See rust-lang/rust#69399
2020-10-21 18:04:18 +02:00
bors
22e6b9c689 Auto merge of #77250 - Aaron1011:feature/flat-token-collection, r=petrochenkov
Rewrite `collect_tokens` implementations to use a flattened buffer

Instead of trying to collect tokens at each depth, we 'flatten' the
stream as we go allong, pushing open/close delimiters to our buffer
just like regular tokens. One capturing is complete, we reconstruct a
nested `TokenTree::Delimited` structure, producing a normal
`TokenStream`.

The reconstructed `TokenStream` is not created immediately - instead, it is
produced on-demand by a closure (wrapped in a new `LazyTokenStream` type). This
closure stores a clone of the original `TokenCursor`, plus a record of the
number of calls to `next()/next_desugared()`. This is sufficient to reconstruct
the tokenstream seen by the callback without storing any additional state. If
the tokenstream is never used (e.g. when a captured `macro_rules!` argument is
never passed to a proc macro), we never actually create a `TokenStream`.

This implementation has a number of advantages over the previous one:

* It is significantly simpler, with no edge cases around capturing the
  start/end of a delimited group.

* It can be easily extended to allow replacing tokens an an arbitrary
  'depth' by just using `Vec::splice` at the proper position. This is
  important for PR #76130, which requires us to track information about
  attributes along with tokens.

* The lazy approach to `TokenStream` construction allows us to easily
  parse an AST struct, and then decide after the fact whether we need a
  `TokenStream`. This will be useful when we start collecting tokens for
  `Attribute` - we can discard the `LazyTokenStream` if the parsed
  attribute doesn't need tokens (e.g. is a builtin attribute).

The performance impact seems to be neglibile (see
https://github.com/rust-lang/rust/pull/77250#issuecomment-703960604). There is a
small slowdown on a few benchmarks, but it only rises above 1% for incremental
builds, where it represents a larger fraction of the much smaller instruction
count. There a ~1% speedup on a few other incremental benchmarks - my guess is
that the speedups and slowdowns will usually cancel out in practice.
2020-10-21 15:03:14 +00:00
Ralf Jung
fcaf2338da Miri engine interning: improve comments, and entirely skip ZST 2020-10-21 09:47:15 +02:00
Ralf Jung
2202653893 Miri engine validity check: simplify code with 'matches!'
and improve a comment a bit
2020-10-21 09:46:51 +02:00
bishtpawan
7f5847735a Fix formatting 2020-10-21 11:42:52 +05:30
Yuki Okushi
de24210ebf
Rollup merge of #78118 - spastorino:inline-const-followups, r=petrochenkov
Inline const followups

r? @petrochenkov

Follow ups of #77124
2020-10-21 13:59:44 +09:00
Yuki Okushi
83f126bedf
Rollup merge of #78101 - RalfJung:foreign-static, r=oli-obk
fix static_ptr_ty for foreign statics

Cc https://github.com/rust-lang/rust/issues/74840

This does not fix that issue but fixes a problem in `static_ptr_ty` that we noticed while discussing that issue. I also added and updated a few comments. The one about `internal` locals being ignored does not seem to have been true [even in the commit that introduced it](https://github.com/rust-lang/rust/pull/44700/files#diff-ae2f3c7e2f9744f7ef43e96072b10e98d4e3fe74a3a399a3ad8a810fbe56c520R139).

r? @oli-obk
2020-10-21 13:59:43 +09:00
Yuki Okushi
89c98cd6b4
Rollup merge of #78063 - camelid:improve-cannot-multiply-error, r=estebank
Improve wording of "cannot multiply" type error

For example, if you had this code:

    fn foo(x: i32, y: f32) -> f32 {
        x * y
    }

You would get this error:

    error[E0277]: cannot multiply `f32` to `i32`
     --> src/lib.rs:2:7
      |
    2 |     x * y
      |       ^ no implementation for `i32 * f32`
      |
      = help: the trait `Mul<f32>` is not implemented for `i32`

However, that's not usually how people describe multiplication. People
usually describe multiplication like how the division error words it:

    error[E0277]: cannot divide `i32` by `f32`
     --> src/lib.rs:2:7
      |
    2 |     x / y
      |       ^ no implementation for `i32 / f32`
      |
      = help: the trait `Div<f32>` is not implemented for `i32`

So that's what this change does. It changes this:

    error[E0277]: cannot multiply `f32` to `i32`
     --> src/lib.rs:2:7
      |
    2 |     x * y
      |       ^ no implementation for `i32 * f32`
      |
      = help: the trait `Mul<f32>` is not implemented for `i32`

To this:

    error[E0277]: cannot multiply `i32` by `f32`
     --> src/lib.rs:2:7
      |
    2 |     x * y
      |       ^ no implementation for `i32 * f32`
      |
      = help: the trait `Mul<f32>` is not implemented for `i32`
2020-10-21 13:59:39 +09:00
Yuki Okushi
9583029a2d
Rollup merge of #78002 - estebank:issue-77598, r=oli-obk
Tweak "object unsafe" errors

CC #77598.
2020-10-21 13:59:35 +09:00
Eduard-Mihai Burtescu
aff4d3e659 rustc_mir: run the MIR inlining Integrator on the whole callee body at once. 2020-10-21 05:46:16 +03:00
Eduard-Mihai Burtescu
9b21c50335 rustc_mir: create the Integrator as soon as possible in MIR inlining. 2020-10-21 05:46:16 +03:00
Eduard-Mihai Burtescu
0ce4452fce rustc_codegen_llvm: add support for inlined function debuginfo. 2020-10-21 04:43:57 +03:00
Eduard-Mihai Burtescu
737499593d rustc_codegen_llvm: expose DILocation to rustc_codegen_ssa. 2020-10-21 04:43:57 +03:00
Eduard-Mihai Burtescu
88d874de63 rustc_codegen_llvm: avoid converting between DILocation and Value. 2020-10-21 04:43:57 +03:00
Eduard-Mihai Burtescu
fa2b381ec8 rustc_codegen_llvm: move DISubprogram creation to a dbg_scope_fn method. 2020-10-21 04:43:57 +03:00
Eduard-Mihai Burtescu
9d57c417fc rustc_codegen_llvm: create DIFiles from just SourceFiles. 2020-10-21 04:43:56 +03:00
Eduard-Mihai Burtescu
2bfb462b58 rustc_mir: don't throw away inlined locals' spans. 2020-10-21 04:43:56 +03:00
Eduard-Mihai Burtescu
387e31c9a7 rustc_mir: properly map scope parent chains into the caller when inlining. 2020-10-21 04:43:56 +03:00
Eduard-Mihai Burtescu
6451b39a25 rustc_mir: support MIR-inlining #[track_caller] functions. 2020-10-21 04:43:56 +03:00
Eduard-Mihai Burtescu
6bc5eafbce rustc_mir: track inlined callees in SourceScopeData. 2020-10-21 04:43:56 +03:00
Eduard-Mihai Burtescu
708fc0b692 rustc_mir: use Instance more in the inliner. 2020-10-21 04:43:55 +03:00
Eduard-Mihai Burtescu
8c942c1511 rustc_mir: rename location: SourceInfo to source_info. 2020-10-21 04:43:55 +03:00
Tomasz Miąsko
a4dc92b483 Introduce a temporary for discriminant value in MatchBranchSimplification
The optimization introduces additional uses of the discriminant operand, but
does not ensure that it is still valid to evaluate it or that it still
evaluates to the same value.

Evaluate it once at original position, and store the result in a new temporary.
2020-10-21 00:00:00 +00:00
Tomasz Miąsko
a9470d0522 Simplify assert terminator only if condition evaluates to expected value 2020-10-21 00:00:00 +00:00
Tomasz Miąsko
e200a4a0d2 Disable "optimization to avoid load of address" in InstCombine 2020-10-21 00:00:00 +00:00
Guillaume Gomez
0c2dbb2a18
Rollup merge of #78145 - LingMan:ast_pretty_mut, r=jonas-schievink
Drop unneeded `mut`

These parameters don't get modified.

Note that `trailing_comment` is pub and gets exported from `rustc_ast_pretty`. Is that considered to be a stable API? If yes, and you want to reserve the right to modify `self` in `trailing_comment` in the future, that hunk would need to be dropped.
2020-10-20 21:46:42 +02:00
Guillaume Gomez
ad218f9bb9
Rollup merge of #78144 - bugadani:elements-nodrop, r=oli-obk
Don't update `entries` in `TypedArena` if T does not need drop

As far as I can tell, `entries` is only used when dropping `TypedArenaChunk`s and their contents. It is already ignored there, if T is not `mem::needs_drop`, this PR just skips updating it's value.

You can see `TypedArenaChunk` ignoring the entry count in L71. The reasoning is similar to what you can find in `DroplessArena`.

r? @oli-obk
2020-10-20 21:46:40 +02:00
Guillaume Gomez
01e6019448
Rollup merge of #78076 - est31:orphan_mod, r=Mark-Simulacrum
Move orphan module-name/mod.rs files into module-name.rs files
2020-10-20 21:46:35 +02:00
Guillaume Gomez
3fea201b11
Rollup merge of #78061 - wesleywiser:opt_zst_const_interning, r=oli-obk
Optimize const value interning for ZST types

Interning can skip any inhabited ZST type in general.

Fixes #68010

r? @oli-obk
2020-10-20 21:46:32 +02:00
bishtpawan
fa094044a9 Fix build failure of rustfmt 2020-10-20 23:13:21 +05:30
est31
00d23cf220 Make {u,}int_range functions a bit nicer
.into() guarantees safety of the conversion.
Furthermore, the minimum value of all uints is known to be 0.
2020-10-20 19:36:44 +02:00
est31
c647735f40 rustc_lint: remove unused to_string
In this instance, we can just pass a &str slice
and save an allocation.
2020-10-20 19:30:09 +02:00
Esteban Küber
88f5e110db review comments 2020-10-20 09:26:15 -07:00
Esteban Küber
ae0e3d0511 Tweak "object unsafe" errors
Fix #77598.
2020-10-20 09:26:14 -07:00
Dániel Buga
2705caed8a Track element count only for types that need drop 2020-10-20 17:01:51 +02:00
LingMan
13f0f49a4e Drop unneeded mut
These parameters don't get modified.
2020-10-20 16:42:51 +02:00
Dániel Buga
9b453d6954 Use DroplessArena for variance inference 2020-10-20 11:05:00 +02:00
bors
9832374f6e Auto merge of #76893 - lcnr:existential-proj, r=estebank
Improve `skip_binder` usage during FlagComputation

It looks like there was previously a bug around `ExistentialPredicate::Projection` here, don't know how to best trigger that one to add a regression test though.
2020-10-20 08:59:12 +00:00
Dániel Buga
d07ce65d56 Resolve: Use dropless arena for types that don't need drop 2020-10-20 10:37:56 +02:00
bors
554633534c Auto merge of #76696 - Aaron1011:tokenstream-avoid-clone, r=petrochenkov
Avoid cloning the contents of a `TokenStream` in a few places
2020-10-20 05:45:08 +00:00
Yuki Okushi
21df410a62
Rollup merge of #78121 - LeSeulArtichaut:issue-78115, r=tmandry
Do not ICE on pattern that uses a binding multiple times in generator

Fixes #78115.
r? @tmandry
2020-10-20 12:11:13 +09:00
Yuki Okushi
3f1c637db4
Rollup merge of #78111 - SNCPlay42:not-always-self, r=lcnr
Trait predicate ambiguities are not always in `Self`

When reporting ambiguities in trait predicates, the compiler incorrectly assumed the ambiguity was always in the type the trait should be implemented on, and never the generic parameters of the trait. This caused silly suggestions for predicates like `<KnownType as Trait<_>>`, such as giving explicit types to completely unrelated variables that happened to be of type `KnownType`.

This also reverts #73027, which worked around this issue in some cases and does not appear to be necessary any more.

fixes #77982
fixes #78055
2020-10-20 12:11:11 +09:00
Yuki Okushi
378ca5e640
Rollup merge of #77931 - aticu:fix_60336, r=petrochenkov
Fix false positive for `unused_parens` lint

Fixes #60336
2020-10-20 12:11:06 +09:00
Tomasz Miąsko
c2af254e3b Disable MatchBranchSimplification
This optimization can result in unsoundness, because it introduces
additional uses of a place holding the discriminant value without
ensuring that it is valid to do so.
2020-10-20 00:00:00 +00:00
Santiago Pastorino
d641cb82c1
Allow NtBlock to parse on check inline const next token 2020-10-19 18:50:58 -03:00
LeSeulArtichaut
66ac5a2d63 Do not ICE on pattern that uses a binding multiple times in generator 2020-10-19 23:34:47 +02:00
SNCPlay42
c146e8c54f revert workaround #73027 2020-10-19 21:11:40 +01:00
SNCPlay42
71ca239f80 don't assume trait ambiguity happens in Self 2020-10-19 21:11:40 +01:00
Santiago Pastorino
9dd0bb6fbc
Do not print braces again print_anon_const already does it 2020-10-19 16:26:13 -03:00
Aaron Hill
593fdd3d45
Rewrite collect_tokens implementations to use a flattened buffer
Instead of trying to collect tokens at each depth, we 'flatten' the
stream as we go allong, pushing open/close delimiters to our buffer
just like regular tokens. One capturing is complete, we reconstruct a
nested `TokenTree::Delimited` structure, producing a normal
`TokenStream`.

The reconstructed `TokenStream` is not created immediately - instead, it is
produced on-demand by a closure (wrapped in a new `LazyTokenStream` type). This
closure stores a clone of the original `TokenCursor`, plus a record of the
number of calls to `next()/next_desugared()`. This is sufficient to reconstruct
the tokenstream seen by the callback without storing any additional state. If
the tokenstream is never used (e.g. when a captured `macro_rules!` argument is
never passed to a proc macro), we never actually create a `TokenStream`.

This implementation has a number of advantages over the previous one:

* It is significantly simpler, with no edge cases around capturing the
  start/end of a delimited group.

* It can be easily extended to allow replacing tokens an an arbitrary
  'depth' by just using `Vec::splice` at the proper position. This is
  important for PR #76130, which requires us to track information about
  attributes along with tokens.

* The lazy approach to `TokenStream` construction allows us to easily
  parse an AST struct, and then decide after the fact whether we need a
  `TokenStream`. This will be useful when we start collecting tokens for
  `Attribute` - we can discard the `LazyTokenStream` if the parsed
  attribute doesn't need tokens (e.g. is a builtin attribute).

The performance impact seems to be neglibile (see
https://github.com/rust-lang/rust/pull/77250#issuecomment-703960604). There is a
small slowdown on a few benchmarks, but it only rises above 1% for incremental
builds, where it represents a larger fraction of the much smaller instruction
count. There a ~1% speedup on a few other incremental benchmarks - my guess is
that the speedups and slowdowns will usually cancel out in practice.
2020-10-19 13:59:18 -04:00
bors
a85e949276 Auto merge of #78106 - GuillaumeGomez:rollup-06vwk7p, r=GuillaumeGomez
Rollup of 4 pull requests

Successful merges:

 - #77877 (Use `try{}` in `try_fold` to decouple iterators in the library from `Try` details)
 - #78089 (Fix issue with specifying generic arguments for primitive types)
 - #78099 (Add missing punctuation)
 - #78103 (Add link to rustdoc book in rustdoc help popup)

Failed merges:

r? `@ghost`
2020-10-19 17:53:17 +00:00
Aaron Hill
f6aec82d4d
Avoid cloning the contents of a TokenStream in a few places 2020-10-19 12:30:41 -04:00
Guillaume Gomez
684fbd50ab
Rollup merge of #78089 - varkor:opt_const_param_of-error, r=lcnr
Fix issue with specifying generic arguments for primitive types

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

r? @lcnr
2020-10-19 18:20:23 +02:00
bors
f90e617305 Auto merge of #77908 - bugadani:obl-forest, r=nnethercote
Try to make ObligationForest more efficient

This PR tries to decrease the number of allocations in ObligationForest, as well as moves some cold path code to an uninlined function.
2020-10-19 15:14:15 +00:00
Ralf Jung
153e843c49 fix Rvalue::ty for ThreadLocalRef 2020-10-19 11:44:28 +02:00
Julian Wollersberger
52cedcab92 Remove <CTX: QueryContext> in a bunch of places.
It was only needed by `find_cycle_in_stack()` in job.rs, but needed to be forwarded through dozens of types.
2020-10-19 11:11:09 +02:00