Commit Graph

15935 Commits

Author SHA1 Message Date
Matthias Krüger
e65de39763
Rollup merge of #100586 - the8472:available_parallelism_2, r=jyn514
Reland changes replacing num_cpus with available_parallelism

Since #97925 added cgroupv1 support the problem in #97549 which lead to the previous revert should be addressed now.

Cargo has reapplied the replacement too https://github.com/rust-lang/cargo/pull/10969

Reverts 1ae4b25826 (part of #97911)
Relands #94524
2022-08-15 20:11:41 +02:00
Matthias Krüger
e14d12cb66
Rollup merge of #100559 - nnethercote:parser-simplifications, r=compiler-errors
Parser simplifications

Best reviewed one commit at a time.

r? ``@compiler-errors``
2022-08-15 20:11:38 +02:00
Matthias Krüger
17914c89ec
Rollup merge of #100528 - tux3:riscv-bitmanip-features, r=davidtwco
Support 1st group of RISC-V Bitmanip backend target features

These target features use the same names as LLVM and `is_riscv_feature_detected!`, they are:
- zba (address generation instructions)
- zbb (basic bit manipulation)
- zbc (carry-less multiplication)
- zbs (single-bit manipulation)

The extension is frozen and ratified, and I don't think we should expect LLVM to change those feature names in the future.
For reference, the specification for the B extension can be found here: https://github.com/riscv/riscv-bitmanip/releases/download/1.0.0/bitmanip-1.0.0-38-g865e7a7.pdf)

On my current project, I see a 7.6% reduction in binary size with these features on, so I have some incentive to try to silence the "unknown feature" warning from `-Ctarget-feature` =)
2022-08-15 20:11:37 +02:00
Matthias Krüger
a1fdea2b78
Rollup merge of #100514 - compiler-errors:issue-100191, r=spastorino
Delay span bug when failing to normalize negative coherence impl subject due to other malformed impls

Fixes #100191

r? ``@spastorino``
2022-08-15 20:11:36 +02:00
Matthias Krüger
e369ec871e
Rollup merge of #100458 - compiler-errors:fn-argument-span, r=estebank
Adjust span of fn argument declaration

Span of a fn argument declaration goes from:

```
fn foo(i : i32 , ...)
       ^^^^^^^^
```

to:

```
fn foo(i : i32 , ...)
       ^^^^^^^
```

That is, we don't include the extra spacing up to the trailing comma, which I think is more correct.

cc https://github.com/rust-lang/rust/pull/99646#discussion_r944568074
r? ``@estebank``

---

The two tests that had dramatic changes in their rendering I think actually are improved, though they are kinda poor spans both before and after the changes. 🤷 Thoughts?
2022-08-15 20:11:35 +02:00
Matthias Krüger
3aa5734a2c
Rollup merge of #100377 - est31:fluent_grepability, r=davidtwco
Replace - with _ in fluent slugs to improve developer workflows

This is a proposal to smoothen the compiler contribution experience in the face of the move to fluent.

## Context

The fluent project has introduced a layer of abstraction to compiler errors. Previously, people would write down error messages directly in the same file the code was located to emit them. Now, there is a slug that connects the code in the compiler to the error message in the ftl file.

You can look at 7ef610c003 to see an example of the changes:

Old:
```Rust
let msg = format!(
    "bounds on `{}` are most likely incorrect, consider instead \
        using `{}` to detect whether a type can be trivially dropped",
    predicate,
    cx.tcx.def_path_str(needs_drop)
);
lint.build(&msg).emit();
```
New (Rust side):
```Rust
lint.build(fluent::lint::drop_trait_constraints)
    .set_arg("predicate", predicate)
    .set_arg("needs_drop", cx.tcx.def_path_str(needs_drop))
    .emit();
```
New (Fluent side):
```fluent
lint-drop-trait-constraints =
    bounds on `{$predicate}` are most likely incorrect, consider instead using `{$needs_drop}` to detect whether a type can be trivially dropped
```

You will note that in the ftl file, the slug is slightly different from the slug in the Rust file: The ftl slug uses `-` (e.g. `lint-drop-trait-constraints`) while the rust slug uses `::` and `_` (e.g. `lint::drop_trait_constraints`). This choice was probably done due to:

* Rust not accepting `-` in identifiers (as it is an operator)
* fluent not supporting the `:` character in slug names (parse error upon attempts)
* all official fluent documentation using `-` instead of `_`

## The problem

The two different types of slugs, one with `-`, and one with `_`, cause difficulties for contributors. Imagine you don't have perfect knowledge of where stuff is in the compiler (i would say this is most people), and you encounter an error for which you think there is something you could improve that is not just a rewording.

So you want to find out where in the compiler's code that error is being emitted. The best way is via grepping.

1. you grep for the message in the compiler's source code. You discover the ftl file and find out the slug for that error.
2. That slug however contains `-` instead of `_`, so you have to manually translate the `-`'s into `_`s, and furthermore either remove the leading module name, or replace the first `-` with a `::`.
3. you do a second grep to get to the emitting location in the compiler's code.

This translation difficulty in step 2 appears also in the other direction when you want to figure out what some code in the compiler is doing and use error messages to help your understanding. Comments and variable names are way less exposed to users so [are more likely going to lie](cc3c5d2700) than error messages.

I think that at least the `-`→`_` translation which makes up most of step 2 can be removed at low cost.

## The solution

If you look closely, the practice of fluent to use `-` is only a stylistic choice and it is not enforced by fluent implementations, neither the playground nor the one the rust compiler uses, that slugs may not contain `_`. Thus, we can in fact migrate the ftl side to `_`. So now we'll have slugs like  `lint_drop_trait_constraints` on the ftl side. You only have to do one replacement now to get to the Rust slug: remove the first `_` and place a `::` in its stead. I would argue that this change is in fact useful as it allows you to control whether you want to look at the rust side of things or the ftl side of things via changing the query string only: with an increased number of translations checked into the repository, grepping for raw slugs will return the slug in many ftl files, so an explicit step to look for the source code is always useful. In the other direction (rust to fluent), you don't need a translation at all any more, as you can just take the final piece of the slug (e.g. `drop_trait_constraints`) and grep for that. The PR also adds enforcement to forbid usage of `_` in slug names. Internal slug names (those leading with a `-`) are exempt from that enforcement.

As another workflow that benefits from this change, people who add new errors don't have to do that `-` conversion either.

| Before/After | Fluent slug | Rust slug (no change) |
|--|--|--|
| Before | `lint-drop-trait-constraints` | `lint::drop_trait_constraints`|
| After | `lint_drop_trait_constraints` | `lint::drop_trait_constraints`|

Note that I've suggested this previously in the translation thread on zulip. I think it's important to think about non-translator contribution impact of fluent. I have certainly plans for more improvements, but this is a good first step.

``@rustbot`` label A-diagnostics
2022-08-15 20:11:34 +02:00
Matthias Krüger
710bd23df1
Rollup merge of #100031 - GoldsteinE:try-removing-the-field, r=michaelwoerister
improve "try ignoring the field" diagnostic

Closes #95795
2022-08-15 20:11:32 +02:00
bors
9b4ea391a1 Auto merge of #100569 - matthiaskrgr:rollup-9450lzs, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #100211 (Refuse to codegen an upstream static.)
 - #100277 (Simplify format_args builtin macro implementation.)
 - #100483 (Point to generic or arg if it's the self type of unsatisfied projection predicate)
 - #100506 (change `InlineAsmCtxt` to not talk about `FnCtxt`)
 - #100534 (Make code slightly more uniform)
 - #100566 (Use `create_snapshot_for_diagnostic` instead of `clone` for `Parser`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-15 15:25:31 +00:00
The 8472
84531229bb Revert "Revert "Remove num_cpus dependency from bootstrap, build-manifest and rustc_session""
This reverts commit 1ae4b25826.
2022-08-15 16:24:07 +02:00
bors
4916e2b9e6 Auto merge of #98393 - michaelwoerister:new-cpp-like-enum-debuginfo, r=wesleywiser
debuginfo: Generalize C++-like encoding for enums.

The updated encoding should be able to handle niche layouts where more than one variant has fields (as introduced in https://github.com/rust-lang/rust/pull/94075).

The new encoding is more uniform as there is no structural difference between direct-tag, niche-tag, and no-tag layouts anymore. The only difference between those cases is that the "dataful" variant in a niche-tag enum will have a `(start, end)` pair denoting the tag range instead of a single value.

The new encoding now also supports 128-bit tags, which occur in at least some standard library types. These tags are represented as `u64` pairs so that debuggers (which don't always have support for 128-bit integers) can reliably deal with them. The downside is that this adds quite a bit of complexity to the encoding and especially to the corresponding NatVis.

The new encoding seems to increase the size of (x86_64-pc-windows-msvc) debuginfo by 10-15%. The size of binaries is not affected (release builds were built with `-Cdebuginfo=2`, numbers are in kilobytes):

EXE | before | after | relative
-- | -- | -- | --
cargo (debug) | 40453 | 40450 | +0%
ripgrep (debug) | 10275 | 10273 | +0%
cargo (release) | 16186 | 16185 | +0%
ripgrep (release) | 4727 | 4726 | +0%

PDB | before | after | relative
-- | -- | -- | --
cargo (debug) | 236524 | 261412 | +11%
ripgrep (debug) | 53140 | 59060 | +11%
cargo (release) | 148516 | 169620 | +14%
ripgrep (release) | 10676 | 11804 | +11%

Given that the new encoding is more general, this is to be expected. Only platforms using C++-like debuginfo are affected -- which currently is only `*-pc-windows-msvc`.

*TODO*
- [x] Properly update documentation
- [x] Add regression tests for new optimized enum layouts as introduced by #94075.

r? `@wesleywiser`
2022-08-15 12:59:53 +00:00
Matthias Krüger
fece51174b
Rollup merge of #100566 - TaKO8Ki:use-create-snapshot-for-diagnostic, r=cjgillot
Use `create_snapshot_for_diagnostic` instead of `clone` for `Parser`

follow-up to #98020
2022-08-15 10:28:14 +02:00
Matthias Krüger
748925bf1b
Rollup merge of #100534 - Rageking8:Rageking8-refactor1, r=compiler-errors
Make code slightly more uniform
2022-08-15 10:28:13 +02:00
Matthias Krüger
a5cdb6566b
Rollup merge of #100506 - lcnr:fnctxt-yeet, r=compiler-errors
change `InlineAsmCtxt` to not talk about `FnCtxt`

wip for https://github.com/rust-lang/compiler-team/issues/529. this currently uses both the `FnCtxt` and is used by `check_mod_item_types`. This should be the only thing blocking that MCP afaict.

I am still unsure whether `rustc_hir_typeck` should depend on `rustc_hir_analysis` to use the `InlineAsmCtxt`. I think that's the best solution for now, so that's what I will go for

r? `@compiler-errors`
2022-08-15 10:28:12 +02:00
Matthias Krüger
ee63d09bd6
Rollup merge of #100483 - compiler-errors:point-to-projection-too, r=jyn514
Point to generic or arg if it's the self type of unsatisfied projection predicate

We do this for `TraitPredicate`s in `point_at_type_arg_instead_of_call_if_possible` and `point_at_arg_instead_of_call_if_possible`, so also do it for `ProjectionPredicate`.

Improves spans for a lot of unit tests.
2022-08-15 10:28:11 +02:00
Matthias Krüger
965ed812fb
Rollup merge of #100277 - m-ou-se:format-args-1, r=compiler-errors
Simplify format_args builtin macro implementation.

Instead of a FxHashMap<Symbol, (usize, Span)> for the named arguments, this now includes the name and span in the elements of the Vec<FormatArg> directly. The FxHashMap still exists to look up the index, but no longer contains the span. Looking up the name or span of an argument is now trivial and does not need the map anymore.
2022-08-15 10:28:10 +02:00
Matthias Krüger
d6b650391a
Rollup merge of #100211 - cjgillot:ctfe-mir-available, r=michaelwoerister
Refuse to codegen an upstream static.

Fixes https://github.com/rust-lang/rust/issues/85401
2022-08-15 10:28:09 +02:00
Takayuki Maeda
84f0d5e460 use create_snapshot_for_diagnostic instead of clone for Parser 2022-08-15 16:42:58 +09:00
bors
6ce76091c7 Auto merge of #96745 - ehuss:even-more-attribute-validation, r=cjgillot
Visit attributes in more places.

This adds 3 loosely related changes (I can split PRs if desired):

- Attribute checking on pattern struct fields.
- Attribute checking on struct expression fields.
- Lint level visiting on pattern struct fields, struct expression fields, and generic parameters.

There are still some lints which ignore lint levels in various positions. This is a consequence of how the lints themselves are implemented. For example, lint levels on associated consts don't work with `unused_braces`.
2022-08-15 05:50:54 +00:00
Nicholas Nethercote
2ef0479568 Simplify attribute handling in parse_bottom_expr.
`Parser::parse_bottom_expr` currently constructs an empty `attrs` and
then passes it to a large number of other functions. This makes the code
harder to read than it should be, because it's not clear that many
`attrs` arguments are always empty.

This commit removes `attrs` and the passing, simplifying a lot of
functions. The commit also renames `Parser::mk_expr` (which takes an
`attrs` argument) as `mk_expr_with_attrs`, and introduces a new
`mk_expr` which creates an expression with no attributes, which is the
more common case.
2022-08-15 13:29:28 +10:00
bors
76c427d6e2 Auto merge of #100510 - compiler-errors:as-a-treat, r=jackh726
make `TypeError` impl `Copy`

r? `@ghost`
2022-08-15 00:22:38 +00:00
Nicholas Nethercote
1e8497351d Streamline parse_path_start_expr.
Let-chaining avoids some code duplication.
2022-08-15 09:51:11 +10:00
Michael Goulet
54edf1863e Also do it for generics 2022-08-14 20:22:10 +00:00
Michael Goulet
16b33cc1e3 Point to argument if it's self type of unsatisfied projection predicate 2022-08-14 20:22:10 +00:00
Michael Goulet
75dfe55a5d TypeError can be Copy 2022-08-14 19:58:46 +00:00
Matthias Krüger
13b8b6ede0
Rollup merge of #100253 - obeis:issue-100197, r=cjgillot
Recover from mutable variable declaration where `mut` is placed before `let`

Closes #100197
2022-08-14 20:16:00 +02:00
Rageking8
44f878d75f
Make code slightly more uniform 2022-08-14 22:17:49 +08:00
Dylan DPC
9de9786ef8
Rollup merge of #100487 - tmiasko:assert-safe, r=petrochenkov
`assert_{inhabited,zero_valid,uninit_valid}` intrinsics are safe

Those intrinsics either panic or do nothing. They are safe.
2022-08-14 17:09:17 +05:30
Dylan DPC
38bc93730b
Rollup merge of #100126 - petrochenkov:screname, r=davidtwco
rustc_target: Update some old naming around self contained linking

The "fallback" naming pre-dates introduction of `-Clink-self-contained`.
Noticed when reviewing https://github.com/rust-lang/rust/pull/99500.

This PR doesn't break any json target spec, but supporting per-linker-flavor startup objects needed by https://github.com/rust-lang/rust/pull/99500 will break them, so maybe next time I'll remove the compatibility names.
2022-08-14 17:09:16 +05:30
Dylan DPC
7473484d52
Rollup merge of #100115 - obeis:issue-99910, r=cjgillot
Suggest removing `let` if `const let` or `let const` is used

Closes #99910
2022-08-14 17:09:15 +05:30
Dylan DPC
92344e369b
Rollup merge of #99861 - lcnr:orphan-check-cg, r=jackh726
orphan check: rationalize our handling of constants

cc `@rust-lang/types` `@rust-lang/project-const-generics` on whether you agree with this reasoning.

r? types
2022-08-14 17:09:13 +05:30
Dylan DPC
a9f3e0393a
Rollup merge of #99582 - compiler-errors:issue-99566, r=cjgillot
Delay a span bug if we see ty/const generic params during writeback

Fixes #99566
2022-08-14 17:09:12 +05:30
tux3
be8fd0e591 feat: Target features for 1st group of RISC-V Bitmanip extensions
These use the same names as LLVM and is_riscv_feature_detected!:
- zba (address generation instructions)
- zbb (basic bit manipulation)
- zbc (carry-less multiplication)
- zbs (single-bit manipulation)
2022-08-14 12:09:44 +02:00
Michael Goulet
b3e76aa491
Rollup merge of #100479 - compiler-errors:argument-type-error-improvements, r=lcnr
Argument type error improvements

Motivated by this interesting code snippet:

```rust
#[derive(Copy, Clone)]
struct Wrapper<T>(T);

fn foo(_: fn(i32), _: Wrapper<i32>) {}

fn f(_: u32) {}

fn main() {
    let w = Wrapper::<isize>(1isize);
    foo(f, w);
}
```

Which currently errors like:
```
error[E0308]: arguments to this function are incorrect
  --> src/main.rs:10:5
   |
10 |     foo(f, w);
   |     ^^^ -  - expected `i32`, found `isize`
   |         |
   |         expected `i32`, found `u32`
   |
   = note: expected fn pointer `fn(i32)`
                 found fn item `fn(u32) {f}`
   = note: expected struct `Wrapper<i32>`
              found struct `Wrapper<isize>`
note: function defined here
  --> src/main.rs:4:4
   |
4  | fn foo(_: fn(i32), _: Wrapper<i32>) {}
   |    ^^^ ----------  ---------------
```

Specifically, that double `expected .. found ..` which is very difficult to correlate to the types in the arguments. Also, the fact that "expected `i32`, found `isize`" and the other argument mismatch label don't even really explain what's going on here.

After this PR:
```
error[E0308]: arguments to this function are incorrect
  --> $DIR/two-mismatch-notes.rs:10:5
   |
LL |     foo(f, w);
   |     ^^^
   |
note: expected fn pointer, found fn item
  --> $DIR/two-mismatch-notes.rs:10:9
   |
LL |     foo(f, w);
   |         ^
   = note: expected fn pointer `fn(i32)`
                 found fn item `fn(u32) {f}`
note: expected struct `Wrapper`, found a different struct `Wrapper`
  --> $DIR/two-mismatch-notes.rs:10:12
   |
LL |     foo(f, w);
   |            ^
   = note: expected struct `Wrapper<i32>`
              found struct `Wrapper<isize>`
note: function defined here
  --> $DIR/two-mismatch-notes.rs:4:4
   |
LL | fn foo(_: fn(i32), _: Wrapper<i32>) {}
   |    ^^^ ----------  ---------------

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
```

Yeah, it's a bit verbose, but much clearer IMO.

---

Open to discussions about how this could be further improved. Motivated by `@jyn514's` [tweet](https://mobile.twitter.com/joshuayn514/status/1558042020601634816) here.
2022-08-13 21:06:53 -07:00
Michael Goulet
86e1d1e28f
Rollup merge of #100446 - TaKO8Ki:suggest-removing-semicolon-after-impl-trait-items, r=compiler-errors
Suggest removing a semicolon after impl/trait items

fixes #99822
2022-08-13 21:06:51 -07:00
Michael Goulet
d46451ce2c
Rollup merge of #100431 - compiler-errors:enum-ctor-variant-stab, r=estebank
Enum variant ctor inherits the stability of the enum variant

Fixes #100399
Fixes #100420

Context #71481 for why enum variants don't need stability
2022-08-13 21:06:50 -07:00
Michael Goulet
e248c7f9ae
Rollup merge of #100367 - fmease:fix-100365, r=compiler-errors
Suggest the path separator when a dot is used on a trait

Fixes #100365.

`@rustbot` label A-diagnostics
r? diagnostics
2022-08-13 21:06:49 -07:00
Michael Goulet
2af344595a
Rollup merge of #99646 - compiler-errors:arg-mismatch-single-arg-label, r=estebank
Only point out a single function parameter if we have a single arg incompatibility

Fixes #99635
2022-08-13 21:06:46 -07:00
Michael Goulet
c436930f91 Delay span bug when failing to normalize negative coherence impl subject due to other malformed impls 2022-08-13 22:11:42 +00:00
Michael Goulet
aafaec38bb
Rollup merge of #100490 - lcnr:wf-consts, r=jackh726
wf: correctly `shallow_resolve` consts

`shallow_resolve` on `InferConst` is always a noop. this is mostly irrelevant as inference vars should already be resolved at most - if not all - call sites. Haven't actually looked too deeply into whether this was a problem.
2022-08-13 14:10:13 -07:00
Michael Goulet
29f905bfaf
Rollup merge of #100475 - chenyukang:fix-100461, r=fee1-dead
Give a helpful diagnostic when the next struct field has an attribute

Fixes #100461
2022-08-13 14:10:12 -07:00
Michael Goulet
9ab54df8d7
Rollup merge of #100438 - compiler-errors:issue-100360, r=lcnr
Erase regions better in `promote_candidate`

Use `tcx.erase_regions` instead of manually walking through the substs.... this also makes the code slightly simpler 🙈

Fixes #100360
Fixes #89851
2022-08-13 14:10:07 -07:00
Michael Goulet
2126cc62fb
Rollup merge of #100434 - compiler-errors:issue-100373, r=cjgillot
Fix HIR pretty printing of let else

Fixes #100373
Fixes #99318
Fixes #99319
2022-08-13 14:10:06 -07:00
Goldstein
3e0df4b5d7
fix span_extend_to_next_char docs 2022-08-13 23:33:21 +03:00
lcnr
1ec2b9bce8 wf correctly shallow_resolve consts 2022-08-13 21:04:52 +02:00
Michael Goulet
aa1a07f114 Do not inline non-simple argument type errors into labels 2022-08-13 18:24:36 +00:00
Michael Goulet
b0cd1e192c Label argument coercion errors 2022-08-13 18:24:36 +00:00
lcnr
1137fffe28 change InlineAsmCtxt to not talk about FnCtxt 2022-08-13 19:58:39 +02:00
Takayuki Maeda
d47df26784 use span_suggestion instead of span_suggestion_verbose 2022-08-13 22:10:54 +09:00
yukang
52a15180d2 give a helpful diagnostic even when the next struct field has an attribute 2022-08-13 12:50:53 +08:00
Tomasz Miąsko
6b19a48e70 assert_{inhabited,zero_valid,uninit_valid} intrinsics are safe
Those intrinsics either panic or do nothing. They are safe.
2022-08-13 00:00:00 +00:00