Commit Graph

1062 Commits

Author SHA1 Message Date
Nicholas Nethercote
67d5cc0462 Use ThinVec in ast::Path. 2022-11-17 13:56:38 +11:00
Nicholas Nethercote
6b7ca2fcf2 Box ExprKind::{Closure,MethodCall}, and QSelf in expressions, types, and patterns. 2022-11-17 13:45:59 +11:00
Matthias Krüger
dc869fcfb2
Rollup merge of #104364 - petrochenkov:docice2, r=GuillaumeGomez
rustdoc: Resolve doc links in external traits having local impls

For external impls it was done in https://github.com/rust-lang/rust/pull/103192 right away, but the local impl case was forgotten.

Fixes https://github.com/rust-lang/rust/issues/104145.
2022-11-14 19:26:19 +01:00
Matthias Krüger
5763fa74f0
Rollup merge of #104349 - rustaceanclub:master, r=oli-obk
fix some typos in comments
2022-11-14 19:26:18 +01:00
Matthias Krüger
5c764da9b0
Rollup merge of #104315 - SparkyPotato:fix-104276, r=cjgillot
Improve spans with `use crate::{self}`

Fixes #104276.

The error becomes:
```
error: crate root imports need to be explicitly named: `use crate as name;`
 --> src/lib.rs.rs:1:13
  |
1 | use crate::{self};
  |             ^^^^

warning: unused import: `self`
 --> src/lib.rs:1:13
  |
1 | use crate::{self};
  |             ^^^^
  |
  = note: `#[warn(unused_imports)]` on by default
```
2022-11-13 17:37:37 +01:00
Vadim Petrochenkov
8e81cc262e rustdoc: Resolve doc links in external traits having local impls 2022-11-13 17:20:24 +03:00
SparkyPotato
c7b2891315 move span to self instead of crate 2022-11-13 13:46:11 +05:30
cui fliter
442f848d74 fix some typos in comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2022-11-13 15:26:17 +08:00
Dylan DPC
fcbe990093
Rollup merge of #103970 - oli-obk:unhide_unknown_spans, r=estebank
Unhide unknown spans

r? ```@estebank```
2022-11-12 12:02:51 +05:30
Dylan DPC
4b0b89827d
Rollup merge of #102049 - fee1-dead-contrib:derive_const, r=oli-obk
Add the `#[derive_const]` attribute

Closes #102371. This is a minimal patchset for the attribute to work. There are no restrictions on what traits this attribute applies to.

r? `````@oli-obk`````
2022-11-12 12:02:50 +05:30
Manish Goregaokar
f00897e2f4
Rollup merge of #103531 - chenyukang:yukang/fix-103474, r=estebank
Suggest calling the instance method of the same name when method not found

Fixes #103474
2022-11-11 12:12:30 -05:00
Oli Scherer
df2adc4760 Print all labels, even if they have no span. Fall back to main item's span. 2022-11-11 14:45:28 +00:00
Manish Goregaokar
819c9315c3
Rollup merge of #104186 - chenyukang:yukang/fix-104086-let-binding-issue, r=oli-obk
Tighten the 'introduce new binding' suggestion

Fixes #104086
2022-11-10 10:47:40 -05:00
Michael Goulet
e807cb3c41 Make span_suggestions take IntoIterator 2022-11-09 19:42:23 +00:00
Michael Goulet
fbce7decd8 DiagnosticBuilder -> Diagnostic 2022-11-09 19:42:23 +00:00
yukang
c69872bb6c add 'is_assign_rhs' to avoid weird suggesting 'let' 2022-11-10 00:43:12 +08:00
yukang
5689f9c679 fix tests and code cleanup 2022-11-09 17:10:33 +08:00
yukang
952df48948 Fix #104086, Tighten the 'introduce new binding' suggestion 2022-11-09 16:46:13 +08:00
bors
c5842b0be7 Auto merge of #103965 - petrochenkov:effvisperf3, r=oli-obk
resolve: More detailed effective visibility tracking for imports

Per-`DefId` tracking is not enough, due to glob imports in particular, which have a single `DefId` for the whole glob import item.
We need to track this stuff per every introduced name (`NameBinding`).

Also drop `extern` blocks from the effective visibility table, they are nominally private and it doesn't make sense to keep them there.

Later commits add some debug-only invariant checking and optimiaztions to mitigate regressions in https://github.com/rust-lang/rust/pull/103965#issuecomment-1304256445.

This is a bugfix and continuation of https://github.com/rust-lang/rust/pull/102026.
2022-11-08 14:37:40 +00:00
Matthias Krüger
51287f264c
Rollup merge of #103927 - fee1-dead-contrib:E0425-no-typo-when-pattern-matching, r=cjgillot
Do not make typo suggestions when suggesting pattern matching

Fixes #103909.
2022-11-05 18:06:06 +01:00
Deadbeef
b1994ce806 Do not make typo suggestions when suggesting pattern matching
Fixes #103909.
2022-11-05 15:33:25 +00:00
Vadim Petrochenkov
43bea6cf69 resolve: Fill effective visibilities for import def ids in a separate pass
This should result in less update calls than doing it repeatedly during the fix point iteration.
2022-11-05 17:55:20 +04:00
Vadim Petrochenkov
24093fc6bd resolve: More detailed effective visibility tracking for imports
Also drop `extern` blocks from the effective visibility table, they are nominally private and it doesn't make sense to keep them there.
2022-11-05 15:46:22 +04:00
Matthias Krüger
1edd63f1e7
Rollup merge of #103953 - TaKO8Ki:remove-unused-arg-from-throw_unresolved_import_error, r=oli-obk
Remove unused argument from `throw_unresolved_import_error`

`throw_unresolved_import_error` does not need the second argument.
2022-11-04 12:18:03 +01:00
Takayuki Maeda
97ddc6343a remove unused argument from throw_unresolved_import_error 2022-11-04 13:59:04 +09:00
Dylan DPC
68afa32985
Rollup merge of #103760 - petrochenkov:macimp, r=cjgillot
resolve: Turn the binding from `#[macro_export]` into a proper `Import`

Continuation of https://github.com/rust-lang/rust/pull/91795.

```rust
#[macro_export]
macro_rules! m { /*...*/ }
```
is desugared to something like
```rust
macro_rules! m { /*...*/ } // Non-modularized macro_rules item

pub use m; // It's modularized reexport
```

This PR adjusts the internal representation to better match this model.
2022-11-01 22:01:36 +05:30
Dylan DPC
9f603feaee
Rollup merge of #84022 - Aaron1011:remove-derive-res-fallback, r=petrochenkov
Make PROC_MACRO_DERIVE_RESOLUTION_FALLBACK a hard error

r? `@ghost`
2022-11-01 22:01:35 +05:30
Dylan DPC
7dc3ace6a9
Rollup merge of #103706 - zbyrn:issue-101637-fix, r=estebank
Fix E0433 No Typo Suggestions

Fixes #48676
Fixes #87791
Fixes #96625
Fixes #95462
Fixes #101637
Follows up PR #72923

Several open issues refer to the problem that E0433 does not suggest typos like other errors normally do. This fix augments the implementation of PR #72923.

**Background**
When the path of a function call, e.g. `Struct::foo()`, involves names that cannot be resolved, there are two errors that could be emitted by the compiler:
 - If `Struct` is not found, it is ``E0433: failed to resolve: use of undeclared type `Struct` ``.
 - If `foo` is not found in `Struct`, it is ``E0599: no function or associated item named `foo` found for struct `Struct` in the current scope``

When a name is used as a type, `e.g. fn foo() -> Struct`, and the name cannot be resolved, it is ``E0412: cannot find type `Struct` in this scope``.

Before #72923, `E0433` does not implement any suggestions, and the PR introduces suggestions for missing `use`s. When a resolution error occurs in the path of a function call, it tries to smart resolve just the type part of the path, e.g. `module::Struct` of a call to `module::Struct::foo()`. However, along with the suggestions, the smart-resolve function will report `E0412` since it only knows that it is a type that we cannot resolve instead of being a part of the path. So, the original implementation swap out `E0412` errors returned by the smart-resolve function with the real `E0433` error, but keeps the "missing `use`" suggestions to be reported to the programmer.

**Issue**
The current implementation only reports if there are "missing `use`" suggestions returned by the smart-resolve function; otherwise, it would fall back the normal reporting, which does not emit suggestions. But the smart-resolve function could also produce typo suggestions, which are omitted currently.

Also, it seems like that not all info has been swapped out when there are missing suggestions. The error message underlining the name in the snippet still says ``not found in this scope``, which is a `E0412` messages, if there are `use` suggestions, but says the normal `use of undeclared type` otherwise.

**Fixes**
This fix swaps out all fields in `Diagnostic` returned by the smart-resolve function except for `suggestions` with the current error, and merges the `suggestions` of the returned error and that of the current error together. If there are `use` suggestions, the error is saved to `use_injection` to be reported at the end; otherwise, the error is emitted immediately as `Resolver::report_error` does.

Some tests are updated to use the correct underlining error messages, and one additional test for typo suggestion is added to the test suite.

r? rust-lang/diagnostics
2022-11-01 14:12:26 +05:30
Vadim Petrochenkov
84317518ff resolve: Turn the binding from #[macro_export] into a proper Import 2022-10-31 21:25:00 +04:00
Vadim Petrochenkov
637bfe68a1 resolve: Not all imports have their own NodeId 2022-10-31 20:25:27 +04:00
Dylan DPC
3143472863
Rollup merge of #103560 - zbyrn:issue-103358-fix, r=cjgillot
Point only to the identifiers in the typo suggestions of shadowed names instead of the entire struct

Fixes #103358.

As discussed in the issue, the `Span` of the candidate `Ident` for a typo replacement is stored alongside its `Symbol` in `TypoSuggestion`. Then, the span of the identifier is what the "you might have meant to refer to" note is pointed at, rather than the entire struct definition.

Comments in #103111 and the issue both suggest that it is desirable to:
1. include names defined in the same crate as the typo,
2. ignore names defined elsewhere such as in `std`, _and_
3. include names introduced indirectly via `use`.

Since a name from another crate but introduced via `use` has non-local `def_id`, to achieve this, a suggestion is displayed if either the `def_id` of the suggested name is local, or the `span` of the suggested name is in the same file as the typo itself.

Some UI tests have also been modified to reflect this change.

r? `@cjgillot`
2022-10-30 11:50:26 +05:30
Matthias Krüger
2bff9e2193
Rollup merge of #103726 - TaKO8Ki:avoid-&str-to-string-conversions, r=compiler-errors
Avoid unnecessary `&str` to `String` conversions
2022-10-30 00:09:26 +02:00
bors
5e97720429 Auto merge of #103450 - cjgillot:elision-nodedup, r=Mark-Simulacrum
Do not consider repeated lifetime params for elision.

Fixes https://github.com/rust-lang/rust/issues/103330
2022-10-29 17:32:45 +00:00
Takayuki Maeda
a3a3f4d840 avoid unnecessary &str to String conversions 2022-10-29 17:14:44 +09:00
Camille GILLOT
cb1e7d9676 Only ban duplication across parameters. 2022-10-27 19:04:48 +00:00
Byron Zhong
20a8427a11 Remove redundant braces 2022-10-27 01:41:24 -05:00
Byron Zhong
c0472a5450 Fix E0433 diagnostics ignoring typo suggestions and outputing wrong message 2022-10-27 00:49:39 -05:00
Vadim Petrochenkov
34eb73c72d privacy: Rename "accessibility levels" to "effective visibilities"
And a couple of other naming tweaks

Related to https://github.com/rust-lang/rust/issues/48054
2022-10-26 16:34:53 +04:00
Dylan DPC
c956351f97
Rollup merge of #103520 - petrochenkov:resout, r=cjgillot
rustc_middle: Rearrange resolver outputs structures slightly

Addresses https://github.com/rust-lang/rust/pull/98106#discussion_r898427061.
I also haven't seen the motivation for moving `cstore` from its old place, so I moved it back in this PR.
r? ```@cjgillot```
2022-10-26 11:29:56 +05:30
Byron Zhong
775328c290 Modify check to output 'you might have meant' for indirect reference 2022-10-25 22:08:41 -05:00
Byron Zhong
0b936d2da7 Add check to only output 'you might have meant' when the candidate name is in the same crate 2022-10-25 22:08:41 -05:00
Byron Zhong
be61f0237b Add Span in TypoSuggestion and TypoCandidate 2022-10-25 22:08:41 -05:00
bors
a5406feb1c Auto merge of #103158 - Bryanskiy:resolve_perf, r=petrochenkov
Perf improvements for effective visibility calculating

related to https://github.com/rust-lang/rust/pull/102026
r? `@petrochenkov`
2022-10-26 02:30:18 +00:00
yukang
32a2f0dddb suggest calling the method of the same name when method not found 2022-10-26 00:45:29 +08:00
Bryanskiy
a9447bb9d0 Perf improvements for effective visibility calculating 2022-10-25 15:15:18 +03:00
Vadim Petrochenkov
919673ea03 rustc_middle: Rearrange resolver outputs structures slightly 2022-10-25 15:42:29 +04:00
Yuki Okushi
e47d222a94
Rollup merge of #103350 - clubby789:refer-to-assoc-method, r=wesleywiser
Change terminology for assoc method suggestions when they are not called

Fixes #103325

```@rustbot``` label +A-diagnostics
2022-10-25 08:01:27 +09:00
Aaron Hill
7d82cadd97
Make PROC_MACRO_DERIVE_RESOLUTION_FALLBACK a hard error 2022-10-24 13:40:07 -05:00
Michael Howell
3df030d441
Rollup merge of #103140 - chenyukang:yukang/fix-103112, r=estebank
Add diagnostic for calling a function with the same name with unresolved Macro

Fixes #103112
2022-10-23 14:48:15 -07:00
Camille GILLOT
47704bbcc0 Do not consider repeated lifetime params for elision. 2022-10-23 19:36:19 +00:00