Commit graph

3827 commits

Author SHA1 Message Date
Ryan Levick
8ea0973725 Short circuit full corherence check when dealing with types with different reference mutability 2021-02-12 14:04:09 +01:00
LingMan
fde59a8cb7 Use Iterator::all instead of open-coding it
Shorter code and by initializing to the final value directly, the variable
doesn't need to be mut.
2021-02-12 14:02:35 +01:00
Yuki Okushi
ff8b7f20d9
Rollup merge of #82017 - eltociear:patch-8, r=jyn514
Fix typo in mod.rs

insted -> instead
2021-02-12 19:32:22 +09:00
Yuki Okushi
55539cbdc0
Rollup merge of #82003 - ojeda:stack-probe-msg, r=estebank
Stack probes: fix error message
2021-02-12 19:32:17 +09:00
Yuki Okushi
44d28717da
Rollup merge of #81994 - jesusprubio:improve-long-explanation-e0542-e0546, r=GuillaumeGomez
Improve long explanation for E0542 and E0546

Helps with #61137

To keep the consistency with: https://github.com/rust-lang/rust/pull/81925
2021-02-12 19:32:15 +09:00
Yuki Okushi
46aef0e375
Rollup merge of #81990 - matsujika:suggest-mut-reference, r=estebank
Make suggestion of changing mutability of arguments broader

Fix #81421

Previously rustc tries to emit the suggestion of changing mutablity unless `!trait_ref.has_infer_types_or_consts() && self.predicate_can_apply(obligation.param_env, trait_ref)` and this led to some false negatives to occur.
2021-02-12 19:32:14 +09:00
Yuki Okushi
0b7fc80e45
Rollup merge of #81959 - therealprof:fix-typo, r=oli-obk
Fix assosiated typo

Introduced in d3c4dbd85d, noticed only
after the fact, sorry. 😅

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
2021-02-12 19:32:12 +09:00
Yuki Okushi
c07260d534
Rollup merge of #81947 - camsteffen:to-ty, r=jyn514
Relax ItemCtxt::to_ty lifetime

Tiny simplification by relaxing a lifetime.
2021-02-12 19:32:08 +09:00
LingMan
fda71d676d Push a char instead of a str with len one into a String 2021-02-12 10:27:08 +01:00
Kevin Per
fba2f883f3 Implementing more sophisticated filter for fn in const or static 2021-02-12 09:18:03 +00:00
Aman Arora
96c12f90cf fixup! Implement the precise analysis pass for lint disjoint_capture_drop_reorder 2021-02-12 04:10:17 -05:00
Ikko Ashimine
c8eeb340bc
Fix typo in mod.rs
insted -> instead
2021-02-12 13:47:21 +09:00
Miguel Ojeda
0df8ddee53 Stack probes: fix error message
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2021-02-11 20:33:16 +01:00
bors
e9920ef774 Auto merge of #81760 - tmiasko:debug-borrow, r=pnkfelix
Borrow builder only once in debug derive
2021-02-11 16:46:08 +00:00
0yoyoyo
788e4bb4e5 Fix suggestion to introduce explicit lifetime 2021-02-12 00:48:44 +09:00
Jesus Rubio
a99d869e6c Improve long explanation for E0542 and E0546 2021-02-11 16:26:07 +01:00
bors
26e5bcd220 Auto merge of #81350 - tmiasko:instrument-debug, r=lcnr
Reduce log level used by tracing instrumentation from info to debug

Restore log level to debug to avoid make info log level overly verbose (the uses of instrument attribute modified there, were for the most part a replacement for `debug!`;  one use was novel).
2021-02-11 13:44:00 +00:00
Hirochika Matsumoto
e03f09730f Make suggestion of changing mutability of arguments broader 2021-02-11 17:03:03 +09:00
bors
2918062d1d Auto merge of #81129 - bugadani:lighter-move-errors, r=petrochenkov
Borrowck: don't calculate unused info when reporting move errors
2021-02-11 07:50:02 +00:00
bors
9ce7268bcf Auto merge of #80860 - camelid:nodeid-docs, r=sanxiyn
Document `NodeId`
2021-02-11 00:51:45 +00:00
Matthew Jasper
f852160a99 Keep existing names of regions in placeholder_error 2021-02-10 20:00:36 +00:00
Vadim Petrochenkov
8e74842089 resolve: Remove visibility hacks for enum variants and trait items
Special treatment like this was necessary before `pub(restricted)` had been implemented and only two visibilities existed - `pub` and non-`pub`.
Now it's no longer necessary and the desired behavior follows from `pub(restricted)`-style visibilities naturally assigned to enum variants and trait items.
2021-02-10 22:46:44 +03:00
Vadim Petrochenkov
b4b6b62e70 resolve: Cleanup visibility resolution in enums and traits 2021-02-10 22:46:44 +03:00
Ellen
7ca96ed2af rewrite the comments 2021-02-10 13:11:22 +00:00
bors
07194ffcd2 Auto merge of #79804 - tmiasko:improper-ctypes-no-niche, r=pnkfelix
Types with a hidden niche are not known to be non-null

Fixes #79787.
2021-02-10 12:56:09 +00:00
Ömer Sinan Ağacan
d64b749f2c Allow casting mut array ref to mut ptr
We now allow two new casts:

- mut array reference to mut ptr. Example:

      let mut x: [usize; 2] = [0, 0];
      let p = &mut x as *mut usize;

  We allow casting const array references to const pointers so not
  allowing mut references to mut pointers was inconsistent.

- mut array reference to const ptr. Example:

      let mut x: [usize; 2] = [0, 0];
      let p = &mut x as *const usize;

  This was similarly inconsistent as we allow casting mut references to
  const pointers.

Existing test 'vector-cast-weirdness' updated to test both cases.

Fixes #24151
2021-02-10 15:44:41 +03:00
Daniel Egger
a6d413715c Fix assosiated typo
Introduced in d3c4dbd85d, noticed only
after the fact, sorry. 😅

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
2021-02-10 09:36:26 +01:00
Dániel Buga
3c1d792f49 Only initialize what is used 2021-02-10 09:20:41 +01:00
Ellen
0ffa2da186 comma... 2021-02-10 05:29:45 +00:00
Ellen
0422745585 Fix comment smol mistakes 2021-02-10 05:23:16 +00:00
Ellen
2c4337a70a Comments :3 2021-02-10 05:15:43 +00:00
Yuki Okushi
2e8e591a16
Rollup merge of #81926 - henryboisdequin:fix-81907, r=estebank
add suggestion to use the `async_recursion` crate

Closes #81907

CC `@estebank`
2021-02-10 12:24:30 +09:00
Yuki Okushi
40fa6fc43f
Rollup merge of #81925 - jesusprubio:add-long-explanation-e0547, r=GuillaumeGomez
Add long explanation for E0547

Helps with #61137
2021-02-10 12:24:29 +09:00
Yuki Okushi
a58feb9282
Rollup merge of #81913 - osa1:rename_unop_variants, r=matthewjasper
Rename HIR UnOp variants

This renames the variants in HIR UnOp from

    enum UnOp {
        UnDeref,
        UnNot,
        UnNeg,
    }

to

    enum UnOp {
        Deref,
        Not,
        Neg,
    }

Motivations:

- This is more consistent with the rest of the code base where most enum
  variants don't have a prefix.

- These variants are never used without the `UnOp` prefix so the extra
  `Un` prefix doesn't help with readability. E.g. we don't have any
  `UnDeref`s in the code, we only have `UnOp::UnDeref`.

- MIR `UnOp` type variants don't have a prefix so this is more
  consistent with MIR types.

- "un" prefix reads like "inverse" or "reverse", so as a beginner in
  rustc code base when I see "UnDeref" what comes to my mind is
  something like `&*` instead of just `*`.
2021-02-10 12:24:28 +09:00
Yuki Okushi
fff36f199a
Rollup merge of #81909 - wcampbell0x2a:remove-unnecessary-refs, r=estebank
[compiler/rustc_typeck/src/check/expr.rs] Remove unnecessary refs in pattern matching
2021-02-10 12:24:25 +09:00
Yuki Okushi
3f09418cbe
Rollup merge of #81466 - sasurau4:fix/enhance-sugget-mut-method-for-loop, r=oli-obk
Add suggest mut method for loop

Part of #49839

This PR focus on [the comment case](https://github.com/rust-lang/rust/issues/49839#issuecomment-761930746)
2021-02-10 12:24:21 +09:00
Cameron Steffen
471ed5f80f Use ItemCtxt::to_ty 2021-02-09 19:27:33 -06:00
bors
ca98712ff9 Auto merge of #81411 - Skgland:deprecate_expr_method_call, r=varkor
Remove usages of `expr_method_call` in derive(Ord,PartialOrd,RustcEncode,RustcDecode)

Preparing for deprecation of `expr_method_call`  (#81295), by removing the remaining usages not covered by (#81294).

I am not sure about the changes to `derive(RustcEncode,RustcDecode)`
2021-02-10 00:25:11 +00:00
Tomasz Miąsko
1cf95059eb Borrow builder only once in debug derive 2021-02-10 00:00:00 +00:00
Nam Nguyen
615fd141bd Set the kind for local variables created by &str and slice arguments to LocalVariable 2021-02-09 15:59:28 -08:00
Matthew Jasper
9337d4fde8 Print closure signatures when reporting placeholder errors 2021-02-09 23:00:33 +00:00
Matthew Jasper
94c11dfe78 Report "nice" placeholder errors more often
If we have a cause containing `ValuePairs::PolyTraitRefs` but neither
TraitRef has any escaping bound regions then we report the same error as
for `ValuePairs::TraitRefs`.
2021-02-09 22:59:32 +00:00
Matthew Jasper
daab6db1a0 Avoid repeating self type in placeholder error 2021-02-09 22:28:09 +00:00
bors
87bacf22ec Auto merge of #81132 - bugadani:map-prealloc, r=matthewjasper
Borrowck: refactor visited map to a bitset

This PR refactors `Borrows`  and the `precompute_borrows_out_of_scope` function so that this initial phase has a much reduced memory pressure. This is achieved by reducing what is stored on the heap, and also reusing heap memory as much as possible.
2021-02-09 21:28:58 +00:00
Matthew Jasper
c2066cf069 Remove unnecessary note on errors
Seeing the trait definition doesn't help with implementation not general
enough errors, so don't make the error message larger to show it.
2021-02-09 21:16:00 +00:00
Matthew Jasper
638980a07f Using tracing macros in placeholder_error.rs 2021-02-09 21:03:00 +00:00
Matthew Jasper
1eb79f3c37 Use longer lifetime in try_report_from_nll return type 2021-02-09 20:56:45 +00:00
Ryan Levick
396022b90b Visit more targets when checking attrs 2021-02-09 21:54:46 +01:00
bors
097bc6a84f Auto merge of #81892 - jyn514:no-inline, r=cjgillot
[experiment] remove `#[inline]` from rustc_query_system::plumbing

These functions have a ton of generic parameters and are instantiated
over and over again. Hopefully this will reduce binary bloat and speed
up bootstrapping times.

r? `@cjgillot`
2021-02-09 18:37:33 +00:00
Jesús Rubio
8fbdd2d15e
Update compiler/rustc_error_codes/src/error_codes/E0547.md
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
2021-02-09 14:13:40 +01:00
Henry Boisdequin
4af417a78a add suggestion to use the async_recursion crate 2021-02-09 18:43:39 +05:30
Jesus Rubio
7b84b62d29 Lost text re-added 2021-02-09 14:09:19 +01:00
Skgland
0375022c73
fix derive(RustcEncodable, RustcDecodable) 2021-02-09 13:42:36 +01:00
Skgland
091ef95f8e
use ufcs in derive(RustDecodable) 2021-02-09 13:42:36 +01:00
Skgland
525fc4b8e4
use ufcs in derive(RustEncodable) 2021-02-09 13:42:36 +01:00
Skgland
e1010424dc
add method to construct def site path as a vec of idents
like std_path but used dummy span for all path elements and does not perpend kw:DollarCrate
2021-02-09 13:42:35 +01:00
Skgland
2c33b070ad
use ufcs in derive(Ord) and derive(PartialOrd) 2021-02-09 13:42:35 +01:00
Kevin Per
49fc41f047 Running ./x.py fmt 2021-02-09 10:28:49 +00:00
Ellen
1d9ac3c22c Fix const generics in GAT 2021-02-09 08:58:05 +00:00
bors
c648bd5558 Auto merge of #81384 - tmiasko:partial-ord, r=petrochenkov
Fix derived PartialOrd operators

The derived implementation of `partial_cmp` compares matching fields one
by one, stopping the computation when the result of a comparison is not
equal to `Some(Equal)`.

On the other hand the derived implementation for `lt`, `le`, `gt` and
`ge` continues the computation when the result of a field comparison is
`None`, consequently those operators are not transitive and inconsistent
with `partial_cmp`.

Fix the inconsistency by using the default implementation that fall-backs
to the `partial_cmp`. This also avoids creating very deeply nested
closures that were quite costly to compile.

Fixes #81373.
Helps with #81278, #80118.
2021-02-09 08:47:38 +00:00
Kevin Per
95be69dabb Fixing codestyle 2021-02-09 08:42:08 +00:00
Ömer Sinan Ağacan
c4e3558b8c Rename HIR UnOp variants
This renames the variants in HIR UnOp from

    enum UnOp {
        UnDeref,
        UnNot,
        UnNeg,
    }

to

    enum UnOp {
        Deref,
        Not,
        Neg,
    }

Motivations:

- This is more consistent with the rest of the code base where most enum
  variants don't have a prefix.

- These variants are never used without the `UnOp` prefix so the extra
  `Un` prefix doesn't help with readability. E.g. we don't have any
  `UnDeref`s in the code, we only have `UnOp::UnDeref`.

- MIR `UnOp` type variants don't have a prefix so this is more
  consistent with MIR types.

- "un" prefix reads like "inverse" or "reverse", so as a beginner in
  rustc code base when I see "UnDeref" what comes to my mind is
  something like "&*" instead of just "*".
2021-02-09 11:39:20 +03:00
Kevin Per
09d5d0766e Fixing bad suggestion for _ in const type when a function #81885 2021-02-09 08:35:58 +00:00
Aman Arora
5b54640128 Mark migration code that relies on Deref unreachable 2021-02-09 02:59:29 -05:00
Aman Arora
c01036af1d Implement the precise analysis pass for lint disjoint_capture_drop_reorder 2021-02-09 02:53:58 -05:00
bors
f4008fe949 Auto merge of #81905 - Dylan-DPC:rollup-mxpz1j7, r=Dylan-DPC
Rollup of 11 pull requests

Successful merges:

 - #72209 (Add checking for no_mangle to unsafe_code lint)
 - #80732 (Allow Trait inheritance with cycles on associated types take 2)
 - #81697 (Add "every" as a doc alias for "all".)
 - #81826 (Prefer match over combinators to make some Box methods inlineable)
 - #81834 (Resolve typedef in HashMap lldb pretty-printer only if possible)
 - #81841 ([rustbuild] Output rustdoc-json-types docs )
 - #81849 (Expand the docs for ops::ControlFlow a bit)
 - #81876 (parser: Fix panic in 'const impl' recovery)
 - #81882 (⬆️ rust-analyzer)
 - #81888 (Fix pretty printer macro_rules with semicolon.)
 - #81896 (Remove outdated comment in windows' mutex.rs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-02-09 05:57:18 +00:00
bors
36931ce3d9 Auto merge of #81901 - Mark-Simulacrum:use-string-not-cow, r=jackh726
Switch query descriptions to just String

In practice we never used the borrowed variant anyway.
2021-02-09 03:06:42 +00:00
wcampbell
7554c7742e
Remove unnecessary refs in pattern matching
Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2021-02-08 22:02:35 -05:00
Dylan DPC
78c0153757
Rollup merge of #81888 - ehuss:macro_rules-pp, r=petrochenkov
Fix pretty printer macro_rules with semicolon.

The pretty printer was not including the trailing semicolon for a macro_rules definition that used parenthesis or brackets, which results in invalid code. This adds the semicolon in those two cases.
2021-02-09 02:40:05 +01:00
Dylan DPC
9ab05b4fe3
Rollup merge of #81876 - osa1:issue81806, r=matthewjasper
parser: Fix panic in 'const impl' recovery

The panic happens when in recovery parsing a full `impl`
(`parse_item_impl`) fails and we drop the `DiagnosticBuilder` for the
recovery suggestion and return the `parse_item_impl` error.

We now raise the original error "expected identifier found `impl`" when
parsing the `impl` fails.

Note that the regression test is slightly simplified version of the
original repro in #81806, to make the error output smaller and more
resilient to unrelated changes in parser error messages.

Fixes #81806
2021-02-09 02:40:01 +01:00
Dylan DPC
44e526b2c3
Rollup merge of #80732 - spastorino:trait-inheritance-self2, r=nikomatsakis
Allow Trait inheritance with cycles on associated types take 2

This reverts the revert of #79209 and fixes the ICEs that's occasioned by that PR exposing some problems that are addressed in #80648 and #79811.
For easier review I'd say, check only the last commit, the first one is just a revert of the revert of #79209 which was already approved.

This also could be considered part or the actual fix of #79560 but I guess for that to be closed and fixed completely we would need to land #80648 and #79811 too.

r? `@nikomatsakis`
cc `@Aaron1011`
2021-02-09 02:39:50 +01:00
Dylan DPC
f8b330d9fb
Rollup merge of #72209 - Nemo157:lint-no-mangle-in-unsafe-code, r=nikomatsakis
Add checking for no_mangle to unsafe_code lint

fixes #72188

r? `@estebank`
2021-02-09 02:39:45 +01:00
Tomasz Miąsko
e4efccd4a6 Fix derived PartialOrd operators
The derived implementation of `partial_cmp` compares matching fields one
by one, stopping the computation when the result of a comparison is not
equal to `Some(Equal)`.

On the other hand the derived implementation for `lt`, `le`, `gt` and
`ge` continues the computation when the result of a field comparison is
`None`, consequently those operators are not transitive and inconsistent
with `partial_cmp`.

Fix the inconsistency by using the default implementation that fall-backs
to the `partial_cmp`. This also avoids creating very deeply nested
closures that were quite costly to compile.
2021-02-09 08:15:37 +01:00
Mark Rousskov
f564d7abba Switch query descriptions to just String
In practice we never used the borrowed variant anyway.
2021-02-08 17:20:41 -05:00
Eric Huss
cadffa74df Fix pretty printer macro_rules with semicolon. 2021-02-08 12:08:27 -08:00
Joshua Nelson
4f77a1afc2 [experiment] remove #[inline] from rustc_query_system::plumbing
These functions have a ton of generic parameters and are instantiated
over and over again. Hopefully this will reduce binary bloat and speed
up bootstrapping times.
2021-02-08 14:57:15 -05:00
Santiago Pastorino
8d17c6a85d
Anonymize late bound regions on transitive bounds that define assoc type 2021-02-08 16:47:51 -03:00
Dániel Buga
5271c628be Remove RCs from Borrows 2021-02-08 20:37:16 +01:00
Mara Bos
9d1e8fe045
Rollup merge of #81865 - bugadani:typeck2, r=jyn514
Clean up weird Option mapping
2021-02-08 19:28:25 +01:00
Mara Bos
b376c50aa2
Rollup merge of #81861 - tmiasko:mir-bytes, r=wesleywiser
Show MIR bytes separately in -Zmeta-stats output

The size of serialized MIR is substantial enough to deserve its own category.
2021-02-08 19:28:23 +01:00
Mara Bos
b9045fabf8
Rollup merge of #81828 - davidhewitt:capture-raw-format-strings, r=estebank
parse_format: treat r" as a literal

This PR changes `format_args!` internal parsing machinery to treat raw strings starting `r"` as a literal.

Currently `"` and `r#` are recognised as valid starting combinations for string literals, but `r"` is not.

This was noticed when debugging https://github.com/rust-lang/rust/issues/67984#issuecomment-753413156

As well as fixing the behavior observed in that comment, this improves diagnostic spans for `r"` formatting strings.
2021-02-08 19:28:20 +01:00
Mara Bos
b263981fd7
Rollup merge of #81779 - geogriff:const-ptr-to-int-error, r=lcnr
improve error message for disallowed ptr-to-int casts in const eval

Improves an error message as [suggested](https://github.com/rust-lang/rust/issues/80875#issuecomment-762754580) in #80875.

Does the wording make enough sense? I tried to follow precedent for error message style while maintaining brevity.

It seems like the rest of the `ConstEvalErrKind::NeedsRfc` error messages could be improved as well. I could give that a go if this approach works.

Closes #80875
2021-02-08 19:28:17 +01:00
Mara Bos
2c8d1c8cef
Rollup merge of #81735 - klensy:span-fix, r=varkor
faster few span methods

Touched few methods, so it should be (hopefully) faster.

First two changes: instead splitting string from start and taking only last piece, split it from the end.
Last: swapped conditions, to first check boolean parameter.
2021-02-08 19:28:15 +01:00
Jesus Rubio
4d33d41ef3 Add long explanation for E0547 2021-02-08 18:25:05 +01:00
Tri Vo
c7d9bffe76 HWASan support 2021-02-07 23:48:58 -08:00
Ömer Sinan Ağacan
6eb1bd4c3e parser: Fix panic in 'const impl' recovery
The panic happens when in recovery parsing a full `impl`
(`parse_item_impl`) fails and we drop the `DiagnosticBuilder` for the
recovery suggestion and return the `parse_item_impl` error.

We now raise the original error "expected identifier found `impl`" when
parsing the `impl` fails.

Note that the regression test is slightly simplified version of the
original repro in #81806, to make the error output smaller and more
resilient to unrelated changes in parser error messages.

Fixes #81806
2021-02-08 10:46:19 +03:00
Camelid
0f3e2f68d3 Clarify docs for DUMMY_NODE_ID 2021-02-07 19:42:12 -08:00
bors
0b7a598e12 Auto merge of #72603 - jsgf:extern-loc, r=nikomatsakis
Implement `--extern-location`

This PR implements `--extern-location` as a followup to #72342 as part of the implementation of #57274. The goal of this PR is to allow rustc, in coordination with the build system, to present a useful diagnostic about how to remove an unnecessary dependency from a dependency specification file (eg Cargo.toml).

EDIT: Updated to current PR state.

The location is specified for each named crate - that is, for a given `--extern foo[=path]` there can also be `--extern-location foo=<location>`. It supports ~~three~~ two styles of location:
~~1. `--extern-location foo=file:<path>:<line>` - a file path and line specification
1. `--extern-location foo=span:<path>:<start>:<end>` - a span specified as a file and start and end byte offsets~~
1. `--extern-location foo=raw:<anything>` - a raw string which is included in the output
1. `--extern-location foo=json:<anything>` - an arbitrary Json structure which is emitted via Json diagnostics in a `tool_metadata` field.

~~1 & 2 are turned into an internal `Span`, so long as the path exists and is readable, and the location is meaningful (within the file, etc). This is used as the `Span` for a fix suggestion which is reported like other fix suggestions.~~

`raw` and `json` are for the case where the location isn't best expressed as a file and location within that file. For example, it could be a rule name and the name of a dependency within that rule. `rustc` makes no attempt to parse the raw string, and simply includes it in the output diagnostic text. `json` is only included in json diagnostics. `raw` is emitted as text and also as a json string in `tool_metadata`.

If no `--extern-location` option is specified then it will emit a default json structure consisting of `{"name": name, "path": path}` corresponding to the name and path in `--extern name=path`.

This is a prototype/RFC to make some of the earlier conversations more concrete. It doesn't stand on its own - it's only useful if implemented by Cargo and other build systems. There's also a ton of implementation details which I'd appreciate a second eye on as well.

~~**NOTE** The first commit in this PR is #72342 and should be ignored for the purposes of review. The first commit is a very simplistic implementation which is basically raw-only, presented as a MVP. The second implements the full thing, and subsequent commits are incremental fixes.~~

cc `@ehuss` `@est31` `@petrochenkov` `@estebank`
2021-02-08 02:23:17 +00:00
Dániel Buga
37cbc08a92 Clean up weird option mapping 2021-02-08 00:24:36 +01:00
Jeremy Fitzhardinge
91d8c3b521 Make sure all fields are accounted for in encode_fields!
This will make sure the encoder will get updated if any new fields are
added to Diagnostic.
2021-02-07 14:54:22 -08:00
Jeremy Fitzhardinge
50572d6629 Implement Encoder for Diagnostic manually
...so we can skip serializing `tool_metadata` if it hasn't been set.
This makes the output a bit cleaner, and avoiding having to update a
bunch of unrelated tests.
2021-02-07 14:54:22 -08:00
Jeremy Fitzhardinge
82ccb6582a Add --extern-loc to augment unused crate dependency diagnostics
This allows a build system to indicate a location in its own dependency
specification files (eg Cargo's `Cargo.toml`) which can be reported
along side any unused crate dependency.

This supports several types of location:
 - 'json' - provide some json-structured data, which is included in the json diagnostics
     in a `tool_metadata` field
 - 'raw' - emit the provided string into the output. This also appears as a json string in
     `tool_metadata`.

If no `--extern-location` is explicitly provided then a default json entry of the form
`"tool_metadata":{"name":<cratename>,"path":<cratepath>}` is emitted.
2021-02-07 14:54:20 -08:00
bors
bb587b1a17 Auto merge of #80652 - calebzulawski:simd-lanes, r=nagisa
Improve SIMD type element count validation

Resolves rust-lang/stdsimd#53.

These changes are motivated by `stdsimd` moving in the direction of const generic vectors, e.g.:
```rust
#[repr(simd)]
struct SimdF32<const N: usize>([f32; N]);
```

This makes a few changes:
* Establishes a maximum SIMD lane count of 2^16 (65536).  This value is arbitrary, but attempts to validate lane count before hitting potential errors in the backend.  It's not clear what LLVM's maximum lane count is, but cranelift's appears to be much less than `usize::MAX`, at least.
* Expands some SIMD intrinsics to support arbitrary lane counts.  This resolves the ICE in the linked issue.
* Attempts to catch invalid-sized vectors during typeck when possible.

Unresolved questions:
* Generic-length vectors can't be validated in typeck and are only validated after monomorphization while computing layout.  This "works", but the errors simply bail out with no context beyond the name of the type.  Should these errors instead return `LayoutError` or otherwise provide context in some way?  As it stands, users of `stdsimd` could trivially produce monomorphization errors by making zero-length vectors.

cc `@bjorn3`
2021-02-07 22:25:14 +00:00
Dániel Buga
46f30455f4 Optimize Borrows
Reuse as much memory as possible, reduce number of allocations.
Use BitSet instead of a HashMap, since only a single bit of
information was used as the map's value.
2021-02-07 22:26:21 +01:00
Ömer Sinan Ağacan
7e94641ee9 Fix SourceMap::start_point
`start_point` needs to return the *first* character's span, but it would
previously call `find_width_of_character_at_span` which returns the span
of the *last* character. The implementation is now fixed.

Other changes:

- Docs for start_point, end_point, find_width_of_character_at_span
  updated

- Minor simplification in find_width_of_character_at_span code

Fixes #81800
2021-02-07 23:23:09 +03:00
bors
9778068cbc Auto merge of #79078 - petrochenkov:derattr, r=Aaron1011
expand/resolve: Turn `#[derive]` into a regular macro attribute

This PR turns `#[derive]` into a regular attribute macro declared in libcore and defined in `rustc_builtin_macros`, like it was previously done with other "active" attributes in https://github.com/rust-lang/rust/pull/62086, https://github.com/rust-lang/rust/pull/62735 and other PRs.
This PR is also a continuation of #65252, #69870 and other PRs linked from them, which layed the ground for converting `#[derive]` specifically.

`#[derive]` still asks `rustc_resolve` to resolve paths inside `derive(...)`, and `rustc_expand` gets those resolution results through some backdoor (which I'll try to address later), but otherwise `#[derive]` is treated as any other macro attributes, which simplifies the resolution-expansion infra pretty significantly.

The change has several observable effects on language and library.
Some of the language changes are **feature-gated** by [`feature(macro_attributes_in_derive_output)`](https://github.com/rust-lang/rust/issues/81119).

#### Library

- `derive` is now available through standard library as `{core,std}::prelude::v1::derive`.

#### Language

- `derive` now goes through name resolution, so it can now be renamed - `use derive as my_derive; #[my_derive(Debug)] struct S;`.
- `derive` now goes through name resolution, so this resolution can fail in corner cases. Crater found one such regression, where import `use foo as derive` goes into a cycle with `#[derive(Something)]`.
- **[feature-gated]** `#[derive]` is now expanded as any other attributes in left-to-right order. This allows to remove the restriction on other macro attributes following `#[derive]` (https://github.com/rust-lang/reference/issues/566). The following macro attributes become a part of the derive's input (this is not a change, non-macro attributes following `#[derive]` were treated in the same way previously).
- `#[derive]` is now expanded as any other attributes in left-to-right order. This means two derive attributes `#[derive(Foo)] #[derive(Bar)]` are now expanded separately rather than together. It doesn't generally make difference, except for esoteric cases. For example `#[derive(Foo)]` can now produce an import bringing `Bar` into scope, but previously both `Foo` and `Bar` were required to be resolved before expanding any of them.
- **[feature-gated]** `#[derive()]` (with empty list in parentheses) actually becomes useful. For historical reasons `#[derive]` *fully configures* its input, eagerly evaluating `cfg` everywhere in its target, for example on fields.
Expansion infra doesn't do that for other attributes, but now when macro attributes attributes are allowed to be written after `#[derive]`, it means that derive can *fully configure* items for them.
    ```rust
	#[derive()]
	#[my_attr]
	struct S {
		#[cfg(FALSE)] // this field in removed by `#[derive()]` and not observed by `#[my_attr]`
		field: u8
	}
    ```
- `#[derive]` on some non-item targets is now prohibited. This was accidentally allowed as noop in the past, but was warned about since early 2018 (#50092), despite that crater found a few such cases in unmaintained crates.
- Derive helper attributes used before their introduction are now reported with a deprecation lint. This change is long overdue (since macro modularization, https://github.com/rust-lang/rust/issues/52226#issuecomment-422605033), but it was hard to do without fixing expansion order for derives. The deprecation is tracked by #79202.
```rust
    #[trait_helper] // warning: derive helper attribute is used before it is introduced
    #[derive(Trait)]
    struct S {}
```

Crater analysis: https://github.com/rust-lang/rust/pull/79078#issuecomment-731436821
2021-02-07 19:36:10 +00:00
Vadim Petrochenkov
d8af6de911 Address review comments 2021-02-07 20:08:45 +03:00
Vadim Petrochenkov
f6caae52c1 Feature gate macro attributes in #[derive] output 2021-02-07 20:08:45 +03:00
Vadim Petrochenkov
dbdbd30bf2 expand/resolve: Turn #[derive] into a regular macro attribute 2021-02-07 20:08:45 +03:00
bors
36ecbc94eb Auto merge of #80632 - Nadrieril:fix-80501, r=varkor
Identify unreachable subpatterns more reliably

In https://github.com/rust-lang/rust/pull/80104 I used `Span`s to identify unreachable sub-patterns in the presence of or-patterns during exhaustiveness checking. In https://github.com/rust-lang/rust/issues/80501 it was revealed that `Span`s are complicated and that this was not a good idea.
Instead, this PR identifies subpatterns logically: as a path in the tree of subpatterns of a given pattern. I made a struct that captures a set of such subpatterns. This is a bit complex, but thankfully self-contained; the rest of the code does not need to know anything about it.
Fixes https://github.com/rust-lang/rust/issues/80501. I think I managed to keep the perf neutral.

r? `@varkor`
2021-02-07 16:48:57 +00:00
Guillaume Gomez
b2beb67fac
Rollup merge of #81835 - jesusprubio:improve-long-eplanation-e0546, r=GuillaumeGomez
Improve long explanation for E0546

Helps with #61137
2021-02-07 14:45:54 +01:00
Guillaume Gomez
6c648822c5
Rollup merge of #81830 - jesusprubio:add-log-explanation-e0542, r=GuillaumeGomez
Add long error explanation for E0542

Helps with #61137
2021-02-07 14:45:53 +01:00
bors
43e1ea29c4 Auto merge of #81498 - thomaseizinger:ice-workaround-56935-rustc-index, r=matthewjasper
Apply workaround from #72003 for #56935 to allow for cross-compilation of `rustc_index` crate

This patch applies the same workaround as #72003 to the `rustc_index` crate. This allows recent versions of rustfmt to compile to wasm again.

Related: #72017.
2021-02-07 08:09:58 +00:00
Tomasz Miąsko
a14ec1cedf Show MIR bytes separately in -Zmeta-stats output 2021-02-07 00:00:00 +00:00
bors
08fdbd59b7 Auto merge of #78052 - da-x:path-trimming-type-aliases, r=davidtwco
path trimming: ignore type aliases

Continuation of #73996.
2021-02-06 23:44:42 +00:00
Jesus Rubio
ac6c09a980 Typo fix 2021-02-06 19:45:43 +01:00
Jesus Rubio
777582228c References added 2021-02-06 19:44:09 +01:00
Jesus Rubio
023c6d2e04 Comments updated to keep the consistency 2021-02-06 19:41:03 +01:00
Jesus Rubio
0d8a071f98 Improve long explanation for E0546 2021-02-06 18:27:19 +01:00
Jesus Rubio
9be5d2d01f Format fixes 2021-02-06 18:05:21 +01:00
Jesús Rubio
956c81355a
Update compiler/rustc_error_codes/src/error_codes/E0542.md
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
2021-02-06 17:39:11 +01:00
Jonas Schievink
96e843ce6a
Rollup merge of #81738 - camelid:misc-small-diag-cleanup, r=lcnr
Miscellaneous small diagnostics cleanup
2021-02-06 17:01:49 +01:00
Jonas Schievink
f631410159
Rollup merge of #81737 - camelid:typeck-structure-sugg, r=lcnr
typeck: Emit structured suggestions for tuple struct syntax

And tuple variant syntax, but that didn't fit in the subject :)

Now the fact that these are suggestions is exposed both to the layout
engine and to IDEs and rustfix for automatic application.
2021-02-06 17:01:47 +01:00
Jonas Schievink
85fb5cdf26
Rollup merge of #81680 - camsteffen:primty, r=oli-obk
Refactor `PrimitiveTypeTable` for Clippy

I removed `PrimitiveTypeTable` and added `PrimTy::ALL` and `PrimTy::from_name` in its place. This allows Clippy to use `PrimTy::from_name` for the `builtin_type_shadow` lint, and a `const` list of primitive types is deleted from Clippy code (the goal). All changes should be a little faster, if anything.
2021-02-06 17:01:45 +01:00
Jonas Schievink
7acf9ecf4f
Rollup merge of #81402 - ehuss:md-tidy, r=jyn514
tidy: Run tidy style against markdown files.

This adds tidy checks for markdown files.  I think it is useful to have some style enforcement (for the same reasons the style is enforced on other files).  I think it is worthwhile to avoid `ignore` on rust examples since having broken code in documentation is frustrating.  Avoiding trailing whitespace is good because it has semantic meaning in markdown, which I think should be avoided.
2021-02-06 17:01:42 +01:00
Jesus Rubio
be159379f6 Add long error explanation for E0542 2021-02-06 16:42:34 +01:00
David Hewitt
04a19b93c6 parse_format: treat r" as a literal 2021-02-06 15:01:07 +00:00
Dan Aloni
eaefe4a230 path trimming: ignore type aliases 2021-02-06 12:03:48 +02:00
bors
cfba499271 Auto merge of #81810 - m-ou-se:rollup-q3nborp, r=m-ou-se
Rollup of 7 pull requests

Successful merges:

 - #80011 (Stabilize `peekable_next_if`)
 - #81580 (Document how `MaybeUninit<Struct>` can be initialized.)
 - #81610 (BTreeMap: make Ord bound explicit, compile-test its absence)
 - #81664 (Avoid a hir access inside get_static)
 - #81675 (Make rustdoc respect `--error-format short` in doctests)
 - #81753 (Never MIR inline functions with a different instruction set)
 - #81795 (Small refactor with Iterator::reduce)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-02-06 04:55:09 +00:00
Mara Bos
51c68034b9
Rollup merge of #81795 - camsteffen:diagnostics-reduce, r=oli-obk
Small refactor with Iterator::reduce
2021-02-06 00:14:17 +01:00
Mara Bos
728c955ac0
Rollup merge of #81753 - tmiasko:inline-instruction-set, r=oli-obk
Never MIR inline functions with a different instruction set
2021-02-06 00:14:16 +01:00
Mara Bos
add80c9d4b
Rollup merge of #81664 - bjorn3:no_codegen_hir, r=lcnr
Avoid a hir access inside get_static

Together with #81056 this ensures that the codegen unit DepNode doesn't have a direct dependency on any part of the hir.
2021-02-06 00:14:13 +01:00
bors
16b805713c Auto merge of #79253 - rcvalle:fix-rustc-sysroot-cas, r=nagisa
Fix rustc sysroot in systems using CAS

Change filesearch::get_or_default_sysroot() to check if sysroot is found using env::args().next() if rustc in argv[0] is a symlink; otherwise, or if it is not found, use env::current_exe() to imply sysroot. This makes the rustc binary able to locate Rust libraries in systems using content-addressable storage (CAS).
2021-02-05 22:58:13 +00:00
Santiago Pastorino
fd092557ce
Adapt to latest master changes by using PredicateKind 2021-02-05 18:56:57 -03:00
Santiago Pastorino
7aa602b84c
Revert "Auto merge of #79637 - spastorino:revert-trait-inheritance-self, r=Mark-Simulacrum"
This reverts commit b4def89d76, reversing
changes made to 7dc1e852d4.
2021-02-05 18:56:56 -03:00
bors
23adf9fd84 Auto merge of #81215 - cjgillot:defkey-mir, r=oli-obk
Encode MIR metadata by iterating on DefId instead of traversing the HIR tree

Split out of https://github.com/rust-lang/rust/pull/80347.

This part only traverses `mir_keys` and encodes MIR according to the def kind.

r? `@oli-obk`
2021-02-05 18:21:47 +00:00
Cameron Steffen
c89b9d97e2 Small refactor with Iterator::reduce 2021-02-05 09:34:40 -06:00
bors
5605b5d693 Auto merge of #81257 - pnkfelix:issue-80949-short-term-resolution-via-revert-of-pr-78373, r=matthewjasper
Revert 78373 ("dont leak return value after panic in drop")

Short term resolution for issue #80949.

Reopen #47949 after this lands.

(We plan to fine-tune PR #78373 to not run into this problem.)
2021-02-05 14:52:57 +00:00
Daiki Ihara
d3c4dbd85d Add suggest mu method for loop 2021-02-05 22:12:31 +09:00
bors
f9435f4c92 Auto merge of #81784 - m-ou-se:rollup-s23fow7, r=m-ou-se
Rollup of 15 pull requests

Successful merges:

 - #79554 (Generic associated types in trait paths)
 - #80726 (relax adt unsizing requirements)
 - #81307 (Handle `Span`s for byte and raw strings and add more detail )
 - #81318 (rustdoc-json: Fix has_body)
 - #81456 (Make remote-test-server easier to use with new targets)
 - #81497 (rustdoc: Move `display_fn` struct inside `display_fn`)
 - #81500 (Remove struct_type from union output)
 - #81542 (Expose correct symlink API on WASI)
 - #81676 (Add more information to the error code for 'crate not found')
 - #81682 (Add additional bitset benchmarks)
 - #81730 (Make `Allocator` object-safe)
 - #81763 (Cleanup rustdoc pass descriptions a bit)
 - #81767 (Update LayoutError/LayoutErr stability attributes)
 - #81771 (Indicate change in RSS from start to end of pass in time-passes output)
 - #81781 (Fix `install-awscli.sh` error in CI)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-02-05 12:11:05 +00:00
Wesley Wiser
dce5e9e1bf Run x.py fmt to fix tidy issues 2021-02-05 06:35:32 -05:00
Mara Bos
08d8fc14be
Rollup merge of #81771 - tgnottingham:time-passes-rss-delta, r=oli-obk
Indicate change in RSS from start to end of pass in time-passes output

Previously, this was omitted because it could be misleading, but the
functionality seems too useful not to include.

r? ``@oli-obk``
2021-02-05 12:26:08 +01:00
Mara Bos
21c276f9c8
Rollup merge of #81682 - JulianKnodt:bit_set_iter_benchmarks, r=oli-obk
Add additional bitset benchmarks

Add additional benchmarks for operations in bitset, I realize that it was a bit lacking when I intended to optimize it earlier, so I was hoping to put some in so I can verify my work later.
2021-02-05 12:26:03 +01:00
Mara Bos
29371c2504
Rollup merge of #81676 - jyn514:crate-not-found, r=oli-obk
Add more information to the error code for 'crate not found'

This comes up a lot when bootstrapping.
2021-02-05 12:26:02 +01:00
Mara Bos
8d49ca11a2
Rollup merge of #81307 - estebank:invalid-byte-str-span, r=petrochenkov
Handle `Span`s for byte and raw strings and add more detail

CC #81208.
2021-02-05 12:25:53 +01:00
Mara Bos
676ff77fb7
Rollup merge of #80726 - lcnr:unsize-query, r=oli-obk
relax adt unsizing requirements

Changes unsizing of structs in case the last struct field shares generic params with other adt fields which do not change.
This change is currently insta stable and changes the language, so it at least requires a lang fcp. I feel like the current state is fairly unintuitive.

An example for what's now allowed would be https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6dd331d23f5c9ffc8c978175aae2e967
```rust
struct A<T, U: ?Sized>(T, B<T, U>); // previously ERR
// struct A<T, U: ?Sized>(T, B<[u32; 1], U>); // ok
struct B<T, U: ?Sized>(T, U);

fn main() {
    let x = A([0; 1], B([0; 1], [0; 1]));
    let y: &A<[u32; 1], [u32]> = &x;
    assert_eq!(y.1.1.len(), 1);
}
```
2021-02-05 12:25:52 +01:00
Mara Bos
deec6a96d4
Rollup merge of #79554 - b-naber:generic-associated-types-in-trait-paths, r=jackh726
Generic associated types in trait paths

This is the second part of https://github.com/rust-lang/rust/pull/78978

This should fix:

Fixes #67510
Fixes #68648
Fixes #68649
Fixes #68650
Fixes #68652
Fixes #74684
Fixes #76535
Fixes #79422
Fixes #80433

and implement the remaining functionality needed for https://github.com/rust-lang/rust/issues/44265

r? ``@matthewjasper``
2021-02-05 12:25:50 +01:00
bors
730d6dfddd Auto merge of #81736 - tgnottingham:tune-cgu-scheduling-for-memory, r=nagisa
rustc_codegen_ssa: tune codegen scheduling to reduce memory usage

For better throughput during parallel processing by LLVM, we used to sort
CGUs largest to smallest. This would lead to better thread utilization
by, for example, preventing a large CGU from being processed last and
having only one LLVM thread working while the rest remained idle.

However, this strategy would lead to high memory usage, as it meant the
LLVM-IR for all of the largest CGUs would be resident in memory at once.

Instead, we can compromise by ordering CGUs such that the largest and
smallest are first, second largest and smallest are next, etc. If there
are large size variations, this can reduce memory usage significantly.
2021-02-05 09:20:51 +00:00
Tyson Nottingham
4253919f1d Indicate change in RSS from start to end of pass in time-passes output
Previously, this was omitted because it could be misleading, but the
functionality seems too useful not to include.
2021-02-05 01:11:52 -08:00
Jeffrey Griffin
ff315e34e8 improve error message for disallowed ptr-to-int casts in const eval 2021-02-05 00:52:19 -08:00
Felix S. Klock II
dac354fc32 Revert "Simplify unscheduling of drops after moves"
This reverts commit b766abc88f.
2021-02-04 21:29:50 -05:00
Felix S. Klock II
bed69c6134 Revert "Use record_operands_moved more aggresively"
This reverts commit 7f3e8551dd.
2021-02-04 21:29:50 -05:00
Felix S. Klock II
a71a819480 Revert "Avoid leaking block expression values"
This reverts commit 4fef39113a.
2021-02-04 21:29:49 -05:00
Tomasz Miąsko
eb5e2d08c7 Never MIR inline functions with a different instruction set 2021-02-05 00:00:00 +00:00
b-naber
9e920151a3 remove subst_supertrait call 2021-02-04 21:37:23 +01:00
b-naber
6a68966663 use generic arguments of associated item in trait_ref method 2021-02-04 21:37:14 +01:00
Mara Bos
113e27fcfc
Rollup merge of #81727 - m-ou-se:unstabilize-bits, r=Mark-Simulacrum
Revert stabilizing integer::BITS.

We agreed in the libs meeting just now to revert stablization, since the [breakage](https://github.com/rust-lang/rust/issues/81654) is significant throughout the ecosystem, through `lexical-core`.

cc https://github.com/rust-lang/rust/issues/76904

Fixes https://github.com/rust-lang/rust/issues/81654
2021-02-04 21:10:42 +01:00
Mara Bos
87b269ab66
Rollup merge of #81645 - m-ou-se:panic-lint, r=estebank,flip1995
Add lint for `panic!(123)` which is not accepted in Rust 2021.

This extends the `panic_fmt` lint to warn for all cases where the first argument cannot be interpreted as a format string, as will happen in Rust 2021.

It suggests to add `"{}",` to format the message as a string. In the case of `std::panic!()`, it also suggests the recently stabilized
`std::panic::panic_any()` function as an alternative.

It renames the lint to `non_fmt_panic` to match the lint naming guidelines.

![image](https://user-images.githubusercontent.com/783247/106520928-675ea680-64d5-11eb-81f7-d8fa48b93a0b.png)

This is part of #80162.

r? ```@estebank```
2021-02-04 21:10:36 +01:00
Mara Bos
c5990dd8ad
Rollup merge of #81556 - nikomatsakis:forbidden-lint-groups-lint, r=pnkfelix
introduce future-compatibility warning for forbidden lint groups

We used to ignore `forbid(group)` scenarios completely. This changed in #78864, but that led to a number of regressions (#80988, #81218).

This PR introduces a future compatibility warning for the case where a group is forbidden but then an individual lint within that group is allowed. We now issue a FCW when we see the "allow", but permit it to take effect.

r? ``@Mark-Simulacrum``
2021-02-04 21:10:34 +01:00
Camelid
ed6232927b typeck: Emit structured suggestions for tuple struct syntax
And tuple variant syntax, but that didn't fit in the subject :)

Now the fact that these are suggestions is exposed both to the layout
engine and to IDEs and rustfix for automatic application.
2021-02-04 11:58:55 -08:00