Commit Graph

1772 Commits

Author SHA1 Message Date
Michael Goulet
8490b8ec63 Dont suggest ! for path in function call if it has generic args 2023-11-27 01:02:37 +00:00
bohan
f23befe6c1 merge DefKind::Coroutine into DefKind::Closure 2023-11-26 21:05:08 +08:00
Michael Goulet
8dd8db5073
Rollup merge of #118288 - compiler-errors:is_some_and, r=lqd,dtolnay
Use `is_{some,ok}_and` more in the compiler

slightly more fluent-reading code
2023-11-25 17:23:34 -05:00
Michael Goulet
3b2f33ee28
Rollup merge of #118158 - nnethercote:reduce-fluent-boilerplate, r=compiler-errors
Reduce fluent boilerplate

Best reviewed one commit at a time.

r? `@davidtwco`
2023-11-25 17:23:33 -05:00
Nicholas Nethercote
57cd5e6551 Use rustc_fluent_macro::fluent_messages! directly.
Currently we always do this:
```
use rustc_fluent_macro::fluent_messages;
...
fluent_messages! { "./example.ftl" }
```
But there is no need, we can just do this everywhere:
```
rustc_fluent_macro::fluent_messages! { "./example.ftl" }
```
which is shorter.
2023-11-26 08:38:40 +11:00
Nicholas Nethercote
a733082be9 Avoid need for {D,Subd}iagnosticMessage imports.
The `fluent_messages!` macro produces uses of
`crate::{D,Subd}iagnosticMessage`, which means that every crate using
the macro must have this import:
```
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
```

This commit changes the macro to instead use
`rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the
imports.
2023-11-26 08:38:00 +11:00
Michael Goulet
079a2e865f is_{some,ok}_and 2023-11-25 18:47:16 +00:00
Vadim Petrochenkov
ad0770eeee resolve: Avoid clones of MacroData
And move declarative macro compilation to an earlier point in def collector, which is required for #118188.
2023-11-25 02:32:33 +03:00
bors
4fd68eb47b Auto merge of #117934 - Young-Flash:dev, r=petrochenkov
feat: make `let_binding_suggestion` more reasonable

This is my first PR for rustc, which trying to fix https://github.com/rust-lang/rust/issues/117894, I am not familiar with some internal api so maybe some modification here isn't the way to go, appreciated for any review suggestion.
2023-11-24 15:26:04 +00:00
Young-Flash
c710db8ea7 feat: make let_binding_suggestion more reasonable 2023-11-23 20:22:17 +08:00
bors
360bafad68 Auto merge of #118065 - estebank:core-not-found-404, r=TaKO8Ki
When failing to import `core`, suggest `std`
2023-11-23 02:26:52 +00:00
Esteban Küber
ec50f1c90b When failing to import core, suggest std 2023-11-22 19:30:47 +00:00
Nilstrieb
21a870515b Fix clippy::needless_borrow in the compiler
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`.

Then I had to remove a few unnecessary parens and muts that were exposed
now.
2023-11-21 20:13:40 +01:00
Esteban Küber
eee4cc6616 let-chain fmt 2023-11-20 23:44:37 +00:00
Esteban Küber
02bea16c08 Rely in resolve and not on path name for &str -> String suggestion 2023-11-20 23:44:37 +00:00
Esteban Küber
bb9d720a16 Do not consider traits as ownable in suggestion 2023-11-20 23:44:37 +00:00
Esteban Küber
85f26ade8d Account for '_ in lifetime suggestion 2023-11-20 23:44:37 +00:00
Esteban Küber
2a92d820c7 Suggest 'a when trait object assoc type has '_ 2023-11-20 23:44:37 +00:00
Esteban Küber
dec7f00e15 Fix incorrect lifetime suggestion 2023-11-20 23:44:37 +00:00
Esteban Küber
d30252e359 Tweak wording 2023-11-20 23:44:37 +00:00
Esteban Küber
5fce361d58 Account for impl Trait in lifetime suggestion
When encountering
```rust
fn g(mut x: impl Iterator<Item = &()>) -> Option<&()> { /* */ }
```
Suggest
```rust
fn g<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&'a ()> { /* */ }
```
2023-11-20 23:44:37 +00:00
Esteban Küber
b7a23bc08b On borrow return type, suggest borrowing from arg or owned return type
When we encounter a function with a return type that has an anonymous
lifetime with no argument to borrow from, besides suggesting the
`'static` lifetime we now also suggest changing the arguments to be
borrows or changing the return type to be an owned type.

```
error[E0106]: missing lifetime specifier
  --> $DIR/variadic-ffi-6.rs:7:6
   |
LL | ) -> &usize {
   |      ^ expected named lifetime parameter
   |
   = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
   |
LL | ) -> &'static usize {
   |       +++++++
help: instead, you are more likely to want to change one of the arguments to be borrowed...
   |
LL |     x: &usize,
   |        +
help: ...or alternatively, to want to return an owned value
   |
LL - ) -> &usize {
LL + ) -> usize {
   |
```

Fix #85843.
2023-11-20 23:44:36 +00:00
Esteban Küber
ac56b06b44 fix rebase 2023-11-19 18:07:22 +00:00
Esteban Küber
a519c9b6b7 review comments 2023-11-19 17:50:47 +00:00
Esteban Küber
4d16171f56 Account for number of arguments in suggestion 2023-11-19 17:50:47 +00:00
Esteban Küber
00265f0cc0 fix tidy 2023-11-19 17:50:47 +00:00
Esteban Küber
987155f35d Suggest using builder on curly brace struct called as fn 2023-11-19 17:50:46 +00:00
Esteban Küber
12a8bb8d9b Do not suggest struct literal when fields are private 2023-11-19 17:50:46 +00:00
Esteban Küber
a4f47de7ff On private tuple struct, suggest Default::default when possible 2023-11-19 17:50:46 +00:00
Esteban Küber
f1ae02f4bd Don't sort span_suggestions, leave that to caller 2023-11-19 17:50:45 +00:00
Esteban Küber
42aa1273b0 When encountering struct fn call literal with private fields, suggest all builders
When encountering code like `Box(42)`, suggest `Box::new(42)` and *all*
other associated functions that return `-> Box<T>`.
2023-11-19 17:47:41 +00:00
Matthias Krüger
8792e81f29
Rollup merge of #117964 - estebank:issue-81232, r=petrochenkov
When using existing fn as module, don't claim it doesn't exist

Tweak wording of module not found in resolve, when the name exists but belongs to a non-`mod` item.

Fix #81232.
2023-11-17 23:04:23 +01:00
Esteban Küber
5c3e01a340 On resolve error of [rest..], suggest [rest @ ..]
When writing a pattern to collect multiple entries of a slice in a
single binding, it is easy to misremember or typo the appropriate syntax
to do so, instead writing the experimental `X..` pattern syntax. When we
encounter a resolve error because `X` isn't available, we suggest
`X @ ..` as an alternative.

```
error[E0425]: cannot find value `rest` in this scope
  --> $DIR/range-pattern-meant-to-be-slice-rest-pattern.rs:3:13
   |
LL |         [1, rest..] => println!("{rest:?}"),
   |             ^^^^ not found in this scope
   |
help: if you meant to collect the rest of the slice in `rest`, use the at operator
   |
LL |         [1, rest @ ..] => println!("{rest:?}"),
   |                  +
```

Fix #88404.
2023-11-17 00:55:55 +00:00
Esteban Küber
890ce26213 When using existing fn as module, don't claim it doesn't exist
Tweak wording of module not found in resolve, when the name exists but
belongs to a non-`mod` item.

Fix #81232.
2023-11-16 06:07:33 +00:00
Mark Rousskov
db3e2bacb6 Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
Nicholas Nethercote
1b3733e5a4 rustc: minor changes suggested by clippy perf lints. 2023-11-08 08:57:57 +11:00
Nicholas Nethercote
8ff624a9f2 Clean up rustc_*/Cargo.toml.
- Sort dependencies and features sections.
- Add `tidy` markers to the sorted sections so they stay sorted.
- Remove empty `[lib`] sections.
- Remove "See more keys..." comments.

Excluded files:
- rustc_codegen_{cranelift,gcc}, because they're external.
- rustc_lexer, because it has external use.
- stable_mir, because it has external use.
2023-10-30 08:46:02 +11:00
bors
2cad938a81 Auto merge of #116447 - oli-obk:gen_fn, r=compiler-errors
Implement `gen` blocks in the 2024 edition

Coroutines tracking issue https://github.com/rust-lang/rust/issues/43122
`gen` block tracking issue https://github.com/rust-lang/rust/issues/117078

This PR implements `gen` blocks that implement `Iterator`. Most of the logic with `async` blocks is shared, and thus I renamed various types that were referring to `async` specifically.

An example usage of `gen` blocks is

```rust
fn foo() -> impl Iterator<Item = i32> {
    gen {
        yield 42;
        for i in 5..18 {
            if i.is_even() { continue }
            yield i * 2;
        }
    }
}
```

The limitations (to be resolved) of the implementation are listed in the tracking issue
2023-10-29 00:03:52 +00:00
Oli Scherer
b8bfd08999 Rename RibKind::ClosureOrAsync to reflect how it is actually used 2023-10-27 13:05:49 +00:00
Oli Scherer
621494382d Add gen blocks to ast and do some broken ast lowering 2023-10-27 13:05:48 +00:00
bors
688892938e Auto merge of #116858 - estebank:issue-22488, r=petrochenkov
Suggest assoc fn `new` when trying to build tuple struct with private fields

Fix #22488.
2023-10-27 12:16:01 +00:00
Esteban Küber
87dc85d322 Suggest assoc fn new when trying to build tuple struct with private fields
Fix #22488.
2023-10-26 22:21:05 +00:00
Matthias Krüger
17fb2f4b31
Rollup merge of #116905 - Fenex:refactor/compiler/resolve, r=petrochenkov
refactor(compiler/resolve): simplify some code

Removes unnecessary allocate and double-sorting the same vector, makes the code a little nicer.
2023-10-26 17:45:43 +02:00
Matthias Krüger
2a027faf68
Rollup merge of #117009 - fmease:diag-disambig-sugg-crate, r=b-naber
On unresolved imports, suggest a disambiguated path if necessary to avoid collision with local items

Fixes #116970.
2023-10-25 23:37:10 +02:00
bohan
482275b194 use visibility to check unused imports and delete some stmts 2023-10-22 21:27:46 +08:00
León Orell Valerian Liehr
4aaf8e03e1
on unresolved import disambiguate suggested path if it would collide 2023-10-21 15:40:32 +02:00
Matthias Krüger
c5dd84d493
Rollup merge of #116961 - estebank:issue-60164, r=oli-obk
Typo suggestion to change bindings with leading underscore

When encountering a binding that isn't found but has a typo suggestion for a binding with a leading underscore, suggest changing the binding definition instead of the use place.

Fix #60164.
2023-10-21 10:08:16 +02:00
Oli Scherer
60956837cf s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
Esteban Küber
b0d17f35d9 Typo suggestion to change bindings with leading underscore
When encountering a binding that isn't found but has a typo suggestion
for a binding with a leading underscore, suggest changing the binding
definition instead of the use place.

Fix #60164.
2023-10-20 15:58:25 +00:00
Vitaliy Busko
e68edb89ad
refactor(compiler/resolve): simplify some code
Removes unnecessary allocates and double-sorting the same vector,
makes the code a little nicer.
2023-10-19 04:45:06 +07:00
Michael Goulet
b2d2184ede Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
Michael Howell
c6e6ecb1af rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
Nicholas Nethercote
eb209057b1 Rename Resolver::active_features.
For the reasons described in the previous commit.
2023-10-05 18:01:11 +11:00
Matthias Krüger
144862ede8
Rollup merge of #115863 - chenyukang:yukang-add-message-tidy-check, r=davidtwco
Add check_unused_messages in tidy

From https://github.com/rust-lang/rust/pull/115728#issuecomment-1715490553
The check is not 100% accurate, I guess it's enough for now.
2023-10-03 12:24:11 +02:00
Tyler Mandry
af77806bee
Rollup merge of #114454 - Nilstrieb:no-evil-sorting, r=cjgillot
Replace `HashMap` with `IndexMap` in pattern binding resolve

fixes https://github.com/rust-lang/rust/pull/114332#discussion_r1284189179
2023-10-02 16:09:42 -04:00
Nilstrieb
6ca07235a6 Replace HashMap with IndexMap in pattern binding resolve
It will be iterated over, so we should avoid using `HashMap`.
2023-10-02 19:12:42 +02:00
bors
16b7b39fdd Auto merge of #116228 - bvanjoi:fix-116164, r=cjgillot
resolve: skip underscore character during candidate lookup

Fixes #116164

In use statement, an underscore is merely a placeholder symbol and does not bind to any name. Therefore, it can be safely ignored.
2023-10-01 16:41:03 +00:00
bors
c1f86f0bc8 Auto merge of #116089 - estebank:issue-115992-2, r=compiler-errors
When suggesting `self.x` for `S { x }`, use `S { x: self.x }`

Fix #115992.

r? `@compiler-errors`

Follow up to #116086.
2023-09-29 05:45:18 +00:00
bohan
cfb819fa7e resolve: skip underscore character during candidate lookup 2023-09-28 19:47:58 +08:00
Matthias Krüger
fd95627134 fix clippy::{redundant_guards, useless_format} 2023-09-27 23:49:15 +02:00
bors
6b99cf1d35 Auto merge of #116163 - compiler-errors:lazyness, r=oli-obk
Don't store lazyness in `DefKind::TyAlias`

1. Don't store lazyness of a type alias in its `DefKind`, but instead via a query.
2. This allows us to treat type aliases as lazy if `#[feature(lazy_type_alias)]` *OR* if the alias contains a TAIT, rather than having checks for both in separate parts of the codebase.

r? `@oli-obk` cc `@fmease`
2023-09-27 01:48:53 +00:00
bors
27b4eb96d1 Auto merge of #116125 - RalfJung:const-param-ty-eq, r=compiler-errors
ConstParamTy: require Eq as supertrait

As discussed with `@BoxyUwu` [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/.60ConstParamTy.60.20and.20.60Eq.60).

We want to say that valtree equality on const generic params agrees with `==`, but that only makes sense if `==` actually exists, hence we should have an appropriate bound. Valtree equality is an equivalence relation, so such a type can always be `Eq` and not just `PartialEq`.
2023-09-26 05:33:55 +00:00
Michael Goulet
d6ce9ce115 Don't store lazyness in DefKind 2023-09-26 02:53:59 +00:00
Esteban Küber
d00c7e78ea Point at field definition when unresolved name exists in Self 2023-09-25 15:56:36 +00:00
Esteban Küber
81bca5f5cf When suggesting self.x for S { x }, use S { x: self.x }
Tweak output.

Fix #115992.
2023-09-25 15:56:36 +00:00
Ralf Jung
4f86c69184 fix ICE due to empty span and empty suggestions 2023-09-24 23:32:36 +02:00
Esteban Küber
ac5e18756a Tweak wording and logic 2023-09-23 01:54:05 +00:00
Esteban Küber
0e98682576 When encountering method on Self that we can't suggest, mention it 2023-09-23 01:47:06 +00:00
Esteban Küber
c4a4926083 More accurate suggestion for self. and Self::
Fix #115992.
2023-09-23 01:34:50 +00:00
yukang
42a033affa Cleanup unused messages in ftl files 2023-09-20 19:09:01 +08:00
Ethan Brierley
2243872c26 fix confusing let chain indentation in rustc_resolve 2023-09-19 21:21:01 +01:00
bors
327e6cf55c Auto merge of #114452 - weiznich:feature/diagnostic_on_unimplemented, r=compiler-errors
`#[diagnostic::on_unimplemented]` without filters

This commit adds support for a `#[diagnostic::on_unimplemented]` attribute with the following options:

* `message` to customize the primary error message
* `note` to add a customized note message to an error message
* `label` to customize the label part of the error message

The relevant behavior is specified in [RFC-3366](https://rust-lang.github.io/rfcs/3366-diagnostic-attribute-namespace.html)
2023-09-17 10:00:15 +00:00
bors
dac91a82e1 Auto merge of #115677 - matthewjasper:let-expr-recovery, r=b-naber
Improve invalid let expression handling

- Move all of the checks for valid let expression positions to parsing.
- Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location.
- Suppress some later errors and MIR construction for invalid let expressions.
- Fix a (drop) scope issue that was also responsible for #104172.

Fixes #104172
Fixes #104868
2023-09-14 19:56:55 +00:00
bohan
f1536507e1 resolve: determined binding after parent module macro expand 2023-09-13 16:38:05 +08:00
Georg Semmler
5b8a7a0917
#[diagnostic::on_unimplemented] without filters
This commit adds support for a `#[diagnostic::on_unimplemented]`
attribute with the following options:

* `message` to customize the primary error message
* `note` to add a customized note message to an error message
* `label` to customize the label part of the error message

Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
Co-authored-by: Michael Goulet <michael@errs.io>
2023-09-12 20:03:18 +02:00
bors
36b8e4aa75 Auto merge of #115689 - Alexendoo:clippy-doc-comments, r=notriddle,Manishearth,flip1995
Reuse rustdoc's doc comment handling in Clippy

Moves `source_span_for_markdown_range` and `span_of_attrs` (renamed to `span_of_fragments`) to `rustc_resolve::rustdoc` so it can be used in Clippy

Fixes https://github.com/rust-lang/rust-clippy/issues/10277
Fixes https://github.com/rust-lang/rust-clippy/issues/5593
Fixes https://github.com/rust-lang/rust-clippy/issues/10263
Fixes https://github.com/rust-lang/rust-clippy/issues/2581
2023-09-12 01:45:24 +00:00
Matthew Jasper
333388fd3c Move let expression checking to parsing
There was an incomplete version of the check in parsing and a second
version in AST validation. This meant that some, but not all, invalid
uses were allowed inside macros/disabled cfgs. It also means that later
passes have a hard time knowing when the let expression is in a valid
location, sometimes causing ICEs.

- Add a field to ExprKind::Let in AST/HIR to mark whether it's in a
  valid location.
- Suppress later errors and MIR construction for invalid let
  expressions.
2023-09-11 15:51:18 +00:00
Matthias Krüger
8b49731211
Rollup merge of #115744 - fmease:fix-e0401, r=compiler-errors
Improve diagnostic for generic params from outer items (E0401)

Generalize the wording of E0401 to talk about *outer items* instead of *outer functions* since the current phrasing is outdated. The outer item can be a function, constant, trait, ADT or impl block (see the new UI test for the more exotic examples).

Further, don't suggest introducing generic parameters to constant items unless the feature `generic_const_items` is enabled.

Lastly, make E0401 translatable while we're at it.

Fixes #115720.
2023-09-11 17:03:32 +02:00
bors
9a099d2fa3 Auto merge of #115504 - bvanjoi:error-struct, r=cjgillot
resolve: derive diag for undetermined macro resolution

simply for neatness.
2023-09-11 03:28:52 +00:00
León Orell Valerian Liehr
daf3c45531
Do not suggest generic const items unless enabled 2023-09-10 23:07:48 +02:00
León Orell Valerian Liehr
9b36252477
Make E0401 translatable 2023-09-10 23:07:24 +02:00
León Orell Valerian Liehr
b00e408e61
Generalize E0401 2023-09-10 23:06:14 +02:00
John Kåre Alsaker
1d8fdc0332 Use FreezeLock for CStore 2023-09-09 16:02:11 +02:00
Alex Macleod
caaf1eb887 Reuse rustdoc's doc comment handling in Clippy 2023-09-08 23:42:57 +00:00
Michael Goulet
03bee1f53d Find lowest span out of use + attrs 2023-09-07 05:19:43 +00:00
bohan
7bad066f82 resolve: derive diag for undetermined macro resolution 2023-09-04 09:29:26 +08:00
bors
9229b1eab4 Auto merge of #115429 - compiler-errors:assoc-ct-lt-fallthrough, r=cjgillot
Fall through when resolving elided assoc const lifetimes

`@QuineDot` makes a good point in https://github.com/rust-lang/rust/issues/115010#issuecomment-1702127634 that we probably should not accept *more* code due to #115011 even though that code will eventually become a forbid-warning in a few versions (https://github.com/rust-lang/rust/issues/115010#issuecomment-1701598067).

Fall through when walking thru the `AnonymousWarnToStatic` (renamed to `AnonymousWarn`) rib so that we can resolve as a fresh lifetime like we did before.
2023-09-02 10:55:49 +00:00
bors
1accf068d8 Auto merge of #113126 - Bryanskiy:delete_old, r=petrochenkov
Replace old private-in-public diagnostic with type privacy lints

Next part of RFC https://github.com/rust-lang/rust/issues/48054.

r? `@petrochenkov`
2023-09-01 12:40:01 +00:00
Michael Goulet
b62eeb2aac Fall through when resolving elided assoc const lifetimes 2023-09-01 07:23:39 +00:00
bors
2f5df8a94b Auto merge of #115366 - compiler-errors:associated-type-bound-implicit-lifetimes, r=jackh726
Capture lifetimes for associated type bounds destined to be lowered to opaques

Some associated type bounds get lowered to opaques, but they're not represented in the AST as opaques.

That means that we never collect lifetimes for them (`record_lifetime_params_for_impl_trait`) which are used currently for RPITITs, which capture all of their in-scope lifetimes[^1]. This means that the nested RPITITs that arise from some type like `impl Foo<Type: Bar>` (~> `impl Foo<Type = impl Bar>`) don't capture any lifetimes, leading to ICEs.

This PR makes sure we collect the lifetimes for associated type bounds as well, and make sure that they are set up correctly for opaque type lowering later.

Fixes #115360

[^1]: #114489
2023-08-31 21:13:54 +00:00
bohan
107152141b fix(resolve): update def if binding is warning ambiguity 2023-08-31 20:00:04 +08:00
Michael Goulet
f1679f7dd6 Capture lifetimes for associated type bounds destined to be lowered to opaques 2023-08-30 00:31:00 +00:00
Michael Goulet
13d3e57237 RPITITs capture all their lifetimes 2023-08-28 01:05:34 +00:00
bors
58eefc33ad Auto merge of #113408 - petrochenkov:bindintern2, r=cjgillot
resolve: Stop creating `NameBinding`s on every use, create them once per definition instead

`NameBinding` values are supposed to be unique, use referential equality, and be created once for every name declaration.

Before this PR many `NameBinding`s were created on name use, rather than on name declaration, because it's sufficiently cheap, and comparisons are not actually used in practice for some binding kinds.
This PR makes `NameBinding`s consistently unique and created on name declaration.

There are two special cases
- for extern prelude names creating `NameBinding` requires loading the corresponding crate, which is expensive, so such bindings are created lazily on first use, but they still keep the uniqueness by being reused on further uses.
- for legacy derive helpers (helper attributes written before derives that introduce them) the declaration and the use is basically the same thing (that's one of the reasons why they are deprecated), so they are still created on use, but we can still maybe do a bit better in a way that I described in FIXME in the last commit.
2023-08-24 20:05:57 +00:00
bors
8a6b67f988 Auto merge of #115094 - Mark-Simulacrum:bootstrap-update, r=ozkanonur
Update bootstrap compiler to 1.73.0 beta
2023-08-24 11:10:52 +00:00
Vadim Petrochenkov
453edebc70 resolve: Leave a comment about name bindings for legacy derive helpers 2023-08-24 18:57:29 +08:00
Vadim Petrochenkov
50bbe01de0 resolve: Make bindings for derive helper attributes unique
instead of creating them every time such attribute is used
2023-08-24 18:57:29 +08:00
Vadim Petrochenkov
02640f9d59 resolve: Make bindings for crate roots unique
instead of creating a new every time `crate` or `$crate` is used
2023-08-24 18:57:29 +08:00
Vadim Petrochenkov
d1f8ea417c resolve: Pre-intern tool module bindings 2023-08-24 18:54:34 +08:00
Vadim Petrochenkov
05010b6074 resolve: Make bindings from extern prelude unique
instead of creating a new every time a name from extern prelude is accessed
2023-08-24 18:54:28 +08:00
Vadim Petrochenkov
9ce35198bf resolve: Pre-intern builtin name bindings 2023-08-24 18:11:51 +08:00
Mark Rousskov
0a916062aa Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
Michael Goulet
e9897c3a71
Rollup merge of #115011 - compiler-errors:warn-on-elided-assoc-ct-lt, r=cjgillot
Warn on elided lifetimes in associated constants (`ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT`)

Elided lifetimes in associated constants (in impls) erroneously resolve to fresh lifetime parameters on the impl since #97313. This is not correct behavior (see #38831).

I originally opened #114716 to fix this, but given the time that has passed, the crater results seem pretty bad: https://github.com/rust-lang/rust/pull/114716#issuecomment-1682091952

This PR alternatively implements a lint against this behavior, and I'm hoping to bump this to deny in a few versions.
2023-08-22 09:00:49 -07:00
Michael Goulet
fad7d220fd Warn on elided lifetimes in associated constants 2023-08-20 00:21:47 +00:00
Kyle Lin
ecb26376e5 narrow down the lint trigger constraint 2023-08-18 15:19:22 +08:00
Kyle Lin
78c85f439f fomar files 2023-08-18 15:19:19 +08:00
Kyle Lin
5ce6cc7df3 Still resolving rustdoc resolution panicking 2023-08-18 15:19:17 +08:00
Kyle Lin
65e24a57bb Fix resolution caching 2023-08-18 15:19:10 +08:00
Vadim Petrochenkov
7353c96be8 rustc: Move features from Session to GlobalCtxt
Removes two pieces of mutable state.
Follow up to #114622.
2023-08-11 16:51:50 +08:00
Michael Goulet
94533d924e
Rollup merge of #114622 - petrochenkov:noplugin, r=oli-obk
rustc: Move `crate_types` and `stable_crate_id` from `Session` to `GlobalCtxt`

Removes two pieces of mutable state.
Follow up to https://github.com/rust-lang/rust/pull/114578.
2023-08-10 21:17:07 -07:00
Vadim Petrochenkov
0b89aac08d rustc: Move crate_types from Session to GlobalCtxt
Removes a piece of mutable state.
Follow up to #114578.
2023-08-09 14:17:54 +08:00
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
Bryanskiy
e26614e6a7 Replace old private-in-public diagnostic with type privacy lints 2023-08-02 13:40:28 +03: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
Esteban Küber
7d33094d3a 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 00:34:14 +00:00
Vadim Petrochenkov
4dcce38cda resolve: Remove artificial import ambiguity errors 2023-06-29 13:42:58 +03:00
Matthias Krüger
d505582ce2
Rollup merge of #113084 - WaffleLapkin:less_map_or, r=Nilstrieb
Simplify some conditions

r? `@Nilstrieb`

Some things taken out of my `is_none_or` pr.
2023-06-27 22:10:15 +02:00
Maybe Waffle
ef05533c39 Simplify some conditions 2023-06-27 07:40:47 +00:00
Matthias Krüger
005d860fc6
Rollup merge of #112979 - NotStirred:translatable_diag/resolve_imports, r=fee1-dead
Rewrite most diagnostics as translatable within resolve/imports
2023-06-26 11:58:45 +02:00
Tom Martin
b7d6032082
Add translatable diagnostic for import resolution strings
Add translatable diagnostic for cannot be reexported error
also added for subdiagnostics

Add translatable diagnostics for resolve_glob_import errors

Add translatable diag for unable to determine import resolution

Add translatable diag for is not directly importable
2023-06-25 08:29:28 +01:00
bohan
8c8c7ef78a fix: add cfg diagnostic for unresolved import error 2023-06-24 21:45:17 +08:00
Esteban Küber
7dffd24da5 Tweak privacy errors to account for reachable items
Suggest publicly accessible paths for items in private mod:

  When encountering a path in non-import situations that are not reachable
  due to privacy constraints, search for any public re-exports that the
  user could use instead.

Track whether an import suggestion is offering a re-export.

When encountering a path with private segments, mention if the item at
the final path segment is not publicly accessible at all.

Add item visibility metadata to privacy errors from imports:

  On unreachable imports, record the item that was being imported in order
  to suggest publicly available re-exports or to be explicit that the item
  is not available publicly from any path.

  In order to allow this, we add a mode to `resolve_path` that will not
  add new privacy errors, nor return early if it encounters one. This way
  we can get the `Res` corresponding to the final item in the import,
  which is used in the privacy error machinery.
2023-06-22 16:50:31 +00:00
yukang
e7e1a39fa0 suggest importing for partial mod path in name resolving 2023-06-22 11:18:48 +08:00
Vadim Petrochenkov
c007293e29 resolve: Minor cleanup to fn resolve_path_with_ribs
A single-use closure is inlined and one unnecessary enum is removed.
2023-06-21 17:48:04 +03:00
bohan
629b50928c Revert "Rollup merge of #112758 - bvanjoi:clean-up-resolve, r=petrochenkov"
This reverts commit 3b059e0fdb, reversing
changes made to d70be67047.
2023-06-20 22:47:50 +08:00
Matthias Krüger
6de869fd23
Rollup merge of #112768 - NotStirred:translatable_diag/resolve1, r=WaffleLapkin
Rewrite various resolve/diagnostics errors as translatable diagnostics

additional question:

For trivial strings is it ever accepted to use `fluent_generated::foo` in a `label` for example? Or is an empty struct `Diagnostic` preferred?
2023-06-19 19:26:27 +02:00
Tom Martin
2027e989bc
Remove unreachable and untested suggestion for invalid span enum derive(Default) 2023-06-19 16:22:21 +01:00
Tom Martin
db613750a9
Reformatting 2023-06-19 16:21:33 +01:00
Tom Martin
c07b50a213
Fix tidy 2023-06-18 14:16:37 +01:00
bohan
894ab2ce7a refactor(resolve): delete update_resolution function 2023-06-18 21:03:59 +08:00
Tom Martin
4b5a5a4529
Add translatable diagnostic for various strings in resolve::unresolved_macro_suggestions 2023-06-18 12:32:40 +01:00
Tom Martin
355a689542
Add translatable diagnostic for cannot find in this scope 2023-06-18 12:28:17 +01:00
Tom Martin
50c971a0b7
Add translatable diagnostic for invalid imports 2023-06-18 12:28:17 +01:00
Tom Martin
8fa9003621
Add translatable diagnostic for changing import binding 2023-06-18 12:28:16 +01:00
许杰友 Jieyou Xu (Joe)
32ae8810fc
Fix suggestion for E0404 not dealing with multiple generics 2023-06-15 18:19:09 +08:00
bors
6ee4265ca6 Auto merge of #104455 - the8472:dont-drain-on-drop, r=Amanieu
Don't drain-on-drop in DrainFilter impls of various collections.

This removes drain-on-drop behavior from various unstable DrainFilter impls (not yet for HashSet/Map) because that behavior [is problematic](https://github.com/rust-lang/rust/issues/43244#issuecomment-641638196) (because it can lead to panic-in-drop when user closures panic) and may become forbidden if [this draft RFC passes](https://github.com/rust-lang/rfcs/pull/3288).

closes #101122

[ACP](https://github.com/rust-lang/libs-team/issues/136)

affected tracking issues
* #43244
* #70530
* #59618

Related hashbrown update: https://github.com/rust-lang/hashbrown/pull/374
2023-06-15 00:03:10 +00:00
The 8472
114d5f221c s/drain_filter/extract_if/ for Vec, Btree{Map,Set} and LinkedList 2023-06-14 09:28:54 +02:00
bohan
f7330eb752 fix(resolve): update shadowed_glob more precision 2023-06-14 01:38:35 +08:00
bors
d0ee1908ed Auto merge of #112452 - MU001999:fix/issue-112439, r=petrochenkov
Make "consider importing" consistent for macros

Fixes #112439
2023-06-10 05:07:53 +00:00
bors
29611778b7 Auto merge of #112426 - Bryanskiy:full_priv_ev, r=petrochenkov
increase the accuracy of effective visibilities calculation

Effective visibilities are calculated lazily due to performance restrictions.  Therefore

- crate should be walked at least 1 time in `compute_effective_visibilities` pass
- Impl's should always be in the effective visibilities table

to ensure that the table is filled in correctly.

r? `@petrochenkov`
2023-06-10 02:16:24 +00:00
Mu001999
5bd8ba8493 Make "consider importing" consistent for macros 2023-06-10 00:06:34 +08:00
Bryanskiy
5e917a6039 increase the accuracy of effective visibilities calculation 2023-06-08 19:22:30 +03:00
Nilstrieb
a647ba250a Remember names of cfg-ed out items to mention them in diagnostics
`#[cfg]`s are frequently used to gate crate content behind cargo
features. This can lead to very confusing errors when features are
missing. For example, `serde` doesn't have the `derive` feature by
default. Therefore, `serde::Serialize` fails to resolve with a generic
error, even though the macro is present in the docs.

This commit adds a list of all stripped item names to metadata. This is
filled during macro expansion and then, through a fed query, persisted
in metadata. The downstream resolver can then access the metadata to
look at possible candidates for mentioning in the errors.

This slightly increases metadata (800k->809k for the feature-heavy
windows crate), but not enough to really matter.
2023-06-01 19:17:19 +02:00
Nicholas Nethercote
781111ef35 Use Cow in {D,Subd}iagnosticMessage.
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment:
```
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
```
This commit answers that question in the affirmative. It's not the most
compelling change ever, but it might be worth merging.

This requires changing the `impl<'a> From<&'a str>` impls to `impl
From<&'static str>`, which involves a bunch of knock-on changes that
require/result in call sites being a little more precise about exactly
what kind of string they use to create errors, and not just `&str`. This
will result in fewer unnecessary allocations, though this will not have
any notable perf effects given that these are error paths.

Note that I was lazy within Clippy, using `to_string` in a few places to
preserve the existing string imprecision. I could have used `impl
Into<{D,Subd}iagnosticMessage>` in various places as is done in the
compiler, but that would have required changes to *many* call sites
(mostly changing `&format("...")` to `format!("...")`) which didn't seem
worthwhile.
2023-05-29 09:23:43 +10:00
许杰友 Jieyou Xu (Joe)
b9606589c4
Add warn-by-default lint for local binding shadowing exported glob re-export item 2023-05-27 18:49:07 +08:00
bors
c86212f9bc Auto merge of #111858 - clubby789:fluent-alphabetical, r=jyn514,compiler-errors
Ensure Fluent messages are in alphabetical order

Fixes #111847

This adds a tidy check to ensure Fluent messages are in alphabetical order, as well as sorting all existing messages. I think the error could be worded better, would appreciate suggestions.

<details>
<summary>Script used to sort files</summary>

```py
import sys
import re

fn = sys.argv[1]
with open(fn, 'r') as f:
    data = f.read().split("\n")

chunks = []
cur = ""
for line in data:
    if re.match(r"^([a-zA-Z0-9_]+)\s*=\s*", line):
        chunks.append(cur)
        cur = ""
    cur += line + "\n"
chunks.append(cur)
chunks.sort()

with open(fn, 'w') as f:
    f.write(''.join(chunks).strip("\n\n") + "\n")
```
</details>
2023-05-26 03:31:04 +00:00
clubby789
f97fddab91 Ensure Fluent messages are in alphabetical order 2023-05-25 23:49:35 +00:00
Michael Goulet
bd7e8b5ef9
Rollup merge of #111152 - lukas-code:markdown-parsers-are-hard, r=GuillaumeGomez
update `pulldown-cmark` to `0.9.3`

This PR updates `pulldown-cmark` to version `0.9.3`, which does two main things:
* Pulls in https://github.com/raphlinus/pulldown-cmark/pull/643 to fix https://github.com/rust-lang/rust/issues/111117
* Allows parsing strikethrough with single tildes, e.g. `~foo~` -> ~foo~. This matches the [GFM spec](https://github.github.com/gfm/#strikethrough-extension-).

Full changelog: https://github.com/raphlinus/pulldown-cmark/pull/646
2023-05-25 13:57:59 -07:00
Maybe Waffle
307799a711 Use is_some_and/is_ok_and in less obvious spots 2023-05-24 14:33:43 +00:00
Maybe Waffle
fb0f74a8c9 Use Option::is_some_and and Result::is_ok_and in the compiler 2023-05-24 14:20:41 +00:00
bors
d69787f098 Auto merge of #111195 - GuillaumeGomez:fix-ice-intra-doc-link, r=petrochenkov
Prevent crash when a path is not resolved in intra-doc link

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

cc `@petrochenkov`
r? `@notriddle`
2023-05-24 07:49:53 +00:00
Guillaume Gomez
234927e098 Ignore "non-real" type Res in rustdoc intra doc link resolution 2023-05-23 15:33:34 +02:00
bohan
c41b2089c7 fix(resolve): not defined extern crate shadow_name 2023-05-23 13:14:34 +08:00
Lukas Markeffsky
cb2ba42a10 update pulldown-cmark to 0.9.3 2023-05-22 11:35:25 +02:00
Dylan DPC
13f3585dc6
Rollup merge of #111652 - clubby789:self-import-improvement, r=compiler-errors
Better diagnostic for `use Self::..`

Fixes #111627

cc `@petrochenkov,` you might have thoughts on a better way to handle this (https://github.com/rust-lang/rust/issues/63720#issuecomment-591597466)
2023-05-20 12:21:00 +05:30
bors
92f5dea0eb Auto merge of #109602 - bvanjoi:fix-issue-109343, r=petrochenkov
fix(resolve): replace bindings to dummy for unresolved imports

close #109343

In #109343, `f` in `pub use f as g` points to:

|namespace| binding|
|-|-|
|type| `external crate f`|
|value| `None` |
|macro| `None` |

When resolve `value_ns` during `resolve_doc_links`, the value of the binding of single_import `pub use f as g` goes to `pub use inner::f`, and since it does not satisfy [!self.is_accessible_from(binding.vis, single_import.parent_scope.module)](https://github.com/rust-lang/rust/blob/master/compiler/rustc_resolve/src/ident.rs#L971) and returns `Err(Undetermined)`, which eventually goes to `PathResult::Indeterminate => unreachable!`.

This PR replace all namespace binding to `dummy_binding` for indeterminate import, so, the bindings of `pub use f as g` had been changed to followings after finalize:

|namespace| binding|
|-|-|
|type| `dummy`|
|value| `dummy` |
|macro| `dummy` |

r?`@petrochenkov`
2023-05-19 00:41:32 +00:00
bohan
5b09810976 fix(resolve): only disambiguate binding key during define 2023-05-18 09:29:48 +08:00
bohan
f34678c097 fix(resolve): replace bindings to dummy for unresolved imports 2023-05-18 09:22:29 +08:00
Dylan DPC
ff364b0082
Rollup merge of #111557 - cjgillot:revert-111020, r=petrochenkov
Revert "Validate resolution for SelfCtor too."

This reverts commit 83453408a0.

That PR introduced a breaking change.

Fixes https://github.com/rust-lang/rust/issues/111541
Reopens https://github.com/rust-lang/rust/issues/89868

r? `@petrochenkov`
2023-05-17 19:11:54 +05:30
clubby789
eaf47a30cb Better diagnostic for use Self::.. 2023-05-16 20:30:48 +00:00
Nilstrieb
f65281534f
Rollup merge of #111428 - bvanjoi:fix-109250, r=Nilstrieb
refactor(resolve): clean up the early error return caused by non-call

closes https://github.com/rust-lang/rust/issues/109250

It seems no bad happened, r? ``@Nilstrieb``
2023-05-16 11:39:38 +02:00
John Kåre Alsaker
fff20a703d Move expansion of query macros in rustc_middle to rustc_middle::query 2023-05-15 08:49:13 +02:00
Camille GILLOT
343819d33f Revert "Validate resolution for SelfCtor too."
This reverts commit 83453408a0.
2023-05-14 12:48:32 +00:00
bors
ad6ab11234 Auto merge of #111425 - Bryanskiy:privacy_ef, r=petrochenkov
Populate effective visibilities in `rustc_privacy` (take 2)

Same as https://github.com/rust-lang/rust/pull/110907 + regressions fixes.
Fixes https://github.com/rust-lang/rust/issues/111359.

r? `@petrochenkov`
2023-05-14 02:53:52 +00:00
Michael Goulet
6641b49cdd
Rollup merge of #111460 - clubby789:lowercase-box-self, r=compiler-errors
Improve suggestion for `self: Box<self>`

Fixes #110642
2023-05-11 17:43:09 -07:00
clubby789
3851a4bb91 Improve error for self: Box<self> 2023-05-11 13:21:10 +01:00
Bryanskiy
670f5b134e Populate effective visibilities in rustc_privacy 2023-05-11 14:51:01 +03:00
Camille GILLOT
a2fe9935ea Only warn single-use lifetime when the binders match. 2023-05-10 19:49:02 +00:00
bohan
7c1bc0353b refactor(resolve): clean up the early error return caused by non-call 2023-05-10 22:35:01 +08:00
Boxy
73b3ce26ec improve diagnostics and bless tests 2023-05-05 21:42:54 +01:00
Boxy
442617c046 misc nameres changes for anon consts 2023-05-05 21:31:35 +01:00
Matthias Krüger
8d66f01ab5
Rollup merge of #110982 - cjgillot:elided-self-const, r=petrochenkov
Do not recurse into const generic args when resolving self lifetime elision.

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

r? `@petrochenkov`
2023-05-04 19:18:20 +02:00
Matthias Krüger
50754578f6
Rollup merge of #111070 - WaffleLapkin:break_ribs, r=lcnr
Don't suffix `RibKind` variants

This PR
- Removes `use RibKind::*`
- Renames `RibKind::{SomethingRibKind => Something}`

It seems unnecessary to have "RibKind" in the end of all variants, if we can just use it as a normal enum. Additionally previously it was weird that `MacroDefinition` is the only unsuffixed variant.
2023-05-04 08:09:06 +02:00
Matthias Krüger
1187ce7213
Rollup merge of #111020 - cjgillot:validate-self-ctor, r=petrochenkov
Validate resolution for SelfCtor too.

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

r? `@petrochenkov`
2023-05-04 08:09:04 +02:00
Dylan DPC
0228994cdf
Rollup merge of #110908 - petrochenkov:notagain4, r=compiler-errors
resolve: One more attempt to simplify `module_children`

If the next step is performed and `fn module_children_local` is merged with the `module_children` query, then it causes perf regressions, regardless of whether query result feeding is [used](https://perf.rust-lang.org/compare.html?start=43a78029b4f4d92978b8fde0a677ea300b113c41&end=2eb5bcc5068b9d92f74bcb1797da664865d6981d&stat=instructions:u) or [not](https://perf.rust-lang.org/compare.html?start=2fce2290865f012391b8f3e581c3852a248031fa&end=2a33d6cd99481d1712037a79e7d66a8aefadbf72&stat=instructions:u).
2023-05-04 00:17:24 +05:30
Camille GILLOT
8972a23f48 Do not recurse into const generic args when resolving self lifetime elision. 2023-05-03 18:07:53 +00:00
Camille GILLOT
83453408a0 Validate resolution for SelfCtor too. 2023-05-03 17:55:27 +00:00
Nicholas Nethercote
6b62f37402 Restrict From<S> for {D,Subd}iagnosticMessage.
Currently a `{D,Subd}iagnosticMessage` can be created from any type that
impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static,
str>`, which are reasonable. It also includes `&String`, which is pretty
weird, and results in many places making unnecessary allocations for
patterns like this:
```
self.fatal(&format!(...))
```
This creates a string with `format!`, takes a reference, passes the
reference to `fatal`, which does an `into()`, which clones the
reference, doing a second allocation. Two allocations for a single
string, bleh.

This commit changes the `From` impls so that you can only create a
`{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static,
str>`. This requires changing all the places that currently create one
from a `&String`. Most of these are of the `&format!(...)` form
described above; each one removes an unnecessary static `&`, plus an
allocation when executed. There are also a few places where the existing
use of `&String` was more reasonable; these now just use `clone()` at
the call site.

As well as making the code nicer and more efficient, this is a step
towards possibly using `Cow<'static, str>` in
`{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing
the `From<&'a str>` impls to `From<&'static str>`, which is doable, but
I'm not yet sure if it's worthwhile.
2023-05-03 08:44:39 +10:00
Vadim Petrochenkov
ef77dd232d resolve: One more attempt to simplify module_children 2023-05-02 17:21:08 +03:00
Maybe Waffle
0fa59204e5 Remove "RibKind" suffix from RibKind variants 2023-05-01 15:54:48 +00:00
Maybe Waffle
6197e4d209 Don't use RibKind::* 2023-05-01 15:52:23 +00:00
yukang
f54489978d fix tests 2023-05-01 16:15:17 +08:00
yukang
1b08eaca20 clean up debug code 2023-05-01 16:15:17 +08:00
yukang
10512b2932 remove current_type_ascription from DiagnosticMetadata 2023-05-01 16:15:17 +08:00
yukang
f65b875e83 remove type_ascription_path_suggestions in parser 2023-05-01 16:15:16 +08:00
yukang
9569a0129c Remove more diagnostics for ascription in resolve 2023-05-01 16:15:16 +08:00
Nilstrieb
c63b6a437e Rip it out
My type ascription
Oh rip it out
Ah
If you think we live too much then
You can sacrifice diagnostics
Don't mix your garbage
Into my syntax
So many weird hacks keep diagnostics alive
Yet I don't even step outside
So many bad diagnostics keep tyasc alive
Yet tyasc doesn't even bother to survive!
2023-05-01 16:15:13 +08:00
Matthias Krüger
a656a2019a
Rollup merge of #110984 - cjgillot:const-infer-lifetime, r=compiler-errors
Do not resolve anonymous lifetimes in consts to be static.

Fixes https://github.com/rust-lang/rust/issues/110931
2023-04-30 01:14:59 +02:00
Camille GILLOT
63028ac3a1 Do not force anonymous lifetimes in consts to be static. 2023-04-29 10:32:31 +00:00
Michael Goulet
4e05cfb5ff Don't duplicate anonymous lifetimes for async fn in traits 2023-04-28 20:21:03 +00:00
clubby789
0138513635 Fix static string lints 2023-04-25 18:59:55 +01:00
Maybe Waffle
e496fbec92 Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
Matthias Krüger
0f271619e4
Rollup merge of #110255 - clubby789:proc-macro-test-help, r=jackh726
Suggest using integration tests for test crate using own proc-macro

cc #110247
2023-04-24 07:53:23 +02:00
bors
fec9adcdbc Auto merge of #110648 - Dylan-DPC:rollup-em3ovcq, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #110333 (rustc_metadata: Split `children` into multiple tables)
 - #110501 (rustdoc: fix ICE from rustc_resolve and librustdoc parse divergence)
 - #110608 (Specialize some `io::Read` and `io::Write` methods for `VecDeque<u8>` and `&[u8]`)
 - #110632 (Panic instead of truncating if the incremental on-disk cache is too big)
 - #110633 (More `mem::take` in `library`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-04-21 19:43:11 +00:00
Dylan DPC
fbc905e16a
Rollup merge of #110501 - notriddle:notriddle/ice-110495, r=petrochenkov
rustdoc: fix ICE from rustc_resolve and librustdoc parse divergence

Fixes #110495
2023-04-21 20:35:28 +05:30
Vadim Petrochenkov
53c71b6ab3 resolve: Remove module_children_untracked 2023-04-19 16:35:08 +03:00
bors
d7f9e81650 Auto merge of #110407 - Nilstrieb:fluent-macro, r=davidtwco
Add `rustc_fluent_macro` to decouple fluent from `rustc_macros`

Fluent, with all the icu4x it brings in, takes quite some time to compile. `fluent_messages!` is only needed in further downstream rustc crates, but is blocking more upstream crates like `rustc_index`. By splitting it out, we allow `rustc_macros` to be compiled earlier, which speeds up `x check compiler` by about 5 seconds (and even more after the needless dependency on `serde_json` is removed from `rustc_data_structures`).
2023-04-19 08:26:47 +00:00
bors
c609da59d9 Auto merge of #109772 - petrochenkov:slimchild, r=cjgillot
rustc_metadata: Remove `Span` from `ModChild`

It can be decoded on demand from regular `def_span` tables.

Partially mitigates perf regressions from https://github.com/rust-lang/rust/pull/109500.
2023-04-18 20:16:56 +00:00
Michael Howell
df8a48fc8a rustdoc: fix ICE from rustc_resolve and librustdoc parse divergence 2023-04-18 12:22:13 -07:00
Nilstrieb
b5d3d970fa Add rustc_fluent_macro to decouple fluent from rustc_macros
Fluent, with all the icu4x it brings in, takes quite some time to
compile. `fluent_messages!` is only needed in further downstream rustc
crates, but is blocking more upstream crates like `rustc_index`. By
splitting it out, we allow `rustc_macros` to be compiled earlier, which
speeds up `x check compiler` by about 5 seconds (and even more after the
needless dependency on `serde_json` is removed from
`rustc_data_structures`).
2023-04-18 18:56:22 +00:00
Vadim Petrochenkov
ec8f68859a rustc_metadata: Remove Span from ModChild
It can be decoded on demand from regular `def_span` tables.

Partially mitigates perf regressions from #109500.
2023-04-18 17:25:04 +03:00
Josh Soref
e09d0d2a29 Spelling - compiler
* account
* achieved
* advising
* always
* ambiguous
* analysis
* annotations
* appropriate
* build
* candidates
* cascading
* category
* character
* clarification
* compound
* conceptually
* constituent
* consts
* convenience
* corresponds
* debruijn
* debug
* debugable
* debuggable
* deterministic
* discriminant
* display
* documentation
* doesn't
* ellipsis
* erroneous
* evaluability
* evaluate
* evaluation
* explicitly
* fallible
* fulfill
* getting
* has
* highlighting
* illustrative
* imported
* incompatible
* infringing
* initialized
* into
* intrinsic
* introduced
* javascript
* liveness
* metadata
* monomorphization
* nonexistent
* nontrivial
* obligation
* obligations
* offset
* opaque
* opportunities
* opt-in
* outlive
* overlapping
* paragraph
* parentheses
* poisson
* precisely
* predecessors
* predicates
* preexisting
* propagated
* really
* reentrant
* referent
* responsibility
* rustonomicon
* shortcircuit
* simplifiable
* simplifications
* specify
* stabilized
* structurally
* suggestibility
* translatable
* transmuting
* two
* unclosed
* uninhabited
* visibility
* volatile
* workaround

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-17 16:09:18 -04:00