Commit graph

2307 commits

Author SHA1 Message Date
Jonas Schievink 89ab56344d
Rollup merge of #79428 - camelid:fixup-compiler-docs, r=davidtwco
Fixup compiler docs

The sublist was being rendered as a code block because it was indented 4
spaces.
2020-11-26 13:39:20 +01:00
Jonas Schievink 815d96111d
Rollup merge of #79421 - camelid:_match-docs-fmt, r=petrochenkov
Fix docs formatting for `thir::pattern::_match`

They were being rendered all on one line.
2020-11-26 13:39:18 +01:00
Jonas Schievink 005a3e5986
Rollup merge of #79402 - bugadani:typos, r=matthewjasper
Fix typos
2020-11-26 13:39:11 +01:00
Jonas Schievink 0ae653a531
Rollup merge of #79365 - richkadel:llvm-cov-map-version-4, r=wesleywiser
Upgrades the coverage map to Version 4

Changes the coverage map injected into binaries compiled with
`-Zinstrument-coverage` to LLVM Coverage Mapping Format, Version 4 (from
Version 3). Note, binaries compiled with this version will require LLVM
tools from at least LLVM Version 11.

r? ``@wesleywiser``
2020-11-26 13:39:09 +01:00
Jonas Schievink 85c11de2f2
Rollup merge of #79362 - cjgillot:relou, r=oli-obk
Lower patterns before using the bound variable

So as to avoid having to lower patterns twice.
2020-11-26 13:39:07 +01:00
Jonas Schievink 6fcd589025
Rollup merge of #79000 - sivadeilra:user/ardavis/lev_distance, r=wesleywiser
Move lev_distance to rustc_ast, make non-generic

rustc_ast currently has a few dependencies on rustc_lexer. Ideally, an AST
would not have any dependency its lexer, for minimizing
design-time dependencies. Breaking this dependency would also have practical
benefits, since modifying rustc_lexer would not trigger a rebuild of rustc_ast.

This commit does not remove the rustc_ast --> rustc_lexer dependency,
but it does remove one of the sources of this dependency, which is the
code that handles fuzzy matching between symbol names for making suggestions
in diagnostics. Since that code depends only on Symbol, it is easy to move
it to rustc_span. It might even be best to move it to a separate crate,
since other tools such as Cargo use the same algorithm, and have simply
contain a duplicate of the code.

This changes the signature of find_best_match_for_name so that it is no
longer generic over its input. I checked the optimized binaries, and this
function was duplicated for nearly every call site, because most call sites
used short-lived iterator chains, generic over Map and such. But there's
no good reason for a function like this to be generic, since all it does
is immediately convert the generic input (the Iterator impl) to a concrete
Vec<Symbol>. This has all of the costs of generics (duplicated method bodies)
with no benefit.

Changing find_best_match_for_name to be non-generic removed about 10KB of
code from the optimized binary. I know it's a drop in the bucket, but we have
to start reducing binary size, and beginning to tame over-use of generics
is part of that.
2020-11-26 13:39:05 +01:00
Jonas Schievink 9b2117d1f6
Rollup merge of #77758 - Stupremee:turbofish-help-for-const, r=varkor
suggest turbofish syntax for uninferred const arguments

When not providing a const generic value, and it can not be inferred, the following suggestion is suggested:
![image](https://user-images.githubusercontent.com/39732259/95616180-af127b80-0a69-11eb-8877-551c815f9627.png)

Resolves #76737

r? ``@varkor``
2020-11-26 13:39:00 +01:00
bors aefcf1f342 Auto merge of #79427 - Aaron1011:fix/const-array-index, r=oli-obk
Resolve inference variables before trying to remove overloaded indexing

Fixes #79152

This code was already set up to handle indexing an array. However, it
appears that we never end up with an inference variable for the slice
case, so the missing call to `resolve_vars_if_possible` had no effect
until now.
2020-11-26 11:59:17 +00:00
Benedikt Terhechte 96779647c4 Add support for Arm64 Catalyst on ARM Macs 2020-11-26 11:31:59 +01:00
Aaron Hill 0b64110b10
Resolve inference variables before trying to remove overloaded indexing
Fixes #79152

This code was already set up to handle indexing an array. However, it
appears that we never end up with an inference variable for the slice
case, so the missing call to `resolve_vars_if_possible` had no effect
until now.
2020-11-25 18:41:10 -05:00
Rich Kadel fdbc121620
fix URLs in doc comment
The angle brackets were confusing my IDE and I thought they were unnecessary. I was wrong.
2020-11-25 13:30:33 -08:00
Camelid c5c70d4017 Fix docs formatting for thir::pattern::_match
A list was being rendered all on one line and there were other
formatting issues as well.
2020-11-25 13:23:06 -08:00
bors b48cafd9eb Auto merge of #79411 - tmiasko:naked-params, r=Amanieu
Validate use of parameters in naked functions

* Reject use of parameters inside naked function body.
* Reject use of patterns inside function parameters, to emphasize role
  of parameters a signature declaration (mirroring existing behaviour
  for function declarations) and avoid generating code introducing
  specified bindings.

Closes issues below by considering input to be ill-formed.

Closes #75922.
Closes #77848.
Closes #79350.
2020-11-25 21:22:46 +00:00
Camelid 46a750e35b Fixup compiler docs
The sublist was being rendered as a code block because it was indented 4
spaces.
2020-11-25 13:15:48 -08:00
Aaron Hill 7a9aa4f980
Fix rebase fallout 2020-11-25 15:08:51 -05:00
Aaron Hill 6a9dbd2e0e
Only populate local_def_path_hash_to_def_id when needed 2020-11-25 14:49:44 -05:00
Aaron Hill e935d3832c
Lazy DefPath decoding for incremental compilation 2020-11-25 14:49:15 -05:00
Rich Kadel d334f589c4
Update compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs 2020-11-25 11:41:23 -08:00
Rich Kadel b1df6c0e63
replace assert with condition and fatal error 2020-11-25 11:38:09 -08:00
Dániel Buga 29e8e72675 Fix typos 2020-11-25 20:18:36 +01:00
b-naber 37d103f3cf insert span_fatal call in ast lowering to indicate that generic arguments in AssocTyConstraints haven't been fully implemented 2020-11-25 19:56:10 +01:00
b-naber 823dbb38e4 ast and parser 2020-11-25 19:55:41 +01:00
bors 192c7dbb6d Auto merge of #79326 - Aaron1011:fix/builtin-macro-stmt, r=petrochenkov
Always invoke statement attributes on the statement itself

This is preparation for PR #78296, which will require us to handle
statement items in addition to normal items.
2020-11-25 18:37:55 +00:00
Rich Kadel b4668ecb73 Improved version check 2020-11-25 09:45:33 -08:00
Aaron Hill baefba80b7
Adjust pretty-print compat hack to work with item statements 2020-11-25 11:32:08 -05:00
bors db79d2f637 Auto merge of #79216 - Aaron1011:opt-on-disk-cache, r=pnkfelix
Only create `OnDiskCache` in incremental compilation mode

This lets us skip doing useless work when we're not in incremental
compilation mode.
2020-11-25 16:22:11 +00:00
flip1995 e54c0600b4
Reword message at the end of the output if not run with a lint tool 2020-11-25 13:16:36 +01:00
bors 20dcbf0df0 Auto merge of #79397 - camelid:polonious-incr-comp, r=jonas-schievink
TRACK '-Z polonius' flag

Fixes #79316.

r? `@jonas-schievink`
2020-11-25 11:54:04 +00:00
bors 773ddbada7 Auto merge of #79388 - tmiasko:naked-def-only, r=lcnr
Validate that `#[naked]` is applied to a function definition
2020-11-25 09:41:15 +00:00
bors ec039bd075 Auto merge of #79336 - camelid:rename-feature-oibit-to-auto, r=oli-obk
Rename `optin_builtin_traits` to `auto_traits`

They were originally called "opt-in, built-in traits" (OIBITs), but
people realized that the name was too confusing and a mouthful, and so
they were renamed to just "auto traits". The feature flag's name wasn't
updated, though, so that's what this PR does.

There are some other spots in the compiler that still refer to OIBITs,
but I don't think changing those now is worth it since they are internal
and not particularly relevant to this PR.

Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>.

r? `@oli-obk` (feel free to re-assign if you're not the right reviewer for this)
2020-11-25 07:25:19 +00:00
Camelid c4caf5ad36 TRACK '-Z polonius' flag 2020-11-24 20:08:54 -08:00
Rich Kadel b5fef37d23
Apply suggestions from code review
Co-authored-by: Wesley Wiser <wwiser@gmail.com>
2020-11-24 18:34:10 -08:00
Camelid 82dc99ba7a Use the name "auto traits" everywhere in the compiler
Goodbye, OIBIT!
2020-11-24 16:25:43 -08:00
Arlie Davis 5481c1bd6d Move lev_distance to rustc_ast, make non-generic
rustc_ast currently has a few dependencies on rustc_lexer. Ideally, an AST
would not have any dependency its lexer, for minimizing unnecessarily
design-time dependencies. Breaking this dependency would also have practical
benefits, since modifying rustc_lexer would not trigger a rebuild of rustc_ast.

This commit does not remove the rustc_ast --> rustc_lexer dependency,
but it does remove one of the sources of this dependency, which is the
code that handles fuzzy matching between symbol names for making suggestions
in diagnostics. Since that code depends only on Symbol, it is easy to move
it to rustc_span. It might even be best to move it to a separate crate,
since other tools such as Cargo use the same algorithm, and have simply
contain a duplicate of the code.

This changes the signature of find_best_match_for_name so that it is no
longer generic over its input. I checked the optimized binaries, and this
function was duplicated at nearly every call site, because most call sites
used short-lived iterator chains, generic over Map and such. But there's
no good reason for a function like this to be generic, since all it does
is immediately convert the generic input (the Iterator impl) to a concrete
Vec<Symbol>. This has all of the costs of generics (duplicated method bodies)
with no benefit.

Changing find_best_match_for_name to be non-generic removed about 10KB of
code from the optimized binary. I know it's a drop in the bucket, but we have
to start reducing binary size, and beginning to tame over-use of generics
is part of that.
2020-11-24 16:12:23 -08:00
Tomasz Miąsko 22d3431221 Validate use of parameters in naked functions
* Reject use of parameters inside naked function body.
* Reject use of patterns inside function parameters, to emphasize role
  of parameters a signature declaration (mirroring existing behaviour
  for function declarations) and avoid generating code introducing
  specified bindings.
2020-11-25 00:00:00 +00:00
Aaron Hill 9c9f40656d
Invoke attributes on the statement for statement items 2020-11-24 16:38:58 -05:00
bors 1c389ffeff Auto merge of #78548 - camelid:driver-tty, r=oli-obk
driver: Only output ANSI logging if connected to a terminal

Fixes #78435.

See #78435 for more.

Cc `@RalfJung` `@oli-obk`
2020-11-24 20:58:20 +00:00
Rich Kadel 51268d2735 Check for LLVM 11+ when using -Z instrument-coverage
* `rustc` should now compile under LLVM 9 or 10
* Compiler generates an error if `-Z instrument-coverage` is specified
  but LLVM version is less than 11
* Coverage tests that require `-Z instrument-coverage` and run codegen
  should be skipped if LLVM version is less than 11
2020-11-24 11:50:24 -08:00
Aaron Hill e9546bdbaf
Handle Annotatable::Stmt in some builtin macros
This is preparation for PR #78296, which will require us to handle
statement items in addition to normal items.
2020-11-24 14:04:32 -05:00
Jonas Schievink f049b0be96
Rollup merge of #79374 - mendess:const-param-expr-diagnostic, r=lcnr
Add note to use nightly when using expr in const generics

As recommended by `@Icnr` in #73899 and in zulip, I've added a note saying that const expressions can be used in nightly.

```
error: generic parameters may not be used in const operations
  --> $DIR/issue-61935.rs:10:23
   |
 6 |         Self:FooImpl<{N==0}>
   |                       ^ cannot perform const operation using `N`
   |
   = help: const parameters may only be used as standalone arguments, i.e. `N`
   = note: use feature(const_generics) and feature(const_evaluatable_checked) to enable this

error: aborting due to previous error
```

I hope the note is well written 😅
2020-11-24 13:17:51 +01:00
Jonas Schievink 95e7af353f
Rollup merge of #79367 - Dirbaio:trap-unreachable, r=jonas-schievink
Allow disabling TrapUnreachable via -Ztrap-unreachable=no

Currently this is only possible by defining a custom target, which is quite unwieldy.

This is useful for embedded targets where small code size is desired. For example, on my project (thumbv7em-none-eabi) this yields a 0.6% code size reduction: 132892 bytes -> 132122 bytes (770 bytes down).
2020-11-24 13:17:49 +01:00
Jonas Schievink 3a728bd129
Rollup merge of #79346 - tmiasko:more-names, r=jonas-schievink
Allow using `-Z fewer-names=no` to retain value names

Change `-Z fewer-names` into an optional boolean flag and allow using it
to either discard value names when true or retain them when false,
regardless of other settings.
2020-11-24 13:17:41 +01:00
mendess 888055eb4c Swap note for help 2020-11-24 11:05:55 +00:00
mendess af978e3b63 Requested changes 2020-11-24 10:28:18 +00:00
flip1995 13db749c4b
Cleanup message at the end of the lint list output 2020-11-24 10:37:15 +01:00
flip1995 4daa263e0b
Always print lints from plugins, if they're available
Currently you can get a list of lints and lint groups by running `rustc
-Whelp`. This prints an additional line at the end:
```
Compiler plugins can provide additional lints and lint groups. To see a
listing of these, re-run `rustc -W help` with a crate filename.
```

Clippy is such a "compiler plugin", that provides additional lints.
Running `clippy-driver -Whelp` (`rustc` wrapper) still only prints the
rustc lints with the above message at the end. But when running
`clippy-driver -Whelp main.rs`, where `main.rs` is any rust file, it
also prints Clippy lints. I don't think this is a good approach from a
UX perspective: Why is a random file necessary to print a help message?

This commit changes this behavior: Whenever a compiler callback
registers lints, it is assumed that these lints come from a plugin and
are printed without having to specify a Rust source file.
2020-11-24 10:37:15 +01:00
flip1995 be1e502cef
Add method to get the register_lints function from the compiler 2020-11-24 10:37:14 +01:00
mendess b7593e5070 Add note to use nightly when using expr in const generics 2020-11-24 09:35:08 +00:00
bors 6331023708 Auto merge of #79294 - petrochenkov:determ, r=varkor
resolve: Do not put macros into `module.unexpanded_invocations` unless necessary

Macro invocations in modules <sup>(*)</sup> need to be tracked because they can produce named items when expanded.
We cannot give definite answer to queries like "does this module declare name `n`?" until all macro calls in that module are expanded.

Previously we marked too many macros as potentially producing named items.
E.g. in this example
```rust
mod m {
    const C: u32 = line!();
}
```
`line!()` cannot emit any items into module `m`, but it was still marked.
This PR fixes that and marks macro calls as "unexpanded in module" only if they can actually emit named items into that module.

Diagnostics in UI test outputs have different order now because this change affects macro expansion order.

<sup>*</sup> Any containers for named items are called modules in resolve (that includes blocks, traits and enums in addition to `mod` items).
2020-11-24 09:17:33 +00:00
Rich Kadel 5d5dc4c9d8 Updated links to LLVM 11 docs and types 2020-11-23 19:15:10 -08:00
Camelid 173a7dbace Use early_error 2020-11-23 17:39:18 -08:00
Dario Nieuwenhuis 7b62e09b03 Allow disabling TrapUnreachable via -Ztrap-unreachable=no
This is useful for embedded targets where small code size is desired.
For example, on my project (thumbv7em-none-eabi) this yields a 0.6% code size reduction.
2020-11-24 01:08:27 +01:00
Tomasz Miąsko 75e00e8cf4 Validate that #[naked] is applied to a function definition 2020-11-24 00:00:00 +00:00
Tomasz Miąsko bdc1d9774b Don't mark #[naked] as used when checking #[track_caller] 2020-11-24 20:45:09 +01:00
Rich Kadel 1d8c381c01 Upgrades the coverage map to Version 4
Changes the coverage map injected into binaries compiled with
`-Zinstrument-coverage` to LLVM Coverage Mapping Format, Version 4 (from
Version 3). Note, binaries compiled with this version will require LLVM
tools from at least LLVM Version 11.
2020-11-23 15:14:47 -08:00
Camelid 810324d1f3 Rename optin_builtin_traits to auto_traits
They were originally called "opt-in, built-in traits" (OIBITs), but
people realized that the name was too confusing and a mouthful, and so
they were renamed to just "auto traits". The feature flag's name wasn't
updated, though, so that's what this PR does.

There are some other spots in the compiler that still refer to OIBITs,
but I don't think changing those now is worth it since they are internal
and not particularly relevant to this PR.

Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>.
2020-11-23 14:14:06 -08:00
bors d9a105fdd4 Auto merge of #78439 - lzutao:rm-clouldabi, r=Mark-Simulacrum
Drop support for all cloudabi targets

`cloudabi` is a tier-3 target, and [it is no longer being maintained upstream][no].

This PR drops supports for cloudabi targets. Those targets are:
* aarch64-unknown-cloudabi
* armv7-unknown-cloudabi
* i686-unknown-cloudabi
* x86_64-unknown-cloudabi

Since this drops supports for a target, I'd like somebody to tag `relnotes` label to this PR.

Some other issues:
* The tidy exception for `cloudabi` crate is still remained because
  * `parking_lot v0.9.0` and `parking_lot v0.10.2` depends on `cloudabi v0.0.3`.
  * `parking_lot v0.11.0` depends on `cloudabi v0.1.0`.

[no]: https://github.com/NuxiNL/cloudabi#note-this-project-is-unmaintained
2020-11-23 19:01:19 +00:00
Camille GILLOT 27c60bad8a Remove Pat pre-lowering. 2020-11-23 19:02:47 +01:00
Camille GILLOT 6e17ab57fc Lower if let before the arms. 2020-11-23 18:55:59 +01:00
Jonas Schievink 064c3c146a
Rollup merge of #79337 - LingMan:map, r=jyn514
Use Option::map instead of open coding it

r?  `@jonas-schievink` since you're frequently sniping these minor cleanups anyway.
`@rustbot` modify labels +C-cleanup  +T-compiler
2020-11-23 15:25:53 +01:00
Jonas Schievink b48ebc6b15
Rollup merge of #79330 - jyn514:typo, r=jyn514
Fix typo in comment

This is trivial enough I'm just going to merge without review.

r? `@ghost`
2020-11-23 15:25:49 +01:00
Jonas Schievink b4db342f51
Rollup merge of #79325 - LingMan:try_op, r=jonas-schievink
Reduce boilerplate with the `?` operator

`@rustbot` modify labels to +C-cleanup.
2020-11-23 15:25:47 +01:00
Jonas Schievink 32be3ae06a
Rollup merge of #79324 - LingMan:and_then, r=jonas-schievink
Use Option::and_then instead of open-coding it

`@rustbot` modify labels to +C-cleanup.
2020-11-23 15:25:46 +01:00
Jonas Schievink c7a67209c8
Rollup merge of #79287 - jonas-schievink:const-trait-impl, r=oli-obk
Allow using generic trait methods in `const fn`

Next step for https://github.com/rust-lang/rust/issues/67792, this now also allows code like the following:

```rust
struct S;

impl const PartialEq for S {
    fn eq(&self, _: &S) -> bool {
        true
    }
}

const fn equals_self<T: PartialEq>(t: &T) -> bool {
    *t == *t
}

pub const EQ: bool = equals_self(&S);
```

This works by threading const-ness of trait predicates through trait selection, in particular through `ParamCandidate`, and exposing it in the resulting `ImplSource`.

Since this change makes two bounds `T: Trait` and `T: ?const Trait` that only differ in their const-ness be treated like different bounds, candidate winnowing has been changed to drop the `?const` candidate in favor of the const candidate, to avoid ambiguities when both a const and a non-const bound is present.
2020-11-23 15:25:44 +01:00
Jonas Schievink c58c245e2c
Rollup merge of #79236 - lcnr:mcg-resolve-dsb, r=eddyb
const_generics: assert resolve hack causes an error

prevent the min_const_generics `HACK`s in resolve from triggering a fallback path which successfully compiles so that we don't have to worry about future compat issues when removing it

r? `@eddyb` cc `@varkor`
2020-11-23 15:25:42 +01:00
Jonas Schievink d4a05696d9
Rollup merge of #79080 - camelid:mir-visit-debuginfo-project, r=jonas-schievink
MIR visitor: Don't treat debuginfo field access as a use of the struct

Fixes #77454.

r? `@jonas-schievink`
2020-11-23 15:25:40 +01:00
Aaron Hill 6e466efa11
Cache pretty-print/retokenize result to avoid compile time blowup
Fixes #79242

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

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

The proper solution is to remove the pretty-print/retokenize hack
entirely. However, this will almost certainly break a large number of
crates that were relying on hygiene bugs created by using the reparsed
`TokenStream`. As a result, we will definitely not want to backport
such a change.
2020-11-23 02:40:57 -05:00
LingMan cd8973250d Use Option::map instead of open coding it 2020-11-23 04:58:21 +01:00
Camelid b196bec236 Add comment and remove obsolete special case 2020-11-22 17:39:15 -08:00
Joshua Nelson 432a33e1e2 Fix typo in comment 2020-11-22 20:32:36 -05:00
Tomasz Miąsko fafe3cd682 Allow using -Z fewer-names=no to retain value names
Change `-Z fewer-names` into an optional boolean flag and allow using it
to either discard value names when true or retain them when false,
regardless of other settings.
2020-11-23 00:00:00 +00:00
LingMan e0871cc0be Reduce boilerplate with the ? operator 2020-11-23 00:58:53 +01:00
LingMan 674f196c50 Use Option::and_then instead of open-coding it 2020-11-22 23:44:05 +01:00
Lzu Tao 6bfe27a3e0 Drop support for cloudabi targets 2020-11-22 17:11:41 -05:00
Mara Bos 41c033b2f7
Rollup merge of #79299 - varkor:stabilise-then, r=m-ou-se
Stabilise `then`

Stabilises the lazy variant of https://github.com/rust-lang/rust/issues/64260 now that the FCP [has ended](https://github.com/rust-lang/rust/issues/64260#issuecomment-731636203).

I've kept the original feature gate `bool_to_option` for the strict variant (`then_some`), and created a new insta-stable feature gate `lazy_bool_to_option` for `then`.
2020-11-22 23:01:08 +01:00
bors c643dd2ec8 Auto merge of #79243 - Nadrieril:consolidate-tests, r=varkor
Consolidate exhaustiveness-related tests

I hunted for tests that only exercised the match exhaustiveness algorithm and regrouped them. I also improved integer-range tests since I had found them lacking while hacking around.
The interest is mainly so that one can pass `--test-args patterns` and catch most relevant tests.

r? `@varkor`
`@rustbot` modify labels: +A-exhaustiveness-checking
2020-11-22 18:29:38 +00:00
Guillaume Gomez 5c982b7ca2
Rollup merge of #79292 - nico-abram:master, r=jonas-schievink
Fix typo in doc comment for report_too_many_hashes

"to big" -> "too big"
2020-11-22 16:15:12 +01:00
varkor cf32afcf48 Stabilise then 2020-11-22 13:45:14 +00:00
Vadim Petrochenkov 27af650a0d resolve: Do not put macros into module.unexpanded_invocations unless necessary 2020-11-22 14:42:29 +03:00
Nicolas 7be6d67f82
Fix typo in doc comment for report_too_many_hashes
"to big" -> "too big"
2020-11-22 07:02:58 -03:00
bors 20328b5323 Auto merge of #79275 - integer32llc:doc-style, r=jonas-schievink
More consistently use spaces after commas in lists in docs

This PR changes instances of lists that didn't use spaces after commas, like `vec![1,2,3]`, to `vec![1, 2, 3]` to be more consistent with idiomatic Rust style (the way these were looks strange to me, especially because there are often lists that *do* use spaces after the commas later in the same code block 😬).

I noticed one of these in an example in the stdlib docs and went looking for more, but as far as I can see, I'm only changing those spots in user-facing documentation or rustc output, and the changes make no semantic difference.
2020-11-22 08:30:23 +00:00
Jonas Schievink e69fcea609 const fn: allow use of trait impls from bounds 2020-11-22 04:19:46 +01:00
Jonas Schievink 71d350e33a winnow: drop non-const cand. in favor of const 2020-11-22 04:04:49 +01:00
Jonas Schievink ee6f42ba94 Thread Constness through selection 2020-11-22 02:13:53 +01:00
Carol (Nichols || Goulding) ae17d7d455
More consistently use spaces after commas in lists in docs 2020-11-21 14:43:34 -05:00
Dylan DPC 68c9caa6f6
Rollup merge of #79272 - tmiasko:array-clone, r=jonas-schievink
Support building clone shims for arrays with generic size

Fixes #79269.
2020-11-21 19:44:20 +01:00
Dylan DPC 96ec5d299b
Rollup merge of #79256 - bugadani:query-typo, r=jonas-schievink
Fix typos
2020-11-21 19:44:16 +01:00
Dylan DPC 3958ceccac
Rollup merge of #79238 - eddyb:rustc-log-stderr, r=jyn514
Direct RUSTC_LOG (tracing/log) output to stderr instead of stdout.

Looks like this got missed in the initial implementation, AFAIK the old behavior was to output on stderr.
(Hit this while trying to debug `rustc` running inside a build script which was only letting stderr through)

r? ``@oli-obk`` cc ``@davidbarsky`` ``@hawkw``
2020-11-21 19:44:15 +01:00
Dylan DPC bb73ea6702
Rollup merge of #79231 - wusyong:issue-79137, r=lcnr
Exhaustively match in variant count instrinsic

Fix #79137
2020-11-21 19:44:13 +01:00
Dylan DPC 5d428cae7d
Rollup merge of #79182 - lochsh:78777-fix-extern-types-ref, r=jyn514
Fix links to extern types in rustdoc (fixes #78777)

 r? `@jyn514`
 Fixes #78777.
The initial fix we tried was:
```diff
diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs
index 8be9482acff..c4b7086fdb1 100644
--- a/src/librustdoc/passes/collect_intra_doc_links.rs
+++ b/src/librustdoc/passes/collect_intra_doc_links.rs
`@@` -433,8 +433,9 `@@` impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
             Res::PrimTy(prim) => Some(
                 self.resolve_primitive_associated_item(prim, ns, module_id, item_name, item_str),
             ),
-            Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::TyAlias, did) => {
+            Res::Def(kind, did) if kind.ns() == Some(Namespace::TypeNS) => {
                 debug!("looking for associated item named {} for item {:?}", item_name, did);
+
                 // Checks if item_name belongs to `impl SomeItem`
                 let assoc_item = cx
                     .tcx
```

However, this caused traits to be matched, resulting in a panic when `resolve_associated_trait_item` is called further down in this function.

This PR also adds an error message for that panic. Currently it will look something like:
```rust
thread 'rustc' panicked at 'Not a type: DefIndex(8624)', compiler/rustc_metadata/src/rmeta/decoder.rs:951:32
```
I wasn't sure how to get a better debug output than `DefIndex(...)`, and am open to suggestions.
2020-11-21 19:44:11 +01:00
bjorn3 43968aa8b8 Replace sext() and zext() with single ext() method 2020-11-21 19:22:31 +01:00
bjorn3 6a5f537fb9 Rename prefix_chunk to prefix_chunk_size 2020-11-21 19:22:31 +01:00
bjorn3 39b8b2b623 Remove StructRet arg attr
It is applied exactly when the return value has an indirect pass mode.
Except for InReg on x86 fastcall, arg attrs are now only used for
optimization purposes and thus are fine to ignore.
2020-11-21 19:22:31 +01:00
bjorn3 42b0b8080d Replace ByVal attribute with on_stack field for Indirect
This makes it clearer that only PassMode::Indirect allows ByVal
2020-11-21 19:22:30 +01:00
bjorn3 967a228208 Replace ZExt and SExt flags with ArgExtension enum
Both flags are mutually exclusive
2020-11-21 19:07:38 +01:00
bors 539402cb0b Auto merge of #77805 - JohnTitor:non-standard-char-sugg, r=Dylan-DPC
lint: Do not provide suggestions for non standard characters

Fixes #77273

Only provide suggestions if the case-fixed result is different than the original.
2020-11-21 13:11:35 +00:00
Dániel Buga db8b86b2df Fix typos 2020-11-21 09:06:45 +01:00
bors 502c477b34 Auto merge of #79003 - petrochenkov:innertest, r=estebank
rustc_expand: Mark inner `#![test]` attributes as soft-unstable

Custom inner attributes are feature gated (https://github.com/rust-lang/rust/issues/54726) except for attributes having name `test` literally, which are not gated for historical reasons.

`#![test]` is an inner proc macro attribute, so it has all the issues described in https://github.com/rust-lang/rust/issues/54726 too.
This PR gates it with the `soft_unstable` lint.
2020-11-21 05:52:16 +00:00
Ngo Iok Ui ef34e06781
List all variants of TyKind 2020-11-21 13:45:59 +08:00
bors 8cfa7b4ec9 Auto merge of #78588 - HeroicKatora:sccc, r=nikomatsakis
Reworks Sccc computation to iteration instead of recursion

Linear graphs, producing as many scc's as nodes, would recurse once for every node when entered from the start of the list. This adds a test that exhausted the stack at least on my machine with error:

```
thread 'graph::scc::tests::test_deep_linear' has overflowed its stack
fatal runtime error: stack overflow
```

This may or may not be connected to #78567. I was only reminded that I started this rework some time ago. It might be plausible as borrow checking a long function with many borrow regions around each other—((((((…))))))— may produce the linear list setup to trigger this stack overflow ? I don't know enough about borrow check to say for sure.

This is best read in two separate commits. The first addresses only `find_state` internally. This is classical union phase from union-find. There's also a common solution of using the parent pointers in the (virtual) linked list to track the backreferences while traversing upwards and then following them backwards in a second path compression phase.

The second is more involved as it rewrites the mutually recursive `walk_node` and `walk_unvisited_node`. Firstly, the caller is required to handle the unvisited case of `walk_node` so a new `start_walk_from` method is added to handle that by walking the unvisited node if necessary. Then `walk_unvisited_node`, where we would previously recurse into in the missing case, is rewritten to construct a manual stack of its frames. The state fields consist of the previous stack slots.
2020-11-21 01:30:26 +00:00
Tomasz Miąsko fac8b4e21a Support building clone shims for arrays with generic size 2020-11-21 00:00:00 +00:00
bors 432d116a5c Auto merge of #78569 - bugadani:arena-spec, r=Mark-Simulacrum
Arena: use specialization to avoid copying data

In several cases, a `Vec` or `SmallVec` is passed to `Arena::alloc_from_iter` directly. This PR makes sure those cases don't copy their data unnecessarily, by specializing the `alloc_from_iter` implementation.
2020-11-20 23:21:34 +00:00
Bastian Kauschke c85af74fcd update bug message for cg 2020-11-20 23:31:36 +01:00
Bastian Kauschke 34ea5d02dd const_generics: assert resolve hack causes an error 2020-11-20 23:29:54 +01:00
Dániel Buga e93a4637c0 Use specialization to avoid copying 2020-11-20 21:02:09 +01:00
Eduard-Mihai Burtescu 5ed2d42334 Direct RUSTC_LOG (tracing/log) output to stderr instead of stdout. 2020-11-20 19:34:44 +02:00
Vadim Petrochenkov 993bb072ff rustc_expand: Mark inner #![test] attributes as soft-unstable 2020-11-20 19:35:03 +03:00
Ngo Iok Ui 459c83f980
Exhaustively match in variant count instrinsic 2020-11-20 21:49:49 +08:00
bors ae6aa22cf2 Auto merge of #78646 - tgnottingham:packed_fingerprints, r=nnethercote
Use PackedFingerprint in DepNode to reduce memory consumption
2020-11-20 11:11:19 +00:00
Tyson Nottingham 142932ab19 Set unaligned_references lint to deny in rustc_data_structures
To detect misuse of private packed field in `PackedFingerprint`.
2020-11-20 01:13:15 -08:00
bors 5c45969502 Auto merge of #79192 - tmiasko:naked-noinline, r=oli-obk
Never inline naked functions

The `#[naked]` attribute disabled prologue / epilogue emission for the
function and it is responsibility of a developer to provide them. The
compiler is no position to inline such functions correctly.

Disable inlining of naked functions at LLVM and MIR level.

Closes #60919.
2020-11-20 06:01:49 +00:00
bors 74285eb3a8 Auto merge of #78088 - fusion-engineering-forks:panic-fmt-lint, r=estebank
Add lint for panic!("{}")

This adds a lint that warns about `panic!("{}")`.

`panic!(msg)` invocations with a single argument use their argument as panic payload literally, without using it as a format string. The same holds for `assert!(expr, msg)`.

This lints checks if `msg` is a string literal (after expansion), and warns in case it contained braces. It suggests to insert `"{}", ` to use the message literally, or to add arguments to use it as a format string.

![image](https://user-images.githubusercontent.com/783247/96643867-79eb1080-1328-11eb-8d4e-a5586837c70a.png)

This lint is also a good starting point for adding warnings about `panic!(not_a_string)` later, once [`panic_any()`](https://github.com/rust-lang/rust/pull/74622) becomes a stable alternative.
2020-11-20 03:40:20 +00:00
Tomasz Miąsko c2fb99984c Never inline naked functions
The `#[naked]` attribute disabled prologue / epilogue emission for the
function and it is responsibility of a developer to provide them. The
compiler is no position to inline such functions correctly.

Disable inlining of naked functions at LLVM and MIR level.
2020-11-20 00:00:00 +00:00
Dylan DPC 95da425593
Rollup merge of #79212 - LeSeulArtichaut:rustc-ty, r=jonas-schievink
Move `rustc_ty` -> `rustc_ty_utils`

Implements MCP rust-lang/compiler-team#387.
r? `@jonas-schievink`
2020-11-19 23:58:48 +01:00
Dylan DPC 084fc293eb
Rollup merge of #79193 - tmiasko:revert-78969-normalize, r=davidtwco
Revert #78969 "Normalize function type during validation"

Closes #79066.
Reopens #78442.
2020-11-19 23:58:43 +01:00
Dylan DPC 8216b359e5
Rollup merge of #79185 - petrochenkov:derattr2, r=Aaron1011
expand/resolve: Pre-requisites to "Turn `#[derive]` into a regular macro attribute"

Miscellaneous refactorings and error reporting changes extracted from https://github.com/rust-lang/rust/pull/79078.

Unlike https://github.com/rust-lang/rust/pull/79078 this PR doesn't make any observable changes to the language or library.
r? ```@Aaron1011```
2020-11-19 23:58:42 +01:00
LeSeulArtichaut f59d03038c Move rustc_ty -> rustc_ty_utils 2020-11-19 21:57:29 +01:00
Aaron Hill d00ed01876
Only create OnDiskCache in incremental compilation mode
This lets us skip doing useless work when we're not in incremental
compilation mode.
2020-11-19 15:50:55 -05:00
Nadrieril 82bf5b61cd Regroup many usefulness-related test in the same folder 2020-11-19 19:52:54 +00:00
Vadim Petrochenkov d575aa4d58 expand: Mark some dead code in derive expansion as unreachable 2020-11-19 19:25:20 +03:00
Vadim Petrochenkov cd2177f3de expand: Stop derive expansion un unexpected targets early
Collect derive placeholders using `collect` instead of `push`
2020-11-19 19:25:20 +03:00
Vadim Petrochenkov ec547202b4 expand: Cleanup attribute collection in invocation collector 2020-11-19 19:25:20 +03:00
Vadim Petrochenkov dfb690eaa9 resolve/expand: Misc cleanup 2020-11-19 19:25:20 +03:00
Vadim Petrochenkov 68f94e94ed resolve: Centralize some error reporting for unexpected macro resolutions 2020-11-19 19:25:20 +03:00
Vadim Petrochenkov 69894ce9ac resolve: Introduce a separate NonMacroAttrKind for legacy derive helpers 2020-11-19 19:25:20 +03:00
Vadim Petrochenkov e7ee4d66ce expand: Move fully_configure to config.rs 2020-11-19 19:25:20 +03:00
Vadim Petrochenkov b49fbc9432 expand: Tell built-in macros whether we are currently in forced expansion mode 2020-11-19 19:25:20 +03:00
Dylan DPC b5fffdc12b
Rollup merge of #79164 - varkor:unbraced-single-segment-const-arguments, r=petrochenkov
Permit standalone generic parameters as const generic arguments in macros

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

r? ```@petrochenkov```
2020-11-19 16:26:44 +01:00
Dylan DPC 5c7d530b5e
Rollup merge of #79149 - sexxi-goose:upvar_ref, r=nikomatsakis
Move capture lowering from THIR to MIR

This allows us to:
- Handle precise Places captured by a closure directly in MIR. Handling
  captures in MIR is easier since we can rely on/ tweak PlaceBuilder to
  generate `mir::Place`s that resemble how we store captures (`hir::Place`).

- Handle `let _ = x` case when feature `capture_disjoint_fields`
  is enabled directly in MIR. This is required to be done in MIR since
  patterns are desugared in MIR.

Closes: rust-lang/project-rfc-2229#25

r? ```@nikomatsakis```
2020-11-19 16:26:39 +01:00
Dylan DPC 2fdcd245df
Rollup merge of #79117 - cjkenn:mir-fuel, r=oli-obk
add optimization fuel checks to some mir passes

Fixes #77402

Inserts a bunch of calls to `consider_optimizing`. Note that `consider_optimizing` is the method that actually decrements the fuel count, so the point at which it's called is when the optimization takes place, from a fuel perspective. This means that where we call it has some thought behind it:

1. We probably don't want to decrement the fuel count before other simple checks, otherwise we count an optimization as being performed even if nothing was mutated (ie. it returned early).
2. In cases like `InstCombine`, where we gather optimizations in a pass and then mutate values, we probably would rather skip the gathering pass for performance reasons rather than skip the mutations afterwards.
2020-11-19 16:26:35 +01:00
Dylan DPC 470f768c97
Rollup merge of #79110 - estebank:issue-58964, r=oli-obk
Remove redundant notes in E0275

Fix #58964.
2020-11-19 16:26:31 +01:00
Dylan DPC 05ff58e645
Rollup merge of #79101 - tmiasko:lower-func-type, r=jonas-schievink
Don't special case constant operands when lowering intrinsics
2020-11-19 16:26:27 +01:00
Dylan DPC 3f0f224be4
Rollup merge of #79082 - ThePuzzlemaker:issue-78941-fix, r=estebank
Improve the diagnostic for when an `fn` contains qualifiers inside an `extern` block.

This mitigates #78941. As suggested by ```@estebank,``` `span_suggestion` was replaced with `span_suggestion_verbose` for this specific diagnostic.
2020-11-19 16:26:21 +01:00
Dylan DPC 5a58b50698
Rollup merge of #78961 - CraftSpider:22565, r=oli-obk
Make bad "rust-call" arguments no longer ICE

The simplest of bad rust-call definitions will no longer cause an ICE. There is a FIXME added for future work, as I wanted to get this easy fix in before trying to either add a hack or mess with the whole obligation system

fixes #22565
2020-11-19 16:26:19 +01:00
cjkenn 1d3305aa66 remove check from const promotion 2020-11-19 08:21:20 -05:00
Tomasz Miąsko 0ab44584aa Revert "Normalize function type during validation"
This reverts commit d486bfcbff.
2020-11-19 05:36:55 +01:00
Tomasz Miąsko 8247223f74 Revert "Always use param_env_reveal_all_normalized in validator"
This reverts commit 99be78d135.
2020-11-19 05:36:51 +01:00
cjkenn b556690c53 move checks later into optimization passes 2020-11-18 19:16:23 -05:00
bors 675f114d95 Auto merge of #79106 - tmiasko:inline-hint, r=nagisa,eddyb
Fix setting inline hint based on `InstanceDef::requires_inline`

For instances where `InstanceDef::requires_inline` is true, an attempt
is made to set an inline hint though a call to the `inline` function.
The attempt is ineffective, since all attributes will be usually removed
by the second call.

Fix the issue by applying the attributes only once, with user provided
attributes having a priority when provided.

Closes #79108.
2020-11-18 23:44:54 +00:00
Tyson Nottingham 05dde137ca Make PackedFingerprint's Fingerprint private 2020-11-18 15:10:43 -08:00
bors 8256379832 Auto merge of #78995 - Nadrieril:clean-empty-match, r=varkor
Handle empty matches cleanly in exhaustiveness checking

This removes the special-casing of empty matches that was done in `check_match`. This fixes most of https://github.com/rust-lang/rust/issues/55123.
Somewhat unrelatedly, I also made `_match.rs` more self-contained, because I think it's cleaner.

r? `@varkor`
`@rustbot` modify labels: +A-exhaustiveness-checking
2020-11-18 21:24:40 +00:00
Hannah McLaughlin d38dbcb19f Improve error message when we try to get_type on something that does not have a type 2020-11-18 21:20:51 +00:00
Tyson Nottingham f09d474836 Use PackedFingerprint in DepNode to reduce memory consumption 2020-11-18 12:49:09 -08:00
Justus K 4379a43e46
Suggest turbofish for uninferred const argument 2020-11-18 19:23:22 +01:00
Joshua Nelson 6354e85e8f Don't run resolve_vars_if_possible in normalize_erasing_regions
NOTE: `needs_infer()` needs to come after ignoring generic parameters
2020-11-18 12:25:36 -05:00
Esteban Küber c12e77badd review comment 2020-11-18 09:06:18 -08:00
Esteban Küber 352796402f Account for indirect cyclic requirements 2020-11-18 09:06:18 -08:00
Esteban Küber 2098ade771 Remove redundant notes in E0275
Fix #58964.
2020-11-18 09:05:48 -08:00
Mara Bos 43d13e2d58
Rollup merge of #79158 - lcnr:lazy-norm-coerce, r=oli-obk
type is too big -> values of the type are too big

strictly speaking, `[u8; usize::MAX]` or even `[[[u128; usize::MAX]; usize::MAX]; usize::MAX]` are absolutely fine types as long as you don't try to deal with any values of it.

This error message seems to cause some confusion imo, for example in https://github.com/rust-lang/rust/pull/79135#issuecomment-729361380 so I would prefer us to be more precise here.

See the added test case which uses one of these types without causing an error.

r? ``@oli-obk``
2020-11-18 15:46:40 +01:00
Mara Bos f85c3f72a4
Rollup merge of #79079 - camelid:mir-visit-docs, r=matthewjasper
Turn top-level comments into module docs in MIR visitor
2020-11-18 15:46:29 +01:00