Commit Graph

227 Commits

Author SHA1 Message Date
Santiago Pastorino
03321b8cca
Add inline const to INCOMPLETE_FEATURES 2020-10-16 18:15:57 -03:00
Santiago Pastorino
3c4ad55082
Add inline_const feature flag 2020-10-16 15:13:28 -03:00
Dylan DPC
85dbb03490
Rollup merge of #76119 - Amjad50:stabilizing-move_ref_pattern, r=nikomatsakis
Stabilize move_ref_pattern

# Implementation
- Initially the rule was added in the run-up to 1.0. The AST-based borrow checker was having difficulty correctly enforcing match expressions that combined ref and move bindings, and so it was decided to simplify forbid the combination out right.
- The move to MIR-based borrow checking made it possible to enforce the rules in a finer-grained level, but we kept the rule in place in an effort to be conservative in our changes.
- In #68376, @Centril lifted the restriction but required a feature-gate.
- This PR removes the feature-gate.

Tracking issue: #68354.

# Description
This PR is to stabilize the feature `move_ref_pattern`, which allows patterns
containing both `by-ref` and `by-move` bindings at the same time.

For example: `Foo(ref x, y)`, where `x` is `by-ref`,
and `y` is `by-move`.

The rules of moving a variable also apply here when moving *part* of a variable,
such as it can't be referenced or moved before.

If this pattern is used, it would result in *partial move*, which means that
part of the variable is moved. The variable that was partially moved from
cannot be used as a whole in this case, only the parts that are still
not moved can be used.

## Documentation
- The reference (rust-lang/reference#881)
- Rust by example (rust-lang/rust-by-example#1377)

## Tests
There are many tests, but I think one of the comperhensive ones:
- [borrowck-move-ref-pattern-pass.rs](85fbf49ce0/src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern-pass.rs)
- [borrowck-move-ref-pattern.rs](85fbf49ce0/src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.rs)

# Examples

```rust
#[derive(PartialEq, Eq)]
struct Finished {}

#[derive(PartialEq, Eq)]
struct Processing {
    status: ProcessStatus,
}

#[derive(PartialEq, Eq)]
enum ProcessStatus {
    One,
    Two,
    Three,
}

#[derive(PartialEq, Eq)]
enum Status {
    Finished(Finished),
    Processing(Processing),
}

fn check_result(_url: &str) -> Status {
    // fetch status from some server
    Status::Processing(Processing {
        status: ProcessStatus::One,
    })
}

fn wait_for_result(url: &str) -> Finished {
    let mut previous_status = None;
    loop {
        match check_result(url) {
            Status::Finished(f) => return f,
            Status::Processing(p) => {
                match (&mut previous_status, p.status) {
                    (None, status) => previous_status = Some(status), // first status
                    (Some(previous), status) if *previous == status => {} // no change, ignore
                    (Some(previous), status) => { // Now it can be used
                        // new status
                        *previous = status;
                    }
                }
            }
        }
    }
}
```

Before, we would have used:
```rust
                match (&previous_status, p.status) {
                    (Some(previous), status) if *previous == status => {} // no change, ignore
                    (_, status) => {
                        // new status
                        previous_status = Some(status);
                    }
                }
```

Demonstrating *partial move*
```rust
fn main() {
    #[derive(Debug)]
    struct Person {
        name: String,
        age: u8,
    }

    let person = Person {
        name: String::from("Alice"),
        age: 20,
    };

    // `name` is moved out of person, but `age` is referenced
    let Person { name, ref age } = person;

    println!("The person's age is {}", age);

    println!("The person's name is {}", name);

    // Error! borrow of partially moved value: `person` partial move occurs
    //println!("The person struct is {:?}", person);

    // `person` cannot be used but `person.age` can be used as it is not moved
    println!("The person's age from person struct is {}", person.age);
}
```
2020-10-16 02:10:07 +02:00
xd009642
a6e2b636e6 Implement the instruction_set attribute 2020-10-08 23:32:20 +01:00
Dylan MacKenzie
c4ef5fdf8f Remove fn from feature name 2020-10-05 21:44:00 -07:00
Dylan MacKenzie
e1d76818b2 Add #![feature(const_fn_impl)] 2020-10-05 19:56:50 -07:00
Dylan DPC
e032bb7c65
Rollup merge of #77439 - varkor:min_const_generics-tests, r=lcnr,estebank
Fix missing diagnostic span for `impl Trait` with const generics, and add various tests for `min_const_generics` and `const_generics`

Closes https://github.com/rust-lang/rust/issues/61410.

Adds `min_const_generics` tests for:
- https://github.com/rust-lang/rust/issues/73727
- https://github.com/rust-lang/rust/issues/72293
- https://github.com/rust-lang/rust/issues/67375
- https://github.com/rust-lang/rust/issues/75153
- https://github.com/rust-lang/rust/issues/71922
- https://github.com/rust-lang/rust/issues/69913
- https://github.com/rust-lang/rust/issues/67945
- https://github.com/rust-lang/rust/issues/69239

Adds `const_generics` tests for:
- https://github.com/rust-lang/rust/issues/67375
- https://github.com/rust-lang/rust/issues/75153
- https://github.com/rust-lang/rust/issues/71922
- https://github.com/rust-lang/rust/issues/69913
- https://github.com/rust-lang/rust/issues/67945
- https://github.com/rust-lang/rust/issues/69239

(I only added separate `min_const_generics` and `const_generics` tests if they were handled differently by the two features.)

We need to figure out how to deduplicate when `const_generics` is stabilised, but we can discuss that later. For now, we should be checking neither feature breaks, so require regression tests for both. I've given them identical names when I've added both, which should make it easier to spot them later.

r? @lcnr
2020-10-05 02:29:36 +02:00
varkor
488b759d5c Replace "non trivial" with "non-trivial" 2020-10-03 14:28:54 +01:00
Harald Hoyer
cadd12b5f0 Implement Make handle_alloc_error default to panic (for no_std + liballoc)
Related: https://github.com/rust-lang/rust/issues/66741

Guarded with `#![feature(default_alloc_error_handler)]` a default
`alloc_error_handler` is called, if a custom allocator is used and no
other custom `#[alloc_error_handler]` is defined.

The panic message does not contain the size anymore, because it would
pull in the fmt machinery, which would blow up the code size
significantly.
2020-10-02 09:00:29 +02:00
Yuki Okushi
1fa5f8f05b
Rollup merge of #76851 - fusion-engineering-forks:fixme-nonzero, r=petrochenkov
Fix 'FIXME' about using NonZeroU32 instead of u32.

It was blocked by #58732 (const fn NonZeroU32::new), which is fixed now.
2020-10-02 08:25:10 +09:00
Mara Bos
2140d80a9d
Add note about possible future improvement
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2020-10-01 17:32:23 +02:00
Hugues de Valon
1aaafac6ff Add support for cmse_nonsecure_entry attribute
This patch adds support for the LLVM cmse_nonsecure_entry attribute.
This is a target-dependent attribute that only has sense for the
thumbv8m Rust targets.
You can find more information about this attribute here:
https://developer.arm.com/documentation/ecm0359818/latest/

Signed-off-by: Hugues de Valon <hugues.devalon@arm.com>
2020-09-30 15:48:59 +01:00
Dylan MacKenzie
3cbd17fcc6 Remove rustc_allow_const_fn_ptr
This was a hack to work around the lack of an escape hatch for the "min
`const fn`" checks in const-stable functions. Now that we have co-opted
`allow_internal_unstable` for this purpose, we no longer need the
bespoke attribute.
2020-09-27 10:46:41 -07:00
Dylan MacKenzie
1ff143191c Add a feature gate for basic function pointer use in const fn 2020-09-27 10:46:41 -07:00
Dylan MacKenzie
659028f48b Use proper issue for const_fn_floating_point_arithmetic 2020-09-25 10:39:11 -07:00
Dylan MacKenzie
0d2521aaf7 Add const_fn_floating_point_arithmetic 2020-09-25 10:37:52 -07:00
Mara Bos
db74e1f1e3 Add cfg(target_has_atomic_equal_alignment).
This is needed for Atomic::from_mut.
2020-09-21 20:42:25 +02:00
Mateusz Mikuła
5de2c95e6e Remove MMX from Rust 2020-09-20 15:13:11 +02:00
Mara Bos
84ef603c84 Fix 'FIXME' about using NonZeroU32 instead of u32.
It was blocked by #58732 (const fn NonZeroU32::new), which is fixed now.
2020-09-17 21:54:13 +02:00
Amjad Alsharafi
da700cba08 Stabilize move_ref_pattern 2020-09-15 14:23:05 +08:00
Guillaume Gomez
d069c7e928 Stabilize doc_alias feature 2020-09-14 11:03:47 +02:00
Bastian Kauschke
300b0acb85 fix tidy, small cleanup 2020-09-10 09:48:02 +02:00
Bastian Kauschke
8667f93040 implement const_evaluatable_checked feature MVP 2020-09-10 08:52:02 +02:00
Amjad Alsharafi
8f2d9069a8 Implementation of incompatible features error
If two features are defined as incompatible, using them together would
result in an error
2020-09-04 22:17:28 +08:00
marmeladema
99c96c5bfe driver: replace lazy_static by SyncLazy from std 2020-09-01 22:06:47 +01:00
marmeladema
73a7204983 feature: replace lazy_static by SyncLazy from std 2020-09-01 22:06:47 +01:00
mark
9e5f7d5631 mv compiler to compiler/ 2020-08-30 18:45:07 +03:00