Commit graph

129536 commits

Author SHA1 Message Date
Dylan DPC 0e4d19603b
Rollup merge of #77493 - hosseind88:ICEs_should_always_print_the_top_of_the_query_stack, r=oli-obk
ICEs should always print the top of the query stack

see #76920
2020-10-16 02:10:09 +02: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
Dylan DPC 5acb7f198f
Rollup merge of #76084 - Lucretiel:split-buffered, r=dtolnay
Refactor io/buffered.rs into submodules

This pull request splits `BufWriter`, `BufReader`, `LineWriter`, and `LineWriterShim` (along with their associated tests) into separate submodules. It contains no functional changes. This change is being made in anticipation of adding another type of buffered writer which can be switched between line- and block-buffering mode.

Part of a series of pull requests resolving #60673.
2020-10-16 02:10:04 +02:00
Dylan DPC 1643fd86a7
Rollup merge of #75675 - davidtwco:symbol-mangling-impl-params, r=eddyb
mangling: mangle impl params w/ v0 scheme

This PR modifies v0 symbol mangling to include all generic parameters from impl blocks (not just those used in the self type) - an alternative fix to #75326.

```
original:
   _RNCNvXCs4fqI2P2rA04_19impl_param_manglingINtB4_3FooppENtNtNtNtCsfnEnqCNU58Z_4core4iter6traits8iterator8Iterator4next0B4_
//        |------------ B4_ ----------------|
// _R (N C (N v (X (C ((s 4fqI2p2rA04_) 19impl_param_mangling)) (I (N t B4_ 3Foo) pp E) (N t (N t (N t (N t (C ((s fnEnqCNU58Z_) 4core)) 4iter) 6traits) 8iterator) 8Iterator)) 4next) 0) B4_

modified:
   _RNvXINICs4fqI2P2rA04_11issue_753260pppEINtB5_3FooppENtNtNtNtCsfnEnqCNU58Z_4core4iter6traits8iterator8Iterator4nextB5_
// _R (N v (X (I (N I (C ((s 4fqI2P2rA04_) 11issue_75326)) 0) ppp E) (I (N t B5_ 3Foo) pp E) (N t (N t (N t (N t (C ((s fnEnqCNU58Z_) 4core)) 4iter) 6traits) 8iterator) 8Iterator)) 4next) B5_
//            |     ^                                              |
//            |     |                                              |
//            |     new impl namespace                             |
```

~~Submitted as a draft as after some discussion w/ @eddyb, I'm going to do some investigation into (yet more alternative) changes to polymorphization that might remove the necessity for this.~~

r? @eddyb
2020-10-16 02:10:02 +02:00
Dylan DPC 977df43c4a
Rollup merge of #75265 - WaffleLapkin:str_split_as_str, r=dtolnay
Add `str::{Split,RSplit,SplitN,RSplitN,SplitTerminator,RSplitTerminator,SplitInclusive}::as_str` methods

tl;dr this allows viewing unyelded part of str-split-iterators, like so:
```rust
let mut split = "Mary had a little lamb".split(' ');
assert_eq!(split.as_str(), "Mary had a little lamb");
split.next();
assert_eq!(split.as_str(), "had a little lamb");
split.by_ref().for_each(drop);
assert_eq!(split.as_str(), "");
```

--------------

This PR adds semi-identical `as_str` methods to most str-split-iterators with signatures like `&'_ Split<'a, P: Pattern<'a>> -> &'a str` (Note: output `&str` lifetime is bound to the `'a`, not the `'_`). The methods are similar to [`Chars::as_str`]

`SplitInclusive::as_str` is under `"str_split_inclusive_as_str"` feature gate, all other methods are under `"str_split_as_str"` feature gate.

Before this PR you had to sum `len`s of all yielded parts or collect into `String` to emulate `as_str`.

[`Chars::as_str`]: https://doc.rust-lang.org/core/str/struct.Chars.html#method.as_str
2020-10-16 02:10:00 +02:00
Dylan DPC 075f2bfc39
Rollup merge of #75023 - euclio:argument-span, r=estebank
ensure arguments are included in count mismatch span

The current diagnostic isn't very helpful if the function header spans multiple lines. Lines comprising the function signature may be elided to keep the diagnostic short, but these lines are essential to fixing the error. This is made worse when the function has a body, because the last two lines of the span are then dedicated to showing the end of the body, which is irrelevant.

This PR changes the span to be a multispan made up of the header and the the arguments, ensuring they won't be elided. It also discards the function body from the span.

[Old](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f92d9f81a8c9416f0f04e4e09923b6d4):

```
error[E0061]: this function takes 6 arguments but 1 argument was supplied
  --> src/main.rs:18:5
   |
1  | / fn bar(
2  | |     a: i32,
3  | |     b: i32,
4  | |     c: i32,
...  |
14 | |     println!("{}", f);
15 | | }
   | |_- defined here
...
18 |       bar(1);
   |       ^^^ - supplied 1 argument
   |       |
   |       expected 6 arguments
```

New:

```
error[E0061]: this function takes 6 arguments but 1 argument was supplied
  --> $DIR/not-enough-arguments.rs:28:3
   |
LL |   bar(1);
   |   ^^^ - supplied 1 argument
   |   |
   |   expected 6 arguments
   |
note: function defined here
  --> $DIR/not-enough-arguments.rs:9:1
   |
LL | / fn bar(
LL | |     a: i32,
   | |     ^^^^^^^
LL | |     b: i32,
   | |     ^^^^^^^
LL | |     c: i32,
   | |     ^^^^^^^
LL | |     d: i32,
   | |     ^^^^^^^
LL | |     e: i32,
   | |     ^^^^^^^
LL | |     f: i32,
   | |     ^^^^^^^
LL | | ) {
   | |_^
```
2020-10-16 02:09:58 +02:00
Waffle 7bd6403b38 fill in the tracking issue 2020-10-16 01:11:39 +03:00
bors dd7fc54ebd Auto merge of #77981 - GuillaumeGomez:rollup-64ydc5g, r=GuillaumeGomez
Rollup of 3 pull requests

Successful merges:

 - #77963 (Fix link to foreign calling conventions)
 - #77978 (Fix typo in documentation)
 - #77979 (Hide help button on mobile)

Failed merges:

r? `@ghost`
2020-10-15 19:03:32 +00:00
bors b5c9e2448c Auto merge of #77943 - est31:target_refactor, r=petrochenkov
No more target.target

Two main changes of this PR:

* Turn `target_pointer_width` into an integer and rename to `pointer_width`.
  The compiler only allowed three valid values for the width anyways.
  An integer is more natural for this value, and saves a few allocations
  and copies.
* Remove the `rustc_session::config::Config` wrapper and replace it with
  its inner member `Target`. Aka. no more `target.target`. This makes life so
  much easier, but it also causes a ton of downstream breakage.

Some changes of this PR were done using tooling. These tooling-made changes
were isolated to their own commits to make review easier.
It's best to review the PR commit-by-commit.

Miri PR: https://github.com/rust-lang/miri/pull/1583

I request p=10 bors priority because of the breakage.
2020-10-15 16:50:00 +00:00
Guillaume Gomez 16b1a6fa67
Rollup merge of #77979 - GuillaumeGomez:hide-help-button, r=jyn514
Hide help button on mobile

Addresses #77899.

This PR is just a quick fix for now: we're still debating about whether or not we want to display this help popup and if so, how. I'll open an issue once this PR is merged to discuss about it.

Before:

![Screenshot from 2020-10-15 17-56-39](https://user-images.githubusercontent.com/3050060/96155127-df499680-0f0f-11eb-8a13-77c537141f21.png)

After:

![Screenshot from 2020-10-15 17-55-06](https://user-images.githubusercontent.com/3050060/96154957-ac070780-0f0f-11eb-9d90-7d8f79a6bf37.png)

r? @jyn514
2020-10-15 18:00:32 +02:00
Guillaume Gomez 313de68e22
Rollup merge of #77978 - strct:patch-2, r=jonas-schievink
Fix typo in documentation
2020-10-15 18:00:30 +02:00
Guillaume Gomez e117c06155
Rollup merge of #77963 - kraai:fix-foreign-calling-conventions-link, r=jonas-schievink
Fix link to foreign calling conventions
2020-10-15 18:00:29 +02:00
Guillaume Gomez fce04fedd6 Hide help button on mobile devices 2020-10-15 17:32:42 +02:00
strct 8d8554d234
Fix typo in documentation 2020-10-15 16:57:19 +02:00
Andy Russell 14b2d16c5c
ensure arguments are included in count mismatch span 2020-10-15 10:22:39 -04:00
Andy Russell 95daa068f1
fix off-by-one in parameter spans 2020-10-15 09:49:36 -04:00
David Wood fbdfe2c63b
mangling: encode all impl parameters
This commit modifies v0 symbol mangling to include all generic
parameters from impl blocks (not just those used in the self type).

Signed-off-by: David Wood <david@davidtw.co>
2020-10-15 12:51:53 +01:00
David Wood 9752787dca
mangling: non-monomorphic #[rustc_symbol_name]
This commit adjust `#[rustc_symbol_name]` so that it can be applied to
non-monomorphic functions without producing an ICE.

Signed-off-by: David Wood <david@davidtw.co>
2020-10-15 12:51:49 +01:00
est31 d683e3ac23 Remove rustc_session::config::Config
The wrapper type led to tons of target.target
across the compiler. Its ptr_width field isn't
required any more, as target_pointer_width
is already present in parsed form.
2020-10-15 12:02:24 +02:00
est31 4fa5578774 Replace target.target with target and target.ptr_width with target.pointer_width
Preparation for a subsequent change that replaces
rustc_target::config::Config with its wrapped Target.

On its own, this commit breaks the build. I don't like making
build-breaking commits, but in this instance I believe that it
makes review easier, as the "real" changes of this PR can be
seen much more easily.

Result of running:

find compiler/ -type f -exec sed -i -e 's/target\.target\([)\.,; ]\)/target\1/g' {} \;
find compiler/ -type f -exec sed -i -e 's/target\.target$/target/g' {} \;
find compiler/ -type f -exec sed -i -e 's/target.ptr_width/target.pointer_width/g' {} \;
./x.py fmt
2020-10-15 12:02:24 +02:00
est31 0d1aa1e034 Rename target_pointer_width to pointer_width and turn it into an u32
Rename target_pointer_width to pointer_width because it is already
member of the Target struct.

The compiler supports only three valid values for target_pointer_width:
16, 32, 64. Thus it can safely be turned into an int.
This means less allocations and clones as well as easier handling of the type.
2020-10-15 12:02:23 +02:00
est31 64ba25d0f2 Use integer literals for builtin target_pointer_width fields
Also change target_pointer_width to pointer_width.

Preparation for a subsequent type change of
target_pointer_width to an integer together with a rename
to pointer_width.

On its own, this commit breaks the build. I don't like making
build-breaking commits, but in this instance I believe that it
makes review easier, as the "real" changes of this PR can be
seen much more easily.

Result of running:

find compiler/rustc_target/src/spec/ -type f -exec sed -i -e 's/target_pointer_width: "\(.*\)"\..*,/pointer_width: \1,/g' {} \;
2020-10-15 12:01:53 +02:00
bors 7f58716810 Auto merge of #77952 - ehuss:update-cargo, r=ehuss
Update cargo

11 commits in 9d1a4863abd9237dbf9d1b74c78632b6a205f6bb..12db56cdedbc2c26a9aa18f994c0188cdcc67df5
2020-10-05 18:29:52 +0000 to 2020-10-14 23:07:45 +0000
- Reinstate CARGO_PRIMARY_PACKAGE (take 2) (rust-lang/cargo#8758)
- Add actionable help message for --features (rust-lang/cargo#8773)
- Fix panic in `cargo doc` with -Zfeatures=itarget (rust-lang/cargo#8777)
- Update git2. (rust-lang/cargo#8778)
- Document RUSTFMT environment variable (rust-lang/cargo#8767)
- Update crossbeam-utils requirement from 0.7 to 0.8 (rust-lang/cargo#8769)
- Update toml dependency (rust-lang/cargo#8772)
- Mark proc-macro crates (rust-lang/cargo#8765)
- cargo-tree: mention special target `all` in CLI help text (rust-lang/cargo#8766)
- Bump to 0.50.0, update changelog (rust-lang/cargo#8764)
- Update deprecated GitHub add-path in workflows. (rust-lang/cargo#8760)
2020-10-15 08:50:36 +00:00
Matthew Kraai f2a237a935 Fix link to foreign calling conventions 2020-10-15 00:57:22 -07:00
bors 596b0d5027 Auto merge of #77948 - cuviper:rust-llvm11, r=nikic
Rebase LLVM onto 11.0.0 final
2020-10-15 06:25:32 +00:00
bors 93deabce03 Auto merge of #77873 - sexxi-goose:use_tuple_inference_for_closures, r=nikomatsakis
Replace tuple of infer vars for upvar_tys with single infer var

This commit allows us to decide the number of captures required after
completing capture ananysis, which is required as part of implementing
RFC-2229.

closes https://github.com/rust-lang/project-rfc-2229/issues/4
r? `@nikomatsakis`
2020-10-15 04:17:10 +00:00
bors 19e1aac6ea Auto merge of #77756 - alarsyo:setup-llvm-detect, r=jyn514
Detect configuration for LLVM during setup

This is a first draft to address #77579, setting `download-ci-llvm` to true on Linux, but I could also implement the `if-available` setting mentioned in the issue.

On other platforms I was thinking about using [the which crate](https://crates.io/crates/which), if adding a dependency on it is considered okay of course, to detect the presence of `llvm-config` in the path, and use it if found. Still a work in progress of course.
2020-10-15 02:10:11 +00:00
Eric Huss 71bf7cfce1 Update cargo 2020-10-14 18:17:47 -07:00
bors f42692b1cc Auto merge of #77954 - JohnTitor:rollup-bpoy497, r=JohnTitor
Rollup of 9 pull requests

Successful merges:

 - #77570 (Allow ascii whitespace char for doc aliases )
 - #77739 (Remove unused code)
 - #77753 (Check html comments)
 - #77879 (Provide better documentation and help messages for x.py setup)
 - #77902 (Include aarch64-pc-windows-msvc in the dist manifests)
 - #77934 (Document -Z codegen-backend in the unstable book)
 - #77936 (Remove needless alloc_slice)
 - #77946 (Validate references to source scopes)
 - #77951 (Update books)

Failed merges:

r? `@ghost`
2020-10-14 23:11:04 +00:00
Yuki Okushi 00100a4576
Rollup merge of #77951 - ehuss:update-books, r=ehuss
Update books

## reference

5 commits in 56a13c082ee90736c08d6abdcd90462517b703d3..1b78182e71709169dc0f1c3acdc4541b6860e1c4
2020-09-14 23:20:16 -0700 to 2020-10-11 13:53:47 -0700
- Specify that SSE4.1 includes SSSE3 instead of SSE3 (rust-lang-nursery/reference#892)
- Fix mutable expressions that can be dereferenced (rust-lang-nursery/reference#890)
- Fix grammar in memory model (rust-lang-nursery/reference#889)
- Add style checks. (rust-lang-nursery/reference#886)
- Add description for LUB Coercion (rust-lang-nursery/reference#808)

## book

1 commits in cb28dee95e5e50b793e6ba9291c5d1568d3ad72e..451a1e30f2dd137aa04e142414eafb8d05f87f84
2020-09-09 10:06:00 -0500 to 2020-10-05 09:11:18 -0500
- clarify description of when ? can be used (rust-lang/book#2471)

## rust-by-example

1 commits in 7d3ff1c12db08a847a57a054be4a7951ce532d2d..152475937a8d8a1f508d8eeb57db79139bc803d9
2020-09-28 15:54:25 -0300 to 2020-10-09 09:29:50 -0300
- Add 1.45.0 cast documentation (rust-lang/rust-by-example#1384)

## embedded-book

2 commits in dd310616308e01f6cf227f46347b744aa56b77d9..79ab7776929c66db83203397958fa7037d5d9a30
2020-09-26 08:54:08 +0000 to 2020-10-12 08:00:05 +0000
- llvm-objdump: Use two hyphens in flags to objdump  (rust-embedded/book#270)
- Start/hardware: clarify which file needs tweaking  (rust-embedded/book#266)
2020-10-15 07:32:40 +09:00
Yuki Okushi ccc86bbb40
Rollup merge of #77946 - tmiasko:validate-source-scope, r=jonas-schievink
Validate references to source scopes
2020-10-15 07:32:39 +09:00
Yuki Okushi df08fe7214
Rollup merge of #77936 - est31:remove_needless_alloc_slice, r=jonas-schievink
Remove needless alloc_slice

Don't invoke alloc_slice.

Arenas are temporary,
empty slices are eternal!
2020-10-15 07:32:37 +09:00
Yuki Okushi 0cf86c2e8a
Rollup merge of #77934 - XAMPPRocky:codegen-backend-docs, r=jonas-schievink
Document -Z codegen-backend in the unstable book

### [Rendered](https://github.com/XAMPPRocky/rust/blob/codegen-backend-docs/src/doc/unstable-book/src/compiler-flags/codegen-backend.md)

Companion PR to #77933 tracking issue.

cc @bjorn3
2020-10-15 07:32:36 +09:00
Yuki Okushi b3f9512490
Rollup merge of #77902 - arlosi:arm64manifest, r=ehuss
Include aarch64-pc-windows-msvc in the dist manifests

r? @ehuss

/cc @pietroalbini @Mark-Simulacrum

#72881
2020-10-15 07:32:34 +09:00
Yuki Okushi c268cc0b4d
Rollup merge of #77879 - ijackson:x-py, r=jyn514
Provide better documentation and help messages for x.py setup

Closes: #77861

I have split this up into tiny comments because I find it clearer this way.  Feel free to squash it.
2020-10-15 07:32:32 +09:00
Yuki Okushi 5f5ef052b1
Rollup merge of #77753 - GuillaumeGomez:check-html-comments, r=jyn514
Check html comments

Part of #67799.

cc @ollie27
r? @jyn514
2020-10-15 07:32:31 +09:00
Yuki Okushi 022d20759b
Rollup merge of #77739 - est31:remove_unused_code, r=petrochenkov,varkor
Remove unused code

Rustc has a builtin lint for detecting unused code inside a crate, but when an item is marked `pub`, the code, even if unused inside the entire workspace, is never marked as such. Therefore, I've built [warnalyzer](https://github.com/est31/warnalyzer) to detect unused items in a cross-crate setting.

Closes https://github.com/est31/warnalyzer/issues/2
2020-10-15 07:32:29 +09:00
Yuki Okushi 35210a66ed
Rollup merge of #77570 - GuillaumeGomez:whitespace-doc-alias, r=jyn514,ollie27
Allow ascii whitespace char for doc aliases

Fixes issue from https://github.com/rust-lang/rust/issues/76705#issuecomment-703123847

cc @lopopolo @ollie27

r? @jyn514
2020-10-15 07:32:27 +09:00
Eric Huss 2350e3f375 Update books 2020-10-14 14:55:41 -07:00
Josh Stone 5c4565771e Rebase LLVM onto 11.0.0 final 2020-10-14 12:13:20 -07:00
bors e160e5cb80 Auto merge of #77944 - shepmaster:aarch64-apple-darwin-new-xcode, r=pietroalbini
Update Xcode beta version to allow aarch64-apple-darwin to compile again

r? `@pietroalbini`
2020-10-14 17:53:52 +00:00
Jake Goulding d959011de0 Update Xcode beta version to allow aarch64-apple-darwin to compile again 2020-10-14 13:51:28 -04:00
hosseind88 46cc889abf fix stderr file of clippy/custom_ice_message test 2020-10-14 18:19:26 +03:30
XAMPPRocky 6ae5f36d0d
Update codegen-backend.md 2020-10-14 14:49:15 +02:00
XAMPPRocky 9ff647a0d1
Update codegen-backend.md 2020-10-14 14:46:30 +02:00
XAMPPRocky a0ea35116b
Update src/doc/unstable-book/src/compiler-flags/codegen-backend.md 2020-10-14 14:44:44 +02:00
Erin Power c50a04bba3 Document -Z codegen-backend in the unstable book 2020-10-14 14:34:47 +02:00
est31 301907497f Remove needless alloc_slice
Don't invoke alloc_slice.

Arenas are temporary,
empty slices are eternal!
2020-10-14 14:23:32 +02:00
Ian Jackson 636728e394 x.py setup: Avoid infinite loop if stdin is /dev/null
EOF is not an error; it just causes read_line to produce "".

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-10-14 11:40:53 +01:00
Ian Jackson e9058571ce x.py setup: Fix handling of wrong interactive input
We need a fresh input buffer each time, or we reuse the previous
data (since `read_line` appends).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2020-10-14 11:40:53 +01:00