Commit Graph

119 Commits

Author SHA1 Message Date
Oli Scherer
42f1f54a5e Don't treat closures from other crates as local 2023-01-19 11:29:40 +00:00
bors
481725984b Auto merge of #106853 - TimNN:undo-remap, r=oli-obk
Heuristically undo path prefix mappings.

Because the compiler produces better diagnostics if it can find the source of (potentially remapped) dependencies.

The new test fails without the other changes in this PR. Let me know if you have better suggestions for the test directory. I moved the existing remapping test to be in the same location as the new one.

Some more context: I'm exploring running UI tests with remapped paths by default in https://github.com/rust-lang/rust/pull/105924 and this was one of the issues discovered.

This may also be useful in the context of https://github.com/rust-lang/rfcs/pull/3127 ("New rustc and Cargo options to allow path sanitisation by default").
2023-01-16 15:11:28 +00:00
bors
a5bfc25c93 Auto merge of #106872 - dtolnay:nbsp, r=fee1-dead
Emit only one nbsp error per file

Fixes #106101.

See https://github.com/rust-lang/rust/issues/106098 for an explanation of how someone would end up with a large number of these nbsp characters in their source code, which is why I think rustc needs to handle this specific case in a friendlier way.
2023-01-16 09:37:08 +00:00
Matthias Krüger
fc78b1e7f9
Rollup merge of #106909 - compiler-errors:only-types-can-be, r=estebank
Only suggest adding type param if path being resolved was a type
2023-01-15 21:17:36 +01:00
Matthias Krüger
5321ad574d
Rollup merge of #106900 - clubby789:unused-braces-regression, r=estebank
Fix regression in `unused_braces` with macros

Fixes #106899
2023-01-15 21:17:35 +01:00
Matthias Krüger
5610231454
Rollup merge of #106896 - Ezrashaw:str-cast-bool-emptyness, r=compiler-errors
suggest `is_empty` for collections when casting to `bool`

Fixes #106883

Matches on slices, `String` and `str`. It would be nice to do this with something like `Deref<Target=str>` as well, but AFAIK it's not possible in this part of the compiler.
2023-01-15 21:17:34 +01:00
Michael Goulet
566202b975 Only suggest adding type param if path being resolved was a type 2023-01-15 16:33:08 +00:00
bors
fc11ee02ee Auto merge of #106171 - compiler-errors:consolidate-extract_callable_info, r=estebank,lcnr
Consolidate two almost duplicated fn info extraction routines

Moves `extract_callable_info` up to trait selection, because it was being (almost) duplicated fully there for similar diagnostic purposes. This also generalizes the diagnostics we can give slightly (see UI test).
2023-01-15 12:10:36 +00:00
Ezra Shaw
92ced4a12e
suggest is_empty for collections when casting to bool 2023-01-15 22:17:54 +13:00
clubby789
295f5483fe Fix regression in unused_braces with macros 2023-01-15 05:08:30 +00:00
Matthias Krüger
30b963c05c
Rollup merge of #106879 - JohnTitor:issue-42114, r=compiler-errors
Add regression test for #42114

Closes #42114
r? compiler-errors
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2023-01-15 01:01:39 +01:00
Matthias Krüger
08ef0ce056
Rollup merge of #106878 - JohnTitor:issue-92157, r=compiler-errors
Add regression test for #92157

Closes #92157
r? compiler-errors
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2023-01-15 01:01:38 +01:00
Matthias Krüger
980bf1979e
Rollup merge of #106859 - tialaramex:master, r=Nilstrieb
Suggestion for type mismatch when we need a u8 but the programmer wrote a char literal

Today Rust just points out that we have a char and we need a u8, but if I wrote 'A' then I could fix this by just writing b'A' instead. This code should detect the case where we're about to report a type mismatch of this kind, and the programmer wrote a char literal, and the char they wrote is ASCII, so therefore just prefixing b to make a byte literal will do what they meant.

I have definitely written this mistake more than once, it's not difficult to figure out what to do, but the compiler might as well tell us anyway.

I provided a test with two simple examples where the suggestion is appropriate, and one where it is not because the char literal is not ASCII, showing that the suggestion is only triggered in the former cases.

I have contributed only a small typo doc fix before, so this is my first substantive rustc change.
2023-01-15 01:01:36 +01:00
Matthias Krüger
d7fcd01f67
Rollup merge of #106072 - eopb:dyn-derive, r=estebank
fix: misleading "add dyn keyword before derive macro" suggestion

Fixes #106071
2023-01-15 01:01:36 +01:00
Nick Lamb
130d02b62e Improve E0308: suggest user meant to use byte literal, w/ tests and fix
suggested by Nilstrieb

Co-authored-by: nils <48135649+Nilstrieb@users.noreply.github.com>
2023-01-14 21:27:14 +00:00
Yuki Okushi
cf5be0c3ac
Add regression test for #42114
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2023-01-15 05:52:22 +09:00
Yuki Okushi
aa51a0f19a
Add regression test for #92157
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2023-01-15 05:47:24 +09:00
David Tolnay
dab06ccdab
Emit only one nbsp error per file 2023-01-14 11:06:22 -08:00
David Tolnay
39edcfa84e
Add more nbsp to unicode-chars test 2023-01-14 11:04:36 -08:00
Matthias Krüger
f04f97cea4
Rollup merge of #106820 - m-ou-se:macro-type-error-thing, r=estebank
Deprioritize fulfillment errors that come from expansions.

Fixes (part of?) #69455
2023-01-14 18:45:27 +01:00
Matthias Krüger
d7bc758638
Rollup merge of #106563 - clubby789:gce-macro-braces, r=TaKO8Ki
Fix `unused_braces` on generic const expr macro call

Fixes #106545

`@rustbot` label +A-const-generics +A-lint
2023-01-14 18:45:26 +01:00
clubby789
4f64de83bc Fix unused_braces on generic const expr macro call 2023-01-14 15:49:08 +00:00
Mara Bos
6821adb651 Deprioritize fulfillment errors that come from expansions. 2023-01-14 14:05:26 +01:00
Tim Neumann
869df76764 Heuristically undo path prefix mappings.
Because the compiler produces better diagnostics if it can find the
source of (potentially remapped) dependencies.
2023-01-14 12:49:37 +00:00
Ethan Brierley
1caec6fa1d fix: misleading add dyn to derive macro suggestion 2023-01-14 12:14:06 +00:00
Matthias Krüger
8c538f7d83
Rollup merge of #106788 - estebank:elaborate_pred_E0599, r=compiler-errors
Tweak E0599 and elaborate_predicates

CC https://github.com/rust-lang/rust/issues/86377.
2023-01-14 13:04:26 +01:00
Matthias Krüger
108b5f462b
Rollup merge of #106752 - sulami:master, r=estebank
Emit a hint for bad call return types due to generic arguments

When the return type of a function call depends on the type of an argument, e.g.

```
fn foo<T>(x: T) -> T {
    x
}
```

and the expected type is set due to either an explicitly typed binding, or because the call to the function is in a tail position without semicolon, the current error implies that the argument in the call has the wrong type.

This new hint highlights that the expected type doesn't match the returned type, which matches the argument type, and that that's why we're flagging the argument type.

Fixes #43608.
2023-01-14 13:04:26 +01:00
Matthias Krüger
3fa9be9094
Rollup merge of #106665 - JulianKnodt:better_fn_trait_note, r=cjgillot
Add note when `FnPtr` vs. `FnDef` impl trait

I encountered an instance where an `FnPtr` implemented a trait, but I was passing an `FnDef`. I was confused for an hour and to examine the source code of the trait's crate's tests in order to understand how to cast it properly (it didn't help that it was behind a reference). To the end user, it might not be immediately obvious that they are different and how to convert from an `FnDef` to an `FnPtr`, but it is necessary to cast to the generic function in order to compile. It is thus useful to suggest `as` in the help note, (even if the `Fn` output implements the trait).
2023-01-14 13:04:25 +01:00
Matthias Krüger
8e0eecdba6
Rollup merge of #106566 - clubby789:contiguous-weird-unicode, r=cjgillot
Emit a single error for contiguous sequences of unknown tokens

Closes #106101

On encountering a sequence of identical source characters which are unknown tokens, note the amount of subsequent characters and advance past them silently. The old behavior was to emit an error and 'help' note for every single one.

`@rustbot` label +A-diagnostics +A-parser
2023-01-14 13:04:24 +01:00
kadmin
2de9d679ad Add note when FnPtr vs. FnDef impl trait
I encountered an instance where an `FnPtr` implemented a trait, but I was passing an `FnDef`. To
the end user, there is really no way to differentiate each of them, but it is necessary to cast
to the generic function in order to compile. It is thus useful to suggest `as` in the help note,
(even if the Fn output implements the trait).
2023-01-14 10:37:56 +00:00
Yuki Okushi
7d02116832
Rollup merge of #106816 - TimNN:rental-remap, r=oli-obj
Update `rental` hack to work with remapped paths.

This PR simply switches to an already-existing helper instead of hard-coding a specific enum variant. The new revision of the test fails without the other changes in this PR.

Context: I'm exploring running UI tests with remapped paths by default in #105924 and the rental test was one of the ones that failed.

This may also be useful in the context of https://github.com/rust-lang/rfcs/pull/3127 ("New rustc and Cargo options to allow path sanitisation by default").
2023-01-14 12:04:37 +09:00
Michael Goulet
b2df88bae1 Consolidate two almost duplicated fn info extraction routines 2023-01-13 22:43:17 +00:00
Esteban Küber
22a0e4fa6e Do not incorrectly suggest restricting implied bounds
When we have already suggested bounds that imply the about to be
suggested bound, skip them.
2023-01-13 20:50:34 +00:00
Tim Neumann
496edf97c5 Update rental hack to work with remapped paths. 2023-01-13 20:36:03 +00:00
Esteban Küber
81ba427a7b Add tests 2023-01-13 18:20:24 +00:00
Esteban Küber
3d6b09e53e Keep obligation chain when elaborating obligations 2023-01-13 18:20:23 +00:00
Esteban Küber
f6e6d2a035 Elaborate unmet obligations in E0599 for more context 2023-01-13 18:20:23 +00:00
Matthias Krüger
e0f6840bb6
Rollup merge of #106793 - Mark-Simulacrum:normalize-test, r=compiler-errors
Normalize test output more thoroughly

This prevents differences in local environments, which may (for example) end up with a longer backtrace with more digits in the backtrace prefix, as happened to me. While we're at it, clean more of the output up, including the exact location of the error in the compiler.

cc https://github.com/rust-lang/rust/pull/106521 which introduced this test
2023-01-13 19:16:44 +01:00
Matthias Krüger
e4d0104754
Rollup merge of #106678 - Veykril:proc-macro-panic-abort, r=eholk
Warn when using panic-strategy abort for proc-macro crates

See https://github.com/rust-lang/rust/issues/82320, this simply warns for now as that seems like the best step that can be immediately taken (opposed to straight up rejecting or ignoring)
2023-01-13 19:16:43 +01:00
Matthias Krüger
57b371ab14
Rollup merge of #106641 - chenyukang:yukang/fix-105761-segguest-this, r=estebank
Provide help on closures capturing self causing borrow checker errors

Fixes #105761

r? ````@estebank````
2023-01-13 19:16:43 +01:00
Matthias Krüger
c6e3a47843
Rollup merge of #106585 - estebank:issue-46585, r=compiler-errors
When suggesting writing a fully qualified path probe for appropriate types

Address the more common part of #46585.
2023-01-13 19:16:42 +01:00
Matthias Krüger
1dc43b2e8b
Rollup merge of #106465 - compiler-errors:bump-IMPLIED_BOUNDS_ENTAILMENT, r=lcnr
Bump `IMPLIED_BOUNDS_ENTAILMENT` to Deny + ReportNow

https://github.com/rust-lang/rust/pull/105575#issuecomment-1357201969

> and then later in the same cycle increase the lint to `deny` and change it to `FutureCompatReportNow` in this nightly cycle.

r? ```@lcnr``` when they're back from holiday 😄
2023-01-13 19:16:41 +01:00
Matthias Krüger
96bb02f35c
Rollup merge of #104645 - yukiomoto:log-backtrace-option, r=oli-obk
Add log-backtrace option to show backtraces along with logging

according to #90698, I added a compiler option, `-Zlog-backtrace=filter`, where `filter` is a module name, to show backtraces for logging without rebuilding.

resolve #90698
2023-01-13 19:16:41 +01:00
bors
5ca6f7d2c3 Auto merge of #106801 - JohnTitor:rollup-xqkraw0, r=JohnTitor
Rollup of 6 pull requests

Successful merges:

 - #106608 (Render missing generics suggestion verbosely)
 - #106716 ([RFC 2397] Deny incorrect locations)
 - #106754 (Rename `Ty::is_ty_infer` -> `Ty::is_ty_or_numeric_infer`)
 - #106782 (Ignore tests move in git blame)
 - #106785 (Make blame spans better for impl wfcheck)
 - #106791 (Fix ICE formatting)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-13 10:56:53 +00:00
Lukas Wirth
549ece7033 Warn when using panic-strategy abort for proc-macro crates 2023-01-13 10:13:49 +01:00
Yuki Okushi
5adc7a5e37
Rollup merge of #106785 - compiler-errors:better-impl-wf-spans, r=estebank
Make blame spans better for impl wfcheck

r? types
2023-01-13 16:54:24 +09:00
Yuki Okushi
f6f362c332
Rollup merge of #106716 - c410-f3r:rfc-2397-1, r=davidtwco
[RFC 2397] Deny incorrect locations

cc #51992

As declared in the RFC, `#[do_not_recommend]` should only be applicable on trait implementations.
2023-01-13 16:54:23 +09:00
Yuki Okushi
9a2f3937fc
Rollup merge of #106608 - compiler-errors:missing-generics-verbose, r=estebank
Render missing generics suggestion verbosely

It's a bit easier to read like this, especially ones that are appending new generics onto an existing list, like ": `, T`" which render somewhat poorly inline.

Also don't suggest `dyn` as a type parameter to add, even if technically that's valid in edition 2015.
2023-01-13 16:54:22 +09:00
bors
4a04f252f9 Auto merge of #106092 - asquared31415:start_lang_item_checks, r=davidtwco
Add checks for the signature of the `start` lang item

Closes #105963
2023-01-13 07:45:34 +00:00
bors
279f1c9d8c Auto merge of #106004 - fee1-dead-contrib:const-closures, r=oli-obk
Const closures

cc https://github.com/rust-lang/rust/issues/106003
2023-01-13 05:04:48 +00:00