Commit Graph

4849 Commits

Author SHA1 Message Date
zetanumbers
fe37cc1d97 Move some methods from tcx.hir() to tcx
Renamings:
- find -> opt_hir_node
- get -> hir_node
- find_by_def_id -> opt_hir_node_by_def_id
- get_by_def_id -> hir_node_by_def_id

Fix rebase changes using removed methods

Use `tcx.hir_node_by_def_id()` whenever possible in compiler

Fix clippy errors

Fix compiler

Apply suggestions from code review

Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>

Add FIXME for `tcx.hir()` returned type about its removal

Simplify with with `tcx.hir_node_by_def_id`
2023-12-12 06:40:29 -08:00
bors
c8213a49bb Auto merge of #117758 - Urgau:lint_pointer_trait_comparisons, r=davidtwco
Add lint against ambiguous wide pointer comparisons

This PR is the resolution of https://github.com/rust-lang/rust/issues/106447 decided in https://github.com/rust-lang/rust/issues/117717 by T-lang.

## `ambiguous_wide_pointer_comparisons`

*warn-by-default*

The `ambiguous_wide_pointer_comparisons` lint checks comparison of `*const/*mut ?Sized` as the operands.

### Example

```rust
let ab = (A, B);
let a = &ab.0 as *const dyn T;
let b = &ab.1 as *const dyn T;

let _ = a == b;
```

### Explanation

The comparison includes metadata which may not be expected.

-------

This PR also drops `clippy::vtable_address_comparisons` which is superseded by this one.

~~One thing: is the current naming right? `invalid` seems a bit too much.~~

Fixes https://github.com/rust-lang/rust/issues/117717
2023-12-11 14:33:16 +00:00
bors
1f9b674bbf Auto merge of #118661 - fee1-dead-contrib:restore-const-partialEq, r=compiler-errors
Restore `const PartialEq`

And thus fixes a number of tests. There is a bug that still needs to be fixed, so WIP for now.

r? `@compiler-errors`
2023-12-11 10:34:51 +00:00
Nicholas Nethercote
e35acc2def Add spacing information to delimiters.
This is an extension of the previous commit. It means the output of
something like this:
```
stringify!(let a: Vec<u32> = vec![];)
```
goes from this:
```
let a: Vec<u32> = vec![] ;
```
With this PR, it now produces this string:
```
let a: Vec<u32> = vec![];
```
2023-12-11 09:36:40 +11:00
Deadbeef
782520088f fix clippy 2023-12-10 13:10:46 +00:00
surechen
0109fa6b49 remove redundant imports
detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
2023-12-10 10:56:22 +08:00
bors
0252580e72 Auto merge of #118420 - compiler-errors:async-gen, r=eholk
Introduce support for `async gen` blocks

I'm delighted to demonstrate that `async gen` block are not very difficult to support. They're simply coroutines that yield `Poll<Option<T>>` and return `()`.

**This PR is WIP and in draft mode for now** -- I'm mostly putting it up to show folks that it's possible. This PR needs a lang-team experiment associated with it or possible an RFC, since I don't think it falls under the jurisdiction of the `gen` RFC that was recently authored by oli (https://github.com/rust-lang/rfcs/pull/3513, https://github.com/rust-lang/rust/issues/117078).

### Technical note on the pre-generator-transform yield type:

The reason that the underlying coroutines yield `Poll<Option<T>>` and not `Poll<T>` (which would make more sense, IMO, for the pre-transformed coroutine), is because the `TransformVisitor` that is used to turn coroutines into built-in state machine functions would have to destructure and reconstruct the latter into the former, which requires at least inserting a new basic block (for a `switchInt` terminator, to match on the `Poll` discriminant).

This does mean that the desugaring (at the `rustc_ast_lowering` level) of `async gen` blocks is a bit more involved. However, since we already need to intercept both `.await` and `yield` operators, I don't consider it much of a technical burden.

r? `@ghost`
2023-12-08 19:13:57 +00:00
Michael Goulet
1512d37af5 coro_kind -> coroutine_kind 2023-12-08 17:23:25 +00:00
bors
f39d18b7a0 Auto merge of #118527 - Nadrieril:never_patterns_parse, r=compiler-errors
never_patterns: Parse match arms with no body

Never patterns are meant to signal unreachable cases, and thus don't take bodies:
```rust
let ptr: *const Option<!> = ...;
match *ptr {
    None => { foo(); }
    Some(!),
}
```
This PR makes rustc accept the above, and enforces that an arm has a body xor is a never pattern. This affects parsing of match arms even with the feature off, so this is delicate. (Plus this is my first non-trivial change to the parser).

~~The last commit is optional; it introduces a bit of churn to allow the new suggestions to be machine-applicable. There may be a better solution? I'm not sure.~~ EDIT: I removed that commit

r? `@compiler-errors`
2023-12-08 17:08:52 +00:00
Urgau
a2ea760b88 Drop clippy::vtable_address_comparisons 2023-12-06 09:03:48 +01:00
Eric Holk
5f191ce9b9 Fix build 2023-12-04 16:46:45 -08:00
Eric Holk
594a5f18a7 Update doctest 2023-12-04 16:37:45 -08:00
Eric Holk
c9eb8c9df6 Remove bad merge 2023-12-04 14:38:10 -08:00
Eric Holk
45be5dd8e6 Option<CoroutineKind> 2023-12-04 13:03:37 -08:00
Eric Holk
b4e3b859f1 Merge Async and Gen into CoroutineKind 2023-12-04 12:48:01 -08:00
Nadrieril
7ffe1ff55f Parse a pattern with no arm 2023-12-03 12:25:46 +01:00
Philipp Krones
c9a43b18f1 Merge commit 'f0cdee4a3f094416189261481eae374b76792af1' into clippy-subtree-sync 2023-12-01 18:21:58 +01:00
Matthias Krüger
071f8f610d Rollup merge of #118157 - Nadrieril:never_pat-feature-gate, r=compiler-errors
Add `never_patterns` feature gate

This PR adds the feature gate and most basic parsing for the experimental `never_patterns` feature. See the tracking issue (https://github.com/rust-lang/rust/issues/118155) for details on the experiment.

`@scottmcm` has agreed to be my lang-team liaison for this experiment.
2023-11-29 12:34:47 +01:00
Nadrieril
02e50f03bf Add never_patterns feature gate 2023-11-29 03:58:29 +01:00
Nicholas Nethercote
684c4bfef1 Rework ast::BinOpKind::to_string and ast::UnOp::to_string.
- Rename them both `as_str`, which is the typical name for a function
  that returns a `&str`. (`to_string` is appropriate for functions
  returning `String` or maybe `Cow<'a, str>`.)
- Change `UnOp::as_str` from an associated function (weird!) to a
  method.
- Avoid needless `self` dereferences.
2023-11-28 09:42:07 +11:00
Vadim Petrochenkov
bf86fe130c rustc: hir().local_def_id_to_hir_id() -> tcx.local_def_id_to_hir_id() cleanup 2023-11-26 12:41:21 +03:00
bors
a79a7d6510 Auto merge of #118250 - petrochenkov:optdefkind, r=compiler-errors
rustc: Make `def_kind` mandatory for all `DefId`s

Prerequisite for https://github.com/rust-lang/rust/pull/118188.
2023-11-26 04:44:20 +00:00
Michael Goulet
fffee10632 Appease the clippy 2023-11-25 18:02:11 +00:00
Vadim Petrochenkov
bafa200f6e rustc: Make def_kind mandatory for all DefIds 2023-11-25 14:49:43 +03:00
Nicholas Nethercote
fa7cd2548c Update itertools to 0.11.
Because the API for `with_position` improved in 0.11 and I want to use
it.
2023-11-22 08:13:21 +11:00
Esteban Küber
82babe0303 Don't sort span_suggestions, leave that to caller 2023-11-19 17:50:45 +00:00
lcnr
8c6c542443 rename bound region instantiation
- `erase_late_bound_regions` -> `instantiate_bound_regions_with_erased`
- `replace_late_bound_regions_X` -> `instantiate_bound_regions_X`
2023-11-17 09:29:48 +00:00
Philipp Krones
6246f0446a Merge commit 'edb720b199083f4107b858a8761648065bf38d86' into clippyup 2023-11-16 19:13:24 +01:00
lcnr
9aa2330e41 finish RegionKind rename
- `ReFree` -> `ReLateParam`
- `ReEarlyBound` -> `ReEarlyParam`
2023-11-14 13:13:27 +00:00
lcnr
9ab054d714 update type flags
- `HAS_RE_LATE_BOUND` -> `HAS_RE_BOUND`
- `HAS_TY_LATE_BOUND` -> `HAS_TY_BOUND`
- `HAS_CT_LATE_BOUND` -> `HAS_CT_BOUND`
- `HAS_LATE_BOUND` -> `HAS_BOUND_VARS`
- `fn has_late_bound_regions` -> `fn has_bound_regions`
- `fnhas_non_region_late_bound` -> `fn has_non_region_bound_vars`
- `fn has_late_bound_vars` -> `fn has_bound_vars`
2023-11-13 14:13:54 +00:00
lcnr
c4971f9f65 rename ReLateBound to ReBound
other changes:
- `Region::new_late_bound` -> `Region::new_bound`
- `Region::is_late_bound` -> `Region::is_bound`
2023-11-13 14:13:54 +00:00
Dinu Blanovschi
67cc4b0cad fix clippy author and failing test 2023-11-04 21:43:18 +01:00
bors
2d9af160af Auto merge of #117507 - nnethercote:rustc_span, r=Nilstrieb
`rustc_span` cleanups

Just some things I found while looking over this crate.

r? `@oli-obk`
2023-11-03 14:57:40 +00:00
Philipp Krones
77c1e3aaa1 Merge commit '09ac14c901abc43bd0d617ae4a44e8a4fed98d9c' into clippyup 2023-11-02 17:35:56 +01:00
Nicholas Nethercote
e1ec2d5cc9 Minimize pub usage in source_map.rs.
Most notably, this commit changes the `pub use crate::*;` in that file
to `use crate::*;`. This requires a lot of `use` items in other crates
to be adjusted, because everything defined within `rustc_span::*` was
also available via `rustc_span::source_map::*`, which is bizarre.

The commit also removes `SourceMap::span_to_relative_line_string`, which
is unused.
2023-11-02 19:35:00 +11:00
Oli Scherer
0c8caee7b9 Add gen blocks to ast and do some broken ast lowering 2023-10-27 13:05:48 +00:00
Oli Scherer
c337899be6 Rename AsyncCoroutineKind to CoroutineSource
similar to how we have `MatchSource`, it explains where the desugaring came from.
2023-10-25 16:14:05 +00:00
Philipp Krones
8e7d1678c4 Merge commit '2b030eb03d9e5837440b1ee0b98c50b97c0c5889' into clippyup 2023-10-21 14:16:11 +02:00
Oli Scherer
d9259fdedd s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Oli Scherer
868e513935 s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
bors
214b4d91bd Auto merge of #115214 - Urgau:rfc-3127-trim-paths, r=compiler-errors
Implement rustc part of RFC 3127 trim-paths

This PR implements (or at least tries to) [RFC 3127 trim-paths](https://github.com/rust-lang/rust/issues/111540), the rustc part. That is `-Zremap-path-scope` with all of it's components/scopes.

`@rustbot` label: +F-trim-paths
2023-10-19 19:09:29 +00:00
Urgau
09535a5d30 [RFC 3127 - Trim Paths]: Fix building tools (rustdoc, clippy, ...) 2023-10-17 10:11:31 +02:00
Arthur Lafrance
9ee26d078d fix lint failures in clippy 2023-10-16 19:50:31 -07:00
Nicholas Nethercote
359fa9822b Rejig some top-level rustc_hir_pretty functions.
There are several that are unused and can be removed.

And there are some calls to `to_string`, which can be expressed more
nicely as a `foo_to_string` call, and then `to_string` need not be
`pub`. (This requires adding `pat_to_string`).
2023-10-10 14:08:12 +11:00
bors
56400a0650 Auto merge of #116437 - nnethercote:rustc_features, r=Nilstrieb
Clean up `rustc_features`

Plenty more to be done, but this is a decent start.

r? `@Nilstrieb`
2023-10-07 19:11:17 +00:00
Matthias Krüger
0ed398eaa4 Rollup merge of #116423 - eltociear:patch-22, r=flip1995
Fix typo in attrs.rs

documenation -> documentation
2023-10-06 21:17:49 +02:00
Philipp Krones
8ebed4cc1a Merge commit 'b105fb4c39bc1a010807a6c076193cef8d93c109' into clippyup 2023-10-06 17:35:45 +02:00
Jason Newcomb
9de3e6c928 Add more diagnostic items for clippy 2023-10-05 18:21:47 -04:00
Nicholas Nethercote
010a9b1e60 Rename Features::active_features.
The word "active" is currently used in two different and confusing ways:
- `ACTIVE_FEATURES` actually means "available unstable features"
- `Features::active_features` actually means "features declared in the
  crate's code", which can include feature within `ACTIVE_FEATURES` but
  also others.

(This is also distinct from "enabled" features which includes declared
features but also some edition-specific features automatically enabled
depending on the edition in use.)

This commit changes the `Features::active_features` to
`Features::declared_features` which actually matches its meaning.
Likewise, `Features::active` becomes `Features::declared`.
2023-10-05 18:01:11 +11:00
Michael Goulet
56794fa5f1 Fix clippy 2023-10-04 21:09:54 +00:00