Commit Graph

312 Commits

Author SHA1 Message Date
Santiago Pastorino a9bfb5d837
Move overlap_mode into trait level attribute + feature flag 2022-01-31 11:50:43 -03:00
yuhaixin.hx 6562069ebe remove allow_fail test flag 2022-01-28 18:31:49 +08:00
lcnr e6808381e5 update pass_by_value 2022-01-27 07:58:33 +01:00
Amanieu d'Antras a62c9fa526 Update tracking issue numbers for inline assembly sub-features 2022-01-26 15:59:46 +00:00
Matthias Krüger 3d6f276ca7
Rollup merge of #93175 - spastorino:negative-traits-coherence-new, r=nikomatsakis
Implement stable overlap check considering negative traits

This PR implement the new disjointness rules for overlap check described in https://rust-lang.github.io/negative-impls-initiative/explainer/coherence-check.html#new-disjointness-rules

r? ``@nikomatsakis``
2022-01-25 05:51:12 +01:00
Santiago Pastorino d2d25a5be0
Implement stable with negative coherence mode 2022-01-21 18:22:21 -03:00
Caio 5f74ef4fb1 Formally implement let chains 2022-01-18 19:38:17 -03:00
bors 7bc7be860f Auto merge of #87648 - JulianKnodt:const_eq_constrain, r=oli-obk
allow eq constraints on associated constants

Updates #70256

(cc `@varkor,` `@Centril)`
2022-01-18 09:58:39 +00:00
Matthias Krüger 804072fdfc
Rollup merge of #92701 - ehuss:even-more-attr-validation, r=matthewjasper
Add some more attribute validation

This adds some more validation for the position of attributes:

* `link` is only valid on an `extern` block
* `windows_subsystem` and `no_builtins` are only valid at the crate level
2022-01-18 04:41:59 +01:00
kadmin 1c1ce2fbda Add term to ExistentialProjection
Also prevent ICE when adding a const in associated const equality.
2022-01-17 20:01:22 +00:00
Matthias Krüger 32d85c0b5a
Rollup merge of #92164 - WaffleLapkin:rustc_must_implement_one_of_attr, r=Aaron1011
Implement `#[rustc_must_implement_one_of]` attribute

This PR adds a new attribute — `#[rustc_must_implement_one_of]` that allows changing the "minimal complete definition" of a trait. It's similar to GHC's minimal `{-# MINIMAL #-}` pragma, though `#[rustc_must_implement_one_of]` is weaker atm.

Such attribute was long wanted. It can be, for example, used in `Read` trait to make transitions to recently added `read_buf` easier:
```rust
#[rustc_must_implement_one_of(read, read_buf)]
pub trait Read {
    fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
        let mut buf = ReadBuf::new(buf);
        self.read_buf(&mut buf)?;
        Ok(buf.filled_len())
    }

    fn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<()> {
        default_read_buf(|b| self.read(b), buf)
    }
}

impl Read for Ty0 {}
//^ This will fail to compile even though all `Read` methods have default implementations

// Both of these will compile just fine
impl Read for Ty1 {
    fn read(&mut self, buf: &mut [u8]) -> Result<usize> { /* ... */ }
}
impl Read for Ty2 {
    fn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<()> { /* ... */ }
}
```

For now, this is implemented as an internal attribute to start experimenting on the design of this feature. In the future we may want to extend it:
- Allow arbitrary requirements like `a | (b & c)`
- Allow multiple requirements like
  - ```rust
    #[rustc_must_implement_one_of(a, b)]
    #[rustc_must_implement_one_of(c, d)]
    ```
- Make it appear in rustdoc documentation
- Change the syntax?
- Etc

Eventually, we should make an RFC and make this (or rather similar) attribute public.

---

I'm fairly new to compiler development and not at all sure if the implementation makes sense, but at least it passes tests :)
2022-01-17 20:07:02 +01:00
Mahdi Dibaiee a6762e962e
rustc_pass_by_value: allow types with no parameters on self
includes minor refactorings
2022-01-11 09:28:13 +00:00
Eric Huss b59e743666 Mark windows_subsytem and no_builtins as crate-only attributes.
These attributes are only checked at the crate root, so they should
have a warning if they are used anywhere else.
2022-01-09 13:08:30 -08:00
Mahdi Dibaiee 4c3e330a8c
feat: pass_by_value lint attribute
Useful for thin wrapper attributes that are best passed as value instead
of reference.
2022-01-09 13:05:51 +00:00
Waffle Maybe 96b2f8ac32 Apply suggestions from code review
Use "(associated) function" terminology instead of "method".

Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
2022-01-09 12:21:33 +03:00
Maybe Waffle 5ab40c8f99 Implement `#[rustc_must_implement_one_of]` attribute 2022-01-09 12:21:23 +03:00
Jacob Pratt d95f749f14
Stabilize `destructuring_assignment` 2021-12-14 22:38:51 -05:00
Ellen 59bf1f732f update accepted feature gate 2021-12-11 00:12:57 +00:00
Ellen 69d2d735bc remove feature gate and cleanup code 2021-12-10 19:20:31 +00:00
cynecx 686ace3b41 add `unwind_asm` feature gate for `may_unwind` option 2021-12-03 23:51:49 +01:00
Guillaume Gomez a6a1d7ca29
Rollup merge of #90420 - GuillaumeGomez:rustdoc-internals-feature, r=camelid
Create rustdoc_internals feature gate

As suggested by ``@camelid`` [here](https://github.com/rust-lang/rust/pull/90398#issuecomment-955093851), since `doc_keyword` and `doc_primitive` aren't meant to be stabilized, we could put them behind a same feature flag.

This is pretty much what it would look like (needs to update the tests too).

The tracking issue is https://github.com/rust-lang/rust/issues/90418.

What do you think ``@rust-lang/rustdoc`` ?
2021-11-24 22:56:37 +01:00
Guillaume Gomez 1e6ced3532 Create rustdoc_internals feature gate 2021-11-24 21:57:18 +01:00
Matthias Krüger a26c2c7495
Rollup merge of #91140 - nbdd0121:const_typeck, r=oli-obk
Split inline const to two feature gates and mark expression position inline const complete

This PR splits inline const in pattern position into its own `#![feature(inline_const_pat)]` feature gate, and make the usage in expression position complete.

I think I have resolved most outstanding issues related to `inline_const` with #89561 and other PRs. The only thing left that I am aware of is #90150 and the lack of lifetime checks when inline const is used in pattern position (FIXME in #89561). Implementation-wise when used in pattern position it has to be lowered during MIR building while in expression position it's evaluated only when monomorphizing (just like normal consts), so it makes some sense to separate it into two feature gates so one can progress without being blocked by another.

``@rustbot`` label: T-compiler F-inline_const
2021-11-23 19:28:10 +01:00
Gary Guo 6f38568dec `#![feature(inline_const)]` is no longer incomplete 2021-11-22 22:17:03 +00:00
Gary Guo 6d61d87b22 Split inline const to two feature gates 2021-11-22 22:17:03 +00:00
Eric Huss 67a5b193c1 Check for duplicate attributes. 2021-11-18 16:10:26 -08:00
Vadim Petrochenkov 91e02177a1 rustc: Remove `#[rustc_synthetic]`
This function parameter attribute was introduced in https://github.com/rust-lang/rust/pull/44866 as an intermediate step in implementing `impl Trait`, it's not necessary or used anywhere by itself.
2021-11-18 14:32:29 +08:00
Jacob Pratt 77b0613f1a
Alphabetize language features
This should significantly reduce the frequency of merge conflicts.
2021-11-15 21:33:39 -05:00
Josh Triplett 8c9bfaa5f3 Stabilize format_args_capture
Works as expected, and there are widespread reports of success with it,
as well as interest in it.
2021-11-15 10:14:29 +01:00
bors d212d902ae Auto merge of #89551 - jhpratt:stabilize-const_raw_ptr_deref, r=oli-obk
Stabilize `const_raw_ptr_deref` for `*const T`

This stabilizes dereferencing immutable raw pointers in const contexts.
It does not stabilize `*mut T` dereferencing. This is behind the
same feature gate as mutable references.

closes https://github.com/rust-lang/rust/issues/51911
2021-11-13 17:10:15 +00:00
Vadim Petrochenkov 6655727041 rustc_feature: Convert `BuiltinAttribute` from tuple to a struct 2021-11-12 20:15:14 +08:00
Amanieu d'Antras eb32c00216 Add features gates for experimental asm features 2021-11-07 01:23:53 +00:00
Jacob Pratt 0cdbeaa2a3
Stabilize `const_raw_ptr_deref` for `*const T`
This stabilizes dereferencing immutable raw pointers in const contexts.
It does not stabilize `*mut T` dereferencing. This is placed behind the
`const_raw_mut_ptr_deref` feature gate.
2021-11-06 17:05:15 -04:00
Matthias Krüger e38844a9d8
Rollup merge of #90502 - GuillaumeGomez:split-doc-cfg-feature, r=jyn514
Split doc_cfg and doc_auto_cfg features

Part of #90497.

With this feature, `doc_cfg` won't pick up items automatically anymore.

cc `@Mark-Simulacrum`
r? `@jyn514`
2021-11-02 23:48:50 +01:00
Matthias Krüger bc26dbba11
Rollup merge of #90472 - joshtriplett:clarify-feature-acceptance, r=jyn514
Clarify what to do with accepted feature gates

The documentation only referenced `removed.rs`, but feature gates for
accepted features move to `accepted.rs`.
2021-11-02 23:48:48 +01:00
Guillaume Gomez d50a4753b8 Split doc_cfg and doc_auto_cfg features 2021-11-02 16:55:50 +01:00
Josh Triplett eb23a7333f Add link to documentation about feature gates 2021-11-02 15:30:28 +01:00
Josh Triplett 597f889e45 Clarify what to do with accepted feature gates
The documentation only referenced `removed.rs`, but feature gates for
accepted features move to `accepted.rs`.
2021-11-01 15:34:19 +01:00
lcnr b40aa64e48 stabilize `relaxed_struct_unsize` 2021-10-30 15:56:02 +02:00
Mark Rousskov 3215eeb99f
Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
Matthias Krüger 87822b27ee
Rollup merge of #89558 - lcnr:query-stable-lint, r=estebank
Add rustc lint, warning when iterating over hashmaps

r? rust-lang/wg-incr-comp
2021-10-24 15:48:42 +02:00
bors aa5740c715 Auto merge of #90104 - spastorino:coherence-for-negative-trait, r=nikomatsakis
Implement coherence checks for negative trait impls

The main purpose of this PR is to be able to [move Error trait to core](https://github.com/rust-lang/project-error-handling/issues/3).

This feature is necessary to handle the following from impl on box.

```rust
impl From<&str> for Box<dyn Error> { ... }
```

Without having negative traits affect coherence moving the error trait into `core` and moving that `From` impl to `alloc` will cause the from impl to no longer compiler because of a potential future incompatibility. The compiler indicates that `&str` _could_ introduce an `Error` impl in the future, and thus prevents the `From` impl in `alloc` that would cause overlap with `From<E: Error> for Box<dyn Error>`. Adding `impl !Error for &str {}` with the negative trait coherence feature will disable this error by encoding a stability guarantee that `&str` will never implement `Error`, making the `From` impl compile.

We would have this in `alloc`:

```rust
impl From<&str> for Box<dyn Error> {} // A
impl<E> From<E> for Box<dyn Error> where E: Error {} // B
```

and this in `core`:

```rust
trait Error {}
impl !Error for &str {}
```

r? `@nikomatsakis`

This PR was built on top of `@yaahc` PR #85764.

Language team proposal: to https://github.com/rust-lang/lang-team/issues/96
2021-10-23 12:51:15 +00:00
Matthias Krüger 736e8ebd1c
Rollup merge of #89730 - crlf0710:type_changing_feature, r=jackh726
add feature flag for `type_changing_struct_update`

This implements the PR0 part of the mentoring notes within #86618.

overrides the previous inactive #86646 pr.

r? ```@nikomatsakis```
2021-10-23 05:28:22 +02:00
Santiago Pastorino da79fa964c
Add rustc_strict_coherence attribute and use it to check overlap 2021-10-22 15:49:46 -03:00
Charles Lew 7d7ebf8805 add feature flag for `type_changing_struct_update` 2021-10-22 11:46:55 -04:00
lcnr 80fe0bb76e add a `rustc::query_stability` lint 2021-10-15 10:58:18 +02:00
Mark Rousskov 8485e6fdec Revert "Stabilize `arbitrary_enum_discriminant`"
This reverts commit 7a62f29f31.
2021-10-14 10:57:56 -04:00
bors c34ac8747c Auto merge of #89247 - fee1-dead:const-eval-select, r=oli-obk
Add `const_eval_select` intrinsic

Adds an intrinsic that calls a given function when evaluated at compiler time, but generates a call to another function when called at runtime.

See https://github.com/rust-lang/const-eval/issues/7 for previous discussion.

r? `@oli-obk.`
2021-10-14 10:06:30 +00:00
Deadbeef 5387b6542f
Add const_eval_select intrinsic 2021-10-12 05:42:23 +00:00
Matthias Krüger cfa5391f0b
Rollup merge of #89428 - DevinR528:reachable-featuregate, r=Nadrieril,camelid
Feature gate the non_exhaustive_omitted_patterns lint

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

Add the machinery to gate the new `non_exhaustive_omitted_patterns` lint.

relates to https://github.com/rust-lang/rust/pull/89105 and https://github.com/rust-lang/rust/pull/89423
2021-10-10 18:22:19 +02:00
Matthias Krüger 03a34a291d
Rollup merge of #89605 - camelid:fix-version, r=nagisa
Fix stabilization version for `bindings_after_at`

According to the release notes and its PR milestone, it was stabilized
in 1.56.0.
2021-10-09 11:55:58 +02:00
Devin Ragotzy 14338786fd Add feature gate to non_exhaustive_omitted_patterns lint
Actually add the feature to the lints ui test
Add tracking issue to the feature declaration
Rename feature gate to non_exhaustive_omitted_patterns_lint
Add more omitted_patterns lint feature gate
2021-10-08 17:40:39 -04:00
Guillaume Gomez 8fac41a530 Clean up code a bit:
* Remove "bool_to_options" feature
 * Update version for compiler feature
 * rustfmt
2021-10-06 20:23:57 +02:00
Noah Lev 6189d0a116 Fix stabilization version for `bindings_after_at`
According to the release notes and its PR milestone, it was stabilized
in 1.56.0.
2021-10-06 09:34:39 -07:00
Joshua Nelson e36a370f08 Add test case for `doc_cfg_hide` feature gate 2021-10-05 18:15:30 +02:00
Wim Looman 18fdd816b7 Allow adding a set of cfg's to hide from being implicitly doc(cfg)'d
By adding #![doc(cfg_hide(foobar))] to the crate attributes the cfg
 #[cfg(foobar)] (and _only_ that _exact_ cfg) will not be implicitly
treated as a doc(cfg) to render a message in the documentation.
2021-10-05 18:04:15 +02:00
Jacob Pratt bce8621983
Stabilize `const_panic` 2021-10-04 02:33:33 -04:00
Vadim Petrochenkov 85f02901a3 Stabilize `feature(macro_attributes_in_derive_output)` 2021-09-24 21:48:30 +03:00
Aaron Hill 94b19fac26
Support `#[track_caller]` on closures and generators
This PR allows applying a `#[track_caller]` attribute to a
closure/generator expression. The attribute as interpreted as applying
to the compiler-generated implementation of the corresponding trait
method (`FnOnce::call_once`, `FnMut::call_mut`, `Fn::call`, or
`Generator::resume`).

This feature does not have its own feature gate - however, it requires
`#![feature(stmt_expr_attributes)]` in order to actually apply
an attribute to a closure or generator.

This is implemented in the same way as for functions - an extra
location argument is appended to the end of the ABI. For closures,
this argument is *not* part of the 'tupled' argument storing the
parameters - the final closure argument for `#[track_caller]` closures
is no longer a tuple.

For direct (monomorphized) calls, the necessary support was already
implemented - we just needeed to adjust some assertions around checking
the ABI and argument count to take closures into account.

For calls through a trait object, more work was needed.
When creating a `ReifyShim`, we need to create a shim
for the trait method (e.g. `FnOnce::call_mut`) - unlike normal
functions, closures are never invoked directly, and always go through a
trait method.

Additional handling was needed for `InstanceDef::ClosureOnceShim`. In
order to pass location information throgh a direct (monomorphized) call
to `FnOnce::call_once` on an `FnMut` closure, we need to make
`ClosureOnceShim` aware of `#[tracked_caller]`. A new field
`track_caller` is added to `ClosureOnceShim` - this is used by
`InstanceDef::requires_caller` location, allowing codegen to
pass through the extra location argument.

Since `ClosureOnceShim.track_caller` is only used by codegen,
we end up generating two identical MIR shims - one for
`track_caller == true`, and one for `track_caller == false`. However,
these two shims are used by the entire crate (i.e. it's two shims total,
not two shims per unique closure), so this shouldn't a big deal.
2021-09-22 15:19:33 -05:00
bors ce45663e14 Auto merge of #88865 - guswynn:must_not_suspend, r=oli-obk
Implement `#[must_not_suspend]`

implements #83310

Some notes on the impl:

1. The code that searches for the attribute on the ADT is basically copied from the `must_use` lint. It's not shared, as the logic did diverge
2. The RFC does specify that the attribute can be placed on fn's (and fn-like objects), like `must_use`. I think this is a direct copy from the `must_use` reference definition. This implementation does NOT support this, as I felt that ADT's (+ `impl Trait` + `dyn Trait`) cover the usecase's people actually want on the RFC, and adding an imp for the fn call case would be significantly harder. The `must_use` impl can do a single check at fn call stmt time, but `must_not_suspend` would need to answer the question: "for some value X with type T, find any fn call that COULD have produced this value". That would require significant changes to `generator_interior.rs`, and I would need mentorship on that. `@eholk` and I are discussing it.
3. `@estebank` do you know a way I can make the user-provided `reason` note pop out? right now it seems quite hidden

Also, I am not sure if we should run perf on this

r? `@nikomatsakis`
2021-09-22 06:43:33 +00:00
Mark Rousskov c746be2219 Migrate to 2021 2021-09-20 22:21:42 -04:00
Manish Goregaokar fb2d7dff80
Rollup merge of #88775 - pnkfelix:revert-anon-union-parsing, r=davidtwco
Revert anon union parsing

Revert PR #84571 and #85515, which implemented anonymous union parsing in a manner that broke the context-sensitivity for the `union` keyword and thus broke stable Rust code.

Fix #88583.
2021-09-15 14:56:58 -07:00
Gus Wynn 2af1ebfbdf error formatting and fix build 2021-09-13 08:19:40 -07:00
Gus Wynn 2271376fb2 must_not_suspend impl 2021-09-11 10:45:17 -07:00
Fabian Wolff 79adda930f Ignore automatically derived impls of `Clone` and `Debug` in dead code analysis 2021-09-09 19:49:07 +02:00
Felix S. Klock II 91feb76d13 Revert "Implement Anonymous{Struct, Union} in the AST"
This reverts commit 059b68dd67.

Note that this was manually adjusted to retain some of the refactoring
introduced by commit 059b68dd67, so that it could
likewise retain the correction introduced in commit
5b4bc05fa5
2021-09-09 09:14:17 -04:00
Mingwei Samuel f8cbb1935c
Fix typo in `const_generics` replaced with `adt_const_params` note 2021-09-07 09:27:30 -07:00
Cameron Steffen 960ea093ab Add let_else feature gate 2021-08-30 20:18:39 -05:00
lcnr 87e781799a `feature(const_param_types)` -> `feature(adt_const_params)` 2021-08-30 12:07:36 +02:00
lcnr 4747cbb3bb allow unordered const/ty params if any cg feature is active 2021-08-30 11:00:21 +02:00
lcnr 0c28e028b6 `feature(const_generics)` -> `feature(const_param_types)` 2021-08-30 11:00:21 +02:00
Ellen c0e853f274 remove lazy_normalization_consts 2021-08-30 11:00:21 +02:00
Ellen fcc2badf9b rename const_evaluatable_checked to generic_const_exprs
2021-08-30 11:00:21 +02:00
Deadbeef 8660832086
Introduce `~const`
- [x] Removed `?const` and change uses of `?const`
 - [x] Added `~const` to the AST. It is gated behind const_trait_impl.
 - [x] Validate `~const` in ast_validation.
 - [ ] Add enum `BoundConstness` to the HIR. (With variants `NotConst` and
 `ConstIfConst` allowing future extensions)
 - [ ] Adjust trait selection and pre-existing code to use `BoundConstness`.
 - [ ] Optional steps (*for this PR, obviously*)
      - [ ] Fix #88155
      - [ ] Do something with constness bounds in chalk
2021-08-27 05:07:37 +00:00
bors a992a11913 Auto merge of #87937 - LeSeulArtichaut:active-if-let-guards, r=nagisa
Don't mark `if_let_guard` as an incomplete feature

I don't think there is any reason for `if_let_guard` to be an incomplete feature, and I think the reason they were marked in the first place was simply because they weren't implemented at all.

r? `@pnkfelix`
cc tracking issue #51114
2021-08-25 13:42:02 +00:00
Aaron Hill 62aea8c913
Address review comments 2021-08-21 14:11:36 -05:00
Aaron Hill af46699f81
Remove `Session.used_attrs` and move logic to `CheckAttrVisitor`
Instead of updating global state to mark attributes as used,
we now explicitly emit a warning when an attribute is used in
an unsupported position. As a side effect, we are to emit more
detailed warning messages (instead of just a generic "unused" message).

`Session.check_name` is removed, since its only purpose was to mark
the attribute as used. All of the callers are modified to use
`Attribute.has_name`

Additionally, `AttributeType::AssumedUsed` is removed - an 'assumed
used' attribute is implemented by simply not performing any checks
in `CheckAttrVisitor` for a particular attribute.

We no longer emit unused attribute warnings for the `#[rustc_dummy]`
attribute - it's an internal attribute used for tests, so it doesn't
mark sense to treat it as 'unused'.

With this commit, a large source of global untracked state is removed.
2021-08-21 13:27:27 -05:00
bors db002a06ae Auto merge of #87570 - nikic:llvm-13, r=nagisa
Upgrade to LLVM 13

Work in progress update to LLVM 13. Main changes:

 * InlineAsm diagnostics reported using SrcMgr diagnostic kind are now handled. Previously these used a separate diag handler.
 * Codegen tests are updated for additional attributes.
 * Some data layouts have changed.
 * Switch `#[used]` attribute from `llvm.used` to `llvm.compiler.used` to avoid SHF_GNU_RETAIN flag introduced in https://reviews.llvm.org/D97448, which appears to trigger a bug in older versions of gold.
 * Set `LLVM_INCLUDE_TESTS=OFF` to avoid Python 3.6 requirement.

Upstream issues:

 * ~~https://bugs.llvm.org/show_bug.cgi?id=51210 (InlineAsm diagnostic reporting for module asm)~~ Fixed by 1558bb80c0.
 * ~~https://bugs.llvm.org/show_bug.cgi?id=51476 (Miscompile on AArch64 due to incorrect comparison elimination)~~ Fixed by 81b106584f.
 * https://bugs.llvm.org/show_bug.cgi?id=51207 (Can't set custom section flags anymore). Problematic change reverted in our fork, https://reviews.llvm.org/D107216 posted for upstream revert.
 * https://bugs.llvm.org/show_bug.cgi?id=51211 (Regression in codegen for #83623). This is an optimization regression that we may likely have to eat for this release. The fix for #83623 was based on an incorrect premise, and this needs to be properly addressed in the MergeICmps pass.

The [compile-time impact](https://perf.rust-lang.org/compare.html?start=ef9549b6c0efb7525c9b012148689c8d070f9bc0&end=0983094463497eec22d550dad25576a894687002) is mixed, but quite positive as LLVM upgrades go.

The LLVM 13 final release is scheduled for Sep 21st. The current nightly is scheduled for stable release on Oct 21st.

r? `@ghost`
2021-08-21 09:25:28 +00:00
bors 02b27f1e70 Auto merge of #86860 - fee1-dead:stabilize, r=LeSeulArtichaut
Stabilize `arbitrary_enum_discriminant`

Closes #60553.

----

## Stabilization Report

_copied from https://github.com/rust-lang/rust/issues/60553#issuecomment-865922311_

### Summary

Enables a user to specify *explicit* discriminants on arbitrary enums.

Previously, this was hard to achieve:

```rust
#[repr(u8)]
enum Foo {
    A(u8) = 0,
    B(i8) = 1,
    C(bool) = 42,
}
```

Someone would need to add 41 hidden variants in between as a workaround with implicit discriminants.

In conjunction with [RFC 2195](https://github.com/rust-lang/rfcs/blob/master/text/2195-really-tagged-unions.md), this feature would provide more flexibility for FFI and unsafe code involving enums.

### Test cases

Most tests are in [`src/test/ui/enum-discriminant`](https://github.com/rust-lang/rust/tree/master/src/test/ui/enum-discriminant), there are two [historical](https://github.com/rust-lang/rust/blob/master/src/test/ui/parser/tag-variant-disr-non-nullary.rs) [tests](https://github.com/rust-lang/rust/blob/master/src/test/ui/parser/issue-17383.rs) that are now covered by the feature (removed by this pr due to them being obsolete).

### Edge cases

The feature is well defined and does not have many edge cases.
One [edge case](https://github.com/rust-lang/rust/issues/70509) was related to another unstable feature named `repr128` and is resolved.

### Previous PRs

The [implementation PR](https://github.com/rust-lang/rust/pull/60732) added documentation to the Unstable Book, https://github.com/rust-lang/reference/pull/1055 was opened as a continuation of https://github.com/rust-lang/reference/pull/639.

### Resolution of unresolved questions

The questions are resolved in https://github.com/rust-lang/rust/issues/60553#issuecomment-511235271.

----

(someone please add `needs-fcp`)
2021-08-18 01:00:17 +00:00
Nikita Popov 7c015648dd Use llvm.compiler.used insetad of llvm.used
The #[used] attribute explicitly only requires symbols to be
retained in object files, but allows the linker to drop them
if dead. This corresponds to llvm.compiler.used semantics.

The motivation to change this *now* is that https://reviews.llvm.org/D97448
starts emitting #[used] symbols into unique sections with
SHF_GNU_RETAIN flag. This triggers a bug in some version of gold,
resulting in the ARGV_INIT_ARRAY symbol part of the .init_array
section to be incorrectly placed.
2021-08-16 18:28:18 +02:00
Léo Lanteri Thauvin dabdd6de1f Don't mark `if_let_guard` as an incomplete feature 2021-08-16 17:10:31 +02:00
Joshua Nelson 03df65497e feature gate doc(primitive) 2021-08-16 05:41:16 +00:00
bjorn3 a501308ec1 Replace #[plugin_registrar] with exporting __rustc_plugin_registrar 2021-08-10 14:20:48 +02:00
Alex Crichton 1c07096a45 rustc: Fill out remaining parts of C-unwind ABI
This commit intends to fill out some of the remaining pieces of the
C-unwind ABI. This has a number of other changes with it though to move
this design space forward a bit. Notably contained within here is:

* On `panic=unwind`, the `extern "C"` ABI is now considered as "may
  unwind". This fixes a longstanding soundness issue where if you
  `panic!()` in an `extern "C"` function defined in Rust that's actually
  UB because the LLVM representation for the function has the `nounwind`
  attribute, but then you unwind.

* Whether or not a function unwinds now mainly considers the ABI of the
  function instead of first checking the panic strategy. This fixes a
  miscompile of `extern "C-unwind"` with `panic=abort` because that ABI
  can still unwind.

* The aborting stub for non-unwinding ABIs with `panic=unwind` has been
  reimplemented. Previously this was done as a small tweak during MIR
  generation, but this has been moved to a separate and dedicated MIR
  pass. This new pass will, for appropriate functions and function
  calls, insert a `cleanup` landing pad for any function call that may
  unwind within a function that is itself not allowed to unwind. Note
  that this subtly changes some behavior from before where previously on
  an unwind which was caught-to-abort it would run active destructors in
  the function, and now it simply immediately aborts the process.

* The `#[unwind]` attribute has been removed and all users in tests and
  such are now using `C-unwind` and `#![feature(c_unwind)]`.

I think this is largely the last piece of the RFC to implement.
Unfortunately I believe this is still not stabilizable as-is because
activating the feature gate changes the behavior of the existing `extern
"C"` ABI in a way that has no replacement. My thinking for how to enable
this is that we add support for the `C-unwind` ABI on stable Rust first,
and then after it hits stable we change the behavior of the `C` ABI.
That way anyone straddling stable/beta/nightly can switch to `C-unwind`
safely.
2021-08-03 07:06:19 -07:00
Cameron Steffen 14f3418f79
Rollup merge of #86176 - nbdd0121:explicit-generic-args, r=jackh726
Implement a `explicit_generic_args_with_impl_trait` feature gate

Implements #83701

When this gate is enabled, explicit generic arguments can be specified even if `impl Trait` is used in argument position. Generic arguments can only be specified for explicit generic parameters but not for the synthetic type parameters from  `impl Trait`

So code like this will be accepted:
```rust
#![feature(explicit_generic_args_with_impl_trait)]

fn foo<T: ?Sized>(_f: impl AsRef<T>) {}
fn main() {
    foo::<str>("".to_string());
}
```
2021-08-02 09:36:49 -05:00
bors b53a93db2d Auto merge of #87535 - lf-:authors, r=Mark-Simulacrum
rfc3052 followup: Remove authors field from Cargo manifests

Since RFC 3052 soft deprecated the authors field, hiding it from
crates.io, docs.rs, and making Cargo not add it by default, and it is
not generally up to date/useful information for contributors, we may as well
remove it from crates in this repo.
2021-08-02 05:49:17 +00:00
Gary Guo 9b90e7e980 Implement a `explicit_generic_args_with_impl_trait` feature gate
When this gate is enabled, explicit generic arguments can be specified even
if `impl Trait` is used in argument position. Generic arguments can only be
specified for explicit generic parameters but not for the synthetic type
parameters from  `impl Trait`
2021-08-02 04:17:01 +01:00
Charles Lew ac354cf5ce Add feature gate tests. 2021-07-31 00:51:38 +08:00
Alexander Regueiro 2dc86a6450 Added feature gate. 2021-07-31 00:51:38 +08:00
bors 87dc824248 Auto merge of #87237 - jonas-schievink:const-for-and-try, r=oli-obk
Add feature gates for `for` and `?` in consts

These operations seems *relatively* straightforward to support, and only seem to be blocked on `impl const Trait`.

I have included a working test for `const_try`, but `const_for` is currently unusable without reimplementing *every single* defaulted `Iterator` method, so I didn't do that.

(both features still need tracking issues before this is merged)
2021-07-30 12:05:48 +00:00
Jade 3cf820e17d rfc3052: Remove authors field from Cargo manifests
Since RFC 3052 soft deprecated the authors field anyway, hiding it from
crates.io, docs.rs, and making Cargo not add it by default, and it is
not generally up to date/useful information, we should remove it from
crates in this repo.
2021-07-29 14:56:05 -07:00
Jonas Schievink 4ee1840c0c Add tracking issues 2021-07-29 23:21:54 +02:00
Jonas Schievink dbd126901a Add feature gates for `for` and `?` in consts 2021-07-29 23:21:54 +02:00
Santiago Pastorino cf5e48d944
min_type_alias_impl_trait is going to be removed in 1.56 2021-07-28 17:04:45 -03:00
Deadbeef 7a62f29f31
Stabilize `arbitrary_enum_discriminant` 2021-07-28 18:08:34 +08:00
Yuki Okushi 23479f716a
Rollup merge of #87501 - spastorino:remove-min-tait, r=oli-obk
Remove min_type_alias_impl_trait in favor of type_alias_impl_trait

r? ``@oli-obk``
2021-07-28 18:28:19 +09:00
bors aea2e446f0 Auto merge of #86735 - jhpratt:rfc-3107, r=petrochenkov
Implement RFC 3107: `#[derive(Default)]` on enums with a `#[default]` attribute

This PR implements RFC 3107, which permits `#[derive(Default)]` on enums where a unit variant has a `#[default]` attribute. See comments for current status.
2021-07-28 05:59:30 +00:00
Jacob Pratt 7bf791d162
Stabilize `const_fn_union` 2021-07-27 16:03:33 -04:00
Jacob Pratt 36f02f3523
Stabilize `const_fn_transmute` 2021-07-27 16:03:09 -04:00
Jacob Pratt c70147fd66
Permit deriving default on enums with `#[default]` 2021-07-27 15:47:47 -04:00