Commit graph

2080 commits

Author SHA1 Message Date
Celina G. Val
c22a27130d Refactor FnKind variant to hold &Fn 2025-01-28 11:22:25 -08:00
Michael Goulet
c08624d8d2 Remove redundant to_ident_string calls 2025-01-27 01:23:34 +00:00
Michael Goulet
ac1c6c50f4 Use identifiers in diagnostics more often 2025-01-27 01:23:34 +00:00
bors
203e6c127c Auto merge of #133154 - estebank:issue-133137, r=wesleywiser
Reword resolve errors caused by likely missing crate in dep tree

Reword label and add `help`:

```
error[E0432]: unresolved import `some_novel_crate`
 --> f704.rs:1:5
  |
1 | use some_novel_crate::Type;
  |     ^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `some_novel_crate`
  |
  = help: if you wanted to use a crate named `some_novel_crate`, use `cargo add some_novel_crate` to add it to your `Cargo.toml`
```

Fix #133137.
2025-01-25 11:41:21 +00:00
Esteban Küber
dd52bfc76e Reword "crate not found" resolve message
```
error[E0432]: unresolved import `some_novel_crate`
 --> file.rs:1:5
  |
1 | use some_novel_crate::Type;
  |     ^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `some_novel_crate`
```

On resolve errors where there might be a missing crate, mention `cargo add foo`:

```
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `nope`
  --> $DIR/conflicting-impl-with-err.rs:4:11
   |
LL | impl From<nope::Thing> for Error {
   |           ^^^^ use of unresolved module or unlinked crate `nope`
   |
   = help: if you wanted to use a crate named `nope`, use `cargo add nope` to add it to your `Cargo.toml`
```
2025-01-24 01:19:50 +00:00
Yotam Ofek
efabee2dee rustc_resolve: don't open-code Option::filter 2025-01-21 13:44:53 +00:00
Yotam Ofek
6f22dfe4df rustc_resolve: use Iterator combinators instead of for loops where applicable 2025-01-21 13:44:49 +00:00
Yotam Ofek
ae87d005bc rustc_resolve: reduce rightwards drift with let..else 👉💨 2025-01-21 13:42:32 +00:00
Yotam Ofek
cf91a93d09 rustc_resolve: flatten nested ifs 2025-01-21 13:34:12 +00:00
Yotam Ofek
a93616acf3 rustc_resolve: remove unneeded returns 2025-01-21 13:34:12 +00:00
许杰友 Jieyou Xu (Joe)
3e26673b29
Rollup merge of #135676 - yotamofek:resolve-cleanups, r=BoxyUwU
rustc_resolve: use structured fields in traces

I think this crate was written before `tracing` was adopted, and was manually writing fields into trace logs instead of using structured fields.

I kept function names in the trace messages even though I added `#[instrument]` invocations so that the events will be in named spans, wasn't sure if spans are always printed.
2025-01-20 21:45:06 +08:00
bors
b5741a36a8 Auto merge of #135754 - jieyouxu:rollup-j4q1hpr, r=jieyouxu
Rollup of 7 pull requests

Successful merges:

 - #135542 (Add the concrete syntax for precise capturing to 1.82 release notes.)
 - #135700 (Emit single privacy error for struct literal with multiple private fields and add test for `default_field_values` privacy)
 - #135722 (make it possible to use ci-rustc on tarball sources)
 - #135729 (Add debug assertions to compiler profile)
 - #135736 (rustdoc: Fix flaky doctest test)
 - #135738 (Replace usages of `map_or(bool, ...)` with `is_{some_and|none_or|ok_and}`)
 - #135747 (Rename FileName::QuoteExpansion to CfgSpec)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-20 10:35:43 +00:00
Yotam Ofek
539b4d8555 rustc_resolve: use structured fields in traces 2025-01-20 07:20:02 +00:00
许杰友 Jieyou Xu (Joe)
be8f1f9949
Rollup merge of #134276 - RalfJung:destabilize-custom-inner-attr, r=SparrowLii
fully de-stabilize all custom inner attributes

`#![test]` and `#![rustfmt::skip]` were accidentally accepted in more places than they should. These have been marked as soft-unstable since forever (https://github.com/rust-lang/rust/pull/82399) and shown in future-compat reports since Rust 1.77 (https://github.com/rust-lang/rust/pull/116274).

Cc `@rust-lang/lang` `@petrochenkov`
2025-01-20 12:38:30 +08:00
Yotam Ofek
264fa0fc54 Run clippy --fix for unnecessary_map_or lint 2025-01-19 19:15:00 +00:00
Ralf Jung
5bd20b0608 fully de-stabilize all custom inner attributes 2025-01-19 08:53:02 -07:00
Frank King
067cac91f9 Fix ICE in resolving associated items as non-bindings 2025-01-18 08:38:50 +08:00
Matthias Krüger
62d0f457d4
Rollup merge of #134754 - frank-king:feature/import_trait_associated_functions, r=oli-obk
Implement `use` associated items of traits

This PR implements #134691.
2025-01-16 18:46:08 +01:00
Frank King
5079acc060 Implement use associated items of traits 2025-01-16 16:34:05 +08:00
bors
341f60327f Auto merge of #134353 - oli-obk:safe-target-feature-unsafe-by-default, r=wesleywiser
Treat safe target_feature functions as unsafe by default [less invasive variant]

This unblocks
* #134090

As I stated in https://github.com/rust-lang/rust/pull/134090#issuecomment-2541332415 I think the previous impl was too easy to get wrong, as by default it treated safe target feature functions as safe and had to add additional checks for when they weren't. Now the logic is inverted. By default they are unsafe and you have to explicitly handle safe target feature functions.

This is the less (imo) invasive variant of #134317, as it doesn't require changing the Safety enum, so it only affects FnDefs and nothing else, as it should.
2025-01-15 12:06:56 +00:00
Michael Goulet
2743df848b Enforce syntactical stability of const traits in HIR 2025-01-14 19:12:08 +00:00
Oli Scherer
a907c56a77 Add hir::HeaderSafety to make follow up commits simpler 2025-01-14 10:54:11 +00:00
Josh Triplett
9c5b99dc92 Deny clippy:;four_forward_slashes and fix the only occurrence 2025-01-12 15:09:16 +02:00
bors
251206c27b Auto merge of #135268 - pietroalbini:pa-bump-stage0, r=Mark-Simulacrum
Master bootstrap update

Part of the release process.

r? `@Mark-Simulacrum`
2025-01-09 13:33:16 +00:00
Pietro Albini
2af3ba9a8a
update cfg(bootstrap) 2025-01-08 21:26:39 +01:00
Esteban Küber
d44f021904 Add check for missing fields in enum variant pattern 2025-01-08 00:10:16 +00:00
Esteban Küber
5f04f98c9a Ensure that we don't try to access fields on a non-struct pattern type in diagnostic
Fix #135209.
2025-01-07 22:06:58 +00:00
David Tolnay
34b33a6763
Fix spacing of markdown code block fences in compiler rustdoc 2024-12-22 10:16:31 -08:00
Jacob Pratt
0391770c07
Rollup merge of #134473 - acceptacross:master, r=compiler-errors
chore: fix some typos
2024-12-18 21:38:10 -05:00
acceptacross
6734a04c0a chore: fix some typos
Signed-off-by: acceptacross <csqcqs@gmail.com>
2024-12-18 23:23:44 +08:00
Georg Semmler
dd31713c53
Stabilize #[diagnostic::do_not_recommend]
This commit seeks to stabilize the `#[diagnostic::do_not_recommend]`
attribute.
This attribute was first proposed as `#[do_not_recommend`] attribute in
RFC 2397 (https://github.com/rust-lang/rfcs/pull/2397). It gives the
crate authors the ability to not suggest to the compiler to not show
certain traits in it's error messages. With the presence of the
`#[diagnostic]` tool attribute namespace it was decided to move the
attribute there, as that lowers the amount of guarantees the compiler
needs to give about the exact way this influences error messages. It
turns the attribute into a hint which can be ignored. In addition to the
original proposed functionality this attribute now also hides the marked
trait in help messages ("This trait is implemented by: ").
The attribute does not accept any argument and can only be placed on
trait implementations. If it is placed somewhere else a lint warning is
emitted and the attribute is otherwise ignored. If an argument is
detected a lint warning is emitted and the argument is ignored. This
follows the rules outlined by the diagnostic namespace.

This attribute allows crates like diesel to improve their error messages
drastically. The most common example here is the following error
message:

```
error[E0277]: the trait bound `&str: Expression` is not satisfied
  --> /home/weiznich/Documents/rust/rust/tests/ui/diagnostic_namespace/do_not_recommend.rs:53:15
   |
LL |     SelectInt.check("bar");
   |               ^^^^^ the trait `Expression` is not implemented for `&str`, which is required by `&str: AsExpression<Integer>`
   |
   = help: the following other types implement trait `Expression`:
             Bound<T>
             SelectInt
note: required for `&str` to implement `AsExpression<Integer>`
  --> /home/weiznich/Documents/rust/rust/tests/ui/diagnostic_namespace/do_not_recommend.rs:26:13
   |
LL | impl<T, ST> AsExpression<ST> for T
   |             ^^^^^^^^^^^^^^^^     ^
LL | where
LL |     T: Expression<SqlType = ST>,
   |        ------------------------ unsatisfied trait bound introduced here
```

By applying the new attribute to the wild card trait implementation of
`AsExpression` for `T: Expression` the error message becomes:

```
error[E0277]: the trait bound `&str: AsExpression<Integer>` is not satisfied
  --> $DIR/as_expression.rs:55:15
   |
LL |     SelectInt.check("bar");
   |               ^^^^^ the trait `AsExpression<Integer>` is not implemented for `&str`
   |
   = help: the trait `AsExpression<Text>` is implemented for `&str`
   = help: for that trait implementation, expected `Text`, found `Integer`
```

which makes it much easier for users to understand that they are facing
a type mismatch.

Other explored example usages included

* This standard library error message: https://github.com/rust-lang/rust/pull/128008
* That bevy derived example:
e1f3068995/tests/ui/diagnostic_namespace/do_not_recommend/supress_suggestions_in_help.rs (No
more tuple pyramids)

Fixes #51992
2024-12-18 07:10:53 +01:00
bors
a89ca2c85e Auto merge of #134243 - nnethercote:re-export-more-rustc_span, r=jieyouxu
Re-export more `rustc_span::symbol` things from `rustc_span`.

`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason.

This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers to `rustc_span::`. This is a 300+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.

r? `@jieyouxu`
2024-12-18 02:56:38 +00:00
Nicholas Nethercote
2620eb42d7 Re-export more rustc_span::symbol things from rustc_span.
`rustc_span::symbol` defines some things that are re-exported from
`rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some
closely related things such as `Ident` and `kw`. So you can do `use
rustc_span::{Symbol, sym}` but you have to do `use
rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good
reason.

This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`,
and changes many `rustc_span::symbol::` qualifiers in `compiler/` to
`rustc_span::`. This is a 200+ net line of code reduction, mostly
because many files with two `use rustc_span` items can be reduced to
one.
2024-12-18 13:38:53 +11:00
bors
52890e8215 Auto merge of #134439 - matthiaskrgr:rollup-grmmmx2, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #133265 (Add a range argument to vec.extract_if)
 - #133801 (Promote powerpc64le-unknown-linux-musl to tier 2 with host tools)
 - #134323 (coverage: Dismantle `map_data.rs` by moving its responsibilities elsewhere)
 - #134378 (An octuple of polonius fact generation cleanups)
 - #134408 (Regression test for RPIT inheriting lifetime from projection)
 - #134423 (bootstrap: use specific-purpose ui test path for `test_valid` self-test)
 - #134426 (Fix typo in uint_macros.rs)

Failed merges:

 - #133103 (Pass FnAbi to find_mir_or_eval_fn)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-12-18 00:14:56 +00:00
Matthias Krüger
938742e687
Rollup merge of #133265 - the8472:extract-if-ranges, r=cuviper
Add a range argument to vec.extract_if

tracking issue: #43244

This adds the range argument requested in https://github.com/rust-lang/rust/issues/43244#issuecomment-2486160659
2024-12-17 22:34:40 +01:00
bors
7e6bf003f3 Auto merge of #134376 - jdonszelmann:fix-rustdoc-perf, r=jieyouxu
Try to fix perf regression in rustdoc after hir attributes

Slight performance regression introduced in #131808

r? `@jieyouxu`
2024-12-17 21:34:13 +00:00
bors
a4cb3c8318 Auto merge of #134381 - jdonszelmann:move-attribute-types, r=oli-obk
Split up attribute parsing code and move data types to `rustc_attr_data_structures`

This change renames `rustc_attr` to `rustc_attr_parsing`, and splits up the parsing code. At the same time, all the data types used move to `rustc_attr_data_structures`. This is in preparation of also having a third crate: `rustc_attr_validation`

I initially envisioned this as two separate PRs, but I think doing it in one go reduces the number of ways others would have to rebase their changes on this. However, I can still split them.

r? `@oli-obk` (we already discussed how this is a first step in a larger plan)

For a more detailed plan on how attributes are going to change, see https://github.com/rust-lang/rust/issues/131229

Edit: this looks like a giant PR, but the changes are actually rather trivial. Each commit is reviewable on its own, and mostly moves code around. No new logic is added.
2024-12-17 18:50:50 +00:00
The 8472
fe521506a6 update uses of extract_if in the compiler 2024-12-16 22:06:52 +01:00
Matthias Krüger
86db97e2b3
Rollup merge of #134284 - estebank:issue-74863, r=lcnr
Keep track of patterns that could have introduced a binding, but didn't

When we recover from a pattern parse error, or a pattern uses `..`, we keep track of that and affect resolution error for missing bindings that could have been provided by that pattern. We differentiate between `..` and parse recovery. We silence resolution errors likely caused by the pattern parse error.

```
error[E0425]: cannot find value `title` in this scope
  --> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:18:30
   |
LL |     if let Website { url, .. } = website {
   |            ------------------- this pattern doesn't include `title`, which is available in `Website`
LL |         println!("[{}]({})", title, url);
   |                              ^^^^^ not found in this scope
```

Fix #74863.
2024-12-16 20:00:22 +01:00
Jonathan Dönszelmann
efb98b6552
rename rustc_attr to rustc_attr_parsing and create rustc_attr_data_structures 2024-12-16 19:08:19 +01:00
Jonathan Dönszelmann
1341366af9
split attributes 2024-12-16 19:08:19 +01:00
Jonathan Dönszelmann
62a21038ec
try fix hir-attrs perf 2024-12-16 10:00:38 +01:00
Esteban Küber
733fd03f0f Use span_label as it looks better when we show pattern missing binding in order 2024-12-15 22:58:16 +00:00
Esteban Küber
8c8e8d35bc Use ErrorGuaranteed more 2024-12-15 22:48:05 +00:00
Jonathan Dönszelmann
d50c0a5480
Add hir::Attribute 2024-12-15 19:18:46 +01:00
Oli Scherer
53b2c7cc95 Rename value field to expr to simplify later commits' diffs 2024-12-15 18:47:45 +01:00
Michael Goulet
ca055ee7db Don't make a def id for impl_trait_in_bindings 2024-12-14 18:08:30 +00:00
Esteban Küber
0f82cfffda Keep track of patterns that could have introduced a binding, but didn't
When we recover from a pattern parse error, or a pattern uses `..`, we keep track of that and affect resolution error for missing bindings that could have been provided by that pattern. We differentiate between `..` and parse recovery. We silence resolution errors likely caused by the pattern parse error.

```
error[E0425]: cannot find value `title` in this scope
  --> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:19:30
   |
LL |         println!("[{}]({})", title, url);
   |                              ^^^^^ not found in this scope
   |
note: `Website` has a field `title` which could have been included in this pattern, but it wasn't
  --> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:17:12
   |
LL | / struct Website {
LL | |     url: String,
LL | |     title: Option<String> ,
   | |     ----- defined here
LL | | }
   | |_-
...
LL |       if let Website { url, .. } = website {
   |              ^^^^^^^^^^^^^^^^^^^ this pattern doesn't include `title`, which is available in `Website`
```

Fix #74863.
2024-12-13 21:51:33 +00:00
Matthias Krüger
5c9b227a3d
Rollup merge of #134140 - compiler-errors:unsafe-binders-ast, r=oli-obk
Add AST support for unsafe binders

I'm splitting up #130514 into pieces. It's impossible for me to keep up with a huge PR like that. I'll land type system support for this next, probably w/o MIR lowering, which will come later.

r? `@oli-obk`
cc `@BoxyUwU` and `@lcnr` who also may want to look at this, though this PR doesn't do too much yet
2024-12-13 17:25:31 +01:00
Michael Goulet
2a9e358c72 Lower AST and resolve lifetimes for unsafe binder types 2024-12-12 16:29:40 +00:00