Commit Graph

1460 Commits

Author SHA1 Message Date
bohan
078b942fef fix: not insert missing lifetime for ConstParamTy 2023-08-08 14:48:17 +08:00
Matthias Krüger
3cd0a109a8
Rollup merge of #114566 - fmease:type-alias-laziness-is-crate-specific, r=oli-obk
Store the laziness of type aliases in their `DefKind`

Previously, we would treat paths referring to type aliases as *lazy* type aliases if the current crate had lazy type aliases enabled independently of whether the crate which the alias was defined in had the feature enabled or not.

With this PR, the laziness of a type alias depends on the crate it is defined in. This generally makes more sense to me especially if / once lazy type aliases become the default in a new edition and we need to think about *edition interoperability*:

Consider the hypothetical case where the dependency crate has an older edition (and thus eager type aliases), it exports a type alias with bounds & a where-clause (which are void but technically valid), the dependent crate has the latest edition (and thus lazy type aliases) and it uses that type alias. Arguably, the bounds should *not* be checked since at any time, the dependency crate should be allowed to change the bounds at will with a *non*-major version bump & without negatively affecting downstream crates.

As for the reverse case (dependency: lazy type aliases, dependent: eager type aliases), I guess it rules out anything from slight confusion to mild annoyance from upstream crate authors that would be caused by the compiler ignoring the bounds of their type aliases in downstream crates with older editions.

---

This fixes #114468 since before, my assumption that the type alias associated with a given weak projection was lazy (and therefore had its variances computed) did not necessarily hold in cross-crate scenarios (which [I kinda had a hunch about](https://github.com/rust-lang/rust/pull/114253#discussion_r1278608099)) as outlined above. Now it does hold.

`@rustbot` label F-lazy_type_alias
r? `@oli-obk`
2023-08-08 03:30:56 +02:00
León Orell Valerian Liehr
5468336d6b
Store the laziness of type aliases in the DefKind 2023-08-07 15:54:31 +02:00
Matthias Krüger
d804b74c6c
Rollup merge of #114549 - chenyukang:yukang-review-resolve-part, r=petrochenkov
Style fix and refactor on resolve diagnostics

- coding style
- refactor api of `span_look_ahead`
2023-08-07 05:29:13 +02:00
yukang
eb0fcc5ad1 refactor on span_look_ahead 2023-08-06 22:44:11 +08:00
bors
bc720ad36b Auto merge of #114487 - compiler-errors:opaques-refactoring-idk, r=cjgillot
Consolidate opaque ty and async fn lowering code

The codepaths for lowering "regular" opaques and async fn were almost identical, modulo some bookkeeping that seemed pretty easy to consolidate.

r? `@cjgillot`
2023-08-06 11:16:31 +00:00
Matthias Krüger
83d84ffdd5
Rollup merge of #114503 - chenyukang:yukang-fix-114433-unused-qualifications, r=compiler-errors
Remove invalid lint when there is a generic argument in prefix path

Fixes #114433
2023-08-06 03:56:09 +02:00
Michael Goulet
169236ec8a a function is just another AnonymousCreateParameter rib 2023-08-05 16:53:13 +00:00
Michael Goulet
57a96893f6 Consolidate opaque ty and async fn lowering code 2023-08-05 16:53:13 +00:00
bors
28b6607b5f Auto merge of #109348 - cjgillot:issue-109146, r=petrochenkov
Resolve visibility paths as modules not as types.

Asking for a resolution with `opt_ns = Some(TypeNS)` allows path resolution to look for type-relative paths, leaving unresolved segments behind. However, for visibility paths we really need to look for a module, so we need to pass `opt_ns = None`.

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

r? `@petrochenkov`
2023-08-05 11:52:07 +00:00
yukang
c9be1a71b6 Remove invalid lint when there is a generic argument in prefix path 2023-08-05 15:58:26 +08:00
Matthias Krüger
99e4127d85
Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31
Improve spans for indexing expressions

fixes #114388

Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR.

r? compiler-errors
2023-08-04 21:31:57 +02:00
Nilstrieb
5706be1854 Improve spans for indexing expressions
Indexing is similar to method calls in having an arbitrary
left-hand-side and then something on the right, which is the main part
of the expression. Method calls already have a span for that right part,
but indexing does not. This means that long method chains that use
indexing have really bad spans, especially when the indexing panics and
that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an
extra span which is then put into the `fn_span` field in THIR.
2023-08-04 13:17:39 +02:00
Nilstrieb
5830ca216d Add internal_features lint
It lints against features that are inteded to be internal to the
compiler and standard library. Implements MCP #596.

We allow `internal_features` in the standard library and compiler as those
use many features and this _is_ the standard library from the "internal to the compiler and
standard library" after all.

Marking some features as internal wasn't exactly the most scientific approach, I just marked some
mostly obvious features. While there is a categorization in the macro,
it's not very well upheld (should probably be fixed in another PR).

We always pass `-Ainternal_features` in the testsuite
About 400 UI tests and several other tests use internal features.
Instead of throwing the attribute on each one, just always allow them.
There's nothing wrong with testing internal features^^
2023-08-03 14:50:50 +02:00
Camille GILLOT
2faa2626cc Resolve visibility paths as modules not as types. 2023-08-02 15:30:24 +00:00
yukang
026c4b6a65 trivial style fix 2023-08-02 09:56:02 +08:00
Matthias Krüger
2de51cce90
Rollup merge of #113920 - bvanjoi:fix-81413, r=petrochenkov
fix(resolve): report unresolved imports firstly

Fixes #81413

An easy fix, r? ```@petrochenkov```
2023-07-31 22:49:50 +02:00
Matthias Krüger
3ce90b1649 inline format!() args up to and including rustc_codegen_llvm 2023-07-30 14:22:50 +02:00
bors
2dc661037d Auto merge of #113099 - bvanjoi:fix-112713-2, r=petrochenkov
fix(resolve): update the ambiguity glob binding as warning recursively

Fixes #47525
Fixes #56593, but `issue-56593-2.rs` is not fixed to ensure backward compatibility.
Fixes #98467
Fixes #105235
Fixes #112713

This PR had added a field called `warn_ambiguous` in `NameBinding` which is only for back compatibly reason and used for lint.

More details: https://github.com/rust-lang/rust/pull/112743

r? `@petrochenkov`
2023-07-29 06:04:41 +00:00
León Orell Valerian Liehr
da17134be0
Resolve generic const items 2023-07-28 22:21:41 +02:00
bohan
cac0bd0bef fix(resolve): update the ambiguity glob binding as warning recursively 2023-07-29 00:19:50 +08:00
bohan
1b18e2a176 fix(resolve): report unresolved imports firstly 2023-07-29 00:14:38 +08:00
Georg Semmler
5b576665e5
Introduce the #[diagnostic] attribute namespace
Co-authored-by: est31 <est31@users.noreply.github.com>

Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>

Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
2023-07-28 13:28:02 +02:00
bors
5b1dc9de77 Auto merge of #113980 - bvanjoi:fix-113953, r=petrochenkov
fix(resolve): skip panic when resolution is dummy

Fixes #113953

Skip the panic when the binding refers to a dummy node during the finalization.

r? `@petrochenkov`
2023-07-25 05:25:11 +00:00
bors
beef07fe8f Auto merge of #113958 - lukas-code:doc-links, r=GuillaumeGomez,petrochenkov
fix intra-doc links on nested `use` and `extern crate` items

This PR fixes two rustdoc ICEs that happen if there are any intra-doc links on nested `use` or `extern crate` items, for example:
```rust
/// Re-export [`fmt`] and [`io`].
pub use std::{fmt, io}; // "nested" use = use with braces

/// Re-export [`std`].
pub extern crate std;
```

Nested use items were incorrectly considered private and therefore didn't have their intra-doc links resolved. I fixed this by always resolving intra-doc links for nested `use` items that are declared `pub`.

<details>

During AST->HIR lowering, nested `use` items are desugared like this:
```rust
pub use std::{}; // "list stem"
pub use std::fmt;
pub use std::io;
```
Each of these HIR nodes has it's own effective visibility and the list stem is always considered private.
To check the effective visibility of an AST node, the AST node is mapped to a HIR node with `Resolver::local_def_id`, which returns the (private) list stem for nested use items.

</details>

For `extern crate`, there was a hack in rustdoc that stored the `DefId` of the crate itself in the cleaned item, instead of the `DefId` of the `extern crate` item. This made rustdoc look at the resolved links of the extern crate's crate root instead of the `extern crate` item. I've removed this hack and instead translate the `DefId` in the appropriate places.

As as side effect of fixing `extern crate`, i've turned
```rust
#[doc(masked)]
extern crate self as _;
```
into a no-op instead of hiding all trait impls. Proper verification for `doc(masked)` is included as a bonus.

fixes https://github.com/rust-lang/rust/issues/113896
2023-07-25 01:35:53 +00:00
bohan
4cc3834a5c resolve: ensure compile failed when has dummy or ambiguous 2023-07-25 01:57:12 +08:00
bohan
02f1f6a8a8 fix(resolve): skip panic when resolution is dummy 2023-07-25 01:34:03 +08:00
Matthias Krüger
b594798ae3 fix clippy::useless_format 2023-07-23 11:14:52 +02:00
León Orell Valerian Liehr
2a75a0f724
Use features() over features_untracked() where possible 2023-07-22 20:09:40 +02:00
Lukas Markeffsky
9ebd8095fa fix doc links on use items 2023-07-22 12:14:26 +02:00
Michael Goulet
846cc63e38 Make it clearer that edition functions are >=, not == 2023-07-19 16:38:35 +00:00
许杰友 Jieyou Xu (Joe)
33bd453f35
Fix removal span calculation of unused_qualifications suggestion 2023-07-18 09:52:08 +08:00
Mahdi Dibaiee
e55583c4b8 refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
Matthias Krüger
2cc04536b4
Rollup merge of #112729 - jieyouxu:unused-qualifications-suggestion, r=b-naber
Add machine-applicable suggestion for `unused_qualifications` lint

```
error: unnecessary qualification
  --> $DIR/unused-qualifications-suggestion.rs:17:5
   |
LL |     foo::bar();
   |     ^^^^^^^^
   |
note: the lint level is defined here
  --> $DIR/unused-qualifications-suggestion.rs:3:9
   |
LL | #![deny(unused_qualifications)]
   |         ^^^^^^^^^^^^^^^^^^^^^
help: replace it with the unqualified path
   |
LL |     bar();
   |     ~~~
```

Closes #92198.
2023-07-14 01:03:07 +02:00
Mark Rousskov
cc907f80b9 Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
许杰友 Jieyou Xu (Joe)
0b5c683b06
Add machine-applicable suggestion for unused_qualifications lint 2023-07-13 08:26:02 +08:00
bors
8ca44ef9ca Auto merge of #112988 - spastorino:new-rpitit-24, r=compiler-errors
Replace RPITIT current impl with new strategy that lowers as a GAT

This PR replaces the current implementation of RPITITs with the new implementation that we had under -Zlower-impl-trait-in-trait-to-assoc-ty flag that lowers the RPIT as a GAT on the trait and on the impls that implement that trait.

Opening this PR as a draft because this goes after #112682, ~#112981~ and ~#112983~.
As soon as those are merged, I can rebase and we should run perf, crater and test a lot.

r? `@compiler-errors`
2023-07-10 19:01:30 +00:00
Matthias Krüger
70c637808f
Rollup merge of #113331 - chenyukang:yukang-fix-112590-false-positive, r=estebank
Add filter with following segment while lookup typo for path

From the discussion: https://github.com/rust-lang/rust/pull/112917#discussion_r1239150173

Seems we can not get the assoc items for `Struct`, `Enum` in the resolving phase.
A obvious filter is avoid suggesting the same name with the following segment path.

Use `following_seg` can extend the function `smart_resolve_partial_mod_path_errors` for more scenarios, such as `std::sync_error::atomic::AtomicBool` in test case.

r? `@estebank`
2023-07-10 12:01:32 +02:00
Santiago Pastorino
20429af7a3
Replace RPITIT current impl with new strategy that lowers as a GAT 2023-07-08 18:21:34 -03:00
yukang
37b40e592a adjust smart_resolve_partial_mod_path_errors 2023-07-07 10:19:30 +08:00
yukang
9763472e2b smart_resolve_partial_mod_path_errors should not suggest parent 2023-07-07 10:18:20 +08:00
yukang
6f53e61887 Add filter with next segment while lookup typo for path 2023-07-07 09:00:50 +08:00
Vadim Petrochenkov
9f3fba8da8 resolve: Add comments explaining use of Interned 2023-07-05 13:47:37 +03:00
Vadim Petrochenkov
c1f412f9a9 resolve: Use Interned for Module 2023-07-05 13:47:36 +03:00
Vadim Petrochenkov
4abdaeb67e resolve: Use Interned for Import 2023-07-05 13:47:36 +03:00
Vadim Petrochenkov
8efd9cc30d resolve: Use Interned for NameBinding 2023-07-05 13:47:36 +03:00
bors
e728b5b98d Auto merge of #112917 - chenyukang:yukang-fix-112590, r=estebank
Suggest importing for partial mod path matching in name resolving

Fixes #112590
2023-07-04 02:01:24 +00:00
yukang
b26701ea79 add testcase for 112590 2023-07-02 15:35:18 +08:00
bohan
549f48d0ed fix(resolve): skip assertion judgment when NonModule is dummy 2023-07-01 11:53:31 +08:00
Matthias Krüger
207b24413c
Rollup merge of #113177 - estebank:hrlt-sugg, r=compiler-errors
Use structured suggestion when telling user about `for<'a>`

```
error[E0637]: `&` without an explicit lifetime name cannot be used here
  --> $DIR/E0637.rs:13:13
   |
LL |     T: Into<&u32>,
   |             ^ explicit lifetime name needed here
   |
help: consider introducing a higher-ranked lifetime here
   |
LL |     T: for<'a> Into<&'a u32>,
   |        +++++++       ++
```
2023-06-30 08:01:14 +02:00