Auto merge of #37657 - steveklabnik:rollup, r=steveklabnik
Rollup of 8 pull requests - Successful merges: #35102, #37425, #37483, #37588, #37601, #37610, #37650, #37652 - Failed merges:
This commit is contained in:
commit
02aa42860d
9 changed files with 619 additions and 145 deletions
|
@ -4,112 +4,25 @@ This first chapter of the book will get us going with Rust and its tooling.
|
||||||
First, we’ll install Rust. Then, the classic ‘Hello World’ program. Finally,
|
First, we’ll install Rust. Then, the classic ‘Hello World’ program. Finally,
|
||||||
we’ll talk about Cargo, Rust’s build system and package manager.
|
we’ll talk about Cargo, Rust’s build system and package manager.
|
||||||
|
|
||||||
# Installing Rust
|
|
||||||
|
|
||||||
The first step to using Rust is to install it. Generally speaking, you’ll need
|
|
||||||
an Internet connection to run the commands in this section, as we’ll be
|
|
||||||
downloading Rust from the Internet.
|
|
||||||
|
|
||||||
We’ll be showing off a number of commands using a terminal, and those lines all
|
We’ll be showing off a number of commands using a terminal, and those lines all
|
||||||
start with `$`. You don't need to type in the `$`s, they are there to indicate
|
start with `$`. You don't need to type in the `$`s, they are there to indicate
|
||||||
the start of each command. We’ll see many tutorials and examples around the web
|
the start of each command. We’ll see many tutorials and examples around the web
|
||||||
that follow this convention: `$` for commands run as our regular user, and `#`
|
that follow this convention: `$` for commands run as our regular user, and `#`
|
||||||
for commands we should be running as an administrator.
|
for commands we should be running as an administrator.
|
||||||
|
|
||||||
## Platform support
|
# Installing Rust
|
||||||
|
|
||||||
The Rust compiler runs on, and compiles to, a great number of platforms, though
|
The first step to using Rust is to install it. Generally speaking, you’ll need
|
||||||
not all platforms are equally supported. Rust's support levels are organized
|
an Internet connection to run the commands in this section, as we’ll be
|
||||||
into three tiers, each with a different set of guarantees.
|
downloading Rust from the Internet.
|
||||||
|
|
||||||
Platforms are identified by their "target triple" which is the string to inform
|
The Rust compiler runs on, and compiles to, a great number of platforms, but is
|
||||||
the compiler what kind of output should be produced. The columns below indicate
|
best supported on Linux, Mac, and Windows, on the x86 and x86-64 CPU
|
||||||
whether the corresponding component works on the specified platform.
|
architecture. There are official builds of the Rust compiler and standard
|
||||||
|
library for these platforms and more. [For full details on Rust platform support
|
||||||
|
see the website][platform-support].
|
||||||
|
|
||||||
### Tier 1
|
[platform-support]: https://forge.rust-lang.org/platform-support.html
|
||||||
|
|
||||||
Tier 1 platforms can be thought of as "guaranteed to build and work".
|
|
||||||
Specifically they will each satisfy the following requirements:
|
|
||||||
|
|
||||||
* Automated testing is set up to run tests for the platform.
|
|
||||||
* Landing changes to the `rust-lang/rust` repository's master branch is gated on
|
|
||||||
tests passing.
|
|
||||||
* Official release artifacts are provided for the platform.
|
|
||||||
* Documentation for how to use and how to build the platform is available.
|
|
||||||
|
|
||||||
| Target | std |rustc|cargo| notes |
|
|
||||||
|-------------------------------|-----|-----|-----|----------------------------|
|
|
||||||
| `i686-apple-darwin` | ✓ | ✓ | ✓ | 32-bit OSX (10.7+, Lion+) |
|
|
||||||
| `i686-pc-windows-gnu` | ✓ | ✓ | ✓ | 32-bit MinGW (Windows 7+) |
|
|
||||||
| `i686-pc-windows-msvc` | ✓ | ✓ | ✓ | 32-bit MSVC (Windows 7+) |
|
|
||||||
| `i686-unknown-linux-gnu` | ✓ | ✓ | ✓ | 32-bit Linux (2.6.18+) |
|
|
||||||
| `x86_64-apple-darwin` | ✓ | ✓ | ✓ | 64-bit OSX (10.7+, Lion+) |
|
|
||||||
| `x86_64-pc-windows-gnu` | ✓ | ✓ | ✓ | 64-bit MinGW (Windows 7+) |
|
|
||||||
| `x86_64-pc-windows-msvc` | ✓ | ✓ | ✓ | 64-bit MSVC (Windows 7+) |
|
|
||||||
| `x86_64-unknown-linux-gnu` | ✓ | ✓ | ✓ | 64-bit Linux (2.6.18+) |
|
|
||||||
|
|
||||||
### Tier 2
|
|
||||||
|
|
||||||
Tier 2 platforms can be thought of as "guaranteed to build". Automated tests
|
|
||||||
are not run so it's not guaranteed to produce a working build, but platforms
|
|
||||||
often work to quite a good degree and patches are always welcome! Specifically,
|
|
||||||
these platforms are required to have each of the following:
|
|
||||||
|
|
||||||
* Automated building is set up, but may not be running tests.
|
|
||||||
* Landing changes to the `rust-lang/rust` repository's master branch is gated on
|
|
||||||
platforms **building**. Note that this means for some platforms only the
|
|
||||||
standard library is compiled, but for others the full bootstrap is run.
|
|
||||||
* Official release artifacts are provided for the platform.
|
|
||||||
|
|
||||||
| Target | std |rustc|cargo| notes |
|
|
||||||
|-------------------------------|-----|-----|-----|----------------------------|
|
|
||||||
| `aarch64-apple-ios` | ✓ | | | ARM64 iOS |
|
|
||||||
| `aarch64-unknown-linux-gnu` | ✓ | ✓ | ✓ | ARM64 Linux (2.6.18+) |
|
|
||||||
| `arm-linux-androideabi` | ✓ | | | ARM Android |
|
|
||||||
| `arm-unknown-linux-gnueabi` | ✓ | ✓ | ✓ | ARM Linux (2.6.18+) |
|
|
||||||
| `arm-unknown-linux-gnueabihf` | ✓ | ✓ | ✓ | ARM Linux (2.6.18+) |
|
|
||||||
| `armv7-apple-ios` | ✓ | | | ARM iOS |
|
|
||||||
|`armv7-unknown-linux-gnueabihf`| ✓ | ✓ | ✓ | ARMv7 Linux (2.6.18+) |
|
|
||||||
| `armv7s-apple-ios` | ✓ | | | ARM iOS |
|
|
||||||
| `i386-apple-ios` | ✓ | | | 32-bit x86 iOS |
|
|
||||||
| `i586-pc-windows-msvc` | ✓ | | | 32-bit Windows w/o SSE |
|
|
||||||
| `mips-unknown-linux-gnu` | ✓ | | | MIPS Linux (2.6.18+) |
|
|
||||||
| `mips-unknown-linux-musl` | ✓ | | | MIPS Linux with MUSL |
|
|
||||||
| `mipsel-unknown-linux-gnu` | ✓ | | | MIPS (LE) Linux (2.6.18+) |
|
|
||||||
| `mipsel-unknown-linux-musl` | ✓ | | | MIPS (LE) Linux with MUSL |
|
|
||||||
| `powerpc-unknown-linux-gnu` | ✓ | | | PowerPC Linux (2.6.18+) |
|
|
||||||
| `powerpc64-unknown-linux-gnu` | ✓ | | | PPC64 Linux (2.6.18+) |
|
|
||||||
|`powerpc64le-unknown-linux-gnu`| ✓ | | | PPC64LE Linux (2.6.18+) |
|
|
||||||
| `x86_64-apple-ios` | ✓ | | | 64-bit x86 iOS |
|
|
||||||
| `x86_64-rumprun-netbsd` | ✓ | | | 64-bit NetBSD Rump Kernel |
|
|
||||||
| `x86_64-unknown-freebsd` | ✓ | ✓ | ✓ | 64-bit FreeBSD |
|
|
||||||
| `x86_64-unknown-linux-musl` | ✓ | | | 64-bit Linux with MUSL |
|
|
||||||
| `x86_64-unknown-netbsd` | ✓ | ✓ | ✓ | 64-bit NetBSD |
|
|
||||||
|
|
||||||
### Tier 3
|
|
||||||
|
|
||||||
Tier 3 platforms are those which Rust has support for, but landing changes is
|
|
||||||
not gated on the platform either building or passing tests. Working builds for
|
|
||||||
these platforms may be spotty as their reliability is often defined in terms of
|
|
||||||
community contributions. Additionally, release artifacts and installers are not
|
|
||||||
provided, but there may be community infrastructure producing these in
|
|
||||||
unofficial locations.
|
|
||||||
|
|
||||||
| Target | std |rustc|cargo| notes |
|
|
||||||
|-------------------------------|-----|-----|-----|----------------------------|
|
|
||||||
| `aarch64-linux-android` | ✓ | | | ARM64 Android |
|
|
||||||
| `armv7-linux-androideabi` | ✓ | | | ARM-v7a Android |
|
|
||||||
| `i686-linux-android` | ✓ | | | 32-bit x86 Android |
|
|
||||||
| `i686-pc-windows-msvc` (XP) | ✓ | | | Windows XP support |
|
|
||||||
| `i686-unknown-freebsd` | ✓ | ✓ | ✓ | 32-bit FreeBSD |
|
|
||||||
| `x86_64-pc-windows-msvc` (XP) | ✓ | | | Windows XP support |
|
|
||||||
| `x86_64-sun-solaris` | ✓ | ✓ | | 64-bit Solaris/SunOS |
|
|
||||||
| `x86_64-unknown-bitrig` | ✓ | ✓ | | 64-bit Bitrig |
|
|
||||||
| `x86_64-unknown-dragonfly` | ✓ | ✓ | | 64-bit DragonFlyBSD |
|
|
||||||
| `x86_64-unknown-openbsd` | ✓ | ✓ | | 64-bit OpenBSD |
|
|
||||||
|
|
||||||
Note that this table can be expanded over time, this isn't the exhaustive set of
|
|
||||||
tier 3 platforms that will ever be!
|
|
||||||
|
|
||||||
## Installing on Linux or Mac
|
## Installing on Linux or Mac
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ has a command that does that for us. Let’s give it a shot:
|
||||||
```bash
|
```bash
|
||||||
$ cd ~/projects
|
$ cd ~/projects
|
||||||
$ cargo new guessing_game --bin
|
$ cargo new guessing_game --bin
|
||||||
|
Created binary (application) `guessing_game` project
|
||||||
$ cd guessing_game
|
$ cd guessing_game
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -51,6 +52,7 @@ Let’s try compiling what Cargo gave us:
|
||||||
```{bash}
|
```{bash}
|
||||||
$ cargo build
|
$ cargo build
|
||||||
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
||||||
|
Finished debug [unoptimized + debuginfo] target(s) in 0.53 secs
|
||||||
```
|
```
|
||||||
|
|
||||||
Excellent! Open up your `src/main.rs` again. We’ll be writing all of
|
Excellent! Open up your `src/main.rs` again. We’ll be writing all of
|
||||||
|
@ -61,6 +63,7 @@ Remember the `run` command from last chapter? Try it out again here:
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
||||||
|
Finished debug [unoptimized + debuginfo] target(s) in 0.0 secs
|
||||||
Running `target/debug/guessing_game`
|
Running `target/debug/guessing_game`
|
||||||
Hello, world!
|
Hello, world!
|
||||||
```
|
```
|
||||||
|
@ -282,10 +285,13 @@ we’ll get a warning:
|
||||||
```bash
|
```bash
|
||||||
$ cargo build
|
$ cargo build
|
||||||
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
||||||
src/main.rs:10:5: 10:39 warning: unused result which must be used,
|
warning: unused result which must be used, #[warn(unused_must_use)] on by default
|
||||||
#[warn(unused_must_use)] on by default
|
--> src/main.rs:10:5
|
||||||
src/main.rs:10 io::stdin().read_line(&mut guess);
|
|
|
||||||
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
10 | io::stdin().read_line(&mut guess);
|
||||||
|
| ^
|
||||||
|
|
||||||
|
Finished debug [unoptimized + debuginfo] target(s) in 0.42 secs
|
||||||
```
|
```
|
||||||
|
|
||||||
Rust warns us that we haven’t used the `Result` value. This warning comes from
|
Rust warns us that we haven’t used the `Result` value. This warning comes from
|
||||||
|
@ -321,6 +327,7 @@ Anyway, that’s the tour. We can run what we have with `cargo run`:
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
||||||
|
Finished debug [unoptimized + debuginfo] target(s) in 0.44 secs
|
||||||
Running `target/debug/guessing_game`
|
Running `target/debug/guessing_game`
|
||||||
Guess the number!
|
Guess the number!
|
||||||
Please input your guess.
|
Please input your guess.
|
||||||
|
@ -373,11 +380,12 @@ Now, without changing any of our code, let’s build our project:
|
||||||
```bash
|
```bash
|
||||||
$ cargo build
|
$ cargo build
|
||||||
Updating registry `https://github.com/rust-lang/crates.io-index`
|
Updating registry `https://github.com/rust-lang/crates.io-index`
|
||||||
Downloading rand v0.3.8
|
Downloading rand v0.3.14
|
||||||
Downloading libc v0.1.6
|
Downloading libc v0.2.17
|
||||||
Compiling libc v0.1.6
|
Compiling libc v0.2.17
|
||||||
Compiling rand v0.3.8
|
Compiling rand v0.3.14
|
||||||
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
||||||
|
Finished debug [unoptimized + debuginfo] target(s) in 5.88 secs
|
||||||
```
|
```
|
||||||
|
|
||||||
(You may see different versions, of course.)
|
(You may see different versions, of course.)
|
||||||
|
@ -399,22 +407,24 @@ If we run `cargo build` again, we’ll get different output:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo build
|
$ cargo build
|
||||||
|
Finished debug [unoptimized + debuginfo] target(s) in 0.0 secs
|
||||||
```
|
```
|
||||||
|
|
||||||
That’s right, no output! Cargo knows that our project has been built, and that
|
That’s right, nothing was done! Cargo knows that our project has been built, and that
|
||||||
all of its dependencies are built, and so there’s no reason to do all that
|
all of its dependencies are built, and so there’s no reason to do all that
|
||||||
stuff. With nothing to do, it simply exits. If we open up `src/main.rs` again,
|
stuff. With nothing to do, it simply exits. If we open up `src/main.rs` again,
|
||||||
make a trivial change, and then save it again, we’ll only see one line:
|
make a trivial change, and then save it again, we’ll only see two lines:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cargo build
|
$ cargo build
|
||||||
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
||||||
|
Finished debug [unoptimized + debuginfo] target(s) in 0.45 secs
|
||||||
```
|
```
|
||||||
|
|
||||||
So, we told Cargo we wanted any `0.3.x` version of `rand`, and so it fetched the latest
|
So, we told Cargo we wanted any `0.3.x` version of `rand`, and so it fetched the latest
|
||||||
version at the time this was written, `v0.3.8`. But what happens when next
|
version at the time this was written, `v0.3.14`. But what happens when next
|
||||||
week, version `v0.3.9` comes out, with an important bugfix? While getting
|
week, version `v0.3.15` comes out, with an important bugfix? While getting
|
||||||
bugfixes is important, what if `0.3.9` contains a regression that breaks our
|
bugfixes is important, what if `0.3.15` contains a regression that breaks our
|
||||||
code?
|
code?
|
||||||
|
|
||||||
The answer to this problem is the `Cargo.lock` file you’ll now find in your
|
The answer to this problem is the `Cargo.lock` file you’ll now find in your
|
||||||
|
@ -423,11 +433,11 @@ figures out all of the versions that fit your criteria, and then writes them
|
||||||
to the `Cargo.lock` file. When you build your project in the future, Cargo
|
to the `Cargo.lock` file. When you build your project in the future, Cargo
|
||||||
will see that the `Cargo.lock` file exists, and then use that specific version
|
will see that the `Cargo.lock` file exists, and then use that specific version
|
||||||
rather than do all the work of figuring out versions again. This lets you
|
rather than do all the work of figuring out versions again. This lets you
|
||||||
have a repeatable build automatically. In other words, we’ll stay at `0.3.8`
|
have a repeatable build automatically. In other words, we’ll stay at `0.3.14`
|
||||||
until we explicitly upgrade, and so will anyone who we share our code with,
|
until we explicitly upgrade, and so will anyone who we share our code with,
|
||||||
thanks to the lock file.
|
thanks to the lock file.
|
||||||
|
|
||||||
What about when we _do_ want to use `v0.3.9`? Cargo has another command,
|
What about when we _do_ want to use `v0.3.15`? Cargo has another command,
|
||||||
`update`, which says ‘ignore the lock, figure out all the latest versions that
|
`update`, which says ‘ignore the lock, figure out all the latest versions that
|
||||||
fit what we’ve specified. If that works, write those versions out to the lock
|
fit what we’ve specified. If that works, write those versions out to the lock
|
||||||
file’. But, by default, Cargo will only look for versions larger than `0.3.0`
|
file’. But, by default, Cargo will only look for versions larger than `0.3.0`
|
||||||
|
@ -510,6 +520,7 @@ Try running our new program a few times:
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
||||||
|
Finished debug [unoptimized + debuginfo] target(s) in 0.55 secs
|
||||||
Running `target/debug/guessing_game`
|
Running `target/debug/guessing_game`
|
||||||
Guess the number!
|
Guess the number!
|
||||||
The secret number is: 7
|
The secret number is: 7
|
||||||
|
@ -517,6 +528,7 @@ Please input your guess.
|
||||||
4
|
4
|
||||||
You guessed: 4
|
You guessed: 4
|
||||||
$ cargo run
|
$ cargo run
|
||||||
|
Finished debug [unoptimized + debuginfo] target(s) in 0.0 secs
|
||||||
Running `target/debug/guessing_game`
|
Running `target/debug/guessing_game`
|
||||||
Guess the number!
|
Guess the number!
|
||||||
The secret number is: 83
|
The secret number is: 83
|
||||||
|
@ -618,15 +630,20 @@ I did mention that this won’t quite compile yet, though. Let’s try it:
|
||||||
```bash
|
```bash
|
||||||
$ cargo build
|
$ cargo build
|
||||||
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
||||||
src/main.rs:28:21: 28:35 error: mismatched types:
|
error[E0308]: mismatched types
|
||||||
expected `&collections::string::String`,
|
--> src/main.rs:23:21
|
||||||
found `&_`
|
|
|
||||||
(expected struct `collections::string::String`,
|
23 | match guess.cmp(&secret_number) {
|
||||||
found integral variable) [E0308]
|
| ^^^^^^^^^^^^^^ expected struct `std::string::String`, found integral variable
|
||||||
src/main.rs:28 match guess.cmp(&secret_number) {
|
|
|
||||||
^~~~~~~~~~~~~~
|
= note: expected type `&std::string::String`
|
||||||
|
= note: found type `&{integer}`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
Could not compile `guessing_game`.
|
|
||||||
|
error: Could not compile `guessing_game`.
|
||||||
|
|
||||||
|
To learn more, run the command again with --verbose.
|
||||||
```
|
```
|
||||||
|
|
||||||
Whew! This is a big error. The core of it is that we have ‘mismatched types’.
|
Whew! This is a big error. The core of it is that we have ‘mismatched types’.
|
||||||
|
@ -722,6 +739,7 @@ Let’s try our program out!
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
||||||
|
Finished debug [unoptimized + debuginfo] target(s) in 0.57 secs
|
||||||
Running `target/guessing_game`
|
Running `target/guessing_game`
|
||||||
Guess the number!
|
Guess the number!
|
||||||
The secret number is: 58
|
The secret number is: 58
|
||||||
|
@ -785,6 +803,7 @@ and quit. Observe:
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
||||||
|
Finished debug [unoptimized + debuginfo] target(s) in 0.58 secs
|
||||||
Running `target/guessing_game`
|
Running `target/guessing_game`
|
||||||
Guess the number!
|
Guess the number!
|
||||||
The secret number is: 59
|
The secret number is: 59
|
||||||
|
@ -919,6 +938,7 @@ Now we should be good! Let’s try:
|
||||||
```bash
|
```bash
|
||||||
$ cargo run
|
$ cargo run
|
||||||
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
|
||||||
|
Finished debug [unoptimized + debuginfo] target(s) in 0.57 secs
|
||||||
Running `target/guessing_game`
|
Running `target/guessing_game`
|
||||||
Guess the number!
|
Guess the number!
|
||||||
The secret number is: 61
|
The secret number is: 61
|
||||||
|
|
|
@ -61,7 +61,7 @@ write something like this:
|
||||||
|
|
||||||
```rust,ignore
|
```rust,ignore
|
||||||
struct Point {
|
struct Point {
|
||||||
mut x: i32,
|
mut x: i32, // This causes an error.
|
||||||
y: i32,
|
y: i32,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -21,6 +21,11 @@ separately by extracting documentation attributes from their source code. Many
|
||||||
of the features that one might expect to be language features are library
|
of the features that one might expect to be language features are library
|
||||||
features in Rust, so what you're looking for may be there, not here.
|
features in Rust, so what you're looking for may be there, not here.
|
||||||
|
|
||||||
|
Finally, this document is not normative. It may include details that are
|
||||||
|
specific to `rustc` itself, and should not be taken as a specification for
|
||||||
|
the Rust language. We intend to produce such a document someday, but this
|
||||||
|
is what we have for now.
|
||||||
|
|
||||||
You may also be interested in the [grammar].
|
You may also be interested in the [grammar].
|
||||||
|
|
||||||
[book]: book/index.html
|
[book]: book/index.html
|
||||||
|
|
|
@ -381,11 +381,14 @@ impl<T: ?Sized> Arc<T> {
|
||||||
|
|
||||||
/// Gets the number of [`Weak`][weak] pointers to this value.
|
/// Gets the number of [`Weak`][weak] pointers to this value.
|
||||||
///
|
///
|
||||||
/// Be careful how you use this information, because another thread
|
|
||||||
/// may change the weak count at any time.
|
|
||||||
///
|
|
||||||
/// [weak]: struct.Weak.html
|
/// [weak]: struct.Weak.html
|
||||||
///
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// This method by itself is safe, but using it correctly requires extra care.
|
||||||
|
/// Another thread can change the weak count at any time,
|
||||||
|
/// including potentially between calling this method and acting on the result.
|
||||||
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -409,8 +412,11 @@ impl<T: ?Sized> Arc<T> {
|
||||||
|
|
||||||
/// Gets the number of strong (`Arc`) pointers to this value.
|
/// Gets the number of strong (`Arc`) pointers to this value.
|
||||||
///
|
///
|
||||||
/// Be careful how you use this information, because another thread
|
/// # Safety
|
||||||
/// may change the strong count at any time.
|
///
|
||||||
|
/// This method by itself is safe, but using it correctly requires extra care.
|
||||||
|
/// Another thread can change the strong count at any time,
|
||||||
|
/// including potentially between calling this method and acting on the result.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
|
|
@ -556,10 +556,14 @@ impl<'a, I: ExactSizeIterator + ?Sized> ExactSizeIterator for &'a mut I {}
|
||||||
|
|
||||||
/// Trait to represent types that can be created by summing up an iterator.
|
/// Trait to represent types that can be created by summing up an iterator.
|
||||||
///
|
///
|
||||||
/// This trait is used to implement the `sum` method on iterators. Types which
|
/// This trait is used to implement the [`sum()`] method on iterators. Types which
|
||||||
/// implement the trait can be generated by the `sum` method. Like
|
/// implement the trait can be generated by the [`sum()`] method. Like
|
||||||
/// `FromIterator` this trait should rarely be called directly and instead
|
/// [`FromIterator`] this trait should rarely be called directly and instead
|
||||||
/// interacted with through `Iterator::sum`.
|
/// interacted with through [`Iterator::sum()`].
|
||||||
|
///
|
||||||
|
/// [`sum()`]: ../../std/iter/trait.Sum.html#tymethod.sum
|
||||||
|
/// [`FromIterator`]: ../../std/iter/trait.FromIterator.html
|
||||||
|
/// [`Iterator::sum()`]: ../../std/iter/trait.Iterator.html#method.sum
|
||||||
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
|
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
|
||||||
pub trait Sum<A = Self>: Sized {
|
pub trait Sum<A = Self>: Sized {
|
||||||
/// Method which takes an iterator and generates `Self` from the elements by
|
/// Method which takes an iterator and generates `Self` from the elements by
|
||||||
|
@ -571,10 +575,14 @@ pub trait Sum<A = Self>: Sized {
|
||||||
/// Trait to represent types that can be created by multiplying elements of an
|
/// Trait to represent types that can be created by multiplying elements of an
|
||||||
/// iterator.
|
/// iterator.
|
||||||
///
|
///
|
||||||
/// This trait is used to implement the `product` method on iterators. Types
|
/// This trait is used to implement the [`product()`] method on iterators. Types
|
||||||
/// which implement the trait can be generated by the `product` method. Like
|
/// which implement the trait can be generated by the [`product()`] method. Like
|
||||||
/// `FromIterator` this trait should rarely be called directly and instead
|
/// [`FromIterator`] this trait should rarely be called directly and instead
|
||||||
/// interacted with through `Iterator::product`.
|
/// interacted with through [`Iterator::product()`].
|
||||||
|
///
|
||||||
|
/// [`product()`]: ../../std/iter/trait.Product.html#tymethod.product
|
||||||
|
/// [`FromIterator`]: ../../std/iter/trait.FromIterator.html
|
||||||
|
/// [`Iterator::product()`]: ../../std/iter/trait.Iterator.html#method.product
|
||||||
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
|
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
|
||||||
pub trait Product<A = Self>: Sized {
|
pub trait Product<A = Self>: Sized {
|
||||||
/// Method which takes an iterator and generates `Self` from the elements by
|
/// Method which takes an iterator and generates `Self` from the elements by
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
//! of other types, and you can implement them for your types too. As such,
|
//! of other types, and you can implement them for your types too. As such,
|
||||||
//! you'll see a few different types of I/O throughout the documentation in
|
//! you'll see a few different types of I/O throughout the documentation in
|
||||||
//! this module: [`File`]s, [`TcpStream`]s, and sometimes even [`Vec<T>`]s. For
|
//! this module: [`File`]s, [`TcpStream`]s, and sometimes even [`Vec<T>`]s. For
|
||||||
//! example, `Read` adds a `read()` method, which we can use on `File`s:
|
//! example, [`Read`] adds a [`read()`] method, which we can use on `File`s:
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! use std::io;
|
//! use std::io;
|
||||||
|
@ -251,6 +251,7 @@
|
||||||
//! [`Lines`]: struct.Lines.html
|
//! [`Lines`]: struct.Lines.html
|
||||||
//! [`io::Result`]: type.Result.html
|
//! [`io::Result`]: type.Result.html
|
||||||
//! [`try!`]: ../macro.try.html
|
//! [`try!`]: ../macro.try.html
|
||||||
|
//! [`read()`]: trait.Read.html#tymethod.read
|
||||||
|
|
||||||
#![stable(feature = "rust1", since = "1.0.0")]
|
#![stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
||||||
|
@ -814,19 +815,23 @@ pub trait Read {
|
||||||
///
|
///
|
||||||
/// Implementors of the `Write` trait are sometimes called 'writers'.
|
/// Implementors of the `Write` trait are sometimes called 'writers'.
|
||||||
///
|
///
|
||||||
/// Writers are defined by two required methods, `write()` and `flush()`:
|
/// Writers are defined by two required methods, [`write()`] and [`flush()`]:
|
||||||
///
|
///
|
||||||
/// * The `write()` method will attempt to write some data into the object,
|
/// * The [`write()`] method will attempt to write some data into the object,
|
||||||
/// returning how many bytes were successfully written.
|
/// returning how many bytes were successfully written.
|
||||||
///
|
///
|
||||||
/// * The `flush()` method is useful for adaptors and explicit buffers
|
/// * The [`flush()`] method is useful for adaptors and explicit buffers
|
||||||
/// themselves for ensuring that all buffered data has been pushed out to the
|
/// themselves for ensuring that all buffered data has been pushed out to the
|
||||||
/// 'true sink'.
|
/// 'true sink'.
|
||||||
///
|
///
|
||||||
/// Writers are intended to be composable with one another. Many implementors
|
/// Writers are intended to be composable with one another. Many implementors
|
||||||
/// throughout `std::io` take and provide types which implement the `Write`
|
/// throughout [`std::io`] take and provide types which implement the `Write`
|
||||||
/// trait.
|
/// trait.
|
||||||
///
|
///
|
||||||
|
/// [`write()`]: #tymethod.write
|
||||||
|
/// [`flush()`]: #tymethod.flush
|
||||||
|
/// [`std::io`]: index.html
|
||||||
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -1475,10 +1480,10 @@ impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> {
|
||||||
|
|
||||||
/// Reader adaptor which limits the bytes read from an underlying reader.
|
/// Reader adaptor which limits the bytes read from an underlying reader.
|
||||||
///
|
///
|
||||||
/// This struct is generally created by calling [`take()`][take] on a reader.
|
/// This struct is generally created by calling [`take()`] on a reader.
|
||||||
/// Please see the documentation of `take()` for more details.
|
/// Please see the documentation of [`take()`] for more details.
|
||||||
///
|
///
|
||||||
/// [take]: trait.Read.html#method.take
|
/// [`take()`]: trait.Read.html#method.take
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct Take<T> {
|
pub struct Take<T> {
|
||||||
inner: T,
|
inner: T,
|
||||||
|
@ -1491,8 +1496,10 @@ impl<T> Take<T> {
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
///
|
///
|
||||||
/// This instance may reach EOF after reading fewer bytes than indicated by
|
/// This instance may reach `EOF` after reading fewer bytes than indicated by
|
||||||
/// this method if the underlying `Read` instance reaches EOF.
|
/// this method if the underlying [`Read`] instance reaches EOF.
|
||||||
|
///
|
||||||
|
/// [`Read`]: ../../std/io/trait.Read.html
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
|
|
@ -318,10 +318,11 @@ impl<'a> BufRead for StdinLock<'a> {
|
||||||
///
|
///
|
||||||
/// Each handle shares a global buffer of data to be written to the standard
|
/// Each handle shares a global buffer of data to be written to the standard
|
||||||
/// output stream. Access is also synchronized via a lock and explicit control
|
/// output stream. Access is also synchronized via a lock and explicit control
|
||||||
/// over locking is available via the `lock` method.
|
/// over locking is available via the [`lock()`] method.
|
||||||
///
|
///
|
||||||
/// Created by the [`io::stdout`] method.
|
/// Created by the [`io::stdout`] method.
|
||||||
///
|
///
|
||||||
|
/// [`lock()`]: #method.lock
|
||||||
/// [`io::stdout`]: fn.stdout.html
|
/// [`io::stdout`]: fn.stdout.html
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct Stdout {
|
pub struct Stdout {
|
||||||
|
|
514
src/test/incremental/hashes/unary_and_binary_exprs.rs
Normal file
514
src/test/incremental/hashes/unary_and_binary_exprs.rs
Normal file
|
@ -0,0 +1,514 @@
|
||||||
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
|
||||||
|
// This test case tests the incremental compilation hash (ICH) implementation
|
||||||
|
// for unary and binary expressions.
|
||||||
|
|
||||||
|
// The general pattern followed here is: Change one thing between rev1 and rev2
|
||||||
|
// and make sure that the hash has changed, then change nothing between rev2 and
|
||||||
|
// rev3 and make sure that the hash has not changed.
|
||||||
|
|
||||||
|
// must-compile-successfully
|
||||||
|
// revisions: cfail1 cfail2 cfail3
|
||||||
|
// compile-flags: -Z query-dep-graph -Z force-overflow-checks=off
|
||||||
|
|
||||||
|
#![allow(warnings)]
|
||||||
|
#![feature(rustc_attrs)]
|
||||||
|
#![crate_type="rlib"]
|
||||||
|
|
||||||
|
|
||||||
|
// Change constant operand of negation -----------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn const_negation() -> i32 {
|
||||||
|
-10
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn const_negation() -> i32 {
|
||||||
|
-1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change constant operand of bitwise not --------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn const_bitwise_not() -> i32 {
|
||||||
|
!100
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn const_bitwise_not() -> i32 {
|
||||||
|
!99
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change variable operand of negation -----------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn var_negation(x: i32, y: i32) -> i32 {
|
||||||
|
-x
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn var_negation(x: i32, y: i32) -> i32 {
|
||||||
|
-y
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change variable operand of bitwise not --------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn var_bitwise_not(x: i32, y: i32) -> i32 {
|
||||||
|
!x
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn var_bitwise_not(x: i32, y: i32) -> i32 {
|
||||||
|
!y
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change variable operand of deref --------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn var_deref(x: &i32, y: &i32) -> i32 {
|
||||||
|
*x
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn var_deref(x: &i32, y: &i32) -> i32 {
|
||||||
|
*y
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change first constant operand of addition -----------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn first_const_add() -> i32 {
|
||||||
|
1 + 3
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn first_const_add() -> i32 {
|
||||||
|
2 + 3
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change second constant operand of addition -----------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn second_const_add() -> i32 {
|
||||||
|
1 + 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn second_const_add() -> i32 {
|
||||||
|
1 + 3
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change first variable operand of addition -----------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn first_var_add(a: i32, b: i32) -> i32 {
|
||||||
|
a + 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn first_var_add(a: i32, b: i32) -> i32 {
|
||||||
|
b + 2
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change second variable operand of addition ----------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn second_var_add(a: i32, b: i32) -> i32 {
|
||||||
|
1 + a
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn second_var_add(a: i32, b: i32) -> i32 {
|
||||||
|
1 + b
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change operator from + to - -------------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn plus_to_minus(a: i32) -> i32 {
|
||||||
|
1 + a
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn plus_to_minus(a: i32) -> i32 {
|
||||||
|
1 - a
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change operator from + to * -------------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn plus_to_mult(a: i32) -> i32 {
|
||||||
|
1 + a
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn plus_to_mult(a: i32) -> i32 {
|
||||||
|
1 * a
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change operator from + to / -------------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn plus_to_div(a: i32) -> i32 {
|
||||||
|
1 + a
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn plus_to_div(a: i32) -> i32 {
|
||||||
|
1 / a
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change operator from + to % -------------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn plus_to_mod(a: i32) -> i32 {
|
||||||
|
1 + a
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn plus_to_mod(a: i32) -> i32 {
|
||||||
|
1 % a
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change operator from && to || -----------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn and_to_or(a: bool, b: bool) -> bool {
|
||||||
|
a && b
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn and_to_or(a: bool, b: bool) -> bool {
|
||||||
|
a || b
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change operator from & to | -------------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn bitwise_and_to_bitwise_or(a: i32) -> i32 {
|
||||||
|
1 & a
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn bitwise_and_to_bitwise_or(a: i32) -> i32 {
|
||||||
|
1 | a
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change operator from & to ^ -------------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn bitwise_and_to_bitwise_xor(a: i32) -> i32 {
|
||||||
|
1 & a
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn bitwise_and_to_bitwise_xor(a: i32) -> i32 {
|
||||||
|
1 ^ a
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change operator from & to << ------------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn bitwise_and_to_lshift(a: i32) -> i32 {
|
||||||
|
a & 1
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn bitwise_and_to_lshift(a: i32) -> i32 {
|
||||||
|
a << 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change operator from & to >> ------------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn bitwise_and_to_rshift(a: i32) -> i32 {
|
||||||
|
a & 1
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn bitwise_and_to_rshift(a: i32) -> i32 {
|
||||||
|
a >> 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change operator from == to != -----------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn eq_to_uneq(a: i32) -> bool {
|
||||||
|
a == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn eq_to_uneq(a: i32) -> bool {
|
||||||
|
a != 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change operator from == to < ------------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn eq_to_lt(a: i32) -> bool {
|
||||||
|
a == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn eq_to_lt(a: i32) -> bool {
|
||||||
|
a < 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change operator from == to > ------------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn eq_to_gt(a: i32) -> bool {
|
||||||
|
a == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn eq_to_gt(a: i32) -> bool {
|
||||||
|
a > 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change operator from == to <= -----------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn eq_to_le(a: i32) -> bool {
|
||||||
|
a == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn eq_to_le(a: i32) -> bool {
|
||||||
|
a <= 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change operator from == to >= -----------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn eq_to_ge(a: i32) -> bool {
|
||||||
|
a == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn eq_to_ge(a: i32) -> bool {
|
||||||
|
a >= 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change type in cast expression ----------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn type_cast(a: u8) -> u64 {
|
||||||
|
let b = a as i32;
|
||||||
|
let c = b as u64;
|
||||||
|
c
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn type_cast(a: u8) -> u64 {
|
||||||
|
let b = a as u32;
|
||||||
|
let c = b as u64;
|
||||||
|
c
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change value in cast expression ---------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn value_cast(a: u32) -> i32 {
|
||||||
|
1 as i32
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn value_cast(a: u32) -> i32 {
|
||||||
|
2 as i32
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change l-value in assignment ------------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn lvalue() -> i32 {
|
||||||
|
let mut x = 10;
|
||||||
|
let mut y = 11;
|
||||||
|
x = 9;
|
||||||
|
x
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn lvalue() -> i32 {
|
||||||
|
let mut x = 10;
|
||||||
|
let mut y = 11;
|
||||||
|
y = 9;
|
||||||
|
x
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change r-value in assignment ------------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn rvalue() -> i32 {
|
||||||
|
let mut x = 10;
|
||||||
|
x = 9;
|
||||||
|
x
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn rvalue() -> i32 {
|
||||||
|
let mut x = 10;
|
||||||
|
x = 8;
|
||||||
|
x
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Change index into slice -----------------------------------------------------
|
||||||
|
#[cfg(cfail1)]
|
||||||
|
pub fn index_to_slice(s: &[u8], i: usize, j: usize) -> u8 {
|
||||||
|
s[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(cfail1))]
|
||||||
|
#[rustc_dirty(label="Hir", cfg="cfails2")]
|
||||||
|
#[rustc_clean(label="Hir", cfg="cfails3")]
|
||||||
|
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||||
|
#[rustc_metadata_clean(cfg="cfail3")]
|
||||||
|
pub fn index_to_slice(s: &[u8], i: usize, j: usize) -> u8 {
|
||||||
|
s[j]
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue