Commit Graph

55 Commits

Author SHA1 Message Date
Matthias Krüger
3035ccbcb9
Rollup merge of #108031 - jieyouxu:issue-108019, r=estebank
Don't recover lifetimes/labels containing emojis as character literals

Fixes #108019.

Note that at the time of this commit, `unic-emoji-char` seems to have data tables only up to Unicode 5.0, but Unicode is already newer than this.

A newer emoji such as `🥺` will not be recognized as an emoji but older emojis such as `🐱` will.

This PR leaves a couple of FIXMEs where `unic_emoji_char::is_emoji` is used.
2023-02-18 13:26:46 +01:00
Michael Goulet
262a344d72 Add feature gate for non_lifetime_binders 2023-02-16 03:39:58 +00:00
Matthias Krüger
202c70666f
Rollup merge of #103478 - SpanishPear:spanishpear/issue_103366_fix, r=TaKO8Ki
Suggest fix for misplaced generic params on fn item #103366

fixes #103366

This still has some work to go, but works for 2/3 of the initial base cases described in #1033366

simple fn:
```
error: expected identifier, found `<`
 --> shreys/test_1.rs:1:3
  |
1 | fn<T> id(x: T) -> T { x }
  |   ^ expected identifier
  |
help: help: place the generic parameter list after the function name:
  |
1 | fn id<T>(x: T) -> T { x }
  |    ~~~~

```

Complicated bounds
```
error: expected identifier, found `<`
 --> spanishpear/test_2.rs:1:3
  |
1 | fn<'a, B: 'a + std::ops::Add<Output = u32>> f(_x: B) { }
  |   ^ expected identifier
  |
help: help: place the generic parameter list after the function name:
  |
1 | fn f<'a, B: 'a + std::ops::Add<Output = u32>>(_x: B) { }
  |    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

Opening a draft PR for comments on approach, particularly I have the following questions:
 -  [x]  Is it okay to be using `err.span_suggestion` over struct derives? I struggled to get the initial implementation (particularly the correct suggestion message) on struct derives, although I think given what I've learned since starting, I could attempt re-doing it with that approach.
  -  [x] in the case where the snippet cannot be obtained from a span, is the `help` but no suggestion okay? I think yes (also, when does this case occur?)
  -  [x] are there any red flags for the generalisation of this work for relevant item kinds (i.e. `struct`, `enum`, `trait`, and `union`). My basic testing indicates it does work for those types except the help tip is currently hardcoded to `after the function name` - which should change dependent on the item.
  - [x] I am planning to not show the suggestion if there is already a `<` after the item identifier, (i.e. if there are already generics, as after a function name per the original issue). Any major objections?
  - [x] Is the style of error okay? I wasn't sure if there was a way to make it display nicer, or if thats handled by span_suggestion

These aren't blocking questions, and I will keep working on:
  - check if there is a `<` after the ident (and if so, not showing the suggestion)
  - generalize the help message
  - figuring out how to write/run/etc ui tests (including reading the docs for them)
  - logic cleanups
2023-02-14 18:02:50 +01:00
许杰友 Jieyou Xu (Joe)
98b82aedba
Update numeric lifetime test 2023-02-14 18:17:59 +08:00
Matthias Krüger
dc7559b599
Rollup merge of #107789 - jieyouxu:issue-107745, r=lcnr
Avoid exposing type parameters and implementation details sourced from macro expansions

Fixes #107745.

~~I would like to **request some guidance** for this issue, because I don't think this is a good fix (a band-aid at best).~~

### The Problem

The code

```rust
fn main() {
    println!("{:?}", []);
}
```

gets desugared into (`rustc +nightly --edition=2018 issue-107745.rs -Z unpretty=hir`):

```rust
#[prelude_import]
use std::prelude::rust_2018::*;
#[macro_use]
extern crate std;
fn main() {
        {
                ::std::io::_print(<#[lang = "format_arguments"]>::new_v1(&["",
                                    "\n"], &[<#[lang = "format_argument"]>::new_debug(&[])]));
            };
    }
```

so the diagnostics code tries to be as specific and helpful as possible, and I think it finds that `[]` needs a type parameter and so does `new_debug`. But since `[]` doesn't have an origin for the type parameter definition, it points to `new_debug` instead and leaks the internal implementation detail since all `[]` has is an type inference variable.

### ~~The Bad Fix~~

~~This PR currently tries to fix the problem by bypassing the generated function `<#[lang = "format_argument"]>::new_debug` to avoid its generic parameter (I think it is auto-generated from the argument `[_; 0]`?) from getting collected as an `InsertableGenericArg`. This is problematic because it also prevents the help from getting displayed.~~

~~I think this fix is not ideal and hard-codes the format generated code pattern, but I can't think of a better fix. I have tried asking on Zulip but no responses there yet.~~
2023-02-10 15:28:47 +01:00
Matthias Krüger
3b9543c89d
Rollup merge of #107446 - clubby789:rustc-parse-diag-migrate, r=compiler-errors
Migrate some of `rustc_parse` to derive diagnostics

`@rustbot` label +A-translation
r? rust-lang/diagnostics
cc #100717
2023-02-09 11:21:57 +01:00
许杰友 Jieyou Xu (Joe)
b58347a9c6
Don't expose type parameters and implementation details from macro expansion 2023-02-09 15:15:15 +08:00
Michael Goulet
0017822b70 Do not eagerly recover for bad impl-trait in macros 2023-02-08 17:56:08 +00:00
clubby789
521c5f36d6 Migrate rustc_parse to derive diagnostics 2023-02-06 14:40:35 +00:00
Obei Sideg
17b6bd6b70 Add ui test for missing expression in for loop 2023-02-05 17:33:17 +03:00
Michael Goulet
e99e05d135
Rollup merge of #107551 - fee1-dead-contrib:rm_const_fnmut_helper, r=oli-obk
Replace `ConstFnMutClosure` with const closures

Also fixes a parser bug. cc `@oli-obk` for compiler changes
2023-02-03 14:15:22 -08:00
Dylan DPC
d6f0c51e98
Rollup merge of #107585 - compiler-errors:fndef-sig-cycle, r=oli-obk
Don't cause a cycle when formatting query description that references a FnDef

When a function returns `-> _`, we use typeck to compute what the resulting type of the body _should_ be. If we call another query inside of typeck and hit a cycle error, we attempt to report the cycle error which requires us to compute all of the query descriptions for the stack.

However, if one of the queries in that cycle has a query description that references this function as a FnDef type, we'll cause a *second* cycle error from within the cycle error reporting code, since rendering a FnDef requires us to compute its signature. This causes an unwrap to ICE, since during the *second* cycle reporting code, we try to look for a job that isn't in the active jobs list.

We can avoid this by using `with_no_queries!` when computing these query descriptions.

Fixes #107089

The only drawback is that the rendering of opaque types in cycles regresses a bit :| I'm open to alternate suggestions about how we may handle this...
2023-02-03 23:04:52 +05:30
Matthias Krüger
743ca67edf
Rollup merge of #107602 - estebank:anon-enum-access, r=compiler-errors
Parse and recover from type ascription in patterns

Reintroduce part of #106960, which was reverted in #107478.

r? `@compiler-errors`
2023-02-03 06:30:24 +01:00
Esteban Küber
0ba687a95e Parse and recover from type ascription in patterns 2023-02-02 17:18:48 +00:00
Matthias Krüger
8f47954742
Rollup merge of #106919 - compiler-errors:underscore-typo-in-field-pat, r=jackh726
Recover `_` as `..` in field pattern
2023-02-02 17:14:05 +01:00
Michael Goulet
9dd5d3e8e4 Recover _ as .. in field pattern 2023-02-02 06:10:02 +00:00
Michael Goulet
39db65c526 Add a test 2023-02-02 05:54:35 +00:00
Michael Goulet
e4b2936983 Revert "Teach parser to understand fake anonymous enum syntax" and related commits
Revert "review comment: Remove AST AnonTy"

This reverts commit 020cca8d36.

Revert "Ensure macros are not affected"

This reverts commit 12d18e4031.

Revert "Emit fewer errors on patterns with possible type ascription"

This reverts commit c847a01a3b.

Revert "Teach parser to understand fake anonymous enum syntax"

This reverts commit 2d82420665.
2023-02-02 05:54:35 +00:00
Michael Goulet
64f5293956 Don't cause a cycle when formatting query description that references a FnDef 2023-02-02 05:49:07 +00:00
SpanishPear
a3d32bbbbe fix formatting + test syntax 2023-02-01 18:11:37 +11:00
Deadbeef
679dde7338 fix parser mistaking const closures for const item 2023-02-01 06:44:30 +00:00
bors
f361413cbf Auto merge of #106399 - estebank:type-err-span-label, r=nagisa
Modify primary span label for E0308

Looking at the reactions to https://hachyderm.io/`@ekuber/109622160673605438,` a lot of people seem to have trouble understanding the current output, where the primary span label on type errors talks about the specific types that diverged, but these can be deeply nested type parameters. Because of that we could see "expected i32, found u32" in the label while the note said "expected Vec<i32>, found Vec<u32>". This understandably confuses people. I believe that once people learn to read these errors it starts to make more sense, but this PR changes the output to be more in line with what people might expect, without sacrificing terseness.

Fix #68220.
2023-01-31 13:53:40 +00:00
SpanishPear
70bfcc2518 move to multipart spans 2023-01-31 21:44:11 +11:00
Esteban Küber
62ba3e70a1 Modify primary span label for E0308
The previous output was unintuitive to users.
2023-01-30 20:12:19 +00:00
Lucille Blumire
8348f25493
Update bastion-of-the-turbofish.rs
The original tweet in the chain linked to, and thus the through line of links back to Anna's tweet where she named the turbofish (https://web.archive.org/web/20210911061514/https://twitter.com/whoisaldeka/status/914914008225816576) are lost as the user whoisaldeka has deleted their twitter account.

Switching to an archive link preserves this through line, allowing someone to browse back to see the point at which Anna created the turbofish, as was the original intent of including this context.
2023-01-30 14:22:41 +00:00
Ryo Yoshida
807ebac887
Insert whitespace to avoid ident concatenation in suggestion 2023-01-29 21:01:35 +09:00
bors
bca8b4dc32 Auto merge of #107408 - matthiaskrgr:rollup-b5vz2ow, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #104012 (Improve unexpected close and mismatch delimiter hint in TokenTreesReader)
 - #104252 (Stabilize the const_socketaddr feature)
 - #105524 (Replace libc::{type} with crate::ffi::{type})
 - #107096 (Detect references to non-existant messages in Fluent resources)
 - #107355 (Add regression test for #60755)
 - #107384 (Remove `BOOL_TY_FOR_UNIT_TESTING`)
 - #107385 (Use `FallibleTypeFolder` for `ConstInferUnifier` not `TypeRelation`)
 - #107391 (rustdoc: remove inline javascript from copy-path button)
 - #107398 (Remove `ControlFlow::{BREAK, CONTINUE}`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-28 13:12:59 +00:00
Matthias Krüger
e3048c7838
Rollup merge of #104012 - chenyukang:yukang/fix-103882-deli-indentation, r=petrochenkov
Improve unexpected close and mismatch delimiter hint in TokenTreesReader

Fixes #103882
Fixes #68987
Fixes #69259

The inner indentation mismatching will be covered by outer block, the new added function `report_error_prone_delim_block` will find out the error prone candidates for reporting.
2023-01-28 11:11:05 +01:00
bors
d8da513668 Auto merge of #106916 - lukas-code:overlapping-substs, r=estebank
Remove overlapping parts of multipart suggestions

This PR adds a debug assertion that the parts of a single substitution cannot overlap, fixes a overlapping substitution from the testsuite, and fixes https://github.com/rust-lang/rust/issues/106870.

Note that a single suggestion can still have multiple overlapping substitutions / possible edits, we just don't suggest overlapping replacements in a single edit anymore.

I've also included a fix for an unrelated bug where rustfix for `explicit_outlives_requirements` would produce multiple trailing commas for a where clause.
2023-01-28 10:00:56 +00:00
yukang
cd233231aa Improve unexpected close and mismatch delimiter hint in TokenTreesReader 2023-01-27 17:45:41 +08:00
Matthias Krüger
ba928ba041
Rollup merge of #106960 - estebank:parse-anon-enums, r=cjgillot
Teach parser to understand fake anonymous enum syntax

Parse `Ty | OtherTy` in function argument and return types.
Parse type ascription in top level patterns.

Minimally address #100741.
2023-01-26 06:15:24 +01:00
yukang
c4d00d710c add testcase for #104012 2023-01-26 10:52:57 +08:00
SpanishPear
8292d07cc4 move tests to new rust-lang location 2023-01-22 17:16:39 +11:00
Lukas Markeffsky
31443c63b5 preserve delim spans during macro_rules! expansion if able 2023-01-20 20:16:37 +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
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
clubby789
1487aa9f9d Add double-equals homoglyph 2023-01-19 02:25:55 +00:00
Esteban Küber
12d18e4031 Ensure macros are not affected 2023-01-17 17:09:58 +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
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
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
Maybe Waffle
57d822a904 Recover labels written as identifiers 2023-01-13 09:18:36 +00: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
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
Michael Goulet
bf0623e363 Don't suggest dyn as parameter to add 2023-01-12 22:04:30 +00:00
Michael Goulet
950b47fb96 Render missing generics suggestion verbosely 2023-01-12 22:04:30 +00:00
Maybe Waffle
b0609889d7 Add a test for recovery of unticked labels 2023-01-12 19:25:32 +00:00
Deadbeef
4fb10c0ce4 parse const closures 2023-01-12 02:28:37 +00:00