Commit Graph

788 Commits

Author SHA1 Message Date
Camille GILLOT
d7ea161b7e Remove DefId from AssocItemContainer. 2022-08-01 21:38:45 +02:00
Matthias Krüger
8db3d7cfb6
Rollup merge of #99911 - cjgillot:no-guess, r=davidtwco
Remove some uses of `guess_head_span`

That function cuts a span at the first occurrence of `{`.  Using `def_span` is almost always more precise.
2022-08-01 16:49:31 +02:00
Ding Xiang Fei
8467a7b33e
provide a clearer explanation of scope breaking 2022-07-31 20:37:30 +08:00
Dylan DPC
403c1b3802
Rollup merge of #99186 - camsteffen:closure-localdefid, r=cjgillot
Use LocalDefId for closures more
2022-07-31 17:36:40 +05:30
Cameron Steffen
cf2433a74f Use LocalDefId for closures more 2022-07-30 15:59:17 -05:00
Ding Xiang Fei
02443552c5
break out to one scope higher for let-else 2022-07-31 00:02:47 +08:00
Dylan DPC
c668820365
Rollup merge of #99311 - kckeiks:clean-up-body-owner-methods, r=cjgillot
change maybe_body_owned_by to take local def id

Issue https://github.com/rust-lang/rust/issues/96341
r? `@cjgillot`
2022-07-30 20:39:46 +05:30
Yuki Okushi
955091be8f
Rollup merge of #99518 - dingxiangfei2009:let-else-additional-tests, r=oli-obk
Let-else: break out scopes when a let-else pattern fails to match

This PR will commit to a new behavior so that values from initializer expressions are dropped earlier when a let-else pattern fails to match.

Fix #98672.
Close #93951.
cc `@camsteffen` `@est31`
2022-07-30 07:39:49 +09:00
Miguel Guarniz
0c609a4c1f Change enclosing_body_owner to return LocalDefId
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-07-29 18:26:10 -04:00
Miguel Guarniz
16513d689e Rename local_did to def_id
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-07-29 18:26:10 -04:00
Miguel Guarniz
25bdc8965e Change maybe_body_owned_by to take local def id
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-07-29 18:25:58 -04:00
Camille GILLOT
a09b7ebfd3 Use DefKind instead of FnKind for recursion lint. 2022-07-29 18:10:43 +02:00
Camille GILLOT
6733bc3066 Remove guess_head_span. 2022-07-28 23:14:04 +02:00
Oli Scherer
803d374f9b Pass PatCtxt instead of passing MatchCtxt + Ty separately 2022-07-28 08:49:39 +00:00
Oli Scherer
544de44a6b Don't pass (the rather large) PatCtxt by value 2022-07-28 08:44:49 +00:00
Oli Scherer
970ff3d45d Move constructor into the branch that actually uses it 2022-07-28 08:33:36 +00:00
Guillaume Gomez
9e7b7d5e1c
Rollup merge of #99651 - compiler-errors:fn-and-raw-ptr-in-const-generics, r=oli-obk
Deeply deny fn and raw ptrs in const generics

I think this is right -- just because we wrap a fn ptr in a wrapper type does not mean we should allow it in a const parameter.

We now reject both of these in the same way:

```
#![feature(adt_const_params)]

#[derive(Eq, PartialEq)]
struct Wrapper();

fn foo<const W: Wrapper>() {}

fn foo2<const F: fn()>() {}
```

This does regress one test (`src/test/ui/consts/refs_check_const_eq-issue-88384.stderr`), but I'm not sure it should've passed in the first place.

cc: ``@b-naber`` who introduced that test^
fixes #99641
2022-07-27 17:55:04 +02:00
Takayuki Maeda
051e98b7bf avoid &str/Symbol to String conversions 2022-07-25 22:40:00 +09:00
Michael Goulet
10b69ab0d2 Remove non-descriptive boolean from search_for_structural_match_violation 2022-07-25 03:39:23 +00:00
Michael Goulet
c1f54c30bb Get rid of redundant NonStructuralMatchTyKind 2022-07-25 03:39:22 +00:00
Michael Goulet
1152e70363 Deeply deny fn and raw ptrs in const generics 2022-07-25 03:39:22 +00:00
Ding Xiang Fei
9b56640106
break out scopes when let-else fails to match 2022-07-21 00:35:43 +08:00
Oli Scherer
4a742a691e Revert "Rollup merge of #98582 - oli-obk:unconstrained_opaque_type, r=estebank"
This reverts commit 6f8fb911ad, reversing
changes made to 7210e46dc6.
2022-07-20 07:55:58 +00:00
Michael Goulet
6d2bd541e0 use body's param-env when checking if type needs drop 2022-07-17 10:56:12 -07:00
Caio
3266460749 Stabilize let_chains 2022-07-16 20:17:58 -03:00
Oli Scherer
57e9f7a556 Infer wildcard type from other patterns at every pattern level 2022-07-15 15:56:17 +00:00
Oli Scherer
92e470a1de Move constructor into the branch that actually uses it 2022-07-15 15:56:17 +00:00
Oli Scherer
ea68ce7fac Revert a hack that only ever worked on level deep 2022-07-15 15:56:17 +00:00
Oli Scherer
728c7e8bda Allow destructuring opaque types, since the patterns constrain the opaque types 2022-07-15 15:56:17 +00:00
Oli Scherer
12457f814c Some tracing helpers 2022-07-15 15:56:16 +00:00
Oli Scherer
0c6918fe21 Reuse a helper method instead of manually rolling it 2022-07-15 15:56:16 +00:00
Oli Scherer
7a8a048b58 Remove early return that would likely have caused miscompilations if it ever happened 2022-07-15 15:56:16 +00:00
Oli Scherer
eeb10335ce Pass one argument instead of fetching two fields of it at every call site 2022-07-15 15:56:16 +00:00
Oli Scherer
a034446fae Add some tracing instrumentation 2022-07-15 15:56:16 +00:00
Oli Scherer
84a444a1f4 Introduce opaque type to hidden type projection 2022-07-15 15:49:22 +00:00
bors
f1a8854f9b Auto merge of #99231 - Dylan-DPC:rollup-0tl8c0o, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #97720 (Always create elided lifetime parameters for functions)
 - #98315 (Stabilize `core::ffi:c_*` and rexport in `std::ffi`)
 - #98705 (Implement `for<>` lifetime binder for closures)
 - #99126 (remove allow(rustc::potential_query_instability) in rustc_span)
 - #99139 (Give a better error when `x dist` fails for an optional tool)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-14 11:00:30 +00:00
Dylan DPC
e5a86d7358
Rollup merge of #98705 - WaffleLapkin:closure_binder, r=cjgillot
Implement `for<>` lifetime binder for closures

This PR implements RFC 3216 ([TI](https://github.com/rust-lang/rust/issues/97362)) and allows code like the following:

```rust
let _f = for<'a, 'b> |a: &'a A, b: &'b B| -> &'b C { b.c(a) };
//       ^^^^^^^^^^^--- new!
```

cc ``@Aaron1011`` ``@cjgillot``
2022-07-14 14:14:21 +05:30
bors
0ed9c64c3e Auto merge of #98975 - jyn514:unstable_opts, r=wesleywiser
Rename `debugging_opts` to `unstable_opts`

This is no longer used only for debugging options (e.g. `-Zoutput-width`, `-Zallow-features`).
Rename it to be more clear.

cc https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Codegen.20options.20.2F.20debugging.20options

r? `@Amanieu` cc `@nikic` `@joshtriplett`
2022-07-14 08:14:31 +00:00
Joshua Nelson
3c9765cff1 Rename debugging_opts to unstable_opts
This is no longer used only for debugging options (e.g. `-Zoutput-width`, `-Zallow-features`).
Rename it to be more clear.
2022-07-13 17:47:06 -05:00
Ralf Jung
e4593ef0f2 assigning to a union field can never drop now 2022-07-13 18:27:28 -04:00
Maybe Waffle
df4fee9841 Add an indirection for closures in hir::ExprKind
This helps bring `hir::Expr` size down, `Closure` was the biggest
variant, especially after `for<>` additions.
2022-07-12 21:00:13 +04:00
Ding Xiang Fei
5374688e1d
add tests for async await 2022-07-11 23:20:39 +02:00
Ding Xiang Fei
1cd30e7b32
move else block into the Local struct 2022-07-11 23:20:37 +02:00
Ding Xiang Fei
6c529ded86
lower let-else in MIR instead 2022-07-11 23:20:36 +02:00
Dylan DPC
9fc297a2ae
Rollup merge of #99140 - TaKO8Ki:implement-is-accessible-span, r=fee1-dead
Implement `SourceMap::is_span_accessible`

This patch adds `SourceMap::is_span_accessible` and replaces `span_to_snippet(span).is_ok()` and `span_to_snippet(span).is_err()` with it. This removes a `&str` to `String` conversion.
2022-07-11 15:19:32 +05:30
Takayuki Maeda
018155c3a2 rename a method 2022-07-11 16:51:19 +09:00
Takayuki Maeda
12d11e9a35 implement is_accessible_span 2022-07-11 11:36:15 +09:00
Michael Goulet
a1634642e0 Deny floats even when adt_const_params is enabled 2022-07-11 00:04:00 +00:00
Audun Halland
2036aea18e Determine match_has_guard from candidates instead of looking up thir table again 2022-07-10 11:27:36 +02:00
Ralf Jung
4e7aaf1f44 tweak names and output and bless 2022-07-09 07:43:56 -04:00
Ralf Jung
ac265cdc19 review feedback 2022-07-09 07:27:29 -04:00
Ralf Jung
a422b42159 don't allow ZST in ScalarInt
There are several indications that we should not ZST as a ScalarInt:
- We had two ways to have ZST valtrees, either an empty `Branch` or a `Leaf` with a ZST in it.
  `ValTree::zst()` used the former, but the latter could possibly arise as well.
- Likewise, the interpreter had `Immediate::Uninit` and `Immediate::Scalar(Scalar::ZST)`.
- LLVM codegen already had to special-case ZST ScalarInt.

So instead add new ZST variants to those types that did not have other variants
which could be used for this purpose.
2022-07-09 07:27:29 -04:00
Tomasz Miąsko
c9dd1d9983 Make MIR basic blocks field public
This makes it possible to mutably borrow different fields of the MIR
body without resorting to methods like `basic_blocks_local_decls_mut_and_var_debug_info`.

To preserve validity of control flow graph caches in the presence of
modifications, a new struct `BasicBlocks` wraps together basic blocks
and control flow graph caches.

The `BasicBlocks` dereferences to `IndexVec<BasicBlock, BasicBlockData>`.
On the other hand a mutable access requires explicit `as_mut()` call.
2022-07-07 08:11:49 +02:00
Alan Egerton
4f0a64736b
Update TypeVisitor paths 2022-07-06 06:41:53 +01:00
bors
54f79babae Auto merge of #98925 - Dylan-DPC:rollup-9185c9y, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #97712 (ptr::copy and ptr::swap are doing untyped copies)
 - #98624 (lints: mostly translatable diagnostics)
 - #98776 (rustdoc: improve click behavior of the source code mobile full-screen "sidebar")
 - #98856 (Remove FIXME from rustdoc intra-doc test)
 - #98913 (⬆️ rust-analyzer)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-05 12:17:26 +00:00
Dylan DPC
291df97fae
Rollup merge of #98624 - davidtwco:translation-on-lints, r=compiler-errors
lints: mostly translatable diagnostics

As lints are created slightly differently than other diagnostics, intended to try make them translatable first and then look into the applicability of diagnostic structs but ended up just making most of the diagnostics in the crate translatable (which will still be useful if I do make a lot of them structs later anyway).

r? ``@compiler-errors``
2022-07-05 16:04:32 +05:30
bors
53792b9c5c Auto merge of #96862 - oli-obk:enum_cast_mir, r=RalfJung
Change enum->int casts to not go through MIR casts.

follow-up to https://github.com/rust-lang/rust/pull/96814

this simplifies all backends and even gives LLVM more information about the return value of `Rvalue::Discriminant`, enabling optimizations in more cases.
2022-07-05 09:36:29 +00:00
Oli Scherer
82c73af4a6 Prefer trace level instrumentation for the new noisy instrument attributes 2022-07-05 09:27:06 +00:00
Dylan DPC
d287726aa0
Rollup merge of #98639 - camsteffen:no-node-binding, r=compiler-errors
Factor out `hir::Node::Binding`
2022-07-02 12:23:38 +05:30
Cameron Steffen
ec82bc1996 Factor out hir::Node::Binding 2022-07-01 10:04:19 -05:00
bors
5b9775fe17 Auto merge of #98402 - cjgillot:undead, r=michaelwoerister
Rewrite dead-code pass to avoid fetching HIR.

This allows to get a more uniform handling of spans, and to simplify the grouping of diagnostics for variants and fields.
2022-07-01 14:43:15 +00:00
David Wood
7d2eba6311 middle: translation in LintDiagnosticBuilder
Accept `DiagnosticMessage` in `LintDiagnosticBuilder::build` so that
lints can be built with translatable diagnostic messages.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:58:41 +01:00
Oli Scherer
7839cb963f Change enum->int casts to not go through MIR casts.
Instead we generate a discriminant rvalue and cast the result of that.
2022-06-30 07:47:07 +00:00
Matthias Krüger
d34c4ca9be
Rollup merge of #98668 - TaKO8Ki:avoid-many-&str-to-string-conversions, r=Dylan-DPC
Avoid some `&str` to `String` conversions with `MultiSpan::push_span_label`

This patch removes some`&str` to `String` conversions with `MultiSpan::push_span_label`.
2022-06-29 20:35:07 +02:00
Takayuki Maeda
6212e6b339 avoid many &str to String conversions with MultiSpan::push_span_label 2022-06-29 21:16:43 +09:00
Oli Scherer
0e674b3ec5 Some tracing cleanups 2022-06-29 09:56:30 +00:00
bors
66c83ffca1 Auto merge of #98558 - nnethercote:smallvec-1.8.1, r=lqd
Update `smallvec` to 1.8.1.

This pulls in https://github.com/servo/rust-smallvec/pull/282, which
gives some small wins for rustc.

r? `@lqd`
2022-06-29 09:11:29 +00:00
Michael Goulet
8fd73560b3 Do not use a suggestion to change a binding's name to a type 2022-06-28 22:34:13 +00:00
Nicholas Nethercote
7c40661ddb Update smallvec to 1.8.1.
This pulls in https://github.com/servo/rust-smallvec/pull/282, which
gives some small wins for rustc.
2022-06-27 08:48:55 +10:00
Matthias Krüger
ea07b969ea
Rollup merge of #98429 - b-naber:use-correct-substs-discriminant-cast, r=lcnr
Use correct substs in enum discriminant cast

Fixes https://github.com/rust-lang/rust/issues/97634

r? ```@lcnr```
2022-06-25 15:14:13 +02:00
b-naber
bf48b622a5 fmt 2022-06-24 16:43:38 +02:00
b-naber
f39c0d6b0a address review 2022-06-24 13:43:56 +02:00
b-naber
38814fc039 small refactor 2022-06-24 13:19:23 +02:00
ouz-a
661d488bfd use true recursion 2022-06-24 14:16:48 +03:00
b-naber
2e3221a927 use correct substs in enum discriminant hack 2022-06-24 11:11:40 +02:00
Camille GILLOT
2d82234331 Remove dead code. 2022-06-23 22:16:50 +02:00
Matthias Krüger
3e5800b8d3
Rollup merge of #98267 - compiler-errors:suggest-wildcard-arm, r=oli-obk
Don't omit comma when suggesting wildcard arm after macro expr

* Also adds `Span::eq_ctxt` to consolidate the various usages of `span.ctxt() == other.ctxt()`
* Also fixes an unhygenic usage of spans which caused the suggestion to render weirdly when we had one arm match in a macro
* Also always suggests a comma (i.e. even after a block) if we're rendering a wildcard arm in a single-line match (looks prettier 🌹)

Fixes #94866
2022-06-20 20:13:10 +02:00
bors
9a0b774966 Auto merge of #97931 - xldenis:fix-if-let-source-scopes, r=nagisa
Fix `SourceScope` for `if let` bindings.

Fixes #97799.

I'm not sure how to test this properly, is there any way to observe the difference in behavior apart from `ui` tests? I'm worried that they would be overlooked in the case of a regression.
2022-06-20 03:08:52 +00:00
Michael Goulet
3d16c22864 Be more hygenic with spans 2022-06-19 16:47:21 -07:00
Michael Goulet
52c9906c4b Use Span::eq_ctxt method instead of .ctxt() == .ctxt() 2022-06-19 16:46:59 -07:00
Michael Goulet
2c3bb42ebd Only omit trailing comma if block doesn't come from macro expansion 2022-06-19 16:46:37 -07:00
ouz-a
90abfe9ce2 expand inner or pattern 2022-06-17 21:38:26 +03:00
Nicholas Nethercote
bdbf9b297b compare_const_vals: add a special case for certain ranges.
This commit removes the `a == b` early return, which isn't useful in
practice, and replaces it with one that helps matches with many ranges,
including char ranges.
2022-06-16 11:25:34 +10:00
Nicholas Nethercote
73c52b724a compare_const_vals: Use infallible evaluation.
Because these evaluations can never fail.
2022-06-16 10:52:58 +10:00
Nicholas Nethercote
246a5e08bf Remove ty arg from compare_const_vals.
It's now only used in no-longer-interesting assertion.
2022-06-16 10:52:58 +10:00
Nicholas Nethercote
3ab6ef1938 Remove from_bool closure.
The code is clearer and simpler without it. Note that the `a == b` early
return at the top of the function means the `a == b` test at the end of
the function could never succeed.
2022-06-16 10:52:58 +10:00
Nicholas Nethercote
fab85ddbeb Inline and remove fallback closure. 2022-06-16 10:52:58 +10:00
Nicholas Nethercote
b67635fdfd Remove one use of compare_const_vals.
A direct comparison has the same effect. This also avoids the need for a
type test within `compare_const_vals`.
2022-06-16 10:52:58 +10:00
Nicholas Nethercote
9b4b34a0a6 Assert type equality of a and b in compare_const_vals.
Because they're always equal.
2022-06-16 10:52:58 +10:00
Nicholas Nethercote
d5a13e2ca0 Remove dead code from compare_const_vals.
It's never executed when running the entire test suite. I think it's
because of the early return at the top of the function if `a.ty() != ty`
succeeds.
2022-06-16 10:52:56 +10:00
Nicholas Nethercote
be6c364142 simplify_match_pair: avoid the second comparison if possible.
Also, the `try_to_bits` always succeeds, so use `unwrap`.
2022-06-16 10:52:19 +10:00
Nicholas Nethercote
c4cd04480b sort_candidates: avoid the second comparison if possible.
This is a performance win for `unicode-normalization`.

The commit also removes the closure, which isn't necessary. And
reformulates the comparison into a form I find easier to read.
2022-06-16 10:52:19 +10:00
Nicholas Nethercote
7e4ec35d0c const_range_contains: avoid the second comparison if possible.
This is a performance win for `unicode-normalization`.

Also, I find the new formulation easier to read.
2022-06-16 10:52:19 +10:00
Yuki Okushi
87e373e82f
Rollup merge of #98110 - cjgillot:closure-brace, r=Aaron1011
Make `ExprKind::Closure` a struct variant.

Simple refactor since we both need it to introduce additional fields in `ExprKind::Closure`.

r? ``@Aaron1011``
2022-06-15 19:37:14 +09:00
Xavier Denis
a5e27a1134 Only create scopes for if let 2022-06-14 18:45:33 -07:00
b-naber
060acc97db rebase 2022-06-14 16:12:28 +02:00
b-naber
773d8b2e15 address review 2022-06-14 16:11:27 +02:00
b-naber
dbef6e4507 address review 2022-06-14 16:08:18 +02:00
b-naber
5c95a3db2a fix clippy test failures 2022-06-14 16:08:11 +02:00
b-naber
705d818bd5 implement valtrees as the type-system representation for constant values 2022-06-14 16:07:11 +02:00