Auto merge of #73977 - Manishearth:rollup-2x4s7c6, r=Manishearth

Rollup of 8 pull requests

Successful merges:

 - #73454 (Move contributing.md to rustc-dev-guide and point at getting started)
 - #73724 (Use WASM's saturating casts if they are available)
 - #73726 (resolve: disallow labelled breaks/continues through closures/async blocks)
 - #73753 (Use 'tcx for references to AccessLevels wherever possible.)
 - #73781 (Update psm version)
 - #73952 (Add option for local docker testing.)
 - #73957 (disable BTree min_max test in Miri for now)
 - #73975 (Document rustc_ast::ast::Pat)

Failed merges:

r? @ghost
This commit is contained in:
bors 2020-07-02 23:18:15 +00:00
commit 5f4abc16e1
217 changed files with 2551 additions and 2444 deletions

View file

@ -1,529 +1,8 @@
# Contributing to Rust
[contributing-to-rust]: #contributing-to-rust
Thank you for your interest in contributing to Rust! There are many ways to
contribute, and we appreciate all of them. This document is a bit long, so here's
links to the major sections:
Thank you for your interest in contributing to Rust!
* [Feature Requests](#feature-requests)
* [Bug Reports](#bug-reports)
* [The Build System](#the-build-system)
* [Pull Requests](#pull-requests)
* [Writing Documentation](#writing-documentation)
* [Issue Triage](#issue-triage)
* [Out-of-tree Contributions](#out-of-tree-contributions)
* [Helpful Links and Information](#helpful-links-and-information)
To get started, read the [Getting Started] guide in the [rustc-dev-guide].
If you have questions, please make a post on [internals.rust-lang.org][internals] or
hop on the [Rust Discord server][rust-discord] or [Rust Zulip server][rust-zulip].
As a reminder, all contributors are expected to follow our [Code of Conduct][coc].
The [rustc-dev-guide] is your friend! It describes how the compiler works and how
to contribute to it in more detail than this document.
If this is your first time contributing, the [walkthrough] chapter of the guide
can give you a good example of how a typical contribution would go.
[internals]: https://internals.rust-lang.org
[rust-discord]: http://discord.gg/rust-lang
[rust-zulip]: https://rust-lang.zulipchat.com
[coc]: https://www.rust-lang.org/conduct.html
[Getting Started]: https://rustc-dev-guide.rust-lang.org/getting-started.md
[rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/
[walkthrough]: https://rustc-dev-guide.rust-lang.org/walkthrough.html
## Feature Requests
[feature-requests]: #feature-requests
To request a change to the way the Rust language works, please head over
to the [RFCs repository](https://github.com/rust-lang/rfcs) and view the
[README](https://github.com/rust-lang/rfcs/blob/master/README.md)
for instructions.
## Bug Reports
[bug-reports]: #bug-reports
While bugs are unfortunate, they're a reality in software. We can't fix what we
don't know about, so please report liberally. If you're not sure if something
is a bug or not, feel free to file a bug anyway.
**If you believe reporting your bug publicly represents a security risk to Rust users,
please follow our [instructions for reporting security vulnerabilities](https://www.rust-lang.org/policies/security)**.
If you're using the nightly channel, please check if the bug exists in the
latest toolchain before filing your bug. It might be fixed already.
If you have the chance, before reporting a bug, please [search existing
issues](https://github.com/rust-lang/rust/search?q=&type=Issues&utf8=%E2%9C%93),
as it's possible that someone else has already reported your error. This doesn't
always work, and sometimes it's hard to know what to search for, so consider this
extra credit. We won't mind if you accidentally file a duplicate report.
Similarly, to help others who encountered the bug find your issue,
consider filing an issue with a descriptive title, which contains information that might be unique to it.
This can be the language or compiler feature used, the conditions that trigger the bug,
or part of the error message if there is any.
An example could be: **"impossible case reached" on lifetime inference for impl Trait in return position**.
Opening an issue is as easy as following [this
link](https://github.com/rust-lang/rust/issues/new) and filling out the fields.
Here's a template that you can use to file a bug, though it's not necessary to
use it exactly:
<short summary of the bug>
I tried this code:
<code sample that causes the bug>
I expected to see this happen: <explanation>
Instead, this happened: <explanation>
## Meta
`rustc --version --verbose`:
Backtrace:
All three components are important: what you did, what you expected, what
happened instead. Please include the output of `rustc --version --verbose`,
which includes important information about what platform you're on, what
version of Rust you're using, etc.
Sometimes, a backtrace is helpful, and so including that is nice. To get
a backtrace, set the `RUST_BACKTRACE` environment variable to a value
other than `0`. The easiest way
to do this is to invoke `rustc` like this:
```bash
$ RUST_BACKTRACE=1 rustc ...
```
## The Build System
For info on how to configure and build the compiler, please see [this
chapter][rustcguidebuild] of the rustc-dev-guide. This chapter contains info for
contributions to the compiler and the standard library. It also lists some
really useful commands to the build system (`./x.py`), which could save you a
lot of time.
[rustcguidebuild]: https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html
## Pull Requests
[pull-requests]: #pull-requests
Pull requests are the primary mechanism we use to change Rust. GitHub itself
has some [great documentation][about-pull-requests] on using the Pull Request feature.
We use the "fork and pull" model [described here][development-models], where
contributors push changes to their personal fork and create pull requests to
bring those changes into the source repository.
[about-pull-requests]: https://help.github.com/articles/about-pull-requests/
[development-models]: https://help.github.com/articles/about-collaborative-development-models/
Please make pull requests against the `master` branch.
Rust follows a no merge policy, meaning, when you encounter merge
conflicts you are expected to always rebase instead of merge.
E.g. always use rebase when bringing the latest changes from
the master branch to your feature branch.
Also, please make sure that fixup commits are squashed into other related
commits with meaningful commit messages.
GitHub allows [closing issues using keywords][closing-keywords]. This feature
should be used to keep the issue tracker tidy. However, it is generally preferred
to put the "closes #123" text in the PR description rather than the issue commit;
particularly during rebasing, citing the issue number in the commit can "spam"
the issue in question.
[closing-keywords]: https://help.github.com/en/articles/closing-issues-using-keywords
Please make sure your pull request is in compliance with Rust's style
guidelines by running
$ python x.py test tidy
Make this check before every pull request (and every new commit in a pull
request); you can add [git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks)
before every push to make sure you never forget to make this check.
All pull requests are reviewed by another person. We have a bot,
[@rust-highfive][rust-highfive], that will automatically assign a random person to review your
request.
If you want to request that a specific person reviews your pull request,
you can add an `r?` to the pull request description. For example, [Steve][steveklabnik] usually reviews
documentation changes. So if you were to make a documentation change, add
r? @steveklabnik
to the end of the pull request description, and [@rust-highfive][rust-highfive] will assign
[@steveklabnik][steveklabnik] instead of a random person. This is entirely optional.
After someone has reviewed your pull request, they will leave an annotation
on the pull request with an `r+`. It will look something like this:
@bors r+
This tells [@bors][bors], our lovable integration bot, that your pull request has
been approved. The PR then enters the [merge queue][merge-queue], where [@bors][bors]
will run all the tests on every platform we support. If it all works out,
[@bors][bors] will merge your code into `master` and close the pull request.
Depending on the scale of the change, you may see a slightly different form of `r+`:
@bors r+ rollup
The additional `rollup` tells [@bors][bors] that this change is eligible for to be
"rolled up". Changes that are rolled up are tested and merged at the same time, to
speed the process up. Typically only small changes that are expected not to conflict
with one another are rolled up.
[rust-highfive]: https://github.com/rust-highfive
[steveklabnik]: https://github.com/steveklabnik
[bors]: https://github.com/bors
[merge-queue]: https://buildbot2.rust-lang.org/homu/queue/rust
Speaking of tests, Rust has a comprehensive test suite. More information about
it can be found [here][rctd].
### External Dependencies (subtree)
As a developer to this repository, you don't have to treat the following external projects
differently from other crates that are directly in this repo:
* Clippy
They are just regular files and directories. This is in contrast to `submodule` dependencies
(see below for those). Only tool authors will actually use any operations here.
#### Synchronizing a subtree
There are two synchronization directions: `subtree push` and `subtree pull`.
```
git subtree push -P src/tools/clippy git@github.com:your-github-name/rust-clippy sync-from-rust
```
takes all the changes that
happened to the copy in this repo and creates commits on the remote repo that match the local
changes. Every local commit that touched the subtree causes a commit on the remote repo, but is
modified to move the files from the specified directory to the tool repo root.
Make sure to not pick the `master` branch on the tool repo, so you can open a normal PR to the tool
to merge that subrepo push.
```
git subtree pull -P src/tools/clippy https://github.com/rust-lang/rust-clippy master
```
takes all changes since the last `subtree pull` from the tool repo
repo and adds these commits to the rustc repo + a merge commit that moves the tool changes into
the specified directory in the rust repository.
It is recommended that you always do a push first and get that merged to the tool master branch.
Then, when you do a pull, the merge works without conflicts.
While it's definitely possible to resolve conflicts during a pull, you may have to redo the conflict
resolution if your PR doesn't get merged fast enough and there are new conflicts. Do not try to
rebase the result of a `git subtree pull`, rebasing merge commits is a bad idea in general.
You always need to specify the `-P` prefix to the subtree directory and the corresponding remote
repository. If you specify the wrong directory or repository
you'll get very fun merges that try to push the wrong directory to the wrong remote repository.
Luckily you can just abort this without any consequences by throwing away either the pulled commits
in rustc or the pushed branch on the remote and try again. It is usually fairly obvious
that this is happening because you suddenly get thousands of commits that want to be synchronized.
#### Creating a new subtree dependency
If you want to create a new subtree dependency from an existing repository, call (from this
repository's root directory!)
```
git subtree add -P src/tools/clippy https://github.com/rust-lang/rust-clippy.git master
```
This will create a new commit, which you may not rebase under any circumstances! Delete the commit
and redo the operation if you need to rebase.
Now you're done, the `src/tools/clippy` directory behaves as if Clippy were part of the rustc
monorepo, so no one but you (or others that synchronize subtrees) actually needs to use `git subtree`.
### External Dependencies (submodules)
Currently building Rust will also build the following external projects:
* [miri](https://github.com/rust-lang/miri)
* [rustfmt](https://github.com/rust-lang/rustfmt)
* [rls](https://github.com/rust-lang/rls/)
We allow breakage of these tools in the nightly channel. Maintainers of these
projects will be notified of the breakages and should fix them as soon as
possible.
After the external is fixed, one could add the changes with
```sh
git add path/to/submodule
```
outside the submodule.
In order to prepare your tool-fixing PR, you can run the build locally by doing
`./x.py build src/tools/TOOL`. If you will be editing the sources
there, you may wish to set `submodules = false` in the `config.toml`
to prevent `x.py` from resetting to the original branch.
Breakage is not allowed in the beta and stable channels, and must be addressed
before the PR is merged.
#### Breaking Tools Built With The Compiler
Rust's build system builds a number of tools that make use of the
internals of the compiler. This includes
[RLS](https://github.com/rust-lang/rls) and
[rustfmt](https://github.com/rust-lang/rustfmt). If these tools
break because of your changes, you may run into a sort of "chicken and egg"
problem. These tools rely on the latest compiler to be built so you can't update
them to reflect your changes to the compiler until those changes are merged into
the compiler. At the same time, you can't get your changes merged into the compiler
because the rust-lang/rust build won't pass until those tools build and pass their
tests.
That means that, in the default state, you can't update the compiler without first
fixing rustfmt, rls and the other tools that the compiler builds.
Luckily, a feature was [added to Rust's build](https://github.com/rust-lang/rust/issues/45861)
to make all of this easy to handle. The idea is that we allow these tools to be "broken",
so that the rust-lang/rust build passes without trying to build them, then land the change
in the compiler, wait for a nightly, and go update the tools that you broke. Once you're done
and the tools are working again, you go back in the compiler and update the tools
so they can be distributed again.
This should avoid a bunch of synchronization dances and is also much easier on contributors as
there's no need to block on rls/rustfmt/other tools changes going upstream.
Here are those same steps in detail:
1. (optional) First, if it doesn't exist already, create a `config.toml` by copying
`config.toml.example` in the root directory of the Rust repository.
Set `submodules = false` in the `[build]` section. This will prevent `x.py`
from resetting to the original branch after you make your changes. If you
need to [update any submodules to their latest versions](#updating-submodules),
see the section of this file about that for more information.
2. (optional) Run `./x.py test src/tools/rustfmt` (substituting the submodule
that broke for `rustfmt`). Fix any errors in the submodule (and possibly others).
3. (optional) Make commits for your changes and send them to upstream repositories as a PR.
4. (optional) Maintainers of these submodules will **not** merge the PR. The PR can't be
merged because CI will be broken. You'll want to write a message on the PR referencing
your change, and how the PR should be merged once your change makes it into a nightly.
5. Wait for your PR to merge.
6. Wait for a nightly
7. (optional) Help land your PR on the upstream repository now that your changes are in nightly.
8. (optional) Send a PR to rust-lang/rust updating the submodule.
#### Updating submodules
These instructions are specific to updating `rustfmt`, however they may apply
to the other submodules as well. Please help by improving these instructions
if you find any discrepancies or special cases that need to be addressed.
To update the `rustfmt` submodule, start by running the appropriate
[`git submodule` command](https://git-scm.com/book/en/v2/Git-Tools-Submodules).
For example, to update to the latest commit on the remote master branch,
you may want to run:
```
git submodule update --remote src/tools/rustfmt
```
If you run `./x.py build` now, and you are lucky, it may just work. If you see
an error message about patches that did not resolve to any crates, you will need
to complete a few more steps which are outlined with their rationale below.
*(This error may change in the future to include more information.)*
```
error: failed to resolve patches for `https://github.com/rust-lang/rustfmt`
Caused by:
patch for `rustfmt-nightly` in `https://github.com/rust-lang/rustfmt` did not resolve to any crates
failed to run: ~/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo build --manifest-path ~/rust/src/bootstrap/Cargo.toml
```
If you haven't used the `[patch]`
section of `Cargo.toml` before, there is [some relevant documentation about it
in the cargo docs](http://doc.crates.io/manifest.html#the-patch-section). In
addition to that, you should read the
[Overriding dependencies](http://doc.crates.io/specifying-dependencies.html#overriding-dependencies)
section of the documentation as well.
Specifically, the following [section in Overriding dependencies](http://doc.crates.io/specifying-dependencies.html#testing-a-bugfix) reveals what the problem is:
> Next up we need to ensure that our lock file is updated to use this new version of uuid so our project uses the locally checked out copy instead of one from crates.io. The way [patch] works is that it'll load the dependency at ../path/to/uuid and then whenever crates.io is queried for versions of uuid it'll also return the local version.
>
> This means that the version number of the local checkout is significant and will affect whether the patch is used. Our manifest declared uuid = "1.0" which means we'll only resolve to >= 1.0.0, < 2.0.0, and Cargo's greedy resolution algorithm also means that we'll resolve to the maximum version within that range. Typically this doesn't matter as the version of the git repository will already be greater or match the maximum version published on crates.io, but it's important to keep this in mind!
This says that when we updated the submodule, the version number in our
`src/tools/rustfmt/Cargo.toml` changed. The new version is different from
the version in `Cargo.lock`, so the build can no longer continue.
To resolve this, we need to update `Cargo.lock`. Luckily, cargo provides a
command to do this easily.
```
$ cargo update -p rustfmt-nightly
```
This should change the version listed in `Cargo.lock` to the new version you updated
the submodule to. Running `./x.py build` should work now.
## Writing Documentation
Documentation improvements are very welcome. The source of `doc.rust-lang.org`
is located in `src/doc` in the tree, and standard API documentation is generated
from the source code itself. Documentation pull requests function in the same way
as other pull requests.
To find documentation-related issues, sort by the [T-doc label][tdoc].
[tdoc]: https://github.com/rust-lang/rust/issues?q=is%3Aopen%20is%3Aissue%20label%3AT-doc
You can find documentation style guidelines in [RFC 1574][rfc1574].
[rfc1574]: https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
In many cases, you don't need a full `./x.py doc`, which will build the entire
stage 2 compiler and compile the various books published on
[doc.rust-lang.org]. When updating documentation for the standard library,
first try `./x.py doc --stage 0 src/libstd`. If that fails, or if you need to
see the output from the latest version of `rustdoc`, use `--stage 1` instead of
`--stage 0`. Results should appear in `build/$TARGET/crate-docs`.
[doc.rust-lang.org]: htts://doc.rust-lang.org
You can also use `rustdoc` directly to check small fixes. For example,
`rustdoc src/doc/reference.md` will render reference to `doc/reference.html`.
The CSS might be messed up, but you can verify that the HTML is right.
Additionally, contributions to the [rustc-dev-guide] are always welcome. Contributions
can be made directly at [the
rust-lang/rustc-dev-guide](https://github.com/rust-lang/rustc-dev-guide) repo. The issue
tracker in that repo is also a great way to find things that need doing. There
are issues for beginners and advanced compiler devs alike!
## Issue Triage
Sometimes, an issue will stay open, even though the bug has been fixed. And
sometimes, the original bug may go stale because something has changed in the
meantime.
It can be helpful to go through older bug reports and make sure that they are
still valid. Load up an older issue, double check that it's still true, and
leave a comment letting us know if it is or is not. The [least recently
updated sort][lru] is good for finding issues like this.
Contributors with sufficient permissions on the Rust repo can help by adding
labels to triage issues:
* Yellow, **A**-prefixed labels state which **area** of the project an issue
relates to.
* Magenta, **B**-prefixed labels identify bugs which are **blockers**.
* Dark blue, **beta-** labels track changes which need to be backported into
the beta branches.
* Light purple, **C**-prefixed labels represent the **category** of an issue.
* Green, **E**-prefixed labels explain the level of **experience** necessary
to fix the issue.
* The dark blue **final-comment-period** label marks bugs that are using the
RFC signoff functionality of [rfcbot] and are currently in the final
comment period.
* Red, **I**-prefixed labels indicate the **importance** of the issue. The
[I-nominated][inom] label indicates that an issue has been nominated for
prioritizing at the next triage meeting.
* The purple **metabug** label marks lists of bugs collected by other
categories.
* Purple gray, **O**-prefixed labels are the **operating system** or platform
that this issue is specific to.
* Orange, **P**-prefixed labels indicate a bug's **priority**. These labels
are only assigned during triage meetings, and replace the [I-nominated][inom]
label.
* The gray **proposed-final-comment-period** label marks bugs that are using
the RFC signoff functionality of [rfcbot] and are currently awaiting
signoff of all team members in order to enter the final comment period.
* Pink, **regression**-prefixed labels track regressions from stable to the
release channels.
* The light orange **relnotes** label marks issues that should be documented in
the release notes of the next release.
* Gray, **S**-prefixed labels are used for tracking the **status** of pull
requests.
* Blue, **T**-prefixed bugs denote which **team** the issue belongs to.
If you're looking for somewhere to start, check out the [E-easy][eeasy] tag.
[inom]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3AI-nominated
[eeasy]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3AE-easy
[lru]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc
[rfcbot]: https://github.com/anp/rfcbot-rs/
## Out-of-tree Contributions
There are a number of other ways to contribute to Rust that don't deal with
this repository.
Answer questions in the _Get Help!_ channels from the [Rust Discord server][rust-discord], on [users.rust-lang.org][users],
or on [StackOverflow][so].
Participate in the [RFC process](https://github.com/rust-lang/rfcs).
Find a [requested community library][community-library], build it, and publish
it to [Crates.io](http://crates.io). Easier said than done, but very, very
valuable!
[rust-discord]: https://discord.gg/rust-lang
[users]: https://users.rust-lang.org/
[so]: http://stackoverflow.com/questions/tagged/rust
[community-library]: https://github.com/rust-lang/rfcs/labels/A-community-library
## Helpful Links and Information
For people new to Rust, and just starting to contribute, or even for
more seasoned developers, some useful places to look for information
are:
* The [rustc dev guide] contains information about how various parts of the compiler work and how to contribute to the compiler
* [Rust Forge][rustforge] contains additional documentation, including write-ups of how to achieve common tasks
* The [Rust Internals forum][rif], a place to ask questions and
discuss Rust's internals
* The [generated documentation for rust's compiler][gdfrustc]
* The [rust reference][rr], even though it doesn't specifically talk about Rust's internals, it's a great resource nonetheless
* Although out of date, [Tom Lee's great blog article][tlgba] is very helpful
* [rustaceans.org][ro] is helpful, but mostly dedicated to IRC
* The [Rust Compiler Testing Docs][rctd]
* For [@bors][bors], [this cheat sheet][cheatsheet] is helpful
(though you'll need to replace `@homu` with `@bors` in any commands)
* **Google!** ([search only in Rust Documentation][gsearchdocs] to find types, traits, etc. quickly)
* Don't be afraid to ask! The Rust community is friendly and helpful.
[rustc dev guide]: https://rustc-dev-guide.rust-lang.org/about-this-guide.html
[gdfrustc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/
[gsearchdocs]: https://www.google.com/search?q=site:doc.rust-lang.org+your+query+here
[rif]: http://internals.rust-lang.org
[rr]: https://doc.rust-lang.org/book/README.html
[rustforge]: https://forge.rust-lang.org/
[tlgba]: http://tomlee.co/2014/04/a-more-detailed-tour-of-the-rust-compiler/
[ro]: http://www.rustaceans.org/
[rctd]: https://rustc-dev-guide.rust-lang.org/tests/intro.html
[cheatsheet]: https://buildbot2.rust-lang.org/homu/

View file

@ -2347,9 +2347,9 @@ dependencies = [
[[package]]
name = "psm"
version = "0.1.8"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "659ecfea2142a458893bb7673134bad50b752fea932349c213d6a23874ce3aa7"
checksum = "092d385624a084892d07374caa7b0994956692cf40650419a1f1a787a8d229cf"
dependencies = [
"cc",
]

View file

@ -7,6 +7,8 @@ standard library, and documentation.
[Rust]: https://www.rust-lang.org
**Note: this README is for _users_ rather than _contributors_.**
## Quick Start
Read ["Installation"] from [The Book].
@ -16,13 +18,15 @@ Read ["Installation"] from [The Book].
## Installing from Source
_Note: If you wish to contribute to the compiler, you should read [this
chapter][rustcguidebuild] of the rustc-dev-guide instead of this section._
**Note: If you wish to _contribute_ to the compiler, you should read the
[Getting Started][gettingstarted] of the rustc-dev-guide instead of this
section.**
The Rust build system uses a Python script called `x.py` to build the compiler,
which manages the bootstrapping process. More information about it can be found
by running `./x.py --help` or reading the [rustc dev guide][rustcguidebuild].
[gettingstarted]: https://rustc-dev-guide.rust-lang.org/getting-started.md
[rustcguidebuild]: https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html
### Building on a Unix-like system
@ -225,10 +229,6 @@ Snapshot binaries are currently built and tested on several platforms:
You may find that other platforms work, but these are our officially
supported build environments that are most likely to work.
There is more advice about hacking on Rust in [CONTRIBUTING.md].
[CONTRIBUTING.md]: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md
## Getting Help
The Rust community congregates in a few places:
@ -243,21 +243,8 @@ The Rust community congregates in a few places:
## Contributing
To contribute to Rust, please see [CONTRIBUTING](CONTRIBUTING.md).
Most real-time collaboration happens in a variety of channels on the
[Rust Discord server][rust-discord], with channels dedicated for getting help,
community, documentation, and all major contribution areas in the Rust ecosystem.
A good place to ask for help would be the #help channel.
The [rustc dev guide] might be a good place to start if you want to find out how
various parts of the compiler work.
Also, you may find the [rustdocs for the compiler itself][rustdocs] useful.
[rust-discord]: https://discord.gg/rust-lang
[rustc dev guide]: https://rustc-dev-guide.rust-lang.org/about-this-guide.html
[rustdocs]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/
If you are interested in contributing to the Rust project, please take a look
at the [Getting Started][gettingstarted] guide in the [rustc-dev-guide].
## License

View file

@ -5,7 +5,27 @@ set -e
export MSYS_NO_PATHCONV=1
script=`cd $(dirname $0) && pwd`/`basename $0`
image=$1
image=""
dev=0
while [[ $# -gt 0 ]]
do
case "$1" in
--dev)
dev=1
;;
*)
if [ -n "$image" ]
then
echo "expected single argument for the image name"
exit 1
fi
image="$1"
;;
esac
shift
done
docker_dir="`dirname $script`"
ci_dir="`dirname $docker_dir`"
@ -163,6 +183,15 @@ else
args="$args --env LOCAL_USER_ID=`id -u`"
fi
if [ "$dev" = "1" ]
then
# Interactive + TTY
args="$args -it"
command="/bin/bash"
else
command="/checkout/src/ci/run.sh"
fi
docker \
run \
--workdir /checkout/obj \
@ -183,7 +212,7 @@ docker \
--init \
--rm \
rust-ci \
/checkout/src/ci/run.sh
$command
if [ -f /.dockerenv ]; then
rm -rf $objdir

View file

@ -17,7 +17,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
wget \
patch
RUN curl -sL https://nodejs.org/dist/v9.2.0/node-v9.2.0-linux-x64.tar.xz | \
RUN curl -sL https://nodejs.org/dist/v14.4.0/node-v14.4.0-linux-x64.tar.xz | \
tar -xJ
WORKDIR /build/
@ -30,7 +30,7 @@ RUN sh /scripts/sccache.sh
ENV RUST_CONFIGURE_ARGS \
--musl-root-x86_64=/usr/local/x86_64-linux-musl \
--set build.nodejs=/node-v9.2.0-linux-x64/bin/node \
--set build.nodejs=/node-v14.4.0-linux-x64/bin/node \
--set rust.lld
# Some run-make tests have assertions about code size, and enabling debug

View file

@ -310,6 +310,7 @@ fn test_iter_mixed() {
}
#[test]
#[cfg_attr(miri, ignore)] // FIXME: fails in Miri <https://github.com/rust-lang/rust/issues/73915>
fn test_iter_min_max() {
let mut a = BTreeMap::new();
assert_eq!(a.iter().min(), None);

View file

@ -511,6 +511,9 @@ pub struct Block {
pub span: Span,
}
/// A match pattern.
///
/// Patterns appear in match statements and some other contexts, such as `let` and `if let`.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Pat {
pub id: NodeId,

View file

@ -18,6 +18,7 @@ use rustc_data_structures::small_c_str::SmallCStr;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::layout::TyAndLayout;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::sym;
use rustc_target::abi::{self, Align, Size};
use rustc_target::spec::{HasTargetSpec, Target};
use std::borrow::Cow;
@ -652,6 +653,56 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
unsafe { llvm::LLVMBuildSExt(self.llbuilder, val, dest_ty, UNNAMED) }
}
fn fptoui_sat(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> Option<&'ll Value> {
// WebAssembly has saturating floating point to integer casts if the
// `nontrapping-fptoint` target feature is activated. We'll use those if
// they are available.
if self.sess().target.target.arch == "wasm32"
&& self.sess().target_features.contains(&sym::nontrapping_fptoint)
{
let src_ty = self.cx.val_ty(val);
let float_width = self.cx.float_width(src_ty);
let int_width = self.cx.int_width(dest_ty);
let name = match (int_width, float_width) {
(32, 32) => Some("llvm.wasm.trunc.saturate.unsigned.i32.f32"),
(32, 64) => Some("llvm.wasm.trunc.saturate.unsigned.i32.f64"),
(64, 32) => Some("llvm.wasm.trunc.saturate.unsigned.i64.f32"),
(64, 64) => Some("llvm.wasm.trunc.saturate.unsigned.i64.f64"),
_ => None,
};
if let Some(name) = name {
let intrinsic = self.get_intrinsic(name);
return Some(self.call(intrinsic, &[val], None));
}
}
None
}
fn fptosi_sat(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> Option<&'ll Value> {
// WebAssembly has saturating floating point to integer casts if the
// `nontrapping-fptoint` target feature is activated. We'll use those if
// they are available.
if self.sess().target.target.arch == "wasm32"
&& self.sess().target_features.contains(&sym::nontrapping_fptoint)
{
let src_ty = self.cx.val_ty(val);
let float_width = self.cx.float_width(src_ty);
let int_width = self.cx.int_width(dest_ty);
let name = match (int_width, float_width) {
(32, 32) => Some("llvm.wasm.trunc.saturate.signed.i32.f32"),
(32, 64) => Some("llvm.wasm.trunc.saturate.signed.i32.f64"),
(64, 32) => Some("llvm.wasm.trunc.saturate.signed.i64.f32"),
(64, 64) => Some("llvm.wasm.trunc.saturate.signed.i64.f64"),
_ => None,
};
if let Some(name) = name {
let intrinsic = self.get_intrinsic(name);
return Some(self.call(intrinsic, &[val], None));
}
}
None
}
fn fptoui(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
unsafe { llvm::LLVMBuildFPToUI(self.llbuilder, val, dest_ty, UNNAMED) }
}

View file

@ -497,6 +497,15 @@ impl CodegenCx<'b, 'tcx> {
t_v8f64: t_f64, 8;
}
ifn!("llvm.wasm.trunc.saturate.unsigned.i32.f32", fn(t_f32) -> t_i32);
ifn!("llvm.wasm.trunc.saturate.unsigned.i32.f64", fn(t_f64) -> t_i32);
ifn!("llvm.wasm.trunc.saturate.unsigned.i64.f32", fn(t_f32) -> t_i64);
ifn!("llvm.wasm.trunc.saturate.unsigned.i64.f64", fn(t_f64) -> t_i64);
ifn!("llvm.wasm.trunc.saturate.signed.i32.f32", fn(t_f32) -> t_i32);
ifn!("llvm.wasm.trunc.saturate.signed.i32.f64", fn(t_f64) -> t_i32);
ifn!("llvm.wasm.trunc.saturate.signed.i64.f32", fn(t_f32) -> t_i64);
ifn!("llvm.wasm.trunc.saturate.signed.i64.f64", fn(t_f64) -> t_i64);
ifn!("llvm.trap", fn() -> void);
ifn!("llvm.debugtrap", fn() -> void);
ifn!("llvm.frameaddress", fn(t_i32) -> i8p);

View file

@ -250,8 +250,11 @@ const RISCV_WHITELIST: &[(&str, Option<Symbol>)] = &[
("e", Some(sym::riscv_target_feature)),
];
const WASM_WHITELIST: &[(&str, Option<Symbol>)] =
&[("simd128", Some(sym::wasm_target_feature)), ("atomics", Some(sym::wasm_target_feature))];
const WASM_WHITELIST: &[(&str, Option<Symbol>)] = &[
("simd128", Some(sym::wasm_target_feature)),
("atomics", Some(sym::wasm_target_feature)),
("nontrapping-fptoint", Some(sym::wasm_target_feature)),
];
/// When rustdoc is running, provide a list of all known features so that all their respective
/// primitives may be documented.

View file

@ -774,12 +774,17 @@ fn cast_float_to_int<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
float_ty: Bx::Type,
int_ty: Bx::Type,
) -> Bx::Value {
let fptosui_result = if signed { bx.fptosi(x, int_ty) } else { bx.fptoui(x, int_ty) };
if let Some(false) = bx.cx().sess().opts.debugging_opts.saturating_float_casts {
return fptosui_result;
return if signed { bx.fptosi(x, int_ty) } else { bx.fptoui(x, int_ty) };
}
let try_sat_result = if signed { bx.fptosi_sat(x, int_ty) } else { bx.fptoui_sat(x, int_ty) };
if let Some(try_sat_result) = try_sat_result {
return try_sat_result;
}
let fptosui_result = if signed { bx.fptosi(x, int_ty) } else { bx.fptoui(x, int_ty) };
let int_width = bx.cx().int_width(int_ty);
let float_width = bx.cx().float_width(float_ty);
// LLVM's fpto[su]i returns undef when the input x is infinite, NaN, or does not fit into the

View file

@ -158,6 +158,8 @@ pub trait BuilderMethods<'a, 'tcx>:
fn trunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
fn sext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
fn fptoui_sat(&mut self, val: Self::Value, dest_ty: Self::Type) -> Option<Self::Value>;
fn fptosi_sat(&mut self, val: Self::Value, dest_ty: Self::Type) -> Option<Self::Value>;
fn fptoui(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
fn fptosi(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
fn uitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;

View file

@ -448,6 +448,7 @@ E0763: include_str!("./error_codes/E0763.md"),
E0764: include_str!("./error_codes/E0764.md"),
E0765: include_str!("./error_codes/E0765.md"),
E0766: include_str!("./error_codes/E0766.md"),
E0767: include_str!("./error_codes/E0767.md"),
;
// E0006, // merged with E0005
// E0008, // cannot bind by-move into a pattern guard

View file

@ -0,0 +1,20 @@
An unreachable label was used.
Erroneous code example:
```compile_fail,E0767
'a: loop {
|| {
loop { break 'a } // error: use of unreachable label `'a`
};
}
```
Ensure that the label is within scope. Labels are not reachable through
functions, closures, async blocks or modules. Example:
```
'a: loop {
break 'a; // ok!
}
```

View file

@ -21,8 +21,8 @@ declare_lint_pass!(
ArrayIntoIter => [ARRAY_INTO_ITER]
);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIntoIter {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'tcx>) {
impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
// We only care about method call expressions.
if let hir::ExprKind::MethodCall(call, span, args, _) = &expr.kind {
if call.ident.name != sym::into_iter {

View file

@ -104,7 +104,7 @@ declare_lint! {
declare_lint_pass!(BoxPointers => [BOX_POINTERS]);
impl BoxPointers {
fn check_heap_type(&self, cx: &LateContext<'_, '_>, span: Span, ty: Ty<'_>) {
fn check_heap_type(&self, cx: &LateContext<'_>, span: Span, ty: Ty<'_>) {
for leaf in ty.walk() {
if let GenericArgKind::Type(leaf_ty) = leaf.unpack() {
if leaf_ty.is_box() {
@ -117,8 +117,8 @@ impl BoxPointers {
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers {
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) {
impl<'tcx> LateLintPass<'tcx> for BoxPointers {
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
match it.kind {
hir::ItemKind::Fn(..)
| hir::ItemKind::TyAlias(..)
@ -143,7 +143,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers {
}
}
fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr<'_>) {
fn check_expr(&mut self, cx: &LateContext<'_>, e: &hir::Expr<'_>) {
let ty = cx.tables().node_type(e.hir_id);
self.check_heap_type(cx, e.span, ty);
}
@ -157,8 +157,8 @@ declare_lint! {
declare_lint_pass!(NonShorthandFieldPatterns => [NON_SHORTHAND_FIELD_PATTERNS]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
fn check_pat(&mut self, cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>) {
impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns {
fn check_pat(&mut self, cx: &LateContext<'_>, pat: &hir::Pat<'_>) {
if let PatKind::Struct(ref qpath, field_pats, _) = pat.kind {
let variant = cx
.tables()
@ -348,7 +348,7 @@ impl MissingDoc {
fn check_missing_docs_attrs(
&self,
cx: &LateContext<'_, '_>,
cx: &LateContext<'_>,
id: Option<hir::HirId>,
attrs: &[ast::Attribute],
sp: Span,
@ -388,8 +388,8 @@ impl MissingDoc {
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
fn enter_lint_attrs(&mut self, _: &LateContext<'_, '_>, attrs: &[ast::Attribute]) {
impl<'tcx> LateLintPass<'tcx> for MissingDoc {
fn enter_lint_attrs(&mut self, _: &LateContext<'_>, attrs: &[ast::Attribute]) {
let doc_hidden = self.doc_hidden()
|| attrs.iter().any(|attr| {
attr.check_name(sym::doc)
@ -401,11 +401,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
self.doc_hidden_stack.push(doc_hidden);
}
fn exit_lint_attrs(&mut self, _: &LateContext<'_, '_>, _attrs: &[ast::Attribute]) {
fn exit_lint_attrs(&mut self, _: &LateContext<'_>, _attrs: &[ast::Attribute]) {
self.doc_hidden_stack.pop().expect("empty doc_hidden_stack");
}
fn check_crate(&mut self, cx: &LateContext<'_, '_>, krate: &hir::Crate<'_>) {
fn check_crate(&mut self, cx: &LateContext<'_>, krate: &hir::Crate<'_>) {
self.check_missing_docs_attrs(cx, None, &krate.item.attrs, krate.item.span, "the", "crate");
for macro_def in krate.exported_macros {
@ -420,7 +420,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
}
}
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) {
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
match it.kind {
hir::ItemKind::Trait(.., trait_item_refs) => {
// Issue #11592: traits are always considered exported, even when private.
@ -467,7 +467,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
self.check_missing_docs_attrs(cx, Some(it.hir_id), &it.attrs, it.span, article, desc);
}
fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, trait_item: &hir::TraitItem<'_>) {
fn check_trait_item(&mut self, cx: &LateContext<'_>, trait_item: &hir::TraitItem<'_>) {
if self.private_traits.contains(&trait_item.hir_id) {
return;
}
@ -485,7 +485,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
);
}
fn check_impl_item(&mut self, cx: &LateContext<'_, '_>, impl_item: &hir::ImplItem<'_>) {
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {
// If the method is an impl for a trait, don't doc.
if method_context(cx, impl_item.hir_id) == MethodLateContext::TraitImpl {
return;
@ -503,7 +503,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
);
}
fn check_struct_field(&mut self, cx: &LateContext<'_, '_>, sf: &hir::StructField<'_>) {
fn check_struct_field(&mut self, cx: &LateContext<'_>, sf: &hir::StructField<'_>) {
if !sf.is_positional() {
self.check_missing_docs_attrs(
cx,
@ -516,7 +516,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
}
}
fn check_variant(&mut self, cx: &LateContext<'_, '_>, v: &hir::Variant<'_>) {
fn check_variant(&mut self, cx: &LateContext<'_>, v: &hir::Variant<'_>) {
self.check_missing_docs_attrs(cx, Some(v.id), &v.attrs, v.span, "a", "variant");
}
}
@ -529,8 +529,8 @@ declare_lint! {
declare_lint_pass!(MissingCopyImplementations => [MISSING_COPY_IMPLEMENTATIONS]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations {
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item<'_>) {
impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
if !cx.access_levels.is_reachable(item.hir_id) {
return;
}
@ -590,8 +590,8 @@ pub struct MissingDebugImplementations {
impl_lint_pass!(MissingDebugImplementations => [MISSING_DEBUG_IMPLEMENTATIONS]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations {
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item<'_>) {
impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
if !cx.access_levels.is_reachable(item.hir_id) {
return;
}
@ -813,8 +813,8 @@ declare_lint! {
declare_lint_pass!(InvalidNoMangleItems => [NO_MANGLE_CONST_ITEMS, NO_MANGLE_GENERIC_ITEMS]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) {
impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
match it.kind {
hir::ItemKind::Fn(.., ref generics, _) => {
if let Some(no_mangle_attr) = attr::find_by_name(&it.attrs, sym::no_mangle) {
@ -883,8 +883,8 @@ declare_lint! {
declare_lint_pass!(MutableTransmutes => [MUTABLE_TRANSMUTES]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes {
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for MutableTransmutes {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) {
use rustc_target::spec::abi::Abi::RustIntrinsic;
if let Some((&ty::Ref(_, _, from_mt), &ty::Ref(_, _, to_mt))) =
get_transmute_from_to(cx, expr).map(|(ty1, ty2)| (&ty1.kind, &ty2.kind))
@ -896,8 +896,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes {
}
}
fn get_transmute_from_to<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
fn get_transmute_from_to<'tcx>(
cx: &LateContext<'tcx>,
expr: &hir::Expr<'_>,
) -> Option<(Ty<'tcx>, Ty<'tcx>)> {
let def = if let hir::ExprKind::Path(ref qpath) = expr.kind {
@ -917,7 +917,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes {
None
}
fn def_id_is_transmute(cx: &LateContext<'_, '_>, def_id: DefId) -> bool {
fn def_id_is_transmute(cx: &LateContext<'_>, def_id: DefId) -> bool {
cx.tcx.fn_sig(def_id).abi() == RustIntrinsic
&& cx.tcx.item_name(def_id) == sym::transmute
}
@ -935,8 +935,8 @@ declare_lint_pass!(
UnstableFeatures => [UNSTABLE_FEATURES]
);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnstableFeatures {
fn check_attribute(&mut self, ctx: &LateContext<'_, '_>, attr: &ast::Attribute) {
impl<'tcx> LateLintPass<'tcx> for UnstableFeatures {
fn check_attribute(&mut self, ctx: &LateContext<'_>, attr: &ast::Attribute) {
if attr.check_name(sym::feature) {
if let Some(items) = attr.meta_item_list() {
for item in items {
@ -963,7 +963,7 @@ declare_lint_pass!(
impl UnreachablePub {
fn perform_lint(
&self,
cx: &LateContext<'_, '_>,
cx: &LateContext<'_>,
what: &str,
id: hir::HirId,
vis: &hir::Visibility<'_>,
@ -1003,16 +1003,12 @@ impl UnreachablePub {
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnreachablePub {
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item<'_>) {
impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
self.perform_lint(cx, "item", item.hir_id, &item.vis, item.span, true);
}
fn check_foreign_item(
&mut self,
cx: &LateContext<'_, '_>,
foreign_item: &hir::ForeignItem<'tcx>,
) {
fn check_foreign_item(&mut self, cx: &LateContext<'_>, foreign_item: &hir::ForeignItem<'tcx>) {
self.perform_lint(
cx,
"item",
@ -1023,11 +1019,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnreachablePub {
);
}
fn check_struct_field(&mut self, cx: &LateContext<'_, '_>, field: &hir::StructField<'_>) {
fn check_struct_field(&mut self, cx: &LateContext<'_>, field: &hir::StructField<'_>) {
self.perform_lint(cx, "field", field.hir_id, &field.vis, field.span, false);
}
fn check_impl_item(&mut self, cx: &LateContext<'_, '_>, impl_item: &hir::ImplItem<'_>) {
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {
self.perform_lint(cx, "item", impl_item.hir_id, &impl_item.vis, impl_item.span, false);
}
}
@ -1096,8 +1092,8 @@ impl TypeAliasBounds {
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds {
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::Item<'_>) {
impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
let (ty, type_alias_generics) = match item.kind {
hir::ItemKind::TyAlias(ref ty, ref generics) => (&*ty, generics),
_ => return,
@ -1170,15 +1166,15 @@ declare_lint_pass!(
UnusedBrokenConst => []
);
fn check_const(cx: &LateContext<'_, '_>, body_id: hir::BodyId) {
fn check_const(cx: &LateContext<'_>, body_id: hir::BodyId) {
let def_id = cx.tcx.hir().body_owner_def_id(body_id).to_def_id();
// trigger the query once for all constants since that will already report the errors
// FIXME: Use ensure here
let _ = cx.tcx.const_eval_poly(def_id);
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedBrokenConst {
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) {
impl<'tcx> LateLintPass<'tcx> for UnusedBrokenConst {
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
match it.kind {
hir::ItemKind::Const(_, body_id) => {
check_const(cx, body_id);
@ -1203,8 +1199,8 @@ declare_lint_pass!(
TrivialConstraints => [TRIVIAL_BOUNDS]
);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'tcx>) {
impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::PredicateKind::*;
@ -1372,8 +1368,8 @@ impl UnnameableTestItems {
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestItems {
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) {
impl<'tcx> LateLintPass<'tcx> for UnnameableTestItems {
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
if self.items_nameable {
if let hir::ItemKind::Mod(..) = it.kind {
} else {
@ -1390,7 +1386,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnameableTestItems {
}
}
fn check_item_post(&mut self, _cx: &LateContext<'_, '_>, it: &hir::Item<'_>) {
fn check_item_post(&mut self, _cx: &LateContext<'_>, it: &hir::Item<'_>) {
if !self.items_nameable && self.boundary == Some(it.hir_id) {
self.items_nameable = true;
}
@ -1639,8 +1635,8 @@ impl ExplicitOutlivesRequirements {
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'_>) {
impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
use rustc_middle::middle::resolve_lifetime::Region;
let infer_static = cx.tcx.features().infer_static_outlives_requirements;
@ -1850,8 +1846,8 @@ declare_lint! {
declare_lint_pass!(InvalidValue => [INVALID_VALUE]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &hir::Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for InvalidValue {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &hir::Expr<'_>) {
#[derive(Debug, Copy, Clone, PartialEq)]
enum InitKind {
Zeroed,
@ -1880,7 +1876,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
}
/// Determine if this expression is a "dangerous initialization".
fn is_dangerous_init(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) -> Option<InitKind> {
fn is_dangerous_init(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option<InitKind> {
// `transmute` is inside an anonymous module (the `extern` block?);
// `Invalid` represents the empty string and matches that.
// FIXME(#66075): use diagnostic items. Somehow, that does not seem to work
@ -2134,11 +2130,7 @@ impl ClashingExternDeclarations {
/// Checks whether two types are structurally the same enough that the declarations shouldn't
/// clash. We need this so we don't emit a lint when two modules both declare an extern struct,
/// with the same members (as the declarations shouldn't clash).
fn structurally_same_type<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
a: Ty<'tcx>,
b: Ty<'tcx>,
) -> bool {
fn structurally_same_type<'tcx>(cx: &LateContext<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
let tcx = cx.tcx;
if a == b || rustc_middle::ty::TyS::same_type(a, b) {
// All nominally-same types are structurally same, too.
@ -2212,8 +2204,8 @@ impl ClashingExternDeclarations {
impl_lint_pass!(ClashingExternDeclarations => [CLASHING_EXTERN_DECLARATIONS]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ClashingExternDeclarations {
fn check_foreign_item(&mut self, cx: &LateContext<'a, 'tcx>, this_fi: &hir::ForeignItem<'_>) {
impl<'tcx> LateLintPass<'tcx> for ClashingExternDeclarations {
fn check_foreign_item(&mut self, cx: &LateContext<'tcx>, this_fi: &hir::ForeignItem<'_>) {
trace!("ClashingExternDeclarations: check_foreign_item: {:?}", this_fi);
if let ForeignItemKind::Fn(..) = this_fi.kind {
let tcx = *&cx.tcx;

View file

@ -421,7 +421,7 @@ impl LintStore {
}
/// Context for lint checking after type checking.
pub struct LateContext<'a, 'tcx> {
pub struct LateContext<'tcx> {
/// Type context we're checking in.
pub tcx: TyCtxt<'tcx>,
@ -438,7 +438,7 @@ pub struct LateContext<'a, 'tcx> {
pub param_env: ty::ParamEnv<'tcx>,
/// Items accessible from the crate being checked.
pub access_levels: &'a AccessLevels,
pub access_levels: &'tcx AccessLevels,
/// The store of registered lints and the lint levels.
pub lint_store: &'tcx LintStore,
@ -624,7 +624,7 @@ impl<'a> EarlyContext<'a> {
}
}
impl LintContext for LateContext<'_, '_> {
impl LintContext for LateContext<'_> {
type PassObject = LateLintPassObject;
/// Gets the overall compiler `Session` object.
@ -673,7 +673,7 @@ impl LintContext for EarlyContext<'_> {
}
}
impl<'a, 'tcx> LateContext<'a, 'tcx> {
impl<'tcx> LateContext<'tcx> {
/// Gets the type-checking side-tables for the current body,
/// or `None` if outside a body.
pub fn maybe_typeck_tables(&self) -> Option<&'tcx ty::TypeckTables<'tcx>> {
@ -849,7 +849,7 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
}
}
impl<'a, 'tcx> LayoutOf for LateContext<'a, 'tcx> {
impl<'tcx> LayoutOf for LateContext<'tcx> {
type Ty = Ty<'tcx>;
type TyAndLayout = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>;

View file

@ -84,8 +84,8 @@ declare_lint_pass!(TyTyKind => [
USAGE_OF_QUALIFIED_TY,
]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
fn check_path(&mut self, cx: &LateContext<'_, '_>, path: &'tcx Path<'tcx>, _: HirId) {
impl<'tcx> LateLintPass<'tcx> for TyTyKind {
fn check_path(&mut self, cx: &LateContext<'_>, path: &'tcx Path<'tcx>, _: HirId) {
let segments = path.segments.iter().rev().skip(1).rev();
if let Some(last) = segments.last() {
@ -105,7 +105,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
}
}
fn check_ty(&mut self, cx: &LateContext<'_, '_>, ty: &'tcx Ty<'tcx>) {
fn check_ty(&mut self, cx: &LateContext<'_>, ty: &'tcx Ty<'tcx>) {
match &ty.kind {
TyKind::Path(qpath) => {
if let QPath::Resolved(_, path) = qpath {
@ -164,7 +164,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
}
}
fn lint_ty_kind_usage(cx: &LateContext<'_, '_>, segment: &PathSegment<'_>) -> bool {
fn lint_ty_kind_usage(cx: &LateContext<'_>, segment: &PathSegment<'_>) -> bool {
if let Some(res) = segment.res {
if let Some(did) = res.opt_def_id() {
return cx.tcx.is_diagnostic_item(sym::TyKind, did);
@ -174,7 +174,7 @@ fn lint_ty_kind_usage(cx: &LateContext<'_, '_>, segment: &PathSegment<'_>) -> bo
false
}
fn is_ty_or_ty_ctxt(cx: &LateContext<'_, '_>, ty: &Ty<'_>) -> Option<String> {
fn is_ty_or_ty_ctxt(cx: &LateContext<'_>, ty: &Ty<'_>) -> Option<String> {
if let TyKind::Path(qpath) = &ty.kind {
if let QPath::Resolved(_, path) = qpath {
let did = path.res.opt_def_id()?;

View file

@ -44,12 +44,12 @@ macro_rules! lint_callback { ($cx:expr, $f:ident, $($args:expr),*) => ({
$cx.pass.$f(&$cx.context, $($args),*);
}) }
struct LateContextAndPass<'a, 'tcx, T: LateLintPass<'a, 'tcx>> {
context: LateContext<'a, 'tcx>,
struct LateContextAndPass<'tcx, T: LateLintPass<'tcx>> {
context: LateContext<'tcx>,
pass: T,
}
impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> LateContextAndPass<'a, 'tcx, T> {
impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> {
/// Merge the lints specified by any lint attributes into the
/// current lint context, call the provided function, then reset the
/// lints in effect to their previous state.
@ -93,9 +93,7 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> LateContextAndPass<'a, 'tcx, T> {
}
}
impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> hir_visit::Visitor<'tcx>
for LateContextAndPass<'a, 'tcx, T>
{
impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPass<'tcx, T> {
type Map = Map<'tcx>;
/// Because lints are scoped lexically, we want to walk nested
@ -348,8 +346,8 @@ impl LintPass for LateLintPassObjects<'_> {
}
macro_rules! expand_late_lint_pass_impl_methods {
([$a:tt, $hir:tt], [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
$(fn $name(&mut self, context: &LateContext<$a, $hir>, $($param: $arg),*) {
([$hir:tt], [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
$(fn $name(&mut self, context: &LateContext<$hir>, $($param: $arg),*) {
for obj in self.lints.iter_mut() {
obj.$name(context, $($param),*);
}
@ -358,16 +356,16 @@ macro_rules! expand_late_lint_pass_impl_methods {
}
macro_rules! late_lint_pass_impl {
([], [$hir:tt], $methods:tt) => (
impl<'a, $hir> LateLintPass<'a, $hir> for LateLintPassObjects<'_> {
expand_late_lint_pass_impl_methods!(['a, $hir], $methods);
([], [$hir:tt], $methods:tt) => {
impl<$hir> LateLintPass<$hir> for LateLintPassObjects<'_> {
expand_late_lint_pass_impl_methods!([$hir], $methods);
}
)
};
}
crate::late_lint_methods!(late_lint_pass_impl, [], ['tcx]);
fn late_lint_mod_pass<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
fn late_lint_mod_pass<'tcx, T: LateLintPass<'tcx>>(
tcx: TyCtxt<'tcx>,
module_def_id: LocalDefId,
pass: T,
@ -397,7 +395,7 @@ fn late_lint_mod_pass<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
}
}
pub fn late_lint_mod<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx>>(
tcx: TyCtxt<'tcx>,
module_def_id: LocalDefId,
builtin_lints: T,
@ -417,7 +415,7 @@ pub fn late_lint_mod<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
}
}
fn late_lint_pass_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(tcx: TyCtxt<'tcx>, pass: T) {
fn late_lint_pass_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, pass: T) {
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
let krate = tcx.hir().krate();
@ -448,7 +446,7 @@ fn late_lint_pass_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(tcx: TyCtxt<'tc
})
}
fn late_lint_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(tcx: TyCtxt<'tcx>, builtin_lints: T) {
fn late_lint_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, builtin_lints: T) {
let mut passes = unerased_lint_store(tcx).late_passes.iter().map(|p| (p)()).collect::<Vec<_>>();
if !tcx.sess.opts.debugging_opts.no_interleave_lints {
@ -478,7 +476,7 @@ fn late_lint_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(tcx: TyCtxt<'tcx>, b
}
/// Performs lint checking on a crate.
pub fn check_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
pub fn check_crate<'tcx, T: LateLintPass<'tcx>>(
tcx: TyCtxt<'tcx>,
builtin_lints: impl FnOnce() -> T + Send,
) {

View file

@ -18,7 +18,7 @@ pub enum MethodLateContext {
PlainImpl,
}
pub fn method_context(cx: &LateContext<'_, '_>, id: hir::HirId) -> MethodLateContext {
pub fn method_context(cx: &LateContext<'_>, id: hir::HirId) -> MethodLateContext {
let def_id = cx.tcx.hir().local_def_id(id);
let item = cx.tcx.associated_item(def_id);
match item.container {
@ -200,7 +200,7 @@ impl NonSnakeCase {
}
/// Checks if a given identifier is snake case, and reports a diagnostic if not.
fn check_snake_case(&self, cx: &LateContext<'_, '_>, sort: &str, ident: &Ident) {
fn check_snake_case(&self, cx: &LateContext<'_>, sort: &str, ident: &Ident) {
fn is_snake_case(ident: &str) -> bool {
if ident.is_empty() {
return true;
@ -248,10 +248,10 @@ impl NonSnakeCase {
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
fn check_mod(
&mut self,
cx: &LateContext<'_, '_>,
cx: &LateContext<'_>,
_: &'tcx hir::Mod<'tcx>,
_: Span,
id: hir::HirId,
@ -300,7 +300,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
}
}
fn check_generic_param(&mut self, cx: &LateContext<'_, '_>, param: &hir::GenericParam<'_>) {
fn check_generic_param(&mut self, cx: &LateContext<'_>, param: &hir::GenericParam<'_>) {
if let GenericParamKind::Lifetime { .. } = param.kind {
self.check_snake_case(cx, "lifetime", &param.name.ident());
}
@ -308,7 +308,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
fn check_fn(
&mut self,
cx: &LateContext<'_, '_>,
cx: &LateContext<'_>,
fk: FnKind<'_>,
_: &hir::FnDecl<'_>,
_: &hir::Body<'_>,
@ -336,13 +336,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
}
}
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) {
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
if let hir::ItemKind::Mod(_) = it.kind {
self.check_snake_case(cx, "module", &it.ident);
}
}
fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::TraitItem<'_>) {
fn check_trait_item(&mut self, cx: &LateContext<'_>, item: &hir::TraitItem<'_>) {
if let hir::TraitItemKind::Fn(_, hir::TraitFn::Required(pnames)) = item.kind {
self.check_snake_case(cx, "trait method", &item.ident);
for param_name in pnames {
@ -351,7 +351,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
}
}
fn check_pat(&mut self, cx: &LateContext<'_, '_>, p: &hir::Pat<'_>) {
fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) {
if let &PatKind::Binding(_, hid, ident, _) = &p.kind {
if let hir::Node::Pat(parent_pat) = cx.tcx.hir().get(cx.tcx.hir().get_parent_node(hid))
{
@ -370,7 +370,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
}
}
fn check_struct_def(&mut self, cx: &LateContext<'_, '_>, s: &hir::VariantData<'_>) {
fn check_struct_def(&mut self, cx: &LateContext<'_>, s: &hir::VariantData<'_>) {
for sf in s.fields() {
self.check_snake_case(cx, "structure field", &sf.ident);
}
@ -386,7 +386,7 @@ declare_lint! {
declare_lint_pass!(NonUpperCaseGlobals => [NON_UPPER_CASE_GLOBALS]);
impl NonUpperCaseGlobals {
fn check_upper_case(cx: &LateContext<'_, '_>, sort: &str, ident: &Ident) {
fn check_upper_case(cx: &LateContext<'_>, sort: &str, ident: &Ident) {
let name = &ident.name.as_str();
if name.chars().any(|c| c.is_lowercase()) {
cx.struct_span_lint(NON_UPPER_CASE_GLOBALS, ident.span, |lint| {
@ -404,8 +404,8 @@ impl NonUpperCaseGlobals {
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) {
impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
match it.kind {
hir::ItemKind::Static(..) if !attr::contains_name(&it.attrs, sym::no_mangle) => {
NonUpperCaseGlobals::check_upper_case(cx, "static variable", &it.ident);
@ -417,19 +417,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
}
}
fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, ti: &hir::TraitItem<'_>) {
fn check_trait_item(&mut self, cx: &LateContext<'_>, ti: &hir::TraitItem<'_>) {
if let hir::TraitItemKind::Const(..) = ti.kind {
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", &ti.ident);
}
}
fn check_impl_item(&mut self, cx: &LateContext<'_, '_>, ii: &hir::ImplItem<'_>) {
fn check_impl_item(&mut self, cx: &LateContext<'_>, ii: &hir::ImplItem<'_>) {
if let hir::ImplItemKind::Const(..) = ii.kind {
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", &ii.ident);
}
}
fn check_pat(&mut self, cx: &LateContext<'_, '_>, p: &hir::Pat<'_>) {
fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) {
// Lint for constants that look like binding identifiers (#7526)
if let PatKind::Path(hir::QPath::Resolved(None, ref path)) = p.kind {
if let Res::Def(DefKind::Const, _) = path.res {
@ -444,7 +444,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
}
}
fn check_generic_param(&mut self, cx: &LateContext<'_, '_>, param: &hir::GenericParam<'_>) {
fn check_generic_param(&mut self, cx: &LateContext<'_>, param: &hir::GenericParam<'_>) {
if let GenericParamKind::Const { .. } = param.kind {
NonUpperCaseGlobals::check_upper_case(cx, "const parameter", &param.name.ident());
}

View file

@ -90,15 +90,15 @@ macro_rules! expand_lint_pass_methods {
macro_rules! declare_late_lint_pass {
([], [$hir:tt], [$($methods:tt)*]) => (
pub trait LateLintPass<'a, $hir>: LintPass {
expand_lint_pass_methods!(&LateContext<'a, $hir>, [$($methods)*]);
pub trait LateLintPass<$hir>: LintPass {
expand_lint_pass_methods!(&LateContext<$hir>, [$($methods)*]);
}
)
}
late_lint_methods!(declare_late_lint_pass, [], ['tcx]);
impl LateLintPass<'_, '_> for HardwiredLints {}
impl LateLintPass<'_> for HardwiredLints {}
#[macro_export]
macro_rules! expand_combined_late_lint_pass_method {
@ -110,7 +110,7 @@ macro_rules! expand_combined_late_lint_pass_method {
#[macro_export]
macro_rules! expand_combined_late_lint_pass_methods {
($passes:tt, [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
$(fn $name(&mut self, context: &LateContext<'a, 'tcx>, $($param: $arg),*) {
$(fn $name(&mut self, context: &LateContext<'tcx>, $($param: $arg),*) {
expand_combined_late_lint_pass_method!($passes, self, $name, (context, $($param),*));
})*
)
@ -138,7 +138,7 @@ macro_rules! declare_combined_late_lint_pass {
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for $name {
impl<'tcx> LateLintPass<'tcx> for $name {
expand_combined_late_lint_pass_methods!([$($passes),*], $methods);
}
@ -282,4 +282,4 @@ macro_rules! declare_combined_early_lint_pass {
/// A lint pass boxed up as a trait object.
pub type EarlyLintPassObject = Box<dyn EarlyLintPass + sync::Send + sync::Sync + 'static>;
pub type LateLintPassObject =
Box<dyn for<'a, 'tcx> LateLintPass<'a, 'tcx> + sync::Send + sync::Sync + 'static>;
Box<dyn for<'tcx> LateLintPass<'tcx> + sync::Send + sync::Sync + 'static>;

View file

@ -55,8 +55,8 @@ impl TypeLimits {
/// Attempts to special-case the overflowing literal lint when it occurs as a range endpoint.
/// Returns `true` iff the lint was overridden.
fn lint_overflowing_range_endpoint<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
fn lint_overflowing_range_endpoint<'tcx>(
cx: &LateContext<'tcx>,
lit: &hir::Lit,
lit_val: u128,
max: u128,
@ -127,7 +127,7 @@ fn uint_ty_range(uint_ty: ast::UintTy) -> (u128, u128) {
}
}
fn get_bin_hex_repr(cx: &LateContext<'_, '_>, lit: &hir::Lit) -> Option<String> {
fn get_bin_hex_repr(cx: &LateContext<'_>, lit: &hir::Lit) -> Option<String> {
let src = cx.sess().source_map().span_to_snippet(lit.span).ok()?;
let firstch = src.chars().next()?;
@ -142,7 +142,7 @@ fn get_bin_hex_repr(cx: &LateContext<'_, '_>, lit: &hir::Lit) -> Option<String>
}
fn report_bin_hex_error(
cx: &LateContext<'_, '_>,
cx: &LateContext<'_>,
expr: &hir::Expr<'_>,
ty: attr::IntType,
repr_str: String,
@ -233,8 +233,8 @@ fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<&'static
}
}
fn lint_int_literal<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
fn lint_int_literal<'tcx>(
cx: &LateContext<'tcx>,
type_limits: &TypeLimits,
e: &'tcx hir::Expr<'tcx>,
lit: &hir::Lit,
@ -283,8 +283,8 @@ fn lint_int_literal<'a, 'tcx>(
}
}
fn lint_uint_literal<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
fn lint_uint_literal<'tcx>(
cx: &LateContext<'tcx>,
e: &'tcx hir::Expr<'tcx>,
lit: &hir::Lit,
t: ast::UintTy,
@ -347,8 +347,8 @@ fn lint_uint_literal<'a, 'tcx>(
}
}
fn lint_literal<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
fn lint_literal<'tcx>(
cx: &LateContext<'tcx>,
type_limits: &TypeLimits,
e: &'tcx hir::Expr<'tcx>,
lit: &hir::Lit,
@ -391,8 +391,8 @@ fn lint_literal<'a, 'tcx>(
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx hir::Expr<'tcx>) {
impl<'tcx> LateLintPass<'tcx> for TypeLimits {
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx hir::Expr<'tcx>) {
match e.kind {
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref expr) => {
// propagate negation, if the negation itself isn't negated
@ -436,7 +436,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits {
}
fn check_limits(
cx: &LateContext<'_, '_>,
cx: &LateContext<'_>,
binop: hir::BinOp,
l: &hir::Expr<'_>,
r: &hir::Expr<'_>,
@ -515,7 +515,7 @@ enum ImproperCTypesMode {
}
struct ImproperCTypesVisitor<'a, 'tcx> {
cx: &'a LateContext<'a, 'tcx>,
cx: &'a LateContext<'tcx>,
mode: ImproperCTypesMode,
}
@ -939,7 +939,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
fn check_for_opaque_ty(&mut self, sp: Span, ty: Ty<'tcx>) -> bool {
struct ProhibitOpaqueTypes<'a, 'tcx> {
cx: &'a LateContext<'a, 'tcx>,
cx: &'a LateContext<'tcx>,
ty: Option<Ty<'tcx>>,
};
@ -1050,8 +1050,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypesDeclarations {
fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::ForeignItem<'_>) {
impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDeclarations {
fn check_foreign_item(&mut self, cx: &LateContext<'_>, it: &hir::ForeignItem<'_>) {
let mut vis = ImproperCTypesVisitor { cx, mode: ImproperCTypesMode::Declarations };
let abi = cx.tcx.hir().get_foreign_abi(it.hir_id);
@ -1069,10 +1069,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypesDeclarations {
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypesDefinitions {
impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDefinitions {
fn check_fn(
&mut self,
cx: &LateContext<'a, 'tcx>,
cx: &LateContext<'tcx>,
kind: hir::intravisit::FnKind<'tcx>,
decl: &'tcx hir::FnDecl<'_>,
_: &'tcx hir::Body<'_>,
@ -1096,8 +1096,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypesDefinitions {
declare_lint_pass!(VariantSizeDifferences => [VARIANT_SIZE_DIFFERENCES]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences {
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) {
impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences {
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
if let hir::ItemKind::Enum(ref enum_definition, _) = it.kind {
let item_def_id = cx.tcx.hir().local_def_id(it.hir_id);
let t = cx.tcx.type_of(item_def_id);

View file

@ -35,8 +35,8 @@ declare_lint! {
declare_lint_pass!(UnusedResults => [UNUSED_MUST_USE, UNUSED_RESULTS]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt<'_>) {
impl<'tcx> LateLintPass<'tcx> for UnusedResults {
fn check_stmt(&mut self, cx: &LateContext<'_>, s: &hir::Stmt<'_>) {
let expr = match s.kind {
hir::StmtKind::Semi(ref expr) => &**expr,
_ => return,
@ -116,7 +116,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
// Returns whether an error has been emitted (and thus another does not need to be later).
fn check_must_use_ty<'tcx>(
cx: &LateContext<'_, 'tcx>,
cx: &LateContext<'tcx>,
ty: Ty<'tcx>,
expr: &hir::Expr<'_>,
span: Span,
@ -213,7 +213,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
// this would still require a copy into the format string, which would only be executed
// when needed.
fn check_must_use_def(
cx: &LateContext<'_, '_>,
cx: &LateContext<'_>,
def_id: DefId,
span: Span,
descr_pre_path: &str,
@ -251,8 +251,8 @@ declare_lint! {
declare_lint_pass!(PathStatements => [PATH_STATEMENTS]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathStatements {
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt<'_>) {
impl<'tcx> LateLintPass<'tcx> for PathStatements {
fn check_stmt(&mut self, cx: &LateContext<'_>, s: &hir::Stmt<'_>) {
if let hir::StmtKind::Semi(ref expr) = s.kind {
if let hir::ExprKind::Path(_) = expr.kind {
cx.struct_span_lint(PATH_STATEMENTS, s.span, |lint| {
@ -276,8 +276,8 @@ impl UnusedAttributes {
impl_lint_pass!(UnusedAttributes => [UNUSED_ATTRIBUTES]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
fn check_attribute(&mut self, cx: &LateContext<'_, '_>, attr: &ast::Attribute) {
impl<'tcx> LateLintPass<'tcx> for UnusedAttributes {
fn check_attribute(&mut self, cx: &LateContext<'_>, attr: &ast::Attribute) {
debug!("checking attribute: {:?}", attr);
if attr.is_doc_comment() {
@ -943,8 +943,8 @@ declare_lint! {
declare_lint_pass!(UnusedAllocation => [UNUSED_ALLOCATION]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAllocation {
fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for UnusedAllocation {
fn check_expr(&mut self, cx: &LateContext<'_>, e: &hir::Expr<'_>) {
match e.kind {
hir::ExprKind::Box(_) => {}
_ => return,

View file

@ -1123,16 +1123,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
match target {
Some(b) => self.propagate_through_opt_expr(opt_expr.as_ref().map(|e| &**e), b),
None => {
// FIXME: This should have been checked earlier. Once this is fixed,
// replace with `delay_span_bug`. (#62480)
self.ir
.tcx
.sess
.struct_span_err(expr.span, "`break` to unknown label")
.emit();
rustc_errors::FatalError.raise()
}
None => span_bug!(expr.span, "`break` to unknown label"),
}
}

View file

@ -331,12 +331,12 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
}
}
struct MissingStabilityAnnotations<'a, 'tcx> {
struct MissingStabilityAnnotations<'tcx> {
tcx: TyCtxt<'tcx>,
access_levels: &'a AccessLevels,
access_levels: &'tcx AccessLevels,
}
impl<'a, 'tcx> MissingStabilityAnnotations<'a, 'tcx> {
impl<'tcx> MissingStabilityAnnotations<'tcx> {
fn check_missing_stability(&self, hir_id: HirId, span: Span) {
let stab = self.tcx.stability().local_stability(hir_id);
let is_error =
@ -349,7 +349,7 @@ impl<'a, 'tcx> MissingStabilityAnnotations<'a, 'tcx> {
}
}
impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> {
impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
type Map = Map<'tcx>;
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {

View file

@ -33,6 +33,10 @@ type Res = def::Res<ast::NodeId>;
/// A vector of spans and replacements, a message and applicability.
crate type Suggestion = (Vec<(Span, String)>, String, Applicability);
/// Potential candidate for an undeclared or out-of-scope label - contains the ident of a
/// similarly named label and whether or not it is reachable.
crate type LabelSuggestion = (Ident, bool);
crate struct TypoSuggestion {
pub candidate: Symbol,
pub res: Res,
@ -282,7 +286,7 @@ impl<'a> Resolver<'a> {
err.span_label(span, "used in a pattern more than once");
err
}
ResolutionError::UndeclaredLabel(name, lev_candidate) => {
ResolutionError::UndeclaredLabel { name, suggestion } => {
let mut err = struct_span_err!(
self.session,
span,
@ -290,16 +294,31 @@ impl<'a> Resolver<'a> {
"use of undeclared label `{}`",
name
);
if let Some(lev_candidate) = lev_candidate {
err.span_suggestion(
span,
"a label with a similar name exists in this scope",
lev_candidate.to_string(),
Applicability::MaybeIncorrect,
);
} else {
err.span_label(span, format!("undeclared label `{}`", name));
err.span_label(span, format!("undeclared label `{}`", name));
match suggestion {
// A reachable label with a similar name exists.
Some((ident, true)) => {
err.span_label(ident.span, "a label with a similar name is reachable");
err.span_suggestion(
span,
"try using similarly named label",
ident.name.to_string(),
Applicability::MaybeIncorrect,
);
}
// An unreachable label with a similar name exists.
Some((ident, false)) => {
err.span_label(
ident.span,
"a label with a similar name exists but is unreachable",
);
}
// No similarly-named labels exist.
None => (),
}
err
}
ResolutionError::SelfImportsOnlyAllowedWithin { root, span_with_rename } => {
@ -433,6 +452,45 @@ impl<'a> Resolver<'a> {
err.span_label(span, "`Self` in type parameter default".to_string());
err
}
ResolutionError::UnreachableLabel { name, definition_span, suggestion } => {
let mut err = struct_span_err!(
self.session,
span,
E0767,
"use of unreachable label `{}`",
name,
);
err.span_label(definition_span, "unreachable label defined here");
err.span_label(span, format!("unreachable label `{}`", name));
err.note(
"labels are unreachable through functions, closures, async blocks and modules",
);
match suggestion {
// A reachable label with a similar name exists.
Some((ident, true)) => {
err.span_label(ident.span, "a label with a similar name is reachable");
err.span_suggestion(
span,
"try using similarly named label",
ident.name.to_string(),
Applicability::MaybeIncorrect,
);
}
// An unreachable label with a similar name exists.
Some((ident, false)) => {
err.span_label(
ident.span,
"a label with a similar name exists but is also unreachable",
);
}
// No similarly-named labels exist.
None => (),
}
err
}
}
}

View file

@ -13,7 +13,6 @@ use crate::{ResolutionError, Resolver, Segment, UseError};
use rustc_ast::ast::*;
use rustc_ast::ptr::P;
use rustc_ast::util::lev_distance::find_best_match_for_name;
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
use rustc_ast::{unwrap_or, walk_list};
use rustc_ast_lowering::ResolverAstLowering;
@ -101,6 +100,9 @@ crate enum RibKind<'a> {
/// upvars).
AssocItemRibKind,
/// We passed through a closure. Disallow labels.
ClosureOrAsyncRibKind,
/// We passed through a function definition. Disallow upvars.
/// Permit only those const parameters that are specified in the function's generics.
FnItemRibKind,
@ -124,11 +126,15 @@ crate enum RibKind<'a> {
}
impl RibKind<'_> {
// Whether this rib kind contains generic parameters, as opposed to local
// variables.
/// Whether this rib kind contains generic parameters, as opposed to local
/// variables.
crate fn contains_params(&self) -> bool {
match self {
NormalRibKind | FnItemRibKind | ConstantItemRibKind | ModuleRibKind(_)
NormalRibKind
| ClosureOrAsyncRibKind
| FnItemRibKind
| ConstantItemRibKind
| ModuleRibKind(_)
| MacroDefinition(_) => false,
AssocItemRibKind | ItemRibKind(_) | ForwardTyParamBanRibKind => true,
}
@ -474,7 +480,8 @@ impl<'a, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
// Bail if there's no body.
FnKind::Fn(.., None) => return visit::walk_fn(self, fn_kind, sp),
FnKind::Fn(FnCtxt::Free | FnCtxt::Foreign, ..) => FnItemRibKind,
FnKind::Fn(FnCtxt::Assoc(_), ..) | FnKind::Closure(..) => NormalRibKind,
FnKind::Fn(FnCtxt::Assoc(_), ..) => NormalRibKind,
FnKind::Closure(..) => ClosureOrAsyncRibKind,
};
let previous_value =
replace(&mut self.diagnostic_metadata.current_function, Some((fn_kind, sp)));
@ -725,35 +732,79 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
}
}
/// Searches the current set of local scopes for labels. Returns the first non-`None` label that
/// is returned by the given predicate function
///
/// Stops after meeting a closure.
fn search_label<P, R>(&self, mut ident: Ident, pred: P) -> Option<R>
where
P: Fn(&Rib<'_, NodeId>, Ident) -> Option<R>,
{
for rib in self.label_ribs.iter().rev() {
match rib.kind {
NormalRibKind => {}
/// Searches the current set of local scopes for labels. Returns the `NodeId` of the resolved
/// label and reports an error if the label is not found or is unreachable.
fn resolve_label(&self, mut label: Ident) -> Option<NodeId> {
let mut suggestion = None;
// Preserve the original span so that errors contain "in this macro invocation"
// information.
let original_span = label.span;
for i in (0..self.label_ribs.len()).rev() {
let rib = &self.label_ribs[i];
if let MacroDefinition(def) = rib.kind {
// If an invocation of this macro created `ident`, give up on `ident`
// and switch to `ident`'s source from the macro definition.
MacroDefinition(def) => {
if def == self.r.macro_def(ident.span.ctxt()) {
ident.span.remove_mark();
}
}
_ => {
// Do not resolve labels across function boundary
return None;
if def == self.r.macro_def(label.span.ctxt()) {
label.span.remove_mark();
}
}
let r = pred(rib, ident);
if r.is_some() {
return r;
let ident = label.normalize_to_macro_rules();
if let Some((ident, id)) = rib.bindings.get_key_value(&ident) {
return if self.is_label_valid_from_rib(i) {
Some(*id)
} else {
self.r.report_error(
original_span,
ResolutionError::UnreachableLabel {
name: &label.name.as_str(),
definition_span: ident.span,
suggestion,
},
);
None
};
}
// Diagnostics: Check if this rib contains a label with a similar name, keep track of
// the first such label that is encountered.
suggestion = suggestion.or_else(|| self.suggestion_for_label_in_rib(i, label));
}
self.r.report_error(
original_span,
ResolutionError::UndeclaredLabel { name: &label.name.as_str(), suggestion },
);
None
}
/// Determine whether or not a label from the `rib_index`th label rib is reachable.
fn is_label_valid_from_rib(&self, rib_index: usize) -> bool {
let ribs = &self.label_ribs[rib_index + 1..];
for rib in ribs {
match rib.kind {
NormalRibKind | MacroDefinition(..) => {
// Nothing to do. Continue.
}
AssocItemRibKind
| ClosureOrAsyncRibKind
| FnItemRibKind
| ItemRibKind(..)
| ConstantItemRibKind
| ModuleRibKind(..)
| ForwardTyParamBanRibKind => {
return false;
}
}
}
None
true
}
fn resolve_adt(&mut self, item: &'ast Item, generics: &'ast Generics) {
@ -2044,35 +2095,10 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
}
ExprKind::Break(Some(label), _) | ExprKind::Continue(Some(label)) => {
let node_id = self.search_label(label.ident, |rib, ident| {
rib.bindings.get(&ident.normalize_to_macro_rules()).cloned()
});
match node_id {
None => {
// Search again for close matches...
// Picks the first label that is "close enough", which is not necessarily
// the closest match
let close_match = self.search_label(label.ident, |rib, ident| {
let names = rib.bindings.iter().filter_map(|(id, _)| {
if id.span.ctxt() == label.ident.span.ctxt() {
Some(&id.name)
} else {
None
}
});
find_best_match_for_name(names, &ident.as_str(), None)
});
self.r.record_partial_res(expr.id, PartialRes::new(Res::Err));
self.r.report_error(
label.ident.span,
ResolutionError::UndeclaredLabel(&label.ident.as_str(), close_match),
);
}
Some(node_id) => {
// Since this res is a label, it is never read.
self.r.label_res_map.insert(expr.id, node_id);
self.diagnostic_metadata.unused_labels.remove(&node_id);
}
if let Some(node_id) = self.resolve_label(label.ident) {
// Since this res is a label, it is never read.
self.r.label_res_map.insert(expr.id, node_id);
self.diagnostic_metadata.unused_labels.remove(&node_id);
}
// visit `break` argument if any
@ -2144,21 +2170,26 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
// closure are detected as upvars rather than normal closure arg usages.
ExprKind::Closure(_, Async::Yes { .. }, _, ref fn_decl, ref body, _span) => {
self.with_rib(ValueNS, NormalRibKind, |this| {
// Resolve arguments:
this.resolve_params(&fn_decl.inputs);
// No need to resolve return type --
// the outer closure return type is `FnRetTy::Default`.
this.with_label_rib(ClosureOrAsyncRibKind, |this| {
// Resolve arguments:
this.resolve_params(&fn_decl.inputs);
// No need to resolve return type --
// the outer closure return type is `FnRetTy::Default`.
// Now resolve the inner closure
{
// No need to resolve arguments: the inner closure has none.
// Resolve the return type:
visit::walk_fn_ret_ty(this, &fn_decl.output);
// Resolve the body
this.visit_expr(body);
}
// Now resolve the inner closure
{
// No need to resolve arguments: the inner closure has none.
// Resolve the return type:
visit::walk_fn_ret_ty(this, &fn_decl.output);
// Resolve the body
this.visit_expr(body);
}
})
});
}
ExprKind::Async(..) | ExprKind::Closure(..) => {
self.with_label_rib(ClosureOrAsyncRibKind, |this| visit::walk_expr(this, expr));
}
_ => {
visit::walk_expr(self, expr);
}

View file

@ -1,4 +1,4 @@
use crate::diagnostics::{ImportSuggestion, TypoSuggestion};
use crate::diagnostics::{ImportSuggestion, LabelSuggestion, TypoSuggestion};
use crate::late::lifetimes::{ElisionFailureInfo, LifetimeContext};
use crate::late::{LateResolutionVisitor, RibKind};
use crate::path_names_to_string;
@ -992,6 +992,32 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
}
None
}
/// Given the target `label`, search the `rib_index`th label rib for similarly named labels,
/// optionally returning the closest match and whether it is reachable.
crate fn suggestion_for_label_in_rib(
&self,
rib_index: usize,
label: Ident,
) -> Option<LabelSuggestion> {
// Are ribs from this `rib_index` within scope?
let within_scope = self.is_label_valid_from_rib(rib_index);
let rib = &self.label_ribs[rib_index];
let names = rib
.bindings
.iter()
.filter(|(id, _)| id.span.ctxt() == label.span.ctxt())
.map(|(id, _)| &id.name);
find_best_match_for_name(names, &label.as_str(), None).map(|symbol| {
// Upon finding a similar name, get the ident that it was from - the span
// contained within helps make a useful diagnostic. In addition, determine
// whether this candidate is within scope.
let (ident, _) = rib.bindings.iter().find(|(ident, _)| ident.name == symbol).unwrap();
(*ident, within_scope)
})
}
}
impl<'tcx> LifetimeContext<'_, 'tcx> {

View file

@ -61,7 +61,7 @@ use std::collections::BTreeSet;
use std::{cmp, fmt, iter, ptr};
use diagnostics::{extend_span_to_previous_binding, find_span_of_binding_until_next_binding};
use diagnostics::{ImportSuggestion, Suggestion};
use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion};
use imports::{Import, ImportKind, ImportResolver, NameResolution};
use late::{HasGenericParams, PathSource, Rib, RibKind::*};
use macros::{MacroRulesBinding, MacroRulesScope};
@ -197,7 +197,7 @@ enum ResolutionError<'a> {
/// Error E0416: identifier is bound more than once in the same pattern.
IdentifierBoundMoreThanOnceInSamePattern(&'a str),
/// Error E0426: use of undeclared label.
UndeclaredLabel(&'a str, Option<Symbol>),
UndeclaredLabel { name: &'a str, suggestion: Option<LabelSuggestion> },
/// Error E0429: `self` imports are only allowed within a `{ }` list.
SelfImportsOnlyAllowedWithin { root: bool, span_with_rename: Span },
/// Error E0430: `self` import can only appear once in the list.
@ -216,6 +216,8 @@ enum ResolutionError<'a> {
ForwardDeclaredTyParam, // FIXME(const_generics:defaults)
/// Error E0735: type parameters with a default cannot use `Self`
SelfInTyParamDefault,
/// Error E0767: use of unreachable label
UnreachableLabel { name: &'a str, definition_span: Span, suggestion: Option<LabelSuggestion> },
}
enum VisResolutionError<'a> {
@ -2453,6 +2455,7 @@ impl<'a> Resolver<'a> {
for rib in ribs {
match rib.kind {
NormalRibKind
| ClosureOrAsyncRibKind
| ModuleRibKind(..)
| MacroDefinition(..)
| ForwardTyParamBanRibKind => {
@ -2488,6 +2491,7 @@ impl<'a> Resolver<'a> {
for rib in ribs {
let has_generic_params = match rib.kind {
NormalRibKind
| ClosureOrAsyncRibKind
| AssocItemRibKind
| ModuleRibKind(..)
| MacroDefinition(..)

View file

@ -72,12 +72,12 @@ macro_rules! access_from_vis {
};
}
pub struct DumpVisitor<'l, 'tcx> {
pub save_ctxt: SaveContext<'l, 'tcx>,
pub struct DumpVisitor<'tcx> {
pub save_ctxt: SaveContext<'tcx>,
tcx: TyCtxt<'tcx>,
dumper: Dumper,
span: SpanUtils<'l>,
span: SpanUtils<'tcx>,
// Set of macro definition (callee) spans, and the set
// of macro use (callsite) spans. We store these to ensure
// we only write one macro def per unique macro definition, and
@ -86,8 +86,8 @@ pub struct DumpVisitor<'l, 'tcx> {
// macro_calls: FxHashSet<Span>,
}
impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
pub fn new(save_ctxt: SaveContext<'l, 'tcx>) -> DumpVisitor<'l, 'tcx> {
impl<'tcx> DumpVisitor<'tcx> {
pub fn new(save_ctxt: SaveContext<'tcx>) -> DumpVisitor<'tcx> {
let span_utils = SpanUtils::new(&save_ctxt.tcx.sess);
let dumper = Dumper::new(save_ctxt.config.clone());
DumpVisitor {
@ -1160,7 +1160,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
}
}
impl<'l, 'tcx> Visitor<'tcx> for DumpVisitor<'l, 'tcx> {
impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
type Map = Map<'tcx>;
fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<Self::Map> {

View file

@ -48,10 +48,10 @@ use rls_data::{
use log::{debug, error, info};
pub struct SaveContext<'l, 'tcx: 'l> {
pub struct SaveContext<'tcx> {
tcx: TyCtxt<'tcx>,
maybe_typeck_tables: Option<&'tcx ty::TypeckTables<'tcx>>,
access_levels: &'l AccessLevels,
access_levels: &'tcx AccessLevels,
span_utils: SpanUtils<'tcx>,
config: Config,
impl_counter: Cell<u32>,
@ -64,7 +64,7 @@ pub enum Data {
RelationData(Relation, Impl),
}
impl<'l, 'tcx> SaveContext<'l, 'tcx> {
impl<'tcx> SaveContext<'tcx> {
/// Gets the type-checking side-tables for the current body.
/// As this will ICE if called outside bodies, only call when working with
/// `Expr` or `Pat` nodes (they are guaranteed to be found only in bodies).
@ -917,7 +917,7 @@ impl<'l> Visitor<'l> for PathCollector<'l> {
/// Defines what to do with the results of saving the analysis.
pub trait SaveHandler {
fn save(&mut self, save_ctxt: &SaveContext<'_, '_>, analysis: &Analysis);
fn save(&mut self, save_ctxt: &SaveContext<'_>, analysis: &Analysis);
}
/// Dump the save-analysis results to a file.
@ -931,7 +931,7 @@ impl<'a> DumpHandler<'a> {
DumpHandler { odir, cratename: cratename.to_owned() }
}
fn output_file(&self, ctx: &SaveContext<'_, '_>) -> (BufWriter<File>, PathBuf) {
fn output_file(&self, ctx: &SaveContext<'_>) -> (BufWriter<File>, PathBuf) {
let sess = &ctx.tcx.sess;
let file_name = match ctx.config.output_file {
Some(ref s) => PathBuf::from(s),
@ -967,7 +967,7 @@ impl<'a> DumpHandler<'a> {
}
impl SaveHandler for DumpHandler<'_> {
fn save(&mut self, save_ctxt: &SaveContext<'_, '_>, analysis: &Analysis) {
fn save(&mut self, save_ctxt: &SaveContext<'_>, analysis: &Analysis) {
let sess = &save_ctxt.tcx.sess;
let (output, file_name) = self.output_file(&save_ctxt);
if let Err(e) = serde_json::to_writer(output, &analysis) {
@ -986,7 +986,7 @@ pub struct CallbackHandler<'b> {
}
impl SaveHandler for CallbackHandler<'_> {
fn save(&mut self, _: &SaveContext<'_, '_>, analysis: &Analysis) {
fn save(&mut self, _: &SaveContext<'_>, analysis: &Analysis) {
(self.callback)(analysis)
}
}
@ -1065,7 +1065,7 @@ fn id_from_def_id(id: DefId) -> rls_data::Id {
rls_data::Id { krate: id.krate.as_u32(), index: id.index.as_u32() }
}
fn id_from_hir_id(id: hir::HirId, scx: &SaveContext<'_, '_>) -> rls_data::Id {
fn id_from_hir_id(id: hir::HirId, scx: &SaveContext<'_>) -> rls_data::Id {
let def_id = scx.tcx.hir().opt_local_def_id(id);
def_id.map(|id| id_from_def_id(id.to_def_id())).unwrap_or_else(|| {
// Create a *fake* `DefId` out of a `HirId` by combining the owner
@ -1083,10 +1083,7 @@ fn null_id() -> rls_data::Id {
rls_data::Id { krate: u32::MAX, index: u32::MAX }
}
fn lower_attributes(
attrs: Vec<ast::Attribute>,
scx: &SaveContext<'_, '_>,
) -> Vec<rls_data::Attribute> {
fn lower_attributes(attrs: Vec<ast::Attribute>, scx: &SaveContext<'_>) -> Vec<rls_data::Attribute> {
attrs
.into_iter()
// Only retain real attributes. Doc comments are lowered separately.

View file

@ -36,7 +36,7 @@ use rustc_hir_pretty::id_to_string;
use rustc_hir_pretty::{bounds_to_string, path_segment_to_string, path_to_string, ty_to_string};
use rustc_span::symbol::{Ident, Symbol};
pub fn item_signature(item: &hir::Item<'_>, scx: &SaveContext<'_, '_>) -> Option<Signature> {
pub fn item_signature(item: &hir::Item<'_>, scx: &SaveContext<'_>) -> Option<Signature> {
if !scx.config.signatures {
return None;
}
@ -45,7 +45,7 @@ pub fn item_signature(item: &hir::Item<'_>, scx: &SaveContext<'_, '_>) -> Option
pub fn foreign_item_signature(
item: &hir::ForeignItem<'_>,
scx: &SaveContext<'_, '_>,
scx: &SaveContext<'_>,
) -> Option<Signature> {
if !scx.config.signatures {
return None;
@ -55,10 +55,7 @@ pub fn foreign_item_signature(
/// Signature for a struct or tuple field declaration.
/// Does not include a trailing comma.
pub fn field_signature(
field: &hir::StructField<'_>,
scx: &SaveContext<'_, '_>,
) -> Option<Signature> {
pub fn field_signature(field: &hir::StructField<'_>, scx: &SaveContext<'_>) -> Option<Signature> {
if !scx.config.signatures {
return None;
}
@ -66,10 +63,7 @@ pub fn field_signature(
}
/// Does not include a trailing comma.
pub fn variant_signature(
variant: &hir::Variant<'_>,
scx: &SaveContext<'_, '_>,
) -> Option<Signature> {
pub fn variant_signature(variant: &hir::Variant<'_>, scx: &SaveContext<'_>) -> Option<Signature> {
if !scx.config.signatures {
return None;
}
@ -81,7 +75,7 @@ pub fn method_signature(
ident: Ident,
generics: &hir::Generics<'_>,
m: &hir::FnSig<'_>,
scx: &SaveContext<'_, '_>,
scx: &SaveContext<'_>,
) -> Option<Signature> {
if !scx.config.signatures {
return None;
@ -94,7 +88,7 @@ pub fn assoc_const_signature(
ident: Symbol,
ty: &hir::Ty<'_>,
default: Option<&hir::Expr<'_>>,
scx: &SaveContext<'_, '_>,
scx: &SaveContext<'_>,
) -> Option<Signature> {
if !scx.config.signatures {
return None;
@ -107,7 +101,7 @@ pub fn assoc_type_signature(
ident: Ident,
bounds: Option<hir::GenericBounds<'_>>,
default: Option<&hir::Ty<'_>>,
scx: &SaveContext<'_, '_>,
scx: &SaveContext<'_>,
) -> Option<Signature> {
if !scx.config.signatures {
return None;
@ -118,7 +112,7 @@ pub fn assoc_type_signature(
type Result = std::result::Result<Signature, &'static str>;
trait Sig {
fn make(&self, offset: usize, id: Option<hir::HirId>, scx: &SaveContext<'_, '_>) -> Result;
fn make(&self, offset: usize, id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result;
}
fn extend_sig(
@ -154,12 +148,7 @@ fn text_sig(text: String) -> Signature {
}
impl<'hir> Sig for hir::Ty<'hir> {
fn make(
&self,
offset: usize,
_parent_id: Option<hir::HirId>,
scx: &SaveContext<'_, '_>,
) -> Result {
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
let id = Some(self.hir_id);
match self.kind {
hir::TyKind::Slice(ref ty) => {
@ -334,12 +323,7 @@ impl<'hir> Sig for hir::Ty<'hir> {
}
impl<'hir> Sig for hir::Item<'hir> {
fn make(
&self,
offset: usize,
_parent_id: Option<hir::HirId>,
scx: &SaveContext<'_, '_>,
) -> Result {
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
let id = Some(self.hir_id);
match self.kind {
@ -574,7 +558,7 @@ impl<'hir> Sig for hir::Item<'hir> {
}
impl<'hir> Sig for hir::Path<'hir> {
fn make(&self, offset: usize, id: Option<hir::HirId>, scx: &SaveContext<'_, '_>) -> Result {
fn make(&self, offset: usize, id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
let res = scx.get_path_res(id.ok_or("Missing id for Path")?);
let (name, start, end) = match res {
@ -608,12 +592,7 @@ impl<'hir> Sig for hir::Path<'hir> {
// This does not cover the where clause, which must be processed separately.
impl<'hir> Sig for hir::Generics<'hir> {
fn make(
&self,
offset: usize,
_parent_id: Option<hir::HirId>,
scx: &SaveContext<'_, '_>,
) -> Result {
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
if self.params.is_empty() {
return Ok(text_sig(String::new()));
}
@ -671,12 +650,7 @@ impl<'hir> Sig for hir::Generics<'hir> {
}
impl<'hir> Sig for hir::StructField<'hir> {
fn make(
&self,
offset: usize,
_parent_id: Option<hir::HirId>,
scx: &SaveContext<'_, '_>,
) -> Result {
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
let mut text = String::new();
text.push_str(&self.ident.to_string());
@ -696,12 +670,7 @@ impl<'hir> Sig for hir::StructField<'hir> {
}
impl<'hir> Sig for hir::Variant<'hir> {
fn make(
&self,
offset: usize,
parent_id: Option<hir::HirId>,
scx: &SaveContext<'_, '_>,
) -> Result {
fn make(&self, offset: usize, parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
let mut text = self.ident.to_string();
match self.data {
hir::VariantData::Struct(fields, r) => {
@ -760,12 +729,7 @@ impl<'hir> Sig for hir::Variant<'hir> {
}
impl<'hir> Sig for hir::ForeignItem<'hir> {
fn make(
&self,
offset: usize,
_parent_id: Option<hir::HirId>,
scx: &SaveContext<'_, '_>,
) -> Result {
fn make(&self, offset: usize, _parent_id: Option<hir::HirId>, scx: &SaveContext<'_>) -> Result {
let id = Some(self.hir_id);
match self.kind {
hir::ForeignItemKind::Fn(decl, _, ref generics) => {
@ -839,7 +803,7 @@ fn name_and_generics(
generics: &hir::Generics<'_>,
id: hir::HirId,
name: Ident,
scx: &SaveContext<'_, '_>,
scx: &SaveContext<'_>,
) -> Result {
let name = name.to_string();
let def = SigElement {
@ -859,7 +823,7 @@ fn make_assoc_type_signature(
ident: Ident,
bounds: Option<hir::GenericBounds<'_>>,
default: Option<&hir::Ty<'_>>,
scx: &SaveContext<'_, '_>,
scx: &SaveContext<'_>,
) -> Result {
let mut text = "type ".to_owned();
let name = ident.to_string();
@ -891,7 +855,7 @@ fn make_assoc_const_signature(
ident: Symbol,
ty: &hir::Ty<'_>,
default: Option<&hir::Expr<'_>>,
scx: &SaveContext<'_, '_>,
scx: &SaveContext<'_>,
) -> Result {
let mut text = "const ".to_owned();
let name = ident.to_string();
@ -922,7 +886,7 @@ fn make_method_signature(
ident: Ident,
generics: &hir::Generics<'_>,
m: &hir::FnSig<'_>,
scx: &SaveContext<'_, '_>,
scx: &SaveContext<'_>,
) -> Result {
// FIXME code dup with function signature
let mut text = String::new();

View file

@ -517,6 +517,7 @@ symbols! {
None,
non_exhaustive,
non_modrs_mods,
nontrapping_fptoint: "nontrapping-fptoint",
noreturn,
no_niche,
no_sanitize,

View file

@ -0,0 +1,162 @@
// only-wasm32
// compile-flags: -C target-feature=+nontrapping-fptoint
#![crate_type = "lib"]
// CHECK-LABEL: @cast_f64_i64
#[no_mangle]
pub fn cast_f64_i64(a: f64) -> i64 {
// CHECK: tail call i64 @llvm.wasm.trunc.saturate.signed.i64.f64(double {{.*}})
// CHECK-NEXT: ret i64 {{.*}}
a as _
}
// CHECK-LABEL: @cast_f64_i32
#[no_mangle]
pub fn cast_f64_i32(a: f64) -> i32 {
// CHECK: tail call i32 @llvm.wasm.trunc.saturate.signed.i32.f64(double {{.*}})
// CHECK-NEXT: ret i32 {{.*}}
a as _
}
// CHECK-LABEL: @cast_f32_i64
#[no_mangle]
pub fn cast_f32_i64(a: f32) -> i64 {
// CHECK: tail call i64 @llvm.wasm.trunc.saturate.signed.i64.f32(float {{.*}})
// CHECK-NEXT: ret i64 {{.*}}
a as _
}
// CHECK-LABEL: @cast_f32_i32
#[no_mangle]
pub fn cast_f32_i32(a: f32) -> i32 {
// CHECK: tail call i32 @llvm.wasm.trunc.saturate.signed.i32.f32(float {{.*}})
// CHECK-NEXT: ret i32 {{.*}}
a as _
}
// CHECK-LABEL: @cast_f64_u64
#[no_mangle]
pub fn cast_f64_u64(a: f64) -> u64 {
// CHECK: tail call i64 @llvm.wasm.trunc.saturate.unsigned.i64.f64(double {{.*}})
// CHECK-NEXT: ret i64 {{.*}}
a as _
}
// CHECK-LABEL: @cast_f64_u32
#[no_mangle]
pub fn cast_f64_u32(a: f64) -> u32 {
// CHECK: tail call i32 @llvm.wasm.trunc.saturate.unsigned.i32.f64(double {{.*}})
// CHECK-NEXT: ret i32 {{.*}}
a as _
}
// CHECK-LABEL: @cast_f32_u64
#[no_mangle]
pub fn cast_f32_u64(a: f32) -> u64 {
// CHECK: tail call i64 @llvm.wasm.trunc.saturate.unsigned.i64.f32(float {{.*}})
// CHECK-NEXT: ret i64 {{.*}}
a as _
}
// CHECK-LABEL: @cast_f32_u32
#[no_mangle]
pub fn cast_f32_u32(a: f32) -> u32 {
// CHECK: tail call i32 @llvm.wasm.trunc.saturate.unsigned.i32.f32(float {{.*}})
// CHECK-NEXT: ret i32 {{.*}}
a as _
}
// CHECK-LABEL: @cast_f32_u8
#[no_mangle]
pub fn cast_f32_u8(a: f32) -> u8 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptoui float {{.*}} to i8
// CHECK-NEXT: select i1 {{.*}}, i8 {{.*}}, i8 {{.*}}
// CHECK-NEXT: ret i8 {{.*}}
a as _
}
// CHECK-LABEL: @cast_unchecked_f64_i64
#[no_mangle]
pub unsafe fn cast_unchecked_f64_i64(a: f64) -> i64 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptosi double {{.*}} to i64
// CHECK-NEXT: ret i64 {{.*}}
a.to_int_unchecked()
}
// CHECK-LABEL: @cast_unchecked_f64_i32
#[no_mangle]
pub unsafe fn cast_unchecked_f64_i32(a: f64) -> i32 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptosi double {{.*}} to i32
// CHECK-NEXT: ret i32 {{.*}}
a.to_int_unchecked()
}
// CHECK-LABEL: @cast_unchecked_f32_i64
#[no_mangle]
pub unsafe fn cast_unchecked_f32_i64(a: f32) -> i64 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptosi float {{.*}} to i64
// CHECK-NEXT: ret i64 {{.*}}
a.to_int_unchecked()
}
// CHECK-LABEL: @cast_unchecked_f32_i32
#[no_mangle]
pub unsafe fn cast_unchecked_f32_i32(a: f32) -> i32 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptosi float {{.*}} to i32
// CHECK-NEXT: ret i32 {{.*}}
a.to_int_unchecked()
}
// CHECK-LABEL: @cast_unchecked_f64_u64
#[no_mangle]
pub unsafe fn cast_unchecked_f64_u64(a: f64) -> u64 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptoui double {{.*}} to i64
// CHECK-NEXT: ret i64 {{.*}}
a.to_int_unchecked()
}
// CHECK-LABEL: @cast_unchecked_f64_u32
#[no_mangle]
pub unsafe fn cast_unchecked_f64_u32(a: f64) -> u32 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptoui double {{.*}} to i32
// CHECK-NEXT: ret i32 {{.*}}
a.to_int_unchecked()
}
// CHECK-LABEL: @cast_unchecked_f32_u64
#[no_mangle]
pub unsafe fn cast_unchecked_f32_u64(a: f32) -> u64 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptoui float {{.*}} to i64
// CHECK-NEXT: ret i64 {{.*}}
a.to_int_unchecked()
}
// CHECK-LABEL: @cast_unchecked_f32_u32
#[no_mangle]
pub unsafe fn cast_unchecked_f32_u32(a: f32) -> u32 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptoui float {{.*}} to i32
// CHECK-NEXT: ret i32 {{.*}}
a.to_int_unchecked()
}
// CHECK-LABEL: @cast_unchecked_f32_u8
#[no_mangle]
pub unsafe fn cast_unchecked_f32_u8(a: f32) -> u8 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptoui float {{.*}} to i8
// CHECK-NEXT: ret i8 {{.*}}
a.to_int_unchecked()
}

View file

@ -0,0 +1,169 @@
// only-wasm32
// compile-flags: -C target-feature=-nontrapping-fptoint
#![crate_type = "lib"]
// CHECK-LABEL: @cast_f64_i64
#[no_mangle]
pub fn cast_f64_i64(a: f64) -> i64 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptosi double {{.*}} to i64
// CHECK-NEXT: select i1 {{.*}}, i64 {{.*}}, i64 {{.*}}
a as _
}
// CHECK-LABEL: @cast_f64_i32
#[no_mangle]
pub fn cast_f64_i32(a: f64) -> i32 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptosi double {{.*}} to i32
// CHECK-NEXT: select i1 {{.*}}, i32 {{.*}}, i32 {{.*}}
a as _
}
// CHECK-LABEL: @cast_f32_i64
#[no_mangle]
pub fn cast_f32_i64(a: f32) -> i64 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptosi float {{.*}} to i64
// CHECK-NEXT: select i1 {{.*}}, i64 {{.*}}, i64 {{.*}}
a as _
}
// CHECK-LABEL: @cast_f32_i32
#[no_mangle]
pub fn cast_f32_i32(a: f32) -> i32 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptosi float {{.*}} to i32
// CHECK-NEXT: select i1 {{.*}}, i32 {{.*}}, i32 {{.*}}
a as _
}
// CHECK-LABEL: @cast_f64_u64
#[no_mangle]
pub fn cast_f64_u64(a: f64) -> u64 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptoui double {{.*}} to i64
// CHECK-NEXT: select i1 {{.*}}, i64 {{.*}}, i64 {{.*}}
a as _
}
// CHECK-LABEL: @cast_f64_u32
#[no_mangle]
pub fn cast_f64_u32(a: f64) -> u32 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptoui double {{.*}} to i32
// CHECK-NEXT: select i1 {{.*}}, i32 {{.*}}, i32 {{.*}}
a as _
}
// CHECK-LABEL: @cast_f32_u64
#[no_mangle]
pub fn cast_f32_u64(a: f32) -> u64 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptoui float {{.*}} to i64
// CHECK-NEXT: select i1 {{.*}}, i64 {{.*}}, i64 {{.*}}
a as _
}
// CHECK-LABEL: @cast_f32_u32
#[no_mangle]
pub fn cast_f32_u32(a: f32) -> u32 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptoui float {{.*}} to i32
// CHECK-NEXT: select i1 {{.*}}, i32 {{.*}}, i32 {{.*}}
a as _
}
// CHECK-LABEL: @cast_f32_u8
#[no_mangle]
pub fn cast_f32_u8(a: f32) -> u8 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptoui float {{.*}} to i8
// CHECK-NEXT: select i1 {{.*}}, i8 {{.*}}, i8 {{.*}}
a as _
}
// CHECK-LABEL: @cast_unchecked_f64_i64
#[no_mangle]
pub unsafe fn cast_unchecked_f64_i64(a: f64) -> i64 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptosi double {{.*}} to i64
// CHECK-NEXT: ret i64 {{.*}}
a.to_int_unchecked()
}
// CHECK-LABEL: @cast_unchecked_f64_i32
#[no_mangle]
pub unsafe fn cast_unchecked_f64_i32(a: f64) -> i32 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptosi double {{.*}} to i32
// CHECK-NEXT: ret i32 {{.*}}
a.to_int_unchecked()
}
// CHECK-LABEL: @cast_unchecked_f32_i64
#[no_mangle]
pub unsafe fn cast_unchecked_f32_i64(a: f32) -> i64 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptosi float {{.*}} to i64
// CHECK-NEXT: ret i64 {{.*}}
a.to_int_unchecked()
}
// CHECK-LABEL: @cast_unchecked_f32_i32
#[no_mangle]
pub unsafe fn cast_unchecked_f32_i32(a: f32) -> i32 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptosi float {{.*}} to i32
// CHECK-NEXT: ret i32 {{.*}}
a.to_int_unchecked()
}
// CHECK-LABEL: @cast_unchecked_f64_u64
#[no_mangle]
pub unsafe fn cast_unchecked_f64_u64(a: f64) -> u64 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptoui double {{.*}} to i64
// CHECK-NEXT: ret i64 {{.*}}
a.to_int_unchecked()
}
// CHECK-LABEL: @cast_unchecked_f64_u32
#[no_mangle]
pub unsafe fn cast_unchecked_f64_u32(a: f64) -> u32 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptoui double {{.*}} to i32
// CHECK-NEXT: ret i32 {{.*}}
a.to_int_unchecked()
}
// CHECK-LABEL: @cast_unchecked_f32_u64
#[no_mangle]
pub unsafe fn cast_unchecked_f32_u64(a: f32) -> u64 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptoui float {{.*}} to i64
// CHECK-NEXT: ret i64 {{.*}}
a.to_int_unchecked()
}
// CHECK-LABEL: @cast_unchecked_f32_u32
#[no_mangle]
pub unsafe fn cast_unchecked_f32_u32(a: f32) -> u32 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptoui float {{.*}} to i32
// CHECK-NEXT: ret i32 {{.*}}
a.to_int_unchecked()
}
// CHECK-LABEL: @cast_unchecked_f32_u8
#[no_mangle]
pub unsafe fn cast_unchecked_f32_u8(a: f32) -> u8 {
// CHECK-NOT: {{.*}} call {{.*}} @llvm.wasm.trunc.{{.*}}
// CHECK: fptoui float {{.*}} to i8
// CHECK-NEXT: ret i8 {{.*}}
a.to_int_unchecked()
}

View file

@ -33,10 +33,10 @@ declare_lint! {
declare_lint_pass!(MissingWhitelistedAttrPass => [MISSING_WHITELISTED_ATTR]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingWhitelistedAttrPass {
impl<'tcx> LateLintPass<'tcx> for MissingWhitelistedAttrPass {
fn check_fn(
&mut self,
cx: &LateContext<'a, 'tcx>,
cx: &LateContext<'tcx>,
_: intravisit::FnKind<'tcx>,
_: &'tcx hir::FnDecl,
_: &'tcx hir::Body,

View file

@ -26,7 +26,7 @@ macro_rules! fake_lint_pass {
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for $struct {
impl LateLintPass<'_> for $struct {
fn check_crate(&mut self, cx: &LateContext, krate: &rustc_hir::Crate) {
$(
if !attr::contains_name(&krate.item.attrs, $attr) {

View file

@ -25,7 +25,7 @@ declare_lint! {
declare_lint_pass!(Pass => [CRATE_NOT_OKAY]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
impl<'tcx> LateLintPass<'tcx> for Pass {
fn check_crate(&mut self, cx: &LateContext, krate: &rustc_hir::Crate) {
if !attr::contains_name(&krate.item.attrs, Symbol::intern("crate_okay")) {
cx.lint(CRATE_NOT_OKAY, |lint| {

View file

@ -20,7 +20,7 @@ declare_lint!(PLEASE_LINT, Warn, "Warn about items named 'pleaselintme'");
declare_lint_pass!(Pass => [TEST_LINT, PLEASE_LINT]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
impl<'tcx> LateLintPass<'tcx> for Pass {
fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) {
match &*it.ident.as_str() {
"lintme" => cx.lint(TEST_LINT, |lint| {

View file

@ -27,7 +27,9 @@ fn main() {
// not the `loop`, which failed in the call to `find_breakable`. (#65383)
'lab: loop {
|| {
break 'lab; //~ ERROR `break` inside of a closure
break 'lab;
//~^ ERROR use of unreachable label `'lab`
//~| ERROR `break` inside of a closure
};
}
}

View file

@ -1,3 +1,14 @@
error[E0767]: use of unreachable label `'lab`
--> $DIR/break-outside-loop.rs:30:19
|
LL | 'lab: loop {
| ---- unreachable label defined here
LL | || {
LL | break 'lab;
| ^^^^ unreachable label `'lab`
|
= note: labels are unreachable through functions, closures, async blocks and modules
error[E0268]: `break` outside of a loop
--> $DIR/break-outside-loop.rs:10:15
|
@ -41,7 +52,7 @@ LL | || {
LL | break 'lab;
| ^^^^^^^^^^ cannot `break` inside of a closure
error: aborting due to 6 previous errors
error: aborting due to 7 previous errors
Some errors have detailed explanations: E0267, E0268.
Some errors have detailed explanations: E0267, E0268, E0767.
For more information about an error, try `rustc --explain E0267`.

View file

@ -0,0 +1,7 @@
fn main () {
'a: loop {
|| {
loop { break 'a; } //~ ERROR E0767
}
}
}

View file

@ -0,0 +1,14 @@
error[E0767]: use of unreachable label `'a`
--> $DIR/E0767.rs:4:26
|
LL | 'a: loop {
| -- unreachable label defined here
LL | || {
LL | loop { break 'a; }
| ^^ unreachable label `'a`
|
= note: labels are unreachable through functions, closures, async blocks and modules
error: aborting due to previous error
For more information about this error, try `rustc --explain E0767`.

View file

@ -5,6 +5,8 @@ fn main() {
// `propagate_through_expr` would be the closure and not the `loop`, which wouldn't be found in
// `self.break_ln`. (#62480)
'a: {
|| break 'a //~ ERROR `break` to unknown label
|| break 'a
//~^ ERROR use of unreachable label `'a`
//~| ERROR `break` inside of a closure
}
}

View file

@ -1,8 +1,22 @@
error: `break` to unknown label
error[E0767]: use of unreachable label `'a`
--> $DIR/issue-62480.rs:8:18
|
LL | 'a: {
| -- unreachable label defined here
LL | || break 'a
| ^^ unreachable label `'a`
|
= note: labels are unreachable through functions, closures, async blocks and modules
error[E0267]: `break` inside of a closure
--> $DIR/issue-62480.rs:8:12
|
LL | || break 'a
| ^^^^^^^^
| -- ^^^^^^^^ cannot `break` inside of a closure
| |
| enclosing closure
error: aborting due to previous error
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0267, E0767.
For more information about an error, try `rustc --explain E0267`.

View file

@ -2,6 +2,8 @@
fn main() {
'some_label: loop {
|| break 'some_label (); //~ ERROR: `break` inside of a closure
|| break 'some_label ();
//~^ ERROR: use of unreachable label `'some_label`
//~| ERROR: `break` inside of a closure
}
}

View file

@ -1,3 +1,13 @@
error[E0767]: use of unreachable label `'some_label`
--> $DIR/issue-66702-break-outside-loop-val.rs:5:18
|
LL | 'some_label: loop {
| ----------- unreachable label defined here
LL | || break 'some_label ();
| ^^^^^^^^^^^ unreachable label `'some_label`
|
= note: labels are unreachable through functions, closures, async blocks and modules
error[E0267]: `break` inside of a closure
--> $DIR/issue-66702-break-outside-loop-val.rs:5:12
|
@ -6,6 +16,7 @@ LL | || break 'some_label ();
| |
| enclosing closure
error: aborting due to previous error
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0267`.
Some errors have detailed explanations: E0267, E0767.
For more information about an error, try `rustc --explain E0267`.

View file

@ -0,0 +1,12 @@
// edition:2018
fn main() {
'a: loop {
async {
loop {
continue 'a
//~^ ERROR use of unreachable label `'a`
}
};
}
}

View file

@ -0,0 +1,14 @@
error[E0767]: use of unreachable label `'a`
--> $DIR/issue-73541-1.rs:7:26
|
LL | 'a: loop {
| -- unreachable label defined here
...
LL | continue 'a
| ^^ unreachable label `'a`
|
= note: labels are unreachable through functions, closures, async blocks and modules
error: aborting due to previous error
For more information about this error, try `rustc --explain E0767`.

View file

@ -0,0 +1,20 @@
// edition:2018
async fn c() {
'a: loop {
macro_rules! b {
() => {
continue 'a
//~^ ERROR use of unreachable label `'a`
}
}
async {
loop {
b!();
}
};
}
}
fn main() { }

View file

@ -0,0 +1,18 @@
error[E0767]: use of unreachable label `'a`
--> $DIR/issue-73541-2.rs:7:26
|
LL | 'a: loop {
| -- unreachable label defined here
...
LL | continue 'a
| ^^ unreachable label `'a`
...
LL | b!();
| ----- in this macro invocation
|
= note: labels are unreachable through functions, closures, async blocks and modules
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
For more information about this error, try `rustc --explain E0767`.

View file

@ -0,0 +1,9 @@
fn main() {
'aaaaab: loop {
|| {
loop { continue 'aaaaaa }
//~^ ERROR use of undeclared label `'aaaaaa`
};
}
}

View file

@ -0,0 +1,12 @@
error[E0426]: use of undeclared label `'aaaaaa`
--> $DIR/issue-73541-3.rs:4:29
|
LL | 'aaaaab: loop {
| ------- a label with a similar name exists but is unreachable
LL | || {
LL | loop { continue 'aaaaaa }
| ^^^^^^^ undeclared label `'aaaaaa`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0426`.

View file

@ -0,0 +1,9 @@
fn main() {
'a: loop {
|| {
loop { continue 'a }
//~^ ERROR use of unreachable label `'a`
};
}
}

View file

@ -0,0 +1,14 @@
error[E0767]: use of unreachable label `'a`
--> $DIR/issue-73541.rs:4:29
|
LL | 'a: loop {
| -- unreachable label defined here
LL | || {
LL | loop { continue 'a }
| ^^ unreachable label `'a`
|
= note: labels are unreachable through functions, closures, async blocks and modules
error: aborting due to previous error
For more information about this error, try `rustc --explain E0767`.

View file

@ -0,0 +1,507 @@
// ignore-test
// Tests saturating float->int casts. See u128-as-f32.rs for the opposite direction.
//
// Some of these tests come from a similar file in miri,
// tests/run-pass/float.rs. Individual test cases are potentially duplicated
// with the previously existing tests, but since this runs so quickly anyway,
// we're not spending the time to figure out exactly which ones should be
// merged.
extern crate test;
use self::test::black_box;
use std::{f32, f64};
#[cfg(not(target_os = "emscripten"))]
use std::{i128, u128};
use std::{i16, i32, i64, i8, u16, u32, u64, u8};
macro_rules! test {
($val:expr, $src_ty:ident -> $dest_ty:ident, $expected:expr) => (
// black_box disables constant evaluation to test run-time conversions:
assert_eq!(black_box::<$src_ty>($val) as $dest_ty, $expected,
"run-time {} -> {}", stringify!($src_ty), stringify!($dest_ty));
{
const X: $src_ty = $val;
const Y: $dest_ty = X as $dest_ty;
assert_eq!(Y, $expected,
"const eval {} -> {}", stringify!($src_ty), stringify!($dest_ty));
}
);
($fval:expr, f* -> $ity:ident, $ival:expr) => (
test!($fval, f32 -> $ity, $ival);
test!($fval, f64 -> $ity, $ival);
)
}
macro_rules! common_fptoi_tests {
($fty:ident -> $($ity:ident)+) => ({ $(
test!($fty::NAN, $fty -> $ity, 0);
test!($fty::INFINITY, $fty -> $ity, $ity::MAX);
test!($fty::NEG_INFINITY, $fty -> $ity, $ity::MIN);
// These two tests are not solely float->int tests, in particular the latter relies on
// `u128::MAX as f32` not being UB. But that's okay, since this file tests int->float
// as well, the test is just slightly misplaced.
test!($ity::MIN as $fty, $fty -> $ity, $ity::MIN);
test!($ity::MAX as $fty, $fty -> $ity, $ity::MAX);
test!(0., $fty -> $ity, 0);
test!($fty::MIN_POSITIVE, $fty -> $ity, 0);
test!(-0.9, $fty -> $ity, 0);
test!(1., $fty -> $ity, 1);
test!(42., $fty -> $ity, 42);
)+ });
(f* -> $($ity:ident)+) => ({
common_fptoi_tests!(f32 -> $($ity)+);
common_fptoi_tests!(f64 -> $($ity)+);
})
}
macro_rules! fptoui_tests {
($fty: ident -> $($ity: ident)+) => ({ $(
test!(-0., $fty -> $ity, 0);
test!(-$fty::MIN_POSITIVE, $fty -> $ity, 0);
test!(-0.99999994, $fty -> $ity, 0);
test!(-1., $fty -> $ity, 0);
test!(-100., $fty -> $ity, 0);
test!(#[allow(overflowing_literals)] -1e50, $fty -> $ity, 0);
test!(#[allow(overflowing_literals)] -1e130, $fty -> $ity, 0);
)+ });
(f* -> $($ity:ident)+) => ({
fptoui_tests!(f32 -> $($ity)+);
fptoui_tests!(f64 -> $($ity)+);
})
}
use std::fmt::Debug;
// Helper function to avoid promotion so that this tests "run-time" casts, not CTFE.
#[track_caller]
#[inline(never)]
fn assert_eq<T: PartialEq + Debug>(x: T, y: T) {
assert_eq!(x, y);
}
trait FloatToInt<Int>: Copy {
fn cast(self) -> Int;
unsafe fn cast_unchecked(self) -> Int;
}
impl FloatToInt<i8> for f32 {
fn cast(self) -> i8 {
self as _
}
unsafe fn cast_unchecked(self) -> i8 {
self.to_int_unchecked()
}
}
impl FloatToInt<i32> for f32 {
fn cast(self) -> i32 {
self as _
}
unsafe fn cast_unchecked(self) -> i32 {
self.to_int_unchecked()
}
}
impl FloatToInt<u32> for f32 {
fn cast(self) -> u32 {
self as _
}
unsafe fn cast_unchecked(self) -> u32 {
self.to_int_unchecked()
}
}
impl FloatToInt<i64> for f32 {
fn cast(self) -> i64 {
self as _
}
unsafe fn cast_unchecked(self) -> i64 {
self.to_int_unchecked()
}
}
impl FloatToInt<u64> for f32 {
fn cast(self) -> u64 {
self as _
}
unsafe fn cast_unchecked(self) -> u64 {
self.to_int_unchecked()
}
}
impl FloatToInt<i8> for f64 {
fn cast(self) -> i8 {
self as _
}
unsafe fn cast_unchecked(self) -> i8 {
self.to_int_unchecked()
}
}
impl FloatToInt<i32> for f64 {
fn cast(self) -> i32 {
self as _
}
unsafe fn cast_unchecked(self) -> i32 {
self.to_int_unchecked()
}
}
impl FloatToInt<u32> for f64 {
fn cast(self) -> u32 {
self as _
}
unsafe fn cast_unchecked(self) -> u32 {
self.to_int_unchecked()
}
}
impl FloatToInt<i64> for f64 {
fn cast(self) -> i64 {
self as _
}
unsafe fn cast_unchecked(self) -> i64 {
self.to_int_unchecked()
}
}
impl FloatToInt<u64> for f64 {
fn cast(self) -> u64 {
self as _
}
unsafe fn cast_unchecked(self) -> u64 {
self.to_int_unchecked()
}
}
// FIXME emscripten does not support i128
#[cfg(not(target_os = "emscripten"))]
impl FloatToInt<i128> for f64 {
fn cast(self) -> i128 {
self as _
}
unsafe fn cast_unchecked(self) -> i128 {
self.to_int_unchecked()
}
}
// FIXME emscripten does not support i128
#[cfg(not(target_os = "emscripten"))]
impl FloatToInt<u128> for f64 {
fn cast(self) -> u128 {
self as _
}
unsafe fn cast_unchecked(self) -> u128 {
self.to_int_unchecked()
}
}
/// Test this cast both via `as` and via `to_int_unchecked` (i.e., it must not saturate).
#[track_caller]
#[inline(never)]
fn test_both_cast<F, I>(x: F, y: I)
where
F: FloatToInt<I>,
I: PartialEq + Debug,
{
assert_eq!(x.cast(), y);
assert_eq!(unsafe { x.cast_unchecked() }, y);
}
fn casts() {
// f32 -> i8
test_both_cast::<f32, i8>(127.99, 127);
test_both_cast::<f32, i8>(-128.99, -128);
// f32 -> i32
test_both_cast::<f32, i32>(0.0, 0);
test_both_cast::<f32, i32>(-0.0, 0);
test_both_cast::<f32, i32>(/*0x1p-149*/ f32::from_bits(0x00000001), 0);
test_both_cast::<f32, i32>(/*-0x1p-149*/ f32::from_bits(0x80000001), 0);
test_both_cast::<f32, i32>(/*0x1.19999ap+0*/ f32::from_bits(0x3f8ccccd), 1);
test_both_cast::<f32, i32>(/*-0x1.19999ap+0*/ f32::from_bits(0xbf8ccccd), -1);
test_both_cast::<f32, i32>(1.9, 1);
test_both_cast::<f32, i32>(-1.9, -1);
test_both_cast::<f32, i32>(5.0, 5);
test_both_cast::<f32, i32>(-5.0, -5);
test_both_cast::<f32, i32>(2147483520.0, 2147483520);
test_both_cast::<f32, i32>(-2147483648.0, -2147483648);
// unrepresentable casts
assert_eq::<i32>(2147483648.0f32 as i32, i32::MAX);
assert_eq::<i32>(-2147483904.0f32 as i32, i32::MIN);
assert_eq::<i32>(f32::MAX as i32, i32::MAX);
assert_eq::<i32>(f32::MIN as i32, i32::MIN);
assert_eq::<i32>(f32::INFINITY as i32, i32::MAX);
assert_eq::<i32>(f32::NEG_INFINITY as i32, i32::MIN);
assert_eq::<i32>(f32::NAN as i32, 0);
assert_eq::<i32>((-f32::NAN) as i32, 0);
// f32 -> u32
test_both_cast::<f32, u32>(0.0, 0);
test_both_cast::<f32, u32>(-0.0, 0);
test_both_cast::<f32, u32>(-0.9999999, 0);
test_both_cast::<f32, u32>(/*0x1p-149*/ f32::from_bits(0x1), 0);
test_both_cast::<f32, u32>(/*-0x1p-149*/ f32::from_bits(0x80000001), 0);
test_both_cast::<f32, u32>(/*0x1.19999ap+0*/ f32::from_bits(0x3f8ccccd), 1);
test_both_cast::<f32, u32>(1.9, 1);
test_both_cast::<f32, u32>(5.0, 5);
test_both_cast::<f32, u32>(2147483648.0, 0x8000_0000);
test_both_cast::<f32, u32>(4294967040.0, 0u32.wrapping_sub(256));
test_both_cast::<f32, u32>(/*-0x1.ccccccp-1*/ f32::from_bits(0xbf666666), 0);
test_both_cast::<f32, u32>(/*-0x1.fffffep-1*/ f32::from_bits(0xbf7fffff), 0);
test_both_cast::<f32, u32>((u32::MAX - 128) as f32, u32::MAX - 255); // rounding loss
// unrepresentable casts:
// rounds up and then becomes unrepresentable
assert_eq::<u32>((u32::MAX - 127) as f32 as u32, u32::MAX);
assert_eq::<u32>(4294967296.0f32 as u32, u32::MAX);
assert_eq::<u32>(-5.0f32 as u32, 0);
assert_eq::<u32>(f32::MAX as u32, u32::MAX);
assert_eq::<u32>(f32::MIN as u32, 0);
assert_eq::<u32>(f32::INFINITY as u32, u32::MAX);
assert_eq::<u32>(f32::NEG_INFINITY as u32, 0);
assert_eq::<u32>(f32::NAN as u32, 0);
assert_eq::<u32>((-f32::NAN) as u32, 0);
// f32 -> i64
test_both_cast::<f32, i64>(4294967296.0, 4294967296);
test_both_cast::<f32, i64>(-4294967296.0, -4294967296);
test_both_cast::<f32, i64>(9223371487098961920.0, 9223371487098961920);
test_both_cast::<f32, i64>(-9223372036854775808.0, -9223372036854775808);
// f64 -> i8
test_both_cast::<f64, i8>(127.99, 127);
test_both_cast::<f64, i8>(-128.99, -128);
// f64 -> i32
test_both_cast::<f64, i32>(0.0, 0);
test_both_cast::<f64, i32>(-0.0, 0);
test_both_cast::<f64, i32>(/*0x1.199999999999ap+0*/ f64::from_bits(0x3ff199999999999a), 1);
test_both_cast::<f64, i32>(
/*-0x1.199999999999ap+0*/ f64::from_bits(0xbff199999999999a),
-1,
);
test_both_cast::<f64, i32>(1.9, 1);
test_both_cast::<f64, i32>(-1.9, -1);
test_both_cast::<f64, i32>(1e8, 100_000_000);
test_both_cast::<f64, i32>(2147483647.0, 2147483647);
test_both_cast::<f64, i32>(-2147483648.0, -2147483648);
// unrepresentable casts
assert_eq::<i32>(2147483648.0f64 as i32, i32::MAX);
assert_eq::<i32>(-2147483649.0f64 as i32, i32::MIN);
// f64 -> i64
test_both_cast::<f64, i64>(0.0, 0);
test_both_cast::<f64, i64>(-0.0, 0);
test_both_cast::<f64, i64>(/*0x0.0000000000001p-1022*/ f64::from_bits(0x1), 0);
test_both_cast::<f64, i64>(
/*-0x0.0000000000001p-1022*/ f64::from_bits(0x8000000000000001),
0,
);
test_both_cast::<f64, i64>(/*0x1.199999999999ap+0*/ f64::from_bits(0x3ff199999999999a), 1);
test_both_cast::<f64, i64>(
/*-0x1.199999999999ap+0*/ f64::from_bits(0xbff199999999999a),
-1,
);
test_both_cast::<f64, i64>(5.0, 5);
test_both_cast::<f64, i64>(5.9, 5);
test_both_cast::<f64, i64>(-5.0, -5);
test_both_cast::<f64, i64>(-5.9, -5);
test_both_cast::<f64, i64>(4294967296.0, 4294967296);
test_both_cast::<f64, i64>(-4294967296.0, -4294967296);
test_both_cast::<f64, i64>(9223372036854774784.0, 9223372036854774784);
test_both_cast::<f64, i64>(-9223372036854775808.0, -9223372036854775808);
// unrepresentable casts
assert_eq::<i64>(9223372036854775808.0f64 as i64, i64::MAX);
assert_eq::<i64>(-9223372036854777856.0f64 as i64, i64::MIN);
assert_eq::<i64>(f64::MAX as i64, i64::MAX);
assert_eq::<i64>(f64::MIN as i64, i64::MIN);
assert_eq::<i64>(f64::INFINITY as i64, i64::MAX);
assert_eq::<i64>(f64::NEG_INFINITY as i64, i64::MIN);
assert_eq::<i64>(f64::NAN as i64, 0);
assert_eq::<i64>((-f64::NAN) as i64, 0);
// f64 -> u64
test_both_cast::<f64, u64>(0.0, 0);
test_both_cast::<f64, u64>(-0.0, 0);
test_both_cast::<f64, u64>(-0.99999999999, 0);
test_both_cast::<f64, u64>(5.0, 5);
test_both_cast::<f64, u64>(1e16, 10000000000000000);
test_both_cast::<f64, u64>((u64::MAX - 1024) as f64, u64::MAX - 2047); // rounding loss
test_both_cast::<f64, u64>(9223372036854775808.0, 9223372036854775808);
// unrepresentable casts
assert_eq::<u64>(-5.0f64 as u64, 0);
// rounds up and then becomes unrepresentable
assert_eq::<u64>((u64::MAX - 1023) as f64 as u64, u64::MAX);
assert_eq::<u64>(18446744073709551616.0f64 as u64, u64::MAX);
assert_eq::<u64>(f64::MAX as u64, u64::MAX);
assert_eq::<u64>(f64::MIN as u64, 0);
assert_eq::<u64>(f64::INFINITY as u64, u64::MAX);
assert_eq::<u64>(f64::NEG_INFINITY as u64, 0);
assert_eq::<u64>(f64::NAN as u64, 0);
assert_eq::<u64>((-f64::NAN) as u64, 0);
// FIXME emscripten does not support i128
#[cfg(not(target_os = "emscripten"))]
{
// f64 -> i128
assert_eq::<i128>(f64::MAX as i128, i128::MAX);
assert_eq::<i128>(f64::MIN as i128, i128::MIN);
// f64 -> u128
assert_eq::<u128>(f64::MAX as u128, u128::MAX);
assert_eq::<u128>(f64::MIN as u128, 0);
}
// int -> f32
assert_eq::<f32>(127i8 as f32, 127.0);
assert_eq::<f32>(2147483647i32 as f32, 2147483648.0);
assert_eq::<f32>((-2147483648i32) as f32, -2147483648.0);
assert_eq::<f32>(1234567890i32 as f32, /*0x1.26580cp+30*/ f32::from_bits(0x4e932c06));
assert_eq::<f32>(16777217i32 as f32, 16777216.0);
assert_eq::<f32>((-16777217i32) as f32, -16777216.0);
assert_eq::<f32>(16777219i32 as f32, 16777220.0);
assert_eq::<f32>((-16777219i32) as f32, -16777220.0);
assert_eq::<f32>(
0x7fffff4000000001i64 as f32,
/*0x1.fffffep+62*/ f32::from_bits(0x5effffff),
);
assert_eq::<f32>(
0x8000004000000001u64 as i64 as f32,
/*-0x1.fffffep+62*/ f32::from_bits(0xdeffffff),
);
assert_eq::<f32>(
0x0020000020000001i64 as f32,
/*0x1.000002p+53*/ f32::from_bits(0x5a000001),
);
assert_eq::<f32>(
0xffdfffffdfffffffu64 as i64 as f32,
/*-0x1.000002p+53*/ f32::from_bits(0xda000001),
);
// FIXME emscripten does not support i128
#[cfg(not(target_os = "emscripten"))]
{
assert_eq::<f32>(i128::MIN as f32, -170141183460469231731687303715884105728.0f32);
assert_eq::<f32>(u128::MAX as f32, f32::INFINITY); // saturation
}
// int -> f64
assert_eq::<f64>(127i8 as f64, 127.0);
assert_eq::<f64>(i16::MIN as f64, -32768.0f64);
assert_eq::<f64>(2147483647i32 as f64, 2147483647.0);
assert_eq::<f64>(-2147483648i32 as f64, -2147483648.0);
assert_eq::<f64>(987654321i32 as f64, 987654321.0);
assert_eq::<f64>(9223372036854775807i64 as f64, 9223372036854775807.0);
assert_eq::<f64>(-9223372036854775808i64 as f64, -9223372036854775808.0);
assert_eq::<f64>(4669201609102990i64 as f64, 4669201609102990.0); // Feigenbaum (?)
assert_eq::<f64>(9007199254740993i64 as f64, 9007199254740992.0);
assert_eq::<f64>(-9007199254740993i64 as f64, -9007199254740992.0);
assert_eq::<f64>(9007199254740995i64 as f64, 9007199254740996.0);
assert_eq::<f64>(-9007199254740995i64 as f64, -9007199254740996.0);
// FIXME emscripten does not support i128
#[cfg(not(target_os = "emscripten"))]
{
// even that fits...
assert_eq::<f64>(u128::MAX as f64, 340282366920938463463374607431768211455.0f64);
}
// f32 -> f64
assert_eq::<u64>((0.0f32 as f64).to_bits(), 0.0f64.to_bits());
assert_eq::<u64>(((-0.0f32) as f64).to_bits(), (-0.0f64).to_bits());
assert_eq::<f64>(5.0f32 as f64, 5.0f64);
assert_eq::<f64>(
/*0x1p-149*/ f32::from_bits(0x1) as f64,
/*0x1p-149*/ f64::from_bits(0x36a0000000000000),
);
assert_eq::<f64>(
/*-0x1p-149*/ f32::from_bits(0x80000001) as f64,
/*-0x1p-149*/ f64::from_bits(0xb6a0000000000000),
);
assert_eq::<f64>(
/*0x1.fffffep+127*/ f32::from_bits(0x7f7fffff) as f64,
/*0x1.fffffep+127*/ f64::from_bits(0x47efffffe0000000),
);
assert_eq::<f64>(
/*-0x1.fffffep+127*/ (-f32::from_bits(0x7f7fffff)) as f64,
/*-0x1.fffffep+127*/ -f64::from_bits(0x47efffffe0000000),
);
assert_eq::<f64>(
/*0x1p-119*/ f32::from_bits(0x4000000) as f64,
/*0x1p-119*/ f64::from_bits(0x3880000000000000),
);
assert_eq::<f64>(
/*0x1.8f867ep+125*/ f32::from_bits(0x7e47c33f) as f64,
6.6382536710104395e+37,
);
assert_eq::<f64>(f32::INFINITY as f64, f64::INFINITY);
assert_eq::<f64>(f32::NEG_INFINITY as f64, f64::NEG_INFINITY);
// f64 -> f32
assert_eq::<u32>((0.0f64 as f32).to_bits(), 0.0f32.to_bits());
assert_eq::<u32>(((-0.0f64) as f32).to_bits(), (-0.0f32).to_bits());
assert_eq::<f32>(5.0f64 as f32, 5.0f32);
assert_eq::<f32>(/*0x0.0000000000001p-1022*/ f64::from_bits(0x1) as f32, 0.0);
assert_eq::<f32>(/*-0x0.0000000000001p-1022*/ (-f64::from_bits(0x1)) as f32, -0.0);
assert_eq::<f32>(
/*0x1.fffffe0000000p-127*/ f64::from_bits(0x380fffffe0000000) as f32,
/*0x1p-149*/ f32::from_bits(0x800000),
);
assert_eq::<f32>(
/*0x1.4eae4f7024c7p+108*/ f64::from_bits(0x46b4eae4f7024c70) as f32,
/*0x1.4eae5p+108*/ f32::from_bits(0x75a75728),
);
assert_eq::<f32>(f64::MAX as f32, f32::INFINITY);
assert_eq::<f32>(f64::MIN as f32, f32::NEG_INFINITY);
assert_eq::<f32>(f64::INFINITY as f32, f32::INFINITY);
assert_eq::<f32>(f64::NEG_INFINITY as f32, f32::NEG_INFINITY);
}
pub fn run() {
casts(); // from miri's tests
common_fptoi_tests!(f* -> i8 i16 i32 i64 u8 u16 u32 u64);
fptoui_tests!(f* -> u8 u16 u32 u64);
// FIXME emscripten does not support i128
#[cfg(not(target_os = "emscripten"))]
{
common_fptoi_tests!(f* -> i128 u128);
fptoui_tests!(f* -> u128);
}
// The following tests cover edge cases for some integer types.
// # u8
test!(254., f* -> u8, 254);
test!(256., f* -> u8, 255);
// # i8
test!(-127., f* -> i8, -127);
test!(-129., f* -> i8, -128);
test!(126., f* -> i8, 126);
test!(128., f* -> i8, 127);
// # i32
// -2147483648. is i32::MIN (exactly)
test!(-2147483648., f* -> i32, i32::MIN);
// 2147483648. is i32::MAX rounded up
test!(2147483648., f32 -> i32, 2147483647);
// With 24 significand bits, floats with magnitude in [2^30 + 1, 2^31] are rounded to
// multiples of 2^7. Therefore, nextDown(round(i32::MAX)) is 2^31 - 128:
test!(2147483520., f32 -> i32, 2147483520);
// Similarly, nextUp(i32::MIN) is i32::MIN + 2^8 and nextDown(i32::MIN) is i32::MIN - 2^7
test!(-2147483904., f* -> i32, i32::MIN);
test!(-2147483520., f* -> i32, -2147483520);
// # u32
// round(MAX) and nextUp(round(MAX))
test!(4294967040., f* -> u32, 4294967040);
test!(4294967296., f* -> u32, 4294967295);
// # u128
#[cfg(not(target_os = "emscripten"))]
{
// float->int:
test!(f32::MAX, f32 -> u128, 0xffffff00000000000000000000000000);
// nextDown(f32::MAX) = 2^128 - 2 * 2^104
const SECOND_LARGEST_F32: f32 = 340282326356119256160033759537265639424.;
test!(SECOND_LARGEST_F32, f32 -> u128, 0xfffffe00000000000000000000000000);
}
}

View file

@ -0,0 +1,13 @@
// run-pass
// only-wasm32
// compile-flags: -Zmir-opt-level=0 -C target-feature=+nontrapping-fptoint
#![feature(test, stmt_expr_attributes)]
#![deny(overflowing_literals)]
#[path = "saturating-float-casts-impl.rs"]
mod implementation;
pub fn main() {
implementation::run();
}

View file

@ -1,509 +1,12 @@
// run-pass
// compile-flags:-Zmir-opt-level=0
// Tests saturating float->int casts. See u128-as-f32.rs for the opposite direction.
//
// Some of these tests come from a similar file in miri,
// tests/run-pass/float.rs. Individual test cases are potentially duplicated
// with the previously existing tests, but since this runs so quickly anyway,
// we're not spending the time to figure out exactly which ones should be
// merged.
#![feature(test, stmt_expr_attributes)]
#![deny(overflowing_literals)]
extern crate test;
use std::{f32, f64};
#[cfg(not(target_os = "emscripten"))]
use std::{i128, u128};
use std::{i16, i32, i64, i8, u16, u32, u64, u8};
use test::black_box;
macro_rules! test {
($val:expr, $src_ty:ident -> $dest_ty:ident, $expected:expr) => (
// black_box disables constant evaluation to test run-time conversions:
assert_eq!(black_box::<$src_ty>($val) as $dest_ty, $expected,
"run-time {} -> {}", stringify!($src_ty), stringify!($dest_ty));
{
const X: $src_ty = $val;
const Y: $dest_ty = X as $dest_ty;
assert_eq!(Y, $expected,
"const eval {} -> {}", stringify!($src_ty), stringify!($dest_ty));
}
);
($fval:expr, f* -> $ity:ident, $ival:expr) => (
test!($fval, f32 -> $ity, $ival);
test!($fval, f64 -> $ity, $ival);
)
}
macro_rules! common_fptoi_tests {
($fty:ident -> $($ity:ident)+) => ({ $(
test!($fty::NAN, $fty -> $ity, 0);
test!($fty::INFINITY, $fty -> $ity, $ity::MAX);
test!($fty::NEG_INFINITY, $fty -> $ity, $ity::MIN);
// These two tests are not solely float->int tests, in particular the latter relies on
// `u128::MAX as f32` not being UB. But that's okay, since this file tests int->float
// as well, the test is just slightly misplaced.
test!($ity::MIN as $fty, $fty -> $ity, $ity::MIN);
test!($ity::MAX as $fty, $fty -> $ity, $ity::MAX);
test!(0., $fty -> $ity, 0);
test!($fty::MIN_POSITIVE, $fty -> $ity, 0);
test!(-0.9, $fty -> $ity, 0);
test!(1., $fty -> $ity, 1);
test!(42., $fty -> $ity, 42);
)+ });
(f* -> $($ity:ident)+) => ({
common_fptoi_tests!(f32 -> $($ity)+);
common_fptoi_tests!(f64 -> $($ity)+);
})
}
macro_rules! fptoui_tests {
($fty: ident -> $($ity: ident)+) => ({ $(
test!(-0., $fty -> $ity, 0);
test!(-$fty::MIN_POSITIVE, $fty -> $ity, 0);
test!(-0.99999994, $fty -> $ity, 0);
test!(-1., $fty -> $ity, 0);
test!(-100., $fty -> $ity, 0);
test!(#[allow(overflowing_literals)] -1e50, $fty -> $ity, 0);
test!(#[allow(overflowing_literals)] -1e130, $fty -> $ity, 0);
)+ });
(f* -> $($ity:ident)+) => ({
fptoui_tests!(f32 -> $($ity)+);
fptoui_tests!(f64 -> $($ity)+);
})
}
use std::fmt::Debug;
// Helper function to avoid promotion so that this tests "run-time" casts, not CTFE.
#[track_caller]
#[inline(never)]
fn assert_eq<T: PartialEq + Debug>(x: T, y: T) {
assert_eq!(x, y);
}
trait FloatToInt<Int>: Copy {
fn cast(self) -> Int;
unsafe fn cast_unchecked(self) -> Int;
}
impl FloatToInt<i8> for f32 {
fn cast(self) -> i8 {
self as _
}
unsafe fn cast_unchecked(self) -> i8 {
self.to_int_unchecked()
}
}
impl FloatToInt<i32> for f32 {
fn cast(self) -> i32 {
self as _
}
unsafe fn cast_unchecked(self) -> i32 {
self.to_int_unchecked()
}
}
impl FloatToInt<u32> for f32 {
fn cast(self) -> u32 {
self as _
}
unsafe fn cast_unchecked(self) -> u32 {
self.to_int_unchecked()
}
}
impl FloatToInt<i64> for f32 {
fn cast(self) -> i64 {
self as _
}
unsafe fn cast_unchecked(self) -> i64 {
self.to_int_unchecked()
}
}
impl FloatToInt<u64> for f32 {
fn cast(self) -> u64 {
self as _
}
unsafe fn cast_unchecked(self) -> u64 {
self.to_int_unchecked()
}
}
impl FloatToInt<i8> for f64 {
fn cast(self) -> i8 {
self as _
}
unsafe fn cast_unchecked(self) -> i8 {
self.to_int_unchecked()
}
}
impl FloatToInt<i32> for f64 {
fn cast(self) -> i32 {
self as _
}
unsafe fn cast_unchecked(self) -> i32 {
self.to_int_unchecked()
}
}
impl FloatToInt<u32> for f64 {
fn cast(self) -> u32 {
self as _
}
unsafe fn cast_unchecked(self) -> u32 {
self.to_int_unchecked()
}
}
impl FloatToInt<i64> for f64 {
fn cast(self) -> i64 {
self as _
}
unsafe fn cast_unchecked(self) -> i64 {
self.to_int_unchecked()
}
}
impl FloatToInt<u64> for f64 {
fn cast(self) -> u64 {
self as _
}
unsafe fn cast_unchecked(self) -> u64 {
self.to_int_unchecked()
}
}
// FIXME emscripten does not support i128
#[cfg(not(target_os = "emscripten"))]
impl FloatToInt<i128> for f64 {
fn cast(self) -> i128 {
self as _
}
unsafe fn cast_unchecked(self) -> i128 {
self.to_int_unchecked()
}
}
// FIXME emscripten does not support i128
#[cfg(not(target_os = "emscripten"))]
impl FloatToInt<u128> for f64 {
fn cast(self) -> u128 {
self as _
}
unsafe fn cast_unchecked(self) -> u128 {
self.to_int_unchecked()
}
}
/// Test this cast both via `as` and via `to_int_unchecked` (i.e., it must not saturate).
#[track_caller]
#[inline(never)]
fn test_both_cast<F, I>(x: F, y: I)
where
F: FloatToInt<I>,
I: PartialEq + Debug,
{
assert_eq!(x.cast(), y);
assert_eq!(unsafe { x.cast_unchecked() }, y);
}
fn casts() {
// f32 -> i8
test_both_cast::<f32, i8>(127.99, 127);
test_both_cast::<f32, i8>(-128.99, -128);
// f32 -> i32
test_both_cast::<f32, i32>(0.0, 0);
test_both_cast::<f32, i32>(-0.0, 0);
test_both_cast::<f32, i32>(/*0x1p-149*/ f32::from_bits(0x00000001), 0);
test_both_cast::<f32, i32>(/*-0x1p-149*/ f32::from_bits(0x80000001), 0);
test_both_cast::<f32, i32>(/*0x1.19999ap+0*/ f32::from_bits(0x3f8ccccd), 1);
test_both_cast::<f32, i32>(/*-0x1.19999ap+0*/ f32::from_bits(0xbf8ccccd), -1);
test_both_cast::<f32, i32>(1.9, 1);
test_both_cast::<f32, i32>(-1.9, -1);
test_both_cast::<f32, i32>(5.0, 5);
test_both_cast::<f32, i32>(-5.0, -5);
test_both_cast::<f32, i32>(2147483520.0, 2147483520);
test_both_cast::<f32, i32>(-2147483648.0, -2147483648);
// unrepresentable casts
assert_eq::<i32>(2147483648.0f32 as i32, i32::MAX);
assert_eq::<i32>(-2147483904.0f32 as i32, i32::MIN);
assert_eq::<i32>(f32::MAX as i32, i32::MAX);
assert_eq::<i32>(f32::MIN as i32, i32::MIN);
assert_eq::<i32>(f32::INFINITY as i32, i32::MAX);
assert_eq::<i32>(f32::NEG_INFINITY as i32, i32::MIN);
assert_eq::<i32>(f32::NAN as i32, 0);
assert_eq::<i32>((-f32::NAN) as i32, 0);
// f32 -> u32
test_both_cast::<f32, u32>(0.0, 0);
test_both_cast::<f32, u32>(-0.0, 0);
test_both_cast::<f32, u32>(-0.9999999, 0);
test_both_cast::<f32, u32>(/*0x1p-149*/ f32::from_bits(0x1), 0);
test_both_cast::<f32, u32>(/*-0x1p-149*/ f32::from_bits(0x80000001), 0);
test_both_cast::<f32, u32>(/*0x1.19999ap+0*/ f32::from_bits(0x3f8ccccd), 1);
test_both_cast::<f32, u32>(1.9, 1);
test_both_cast::<f32, u32>(5.0, 5);
test_both_cast::<f32, u32>(2147483648.0, 0x8000_0000);
test_both_cast::<f32, u32>(4294967040.0, 0u32.wrapping_sub(256));
test_both_cast::<f32, u32>(/*-0x1.ccccccp-1*/ f32::from_bits(0xbf666666), 0);
test_both_cast::<f32, u32>(/*-0x1.fffffep-1*/ f32::from_bits(0xbf7fffff), 0);
test_both_cast::<f32, u32>((u32::MAX - 128) as f32, u32::MAX - 255); // rounding loss
// unrepresentable casts:
// rounds up and then becomes unrepresentable
assert_eq::<u32>((u32::MAX - 127) as f32 as u32, u32::MAX);
assert_eq::<u32>(4294967296.0f32 as u32, u32::MAX);
assert_eq::<u32>(-5.0f32 as u32, 0);
assert_eq::<u32>(f32::MAX as u32, u32::MAX);
assert_eq::<u32>(f32::MIN as u32, 0);
assert_eq::<u32>(f32::INFINITY as u32, u32::MAX);
assert_eq::<u32>(f32::NEG_INFINITY as u32, 0);
assert_eq::<u32>(f32::NAN as u32, 0);
assert_eq::<u32>((-f32::NAN) as u32, 0);
// f32 -> i64
test_both_cast::<f32, i64>(4294967296.0, 4294967296);
test_both_cast::<f32, i64>(-4294967296.0, -4294967296);
test_both_cast::<f32, i64>(9223371487098961920.0, 9223371487098961920);
test_both_cast::<f32, i64>(-9223372036854775808.0, -9223372036854775808);
// f64 -> i8
test_both_cast::<f64, i8>(127.99, 127);
test_both_cast::<f64, i8>(-128.99, -128);
// f64 -> i32
test_both_cast::<f64, i32>(0.0, 0);
test_both_cast::<f64, i32>(-0.0, 0);
test_both_cast::<f64, i32>(/*0x1.199999999999ap+0*/ f64::from_bits(0x3ff199999999999a), 1);
test_both_cast::<f64, i32>(
/*-0x1.199999999999ap+0*/ f64::from_bits(0xbff199999999999a),
-1,
);
test_both_cast::<f64, i32>(1.9, 1);
test_both_cast::<f64, i32>(-1.9, -1);
test_both_cast::<f64, i32>(1e8, 100_000_000);
test_both_cast::<f64, i32>(2147483647.0, 2147483647);
test_both_cast::<f64, i32>(-2147483648.0, -2147483648);
// unrepresentable casts
assert_eq::<i32>(2147483648.0f64 as i32, i32::MAX);
assert_eq::<i32>(-2147483649.0f64 as i32, i32::MIN);
// f64 -> i64
test_both_cast::<f64, i64>(0.0, 0);
test_both_cast::<f64, i64>(-0.0, 0);
test_both_cast::<f64, i64>(/*0x0.0000000000001p-1022*/ f64::from_bits(0x1), 0);
test_both_cast::<f64, i64>(
/*-0x0.0000000000001p-1022*/ f64::from_bits(0x8000000000000001),
0,
);
test_both_cast::<f64, i64>(/*0x1.199999999999ap+0*/ f64::from_bits(0x3ff199999999999a), 1);
test_both_cast::<f64, i64>(
/*-0x1.199999999999ap+0*/ f64::from_bits(0xbff199999999999a),
-1,
);
test_both_cast::<f64, i64>(5.0, 5);
test_both_cast::<f64, i64>(5.9, 5);
test_both_cast::<f64, i64>(-5.0, -5);
test_both_cast::<f64, i64>(-5.9, -5);
test_both_cast::<f64, i64>(4294967296.0, 4294967296);
test_both_cast::<f64, i64>(-4294967296.0, -4294967296);
test_both_cast::<f64, i64>(9223372036854774784.0, 9223372036854774784);
test_both_cast::<f64, i64>(-9223372036854775808.0, -9223372036854775808);
// unrepresentable casts
assert_eq::<i64>(9223372036854775808.0f64 as i64, i64::MAX);
assert_eq::<i64>(-9223372036854777856.0f64 as i64, i64::MIN);
assert_eq::<i64>(f64::MAX as i64, i64::MAX);
assert_eq::<i64>(f64::MIN as i64, i64::MIN);
assert_eq::<i64>(f64::INFINITY as i64, i64::MAX);
assert_eq::<i64>(f64::NEG_INFINITY as i64, i64::MIN);
assert_eq::<i64>(f64::NAN as i64, 0);
assert_eq::<i64>((-f64::NAN) as i64, 0);
// f64 -> u64
test_both_cast::<f64, u64>(0.0, 0);
test_both_cast::<f64, u64>(-0.0, 0);
test_both_cast::<f64, u64>(-0.99999999999, 0);
test_both_cast::<f64, u64>(5.0, 5);
test_both_cast::<f64, u64>(1e16, 10000000000000000);
test_both_cast::<f64, u64>((u64::MAX - 1024) as f64, u64::MAX - 2047); // rounding loss
test_both_cast::<f64, u64>(9223372036854775808.0, 9223372036854775808);
// unrepresentable casts
assert_eq::<u64>(-5.0f64 as u64, 0);
// rounds up and then becomes unrepresentable
assert_eq::<u64>((u64::MAX - 1023) as f64 as u64, u64::MAX);
assert_eq::<u64>(18446744073709551616.0f64 as u64, u64::MAX);
assert_eq::<u64>(f64::MAX as u64, u64::MAX);
assert_eq::<u64>(f64::MIN as u64, 0);
assert_eq::<u64>(f64::INFINITY as u64, u64::MAX);
assert_eq::<u64>(f64::NEG_INFINITY as u64, 0);
assert_eq::<u64>(f64::NAN as u64, 0);
assert_eq::<u64>((-f64::NAN) as u64, 0);
// FIXME emscripten does not support i128
#[cfg(not(target_os = "emscripten"))]
{
// f64 -> i128
assert_eq::<i128>(f64::MAX as i128, i128::MAX);
assert_eq::<i128>(f64::MIN as i128, i128::MIN);
// f64 -> u128
assert_eq::<u128>(f64::MAX as u128, u128::MAX);
assert_eq::<u128>(f64::MIN as u128, 0);
}
// int -> f32
assert_eq::<f32>(127i8 as f32, 127.0);
assert_eq::<f32>(2147483647i32 as f32, 2147483648.0);
assert_eq::<f32>((-2147483648i32) as f32, -2147483648.0);
assert_eq::<f32>(1234567890i32 as f32, /*0x1.26580cp+30*/ f32::from_bits(0x4e932c06));
assert_eq::<f32>(16777217i32 as f32, 16777216.0);
assert_eq::<f32>((-16777217i32) as f32, -16777216.0);
assert_eq::<f32>(16777219i32 as f32, 16777220.0);
assert_eq::<f32>((-16777219i32) as f32, -16777220.0);
assert_eq::<f32>(
0x7fffff4000000001i64 as f32,
/*0x1.fffffep+62*/ f32::from_bits(0x5effffff),
);
assert_eq::<f32>(
0x8000004000000001u64 as i64 as f32,
/*-0x1.fffffep+62*/ f32::from_bits(0xdeffffff),
);
assert_eq::<f32>(
0x0020000020000001i64 as f32,
/*0x1.000002p+53*/ f32::from_bits(0x5a000001),
);
assert_eq::<f32>(
0xffdfffffdfffffffu64 as i64 as f32,
/*-0x1.000002p+53*/ f32::from_bits(0xda000001),
);
// FIXME emscripten does not support i128
#[cfg(not(target_os = "emscripten"))]
{
assert_eq::<f32>(i128::MIN as f32, -170141183460469231731687303715884105728.0f32);
assert_eq::<f32>(u128::MAX as f32, f32::INFINITY); // saturation
}
// int -> f64
assert_eq::<f64>(127i8 as f64, 127.0);
assert_eq::<f64>(i16::MIN as f64, -32768.0f64);
assert_eq::<f64>(2147483647i32 as f64, 2147483647.0);
assert_eq::<f64>(-2147483648i32 as f64, -2147483648.0);
assert_eq::<f64>(987654321i32 as f64, 987654321.0);
assert_eq::<f64>(9223372036854775807i64 as f64, 9223372036854775807.0);
assert_eq::<f64>(-9223372036854775808i64 as f64, -9223372036854775808.0);
assert_eq::<f64>(4669201609102990i64 as f64, 4669201609102990.0); // Feigenbaum (?)
assert_eq::<f64>(9007199254740993i64 as f64, 9007199254740992.0);
assert_eq::<f64>(-9007199254740993i64 as f64, -9007199254740992.0);
assert_eq::<f64>(9007199254740995i64 as f64, 9007199254740996.0);
assert_eq::<f64>(-9007199254740995i64 as f64, -9007199254740996.0);
// FIXME emscripten does not support i128
#[cfg(not(target_os = "emscripten"))]
{
// even that fits...
assert_eq::<f64>(u128::MAX as f64, 340282366920938463463374607431768211455.0f64);
}
// f32 -> f64
assert_eq::<u64>((0.0f32 as f64).to_bits(), 0.0f64.to_bits());
assert_eq::<u64>(((-0.0f32) as f64).to_bits(), (-0.0f64).to_bits());
assert_eq::<f64>(5.0f32 as f64, 5.0f64);
assert_eq::<f64>(
/*0x1p-149*/ f32::from_bits(0x1) as f64,
/*0x1p-149*/ f64::from_bits(0x36a0000000000000),
);
assert_eq::<f64>(
/*-0x1p-149*/ f32::from_bits(0x80000001) as f64,
/*-0x1p-149*/ f64::from_bits(0xb6a0000000000000),
);
assert_eq::<f64>(
/*0x1.fffffep+127*/ f32::from_bits(0x7f7fffff) as f64,
/*0x1.fffffep+127*/ f64::from_bits(0x47efffffe0000000),
);
assert_eq::<f64>(
/*-0x1.fffffep+127*/ (-f32::from_bits(0x7f7fffff)) as f64,
/*-0x1.fffffep+127*/ -f64::from_bits(0x47efffffe0000000),
);
assert_eq::<f64>(
/*0x1p-119*/ f32::from_bits(0x4000000) as f64,
/*0x1p-119*/ f64::from_bits(0x3880000000000000),
);
assert_eq::<f64>(
/*0x1.8f867ep+125*/ f32::from_bits(0x7e47c33f) as f64,
6.6382536710104395e+37,
);
assert_eq::<f64>(f32::INFINITY as f64, f64::INFINITY);
assert_eq::<f64>(f32::NEG_INFINITY as f64, f64::NEG_INFINITY);
// f64 -> f32
assert_eq::<u32>((0.0f64 as f32).to_bits(), 0.0f32.to_bits());
assert_eq::<u32>(((-0.0f64) as f32).to_bits(), (-0.0f32).to_bits());
assert_eq::<f32>(5.0f64 as f32, 5.0f32);
assert_eq::<f32>(/*0x0.0000000000001p-1022*/ f64::from_bits(0x1) as f32, 0.0);
assert_eq::<f32>(/*-0x0.0000000000001p-1022*/ (-f64::from_bits(0x1)) as f32, -0.0);
assert_eq::<f32>(
/*0x1.fffffe0000000p-127*/ f64::from_bits(0x380fffffe0000000) as f32,
/*0x1p-149*/ f32::from_bits(0x800000),
);
assert_eq::<f32>(
/*0x1.4eae4f7024c7p+108*/ f64::from_bits(0x46b4eae4f7024c70) as f32,
/*0x1.4eae5p+108*/ f32::from_bits(0x75a75728),
);
assert_eq::<f32>(f64::MAX as f32, f32::INFINITY);
assert_eq::<f32>(f64::MIN as f32, f32::NEG_INFINITY);
assert_eq::<f32>(f64::INFINITY as f32, f32::INFINITY);
assert_eq::<f32>(f64::NEG_INFINITY as f32, f32::NEG_INFINITY);
}
#[path = "saturating-float-casts-impl.rs"]
mod implementation;
pub fn main() {
casts(); // from miri's tests
common_fptoi_tests!(f* -> i8 i16 i32 i64 u8 u16 u32 u64);
fptoui_tests!(f* -> u8 u16 u32 u64);
// FIXME emscripten does not support i128
#[cfg(not(target_os = "emscripten"))]
{
common_fptoi_tests!(f* -> i128 u128);
fptoui_tests!(f* -> u128);
}
// The following tests cover edge cases for some integer types.
// # u8
test!(254., f* -> u8, 254);
test!(256., f* -> u8, 255);
// # i8
test!(-127., f* -> i8, -127);
test!(-129., f* -> i8, -128);
test!(126., f* -> i8, 126);
test!(128., f* -> i8, 127);
// # i32
// -2147483648. is i32::MIN (exactly)
test!(-2147483648., f* -> i32, i32::MIN);
// 2147483648. is i32::MAX rounded up
test!(2147483648., f32 -> i32, 2147483647);
// With 24 significand bits, floats with magnitude in [2^30 + 1, 2^31] are rounded to
// multiples of 2^7. Therefore, nextDown(round(i32::MAX)) is 2^31 - 128:
test!(2147483520., f32 -> i32, 2147483520);
// Similarly, nextUp(i32::MIN) is i32::MIN + 2^8 and nextDown(i32::MIN) is i32::MIN - 2^7
test!(-2147483904., f* -> i32, i32::MIN);
test!(-2147483520., f* -> i32, -2147483520);
// # u32
// round(MAX) and nextUp(round(MAX))
test!(4294967040., f* -> u32, 4294967040);
test!(4294967296., f* -> u32, 4294967295);
// # u128
#[cfg(not(target_os = "emscripten"))]
{
// float->int:
test!(f32::MAX, f32 -> u128, 0xffffff00000000000000000000000000);
// nextDown(f32::MAX) = 2^128 - 2 * 2^104
const SECOND_LARGEST_F32: f32 = 340282326356119256160033759537265639424.;
test!(SECOND_LARGEST_F32, f32 -> u128, 0xfffffe00000000000000000000000000);
}
implementation::run();
}

View file

@ -2,7 +2,7 @@ fn f() {
'l: loop {
fn g() {
loop {
break 'l; //~ ERROR use of undeclared label
break 'l; //~ ERROR use of unreachable label
}
}
}

View file

@ -1,9 +1,14 @@
error[E0426]: use of undeclared label `'l`
error[E0767]: use of unreachable label `'l`
--> $DIR/resolve-label.rs:5:23
|
LL | 'l: loop {
| -- unreachable label defined here
...
LL | break 'l;
| ^^ undeclared label `'l`
| ^^ unreachable label `'l`
|
= note: labels are unreachable through functions, closures, async blocks and modules
error: aborting due to previous error
For more information about this error, try `rustc --explain E0426`.
For more information about this error, try `rustc --explain E0767`.

View file

@ -1,35 +1,35 @@
error[E0426]: use of undeclared label `'fo`
--> $DIR/suggest-labels.rs:4:15
|
LL | 'foo: loop {
| ---- a label with a similar name is reachable
LL | break 'fo;
| ^^^
|
help: a label with a similar name exists in this scope
|
LL | break 'foo;
| ^^^^
| |
| undeclared label `'fo`
| help: try using similarly named label: `'foo`
error[E0426]: use of undeclared label `'bor`
--> $DIR/suggest-labels.rs:8:18
|
LL | 'bar: loop {
| ---- a label with a similar name is reachable
LL | continue 'bor;
| ^^^^
|
help: a label with a similar name exists in this scope
|
LL | continue 'bar;
| ^^^^
| |
| undeclared label `'bor`
| help: try using similarly named label: `'bar`
error[E0426]: use of undeclared label `'longlable`
--> $DIR/suggest-labels.rs:13:19
|
LL | 'longlabel1: loop {
| ----------- a label with a similar name is reachable
LL | break 'longlable;
| ^^^^^^^^^^
|
help: a label with a similar name exists in this scope
|
LL | break 'longlabel1;
| ^^^^^^^^^^^
| |
| undeclared label `'longlable`
| help: try using similarly named label: `'longlabel1`
error: aborting due to 3 previous errors

View file

@ -60,15 +60,15 @@ const KNOWN_CONSTS: [(f64, &str, usize); 18] = [
declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for ApproxConstant {
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
if let ExprKind::Lit(lit) = &e.kind {
check_lit(cx, &lit.node, e);
}
}
}
fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr<'_>) {
fn check_lit(cx: &LateContext<'_>, lit: &LitKind, e: &Expr<'_>) {
match *lit {
LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty {
FloatTy::F32 => check_known_consts(cx, e, s, "f32"),
@ -79,7 +79,7 @@ fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr<'_>) {
}
}
fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr<'_>, s: symbol::Symbol, module: &str) {
fn check_known_consts(cx: &LateContext<'_>, e: &Expr<'_>, s: symbol::Symbol, module: &str) {
let s = s.as_str();
if s.parse::<f64>().is_ok() {
for &(constant, name, min_digits) in &KNOWN_CONSTS {

View file

@ -58,8 +58,8 @@ pub struct Arithmetic {
impl_lint_pass!(Arithmetic => [INTEGER_ARITHMETIC, FLOAT_ARITHMETIC]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for Arithmetic {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
if self.expr_span.is_some() {
return;
}
@ -111,13 +111,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
}
}
fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
fn check_expr_post(&mut self, _: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
if Some(expr.span) == self.expr_span {
self.expr_span = None;
}
}
fn check_body(&mut self, cx: &LateContext<'_, '_>, body: &hir::Body<'_>) {
fn check_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
let body_owner = cx.tcx.hir().body_owner(body.id());
match cx.tcx.hir().body_owner_kind(body_owner) {
@ -135,7 +135,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
}
}
fn check_body_post(&mut self, cx: &LateContext<'_, '_>, body: &hir::Body<'_>) {
fn check_body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
let body_owner = cx.tcx.hir().body_owner(body.id());
let body_span = cx.tcx.hir().span(body_owner);

View file

@ -29,8 +29,8 @@ declare_clippy_lint! {
declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants {
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
let lint_true = |is_debug: bool| {
span_lint_and_help(
cx,
@ -114,7 +114,7 @@ enum AssertKind {
/// ```
///
/// where `message` is any expression and `c` is a constant bool.
fn match_assert_with_message<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option<AssertKind> {
fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<AssertKind> {
if_chain! {
if let ExprKind::Match(ref expr, ref arms, _) = expr.kind;
// matches { let _t = expr; _t }

View file

@ -60,9 +60,9 @@ declare_clippy_lint! {
declare_lint_pass!(AssignOps => [ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
impl<'tcx> LateLintPass<'tcx> for AssignOps {
#[allow(clippy::too_many_lines)]
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
match &expr.kind {
hir::ExprKind::AssignOp(op, lhs, rhs) => {
if let hir::ExprKind::Binary(binop, l, r) = &rhs.kind {
@ -191,7 +191,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
}
fn lint_misrefactored_assign_op(
cx: &LateContext<'_, '_>,
cx: &LateContext<'_>,
expr: &hir::Expr<'_>,
op: hir::BinOp,
rhs: &hir::Expr<'_>,
@ -246,7 +246,7 @@ fn is_commutative(op: hir::BinOpKind) -> bool {
struct ExprVisitor<'a, 'tcx> {
assignee: &'a hir::Expr<'a>,
counter: u8,
cx: &'a LateContext<'a, 'tcx>,
cx: &'a LateContext<'tcx>,
}
impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> {

View file

@ -52,7 +52,7 @@ const ATOMIC_TYPES: [&str; 12] = [
"AtomicUsize",
];
fn type_is_atomic(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
fn type_is_atomic(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
if let ty::Adt(&ty::AdtDef { did, .. }, _) = cx.tables().expr_ty(expr).kind {
ATOMIC_TYPES
.iter()
@ -62,13 +62,13 @@ fn type_is_atomic(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
}
}
fn match_ordering_def_path(cx: &LateContext<'_, '_>, did: DefId, orderings: &[&str]) -> bool {
fn match_ordering_def_path(cx: &LateContext<'_>, did: DefId, orderings: &[&str]) -> bool {
orderings
.iter()
.any(|ordering| match_def_path(cx, did, &["core", "sync", "atomic", "Ordering", ordering]))
}
fn check_atomic_load_store(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
fn check_atomic_load_store(cx: &LateContext<'_>, expr: &Expr<'_>) {
if_chain! {
if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind;
let method = method_path.ident.name.as_str();
@ -103,7 +103,7 @@ fn check_atomic_load_store(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
}
}
fn check_memory_fence(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
fn check_memory_fence(cx: &LateContext<'_>, expr: &Expr<'_>) {
if_chain! {
if let ExprKind::Call(ref func, ref args) = expr.kind;
if let ExprKind::Path(ref func_qpath) = func.kind;
@ -127,8 +127,8 @@ fn check_memory_fence(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AtomicOrdering {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for AtomicOrdering {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
check_atomic_load_store(cx, expr);
check_memory_fence(cx, expr);
}

View file

@ -251,8 +251,8 @@ declare_lint_pass!(Attributes => [
UNKNOWN_CLIPPY_LINTS,
]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) {
impl<'tcx> LateLintPass<'tcx> for Attributes {
fn check_attribute(&mut self, cx: &LateContext<'tcx>, attr: &'tcx Attribute) {
if let Some(items) = &attr.meta_item_list() {
if let Some(ident) = attr.ident() {
match &*ident.as_str() {
@ -278,7 +278,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
}
}
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
if is_relevant_item(cx, item) {
check_attrs(cx, item.span, item.ident.name, &item.attrs)
}
@ -350,13 +350,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
}
}
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem<'_>) {
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
if is_relevant_impl(cx, item) {
check_attrs(cx, item.span, item.ident.name, &item.attrs)
}
}
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem<'_>) {
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
if is_relevant_trait(cx, item) {
check_attrs(cx, item.span, item.ident.name, &item.attrs)
}
@ -364,7 +364,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
}
#[allow(clippy::single_match_else)]
fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
fn check_clippy_lint_names(cx: &LateContext<'_>, items: &[NestedMetaItem]) {
let lint_store = cx.lints();
for lint in items {
if_chain! {
@ -416,7 +416,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
}
}
fn is_relevant_item(cx: &LateContext<'_, '_>, item: &Item<'_>) -> bool {
fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
if let ItemKind::Fn(_, _, eid) = item.kind {
is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value)
} else {
@ -424,14 +424,14 @@ fn is_relevant_item(cx: &LateContext<'_, '_>, item: &Item<'_>) -> bool {
}
}
fn is_relevant_impl(cx: &LateContext<'_, '_>, item: &ImplItem<'_>) -> bool {
fn is_relevant_impl(cx: &LateContext<'_>, item: &ImplItem<'_>) -> bool {
match item.kind {
ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value),
_ => false,
}
}
fn is_relevant_trait(cx: &LateContext<'_, '_>, item: &TraitItem<'_>) -> bool {
fn is_relevant_trait(cx: &LateContext<'_>, item: &TraitItem<'_>) -> bool {
match item.kind {
TraitItemKind::Fn(_, TraitFn::Required(_)) => true,
TraitItemKind::Fn(_, TraitFn::Provided(eid)) => {
@ -441,7 +441,7 @@ fn is_relevant_trait(cx: &LateContext<'_, '_>, item: &TraitItem<'_>) -> bool {
}
}
fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, block: &Block<'_>) -> bool {
fn is_relevant_block(cx: &LateContext<'_>, tables: &ty::TypeckTables<'_>, block: &Block<'_>) -> bool {
if let Some(stmt) = block.stmts.first() {
match &stmt.kind {
StmtKind::Local(_) => true,
@ -453,7 +453,7 @@ fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, bl
}
}
fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, expr: &Expr<'_>) -> bool {
fn is_relevant_expr(cx: &LateContext<'_>, tables: &ty::TypeckTables<'_>, expr: &Expr<'_>) -> bool {
match &expr.kind {
ExprKind::Block(block, _) => is_relevant_block(cx, tables, block),
ExprKind::Ret(Some(e)) => is_relevant_expr(cx, tables, e),
@ -473,7 +473,7 @@ fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, exp
}
}
fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attribute]) {
fn check_attrs(cx: &LateContext<'_>, span: Span, name: Name, attrs: &[Attribute]) {
if span.from_expansion() {
return;
}
@ -498,7 +498,7 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
}
}
fn check_semver(cx: &LateContext<'_, '_>, span: Span, lit: &Lit) {
fn check_semver(cx: &LateContext<'_>, span: Span, lit: &Lit) {
if let LitKind::Str(is, _) = lit.kind {
if Version::parse(&is.as_str()).is_ok() {
return;

View file

@ -51,8 +51,8 @@ declare_clippy_lint! {
declare_lint_pass!(AwaitHoldingLock => [AWAIT_HOLDING_LOCK]);
impl LateLintPass<'_, '_> for AwaitHoldingLock {
fn check_body(&mut self, cx: &LateContext<'_, '_>, body: &'_ Body<'_>) {
impl LateLintPass<'_> for AwaitHoldingLock {
fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) {
use AsyncGeneratorKind::{Block, Closure, Fn};
if let Some(GeneratorKind::Async(Block | Closure | Fn)) = body.generator_kind {
let body_id = BodyId {
@ -65,7 +65,7 @@ impl LateLintPass<'_, '_> for AwaitHoldingLock {
}
}
fn check_interior_types(cx: &LateContext<'_, '_>, ty_causes: &[GeneratorInteriorTypeCause<'_>], span: Span) {
fn check_interior_types(cx: &LateContext<'_>, ty_causes: &[GeneratorInteriorTypeCause<'_>], span: Span) {
for ty_cause in ty_causes {
if let rustc_middle::ty::Adt(adt, _) = ty_cause.ty.kind {
if is_mutex_guard(cx, adt.did) {
@ -82,7 +82,7 @@ fn check_interior_types(cx: &LateContext<'_, '_>, ty_causes: &[GeneratorInterior
}
}
fn is_mutex_guard(cx: &LateContext<'_, '_>, def_id: DefId) -> bool {
fn is_mutex_guard(cx: &LateContext<'_>, def_id: DefId) -> bool {
match_def_path(cx, def_id, &paths::MUTEX_GUARD)
|| match_def_path(cx, def_id, &paths::RWLOCK_READ_GUARD)
|| match_def_path(cx, def_id, &paths::RWLOCK_WRITE_GUARD)

View file

@ -110,8 +110,8 @@ impl BitMask {
impl_lint_pass!(BitMask => [BAD_BIT_MASK, INEFFECTIVE_BIT_MASK, VERBOSE_BIT_MASK]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for BitMask {
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
if let ExprKind::Binary(cmp, left, right) = &e.kind {
if cmp.node.is_comparison() {
if let Some(cmp_opt) = fetch_int_literal(cx, right) {
@ -164,7 +164,7 @@ fn invert_cmp(cmp: BinOpKind) -> BinOpKind {
}
}
fn check_compare(cx: &LateContext<'_, '_>, bit_op: &Expr<'_>, cmp_op: BinOpKind, cmp_value: u128, span: Span) {
fn check_compare(cx: &LateContext<'_>, bit_op: &Expr<'_>, cmp_op: BinOpKind, cmp_value: u128, span: Span) {
if let ExprKind::Binary(op, left, right) = &bit_op.kind {
if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr {
return;
@ -177,7 +177,7 @@ fn check_compare(cx: &LateContext<'_, '_>, bit_op: &Expr<'_>, cmp_op: BinOpKind,
#[allow(clippy::too_many_lines)]
fn check_bit_mask(
cx: &LateContext<'_, '_>,
cx: &LateContext<'_>,
bit_op: BinOpKind,
cmp_op: BinOpKind,
mask_value: u128,
@ -290,7 +290,7 @@ fn check_bit_mask(
}
}
fn check_ineffective_lt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128, op: &str) {
fn check_ineffective_lt(cx: &LateContext<'_>, span: Span, m: u128, c: u128, op: &str) {
if c.is_power_of_two() && m < c {
span_lint(
cx,
@ -304,7 +304,7 @@ fn check_ineffective_lt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128,
}
}
fn check_ineffective_gt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128, op: &str) {
fn check_ineffective_gt(cx: &LateContext<'_>, span: Span, m: u128, c: u128, op: &str) {
if (c + 1).is_power_of_two() && m <= c {
span_lint(
cx,
@ -318,7 +318,7 @@ fn check_ineffective_gt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128,
}
}
fn fetch_int_literal(cx: &LateContext<'_, '_>, lit: &Expr<'_>) -> Option<u128> {
fn fetch_int_literal(cx: &LateContext<'_>, lit: &Expr<'_>) -> Option<u128> {
match constant(cx, cx.tables(), lit)?.0 {
Constant::Int(n) => Some(n),
_ => None,

View file

@ -35,8 +35,8 @@ impl BlacklistedName {
impl_lint_pass!(BlacklistedName => [BLACKLISTED_NAME]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlacklistedName {
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat<'_>) {
impl<'tcx> LateLintPass<'tcx> for BlacklistedName {
fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) {
if let PatKind::Binding(.., ident, _) = pat.kind {
if self.blacklist.contains(&ident.name.to_string()) {
span_lint(

View file

@ -45,7 +45,7 @@ declare_lint_pass!(BlocksInIfConditions => [BLOCKS_IN_IF_CONDITIONS]);
struct ExVisitor<'a, 'tcx> {
found_block: Option<&'tcx Expr<'tcx>>,
cx: &'a LateContext<'a, 'tcx>,
cx: &'a LateContext<'tcx>,
}
impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
@ -71,8 +71,8 @@ const BRACED_EXPR_MESSAGE: &str = "omit braces around single expression conditio
const COMPLEX_BLOCK_MESSAGE: &str = "in an `if` condition, avoid complex blocks or closures with blocks; \
instead, move the block or closure higher and bind it with a `let`";
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlocksInIfConditions {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for BlocksInIfConditions {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if in_external_macro(cx.sess(), expr.span) {
return;
}

View file

@ -55,10 +55,10 @@ const METHODS_WITH_NEGATION: [(&str, &str); 2] = [("is_some", "is_none"), ("is_e
declare_lint_pass!(NonminimalBool => [NONMINIMAL_BOOL, LOGIC_BUG]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool {
impl<'tcx> LateLintPass<'tcx> for NonminimalBool {
fn check_fn(
&mut self,
cx: &LateContext<'a, 'tcx>,
cx: &LateContext<'tcx>,
_: FnKind<'tcx>,
_: &'tcx FnDecl<'_>,
body: &'tcx Body<'_>,
@ -70,13 +70,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool {
}
struct NonminimalBoolVisitor<'a, 'tcx> {
cx: &'a LateContext<'a, 'tcx>,
cx: &'a LateContext<'tcx>,
}
use quine_mc_cluskey::Bool;
struct Hir2Qmm<'a, 'tcx, 'v> {
terminals: Vec<&'v Expr<'v>>,
cx: &'a LateContext<'a, 'tcx>,
cx: &'a LateContext<'tcx>,
}
impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
@ -155,7 +155,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
struct SuggestContext<'a, 'tcx, 'v> {
terminals: &'v [&'v Expr<'v>],
cx: &'a LateContext<'a, 'tcx>,
cx: &'a LateContext<'tcx>,
output: String,
}
@ -222,7 +222,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
}
}
fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option<String> {
fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
match &expr.kind {
ExprKind::Binary(binop, lhs, rhs) => {
if !implements_ord(cx, lhs) {
@ -268,7 +268,7 @@ fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option<String> {
}
}
fn suggest(cx: &LateContext<'_, '_>, suggestion: &Bool, terminals: &[&Expr<'_>]) -> String {
fn suggest(cx: &LateContext<'_>, suggestion: &Bool, terminals: &[&Expr<'_>]) -> String {
let mut suggest_context = SuggestContext {
terminals,
cx,
@ -464,13 +464,13 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
}
}
fn implements_ord<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool {
fn implements_ord<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> bool {
let ty = cx.tables().expr_ty(expr);
get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[]))
}
struct NotSimplificationVisitor<'a, 'tcx> {
cx: &'a LateContext<'a, 'tcx>,
cx: &'a LateContext<'tcx>,
}
impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {

View file

@ -35,8 +35,8 @@ declare_clippy_lint! {
declare_lint_pass!(ByteCount => [NAIVE_BYTECOUNT]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for ByteCount {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
if_chain! {
if let ExprKind::MethodCall(ref count, _, ref count_args, _) = expr.kind;
if count.ident.name == sym!(count);

View file

@ -36,7 +36,7 @@ declare_clippy_lint! {
"common metadata is defined in `Cargo.toml`"
}
fn missing_warning(cx: &LateContext<'_, '_>, package: &cargo_metadata::Package, field: &str) {
fn missing_warning(cx: &LateContext<'_>, package: &cargo_metadata::Package, field: &str) {
let message = format!("package `{}` is missing `{}` metadata", package.name, field);
span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, &message);
}
@ -56,8 +56,8 @@ fn is_empty_vec(value: &[String]) -> bool {
declare_lint_pass!(CargoCommonMetadata => [CARGO_COMMON_METADATA]);
impl LateLintPass<'_, '_> for CargoCommonMetadata {
fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) {
impl LateLintPass<'_> for CargoCommonMetadata {
fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) {
if !run_lints(cx, &[CARGO_COMMON_METADATA], CRATE_HIR_ID) {
return;
}

View file

@ -41,8 +41,8 @@ declare_clippy_lint! {
declare_lint_pass!(CheckedConversions => [CHECKED_CONVERSIONS]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CheckedConversions {
fn check_expr(&mut self, cx: &LateContext<'_, '_>, item: &Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for CheckedConversions {
fn check_expr(&mut self, cx: &LateContext<'_>, item: &Expr<'_>) {
let result = if_chain! {
if !in_external_macro(cx.sess(), item.span);
if let ExprKind::Binary(op, ref left, ref right) = &item.kind;
@ -83,7 +83,7 @@ fn single_check<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<Conversion<'tcx>> {
}
/// Searches for a combination of upper & lower bound checks
fn double_check<'a>(cx: &LateContext<'_, '_>, left: &'a Expr<'_>, right: &'a Expr<'_>) -> Option<Conversion<'a>> {
fn double_check<'a>(cx: &LateContext<'_>, left: &'a Expr<'_>, right: &'a Expr<'_>) -> Option<Conversion<'a>> {
let upper_lower = |l, r| {
let upper = check_upper_bound(l);
let lower = check_lower_bound(r);
@ -112,7 +112,7 @@ enum ConversionType {
impl<'a> Conversion<'a> {
/// Combine multiple conversions if the are compatible
pub fn combine(self, other: Self, cx: &LateContext<'_, '_>) -> Option<Conversion<'a>> {
pub fn combine(self, other: Self, cx: &LateContext<'_>) -> Option<Conversion<'a>> {
if self.is_compatible(&other, cx) {
// Prefer a Conversion that contains a type-constraint
Some(if self.to_type.is_some() { self } else { other })
@ -123,7 +123,7 @@ impl<'a> Conversion<'a> {
/// Checks if two conversions are compatible
/// same type of conversion, same 'castee' and same 'to type'
pub fn is_compatible(&self, other: &Self, cx: &LateContext<'_, '_>) -> bool {
pub fn is_compatible(&self, other: &Self, cx: &LateContext<'_>) -> bool {
(self.cvt == other.cvt)
&& (SpanlessEq::new(cx).eq_expr(self.expr_to_cast, other.expr_to_cast))
&& (self.has_compatible_to_type(other))

View file

@ -43,9 +43,9 @@ impl_lint_pass!(CognitiveComplexity => [COGNITIVE_COMPLEXITY]);
impl CognitiveComplexity {
#[allow(clippy::cast_possible_truncation)]
fn check<'a, 'tcx>(
fn check<'tcx>(
&mut self,
cx: &'a LateContext<'a, 'tcx>,
cx: &LateContext<'tcx>,
kind: FnKind<'tcx>,
decl: &'tcx FnDecl<'_>,
body: &'tcx Body<'_>,
@ -112,10 +112,10 @@ impl CognitiveComplexity {
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CognitiveComplexity {
impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity {
fn check_fn(
&mut self,
cx: &LateContext<'a, 'tcx>,
cx: &LateContext<'tcx>,
kind: FnKind<'tcx>,
decl: &'tcx FnDecl<'_>,
body: &'tcx Body<'_>,
@ -128,10 +128,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CognitiveComplexity {
}
}
fn enter_lint_attrs(&mut self, cx: &LateContext<'a, 'tcx>, attrs: &'tcx [Attribute]) {
fn enter_lint_attrs(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) {
self.limit.push_attrs(cx.sess(), attrs, "cognitive_complexity");
}
fn exit_lint_attrs(&mut self, cx: &LateContext<'a, 'tcx>, attrs: &'tcx [Attribute]) {
fn exit_lint_attrs(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) {
self.limit.pop_attrs(cx.sess(), attrs, "cognitive_complexity");
}
}

View file

@ -52,8 +52,8 @@ declare_clippy_lint! {
declare_lint_pass!(ComparisonChain => [COMPARISON_CHAIN]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ComparisonChain {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for ComparisonChain {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if expr.span.from_expansion() {
return;
}

View file

@ -172,9 +172,9 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
}
}
pub fn constant<'c, 'cc>(
lcx: &LateContext<'c, 'cc>,
tables: &'c ty::TypeckTables<'cc>,
pub fn constant<'tcx>(
lcx: &LateContext<'tcx>,
tables: &ty::TypeckTables<'tcx>,
e: &Expr<'_>,
) -> Option<(Constant, bool)> {
let mut cx = ConstEvalLateContext {
@ -187,19 +187,19 @@ pub fn constant<'c, 'cc>(
cx.expr(e).map(|cst| (cst, cx.needed_resolution))
}
pub fn constant_simple<'c, 'cc>(
lcx: &LateContext<'c, 'cc>,
tables: &'c ty::TypeckTables<'cc>,
pub fn constant_simple<'tcx>(
lcx: &LateContext<'tcx>,
tables: &ty::TypeckTables<'tcx>,
e: &Expr<'_>,
) -> Option<Constant> {
constant(lcx, tables, e).and_then(|(cst, res)| if res { None } else { Some(cst) })
}
/// Creates a `ConstEvalLateContext` from the given `LateContext` and `TypeckTables`.
pub fn constant_context<'c, 'cc>(
lcx: &'c LateContext<'c, 'cc>,
tables: &'c ty::TypeckTables<'cc>,
) -> ConstEvalLateContext<'c, 'cc> {
pub fn constant_context<'a, 'tcx>(
lcx: &'a LateContext<'tcx>,
tables: &'a ty::TypeckTables<'tcx>,
) -> ConstEvalLateContext<'a, 'tcx> {
ConstEvalLateContext {
lcx,
tables,
@ -210,14 +210,14 @@ pub fn constant_context<'c, 'cc>(
}
pub struct ConstEvalLateContext<'a, 'tcx> {
lcx: &'a LateContext<'a, 'tcx>,
lcx: &'a LateContext<'tcx>,
tables: &'a ty::TypeckTables<'tcx>,
param_env: ty::ParamEnv<'tcx>,
needed_resolution: bool,
substs: SubstsRef<'tcx>,
}
impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
/// Simple constant folding: Insert an expression, get a constant or none.
pub fn expr(&mut self, e: &Expr<'_>) -> Option<Constant> {
if let Some((ref cond, ref then, otherwise)) = higher::if_block(&e) {
@ -318,7 +318,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
}
/// Lookup a possibly constant expression from a `ExprKind::Path`.
fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'cc>) -> Option<Constant> {
fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'tcx>) -> Option<Constant> {
let res = self.tables.qpath_res(qpath, id);
match res {
Res::Def(DefKind::Const | DefKind::AssocConst, def_id) => {

View file

@ -151,8 +151,8 @@ declare_clippy_lint! {
declare_lint_pass!(CopyAndPaste => [IFS_SAME_COND, SAME_FUNCTIONS_IN_IF_CONDITION, IF_SAME_THEN_ELSE, MATCH_SAME_ARMS]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for CopyAndPaste {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if !expr.span.from_expansion() {
// skip ifs directly in else, it will be checked in the parent if
if let Some(expr) = get_parent_expr(cx, expr) {
@ -173,7 +173,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
}
/// Implementation of `IF_SAME_THEN_ELSE`.
fn lint_same_then_else(cx: &LateContext<'_, '_>, blocks: &[&Block<'_>]) {
fn lint_same_then_else(cx: &LateContext<'_>, blocks: &[&Block<'_>]) {
let eq: &dyn Fn(&&Block<'_>, &&Block<'_>) -> bool =
&|&lhs, &rhs| -> bool { SpanlessEq::new(cx).eq_block(lhs, rhs) };
@ -190,7 +190,7 @@ fn lint_same_then_else(cx: &LateContext<'_, '_>, blocks: &[&Block<'_>]) {
}
/// Implementation of `IFS_SAME_COND`.
fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) {
fn lint_same_cond(cx: &LateContext<'_>, conds: &[&Expr<'_>]) {
let hash: &dyn Fn(&&Expr<'_>) -> u64 = &|expr| -> u64 {
let mut h = SpanlessHash::new(cx);
h.hash_expr(expr);
@ -213,7 +213,7 @@ fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) {
}
/// Implementation of `SAME_FUNCTIONS_IN_IF_CONDITION`.
fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) {
fn lint_same_fns_in_if_cond(cx: &LateContext<'_>, conds: &[&Expr<'_>]) {
let hash: &dyn Fn(&&Expr<'_>) -> u64 = &|expr| -> u64 {
let mut h = SpanlessHash::new(cx);
h.hash_expr(expr);
@ -241,7 +241,7 @@ fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) {
}
/// Implementation of `MATCH_SAME_ARMS`.
fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>) {
fn lint_match_arms<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) {
fn same_bindings<'tcx>(lhs: &FxHashMap<Symbol, Ty<'tcx>>, rhs: &FxHashMap<Symbol, Ty<'tcx>>) -> bool {
lhs.len() == rhs.len()
&& lhs
@ -309,8 +309,8 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>) {
}
/// Returns the list of bindings in a pattern.
fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat<'_>) -> FxHashMap<Symbol, Ty<'tcx>> {
fn bindings_impl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat<'_>, map: &mut FxHashMap<Symbol, Ty<'tcx>>) {
fn bindings<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'_>) -> FxHashMap<Symbol, Ty<'tcx>> {
fn bindings_impl<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'_>, map: &mut FxHashMap<Symbol, Ty<'tcx>>) {
match pat.kind {
PatKind::Box(ref pat) | PatKind::Ref(ref pat, _) => bindings_impl(cx, pat, map),
PatKind::TupleStruct(_, pats, _) => {

View file

@ -31,8 +31,8 @@ declare_clippy_lint! {
declare_lint_pass!(CopyIterator => [COPY_ITERATOR]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) {
impl<'tcx> LateLintPass<'tcx> for CopyIterator {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
if let ItemKind::Impl {
of_trait: Some(ref trait_ref),
..

View file

@ -30,8 +30,8 @@ declare_clippy_lint! {
declare_lint_pass!(DefaultTraitAccess => [DEFAULT_TRAIT_ACCESS]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for DefaultTraitAccess {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if_chain! {
if let ExprKind::Call(ref path, ..) = expr.kind;
if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id);

View file

@ -38,8 +38,8 @@ declare_lint_pass!(Dereferencing => [
EXPLICIT_DEREF_METHODS
]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Dereferencing {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for Dereferencing {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if_chain! {
if !expr.span.from_expansion();
if let ExprKind::MethodCall(ref method_name, _, ref args, _) = &expr.kind;
@ -70,7 +70,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Dereferencing {
}
}
fn lint_deref(cx: &LateContext<'_, '_>, method_name: &str, call_expr: &Expr<'_>, var_span: Span, expr_span: Span) {
fn lint_deref(cx: &LateContext<'_>, method_name: &str, call_expr: &Expr<'_>, var_span: Span, expr_span: Span) {
match method_name {
"deref" => {
if cx.tcx.lang_items().deref_trait().map_or(false, |id| {

View file

@ -105,8 +105,8 @@ declare_clippy_lint! {
declare_lint_pass!(Derive => [EXPL_IMPL_CLONE_ON_COPY, DERIVE_HASH_XOR_EQ, UNSAFE_DERIVE_DESERIALIZE]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) {
impl<'tcx> LateLintPass<'tcx> for Derive {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
if let ItemKind::Impl {
of_trait: Some(ref trait_ref),
..
@ -127,8 +127,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive {
}
/// Implementation of the `DERIVE_HASH_XOR_EQ` lint.
fn check_hash_peq<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
fn check_hash_peq<'tcx>(
cx: &LateContext<'tcx>,
span: Span,
trait_ref: &TraitRef<'_>,
ty: Ty<'tcx>,
@ -181,7 +181,7 @@ fn check_hash_peq<'a, 'tcx>(
}
/// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint.
fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item<'_>, trait_ref: &TraitRef<'_>, ty: Ty<'tcx>) {
fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &TraitRef<'_>, ty: Ty<'tcx>) {
if match_path(&trait_ref.path, &paths::CLONE_TRAIT) {
if !is_copy(cx, ty) {
return;
@ -222,18 +222,18 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item<'_>, trait
}
/// Implementation of the `UNSAFE_DERIVE_DESERIALIZE` lint.
fn check_unsafe_derive_deserialize<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
fn check_unsafe_derive_deserialize<'tcx>(
cx: &LateContext<'tcx>,
item: &Item<'_>,
trait_ref: &TraitRef<'_>,
ty: Ty<'tcx>,
) {
fn item_from_def_id<'tcx>(cx: &LateContext<'_, 'tcx>, def_id: DefId) -> &'tcx Item<'tcx> {
fn item_from_def_id<'tcx>(cx: &LateContext<'tcx>, def_id: DefId) -> &'tcx Item<'tcx> {
let hir_id = cx.tcx.hir().as_local_hir_id(def_id.expect_local());
cx.tcx.hir().expect_item(hir_id)
}
fn has_unsafe<'tcx>(cx: &LateContext<'_, 'tcx>, item: &'tcx Item<'_>) -> bool {
fn has_unsafe<'tcx>(cx: &LateContext<'tcx>, item: &'tcx Item<'_>) -> bool {
let mut visitor = UnsafeVisitor { cx, has_unsafe: false };
walk_item(&mut visitor, item);
visitor.has_unsafe
@ -261,7 +261,7 @@ fn check_unsafe_derive_deserialize<'a, 'tcx>(
}
struct UnsafeVisitor<'a, 'tcx> {
cx: &'a LateContext<'a, 'tcx>,
cx: &'a LateContext<'tcx>,
has_unsafe: bool,
}

View file

@ -146,12 +146,12 @@ impl DocMarkdown {
impl_lint_pass!(DocMarkdown => [DOC_MARKDOWN, MISSING_SAFETY_DOC, MISSING_ERRORS_DOC, NEEDLESS_DOCTEST_MAIN]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
fn check_crate(&mut self, cx: &LateContext<'a, 'tcx>, krate: &'tcx hir::Crate<'_>) {
impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
fn check_crate(&mut self, cx: &LateContext<'tcx>, krate: &'tcx hir::Crate<'_>) {
check_attrs(cx, &self.valid_idents, &krate.item.attrs);
}
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'_>) {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
match item.kind {
hir::ItemKind::Fn(ref sig, _, body_id) => {
@ -171,13 +171,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
}
}
fn check_item_post(&mut self, _cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'_>) {
fn check_item_post(&mut self, _cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
if let hir::ItemKind::Impl { .. } = item.kind {
self.in_trait_impl = false;
}
}
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::TraitItem<'_>) {
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
if !in_external_macro(cx.tcx.sess, item.span) {
@ -186,7 +186,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
}
}
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::ImplItem<'_>) {
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
if self.in_trait_impl || in_external_macro(cx.tcx.sess, item.span) {
return;
@ -197,8 +197,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
}
}
fn lint_for_missing_headers<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
fn lint_for_missing_headers<'tcx>(
cx: &LateContext<'tcx>,
hir_id: hir::HirId,
span: impl Into<MultiSpan> + Copy,
sig: &hir::FnSig<'_>,
@ -313,7 +313,7 @@ struct DocHeaders {
errors: bool,
}
fn check_attrs<'a>(cx: &LateContext<'_, '_>, valid_idents: &FxHashSet<String>, attrs: &'a [Attribute]) -> DocHeaders {
fn check_attrs<'a>(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &'a [Attribute]) -> DocHeaders {
let mut doc = String::new();
let mut spans = vec![];
@ -370,7 +370,7 @@ fn check_attrs<'a>(cx: &LateContext<'_, '_>, valid_idents: &FxHashSet<String>, a
const RUST_CODE: &[&str] = &["rust", "no_run", "should_panic", "compile_fail", "edition2018"];
fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize>)>>(
cx: &LateContext<'_, '_>,
cx: &LateContext<'_>,
valid_idents: &FxHashSet<String>,
events: Events,
spans: &[(usize, Span)],
@ -442,13 +442,13 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
static LEAVE_MAIN_PATTERNS: &[&str] = &["static", "fn main() {}", "extern crate", "async fn main() {"];
fn check_code(cx: &LateContext<'_, '_>, text: &str, span: Span) {
fn check_code(cx: &LateContext<'_>, text: &str, span: Span) {
if text.contains("fn main() {") && !LEAVE_MAIN_PATTERNS.iter().any(|p| text.contains(p)) {
span_lint(cx, NEEDLESS_DOCTEST_MAIN, span, "needless `fn main` in doctest");
}
}
fn check_text(cx: &LateContext<'_, '_>, valid_idents: &FxHashSet<String>, text: &str, span: Span) {
fn check_text(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, text: &str, span: Span) {
for word in text.split(|c: char| c.is_whitespace() || c == '\'') {
// Trim punctuation as in `some comment (see foo::bar).`
// ^^
@ -471,7 +471,7 @@ fn check_text(cx: &LateContext<'_, '_>, valid_idents: &FxHashSet<String>, text:
}
}
fn check_word(cx: &LateContext<'_, '_>, word: &str, span: Span) {
fn check_word(cx: &LateContext<'_>, word: &str, span: Span) {
/// Checks if a string is camel-case, i.e., contains at least two uppercase
/// letters (`Clippy` is ok) and one lower-case letter (`NASA` is ok).
/// Plurals are also excluded (`IDs` is ok).

View file

@ -37,9 +37,9 @@ declare_clippy_lint! {
declare_lint_pass!(DoubleComparisons => [DOUBLE_COMPARISONS]);
impl<'a, 'tcx> DoubleComparisons {
impl<'tcx> DoubleComparisons {
#[allow(clippy::similar_names)]
fn check_binop(cx: &LateContext<'a, 'tcx>, op: BinOpKind, lhs: &'tcx Expr<'_>, rhs: &'tcx Expr<'_>, span: Span) {
fn check_binop(cx: &LateContext<'tcx>, op: BinOpKind, lhs: &'tcx Expr<'_>, rhs: &'tcx Expr<'_>, span: Span) {
let (lkind, llhs, lrhs, rkind, rlhs, rrhs) = match (&lhs.kind, &rhs.kind) {
(ExprKind::Binary(lb, llhs, lrhs), ExprKind::Binary(rb, rlhs, rrhs)) => {
(lb.node, llhs, lrhs, rb.node, rlhs, rrhs)
@ -86,8 +86,8 @@ impl<'a, 'tcx> DoubleComparisons {
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DoubleComparisons {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for DoubleComparisons {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = expr.kind {
Self::check_binop(cx, kind.node, lhs, rhs, expr.span);
}

View file

@ -1,7 +1,7 @@
use crate::utils::{match_def_path, paths, span_lint};
use if_chain::if_chain;
use rustc_hir::{GenericBound, GenericParam, WhereBoundPredicate, WherePredicate};
use rustc_lint::LateLintPass;
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
declare_clippy_lint! {
@ -41,13 +41,13 @@ const DROP_BOUNDS_SUMMARY: &str = "Bounds of the form `T: Drop` are useless. \
declare_lint_pass!(DropBounds => [DROP_BOUNDS]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropBounds {
fn check_generic_param(&mut self, cx: &rustc_lint::LateContext<'a, 'tcx>, p: &'tcx GenericParam<'_>) {
impl<'tcx> LateLintPass<'tcx> for DropBounds {
fn check_generic_param(&mut self, cx: &LateContext<'tcx>, p: &'tcx GenericParam<'_>) {
for bound in p.bounds.iter() {
lint_bound(cx, bound);
}
}
fn check_where_predicate(&mut self, cx: &rustc_lint::LateContext<'a, 'tcx>, p: &'tcx WherePredicate<'_>) {
fn check_where_predicate(&mut self, cx: &LateContext<'tcx>, p: &'tcx WherePredicate<'_>) {
if let WherePredicate::BoundPredicate(WhereBoundPredicate { bounds, .. }) = p {
for bound in *bounds {
lint_bound(cx, bound);
@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropBounds {
}
}
fn lint_bound<'a, 'tcx>(cx: &rustc_lint::LateContext<'a, 'tcx>, bound: &'tcx GenericBound<'_>) {
fn lint_bound<'tcx>(cx: &LateContext<'tcx>, bound: &'tcx GenericBound<'_>) {
if_chain! {
if let GenericBound::Trait(t, _) = bound;
if let Some(def_id) = t.trait_ref.path.res.opt_def_id();

View file

@ -108,8 +108,8 @@ const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that
declare_lint_pass!(DropForgetRef => [DROP_REF, FORGET_REF, DROP_COPY, FORGET_COPY]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if_chain! {
if let ExprKind::Call(ref path, ref args) = expr.kind;
if let ExprKind::Path(ref qpath) = path.kind;

View file

@ -38,8 +38,8 @@ declare_clippy_lint! {
declare_lint_pass!(DurationSubsec => [DURATION_SUBSEC]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for DurationSubsec {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if_chain! {
if let ExprKind::Binary(Spanned { node: BinOpKind::Div, .. }, ref left, ref right) = expr.kind;
if let ExprKind::MethodCall(ref method_path, _ , ref args, _) = left.kind;

View file

@ -38,8 +38,8 @@ declare_clippy_lint! {
declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item<'_>) {
impl<'tcx> LateLintPass<'tcx> for EmptyEnum {
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
let did = cx.tcx.hir().local_def_id(item.hir_id);
if let ItemKind::Enum(..) = item.kind {
let ty = cx.tcx.type_of(did);

View file

@ -52,8 +52,8 @@ declare_clippy_lint! {
declare_lint_pass!(HashMapPass => [MAP_ENTRY]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapPass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for HashMapPass {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if let Some((ref check, ref then_block, ref else_block)) = higher::if_block(&expr) {
if let ExprKind::Unary(UnOp::UnNot, ref check) = check.kind {
if let Some((ty, map, key)) = check_cond(cx, check) {
@ -98,10 +98,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapPass {
}
}
fn check_cond<'a, 'tcx, 'b>(
cx: &'a LateContext<'a, 'tcx>,
check: &'b Expr<'b>,
) -> Option<(&'static str, &'b Expr<'b>, &'b Expr<'b>)> {
fn check_cond<'a>(cx: &LateContext<'_>, check: &'a Expr<'a>) -> Option<(&'static str, &'a Expr<'a>, &'a Expr<'a>)> {
if_chain! {
if let ExprKind::MethodCall(ref path, _, ref params, _) = check.kind;
if params.len() >= 2;
@ -127,7 +124,7 @@ fn check_cond<'a, 'tcx, 'b>(
}
struct InsertVisitor<'a, 'tcx, 'b> {
cx: &'a LateContext<'a, 'tcx>,
cx: &'a LateContext<'tcx>,
span: Span,
ty: &'static str,
map: &'b Expr<'b>,

View file

@ -36,9 +36,9 @@ declare_clippy_lint! {
declare_lint_pass!(UnportableVariant => [ENUM_CLIKE_UNPORTABLE_VARIANT]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
impl<'tcx> LateLintPass<'tcx> for UnportableVariant {
#[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::cast_sign_loss)]
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
if cx.tcx.data_layout.pointer_size.bits() != 64 {
return;
}

View file

@ -52,9 +52,9 @@ declare_clippy_lint! {
declare_lint_pass!(EqOp => [EQ_OP, OP_REF]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
impl<'tcx> LateLintPass<'tcx> for EqOp {
#[allow(clippy::similar_names, clippy::too_many_lines)]
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
if let ExprKind::Binary(op, ref left, ref right) = e.kind {
if e.span.from_expansion() {
return;

View file

@ -29,8 +29,8 @@ declare_clippy_lint! {
declare_lint_pass!(ErasingOp => [ERASING_OP]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for ErasingOp {
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
if e.span.from_expansion() {
return;
}
@ -47,7 +47,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp {
}
}
fn check(cx: &LateContext<'_, '_>, e: &Expr<'_>, span: Span) {
fn check(cx: &LateContext<'_>, e: &Expr<'_>, span: Span) {
if let Some(Constant::Int(0)) = constant_simple(cx, cx.tables(), e) {
span_lint(
cx,

View file

@ -49,17 +49,17 @@ fn is_non_trait_box(ty: Ty<'_>) -> bool {
}
struct EscapeDelegate<'a, 'tcx> {
cx: &'a LateContext<'a, 'tcx>,
cx: &'a LateContext<'tcx>,
set: HirIdSet,
too_large_for_stack: u64,
}
impl_lint_pass!(BoxedLocal => [BOXED_LOCAL]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
fn check_fn(
&mut self,
cx: &LateContext<'a, 'tcx>,
cx: &LateContext<'tcx>,
_: intravisit::FnKind<'tcx>,
_: &'tcx FnDecl<'_>,
body: &'tcx Body<'_>,

View file

@ -64,8 +64,8 @@ declare_clippy_lint! {
declare_lint_pass!(EtaReduction => [REDUNDANT_CLOSURE, REDUNDANT_CLOSURE_FOR_METHOD_CALLS]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaReduction {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for EtaReduction {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if in_external_macro(cx.sess(), expr.span) {
return;
}
@ -81,7 +81,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaReduction {
}
}
fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) {
if let ExprKind::Closure(_, ref decl, eid, _, _) = expr.kind {
let body = cx.tcx.hir().body(eid);
let ex = &body.value;
@ -151,7 +151,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
}
/// Tries to determine the type for universal function call to be used instead of the closure
fn get_ufcs_type_name(cx: &LateContext<'_, '_>, method_def_id: def_id::DefId, self_arg: &Expr<'_>) -> Option<String> {
fn get_ufcs_type_name(cx: &LateContext<'_>, method_def_id: def_id::DefId, self_arg: &Expr<'_>) -> Option<String> {
let expected_type_of_self = &cx.tcx.fn_sig(method_def_id).inputs_and_output().skip_binder()[0];
let actual_type_of_self = &cx.tables().node_type(self_arg.hir_id);
@ -196,7 +196,7 @@ fn match_types(lhs: Ty<'_>, rhs: Ty<'_>) -> bool {
}
}
fn get_type_name(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> String {
fn get_type_name(cx: &LateContext<'_>, ty: Ty<'_>) -> String {
match ty.kind {
ty::Adt(t, _) => cx.tcx.def_path_str(t.did),
ty::Ref(_, r, _) => get_type_name(cx, &r),

View file

@ -67,8 +67,8 @@ declare_clippy_lint! {
declare_lint_pass!(EvalOrderDependence => [EVAL_ORDER_DEPENDENCE, DIVERGING_SUB_EXPRESSION]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for EvalOrderDependence {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
// Find a write to a local variable.
match expr.kind {
ExprKind::Assign(ref lhs, ..) | ExprKind::AssignOp(_, ref lhs, _) => {
@ -91,7 +91,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
_ => {},
}
}
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) {
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
match stmt.kind {
StmtKind::Local(ref local) => {
if let Local { init: Some(ref e), .. } = **local {
@ -105,7 +105,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
}
struct DivergenceVisitor<'a, 'tcx> {
cx: &'a LateContext<'a, 'tcx>,
cx: &'a LateContext<'tcx>,
}
impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> {
@ -285,7 +285,7 @@ fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt<'_>) -
/// A visitor that looks for reads from a variable.
struct ReadVisitor<'a, 'tcx> {
cx: &'a LateContext<'a, 'tcx>,
cx: &'a LateContext<'tcx>,
/// The ID of the variable we're looking for.
var: HirId,
/// The expressions where the write to the variable occurred (for reporting
@ -354,7 +354,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
}
/// Returns `true` if `expr` is the LHS of an assignment, like `expr = ...`.
fn is_in_assignment_position(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
fn is_in_assignment_position(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
if let Some(parent) = get_parent_expr(cx, expr) {
if let ExprKind::Assign(ref lhs, ..) = parent.kind {
return lhs.hir_id == expr.hir_id;

View file

@ -24,8 +24,8 @@ declare_clippy_lint! {
declare_lint_pass!(Exit => [EXIT]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Exit {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for Exit {
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
if_chain! {
if let ExprKind::Call(ref path_expr, ref _args) = e.kind;
if let ExprKind::Path(ref path) = path_expr.kind;

View file

@ -28,8 +28,8 @@ declare_clippy_lint! {
declare_lint_pass!(ExplicitWrite => [EXPLICIT_WRITE]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitWrite {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for ExplicitWrite {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if_chain! {
// match call to unwrap
if let ExprKind::MethodCall(ref unwrap_fun, _, ref unwrap_args, _) = expr.kind;

View file

@ -52,8 +52,8 @@ declare_clippy_lint! {
declare_lint_pass!(FallibleImplFrom => [FALLIBLE_IMPL_FROM]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'_>) {
impl<'tcx> LateLintPass<'tcx> for FallibleImplFrom {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
// check for `impl From<???> for ..`
let impl_def_id = cx.tcx.hir().local_def_id(item.hir_id);
if_chain! {
@ -67,12 +67,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom {
}
}
fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_items: &[hir::ImplItemRef<'_>]) {
fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[hir::ImplItemRef<'_>]) {
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::{Expr, ExprKind, ImplItemKind, QPath};
struct FindPanicUnwrap<'a, 'tcx> {
lcx: &'a LateContext<'a, 'tcx>,
lcx: &'a LateContext<'tcx>,
tables: &'tcx ty::TypeckTables<'tcx>,
result: Vec<Span>,
}

View file

@ -58,8 +58,8 @@ declare_clippy_lint! {
declare_lint_pass!(FloatLiteral => [EXCESSIVE_PRECISION, LOSSY_FLOAT_LITERAL]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FloatLiteral {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
if_chain! {
let ty = cx.tables().expr_ty(expr);
if let ty::Float(fty) = ty.kind;

Some files were not shown because too many files have changed in this diff Show more