Commit Graph

340 Commits

Author SHA1 Message Date
Esteban Küber
e477cf9475 Suggest coercion of Result using ?
Fix #47560.
2023-01-23 14:46:59 +00:00
Oli Scherer
bcc8b05d5c Make output_filenames a real query 2023-01-23 10:35:21 +00:00
Yuki Okushi
809d4aa478
Rollup merge of #107148 - Ezrashaw:uncode-e0789, r=compiler-errors,GuillaumeGomez
remove error code from `E0789`, add UI test/docs

`E0789` shouldn't have an error code, it's explicitly internal-only and is tiny in scope. (I wonder if we can tighten the standard for this in the RFC?) I also added a UI test and error docs (done like `E0208`, they are "no longer emitted").

r? `@GuillaumeGomez` (shouldn't need a compiler review, it's pretty minor)
2023-01-23 19:30:00 +09:00
Ezra Shaw
00ff718da8
add UI test + docs for E0789 2023-01-23 20:38:14 +13:00
Dylan DPC
66d6a0b5da
Rollup merge of #107203 - chenyukang:yukang/fix-106496-remove-deref, r=compiler-errors
Suggest remove deref for type mismatch

Fixes #106496
2023-01-23 11:52:07 +05:30
Dylan DPC
f4f3335114
Rollup merge of #107108 - sulami:issue-83968-doc-alias-typo-suggestions, r=compiler-errors
Consider doc(alias) when providing typo suggestions

This means that

```rust
impl Foo {
    #[doc(alias = "quux")]
    fn bar(&self) {}
}

fn main() {
    (Foo {}).quux();
}
```

will suggest `bar`. This currently uses the "there is a method with a similar name" help text, because the point where we choose and emit a suggestion is different from where we gather the suggestions. Changes have mainly been made to the latter.

The selection code will now fall back to aliased candidates, but generally only if there is no candidate that matches based on the existing Levenshtein methodology.

Fixes #83968.
2023-01-23 11:52:05 +05:30
Dylan DPC
3d4c3125be
Rollup merge of #104926 - spastorino:calculate_diverging_fallback-cleanups, r=lcnr
Move relationships from FulfillmentContext to Inherited

r? `@lcnr`
2023-01-23 11:52:04 +05:30
Robin Schroer
f908f0be5a
Consider doc(alias) when providing typo suggestions
This means that

```rust
impl Foo {
    #[doc(alias = "quux")]
    fn bar(&self) {}
}

fn main() {
    (Foo {}).quux();
}
```

will suggest `bar`. This currently uses the "there is a method with a
similar name" help text, because the point where we choose and emit a
suggestion is different from where we gather the suggestions. Changes
have mainly been made to the latter.

The selection code will now fall back to aliased candidates, but
generally only if there is no candidate that matches based on the
existing Levenshtein methodology.

Fixes #83968.
2023-01-23 10:07:10 +09:00
yukang
2aa5555ad3 Fix #106496, suggest remove deref for type mismatch 2023-01-23 00:42:20 +08:00
Santiago Pastorino
b905f80036
fn-trait-closure test now pass on new solver 2023-01-22 12:36:58 -03:00
Matthias Krüger
6e79310c55
Rollup merge of #107111 - chenyukang:yukang/fix-107090-fluent-parameters, r=petrochenkov
Fix missing arguments issues and copy-paste bug for fluent

Fixes #107090
2023-01-22 11:43:06 +01:00
bors
940d00f2f6 Auto merge of #107185 - compiler-errors:rollup-wkomjma, r=compiler-errors
Rollup of 8 pull requests

Successful merges:

 - #103418 (Add `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` to future-incompat report)
 - #106113 (llvm-wrapper: adapt for LLVM API change)
 - #106144 (Improve the documentation of `black_box`)
 - #106578 (Label closure captures/generator locals that make opaque types recursive)
 - #106749 (Update cc to 1.0.77)
 - #106935 (Fix `SingleUseLifetime` ICE)
 - #107015 (Re-enable building rust-analyzer on riscv64)
 - #107029 (Add new bootstrap members to triagebot.toml)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-22 06:53:36 +00:00
Michael Goulet
8a830cf182
Rollup merge of #106935 - TaKO8Ki:fix-104440, r=cjgillot
Fix `SingleUseLifetime` ICE

Fixes #104440
cc: ``@matthiaskrgr``
2023-01-21 23:21:00 -05:00
Michael Goulet
1d2c9a84fa
Rollup merge of #106578 - compiler-errors:recursive-opaque-closure, r=TaKO8Ki
Label closure captures/generator locals that make opaque types recursive

cc https://github.com/rust-lang/rust/issues/46415#issuecomment-1374665828
2023-01-21 23:20:59 -05:00
Michael Goulet
bdcfa6c9aa
Rollup merge of #103418 - Aaron1011:macro-semicolon-future-incompat, r=davidtwco
Add `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` to future-incompat report

See https://github.com/rust-lang/rust/issues/79813 for a discussion of this lint. This has been warn-by-default for over a year, so adding it to the future-incompat report should help to find libraries that haven't yet updated.
2023-01-21 23:20:58 -05:00
bors
85da15c016 Auto merge of #107133 - pnkfelix:revert-pr-84022-for-issue-106337, r=Mark-Simulacrum
Revert "Make PROC_MACRO_DERIVE_RESOLUTION_FALLBACK a hard error"

This reverts commit 7d82cadd97 aka PR #84022

I am doing this to buy us some time with respect to issue #106337 w.r.t. the 1.67 release.
2023-01-22 03:58:52 +00:00
Aaron Hill
dc8876196b
Add SEMICOLON_IN_EXPRESSIONS_FROM_MACROS to future-incompat report 2023-01-21 14:38:25 -06:00
bors
52372f9c71 Auto merge of #105924 - TimNN:ui-remap, r=Mark-Simulacrum
Remap paths in UI tests by default

If you think this needs further discussions / something RFC-like, please let me know the best forum for that.

This PR runs UI tests with a remapped "src base" directory by default.

Why? Because some UI tests currently depend on the length of the absolute path to the `src/test/ui` directory. Remapping makes the tests independent of the absolute path.

The path to the source file (which is absolute on CI) is part of the type name of closures. `rustc` diagnostic output depends on the length of type names (long type names are truncated). So a long absolute path leads to long closure type names, which leads to truncation and changed diagnostics.

(I initially tried just disabling type name truncation, but that made some error messages stupid long (thousands of characters, IIRC)).

Additional changes:

* All boolean `compiletest` directives now support explicit `no-` versions to disable them.
* Adapt existing tests when necessary:
  * Disable remapping for individual tests that fail with it enabled (when there's no obvious alternative fix).
  * For tests that already check something remapping related switch to the new option unless we gain something significant by keeping the manual remap.

Passed Windows CI in https://github.com/rust-lang/rust/actions/runs/3933100590
2023-01-21 17:44:20 +00:00
bors
b22aa57fd5 Auto merge of #106884 - clubby789:fieldless-enum-debug, r=michaelwoerister
Simplify `derive(Debug)` output for fieldless enums

Fixes #106875
2023-01-21 07:49:09 +00:00
Michael Goulet
8742fd9c85 Label closure captures/generator locals that make opaque types recursive 2023-01-21 05:49:36 +00:00
Michael Goulet
3452104715
Rollup merge of #107061 - compiler-errors:new-solver-new-candidates-3, r=lcnr
Implement some more new solver candidates and fix some bugs

First, fix some bugs:

1. `IndexVec::drain_enumerated(a..b)` does not give us an iterator of index keys + items enumerated from `a..b`, but from `0..(b-a)`... That caused a bug. See first commit for the fix.
2. Implement the `_: Trait` ambiguity hack. I put it in assemble, let me know if it should live elsewhere. This is important, since we otherwise consider `_: Sized` to have no solutions, and nothing passes!
3. Swap `Ambiguity` and `Unimplemented` cases for the new solver. Sorry for accidentally swapping them 😄
4. Check GATs' own predicates during projection confirmation.

Then implement a few builtin traits:

5. Implement `PointerSized`. Pretty independent.
6. Implement `Fn` family of traits for fnptr, fndef, and closures. Closures are currently broken because `FulfillCtxt::relationships` is intentionally left unimplemented. See comment in the test.

r? ```@lcnr```
2023-01-20 21:33:22 -05:00
Michael Goulet
bf75f8177b
Rollup merge of #104347 - notriddle:notriddle/import-macro-from-self-fixup, r=TaKO8Ki
diagnostics: suggest changing `s@self::{macro}@::macro` for exported

Fixes #99695
2023-01-20 21:33:21 -05:00
Michael Goulet
e6400693b8
Rollup merge of #104154 - timrobertsdev:deny-by-default-bindings_with_variant_name, r=scottmcm
Change `bindings_with_variant_name` to deny-by-default

Changed the `bindings_with_variant_name` lint to deny-by-default and fixed up the affected tests.

Addresses #103442.
2023-01-20 21:33:20 -05:00
Felix S. Klock II
5fa1347331 Revert "Make PROC_MACRO_DERIVE_RESOLUTION_FALLBACK a hard error"
This reverts commit 7d82cadd97.

I am doing this to buy us some time with respect to issue #106337 w.r.t. the
1.67 release.
2023-01-20 17:13:55 -05:00
Michael Howell
e237690a28 diagnostics: add }; only if { was added too 2023-01-20 14:53:33 -07:00
Michael Howell
e9d8d238ef diagnostics: suggest changing s@self::{macro}@::macro for exported
Fixes #99695
2023-01-20 14:52:24 -07:00
bors
94a300b9b8 Auto merge of #105102 - compiler-errors:copy-impl-considering-regions, r=lcnr
Check ADT fields for copy implementations considering regions

Fixes #88901
r? `@ghost`
2023-01-20 21:29:52 +00:00
Lukas Markeffsky
e415e2f1a2 fix overlapping spans for explicit_outlives_requirements in macros
also delete trailing comma if necessary
2023-01-20 20:16:37 +01:00
Lukas Markeffsky
31443c63b5 preserve delim spans during macro_rules! expansion if able 2023-01-20 20:16:37 +01:00
bors
a6269dad38 Auto merge of #107106 - matthiaskrgr:rollup-g7r1ep0, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #106699 ([drop tracking] Visit break expressions )
 - #106738 (Fix known-bug annotations)
 - #106891 (Tweak "borrow closure argument" suggestion)
 - #106928 (add raw identifier for keyword in suggestion)
 - #107065 (Clippy: Make sure to include in beta: Move `unchecked_duration_subtraction` to pedantic)
 - #107068 (autoderive Subdiagnostic for AddtoExternBlockSuggestion)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-20 15:28:40 +00:00
--global
734f375019 Change bindings_with_variant_name to deny-by-default 2023-01-20 02:26:12 -05:00
Matthias Krüger
da7a0c0b30
Rollup merge of #106928 - bvanjoi:print-keyword-raw-identifier, r=petrochenkov
add raw identifier for keyword in suggestion

fix https://github.com/rust-lang/rust/issues/106841
2023-01-20 07:25:29 +01:00
Matthias Krüger
5f2ad80e18
Rollup merge of #106891 - estebank:issue-45727, r=petrochenkov
Tweak "borrow closure argument" suggestion

Fix #45727.
2023-01-20 07:25:28 +01:00
Matthias Krüger
720a9f1d9b
Rollup merge of #106738 - compiler-errors:known-bugs-oops, r=jackh726
Fix known-bug annotations

r? ``@Nilstrieb``
2023-01-20 07:25:28 +01:00
Matthias Krüger
3d79cbc3c1
Rollup merge of #106699 - eholk:await-chains-drop-tracking, r=wesleywiser
[drop tracking] Visit break expressions

This fixes https://github.com/rust-lang/rust/issues/102383 by remembering to visit the expression in `break expr` when building the drop tracking CFG. Missing this step was causing an off-by-one error which meant after a number of awaits we'd be
looking for dropped values at the wrong point in the code.

Additionally, this changes the order of traversal for assignment expressions to visit the rhs and then the lhs. This matches what is done elsewhere.

Finally, this improves some of the debugging output (for example, the CFG visualizer) to make it easier to figure out these sorts of issues.
2023-01-20 07:25:27 +01:00
Matthias Krüger
75655a9246
Rollup merge of #107076 - megakorre:106419_add_test_case, r=compiler-errors
Added const-generic ui test case for issue #106419

This PR adds a test case for #106419 which has been fixed in master by #105292

I also ran the test on f769d34291 (the commit before #105292 was merged)
and it did fail there with the following output.
```
--- stderr -------------------------------
error[E0308]: mismatched types
  --> /home/patrikk/src/rust/src/test/ui/const-generics/issue-106419-struct-with-multiple-const-params.rs:5:10
   |
LL | #[derive(Clone)]
   |          ^^^^^
   |          |
   |          expected `A`, found `B`
   |          expected `Bar<A, B>` because of return type
   |
   = note: expected struct `Bar<A, _>`
              found struct `Bar<B, _>`
   = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
------------------------------------------
```
2023-01-20 07:16:11 +01:00
Matthias Krüger
3693399ffc
Rollup merge of #107058 - clubby789:eqeq-homoglyph, r=wesleywiser
Recognise double-equals homoglyph

Recognise `⩵` as a homoglyph for `==`.

The first commit switches `char` to `&str`, as all previous homoglyphs corresponded to a single ASCII character, while the second implements the fix.

`@rustbot` label +A-diagnostics +A-parser
2023-01-20 07:16:10 +01:00
Matthias Krüger
240cc81768
Rollup merge of #106973 - oli-obk:tait_ice_closure_in_impl_header, r=lcnr
Don't treat closures from other crates as local

fixes #104817

r? `@lcnr`

Specialization can prefer an impl for an opaque type over a blanket impls that also matches. If the blanket impl only applies if an auto-trait applies, we look at the hidden type of the opaque type to see if that implements the auto trait. The hidden type can be a closure or generator, and thus we will end up seeing these types in coherence and have to handle them properly.
2023-01-20 07:16:09 +01:00
Matthias Krüger
df88f7e02c
Rollup merge of #106783 - WaffleLapkin:break-my-ident, r=wesleywiser
Recover labels written as identifiers

This adds recovery for `break label expr` and `continue label`, as well as a test for `break label`.
2023-01-20 07:16:08 +01:00
Michael Goulet
3eecdd10a2 Fix known-bug, silence ICE stderr 2023-01-19 20:20:58 +00:00
Nilstrieb
6d0c91fda3 Add rustc_on_unimplemented on Sync for cell types
Suggest using a lock instead.
2023-01-19 21:09:25 +01:00
Esteban Küber
33e11a3b2e Tweak "borrow closure argument" suggestion
Fix #45727.
2023-01-19 19:35:49 +00:00
bors
4c83bd03a9 Auto merge of #107038 - compiler-errors:dont-wfcheck-non-local-rpit, r=oli-obk
Don't wf-check non-local RPITs

We were using `ty::is_impl_trait_defn(..).is_none()` to check if we need to add WF obligations for an opaque type.

This is *supposed* to be checking if the type is a TAIT, since RPITs' wfness is implied by wf checking its parent item, but since `is_impl_trait_defn` returns `None` for non-local RPIT and async futures, we unnecessarily consider wf predicates for an RPIT if it is coming from a foreign crate.

Fixes #107036

r? `@oli-obk` but feel free to reassign
2023-01-19 16:49:06 +00:00
bohan
97ae79ac9d add raw identifier for keyword in suggestion 2023-01-20 00:36:20 +08:00
Michael Goulet
ed6aebbfec trait solver: Implement Fn traits and tuple trait 2023-01-19 16:15:28 +00:00
Michael Goulet
69890b2df4 trait solver: PointerSized 2023-01-19 16:15:28 +00:00
clubby789
95a824c02c Special case derive(Debug) for fieldless enums 2023-01-19 15:53:31 +00:00
Michael Goulet
9793abc209 Add test 2023-01-19 15:46:08 +00:00
mejrs
8e43414bce Fix proc macro tests 2023-01-19 16:31:50 +01:00
Patrik Kårlin
8657cb8efe Added UI test case for issue #106419 2023-01-19 15:39:05 +01:00
bors
19423b5944 Auto merge of #106910 - aliemjay:alias-ty-in-regionck, r=oli-obk
even more unify Projection/Opaque handling in region outlives code

edit: This continues ate the same pace as #106829. New changes are described in https://github.com/rust-lang/rust/pull/106910#issuecomment-1383251254.

~This touches `OutlivesBound`, `Component`, `GenericKind` enums.~

r? `@oli-obk` (because of overlap with #95474)
2023-01-19 14:05:07 +00:00
Ali MJ Al-Nasrawy
e40567b2cf add test for ICE fix 2023-01-19 15:31:59 +03:00
Oli Scherer
42f1f54a5e Don't treat closures from other crates as local 2023-01-19 11:29:40 +00:00
Guillaume Gomez
246daa49ee
Rollup merge of #106931 - Ezrashaw:docs-e0208, r=compiler-errors
document + UI test `E0208` and make its output more user-friendly

Cleans up `E0208`'s output a lot. It could actually be useful for someone learning about variance now. I also added a UI test for it in `tests/ui/error-codes/` and wrote some docs for it.

r? `@GuillaumeGomez` another error code, can't be bothered to find the issue :P. Obviously there's some compiler stuff, so you'll have to hand it off.

Part of https://github.com/rust-lang/rust/issues/61137.
2023-01-19 11:19:35 +01:00
Guillaume Gomez
1a878df2b8
Rollup merge of #106927 - Ezrashaw:e0606-make-machine-applicable, r=estebank
make `CastError::NeedsDeref` create a `MachineApplicable` suggestion

Fixes #106903

Simple impl for the linked issue. I also made some other small changes:
- `CastError::ErrorGuaranteed` now owns an actual `ErrorGuaranteed`. This better enforces the static guarantees of `ErrorGuaranteed`.
- `CastError::NeedDeref` code simplified a bit, we now just suggest the `*`, instead of the whole expression as well.
2023-01-19 11:19:34 +01:00
clubby789
1487aa9f9d Add double-equals homoglyph 2023-01-19 02:25:55 +00:00
bors
6ba6d22bdf Auto merge of #107052 - compiler-errors:rollup-vxr22g5, r=compiler-errors
Rollup of 8 pull requests

Successful merges:

 - #105796 (rustdoc: simplify JS search routine by not messing with lev distance)
 - #106753 (Make sure that RPITITs are not considered suggestable)
 - #106917 (Encode const mir for closures if they're const)
 - #107004 (Implement some candidates for the new solver (redux))
 - #107023 (Stop using `BREAK` & `CONTINUE` in compiler)
 - #107030 (Correct typo)
 - #107042 (rustdoc: fix corner cases with "?" JS keyboard command)
 - #107045 (rustdoc: remove redundant CSS rule `#settings .setting-line`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-19 02:09:45 +00:00
Michael Goulet
a637e2a950
Rollup merge of #106917 - compiler-errors:const-closure-foreign, r=tmiasko
Encode const mir for closures if they're const

Fixes #106913
2023-01-18 18:00:29 -05:00
Michael Goulet
685c77305c
Rollup merge of #106753 - compiler-errors:rpitit-not-suggestable, r=spastorino
Make sure that RPITITs are not considered suggestable

Makes no sense to suggest `where impl Future<Output = ()>: Send`, for example.
2023-01-18 18:00:28 -05:00
bors
8b11574ca0 Auto merge of #107041 - Nilstrieb:back-to-being-clueless-whether-it-really-is-a-literal, r=compiler-errors
Revert "Improve heuristics whether `format_args` string is a source literal"

This reverts commit e6c02aad93 (from #106195).

Keeps the code improvements from the PR and the test (as a known-bug).

Works around #106408 while a proper fix is discussed more thoroughly in #106505, as proposed by `@tmandry.`

Reopens #106191

r? compiler-errors
2023-01-18 22:58:30 +00:00
Nilstrieb
a8086cf9df Revert "Improve heuristics whether format_args string is a source literal"
This reverts commit e6c02aad93.

Keeps the code improvements from the PR and the test (as a known-bug).
2023-01-18 20:33:17 +01:00
bors
6d46b1ec87 Auto merge of #106503 - cjgillot:remap-nofilter, r=oli-obk
Do not filter substs in `remap_generic_params_to_declaration_params`.

The relevant filtering should have been performed by borrowck.

Fixes https://github.com/rust-lang/rust/issues/105826

r? types
2023-01-18 16:37:33 +00:00
yukang
81efdab3f8 add tests for 107090 2023-01-18 22:53:27 +08:00
Ezra Shaw
708861e5b7
remove error code from #[rustc_variance] and document its remains 2023-01-18 21:10:27 +13:00
Matthias Krüger
9e46c24a90
Rollup merge of #106873 - BoxyUwU:ty_const_formatting, r=compiler-errors
dont randomly use `_` to print out const generic arguments

const generics seem to get printed out as `_` for no reason a lot of the time, as someone who spends a lot of time with const generics this has gotten  very annoying . Latest example would be #106423 where the ICE messaged formatted a `ty::Const` containing no infer vars, as `_`.

For some reason printing of the const argument on arrays was custom instead of using the existing logic for printing `ty::Const`. Additionally the existing logic for printing `ty::Const` would print out `_` for anon consts that are in a separate crate leading to weird diagnostics (see second commit). There ought to be less cases of consts randomly getting printed as `_` hiding valuable info now.
2023-01-18 06:59:20 +01:00
Matthias Krüger
d26e07b91a
Rollup merge of #106747 - yanchen4791:issue-105507-fix, r=estebank
Add 'static lifetime suggestion when GAT implied 'static requirement from HRTB

Fix for issue #105507

The problem:
When generic associated types (GATs) are from higher-ranked trait bounds (HRTB), they are implied 'static requirement (see
[Implied 'static requirement from higher-ranked trait bounds](https://blog.rust-lang.org/2022/10/28/gats-stabilization.html#implied-static-requirement-from-higher-ranked-trait-bounds) for more details). If the user did not explicitly specify the `'static` lifetime when using the GAT, the current error message will only point out the type `does not live long enough` where the type is used, but not where the GAT is specified and how to fix the problem.

The solution:
Add notes at the span where the problematic GATs are specified and suggestions of how to fix the problem by adding `'static` lifetime at the right spans.
2023-01-18 06:59:20 +01:00
Boxy
1171fe5c45 i am free 2023-01-18 04:45:43 +00:00
Boxy
a2a50f96f3 actually print out non local anon consts 2023-01-18 04:07:39 +00:00
Boxy
88f81a0de1 test for non local anon const printing 2023-01-18 04:07:39 +00:00
Boxy
4ca5368a12 defer array len printing to const arg printing 2023-01-18 04:07:39 +00:00
Ezra Shaw
b73cdf1b29
special case removing & suggestion 2023-01-18 13:14:56 +13:00
yanchen4791
aadd58ef7a Add 'static lifetime suggestion when GAT implied 'static requirement from HRTB 2023-01-17 11:52:45 -08:00
Matthias Krüger
48bd3ab81d
Rollup merge of #106980 - Nilstrieb:_use_mk_manual_debug_impl_instead, r=lcnr
Hide `_use_mk_alias_ty_instead` in `<AliasTy as Debug>::fmt`
2023-01-17 20:21:28 +01:00
Matthias Krüger
4ee5e09e19
Rollup merge of #106784 - lyming2007:issue-106695-fix, r=WaffleLapkin
prevent E0512 from emitting [type error] by checking the references_error

but still emit E0512
this will fix #106695
2023-01-17 20:21:26 +01:00
Yiming Lei
d1478a5600 delay E0512 as a bug by checking the references_error
fix #106695
2023-01-17 09:20:15 -08:00
Esteban Küber
12d18e4031 Ensure macros are not affected 2023-01-17 17:09:58 +00:00
Dylan DPC
e6e7c3990e
Rollup merge of #106962 - compiler-errors:use-sugg-span, r=oli-obk
Fix use suggestion span

Fixes #106954
2023-01-17 20:33:05 +05:30
Dylan DPC
f91f369949
Rollup merge of #106148 - chenyukang:yukang/fix-105061-unused, r=lcnr
Fix unused_parens issue for higher ranked function pointers

fixes #105061

r? `@lcnr`
2023-01-17 20:33:03 +05:30
Dylan DPC
09faa266da
Rollup merge of #101698 - raldone01:feat/const_cmp_typeid, r=scottmcm
Constify `TypeId` ordering impls

Tracking issue: #101871

Adding const ordering to `TypeId` allows rtti crates to optimize some casting scenarios (without transmuting to `u64`). This would also prevent these crates from breaking if the underlying type is changed from `u64` to something different.

Feature gate: `#![feature(const_cmp_type_id)]`
2023-01-17 20:33:03 +05:30
nils
cb00bc035b Hide _use_mk_alias_ty_instead in <AliasTy as Debug>::fmt 2023-01-17 15:04:05 +01:00
mejrs
6fe4cf795b Migrate mir_build's borrow conflicts 2023-01-17 13:48:43 +01:00
Oli Scherer
64e5f9129f Handle diagnostics customization on the fluent side 2023-01-17 08:21:34 +00:00
bors
159ba8a92c Auto merge of #106627 - Ezrashaw:no-e0711-without-staged-api, r=Mark-Simulacrum
fix: don't emit `E0711` if `staged_api` not enabled

Fixes #106589

Simple fix, added UI test.

As an aside, it seems a lot of features are susceptible to this, `E0711` stands out to me because it's perma-unstable and we are effectively exposing an implementation detail.
2023-01-17 07:20:32 +00:00
Matthias Krüger
9bcc46ee90
Rollup merge of #106949 - compiler-errors:is-poly, r=BoxyUwU
ConstBlocks are poly if their substs are poly

r? `@BoxyUwU`

fixes #106926
2023-01-17 05:25:23 +01:00
Matthias Krüger
9cda9e0ab6
Rollup merge of #106712 - Ezrashaw:impl-ref-trait, r=estebank
make error emitted on `impl &Trait` nicer

Fixes #106694

Turned out to be simpler than I thought, also added UI test.

Before: ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9bda53271ef3a8886793cf427b8cea91))
```text
error: expected one of `:`, ``@`,` or `|`, found `)`
 --> src/main.rs:2:22
  |
2 | fn foo(_: impl &Trait) {}
  |                      ^ expected one of `:`, ``@`,` or `|`
  |
  = note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
help: if this is a parameter name, give it a type
  |
2 | fn foo(_: impl Trait: &TypeName) {}
  |                ~~~~~~~~~~~~~~~~
help: if this is a type, explicitly ignore the parameter name
  |
2 | fn foo(_: impl _: &Trait) {}
  |                ++

error: expected one of `!`, `(`, `)`, `,`, `?`, `for`, `~`, lifetime, or path, found `&`
 --> src/main.rs:2:16
  |
2 | fn foo(_: impl &Trait) {}
  |               -^ expected one of 9 possible tokens
  |               |
  |               help: missing `,`

error: expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, `~`, lifetime, or path, found `&`
 --> src/main.rs:3:11
  |
3 | fn bar<T: &Trait>(_: T) {}
  |           ^ expected one of 10 possible tokens
```

After:
```text
error: expected a trait, found type
 --> <anon>:2:16
  |
2 | fn foo(_: impl &Trait) {}
  |                -^^^^^
  |                |
  |                help: consider removing the indirection

error: expected a trait, found type
 --> <anon>:3:11
  |
3 | fn bar<T: &Trait>(_: T) {}
  |           -^^^^^
  |           |
  |           help: consider removing the indirection
```
2023-01-17 05:25:21 +01:00
Matthias Krüger
f74044259a
Rollup merge of #106591 - Ezrashaw:attempted-integer-identifer, r=Estebank
suggestion for attempted integer identifier in patterns

Fixes #106552

Implemented a suggestion on `E0005` that occurs when no bindings are present and the pattern is a literal integer.
2023-01-17 05:25:21 +01:00
Michael Goulet
21725774a2 note -> help 2023-01-17 03:09:49 +00:00
Michael Goulet
716ea5f19c Fix use suggestion span 2023-01-17 03:06:38 +00:00
Esteban Küber
7b8251e188 Account for method call and indexing when looking for inner-most path in expression 2023-01-17 02:52:43 +00:00
Esteban Küber
c6111e8d23 Account for field access when looking for inner-most path in expression 2023-01-17 02:47:50 +00:00
Esteban Küber
be2ec32b18 Account for * when looking for inner-most path in expression 2023-01-17 02:45:11 +00:00
Esteban Küber
c847a01a3b Emit fewer errors on patterns with possible type ascription 2023-01-17 01:58:37 +00:00
Esteban Küber
2d82420665 Teach parser to understand fake anonymous enum syntax
Parse `-> Ty | OtherTy`.
Parse type ascription in top level patterns.
2023-01-17 01:58:32 +00:00
onestacked
7355ab3fe3 Constify TypeId ordering impls 2023-01-16 21:26:03 +01:00
Michael Goulet
9f6fef9657 Properly pluralize 'generic constants' 2023-01-16 20:21:29 +00:00
Michael Goulet
fdaac4e48e ConstBlocks are poly if their substs are poly 2023-01-16 20:09:31 +00:00
Matthias Krüger
d2a8a9fb36
Rollup merge of #106940 - oli-obk:tait_error, r=compiler-errors
Improve a TAIT error and add an error code plus documentation

cc https://github.com/rust-lang/rust/issues/106858
2023-01-16 20:29:39 +01:00
Matthias Krüger
37378ee7da
Rollup merge of #106912 - gftea:pr-106736, r=Nilstrieb
check -Z query-dep-graph is enabled if -Z dump-dep-graph (#106736)

PR to solve #106736, r? `@cjgillot`
2023-01-16 20:29:39 +01:00
Tim Neumann
cd1d0bc20c ui tests: Remap test base directory by default. 2023-01-16 18:33:25 +00:00
Oli Scherer
6b69b5e460 Improve a TAIT error and add an error code plus documentation 2023-01-16 16:54:14 +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
Michael Goulet
3a4fdcf86c Encode const mir for closures if they're const 2023-01-16 14:59:27 +00:00
yukang
9d74bb832f comments feedback 2023-01-16 20:44:14 +08:00
Takayuki Maeda
fe96c11aba fix #104440 2023-01-16 21:06:34 +09:00
gftea
2c5583efbd check -Z query-dep-graph is enabled if -Z dump-dep-graph (#106736) 2023-01-16 11:09:53 +01: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
Ezra Shaw
ca1178f022
make CastError::NeedsDeref create a MachineApplicable suggestion + other misc fixes 2023-01-16 20:24:01 +13: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
Esteban Küber
656db98bd9 Tweak E0597
CC #99430
2023-01-15 19:46:20 +00: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
clubby789
2883148e60 Special case deriving PartialOrd for certain enum layouts 2023-01-15 01:35:48 +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
Ezra Shaw
e590b93499
make error emitted on impl &Trait nicer 2023-01-15 12:23:46 +13: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
yukang
644ee8d250 add test case for issue 105601 2023-01-14 17:11:05 +08:00
yukang
7d99866bfc fix #105061, Fix unused_parens issue for higher ranked function pointers 2023-01-14 17:11:04 +08:00
Ezra Shaw
be1a6db9f8
fix: don't emit E0711 if staged_api not enabled 2023-01-14 22:04:42 +13: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
Ezra Shaw
1babece1e8
suggest fix for attempted integer identifier in patterns 2023-01-14 12:51:20 +13:00
Michael Goulet
75074e0e52 Delay normalization bugs instead of reporting them 2023-01-13 23:19:36 +00:00
Michael Goulet
6ec8c13e15 Rebase and move UI tests 2023-01-13 23:06:29 +00: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