Commit graph

428 commits

Author SHA1 Message Date
Matthias Krüger
efac68b93c
Rollup merge of #89347 - TaKO8Ki:crate-or-module-typo, r=estebank
suggestion for typoed crate or module

Previously, the compiler didn't suggest similarly named crates or modules. This pull request adds a suggestion for typoed crates or modules.

#76208

before:

```
error[E0433]: failed to resolve: use of undeclared type or module `chono`
 --> src/main.rs:2:5
  |
2 | use chono::prelude::*;
  |     ^^^^^ use of undeclared type or module `chono`
```

after:

```
error[E0433]: failed to resolve: use of undeclared type or module `chono`
 --> src/main.rs:2:5
  |
2 | use chono::prelude::*;
  |     ^^^^^
  |     |
  |     use of undeclared crate or module `chono`
  |     help: a similar crate or module exists: `chrono`
```
2021-10-13 22:51:00 +02:00
Takayuki Maeda
f819e6d59c suggestion for typoed crate or module
avoid suggesting the same name

sort candidates

fix a message

use `opt_def_id` instead of `def_id`

move `find_similarly_named_module_or_crate` to rustc_resolve/src/diagnostics.rs
2021-10-13 12:17:02 +09:00
klensy
77fce75ba1 remove unwrap_or! macro 2021-10-08 19:32:16 +03:00
bors
55111d656f Auto merge of #89266 - cjgillot:session-ich, r=michaelwoerister
Move ICH to rustc_query_system

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

The StableHashingContext does not need to be in rustc_middle.

This PR moves it to rustc_query_system. This will avoid a dependency between rustc_ast_lowering and rustc_middle in https://github.com/rust-lang/rust/pull/89124.
2021-10-05 09:45:11 +00:00
Camille GILLOT
8961616e60 Move rustc_middle::middle::cstore to rustc_session. 2021-10-03 16:08:51 +02:00
Hirochika Matsumoto
3818981ca1 Practice diagnostic message convention 2021-10-03 16:16:28 +09:00
Vadim Petrochenkov
ded08e44c6 resolve: Avoid comparing modules by optional def-id
It makes all block modules identical during comparison
2021-10-02 18:31:50 +03:00
Vadim Petrochenkov
5aa732a364 resolve: Cache module loading for all foreign modules
It was previously cached for modules loaded from `fn get_module`, but not for modules loaded from `fn build_reduced_graph_for_external_crate_res`.
This also makes all foreign modules use their real parent, span and expansion instead of possibly a parent/span/expansion of their reexport.

An ICE happening on attempt to decode expansions for foreign enums and traits is avoided.

Also local enums and traits are now added to the module map.
2021-10-02 18:31:42 +03:00
bors
69eb996b26 Auto merge of #89417 - Manishearth:rollup-j2gdu95, r=Manishearth
Rollup of 7 pull requests

Successful merges:

 - #88838 (Do not suggest importing inaccessible items)
 - #89251 (Detect when negative literal indices are used and suggest appropriate code)
 - #89321 (Rebase resume argument projections during state transform)
 - #89327 (Pick one possible lifetime in case there are multiple choices)
 - #89344 (Cleanup lower_generics_mut and make span be the bound itself)
 - #89397 (Update `llvm` submodule to fix function name mangling on x86 Windows)
 - #89412 (Add regression test for issues #88969 and #89119 )

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-01 09:00:42 +00:00
Manish Goregaokar
746e46548c
Rollup merge of #89344 - jackh726:maybe-bound-eror, r=cjgillot
Cleanup lower_generics_mut and make span be the bound itself

Closes #86298 (supersedes those changes)

r? `@cjgillot` since you reviewed the other PR

(Used wrong branch for #89338)
2021-09-30 23:41:09 -07:00
Manish Goregaokar
9593e61f64
Rollup merge of #88838 - FabianWolff:issue-88472, r=estebank
Do not suggest importing inaccessible items

Fixes #88472. For this example:
```rust
mod a {
    struct Foo;
}

mod b {
    type Bar = Foo;
}
```
rustc currently emits:
```
error[E0412]: cannot find type `Foo` in this scope
 --> test.rs:6:16
  |
6 |     type Bar = Foo;
  |                ^^^ not found in this scope
  |
help: consider importing this struct
  |
6 |     use a::Foo;
  |
```
this is incorrect, as applying this suggestion leads to
```
error[E0603]: struct `Foo` is private
 --> test.rs:6:12
  |
6 |     use a::Foo;
  |            ^^^ private struct
  |
note: the struct `Foo` is defined here
 --> test.rs:2:5
  |
2 |     struct Foo;
  |     ^^^^^^^^^^^
```
With my changes, I get:
```
error[E0412]: cannot find type `Foo` in this scope
 --> test.rs:6:16
  |
6 |     type Bar = Foo;
  |                ^^^ not found in this scope
  |
  = note: this struct exists but is inaccessible:
          a::Foo
```
As for the wildcard mentioned in #88472, I would argue that the warning is actually correct, since the import _is_ unused. I think the real issue is the wrong suggestion, which I have fixed here.
2021-09-30 23:41:05 -07:00
bors
4e4942dfa6 Auto merge of #89395 - In-line:remove_visible_path_from_allowed_deprecated_lint, r=jyn514
Remove visible path calculation from allowed deprecation lint
2021-10-01 06:19:52 +00:00
Manish Goregaokar
837ac87709
Rollup merge of #89248 - hkmatsumoto:suggest-similarly-named-assoc-items, r=estebank
Suggest similarly named associated items in trait impls

Fix #85942

Previously, the compiler didn't suggest similarly named associated items unlike we do in many situations. This patch adds such diagnostics for associated functions, types, and constants.
2021-09-30 18:05:22 -07:00
Alik Aslanyan
d98ac573a4
Remove visible path calculation from allowed deprecation lint 2021-09-30 15:15:10 +04:00
jackh726
e1a9ecca26 Cleanup lower_generics_mut and make span be the bound itself, not the type 2021-09-29 13:31:03 -04:00
Hirochika Matsumoto
cef736f8a0 Suggest similarly named assoc items in trait impls
Previously, the compiler didn't suggest similarly named associated items
unlike we do in many situations. This patch adds such diagnostics for
associated functions, types and constants.
2021-09-29 00:22:32 +09:00
Oli Scherer
9b5aa063d8 More tracing instrumentation 2021-09-28 12:28:22 +00:00
Takayuki Maeda
564cb87e27 suggest path for tuple struct 2021-09-27 16:28:38 +09:00
Fabian Wolff
750018e16e Improve diagnostics for inaccessible items 2021-09-26 19:22:20 +02:00
Fabian Wolff
65eb381dec Do not suggest importing inaccessible items 2021-09-26 18:43:58 +02:00
Manish Goregaokar
04d3f93a2b
Rollup merge of #89224 - TaKO8Ki:change-the-order-of-suggestions, r=joshtriplett
Change the order of imports suggestions

closes #83564
2021-09-25 18:22:21 -07:00
bors
60fe8b3a65 Auto merge of #87220 - petrochenkov:derivecfglimit2, r=Aaron1011
Make `#[derive(A, B, ...)]` cfg-eval its input only for `A, B, ...` and stabilize `feature(macro_attributes_in_derive_output)`

Stabilization report: https://github.com/rust-lang/rust/pull/87220#issuecomment-881923657

Closes #81119
r? `@Aaron1011`
2021-09-25 04:35:59 +00:00
Takayuki Maeda
4c23905515 use drain_filter instead of filter and retain 2021-09-25 11:33:53 +09:00
Vadim Petrochenkov
85f02901a3 Stabilize feature(macro_attributes_in_derive_output) 2021-09-24 21:48:30 +03:00
Vadim Petrochenkov
ab834e5ea9 resolve: Refactor obtaining Module from its DefId
The `Option<Module>` version is supported for the case where we don't know whether the `DefId` refers to a module or not.
Non-local traits and enums are also correctly found now.
2021-09-24 18:57:15 +03:00
Vadim Petrochenkov
a8021888c8 resolve: Use a single common map for local and foreign modules 2021-09-24 18:57:15 +03:00
Vadim Petrochenkov
1a23858983 resolve: Rename some expansion def scope methods 2021-09-24 18:57:15 +03:00
Vadim Petrochenkov
6e9adcbd82 resolve: Cleanup module allocation
Construction of all modules is now centralized and performed by `fn new_module`.
2021-09-24 18:57:15 +03:00
Vadim Petrochenkov
fd58eea4e1 resolve: Do not cache nearest parent mod in ModuleData 2021-09-24 18:57:14 +03:00
Takayuki Maeda
353d6373ff change the order of path suggestions 2021-09-25 00:22:59 +09:00
bors
d8d1d1059a Auto merge of #89158 - the8472:rollup-3e4ijth, r=the8472
Rollup of 12 pull requests

Successful merges:

 - #88795 (Print a note if a character literal contains a variation selector)
 - #89015 (core::ascii::escape_default: reduce struct size)
 - #89078 (Cleanup: Remove needless reference in ParentHirIterator)
 - #89086 (Stabilize `Iterator::map_while`)
 - #89096 ([bootstrap] Improve the error message when `ninja` is not found to link to installation instructions)
 - #89113 (dont `.ensure()` the `thir_abstract_const` query call in `mir_build`)
 - #89114 (Fixes a technicality regarding the size of C's `char` type)
 - #89115 (⬆️ rust-analyzer)
 - #89126 (Fix ICE when `indirect_structural_match` is allowed)
 - #89141 (Impl `Error` for `FromSecsError` without foreign type)
 - #89142 (Fix match for placeholder region)
 - #89147 (add case for checking const refs in check_const_value_eq)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-09-21 22:07:32 +00:00
the8472
9f50c87267
Rollup merge of #89078 - camsteffen:map-ref, r=cjgillot
Cleanup: Remove needless reference in ParentHirIterator

It forces an intermediate binding of `Map` which is a Copy type.
2021-09-21 22:54:00 +02:00
Mark Rousskov
c746be2219 Migrate to 2021 2021-09-20 22:21:42 -04:00
Yuki Okushi
ba1a90a417
Rollup merge of #88966 - tmiasko:block-label-shadowing, r=petrochenkov
Check for shadowing issues involving block labels
2021-09-19 17:31:30 +09:00
Cameron Steffen
7c8f4f7eab Remove needless hir Map ref 2021-09-18 15:55:34 -05:00
bors
23afad6e7f Auto merge of #88650 - sapessi:issue-77175-fix, r=estebank
Skip single use lifetime lint for generated opaque types

Fix: #77175

The opaque type generated by the desugaring process of an async function uses the lifetimes defined by the originating function. The DefId for the lifetimes in the opaque type are different from the ones in the originating async function - as they should be, as far as I understand, and could therefore be considered a single use lifetimes, this causes the single_use_lifetimes lint to fail compilation if explicitly denied. This fix skips the lint for lifetimes used only once in generated opaque types for an async function that are declared in the parent async function definition.

More info in the comments on the original issue: 1 and 2
2021-09-18 11:56:23 +00:00
Tomasz Miąsko
ffdabc8be8 Check for shadowing issues involving block labels 2021-09-15 15:42:15 +02:00
bors
9bb77da74d Auto merge of #87915 - estebank:fancy-spans, r=oli-obk
Use smaller spans for some structured suggestions

Use more accurate suggestion spans for

* argument parse error
* fully qualified path
* missing code block type
* numeric casts
2021-09-13 16:31:12 +00:00
Manish Goregaokar
bb5ca58d29
Rollup merge of #88677 - petrochenkov:exportid, r=davidtwco
rustc: Remove local variable IDs from `Export`s

Local variables can never be exported.
2021-09-12 03:44:53 -07:00
bors
547d9374d2 Auto merge of #84373 - cjgillot:resolve-span, r=michaelwoerister,petrochenkov
Encode spans relative to the enclosing item

The aim of this PR is to avoid recomputing queries when code is moved without modification.

MCP at https://github.com/rust-lang/compiler-team/issues/443

This is achieved by :
1. storing the HIR owner LocalDefId information inside the span;
2. encoding and decoding spans relative to the enclosing item in the incremental on-disk cache;
3. marking a dependency to the `source_span(LocalDefId)` query when we translate a span from the short (`Span`) representation to its explicit (`SpanData`) representation.

Since all client code uses `Span`, step 3 ensures that all manipulations
of span byte positions actually create the dependency edge between
the caller and the `source_span(LocalDefId)`.
This query return the actual absolute span of the parent item.
As a consequence, any source code motion that changes the absolute byte position of a node will either:
- modify the distance to the parent's beginning, so change the relative span's hash;
- dirty `source_span`, and trigger the incremental recomputation of all code that
  depends on the span's absolute byte position.

With this scheme, I believe the dependency tracking to be accurate.

For the moment, the spans are marked during lowering.
I'd rather do this during def-collection,
but the AST MutVisitor is not practical enough just yet.
The only difference is that we attach macro-expanded spans
to their expansion point instead of the macro itself.
2021-09-11 23:35:28 +00:00
Matthias Krüger
c1e96085d3 don't clone types that are Copy (clippy::clone_on_copy) 2021-09-11 10:18:56 +02:00
Vadim Petrochenkov
294510e1bb rustc: Remove local variable IDs from Exports
Local variables can never be exported.
2021-09-10 23:41:48 +03:00
Camille GILLOT
2e37ed87fc Record call_site parent for macros. 2021-09-10 20:19:25 +02:00
Camille GILLOT
e85ddeb474 Encode spans relative to their parent. 2021-09-10 20:18:11 +02:00
Camille GILLOT
00485e0c0e Keep a parent LocalDefId in SpanData. 2021-09-10 20:17:33 +02:00
Camille GILLOT
06f7ca307d Keep def_spans collected by resolution. 2021-09-10 20:17:08 +02:00
Aaron Hill
404402430d
Move confused_type_with_std_module to ResolverOutputs
This eliminates untracked global state from `Session`.
2021-09-06 11:20:59 -05:00
Stefano Buliani
82f1f50335 Skip single use lifetime lint for generated opaque types
As reported in issue #77175, the opaque type generated by the desugaring process of an async function uses the lifetimes defined by the originating function. The definition ID for the lifetimes in the opaque method is different from the one in the originating async function and it could therefore be considered a single use of the lifetimne, this causes the single_use_lifetimes lint to fail compilation if explicitly denied. This fix skips the lint for lifetimes used only once in generated opaque types for an async function that are declared in the parent async function definition.
2021-09-04 11:47:52 -07:00
bors
b4e8596e3e Auto merge of #88598 - estebank:type-ascription-can-die-in-a-fire, r=wesleywiser
Detect bare blocks with type ascription that were meant to be a `struct` literal

Address part of #34255.

Potential improvement: silence the other knock down errors in `issue-34255-1.rs`.
2021-09-04 01:40:36 +00:00
bors
577a76f003 Auto merge of #88597 - cjgillot:lower-global, r=petrochenkov
Move global analyses from lowering to resolution

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

r? `@petrochenkov`
2021-09-03 14:47:13 +00:00