Commit graph

2166 commits

Author SHA1 Message Date
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
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
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
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
Camelid 82dc99ba7a Use the name "auto traits" everywhere in the compiler
Goodbye, OIBIT!
2020-11-24 16:25:43 -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
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
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
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
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
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
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