Commit Graph

1298 Commits

Author SHA1 Message Date
Yuki Okushi
59ae7957b0
Rollup merge of #78155 - est31:rustc_lint_types_refactor, r=davidtwco
Fix two small issues in compiler/rustc_lint/src/types.rs

Two small improvements of `compiler/rustc_lint/src/types.rs`
2020-10-22 09:45:38 +09:00
Yuki Okushi
ae95005ecc
Rollup merge of #77976 - oliviacrain:issue-77915-fix, r=matthewjasper
Mark inout asm! operands as used in liveness pass

Variables used in `inout` operands in inline assembly (that is, they're used as both input and output to some arbitrary assembly instruction) are being marked as read and written, but are not marked as being used in the RWU table during the liveness pass. This can result in such expressions triggering an unused variable lint warning. This is incorrect behavior- reads without uses are currently only used for compound assignments. We conservatively assume that an `inout` operand is being read and used in the context of the assembly instruction.

Closes #77915
2020-10-22 09:45:33 +09:00
Yuki Okushi
813066c442
Rollup merge of #77554 - varkor:mangle-int-char, r=eddyb
Support signed integers and `char` in v0 mangling

Likely we want more tests, to check the output is correct too: however, I wasn't sure what kind of test we needed, so I just added one similar to that added in https://github.com/rust-lang/rust/pull/77452 for now.

r? @eddyb
2020-10-22 09:45:31 +09:00
Yuki Okushi
6245b951d5
Rollup merge of #77420 - ecstatic-morse:const-checking-raw-mut-ref, r=davidtwco
Unify const-checking structured errors for `&mut` and `&raw mut`

Resolves #77414 as well as a FIXME.
2020-10-22 09:45:25 +09:00
bors
1eaadebb3d Auto merge of #78077 - petrochenkov:qvis, r=davidtwco
Calculate visibilities once in resolve

Then use them through a query based on resolver outputs.

Item visibilities were previously calculated in three places - initially in `rustc_resolve`, then in `rustc_privacy` during type privacy checkin, and then in `rustc_metadata` during metadata encoding.
The visibility logic is not entirely trivial, especially for things like constructors or enum variants, and all of it was duplicated.

This PR deduplicates all the visibility calculations, visibilities are determined once during early name resolution and then stored in `ResolverOutputs` and are later available through `tcx` as a query `tcx.visibility(def_id)`.
(This query existed previously, but only worked for other crates.)

Some special cases (e.g. visibilities for closure types, which are needed for type privacy checking) are not processed in resolve, but deferred and performed directly in the query instead.
2020-10-21 20:23:26 +00:00
varkor
878c97e70c Update to rustc-demangle 0.1.18 2020-10-21 21:11:11 +01:00
varkor
2b9d22d3a9 Update rustc-demangle 2020-10-21 21:05:38 +01:00
varkor
37c00c41f8 Do not print type for placeholder values 2020-10-21 21:05:38 +01:00
varkor
6b52603a49 Support signed integers and char in v0 mangling 2020-10-21 21:05:38 +01:00
bors
1d2726726f Auto merge of #78195 - tmiasko:instcombine, r=jonas-schievink
Disable "optimization to avoid load of address" in InstCombine

The transformation is incorrect #78192. Disable it.
2020-10-21 17:44:48 +00:00
bors
22e6b9c689 Auto merge of #77250 - Aaron1011:feature/flat-token-collection, r=petrochenkov
Rewrite `collect_tokens` implementations to use a flattened buffer

Instead of trying to collect tokens at each depth, we 'flatten' the
stream as we go allong, pushing open/close delimiters to our buffer
just like regular tokens. One capturing is complete, we reconstruct a
nested `TokenTree::Delimited` structure, producing a normal
`TokenStream`.

The reconstructed `TokenStream` is not created immediately - instead, it is
produced on-demand by a closure (wrapped in a new `LazyTokenStream` type). This
closure stores a clone of the original `TokenCursor`, plus a record of the
number of calls to `next()/next_desugared()`. This is sufficient to reconstruct
the tokenstream seen by the callback without storing any additional state. If
the tokenstream is never used (e.g. when a captured `macro_rules!` argument is
never passed to a proc macro), we never actually create a `TokenStream`.

This implementation has a number of advantages over the previous one:

* It is significantly simpler, with no edge cases around capturing the
  start/end of a delimited group.

* It can be easily extended to allow replacing tokens an an arbitrary
  'depth' by just using `Vec::splice` at the proper position. This is
  important for PR #76130, which requires us to track information about
  attributes along with tokens.

* The lazy approach to `TokenStream` construction allows us to easily
  parse an AST struct, and then decide after the fact whether we need a
  `TokenStream`. This will be useful when we start collecting tokens for
  `Attribute` - we can discard the `LazyTokenStream` if the parsed
  attribute doesn't need tokens (e.g. is a builtin attribute).

The performance impact seems to be neglibile (see
https://github.com/rust-lang/rust/pull/77250#issuecomment-703960604). There is a
small slowdown on a few benchmarks, but it only rises above 1% for incremental
builds, where it represents a larger fraction of the much smaller instruction
count. There a ~1% speedup on a few other incremental benchmarks - my guess is
that the speedups and slowdowns will usually cancel out in practice.
2020-10-21 15:03:14 +00:00
Yuki Okushi
de24210ebf
Rollup merge of #78118 - spastorino:inline-const-followups, r=petrochenkov
Inline const followups

r? @petrochenkov

Follow ups of #77124
2020-10-21 13:59:44 +09:00
Yuki Okushi
83f126bedf
Rollup merge of #78101 - RalfJung:foreign-static, r=oli-obk
fix static_ptr_ty for foreign statics

Cc https://github.com/rust-lang/rust/issues/74840

This does not fix that issue but fixes a problem in `static_ptr_ty` that we noticed while discussing that issue. I also added and updated a few comments. The one about `internal` locals being ignored does not seem to have been true [even in the commit that introduced it](https://github.com/rust-lang/rust/pull/44700/files#diff-ae2f3c7e2f9744f7ef43e96072b10e98d4e3fe74a3a399a3ad8a810fbe56c520R139).

r? @oli-obk
2020-10-21 13:59:43 +09:00
Yuki Okushi
89c98cd6b4
Rollup merge of #78063 - camelid:improve-cannot-multiply-error, r=estebank
Improve wording of "cannot multiply" type error

For example, if you had this code:

    fn foo(x: i32, y: f32) -> f32 {
        x * y
    }

You would get this error:

    error[E0277]: cannot multiply `f32` to `i32`
     --> src/lib.rs:2:7
      |
    2 |     x * y
      |       ^ no implementation for `i32 * f32`
      |
      = help: the trait `Mul<f32>` is not implemented for `i32`

However, that's not usually how people describe multiplication. People
usually describe multiplication like how the division error words it:

    error[E0277]: cannot divide `i32` by `f32`
     --> src/lib.rs:2:7
      |
    2 |     x / y
      |       ^ no implementation for `i32 / f32`
      |
      = help: the trait `Div<f32>` is not implemented for `i32`

So that's what this change does. It changes this:

    error[E0277]: cannot multiply `f32` to `i32`
     --> src/lib.rs:2:7
      |
    2 |     x * y
      |       ^ no implementation for `i32 * f32`
      |
      = help: the trait `Mul<f32>` is not implemented for `i32`

To this:

    error[E0277]: cannot multiply `i32` by `f32`
     --> src/lib.rs:2:7
      |
    2 |     x * y
      |       ^ no implementation for `i32 * f32`
      |
      = help: the trait `Mul<f32>` is not implemented for `i32`
2020-10-21 13:59:39 +09:00
Yuki Okushi
9583029a2d
Rollup merge of #78002 - estebank:issue-77598, r=oli-obk
Tweak "object unsafe" errors

CC #77598.
2020-10-21 13:59:35 +09:00
Tomasz Miąsko
e200a4a0d2 Disable "optimization to avoid load of address" in InstCombine 2020-10-21 00:00:00 +00:00
Guillaume Gomez
0c2dbb2a18
Rollup merge of #78145 - LingMan:ast_pretty_mut, r=jonas-schievink
Drop unneeded `mut`

These parameters don't get modified.

Note that `trailing_comment` is pub and gets exported from `rustc_ast_pretty`. Is that considered to be a stable API? If yes, and you want to reserve the right to modify `self` in `trailing_comment` in the future, that hunk would need to be dropped.
2020-10-20 21:46:42 +02:00
Guillaume Gomez
ad218f9bb9
Rollup merge of #78144 - bugadani:elements-nodrop, r=oli-obk
Don't update `entries` in `TypedArena` if T does not need drop

As far as I can tell, `entries` is only used when dropping `TypedArenaChunk`s and their contents. It is already ignored there, if T is not `mem::needs_drop`, this PR just skips updating it's value.

You can see `TypedArenaChunk` ignoring the entry count in L71. The reasoning is similar to what you can find in `DroplessArena`.

r? @oli-obk
2020-10-20 21:46:40 +02:00
Guillaume Gomez
01e6019448
Rollup merge of #78076 - est31:orphan_mod, r=Mark-Simulacrum
Move orphan module-name/mod.rs files into module-name.rs files
2020-10-20 21:46:35 +02:00
Guillaume Gomez
3fea201b11
Rollup merge of #78061 - wesleywiser:opt_zst_const_interning, r=oli-obk
Optimize const value interning for ZST types

Interning can skip any inhabited ZST type in general.

Fixes #68010

r? @oli-obk
2020-10-20 21:46:32 +02:00
est31
00d23cf220 Make {u,}int_range functions a bit nicer
.into() guarantees safety of the conversion.
Furthermore, the minimum value of all uints is known to be 0.
2020-10-20 19:36:44 +02:00
est31
c647735f40 rustc_lint: remove unused to_string
In this instance, we can just pass a &str slice
and save an allocation.
2020-10-20 19:30:09 +02:00
Esteban Küber
88f5e110db review comments 2020-10-20 09:26:15 -07:00
Esteban Küber
ae0e3d0511 Tweak "object unsafe" errors
Fix #77598.
2020-10-20 09:26:14 -07:00
Dániel Buga
2705caed8a Track element count only for types that need drop 2020-10-20 17:01:51 +02:00
LingMan
13f0f49a4e Drop unneeded mut
These parameters don't get modified.
2020-10-20 16:42:51 +02:00
bors
9832374f6e Auto merge of #76893 - lcnr:existential-proj, r=estebank
Improve `skip_binder` usage during FlagComputation

It looks like there was previously a bug around `ExistentialPredicate::Projection` here, don't know how to best trigger that one to add a regression test though.
2020-10-20 08:59:12 +00:00
bors
554633534c Auto merge of #76696 - Aaron1011:tokenstream-avoid-clone, r=petrochenkov
Avoid cloning the contents of a `TokenStream` in a few places
2020-10-20 05:45:08 +00:00
Yuki Okushi
21df410a62
Rollup merge of #78121 - LeSeulArtichaut:issue-78115, r=tmandry
Do not ICE on pattern that uses a binding multiple times in generator

Fixes #78115.
r? @tmandry
2020-10-20 12:11:13 +09:00
Yuki Okushi
3f1c637db4
Rollup merge of #78111 - SNCPlay42:not-always-self, r=lcnr
Trait predicate ambiguities are not always in `Self`

When reporting ambiguities in trait predicates, the compiler incorrectly assumed the ambiguity was always in the type the trait should be implemented on, and never the generic parameters of the trait. This caused silly suggestions for predicates like `<KnownType as Trait<_>>`, such as giving explicit types to completely unrelated variables that happened to be of type `KnownType`.

This also reverts #73027, which worked around this issue in some cases and does not appear to be necessary any more.

fixes #77982
fixes #78055
2020-10-20 12:11:11 +09:00
Yuki Okushi
378ca5e640
Rollup merge of #77931 - aticu:fix_60336, r=petrochenkov
Fix false positive for `unused_parens` lint

Fixes #60336
2020-10-20 12:11:06 +09:00
Tomasz Miąsko
c2af254e3b Disable MatchBranchSimplification
This optimization can result in unsoundness, because it introduces
additional uses of a place holding the discriminant value without
ensuring that it is valid to do so.
2020-10-20 00:00:00 +00:00
Santiago Pastorino
d641cb82c1
Allow NtBlock to parse on check inline const next token 2020-10-19 18:50:58 -03:00
LeSeulArtichaut
66ac5a2d63 Do not ICE on pattern that uses a binding multiple times in generator 2020-10-19 23:34:47 +02:00
SNCPlay42
c146e8c54f revert workaround #73027 2020-10-19 21:11:40 +01:00
SNCPlay42
71ca239f80 don't assume trait ambiguity happens in Self 2020-10-19 21:11:40 +01:00
Santiago Pastorino
9dd0bb6fbc
Do not print braces again print_anon_const already does it 2020-10-19 16:26:13 -03:00
Aaron Hill
593fdd3d45
Rewrite collect_tokens implementations to use a flattened buffer
Instead of trying to collect tokens at each depth, we 'flatten' the
stream as we go allong, pushing open/close delimiters to our buffer
just like regular tokens. One capturing is complete, we reconstruct a
nested `TokenTree::Delimited` structure, producing a normal
`TokenStream`.

The reconstructed `TokenStream` is not created immediately - instead, it is
produced on-demand by a closure (wrapped in a new `LazyTokenStream` type). This
closure stores a clone of the original `TokenCursor`, plus a record of the
number of calls to `next()/next_desugared()`. This is sufficient to reconstruct
the tokenstream seen by the callback without storing any additional state. If
the tokenstream is never used (e.g. when a captured `macro_rules!` argument is
never passed to a proc macro), we never actually create a `TokenStream`.

This implementation has a number of advantages over the previous one:

* It is significantly simpler, with no edge cases around capturing the
  start/end of a delimited group.

* It can be easily extended to allow replacing tokens an an arbitrary
  'depth' by just using `Vec::splice` at the proper position. This is
  important for PR #76130, which requires us to track information about
  attributes along with tokens.

* The lazy approach to `TokenStream` construction allows us to easily
  parse an AST struct, and then decide after the fact whether we need a
  `TokenStream`. This will be useful when we start collecting tokens for
  `Attribute` - we can discard the `LazyTokenStream` if the parsed
  attribute doesn't need tokens (e.g. is a builtin attribute).

The performance impact seems to be neglibile (see
https://github.com/rust-lang/rust/pull/77250#issuecomment-703960604). There is a
small slowdown on a few benchmarks, but it only rises above 1% for incremental
builds, where it represents a larger fraction of the much smaller instruction
count. There a ~1% speedup on a few other incremental benchmarks - my guess is
that the speedups and slowdowns will usually cancel out in practice.
2020-10-19 13:59:18 -04:00
bors
a85e949276 Auto merge of #78106 - GuillaumeGomez:rollup-06vwk7p, r=GuillaumeGomez
Rollup of 4 pull requests

Successful merges:

 - #77877 (Use `try{}` in `try_fold` to decouple iterators in the library from `Try` details)
 - #78089 (Fix issue with specifying generic arguments for primitive types)
 - #78099 (Add missing punctuation)
 - #78103 (Add link to rustdoc book in rustdoc help popup)

Failed merges:

r? `@ghost`
2020-10-19 17:53:17 +00:00
Aaron Hill
f6aec82d4d
Avoid cloning the contents of a TokenStream in a few places 2020-10-19 12:30:41 -04:00
Guillaume Gomez
684fbd50ab
Rollup merge of #78089 - varkor:opt_const_param_of-error, r=lcnr
Fix issue with specifying generic arguments for primitive types

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

r? @lcnr
2020-10-19 18:20:23 +02:00
bors
f90e617305 Auto merge of #77908 - bugadani:obl-forest, r=nnethercote
Try to make ObligationForest more efficient

This PR tries to decrease the number of allocations in ObligationForest, as well as moves some cold path code to an uninlined function.
2020-10-19 15:14:15 +00:00
Ralf Jung
153e843c49 fix Rvalue::ty for ThreadLocalRef 2020-10-19 11:44:28 +02:00
Vadim Petrochenkov
cee5521a03 Calculate visibilities once in resolve
Then use them through a query based on resolver outputs
2020-10-19 11:57:50 +03:00
Ralf Jung
c1766c6372 fix static_ptr_ty for foreign statics, and more comments in check_unsafety 2020-10-19 09:47:18 +02:00
Ralf Jung
cb33f956c3 remove what seems to be an outdated comment
Even in the PR that introduced this comment, it does not seem like these locals are actually ignored -- just their `source_info` is adjusted:
https://github.com/rust-lang/rust/pull/44700/files#diff-ae2f3c7e2f9744f7ef43e96072b10e98d4e3fe74a3a399a3ad8a810fbe56c520R139
2020-10-19 09:46:18 +02:00
Olivia Crain
17c6c5932c Mark InOut operands as used in RWU table with write_place 2020-10-18 23:51:10 -05:00
bors
78307d8700 Auto merge of #77278 - camelid:use-correct-article, r=estebank
Use correct article in help message for conversion or cast

Before it always used `an`; now it uses the correct article for the type.
2020-10-19 02:19:21 +00:00
Camelid
3eab21e22d Don't ICE if called with a TyKind::Error
It felt too harsh to estebank and others to ICE even though it's
technically a mistake to show a `TyKind::Error`.
2020-10-18 17:38:47 -07:00
varkor
c0d29fe7d7 Fix issue with specifying generic arguments for primitive types 2020-10-18 22:40:50 +01:00