Commit Graph

1111 Commits

Author SHA1 Message Date
Guillaume Gomez
1aaf9aec95
Rollup merge of #100147 - Bryanskiy:private-in-public, r=petrochenkov
optimization of access level table construction

Refactoring which was mentioned in #87487
2022-09-02 11:34:48 +02:00
bors
2e35f954ad Auto merge of #98960 - cjgillot:entry-kind, r=estebank
Remove EntryKind from metadata.

This PR continues the refactor of metadata emission to be more systematic, iterating on definitions and filtering based on each definition's `DefKind`. This allows to remove the large `EntryKind` enum, replaced by linear tables in metadata.
2022-09-01 19:31:14 +00:00
Oli Scherer
ee3c835018 Always import all tracing macros for the entire crate instead of piecemeal by module 2022-09-01 14:54:27 +00:00
Oli Scherer
d3b22c7267 Directly use the instrument macro instead of its full path 2022-09-01 14:53:46 +00:00
bors
b32223fec1 Auto merge of #100707 - dzvon:fix-typo, r=davidtwco
Fix a bunch of typo

This PR will fix some typos detected by [typos].

I only picked the ones I was sure were spelling errors to fix, mostly in
the comments.

[typos]: https://github.com/crate-ci/typos
2022-09-01 05:39:58 +00:00
Bryanskiy
10804672c2 access_levels.rs refactor 2022-08-31 14:23:01 +03:00
Dezhi Wu
b1430fb7ca Fix a bunch of typo
This PR will fix some typos detected by [typos].

I only picked the ones I was sure were spelling errors to fix, mostly in
the comments.

[typos]: https://github.com/crate-ci/typos
2022-08-31 18:24:55 +08:00
Donough Liu
3f66efde75 Fix uintended diagnostic caused by drain(..) 2022-08-31 04:12:46 +01:00
Camille GILLOT
b94d421d08 Remove fn_has_self_parameter table. 2022-08-30 19:06:30 +02:00
bors
0631ea5d73 Auto merge of #101183 - Dylan-DPC:rollup-6kewixv, r=Dylan-DPC
Rollup of 9 pull requests

Successful merges:

 - #95376 (Add `vec::Drain{,Filter}::keep_rest`)
 - #100092 (Fall back when relating two opaques by substs in MIR typeck)
 - #101019 (Suggest returning closure as `impl Fn`)
 - #101022 (Erase late bound regions before comparing types in `suggest_dereferences`)
 - #101101 (interpret: make read-pointer-as-bytes a CTFE-only error with extra information)
 - #101123 (Remove `register_attr` feature)
 - #101175 (Don't --bless in pre-push hook)
 - #101176 (rustdoc: remove unused CSS selectors for `.table-display`)
 - #101180 (Add another MaybeUninit array test with const)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-30 08:29:42 +00:00
Dylan DPC
c18292f6a3
Rollup merge of #101123 - JohnTitor:rm-register-attr, r=TaKO8Ki
Remove `register_attr` feature

Closes #66080

Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2022-08-30 11:26:52 +05:30
bors
a0d07093f8 Auto merge of #100812 - Nilstrieb:revert-let-chains-nightly, r=Mark-Simulacrum
Revert let_chains stabilization

This is the revert against master, the beta revert was already done in #100538.

Bumps the stage0 compiler which already has it reverted.
2022-08-30 05:48:22 +00:00
Nilstrieb
d1ef8180f9 Revert let_chains stabilization
This reverts commit 3266460749.

This is the revert against master, the beta revert was already done in #100538.
2022-08-29 19:34:11 +02:00
Dylan DPC
5555e13a6e
Rollup merge of #99821 - cjgillot:ast-lifetimes-2, r=compiler-errors
Remove separate indexing of early-bound regions

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

This PR copies some modifications from https://github.com/rust-lang/rust/pull/97839 around object lifetime defaults.
These modifications allow to stop counting generic parameters during lifetime resolution, and rely on the indexing given by `rustc_typeck::collect`.
2022-08-29 16:49:39 +05:30
bors
ce36e88256 Auto merge of #100497 - kadiwa4:remove_clone_into_iter, r=cjgillot
Avoid cloning a collection only to iterate over it

`@rustbot` label: +C-cleanup
2022-08-28 18:31:08 +00:00
Yuki Okushi
76dd5c58a0
Remove register_attr feature
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2022-08-28 21:23:23 +09:00
Vadim Petrochenkov
fc3f3c304b rustc_middle: Remove Visibility::Invisible 2022-08-27 22:34:18 +03:00
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
Matthias Krüger
326315bf54
Rollup merge of #97609 - Elliot-Roberts:unused-trait-refactor, r=cjgillot
Iterate over `maybe_unused_trait_imports` when checking dead trait imports

Closes #96873
r? `@cjgillot`

Some questions, if you have time:

- Is there a way to shorten the `rustc_data_structures::fx::FxIndexSet` path in the query declaration? I wasn't sure where to put a `use`.
- Was returning by reference from the query the right choice here?
- How would I go about evaluating the importance of the `is_dummy()` call in `check_crate`? I don't see failing tests when I comment it out. Should I just try to determine whether dummy spans can ever be put into `maybe_unused_trait_imports`?
- Am I doing anything silly with the various ID types?
- Is that `let-else` with `unreachable!()` bad? (i.e is there a better idiom? Would `panic!("<explanation>")` be better?)
- If I want to evaluate the perf of using a `Vec` as mentioned in #96873, is the best way to use the CI or is it feasible locally?

Thanks :)
2022-06-04 23:42:00 +02:00
Elliot Roberts
76c6845a85 Iterate over maybe_unused_trait_imports when checking dead trait imports 2022-06-04 12:38:55 -07:00
Camille GILLOT
af8739b96e Completely remove LifetimeScopeForPath. 2022-06-04 15:33:27 +02:00
Camille GILLOT
a07290047e Compute lifetimes in scope at diagnostic time. 2022-06-04 15:28:15 +02:00
Jack Huey
410dcc9674 Fully stabilize NLL 2022-06-03 17:16:41 -04:00
Camille GILLOT
bacd8adeda Fail gracefully when encountering an HRTB in APIT. 2022-06-03 22:50:14 +02:00
Maybe Waffle
afaa9854fa Replace &Vec<_>s with &[_]s 2022-06-03 20:42:42 +04:00
Camille GILLOT
ba40fe99c3 Compute is_late_bound in a separate query.
The computation is actually much simpler, and can be done by directly
fetching the HIR for the `FnDecl` and its generics.
2022-06-03 12:05:04 +02:00
Camille GILLOT
b1294e86bb Manipulate lifetimes by LocalDefId for region resolution. 2022-06-03 12:03:20 +02:00
Urgau
b76d1125d4 Conservatively report "not sure" in cfg_accessible 2022-06-03 11:31:11 +02:00
Camille GILLOT
2aa9c703ce Use the same message as type & const generics. 2022-06-03 08:26:10 +02:00
Camille GILLOT
86bd99060c Reuse resolve_label to check lifetime shadowing. 2022-06-03 08:26:10 +02:00
Camille GILLOT
c75409d5e4 Do not lower generic lifetime params when AST resolution emitted an error. 2022-06-03 08:26:10 +02:00
Camille GILLOT
be40b58895 Stop warning against unrelated labels. 2022-06-02 19:24:26 +02:00
Camille GILLOT
257d8fce3e Do not report mixed label/lifetime shadowing. 2022-06-02 19:24:12 +02:00
Camille GILLOT
6e1b0105c6 Diagnose shadowing on AST. 2022-06-02 19:23:39 +02:00
Matthias Krüger
daedae7b23
Rollup merge of #97264 - TaKO8Ki:suggest-extern-crate-when-failing-to-resolve-use-crate, r=estebank
Suggest `extern crate foo` when failing to resolve `use foo`

closes #97095

r? ``@estebank``
2022-06-01 17:11:05 +02:00
Urgau
163374644b Handle more cases in cfg_accessible 2022-05-30 16:51:38 +02:00
Takayuki Maeda
b2480a0251 suggest extern crate foo when failing to resolve use foo
fix ci error
2022-05-25 09:58:19 +09:00
Yuki Okushi
8d9f258faa
Rollup merge of #97240 - TaKO8Ki:improve-errors-about-typos-on-variables, r=compiler-errors
Typo suggestion for a variable with a name similar to struct fields

closes #97133
2022-05-24 12:18:30 +09:00
Takayuki Maeda
39caed08ae add typo suggestions for all AssocSuggestion variants 2022-05-23 19:58:20 +09:00
bors
32c8c5df06 Auto merge of #97195 - notriddle:notriddle/cleanup, r=GuillaumeGomez
rustdoc: shrink GenericArgs/PathSegment with boxed slices

This PR also contains a few cleanup bits and pieces, but one of them is a broken intra-doc link, and the other is removing an unused Hash impl. The last commit is the one that matters.
2022-05-23 10:46:50 +00:00
Jacob Pratt
7b987e34c0
Merge crate and restricted visibilities 2022-05-21 17:02:55 -04:00
Jacob Pratt
8cece636b2
Remove feature: crate visibility modifier 2022-05-21 14:22:06 -04:00
Michael Howell
98b98ac11e Fix broken intra-doc link 2022-05-21 07:53:45 -07:00
Takayuki Maeda
42e9f2daf3 typo suggestion for a variable with a name similar to struct fields 2022-05-21 12:55:37 +09:00
Jacob Pratt
49c82f31a8
Remove crate visibility usage in compiler 2022-05-20 20:04:54 -04:00
Camille GILLOT
563916d698 Lint single-use-lifetimes on the AST. 2022-05-20 12:26:37 +02:00
Camille GILLOT
db8a9274a9 Introduce BareFnTy::decl_span and fix generics span. 2022-05-20 12:26:37 +02:00
Camille GILLOT
5953c57f27 Introduce LifetimeCtxt. 2022-05-20 12:25:05 +02:00
bors
10d9ecda48 Auto merge of #96800 - nbdd0121:const, r=nagisa
Permit `asm_const` and `asm_sym` to reference generic params

Related #96557

These constructs will be allowed:
```rust
fn foofoo<const N: usize>() {}

unsafe fn foo<const N: usize>() {
    asm!("/* {0} */", const N);
    asm!("/* {0} */", const N + 1);
    asm!("/* {0} */", sym foofoo::<N>);
}

fn barbar<T>() {}

unsafe fn bar<T>() {
    asm!("/* {0} */", const std::mem::size_of::<T>());
    asm!("/* {0} */", const std::mem::size_of::<(T, T)>());
    asm!("/* {0} */", sym barbar::<T>);
    asm!("/* {0} */", sym barbar::<(T, T)>);
}
```

`@Amanieu,` I didn't switch inline asms to use `DefKind::InlineAsm`, as I see little value doing that; given that no type inference is needed, it will only make typecking slower and more complex but will have no real gains. I did switch them to follow the same code path as inline asm during symbol resolution, though.
The `error: unconstrained generic constant` you mentioned in #76001 is due to the fact that `to_const` will actually add a wfness obligation to the constant, which we don't need for `asm_const`, so I have that removed.

`@rustbot` label: +A-inline-assembly +F-asm
2022-05-18 15:07:47 +00:00
Yuki Okushi
78c709ca9b
Rollup merge of #96651 - ken-matsui:omit-unnecessary-help-to-add-cfg-test, r=cjgillot
Omit unnecessary help to add `#[cfg(test)]` when already annotated

Closes: https://github.com/rust-lang/rust/issues/96611

The related PR is: https://github.com/rust-lang/rust/pull/91770
2022-05-18 07:40:56 +09:00
Ken Matsui
03007dee79
Omit unnecessary help to add #[cfg(test)] when already annotated 2022-05-17 06:50:07 +09:00
bors
b36be12d97 Auto merge of #97039 - cjgillot:no-rpit-hrtb, r=jackh726
Forbid nested opaque types to reference HRTB from opaque types.

Avoids https://github.com/rust-lang/rust/issues/96194
Alternative to https://github.com/rust-lang/rust/pull/96970

r? `@oli-obk`
2022-05-14 15:47:22 +00:00
Camille GILLOT
b276b65f46 Forbid nested opaque types to reference HRTB from opaque types. 2022-05-14 11:38:25 +02:00
Vadim Petrochenkov
9ba5281c76 resolve: Move collection of all macro_rules in the crate to rustdoc 2022-05-13 21:43:36 +03:00
Matthias Krüger
f2100daf32
Rollup merge of #96989 - cjgillot:defpath-use, r=davidtwco
Be more precise than DefPathData::Misc.

This variant was used for two unrelated things. Let's make this cleaner.
2022-05-13 05:33:13 +02:00
Camille GILLOT
dde7bff574 Replace DefPathData::Misc by two appropriately-named variants. 2022-05-12 20:12:35 +02:00
bors
481db40311 Auto merge of #95562 - lcnr:attr-no-encode, r=davidtwco
don't encode only locally used attrs

Part of https://github.com/rust-lang/compiler-team/issues/505.

We now filter builtin attributes before encoding them in the crate metadata in case they should only be used in the local crate. To prevent accidental misuse `get_attrs` now requires the caller to state which attribute they are interested in. For places where that isn't trivially possible, I've added a method `fn get_attrs_unchecked` which I intend to remove in a followup PR.

After this pull request landed, we can then slowly move all attributes to only be used in the local crate while being certain that we don't accidentally try to access them from extern crates.

cc https://github.com/rust-lang/rust/pull/94963#issuecomment-1082924289
2022-05-12 12:48:30 +00:00
bors
0cd939e36c Auto merge of #96150 - est31:unused_macro_rules, r=petrochenkov
Implement a lint to warn about unused macro rules

This implements a new lint to warn about unused macro rules (arms/matchers), similar to the `unused_macros` lint added by #41907 that warns about entire macros.

```rust
macro_rules! unused_empty {
    (hello) => { println!("Hello, world!") };
    () => { println!("empty") }; //~ ERROR: 1st rule of macro `unused_empty` is never used
}

fn main() {
    unused_empty!(hello);
}
```

Builds upon #96149 and #96156.

Fixes #73576
2022-05-12 00:08:08 +00:00
lcnr
6c8265dc56 only_local: always check for misuse 2022-05-10 12:07:35 +02:00
bors
574830f573 Auto merge of #96094 - Elliot-Roberts:fix_doctests, r=compiler-errors
Begin fixing all the broken doctests in `compiler/`

Begins to fix #95994.
All of them pass now but 24 of them I've marked with `ignore HELP (<explanation>)` (asking for help) as I'm unsure how to get them to work / if we should leave them as they are.
There are also a few that I marked `ignore` that could maybe be made to work but seem less important.
Each `ignore` has a rough "reason" for ignoring after it parentheses, with

- `(pseudo-rust)` meaning "mostly rust-like but contains foreign syntax"
- `(illustrative)` a somewhat catchall for either a fragment of rust that doesn't stand on its own (like a lone type), or abbreviated rust with ellipses and undeclared types that would get too cluttered if made compile-worthy.
- `(not-rust)` stuff that isn't rust but benefits from the syntax highlighting, like MIR.
- `(internal)` uses `rustc_*` code which would be difficult to make work with the testing setup.

Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run `rg '```ignore \(' .` on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful.

I'm not sure if there was a better existing way to do this but I wrote my own script to help me run all the doctests and wade through the output. If that would be useful to anyone else, I put it here: https://github.com/Elliot-Roberts/rust_doctest_fixing_tool
2022-05-07 06:30:29 +00:00
Gary Guo
b1c6c0648e Permit asm_const and asm_sym to reference outer generic params 2022-05-07 03:32:27 +01:00
Guillaume Gomez
66443a1852
Rollup merge of #96557 - nbdd0121:const, r=oli-obk
Allow inline consts to reference generic params

Tracking issue: #76001

The RFC says that inline consts cannot reference to generic parameters (for now), same as array length expressions. And expresses that it's desirable for it to reference in-scope generics, when array length expressions gain that feature as well.

However it is possible to implement this for inline consts before doing this for all anon consts, because inline consts are only used as values and they won't be used in the type system. So we can have:
```rust
fn foo<T>() {
    let x = [4i32; std::mem::size_of::<T>()];   // NOT ALLOWED (for now)
    let x = const { std::mem::size_of::<T>() }; // ALLOWED with this PR!
    let x = [4i32; const { std::mem::size_of::<T>() }];   // NOT ALLOWED (for now)
}
```

This would make inline consts super useful for compile-time checks and assertions:
```rust
fn assert_zst<T>() {
    const { assert!(std::mem::size_of::<T>() == 0) };
}
```

This would create an error during monomorphization when `assert_zst` is instantiated with non-ZST `T`s. A error during mono might sound scary, but this is exactly what a "desugared" inline const would do:
```rust
fn assert_zst<T>() {
    struct F<T>(T);
    impl<T> F<T> {
        const V: () = assert!(std::mem::size_of::<T>() == 0);
    }
    let _ = F::<T>::V;
}
```

It should also be noted that the current inline const implementation can already reference the type params via type inference, so this resolver-level restriction is not any useful either:
```rust
fn foo<T>() -> usize {
    let (_, size): (PhantomData<T>, usize) = const {
        const fn my_size_of<T>() -> (PhantomData<T>, usize) {
            (PhantomData, std::mem::size_of::<T>())
        }
        my_size_of()
    };
    size
}
```

```@rustbot``` label: F-inline_const
2022-05-06 20:05:37 +02:00
est31
0bd2232fe4 Implement the unused_macro_rules lint 2022-05-05 19:13:00 +02:00
Matthias Krüger
34bf620ac9
Rollup merge of #96507 - TaKO8Ki:suggest-calling-associated-function, r=lcnr
Suggest calling `Self::associated_function()`

closes #96453
2022-05-05 15:43:03 +02:00
Takayuki Maeda
df25189552 suggest calling Self::associated_function()
do not suggest when trait_ref is some

Update compiler/rustc_resolve/src/late/diagnostics.rs

Co-authored-by: lcnr <rust@lcnr.de>

use helper struct

add a test for functions with some params

refactor debug log
2022-05-05 16:44:09 +09:00
Josh Triplett
0fc5c524f5 Stabilize bool::then_some 2022-05-04 13:22:08 +02:00
bors
9add63257b Auto merge of #96353 - estebank:issue-95413, r=compiler-errors
When suggesting to import an item, also suggest changing the path if appropriate

When we don't find an item we search all of them for an appropriate
import and suggest `use`ing it. This is sometimes done for expressions
that have paths with more than one segment. We now also suggest changing
that path to work with the `use`.

Fix #95413
2022-05-04 01:58:23 +00:00
bors
1b2e0b60cc Auto merge of #95380 - compiler-errors:unit-destructure-assign, r=nikomatsakis
Fix unit struct/enum variant in destructuring assignment

See https://github.com/rust-lang/rfcs/blob/master/text/2909-destructuring-assignment.md#guide-level-explanation, "including **unit** and tuple structs"

Fixes #94319
2022-05-03 22:29:58 +00:00
Gary Guo
6baaa527ce Allow inline consts to reference generic params 2022-05-03 15:22:03 +01:00
Yuki Okushi
1e6b880b84
Rollup merge of #96641 - oli-obk:bool_args, r=wesleywiser
Use a yes/no enum instead of a bool.

The bool's meaning wasn't obvious to me at some call sites.
2022-05-03 14:59:01 +09:00
Esteban Kuber
4934a9e643 Tweak wording 2022-05-03 02:07:47 +00:00
Esteban Küber
57967269e9 When suggesting to import an item, also suggest changing the path if appropriate
When we don't find an item we search all of them for an appropriate
import and suggest `use`ing it. This is sometimes done for expressions
that have paths with more than one segment. We now also suggest changing
that path to work with the `use`.

Fix #95413
2022-05-03 02:00:38 +00:00
Elliot Roberts
7907385999 fix most compiler/ doctests 2022-05-02 17:40:30 -07:00
Oli Scherer
0349f8bd79 Use a yes/no enum instead of a bool.
The bool's meaning wasn't obvious to me at some call sites.
2022-05-02 15:39:13 +00:00
bors
879fb42596 Auto merge of #96431 - petrochenkov:parent, r=cjgillot
rustc: Panic by default in `DefIdTree::parent`

Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root.
So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root.

Same applies to `local_parent`/`opt_local_parent`.
2022-05-02 14:03:20 +00:00
Vadim Petrochenkov
5b5964f569 rustc: Panic by default in DefIdTree::parent
Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root.
So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root.

Same applies to `local_parent`/`opt_local_parent`.
2022-05-02 01:56:50 +03:00
bors
4dd8b420c0 Auto merge of #96521 - petrochenkov:docrules, r=notriddle,GuillaumeGomez
rustdoc: Resolve doc links referring to `macro_rules` items

cc https://github.com/rust-lang/rust/issues/81633

UPD: the fallback to considering *all* `macro_rules` in the crate for unresolved names is not removed in this PR, it will be removed separately and will be run through crater.
2022-05-01 20:28:10 +00:00
Vadim Petrochenkov
7841247ca9 resolve: Rename unusable_binding to ignore_binding 2022-05-01 18:02:37 +03:00
Vadim Petrochenkov
f0e0434feb resolve: Merge last_import_segment into Finalize 2022-05-01 18:02:35 +03:00
Vadim Petrochenkov
ffedcec4e8 resolve: Pass full Finalize in nearly all cases 2022-05-01 18:02:01 +03:00
Vadim Petrochenkov
900607f49a resolve: Turn enum Finalize into an optional struct 2022-05-01 17:42:22 +03:00
Vadim Petrochenkov
8b21421873 rustdoc: Track macro_rules scopes during early doc link resolution
This way links referring to `macro_rules` items are resolved correctly
2022-05-01 00:02:15 +03:00
Vadim Petrochenkov
044e45c595 rustdoc: Keep full ParentScope during early doc link resolution 2022-04-30 23:06:48 +03:00
Camille GILLOT
94449e6101 Store all generic bounds as where predicates. 2022-04-30 13:55:13 +02:00
Camille GILLOT
05b29f9a92 Inline WhereClause into Generics. 2022-04-30 13:51:49 +02:00
Camille GILLOT
71b4e2d852 Box HIR Generics and Impl. 2022-04-30 13:51:49 +02:00
bors
76d4862fdd Auto merge of #95776 - cjgillot:ast-lifetimes-static, r=petrochenkov
Enforce static lifetimes in consts during late resolution

This PR moves the handling of implicitly and explicitly static lifetimes in constants from HIR to the AST.
2022-04-30 07:52:18 +00:00
Esteban Kuber
bce5ab2c78 Use newtype enums instead of bool 2022-04-30 02:40:36 +00:00
Esteban Kuber
09f3ea1692 When encountering a binding that could be a const or unit variant, suggest the right path 2022-04-30 02:27:25 +00:00
Camille GILLOT
865d0fef2f Ban non-static lifetimes from AnonConst on AST.
The extra diagnostics come from the compiler no longer aborting before
typeck.
2022-04-30 00:28:42 +02:00
Dylan DPC
2003d833a5
Rollup merge of #96559 - cjgillot:elided-path-fn, r=petrochenkov
Use the correct lifetime binder for elided lifetimes in path.

Fixes https://github.com/rust-lang/rust/issues/96540
2022-04-29 23:54:41 +02:00
Camille GILLOT
6e349c7f07 Remove error variable. 2022-04-29 22:26:22 +02:00
Camille GILLOT
f66de50f8a Use the correct lifetime binder for elided lifetimes in path. 2022-04-29 18:51:21 +02:00
David Wood
73fa217bc1 errors: span_suggestion takes impl ToString
Change `span_suggestion` (and variants) to take `impl ToString` rather
than `String` for the suggested code, as this simplifies the
requirements on the diagnostic derive.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29 02:05:20 +01:00
Camille GILLOT
a87ab48099 Ban non-static in const generics in AST. 2022-04-29 00:02:49 +02:00
bors
81799cd8fd Auto merge of #96495 - Dylan-DPC:rollup-9lm4tpp, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #96377 (make `fn() -> _ { .. }` suggestion MachineApplicable)
 - #96397 (Make EncodeWide implement FusedIterator)
 - #96421 (Less `NoDelim`)
 - #96432 (not need `Option` for `dbg_scope`)
 - #96466 (Better error messages when collecting into `[T; n]`)
 - #96471 (replace let else with `?`)
 - #96483 (Add missing `target_feature` to the list of well known cfg names)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-28 01:37:03 +00:00
Dylan DPC
4c628bbb1c
Rollup merge of #96471 - BoxyUwU:let_else_considered_harmful, r=lcnr
replace let else with `?`

r? `@oli-obk`
2022-04-28 02:40:36 +02:00
bors
c95346b8ac Auto merge of #91557 - cjgillot:ast-lifetimes-named, r=petrochenkov
Perform lifetime resolution on the AST for lowering

Lifetime resolution is currently implemented several times. Once during lowering in order to introduce in-band lifetimes, and once in the resolve_lifetimes query. However, due to the global nature of lifetime resolution and how it interferes with hygiene, it is better suited on the AST.

This PR implements a first draft of lifetime resolution on the AST. For now, we specifically target named lifetimes and everything we need to remove lifetime resolution from lowering. Some diagnostics have already been ported, and sometimes made more precise using available hygiene information. Follow-up PRs will address in particular the resolution of anonymous lifetimes on the AST.

We reuse the rib design of the current resolution framework. Specific `LifetimeRib` and `LifetimeRibKind` types are introduced. The most important variant is `LifetimeRibKind::Generics`, which happens each time we encounter something which may introduce generic lifetime parameters. It can be an item or a `for<...>` binder. The `LifetimeBinderKind` specifies how this rib behaves with respect to in-band lifetimes.

r? `@petrochenkov`
2022-04-27 23:13:28 +00:00
Camille GILLOT
21b6d23890 Collect extra lifetime parameters during late resolution. 2022-04-27 22:03:26 +02:00
Camille GILLOT
f385f856cd Use LifetimeRes during lowering. 2022-04-27 22:00:15 +02:00
Camille GILLOT
69985f0175 Do not resolve elided lifetimes in path twice. 2022-04-27 21:59:47 +02:00