Commit Graph

994 Commits

Author SHA1 Message Date
Michael Goulet
54744601bf
Rollup merge of #100817 - vincenzopalazzo:macros/bool_spelling_sugg, r=davidtwco
sugg: suggest the usage of boolean value when there is a typo in the keyword

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

This adds a new suggestion when there is a well-known typo

With the following program

```rust
fn main() {
    let x = True;
}
```

Now we have the following suggestion

```
error[E0425]: cannot find value `True` in this scope
 --> test.rs:2:13
  |
2 |     let x = True;
  |             ^^^^ not found in this scope
  |
help: you may want to use a bool value instead
  |
2 |     let x = true;
  |             ~~~~

error: aborting due to previous error
```

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-08-26 15:56:26 -07:00
Matthias Krüger
1c0f60f904
Rollup merge of #100901 - TaKO8Ki:make-some-methods-private, r=sanxiyn
Make some methods private
2022-08-24 18:20:12 +02:00
Vincenzo Palazzo
69715c9033 sugg: suggest the usage of boolean value when there is a typo in the keyword
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-08-22 22:53:40 +00:00
Camille GILLOT
dff428013d Mark suggestion as MaybeIncorrect. 2022-08-23 00:09:58 +02:00
Camille GILLOT
da9ccc2c98 Remove FnItemRibKind. 2022-08-23 00:08:42 +02:00
Camille GILLOT
613dc2204d Improve local generic parameter suggestions. 2022-08-23 00:08:42 +02:00
Camille GILLOT
d7d701a9dc Create specific ConstantHasGenerics for ConstantItemRibKind. 2022-08-23 00:08:42 +02:00
Takayuki Maeda
000dc80221 make some methods private 2022-08-22 18:12:18 +09:00
Dylan DPC
769ad70129
Rollup merge of #100592 - cjgillot:debug-import-kind, r=TaKO8Ki
Manually implement Debug for ImportKind.

This avoids crashing due to an infinite loop when running with `RUSTC_LOG=rustc_resolve`.
2022-08-19 12:26:44 +05:30
Matthias Krüger
b295639f14
Rollup merge of #100643 - TaKO8Ki:point-at-type-parameter-shadowing-another-type, r=estebank
Point at a type parameter shadowing another type

This patch fixes a part of #97459.
2022-08-18 05:10:46 +02:00
Takayuki Maeda
1886aef035 point at a type parameter shadowing another type 2022-08-17 04:53:06 +09:00
Camille Gillot
611221d8ae
Update compiler/rustc_resolve/src/imports.rs 2022-08-15 20:51:32 +02:00
Camille GILLOT
4a5c46fb02 Manually implement Debug for ImportKind. 2022-08-15 18:29:43 +02:00
Michael Goulet
e248c7f9ae
Rollup merge of #100367 - fmease:fix-100365, r=compiler-errors
Suggest the path separator when a dot is used on a trait

Fixes #100365.

`@rustbot` label A-diagnostics
r? diagnostics
2022-08-13 21:06:49 -07:00
KaDiWa
4eebcb9910
avoid cloning and then iterating 2022-08-13 16:16:52 +02:00
Mark Rousskov
154a09dd91 Adjust cfgs 2022-08-12 16:28:15 -04:00
León Orell Valerian Liehr
0fb4ef6769 Suggest path separator when a dot is used on a trait 2022-08-11 23:09:39 +02:00
Matthias Krüger
8237efc52d
Rollup merge of #100392 - nnethercote:simplify-visitors, r=cjgillot
Simplify visitors

By removing some unused arguments.

r? `@cjgillot`
2022-08-11 22:53:08 +02:00
Dylan DPC
b5f5bdce87
Rollup merge of #100351 - compiler-errors:diagnostic-convention, r=fee1-dead
Use `&mut Diagnostic` instead of `&mut DiagnosticBuilder` unless needed

This seems to be the established convention (02ff9e0) when `DiagnosticBuilder` was first added. I am guilty of introducing some of these.
2022-08-11 22:47:03 +05:30
Nicholas Nethercote
232bd80130 Simplify rustc_ast::visit::Visitor::visit_poly_trait_ref.
It is passed an argument that is never used.
2022-08-11 11:10:01 +10:00
Camille GILLOT
9701845287 Do not consider method call receiver as an argument in AST. 2022-08-10 18:34:54 +02:00
Michael Goulet
a2b6744af0 Use &mut Diagnostic instead of &mut DiagnosticBuilder unless needed 2022-08-10 03:45:42 +00:00
Dylan DPC
fac84e8bb6
Rollup merge of #100228 - luqmana:suggestion-ice, r=estebank
Don't ICE while suggesting updating item path.

When an item isn't found, we may suggest an appropriate import to `use`. Along with that, we also suggest updating the path to work with the `use`. Unfortunately, if the code in question originates from a macro, the span used to indicate which part of the path needs updating may not be suitable and cause an ICE (*). Since, such code is not adjustable directly by the user without modifying the macro, just skip the suggestion in such cases.

(*) The ICE happens because the emitter want to indicate to the user what code to delete by referencing a certain span. But in this case, said span has `lo == hi == 0` which means it thinks it's a dummy span. Adding a space before the proc macro attribute is enough to stop it from ICE'ing but even then the suggestion doesn't really make any sense:
```
help: if you import `DataStore`, refer to it directly
  |
1 -  #[dbstruct::dbstruct]
1 +  #[dbstruct::dbstruct]
```

Since suggestions are best-effort, I just gated this one on `can_be_used_for_suggestions` which catches cases like this.

Fixes #100199
2022-08-09 17:34:55 +05:30
Camille GILLOT
f6af4efec5 Use start_point instead of next_point to point to elided lifetime ampersand. 2022-08-07 14:35:11 +02:00
Luqman Aden
fc83a0cb57 Don't ICE while suggesting updating item path.
When an item isn't found, we may suggest an appropriate import to
`use`. Along with that, we also suggest updating the path to work
with the `use`. Unfortunately, if the code in question originates
from a macro, the span used to indicate which part of the path
needs updating may not be suitable and cause an ICE. Since, such
code is not adjustable directly by the user without modifying the
macro, just skip the suggestion in such cases.
2022-08-07 04:03:28 -07:00
Santiago Pastorino
c0923c8934
Add docs to generics_def_id_map 2022-08-04 11:27:03 -03:00
Santiago Pastorino
1d6cebfd6b
Implement def_id based remapping 2022-08-04 11:26:57 -03:00
bors
6f18f0a9d4 Auto merge of #99953 - cjgillot:in-path-always, r=petrochenkov
Always create elided lifetimes, even if inferred.

`PathSource` gives the context in which a path is encountered.  The same `PathSource` is used for the full path and the `QSelf` part.

Therefore, we can only rely on `PathSource` to know whether typechecking will be able to infer the lifetimes, not whether we need to insert them at all.

Fixes https://github.com/rust-lang/rust/issues/99949
2022-08-04 10:21:40 +00:00
Camille GILLOT
c95ff1d52b Assert index sanity. 2022-08-03 18:44:19 +02:00
Camille GILLOT
a424090252 Simplify debugging. 2022-08-03 18:44:19 +02:00
Camille GILLOT
48bae9360f Use DefIdTree instead of open-coding it. 2022-08-03 18:44:18 +02:00
Camille GILLOT
421bb6ac62 Remove index from Region::EarlyBound. 2022-08-03 18:44:18 +02:00
Camille GILLOT
99e2d33315 Compute object_lifetime_default per parameter. 2022-08-03 18:42:04 +02:00
Camille GILLOT
236ccce79e Create a specific ObjectLifetimeDefault enum. 2022-08-03 18:42:03 +02:00
Camille GILLOT
39bc74e8b8 Make object_lifetime_defaults a cross-crate query. 2022-08-03 18:32:21 +02:00
Camille GILLOT
ec3f3074a1 Always create elided lifetimes, even if inferred. 2022-07-30 17:58:26 +02:00
Camille GILLOT
6733bc3066 Remove guess_head_span. 2022-07-28 23:14:04 +02:00
Takayuki Maeda
089471b129 change the type of note field to Option<String> 2022-07-28 18:17:55 +09:00
Guillaume Gomez
c37ee1a7e0
Rollup merge of #99728 - cjgillot:ast-lifetimes-anon-clean, r=petrochenkov
Clean up HIR-based lifetime resolution

Based on https://github.com/rust-lang/rust/pull/97313.

Fixes #98932.

r? `@petrochenkov`
2022-07-27 17:55:07 +02:00
Camille GILLOT
4b2f06b8a9 Pacify tidy. 2022-07-26 19:00:31 +02:00
Camille GILLOT
556b02704f Stop creating anonymous late lifetimes. 2022-07-26 19:00:31 +02:00
Camille GILLOT
ad1b1819eb Remove resolve_elided_lifetimes. 2022-07-26 19:00:31 +02:00
Camille GILLOT
30565e5871 Stop resolving lifetime elision on HIR. 2022-07-26 19:00:31 +02:00
Camille GILLOT
267d3620a5 Move fn parameter ribs outwards. 2022-07-26 19:00:31 +02:00
Camille GILLOT
10be0dd8df Replace LifetimeRes::Anonymous by LifetimeRes::Infer. 2022-07-26 19:00:31 +02:00
Camille GILLOT
ab63591f00 Remove the distinction between LifetimeName::Implicit and LifetimeName::Underscore. 2022-07-26 19:00:31 +02:00
Camille GILLOT
a2254d5d7c Do not produce extra lifetime parameters when not needed. 2022-07-26 19:00:30 +02:00
Matthias Krüger
ddb6a46316
Rollup merge of #99729 - cjgillot:rm-unused-tuple, r=michaelwoerister
Remove unused tuple fields

Found by https://github.com/rust-lang/rust/pull/95977
2022-07-26 16:57:50 +02:00
Yuki Okushi
85afb90788
Rollup merge of #99718 - TaKO8Ki:avoid-&str-symbol-to-string-conversions, r=michaelwoerister
Avoid `&str`/`Symbol` to `String` conversions

follow-up to #99342 and #98668
2022-07-26 13:12:23 +09:00
bors
6dbae3ad19 Auto merge of #97313 - cjgillot:ast-lifetimes-anon, r=petrochenkov
Resolve function lifetime elision on the AST

~Based on https://github.com/rust-lang/rust/pull/97720~

Lifetime elision for functions is purely syntactic in nature, so can be resolved on the AST.
This PR replicates the elision logic and diagnostics on the AST, and replaces HIR-based resolution by a `delay_span_bug`.

This refactor allows for more consistent diagnostics, which don't have to guess the original code from HIR.

r? `@petrochenkov`
2022-07-25 20:02:55 +00:00
Camille GILLOT
9450f822fb Unused tuple fields in rustc_resolve. 2022-07-25 19:45:26 +02:00
Camille GILLOT
3148ea31eb Update file description. 2022-07-25 19:19:23 +02:00
Camille GILLOT
3c5048d2ec Report elision failures on the AST. 2022-07-25 19:19:23 +02:00
Takayuki Maeda
051e98b7bf avoid &str/Symbol to String conversions 2022-07-25 22:40:00 +09:00
bors
7f93d4aa0d Auto merge of #98770 - klensy:no-string-dupes-ugly, r=cjgillot
rmeta: avoid embedding `StabilityLevel::Unstable` reason multiple times into .rmeta\.rlib files

Avoids bloating size of some rmeta\rlib files by not placing default string for `StabilityLevel::Unstable` reason multiple times, affects only stdlib\rustc artifacts. For stdlib cuts about 3% (diff of total size for patched\unpatched *.rmeta files of stage1-std) of file size, depending on crates.

fixes #88180
2022-07-25 05:27:17 +00:00
Jordan McQueen
e0c9be539a Use span_bug in case of unexpected rib kind
Extremely minor QOL change to improve the ICE output in case this
default match case is encountered (an unexpected rib kind).
2022-07-23 13:26:45 +09:00
klensy
b38c94857d avoid embedding StabilityLevel::Unstable reason string into metadata multiple times 2022-07-21 22:53:02 +03:00
Matthias Krüger
230b775719
Rollup merge of #99528 - matthiaskrgr:2022_07_perf, r=estebank
couple of clippy::perf fixes
2022-07-21 18:42:07 +02:00
Camille GILLOT
bfd0435fd7 Introduce AnonymousLifetimeRib::Elided and use it for implied 'static. 2022-07-20 22:12:12 +02:00
Matthias Krüger
4b21ad26df
Rollup merge of #99508 - TaKO8Ki:avoid-symbol-to-string-conversion-in-BuiltinLintDiagnostics, r=compiler-errors
Avoid `Symbol` to `String` conversions

follow-up to #99342
2022-07-20 18:58:20 +02:00
David Wood
224aec213d middle: add implies_by to #[unstable]
If part of a feature is stabilized and a new feature is added for the
remaining parts, then the `implied_by` attribute can be used to indicate
which now-stable feature previously contained a item. If the now-stable
feature is still active (if the user has only just updated rustc, for
example) then there will not be an stability error for uses of the item
from the implied feature.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-20 14:53:01 +01:00
Matthias Krüger
611bbcb044 clippy::perf fixes 2022-07-20 11:48:11 +02:00
Takayuki Maeda
56e7777755 avoid &str to String conversions 2022-07-20 18:19:57 +09:00
Matthias Krüger
4815f94c51
Rollup merge of #99401 - TaKO8Ki:avoid-symbol-to-&str-conversions, r=nnethercote
Avoid `Symbol` to `&str` conversions

`Symbol::as_str` is a slowish operation, so this patch removes some usages of it.
2022-07-19 13:30:46 +02:00
bors
96c2df810b Auto merge of #98120 - TaKO8Ki:box-diagnostic-metadata-field, r=estebank
[Experiment] Box `diagnostic_metadata` field

closes #97954

r? `@estebank`
2022-07-19 03:02:30 +00:00
Takayuki Maeda
a22934bea1 avoid Symbol to &str conversions 2022-07-18 14:25:34 +09:00
Caio
3266460749 Stabilize let_chains 2022-07-16 20:17:58 -03:00
Dylan DPC
e5a86d7358
Rollup merge of #98705 - WaffleLapkin:closure_binder, r=cjgillot
Implement `for<>` lifetime binder for closures

This PR implements RFC 3216 ([TI](https://github.com/rust-lang/rust/issues/97362)) and allows code like the following:

```rust
let _f = for<'a, 'b> |a: &'a A, b: &'b B| -> &'b C { b.c(a) };
//       ^^^^^^^^^^^--- new!
```

cc ``@Aaron1011`` ``@cjgillot``
2022-07-14 14:14:21 +05:30
Dylan DPC
f5e9cb53ab
Rollup merge of #97720 - cjgillot:all-fresh, r=petrochenkov
Always create elided lifetime parameters for functions

Anonymous and elided lifetimes in functions are sometimes (async fns) --and sometimes not (regular fns)-- desugared to implicit generic parameters.

This difference of treatment makes it some downstream analyses more complicated to handle.  This step is a pre-requisite to perform lifetime elision resolution on AST.

There is currently an inconsistency in the treatment of argument-position impl-trait for functions and async fns:
```rust
trait Foo<'a> {}
fn foo(t: impl Foo<'_>) {} //~ ERROR missing lifetime specifier
async fn async_foo(t: impl Foo<'_>) {} //~ OK
fn bar(t: impl Iterator<Item = &'_ u8>) {} //~ ERROR missing lifetime specifier
async fn async_bar(t: impl Iterator<Item = &'_ u8>) {} //~ OK
```

The current implementation reports "missing lifetime specifier" on `foo`, but **accepts it** in `async_foo`.
This PR **proposes to accept** the anonymous lifetime in both cases as an extra generic lifetime parameter.
This change would be insta-stable, so let's ping t-lang.
Anonymous lifetimes in GAT bindings keep being forbidden:
```rust
fn foo(t: impl Foo<Assoc<'_> = Bar<'_>>) {}
                         ^^        ^^
                       forbidden   ok
```
I started a discussion here: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Anonymous.20lifetimes.20in.20universal.20impl-trait/near/284968606

r? ``@petrochenkov``
2022-07-14 14:14:19 +05:30
Camille GILLOT
5a20834884 Add feature gate. 2022-07-13 14:17:09 +02:00
Camille GILLOT
031b2c53cd Always use CreateParameter mode for function definitions. 2022-07-13 14:14:37 +02:00
Takayuki Maeda
f65bf0b2bb avoid &str to String conversions 2022-07-13 13:24:38 +09:00
Maybe Waffle
df4fee9841 Add an indirection for closures in hir::ExprKind
This helps bring `hir::Expr` size down, `Closure` was the biggest
variant, especially after `for<>` additions.
2022-07-12 21:00:13 +04:00
Maybe Waffle
3ebb852956 Add LifetimeBinderKind::Closure 2022-07-12 21:00:13 +04:00
Maybe Waffle
0c284843ba make for<> in closures a possible place to suggest adding named lifetime 2022-07-12 21:00:13 +04:00
Maybe Waffle
c2dbd62c7c Lower closure binders to hir & properly check them 2022-07-12 21:00:03 +04:00
Maybe Waffle
40ae7b5b8e Parse closure binders
This is first step in implementing RFC 3216.
- Parse `for<'a>` before closures in ast
  - Error in lowering
- Add `closure_lifetime_binder` feature
2022-07-12 16:25:16 +04:00
bors
38b72154de Auto merge of #98637 - cjgillot:bare-trait-anon-lt, r=petrochenkov
Create fresh lifetime parameters for bare fn trait too

The current code fails to account for the equivalence between `dyn FnMut(&mut u8)` and bare `FnMut(&mut u8)`, and treated them differently.

This PR introduces a special case for `Fn` traits, which are always fully resolved.

Fixes #98616
Fixes #98726
This will require a beta-backport, as beta contains that bug.

r? `@petrochenkov`
2022-07-11 17:09:37 +00:00
Dylan DPC
9fc297a2ae
Rollup merge of #99140 - TaKO8Ki:implement-is-accessible-span, r=fee1-dead
Implement `SourceMap::is_span_accessible`

This patch adds `SourceMap::is_span_accessible` and replaces `span_to_snippet(span).is_ok()` and `span_to_snippet(span).is_err()` with it. This removes a `&str` to `String` conversion.
2022-07-11 15:19:32 +05:30
Takayuki Maeda
018155c3a2 rename a method 2022-07-11 16:51:19 +09:00
Takayuki Maeda
12d11e9a35 implement is_accessible_span 2022-07-11 11:36:15 +09:00
Matthias Krüger
86af7135ae
Rollup merge of #99103 - TaKO8Ki:avoid-&str-to-string-conversions, r=oli-obk
Avoid some `&str` to `String` conversions

This patch removes some `&str` to `String` conversions.
2022-07-10 11:52:17 +02:00
Takayuki Maeda
bda83e6543 avoid some &str to String conversions 2022-07-10 03:18:56 +09:00
Dylan DPC
d75a5723db
Rollup merge of #99008 - obeis:issue-98974, r=compiler-errors
Adding suggestion for E0530

Closes #98974
2022-07-09 11:28:06 +05:30
Obei Sideg
1b32eb34b3 Update ui test for the new E0530 suggestion 2022-07-08 14:54:11 +03:00
Obei Sideg
c2436d54d0 Check if E0530 is rustc_resolve::late::PatternSource::Match to emit suggestion 2022-07-08 14:06:50 +03:00
Obei Sideg
ea46e7a47e Check if E0530 is tuple variant or tuple struct to emit suggestion 2022-07-08 13:20:05 +03:00
Obei Sideg
51504dbf01 Adding suggestion for E0530 2022-07-07 21:00:01 +03:00
Deadbeef
2f0ccdfbba suggest adding a derive for #[default] applied to variants 2022-07-07 04:57:01 +00:00
bors
3dcb616888 Auto merge of #98959 - cjgillot:late-bound-order, r=michaelwoerister
Return a FxIndexSet in is_late_bound query.

This return value is iterated upon by borrowck, hence the need to preserve
a deterministic iteration order.

Fixes https://github.com/rust-lang/rust/issues/98890
Affects https://github.com/rust-lang/rust/issues/96655

I don't know if this supersedes https://github.com/rust-lang/rust/pull/98924 or fixes an unrelated bug.

r? `@michaelwoerister`
This may deserve a backport.
2022-07-06 17:38:48 +00:00
ClementTsang
503c669927 fix typo in note about multiple inaccessible type aliases
Mainly intended as a small typo fix ("aliass" -> "aliases") for
the case where a type cannot be found in scope, and there are
multiple inaccessible type aliases that match the missing type.

In general this change would use the correct plural form in
this scenario for words that end with 's'.
2022-07-05 21:21:12 -04:00
Camille GILLOT
2a7abed87f Return a FxIndexSet in is_late_bound query.
This return value is iterated upon by borrowck, hence the need to preserve
a deterministic iteration order.
2022-07-05 21:54:40 +02:00
Takayuki Maeda
eb80407d79 suggest #[derive(Default)] to enums with #[default] 2022-07-04 20:46:59 +09:00
bors
ada8c80bed Auto merge of #98673 - pietroalbini:pa-bootstrap-update, r=Mark-Simulacrum
Bump bootstrap compiler

r? `@Mark-Simulacrum`
2022-07-03 06:55:50 +00:00
bors
5f98537eb7 Auto merge of #98569 - nnethercote:finalize_resolutions_id, r=cjgillot
Avoid unnecessary work in `finalize_resolutions_in`.

If `module.opt_def_id()` returns `None`, we can skip most of the work.

r? `@lqd`
2022-07-02 23:38:08 +00:00
Camille GILLOT
21a12e8ab7 Handle fresh lifetimes on bare trait objects. 2022-07-02 09:21:55 +02:00
Pietro Albini
6b2d3d5f3c
update cfg(bootstrap)s 2022-07-01 15:48:23 +02:00
Matthias Krüger
6ee667374e
Rollup merge of #98677 - lyming2007:issue-98492-fix, r=lcnr
For diagnostic information of Boolean, remind it as use the type: 'bool'

Fixes #98492.

It helps programmers coming from other languages
	modified:   compiler/rustc_resolve/src/late/diagnostics.rs
2022-06-30 19:55:53 +02:00
Yiming Lei
15d3ea504a For diagnostic information of Boolean, remind it as use the type: 'bool'
It helps programmers coming from other languages
	modified:   compiler/rustc_resolve/src/late/diagnostics.rs

	modified:   src/test/ui/lint/recommend-literal.rs
	modified:   src/test/ui/lint/recommend-literal.stderr

	modified:   compiler/rustc_resolve/src/late/diagnostics.rs
	modified:   src/test/ui/lint/recommend-literal.rs
	modified:   src/test/ui/lint/recommend-literal.stderr

	modified:   compiler/rustc_resolve/src/late/diagnostics.rs
	modified:   src/test/ui/lint/recommend-literal.rs
	modified:   src/test/ui/lint/recommend-literal.stderr
2022-06-30 08:34:10 -07:00
Matthias Krüger
d34c4ca9be
Rollup merge of #98668 - TaKO8Ki:avoid-many-&str-to-string-conversions, r=Dylan-DPC
Avoid some `&str` to `String` conversions with `MultiSpan::push_span_label`

This patch removes some`&str` to `String` conversions with `MultiSpan::push_span_label`.
2022-06-29 20:35:07 +02:00
Takayuki Maeda
6212e6b339 avoid many &str to String conversions with MultiSpan::push_span_label 2022-06-29 21:16:43 +09:00
Nicholas Nethercote
0e475b5d5e Avoid unnecessary work in finalize_resolutions_in.
If `module.opt_def_id()` returns `None`, we can skip most of the work.
2022-06-29 09:20:32 +10:00
Nicholas Nethercote
7c40661ddb Update smallvec to 1.8.1.
This pulls in https://github.com/servo/rust-smallvec/pull/282, which
gives some small wins for rustc.
2022-06-27 08:48:55 +10:00
Yuki Okushi
5e98e55668
Rollup merge of #98419 - WaffleLapkin:remove_excess_rib, r=compiler-errors
Remove excess rib while resolving closures

I've mentioned this on [zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/.60ClosureOrAsyncRibKind.60.20weirdness/near/286982959), in `rustc_resolve`, while resolving closures we add an excess `ClosureOrAsyncRibKind`. It's excess because we later add another one in `visit_fn`.

I couldn't find a way in which removing this will break anything, all test seem to pass, etc.

r? ``@compiler-errors``
cc ``@davidtwco``
2022-06-24 16:43:49 +09:00
Michael Goulet
3b68700d0c
Rollup merge of #98269 - compiler-errors:provide-more-segment-res, r=petrochenkov
Provide a `PathSegment.res` in more cases

I find that in many cases, the `res` associated with a `PathSegment` is `Res::Err` even though the path was fully resolved. A few diagnostics use this `res` and their error messages suffer because of the lack of resolved segment.

This fixes it a bit, but it's obviously not complete and I'm not exactly sure if it's correct.
2022-06-23 14:39:07 -07:00
Maybe Waffle
9730221b9d Remove excess rib while resolving closures 2022-06-23 12:21:23 +04:00
bors
10f4ce324b Auto merge of #98279 - cjgillot:all-fresh-nofn, r=petrochenkov
Create elided lifetime parameters for function-like types

Split from https://github.com/rust-lang/rust/pull/97720

This PR refactor lifetime generic parameters in bare function types and parenthesized traits to introduce the additional required lifetimes as fresh parameters in a `for<>` bound.

This PR does the same to lifetimes appearing in closure signatures, and as-if introducing `for<>` bounds on closures (without the associated change in semantics).

r? `@petrochenkov`
2022-06-22 10:48:58 +00:00
Camille GILLOT
7437136f0e Use CreateParameter mode for closures too. 2022-06-21 21:13:43 +02:00
Camille GILLOT
32af719b07 Always create parameters for functions-like types. 2022-06-21 21:13:41 +02:00
Santiago Pastorino
5ed1495041
This comment is out dated and misleading
Arms are about TAIT and RPIT, as the variants clearly show.
2022-06-21 12:43:58 -03:00
Michael Goulet
f924e74fb1 Provide a segment res in more cases 2022-06-20 21:27:42 -07:00
Matthias Krüger
3e5800b8d3
Rollup merge of #98267 - compiler-errors:suggest-wildcard-arm, r=oli-obk
Don't omit comma when suggesting wildcard arm after macro expr

* Also adds `Span::eq_ctxt` to consolidate the various usages of `span.ctxt() == other.ctxt()`
* Also fixes an unhygenic usage of spans which caused the suggestion to render weirdly when we had one arm match in a macro
* Also always suggests a comma (i.e. even after a block) if we're rendering a wildcard arm in a single-line match (looks prettier 🌹)

Fixes #94866
2022-06-20 20:13:10 +02:00
Michael Goulet
047de83e02 Don't suggest adding Self as a type parameter 2022-06-19 19:44:00 -07:00
Michael Goulet
018c319b21 Mention what item is using an invalid Self type 2022-06-19 19:43:40 -07:00
Michael Goulet
52c9906c4b Use Span::eq_ctxt method instead of .ctxt() == .ctxt() 2022-06-19 16:46:59 -07:00
Camille GILLOT
bc6a2c11ee Leave the responsibility to create Fresh lifetimes to lowering. 2022-06-19 22:32:43 +02:00
Camille GILLOT
dc614b90ca Make matches exhaustive. 2022-06-19 22:30:30 +02:00
Camille GILLOT
87c841e190 Remove the region terminology. 2022-06-19 22:28:53 +02:00
Camille GILLOT
bf38ba260d Separate AnonymousCreateParameter and ReportElidedInPath. 2022-06-18 16:59:27 +02:00
Camille GILLOT
237e267b80 Refactor visit_fn. 2022-06-18 16:59:19 +02:00
Camille GILLOT
80c6a1f275 Rustfmt resolve_implementation. 2022-06-18 16:58:18 +02:00
Camille GILLOT
228def7e20 Extract AssocItem handling. 2022-06-18 16:56:30 +02:00
bors
3a8b0144c8 Auto merge of #98106 - cjgillot:split-definitions, r=michaelwoerister
Split up `Definitions` and `ResolverAstLowering`.

Split off https://github.com/rust-lang/rust/pull/95573

r? `@michaelwoerister`
2022-06-17 10:00:11 +00:00
Camille GILLOT
ae5959f4ba Consume resolutions for lowering separately. 2022-06-15 19:42:43 +02:00
Camille GILLOT
52f22c7d01 Remove unused item_generics_num_lifetimes. 2022-06-15 19:19:53 +02:00
Yuki Okushi
b2d0e7838e
Rollup merge of #98087 - TaKO8Ki:suggest-adding-macro-export, r=oli-obk
Suggest adding a `#[macro_export]` to a private macro

fixes #97628
2022-06-15 12:02:05 +09:00
Yuki Okushi
0ee15040d5
Rollup merge of #97822 - compiler-errors:hesitate-to-suggest-intrinsics, r=oli-obk
Filter out intrinsics if we have other import candidates to suggest

Fixes #97618

Also open to just sorting these candidates to be last. Pretty easy to modify the code to do that, too.
2022-06-15 12:02:01 +09:00
Takayuki Maeda
5ece481162 box diagnostic_metadata field 2022-06-15 11:23:19 +09:00
Camille GILLOT
34e4d72929 Separate source_span and expn_that_defined from Definitions. 2022-06-14 22:45:51 +02:00
Camille GILLOT
603746a35e Make ResolverAstLowering a struct. 2022-06-14 22:44:27 +02:00
Camille GILLOT
47799de35a Separate Definitions and CrateStore from ResolverOutputs. 2022-06-14 22:44:27 +02:00
Takayuki Maeda
0d24405211 implement MacroData 2022-06-15 00:31:21 +09:00
Takayuki Maeda
801725a77b suggest adding a #[macro_export] to a private macro 2022-06-14 14:58:46 +09:00
Takayuki Maeda
fd1290a631 remove unnecessary to_string and String::new for tool_only_span_suggestion 2022-06-13 16:01:16 +09:00
Takayuki Maeda
77d6176e69 remove unnecessary to_string and String::new 2022-06-13 15:48:40 +09:00
bors
fa68e73e99 Auto merge of #97903 - est31:unused_macro_rules_compile_error, r=petrochenkov
Never regard macro rules with compile_error! invocations as unused

The very point of compile_error! is to never be reached, and one of
the use cases of the macro, currently also listed as examples in the
documentation of compile_error, is to create nicer errors for wrong
macro invocations. Thus, we should never warn about unused macro arms
that contain invocations of compile_error.

See also https://github.com/rust-lang/rust/pull/96150#issuecomment-1126599107 and the discussion after that.

Furthermore, the PR also contains two commits to silence `unused_macro_rules` when a macro has an invalid rule, and to add a test that `unused_macros` does not behave badly in the same situation.

r? `@petrochenkov` as I've talked to them about this
2022-06-11 08:46:21 +00:00
Dylan DPC
640019ba6e
Rollup merge of #97812 - TaKO8Ki:suggest-to-swap-struct-and-trait, r=estebank
Suggest to swap a struct and a trait in trait impls

closes #89590
2022-06-11 07:42:14 +02:00
Yuki Okushi
c2355a615d
Rollup merge of #97927 - cjgillot:issue-97836, r=petrochenkov
Do not introduce bindings for types and consts in HRTB.

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

r? `@petrochenkov`
2022-06-10 17:22:32 +09:00
est31
eb3c611e1d Never regard macro rules with compile_error! invocations as unused
The very point of compile_error! is to never be reached, and one of
the use cases of the macro, currently also listed as examples in the
documentation of compile_error, is to create nicer errors for wrong
macro invocations. Thus, we shuuld never warn about unused macro arms
that contain invocations of compile_error.
2022-06-09 23:21:06 +02:00
Camille GILLOT
4d871a25bf Do not introduce bindings for types and consts in HRTB. 2022-06-09 21:49:14 +02:00
Takayuki Maeda
5639e52ae1 move suggestions to its own method 2022-06-09 17:52:10 +09:00
Michael Goulet
2ae1ec9119 Don't suggest adding let in certain if conditions 2022-06-07 21:02:58 -07:00
Michael Goulet
ab0938d0df Filter out intrinsics if we have other import candidates to suggest 2022-06-07 01:08:52 -07:00
bors
bb55bd449e Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis
Remove migrate borrowck mode

Closes #58781
Closes #43234

# Stabilization proposal

This PR proposes the stabilization of `#![feature(nll)]` and the removal of `-Z borrowck`. Current borrow checking behavior of item bodies is currently done by first infering regions *lexically* and reporting any errors during HIR type checking. If there *are* any errors, then MIR borrowck (NLL) never occurs. If there *aren't* any errors, then MIR borrowck happens and any errors there would be reported. This PR removes the lexical region check of item bodies entirely and only uses MIR borrowck. Because MIR borrowck could never *not* be run for a compiled program, this should not break any programs. It does, however, change diagnostics significantly and allows a slightly larger set of programs to compile.

Tracking issue: #43234
RFC: https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.md
Version: 1.63 (2022-06-30 => beta, 2022-08-11 => stable).

## Motivation

Over time, the Rust borrow checker has become "smarter" and thus allowed more programs to compile. There have been three different implementations: AST borrowck, MIR borrowck, and polonius (well, in progress). Additionally, there is the "lexical region resolver", which (roughly) solves the constraints generated through HIR typeck. It is not a full borrow checker, but does emit some errors.

The AST borrowck was the original implementation of the borrow checker and was part of the initially stabilized Rust 1.0. In mid 2017, work began to implement the current MIR borrow checker and that effort ompleted by the end of 2017, for the most part. During 2018, efforts were made to migrate away from the AST borrow checker to the MIR borrow checker - eventually culminating into "migrate" mode - where HIR typeck with lexical region resolving following by MIR borrow checking - being active by default in the 2018 edition.

In early 2019, migrate mode was turned on by default in the 2015 edition as well, but with MIR borrowck errors emitted as warnings. By late 2019, these warnings were upgraded to full errors. This was followed by the complete removal of the AST borrow checker.

In the period since, various errors emitted by the MIR borrow checker have been improved to the point that they are mostly the same or better than those emitted by the lexical region resolver.

While there do remain some degradations in errors (tracked under the [NLL-diagnostics tag](https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3ANLL-diagnostics), those are sufficiently small and rare enough that increased flexibility of MIR borrow check-only is now a worthwhile tradeoff.

## What is stabilized

As said previously, this does not fundamentally change the landscape of accepted programs. However, there are a [few](https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3ANLL-fixed-by-NLL) cases where programs can compile under `feature(nll)`, but not otherwise.

There are two notable patterns that are "fixed" by this stabilization. First, the `scoped_threads` feature, which is a continutation of a pre-1.0 API, can sometimes emit a [weird lifetime error](https://github.com/rust-lang/rust/issues/95527) without NLL. Second, actually seen in the standard library. In the `Extend` impl for `HashMap`, there is an implied bound of `K: 'a` that is available with NLL on but not without - this is utilized in the impl.

As mentioned before, there are a large number of diagnostic differences. Most of them are better, but some are worse. None are serious or happen often enough to need to block this PR. The biggest change is the loss of error code for a number of lifetime errors in favor of more general "lifetime may not live long enough" error. While this may *seem* bad, the former error codes were just attempts to somewhat-arbitrarily bin together lifetime errors of the same type; however, on paper, they end up being roughly the same with roughly the same kinds of solutions.

## What isn't stabilized

This PR does not completely remove the lexical region resolver. In the future, it may be possible to remove that (while still keeping HIR typeck) or to remove it together with HIR typeck.

## Tests

Many test outputs get updated by this PR. However, there are number of tests specifically geared towards NLL under `src/test/ui/nll`

## History

* On 2017-07-14, [tracking issue opened](https://github.com/rust-lang/rust/issues/43234)
* On 2017-07-20, [initial empty MIR pass added](https://github.com/rust-lang/rust/pull/43271)
* On 2017-08-29, [RFC opened](https://github.com/rust-lang/rfcs/pull/2094)
* On 2017-11-16, [Integrate MIR type-checker with NLL](https://github.com/rust-lang/rust/pull/45825)
* On 2017-12-20, [NLL feature complete](https://github.com/rust-lang/rust/pull/46862)
* On 2018-07-07, [Don't run AST borrowck on mir mode](https://github.com/rust-lang/rust/pull/52083)
* On 2018-07-27, [Add migrate mode](https://github.com/rust-lang/rust/pull/52681)
* On 2019-04-22, [Enable migrate mode on 2015 edition](https://github.com/rust-lang/rust/pull/59114)
* On 2019-08-26, [Don't downgrade errors on 2015 edition](https://github.com/rust-lang/rust/pull/64221)
* On 2019-08-27, [Remove AST borrowck](https://github.com/rust-lang/rust/pull/64790)
2022-06-07 05:04:14 +00:00
Takayuki Maeda
9db03b9bc8 suggest swapping a struct and a trait
fmt
2022-06-07 09:52:52 +09:00
Dylan DPC
a736acc804
Rollup merge of #97312 - cjgillot:no-path-in-scope, r=compiler-errors
Compute lifetimes in scope at diagnostic time

The set of available lifetimes is currently computed during lifetime resolution on HIR.  It is only used for one diagnostic.

In this PR, HIR lifetime resolution just reports whether elided lifetimes are well-defined at the place of use.  The diagnostic code is responsible for building a list of lifetime names if elision is not allowed.

This will allow to remove lifetime resolution on HIR eventually.
2022-06-06 14:34:55 +02:00
Matthias Krüger
f2b3808920
Rollup merge of #97683 - cjgillot:no-apit-hrtb, r=nagisa
Fail gracefully when encountering an HRTB in APIT.

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

~The first commit will be merged as part of https://github.com/rust-lang/rust/pull/97415~
2022-06-06 08:37:00 +02:00
bors
4322a785cc Auto merge of #97697 - WaffleLapkin:no_ref_vec, r=WaffleLapkin
Replace `&Vec<_>`s with `&[_]`s

It's generally preferable to use `&[_]` since it's one less indirection and it can be created from types other that `Vec`.

I've left `&Vec` in some locals where it doesn't really matter, in cases where `TypeFoldable` is expected (`TypeFoldable: Clone` so slice can't implement it) and in cases where it's `&TypeAliasThatIsActiallyVec`. Nothing important, really, I was just a little annoyed by `visit_generic_param_vec` :D

r? `@compiler-errors`
2022-06-05 09:30:53 +00:00
Maybe Waffle
cae3c78664 Rename visit_generic_param{_slice => s} 2022-06-05 13:12:31 +04:00
bors
656eec8785 Auto merge of #97391 - Urgau:cfg_accessible, r=petrochenkov
Handle more cases in cfg_accessible

This PR tries to handle more cases in the cfg_accessible implementation by only emitting a "not sure" error only if we have partially resolved a path.

This PR also adds many tests for the "not sure" cases and for private items.

r? `@petrochenkov`
2022-06-05 04:16:03 +00:00