Commit Graph

12493 Commits

Author SHA1 Message Date
Isak Nyberg
657ae03f60
Update compiler/rustc_error_messages/src/lib.rs
Co-authored-by: Janusz Marcinkiewicz <virrages@gmail.com>
2022-04-16 23:52:18 +02:00
Isak Nyberg
53b2aca9da Refactor loop into iterator; simplify negation logic. 2022-04-14 00:22:08 +02:00
Dylan DPC
648d65ac7b
Rollup merge of #95991 - PoorlyDefinedBehaviour:fix/issue_95898, r=fee1-dead
fix: wrong trait import suggestion for T:

The suggestion to bound `T` had an extra `:`.

```rust
fn foo<T:>(t: T) {
  t.clone();
}
```

```
error[E0599]: no method named `clone` found for type parameter `T` in the current scope
 --> src/lib.rs:2:7
  |
2 |     t.clone();
  |       ^^^^^ method not found in `T`
  |
  = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `clone`, perhaps you need to restrict type parameter `T` with it:
  |
1 | fn foo<T: Clone:>(t: T) {
  |        ~~~~~~~~
 ```

Fixes: #95898
2022-04-13 17:35:34 +02:00
Bruno Felipe Francisco
9b9f677104 fix: wrong trait import suggestion for T: 2022-04-13 11:02:01 -03:00
bors
f38c5c8e5d Auto merge of #95656 - cjgillot:no-id-hashing-mode, r=Aaron1011
Remove NodeIdHashingMode.

r? `@ghost`
2022-04-13 11:27:17 +00:00
bors
e3c43e64ec Auto merge of #94255 - b-naber:use-mir-constant-in-thir, r=oli-obk
Use mir constant in thir instead of ty::Const

This is blocked on https://github.com/rust-lang/rust/pull/94059 (does include its changes, the first two commits in this PR correspond to those changes) and https://github.com/rust-lang/rust/pull/93800 being reinstated (which had to be reverted). Mainly opening since `@lcnr` offered to give some feedback and maybe also for a perf-run (if necessary).

This currently contains a lot of duplication since some of the logic of `ty::Const` had to be copied to `mir::ConstantKind`, but with the introduction of valtrees a lot of that functionality will disappear from `ty::Const`.

Only the last commit contains changes that need to be reviewed here. Did leave some `FIXME` comments regarding future implementation decisions and some things that might be incorrectly implemented.

r? `@oli-obk`
2022-04-13 07:50:56 +00:00
Dylan DPC
e96304b73d
Rollup merge of #95973 - oli-obk:tait_ub3, r=compiler-errors
prevent opaque types from appearing in impl headers

cc `@lqd`

opaque types are not distinguishable from their hidden type at the codegen stage. So we could either end up with cases where the hidden type doesn't implement the trait (which will thus ICE) or where the hidden type does implement the trait (so we'd be using its impl instead of the one written for the opaque type). This can even lead to unsound behaviour without unsafe code.

Fixes https://github.com/rust-lang/rust/issues/86411.
Fixes https://github.com/rust-lang/rust/issues/84660.

rebase of #87382 plus some diagnostic tweaks
2022-04-12 23:17:01 +02:00
Dylan DPC
d63a46ad28
Rollup merge of #95970 - WaffleLapkin:nicer_trait_suggestions, r=compiler-errors
Fix suggestions in case of `T:` bounds

This PR fixes a corner case in `suggest_constraining_type_params` that was causing incorrect suggestions.

For the following functions:
```rust
fn a<T:>(t: T) { [t, t]; }
fn b<T>(t: T) where T: { [t, t]; }
```

We previously suggested the following:
```text
...
help: consider restricting type parameter `T`
  |
1 | fn a<T: Copy:>(t: T) { [t, t]; }
  |       ++++++
...
help: consider further restricting this bound
  |
2 | fn b<T>(t: T) where T: + Copy { [t, t]; }
  |                        ++++++
```

Note that neither `T: Copy:` not `where T: + Copy` is a correct bound.

With this commit the suggestions are correct:
```text
...
help: consider restricting type parameter `T`
  |
1 | fn a<T: Copy>(t: T) { [t, t]; }
  |         ++++
...
help: consider further restricting this bound
  |
2 | fn b<T>(t: T) where T: Copy { [t, t]; }
  |                        ++++
```

r? `@compiler-errors`

I've tried fixing #95898 here too, but got too confused with how `suggest_traits_to_import` works and what it does 😅
2022-04-12 23:17:00 +02:00
Dylan DPC
91813a7175
Rollup merge of #95918 - compiler-errors:issue-95878, r=cjgillot
Delay a bug when we see SelfCtor in ref pattern

Fixes #95878
2022-04-12 23:16:59 +02:00
Dylan DPC
2743c13de0
Rollup merge of #95405 - cjgillot:probe, r=petrochenkov
Move name resolution logic to a dedicated file

The code resolution logic from an Ident is scattered between several files.

The first commits creates `rustc_resolve::probe` module to hold the different mutually recursive functions together. Just a move, no code change.
The following commits attempt to make the logic a bit more readable.

The two fields `last_import_segment` and `unusable_binding` are replaced by function parameters.
In order to manage the fallout, `maybe_` variants of the function are added, dedicated to speculative resolution.

r? `@petrochenkov`
2022-04-12 23:16:56 +02:00
Vadim Petrochenkov
276b946010 Handle unusable_binding more compactly. 2022-04-12 22:07:15 +02:00
Oli Scherer
6d0349d2ea
Apply suggestions from code review
Co-authored-by: Michael Goulet <michael@errs.io>
Co-authored-by: Rémy Rakic <remy.rakic+github@gmail.com>
2022-04-12 21:36:09 +02:00
bors
52ca603da7 Auto merge of #95987 - m-ou-se:rollup-sdevd9b, r=m-ou-se
Rollup of 4 pull requests

Successful merges:

 - #95783 (rustdoc doctest: include signal number in exit status)
 - #95794 (`parse_tt`: a few more tweaks)
 - #95963 ([bootstrap] Grab the right FileCheck binary for dist when cross-compiling.)
 - #95975 (Don't test -Cdefault-linker-libraries=yes when cross compiling.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-12 18:44:05 +00:00
Camille GILLOT
443333dc1f Remove NodeIdHashingMode. 2022-04-12 19:59:32 +02:00
Mara Bos
d6843448f1
Rollup merge of #95794 - nnethercote:parse_tt-a-few-more-tweaks, r=petrochenkov
`parse_tt`: a few more tweaks

r? `@petrochenkov`
2022-04-12 19:58:16 +02:00
Camille GILLOT
b796d92da3 Fix imports. 2022-04-12 19:55:47 +02:00
Camille GILLOT
abbd0b85b2 Move diagnostic methods to the dedicated module. 2022-04-12 19:54:09 +02:00
Camille GILLOT
944d852afe Simplify error reporting. 2022-04-12 19:53:46 +02:00
Camille GILLOT
d1c1bbe5f3 Move path resolution error to rustc_resolve::diagnostics. 2022-04-12 19:53:22 +02:00
Camille GILLOT
886613c916 Make the logic more explicit with let chains. 2022-04-12 19:52:58 +02:00
Camille GILLOT
3ee6f6e28a Do not record Res when builing a suggestion. 2022-04-12 19:52:34 +02:00
Camille GILLOT
55ca03c0ac Insert error after checking for binding usability. 2022-04-12 19:52:10 +02:00
Camille GILLOT
24b37a7374 Pass last_import_segment and unusable_binding as parameters. 2022-04-12 19:51:46 +02:00
Camille GILLOT
eb7f5673d9 Simplify binding finalization. 2022-04-12 19:51:22 +02:00
Camille GILLOT
e9a52c27d2 Move ident resolution to a dedicated module. 2022-04-12 19:49:02 +02:00
bors
de56c295c3 Auto merge of #95867 - cjgillot:fixed-size, r=oli-obk
Skip `Lazy` for some metadata tables

Some metadata tables encode their entries indirectly, through the Lazy construct. This is useful when dealing with variable length encoding, but incurs the extra cost of one u32.

Meanwhile, some fields can be encoded in a single u8, or can use a short fixed-length encoding. This PR proposes to do so, and avoid the overhead.
2022-04-12 16:12:48 +00:00
bors
327caac4d0 Auto merge of #95974 - fee1-dead:rollup-2fr55cs, r=fee1-dead
Rollup of 5 pull requests

Successful merges:

 - #95671 (feat: Allow usage of sudo [while not accessing root] in x.py)
 - #95716 (sess: warn w/out fluent bundle w/ user sysroot)
 - #95820 (simplify const params diagnostic on stable)
 - #95900 (Fix documentation for wasm32-unknown-unknown)
 - #95947 (`impl const Default for Box<[T]>` and `Box<str>`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-12 13:06:49 +00:00
fee1-dead
1d76dd9ee7
Rollup merge of #95947 - cuviper:default-box, r=dtolnay
`impl const Default for Box<[T]>` and `Box<str>`

The unstable `const_default_impls` (#87864) already include empty `Vec<T>` and `String`. Now we extend that concept to `Box<[T]>` and `Box<str>` as well.

This obviates a hack in `rustc_ast`'s `P::<[T]>::new`.
2022-04-12 22:44:45 +10:00
fee1-dead
93e6020ed9
Rollup merge of #95820 - OliverMD:95150, r=lcnr
simplify const params diagnostic on stable

Resolves #95150
2022-04-12 22:44:43 +10:00
Oli Scherer
93a3cfb748 Explain the span search logic 2022-04-12 12:31:00 +00:00
Oli Scherer
08ef70bd13 Compute a more precise span for opaque type impls 2022-04-12 12:28:31 +00:00
David Wood
fc3cca24f1 sess: try sysroot candidates for fluent bundle
Instead of checking only the user provided sysroot or the default (when
no sysroot is provided), search user provided sysroot and then check
default sysroots for locale requested by the user.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-12 10:15:37 +01:00
Maybe Waffle
de2edb226b Fix wrong suggestions for T:
This commit fixes a corner case in `suggest_constraining_type_params`
that was causing incorrect suggestions.

For the following functions:
```rust
fn a<T:>(t: T) { [t, t]; }
fn b<T>(t: T) where T: { [t, t]; }
```
We previously suggested the following:
```text
...
help: consider restricting type parameter `T`
  |
1 | fn a<T: Copy:>(t: T) { [t, t]; }
  |       ++++++
...
help: consider further restricting this bound
  |
2 | fn b<T>(t: T) where T: + Copy { [t, t]; }
  |                        ++++++
```
Note that neither `T: Copy:` not `where T: + Copy` is a correct bound.

With this commit the suggestions are correct:
```text
...
help: consider restricting type parameter `T`
  |
1 | fn a<T: Copy>(t: T) { [t, t]; }
  |         ++++
...
help: consider further restricting this bound
  |
2 | fn b<T>(t: T) where T: Copy { [t, t]; }
  |                        ++++
```
2022-04-12 11:29:23 +04:00
Matthias Krüger
c3d6082e9b
Rollup merge of #95936 - TaKO8Ki:fix-relative-paths-error-message, r=Dylan-DPC
Fix a bad error message for `relative paths are not supported in visibilities` error

closes #95638
2022-04-12 08:47:01 +02:00
Matthias Krüger
8d46f9cb57
Rollup merge of #95920 - compiler-errors:cast-suggestion-span, r=oli-obk
use `Span::find_ancestor_inside` to get right span in CastCheck

This is a quick fix. This bad suggestion likely lives in other places... but thought it would be useful to fix all of the CastCheck ones first.

Let me know if reviewer would prefer I add more tests for each of the diagnostics in CastCheck, or would like to do a more thorough review of other suggestions that use spans in typeck. I would also be open to further suggestions on how to better expose an API that gives us the "best" span for a diagnostic suggestion.

Fixed #95919
2022-04-12 08:47:00 +02:00
Matthias Krüger
1b364ae5d6
Rollup merge of #95910 - ehuss:fix-crate-type-duplicate, r=Dylan-DPC
Fix crate_type attribute to not warn on duplicates

In #88681 I accidentally marked the `crate_type` attribute as only allowing a single attribute. However, multiple attributes are allowed (they are joined together [here](027a232755/compiler/rustc_interface/src/util.rs (L530-L542))). This fixes it to not report a warning if duplicates are found.

Closes #95902
2022-04-12 08:46:59 +02:00
Matthias Krüger
3ff5cb20b6
Rollup merge of #95881 - TaKO8Ki:use-to-string-instead-of-format, r=compiler-errors
Use `to_string` instead of `format!`
2022-04-12 08:46:57 +02:00
Matthias Krüger
1d35179077
Rollup merge of #95320 - JakobDegen:mir-docs, r=oli-obk
Document the current MIR semantics that are clear from existing code

This PR adds documentation to places, operands, rvalues, statementkinds, and terminatorkinds that describes their existing semantics and requirements. In many places the semantics depend on the Rust memory model or other T-Lang decisions - when this is the case, it is just noted as such with links to UCG issues where possible. I'm hopeful that none of the documentation added here can be used to justify optimizations that depend on the memory model. The documentation for places and operands probably comes closest to running afoul of this - if people think that it cannot be merged as is, it can definitely also be taken out.

The goal here is to only document parts of MIR that seem to be decided already, or are at least depended on by existing code. That leaves quite a number of open questions - those are marked as "needs clarification." I'm not sure what to do with those in this PR - we obviously can't decide all these questions here. Should I just leave them in as is? Take them out? Keep them in but as `//` instead of `///` comments?

If this is too big to review at once, I can split this up.

r? rust-lang/mir-opt
2022-04-12 08:46:56 +02:00
bors
b8f4cb6231 Auto merge of #95893 - luqmana:no-prepopulate-passes-tweaks, r=nikic
Respect -Z verify-llvm-ir and other flags that add extra passes when combined with -C no-prepopulate-passes in the new LLVM Pass Manager.

As part of the switch to the new LLVM Pass Manager the behaviour of flags such as `-Z verify-llvm-ir` (e.g. sanitizer, instrumentation) was modified when combined with `-C no-prepopulate-passes`. With the old PM, rustc was the one manually constructing the pipeline and respected those flags but in the new pass manager, those flags are used to build a list of callbacks that get invoked at certain extension points in the pipeline. Unfortunately, `-C no-prepopulate-passes` would skip building the pipeline altogether meaning we'd never add the corresponding passes. The fix here is to just manually invoke those callbacks as needed.

Fixes #95874

Demonstrating the current vs fixed behaviour using the bug in #95864
```console
$ rustc +nightly asm-miscompile.rs --edition 2021 --emit=llvm-ir -C no-prepopulate-passes -Z verify-llvm-ir
$ echo $?
0
$ rustc +stage1 asm-miscompile.rs --edition 2021 --emit=llvm-ir -C no-prepopulate-passes -Z verify-llvm-ir
Basic Block in function '_ZN14asm_miscompile3foo28_$u7b$$u7b$closure$u7d$$u7d$17h360e2f7eee1275c5E' does not have terminator!
label %bb1
LLVM ERROR: Broken module found, compilation aborted!
```
2022-04-12 03:26:53 +00:00
Takayuki Maeda
29c41280a1 use to_string instead of format! 2022-04-12 07:51:23 +09:00
Oliver Downard
3b4589a309 simplify const params diagnostic on stable 2022-04-11 21:01:18 +01:00
Jakob Degen
8732bf5db3 Remove rule that place loads may not happen with variant index set 2022-04-11 15:56:04 -04:00
Jakob Degen
4bce639c3b Add more clarifications in response to Ralf's comments 2022-04-11 15:56:04 -04:00
Jakob Degen
411ae6f5ad Address various comments and change some details around place to value conversions 2022-04-11 15:22:32 -04:00
Jakob Degen
1d318e42e7 Improve MIR phases documentation with summaries of changes 2022-04-11 15:22:32 -04:00
Jakob Degen
f2d7908ff7 Adjust MIR validator to check a few more things for terminators 2022-04-11 15:22:32 -04:00
Jakob Degen
f1f25c0f81 Improve documentation for MIR terminators 2022-04-11 15:22:32 -04:00
Jakob Degen
8e01cd6127 Improve documentation for MIR statement kinds. 2022-04-11 15:22:29 -04:00
Jakob Degen
9ac5e986ed Extend the MIR validator to check many more things around rvalues. 2022-04-11 15:18:54 -04:00
Jakob Degen
634369170a Add documentation for the semantics of MIR rvalues 2022-04-11 15:18:54 -04:00