2202 Commits

Author SHA1 Message Date
Camille GILLOT
4bbe078d92 Drop vis in Item. 2022-04-23 09:59:24 +02:00
Camille GILLOT
10d10efb21 Stop visiting visibility. 2022-04-23 09:53:45 +02:00
Matthias Krüger
b100c02fae
Rollup merge of - TaKO8Ki:make-E0117-error-clear, r=davidtwco
Make `E0117` error clear

closes 
2022-04-22 18:56:25 +02:00
Takayuki Maeda
f5a8ee4dd8 remove an error for type params 2022-04-22 11:25:42 +09:00
Dylan DPC
5ebb8b06d6
Rollup merge of - aDotInTheVoid:redundant-fmt, r=jackh726
Remove redundant `format!`s
2022-04-21 20:55:21 +02:00
Nixon Enraght-Moony
8fa20e01a5 Remove redundant format!s 2022-04-21 16:46:20 +01:00
Takayuki Maeda
547cb2722b make E0117 error clear 2022-04-21 16:47:01 +09:00
David Wood
437468daf7 typeck: remove unnecessary fluent attr
Specifying "suggestion" as the attribute for the only suggestion is
unnecessary, it's the default of the derive.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-21 04:03:13 +01:00
Dylan DPC
036d200d1c
Rollup merge of - TaKO8Ki:fix-invalid-error-for-suggestion-to-add-slice-in-pattern-matching, r=nagisa
Fix an invalid error for a suggestion to add a slice in pattern-matching

closes 
2022-04-19 14:43:20 +02:00
bors
e2661bac6d Auto merge of - icewind1991:suggest-associated-type-more, r=jackh726
show suggestion to replace generic bounds with associated types in more cases

Moves the hint to replace generic parameters with associated type bounds from the "not all associated type bounds are specified"(`E0191`) to "to many generic type parameters provided"(`E0107`).

Since `E0191` is only emitted in places where all associated types must be specified (when creating `dyn` types), the suggesting is currently not shown for other generic type uses (such as in generic type bounds). With this change the suggesting is always emitted when the number of excess generic parameters matches the number of unbound associated types.

Main motivation for the change was a lack of useful suggesting when doing

```rust
fn foo<I: Iterator<usize>>(i: I) {}
```
2022-04-19 01:59:35 +00:00
Takayuki Maeda
5924ef874e stop using Autoderef 2022-04-18 12:51:12 +09:00
bors
edba282770 Auto merge of - kckeiks:create-hir-crate-items-query, r=cjgillot
Refactor HIR item-like traversal (part 1)

Issue  

- Create hir_crate_items query which traverses tcx.hir_crate(()).owners to return a hir::ModuleItems
- use tcx.hir_crate_items in tcx.hir().items() to return an iterator of hir::ItemId
- use tcx.hir_crate_items to introduce a tcx.hir().par_items(impl Fn(hir::ItemId)) to traverse all items in parallel;

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>

cc `@cjgillot`
2022-04-17 08:06:53 +00:00
Robin Appelman
decc04dbfb show suggestion to replace generic bounds with associated types in more cases 2022-04-17 00:44:36 +02:00
Dylan DPC
99437b303a
Rollup merge of - niluxv:strict-provenance-lint-improvements, r=nagisa
Strict provenance lint diagnostics improvements

Use `multipart_suggestion` instead of `span_suggestion` and getting a snippet for the expression. Also don't suggest unnecessary parenthesis in `lossy_provenance_casts`.
cc ``@estebank``
``@rustbot`` label A-diagnostics
2022-04-17 00:07:26 +02:00
Takayuki Maeda
a59cc5774b fix an invalid error for a suggestion to add a slice in pattern-matching 2022-04-17 01:20:11 +09:00
bors
c8422403f7 Auto merge of - Dylan-DPC:rollup-t5f2fc9, r=Dylan-DPC
Rollup of 9 pull requests

Successful merges:

 -  (Only add codegen backend to dep info if -Zbinary-dep-depinfo is used)
 -  (Add missing links in platform support docs)
 -  (make unaligned_references lint deny-by-default)
 -  (Improve diagnostics for unterminated nested block comment)
 -  (implement SIMD gather/scatter via vector getelementptr)
 -  (Consider lifetimes when comparing types for equality in MIR validator)
 -  (Remove some now-dead code that was only relevant before deaggregation.)
 -  ([test] Add test cases for untested functions for BTreeMap)
 -  (MaybeUninit array cleanup)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-16 09:19:26 +00:00
niluxv
1d63d6db55 Improve fuzzy_provenance_casts lint diagnostics
Use `multipart_suggestion` instead of getting a snippet.
2022-04-16 10:40:06 +02:00
niluxv
02d12bc30c Improve lossy_provenance_casts lint diagnostics
Use `multipart_suggestion` and don't suggested unnecessary parenthesis.
2022-04-16 10:32:37 +02:00
bors
07bb916d44 Auto merge of - jackh726:Quantumplation/65853/param-heuristics, r=estebank
Better method call error messages

Rebase/continuation of 

~Based on #92360~
~Based on #93118~

There's a decent description in  that I won't copy here (for now at least)

In addition to rebasing, I've tried to restore most of the original suggestions for invalid arguments. Unfortunately, this does make some of the errors a bit verbose. To fix this will require a bit of refactoring to some of the generalized error suggestion functions, and I just don't have the time to go into it right now.

I think this is in a state that the error messages are overall better than before without a reduction in the suggestions given.

~I've tried to split out some of the easier and self-contained changes into separate commits (mostly in , but also one here). There might be more than can be done here, but again just lacking time.~

r? `@estebank` as the original reviewer of 
2022-04-16 06:55:28 +00:00
Jack Huey
b6c87c555f Implementation for 65853
This attempts to bring better error messages to invalid method calls, by applying some heuristics to identify common mistakes.

The algorithm is inspired by Levenshtein distance and longest common sub-sequence.   In essence, we treat the types of the function, and the types of the arguments you provided as two "words" and compute the edits to get from one to the other.

We then modify that algorithm to detect 4 cases:

 - A function input is missing
 - An extra argument was provided
 - The type of an argument is straight up invalid
 - Two arguments have been swapped
 - A subset of the arguments have been shuffled

(We detect the last two as separate cases so that we can detect two swaps, instead of 4 parameters permuted.)

It helps to understand this argument by paying special attention to terminology: "inputs" refers to the inputs being *expected* by the function, and "arguments" refers to what has been provided at the call site.

The basic sketch of the algorithm is as follows:

 - Construct a boolean grid, with a row for each argument, and a column for each input.  The cell [i, j] is true if the i'th argument could satisfy the j'th input.
 - If we find an argument that could satisfy no inputs, provided for an input that can't be satisfied by any other argument, we consider this an "invalid type".
 - Extra arguments are those that can't satisfy any input, provided for an input that *could* be satisfied by another argument.
 - Missing inputs are inputs that can't be satisfied by any argument, where the provided argument could satisfy another input
 - Swapped / Permuted arguments are identified with a cycle detection algorithm.

As each issue is found, we remove the relevant inputs / arguments and check for more issues.  If we find no issues, we match up any "valid" arguments, and start again.

Note that there's a lot of extra complexity:
 - We try to stay efficient on the happy path, only computing the diagonal until we find a problem, and then filling in the rest of the matrix.
 - Closure arguments are wrapped in a tuple and need to be unwrapped
 - We need to resolve closure types after the rest, to allow the most specific type constraints
 - We need to handle imported C functions that might be variadic in their inputs.

I tried to document a lot of this in comments in the code and keep the naming clear.
2022-04-16 02:26:56 -04:00
Dylan DPC
ea131bca17
Rollup merge of - RalfJung:gather-scatter, r=workingjubilee
implement SIMD gather/scatter via vector getelementptr

Fixes https://github.com/rust-lang/portable-simd/issues/271

However, I don't *really* know what I am doing here... Cc ``@workingjubilee`` ``@calebzulawski``

I didn't do anything for cranelift -- ``@bjorn3`` not sure if it's okay for that backend to temporarily break. I'm happy to cherry-pick a patch that adds cranelift support. :)
2022-04-16 07:12:45 +02:00
bors
080d5452e1 Auto merge of - Amanieu:global_asm_sym, r=nagisa
Implement sym operands for global_asm!

Tracking issue: 

This PR is pretty much a complete rewrite of `sym` operand support for inline assembly so that the same implementation can be shared by `asm!` and `global_asm!`. The main changes are:
- At the AST level, `sym` is represented as a special `InlineAsmSym` AST node containing a path instead of an `Expr`.
- At the HIR level, `sym` is split into `SymStatic` and `SymFn` depending on whether the path resolves to a static during AST lowering (defaults to `SynFn` if `get_early_res` fails).
  - `SymFn` is just an `AnonConst`. It runs through typeck and we just collect the resulting type at the end. An error is emitted if the type is not a `FnDef`.
  - `SymStatic` directly holds a path and the `DefId` of the `static` that it is pointing to.
- The representation at the MIR level is mostly unchanged. There is a minor change to THIR where `SymFn` is a constant instead of an expression.
- At the codegen level we need to apply the target's symbol mangling to the result of `tcx.symbol_name()` depending on the target. This is done by calling the LLVM name mangler, which handles all of the details.
  - On Mach-O, all symbols have a leading underscore.
  - On x86 Windows, different mangling is used for cdecl, stdcall, fastcall and vectorcall.
  - No mangling is needed on other platforms.

r? `@nagisa`
cc `@eddyb`
2022-04-16 04:46:01 +00:00
Dylan DPC
fa281fdf65
Rollup merge of - TaKO8Ki:use-format-args-capture-and-remove-unnecessary-nested-blocks, r=compiler-errors
Refactor: Use `format-args-capture` and remove unnecessary nested blocks in rustc_typeck
2022-04-15 20:50:52 +02:00
Dylan DPC
ba9c3a13ee
Rollup merge of - matthiaskrgr:clippy_compl_1304, r=Dylan-DPC
couple of clippy::complexity fixes
2022-04-15 20:50:47 +02:00
Dylan DPC
bdbf0998f3
Rollup merge of - kckeiks:update-algo-in-find-use-placement, r=pnkfelix
remove find_use_placement

A more robust solution to finding where to place use suggestions was added in .
The algorithm uses the AST to find the span for the suggestion so we pass this span
down to the HIR during lowering and use it instead of calling `find_use_placement`

Fixes 
2022-04-15 20:50:45 +02:00
Dylan DPC
a32e0f3041
Rollup merge of - ouz-a:master4, r=oli-obk
Check var scope if it exist

Fixes .

Added helper function to check the scope of a variable, if it doesn't have a scope call delay_span_bug, which avoids us trying to get a block/scope that doesn't exist.

Had to increase `ROOT_ENTRY_LIMIT` was getting tidy error
2022-04-15 20:50:44 +02:00
Takayuki Maeda
f9188ccef6 use format-args-capture and remove unnecessary nested block 2022-04-15 15:56:32 +09:00
ouz-a
c20bb1d59f Update issue-92893.stderr 2022-04-14 23:42:15 +03:00
Vadim Petrochenkov
5bee741a08 library: Move CStr to libcore, and CString to liballoc 2022-04-14 21:53:11 +03:00
Amanieu d'Antras
dc345d8bff Reimplement lowering of sym operands for asm! so that it also works with global_asm! 2022-04-14 15:32:03 +01:00
Matthias Krüger
7c2d57e0fa couple of clippy::complexity fixes 2022-04-13 22:51:34 +02:00
Bruno Felipe Francisco
9b9f677104 fix: wrong trait import suggestion for T: 2022-04-13 11:02:01 -03:00
Dylan DPC
e96304b73d
Rollup merge of - 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  plus some diagnostic tweaks
2022-04-12 23:17:01 +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
Ralf Jung
7f945b2b5b add simd_arith_offset intrinsics 2022-04-12 11:09:26 -04:00
bors
327caac4d0 Auto merge of - fee1-dead:rollup-2fr55cs, r=fee1-dead
Rollup of 5 pull requests

Successful merges:

 -  (feat: Allow usage of sudo [while not accessing root] in x.py)
 -  (sess: warn w/out fluent bundle w/ user sysroot)
 -  (simplify const params diagnostic on stable)
 -  (Fix documentation for wasm32-unknown-unknown)
 -  (`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
93e6020ed9
Rollup merge of - OliverMD:95150, r=lcnr
simplify const params diagnostic on stable

Resolves 
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
Matthias Krüger
8d46f9cb57
Rollup merge of - 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 
2022-04-12 08:47:00 +02:00
Oliver Downard
3b4589a309 simplify const params diagnostic on stable 2022-04-11 21:01:18 +01:00
Rémy Rakic
7d5bbf55f2 prevent opaque types from appearing in impl headers 2022-04-11 15:11:27 +00:00
bors
d00e77078c Auto merge of - compiler-errors:issue-54771, r=estebank
Only suggest removing semicolon when expression is compatible with `impl Trait`

https://github.com/rust-lang/rust/issues/54771#issuecomment-476423690
> It still needs checking that the last statement's expr can actually conform to the trait, but the naïve behavior is there.

Only suggest removing a semicolon when the type behind the semicolon actually implements the trait in an RPIT `-> impl Trait`. Also upgrade the label that suggests removing the semicolon to a suggestion (should it be verbose?).

cc 
2022-04-11 08:31:37 +00:00
Michael Goulet
d2b1bb8a9b use find_ancestor_inside to get right span in CastCheck 2022-04-10 22:15:31 -07:00
Michael Goulet
dfe13dbbcf only suggest removing semicolon when expr implements trait 2022-04-10 16:30:14 -07:00
bors
1f7fb6413d Auto merge of - Dylan-DPC:rollup-1cmywu4, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 -  (Avoid duplication of doc comments in `std::char` constants and functions)
 -  (Suggest replacing `typeof(...)` with an actual type)
 -  (Suggest adding a local for vector to fix borrowck errors)
 -  (Check for git submodules in non-git source tree.)
 -  (Fix missing space in lossy provenance cast lint)
 -  (Allow multiple derefs to be splitted in deref_separator)
 -  (rustdoc: Reduce allocations in a `html::markdown` function)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-10 21:01:13 +00:00
Dylan DPC
a52eb325e6
Rollup merge of - niluxv:strict-provenance-lint-fixup, r=Dylan-DPC
Fix missing space in lossy provenance cast lint

See https://github.com/rust-lang/rust/pull/95599#discussion_r846425050
2022-04-10 21:03:37 +02:00
Dylan DPC
54597ba11f
Rollup merge of - WaffleLapkin:typeof_cool_suggestion, r=compiler-errors
Suggest replacing `typeof(...)` with an actual type

This PR adds suggestion to replace `typeof(...)` with an actual type of `...`, for example in case of `typeof(1)` we suggest replacing it with `i32`.

If the expression
1. Is not const (`{ let a = 1; let _: typeof(a); }`)
2. Can't be found (`let _: typeof(this_variable_does_not_exist)`)
3. Or has non-suggestable type (closure, generator, error, etc)
we don't suggest anything.

The 1 one is sad, but it's not clear how to support non-consts expressions for `typeof`.

_This PR is inspired by [this tweet]._

[this tweet]: https://twitter.com/compiler_errors/status/1511945354752638976
2022-04-10 21:03:34 +02:00
Camille GILLOT
bbacfcb6c4 Avoid checking HIR in variances_of. 2022-04-10 13:58:29 +02:00
Camille GILLOT
69d8183337 Store LocalDefId in is_late_bound_map.
This allows to avoid looking at HIR from borrowck.
2022-04-10 13:36:06 +02:00