about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src
AgeCommit message (Collapse)AuthorLines
2025-01-09Auto merge of #135268 - pietroalbini:pa-bump-stage0, r=Mark-Simulacrumbors-1/+1
Master bootstrap update Part of the release process. r? `@Mark-Simulacrum`
2025-01-08update cfg(bootstrap)Pietro Albini-1/+1
2025-01-08Add check for missing fields in enum variant patternEsteban Küber-1/+1
2025-01-07Ensure that we don't try to access fields on a non-struct pattern type in ↵Esteban Küber-1/+3
diagnostic Fix #135209.
2024-12-22Fix spacing of markdown code block fences in compiler rustdocDavid Tolnay-1/+4
2024-12-18Rollup merge of #134473 - acceptacross:master, r=compiler-errorsJacob Pratt-1/+1
chore: fix some typos
2024-12-18chore: fix some typosacceptacross-1/+1
Signed-off-by: acceptacross <csqcqs@gmail.com>
2024-12-18Stabilize `#[diagnostic::do_not_recommend]`Georg Semmler-2/+1
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: https://github.com/rust-lang/rust/blob/e1f306899514ea80abc1d1c9f6a57762afb304a3/tests/ui/diagnostic_namespace/do_not_recommend/supress_suggestions_in_help.rs (No more tuple pyramids) Fixes #51992
2024-12-18Auto merge of #134243 - nnethercote:re-export-more-rustc_span, r=jieyouxubors-24/+12
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-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-24/+12
`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-18Auto merge of #134439 - matthiaskrgr:rollup-grmmmx2, r=matthiaskrgrbors-4/+4
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-17Rollup merge of #133265 - the8472:extract-if-ranges, r=cuviperMatthias Krüger-4/+4
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-17Auto merge of #134376 - jdonszelmann:fix-rustdoc-perf, r=jieyouxubors-2/+3
Try to fix perf regression in rustdoc after hir attributes Slight performance regression introduced in #131808 r? `@jieyouxu`
2024-12-17Auto merge of #134381 - jdonszelmann:move-attribute-types, r=oli-obkbors-11/+12
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-16update uses of extract_if in the compilerThe 8472-4/+4
2024-12-16Rollup merge of #134284 - estebank:issue-74863, r=lcnrMatthias Krüger-4/+79
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-16rename rustc_attr to rustc_attr_parsing and create rustc_attr_data_structuresJonathan Dönszelmann-2/+2
2024-12-16split attributesJonathan Dönszelmann-10/+11
2024-12-16try fix hir-attrs perfJonathan Dönszelmann-2/+3
2024-12-15Use `span_label` as it looks better when we show pattern missing binding in ↵Esteban Küber-22/+5
order
2024-12-15Use `ErrorGuaranteed` moreEsteban Küber-6/+11
2024-12-15Add hir::AttributeJonathan Dönszelmann-22/+21
2024-12-15Rename `value` field to `expr` to simplify later commits' diffsOli Scherer-2/+2
2024-12-14Don't make a def id for impl_trait_in_bindingsMichael Goulet-0/+10
2024-12-13Keep track of patterns that could have introduced a binding, but didn'tEsteban Küber-3/+90
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-13Rollup merge of #134140 - compiler-errors:unsafe-binders-ast, r=oli-obkMatthias Krüger-0/+22
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-12Lower AST and resolve lifetimes for unsafe binder typesMichael Goulet-0/+22
2024-12-10Silence `use foo::Bar;` error if `Bar` isn't found in `foo` and `foo.rs` has ↵Esteban Küber-1/+6
parse errors
2024-12-10Keep track of parse errors in `mod`s and don't emit resolve errors for paths ↵Esteban Küber-32/+74
involving them When we expand a `mod foo;` and parse `foo.rs`, we now track whether that file had an unrecovered parse error that reached the end of the file. If so, we keep that information around. When resolving a path like `foo::bar`, we do not emit any errors for "`bar` not found in `foo`", as we know that the parse error might have caused `bar` to not be parsed and accounted for. When this happens in an existing project, every path referencing `foo` would be an irrelevant compile error. Instead, we now skip emitting anything until `foo.rs` is fixed. Tellingly enough, we didn't have any test for errors caused by `mod` expansion. Fix #97734.
2024-12-09review comments: rewordingsEsteban Küber-1/+1
2024-12-09Introduce `default_field_values` featureEsteban Küber-4/+23
Initial implementation of `#[feature(default_field_values]`, proposed in https://github.com/rust-lang/rfcs/pull/3681. Support default fields in enum struct variant Allow default values in an enum struct variant definition: ```rust pub enum Bar { Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Allow using `..` without a base on an enum struct variant ```rust Bar::Foo { .. } ``` `#[derive(Default)]` doesn't account for these as it is still gating `#[default]` only being allowed on unit variants. Support `#[derive(Default)]` on enum struct variants with all defaulted fields ```rust pub enum Bar { #[default] Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Check for missing fields in typeck instead of mir_build. Expand test with `const` param case (needs `generic_const_exprs` enabled). Properly instantiate MIR const The following works: ```rust struct S<A> { a: Vec<A> = Vec::new(), } S::<i32> { .. } ``` Add lint for default fields that will always fail const-eval We *allow* this to happen for API writers that might want to rely on users' getting a compile error when using the default field, different to the error that they would get when the field isn't default. We could change this to *always* error instead of being a lint, if we wanted. This will *not* catch errors for partially evaluated consts, like when the expression relies on a const parameter. Suggestions when encountering `Foo { .. }` without `#[feature(default_field_values)]`: - Suggest adding a base expression if there are missing fields. - Suggest enabling the feature if all the missing fields have optional values. - Suggest removing `..` if there are no missing fields.
2024-12-03Rollup merge of #133545 - clubby789:symbol-intern-lit, r=jieyouxuMatthias Krüger-1/+2
Lint against Symbol::intern on a string literal Disabled in tests where this doesn't make much sense
2024-12-02Add a helper method for extracting spans from AttrArgsEqOli Scherer-2/+2
2024-12-02Change `AttrArgs::Eq` into a struct variantOli Scherer-1/+1
2024-11-28Replace `Symbol::intern` calls with preinterned symbolsclubby789-1/+2
2024-11-28always create `DefId`s when lowering anon-constslcnr-147/+28
2024-11-27Auto merge of #133274 - ehuss:macro_rules-edition-from-pm, r=compiler-errorsbors-1/+1
Use edition of `macro_rules` when compiling the macro This changes the edition assigned to a macro_rules macro when it is compiled to use the edition of where the macro came from instead of the local crate's edition. This fixes a problem when a macro_rules macro is created by a proc-macro. Previously that macro would be tagged with the local edition, which would cause problems with using the correct edition behavior inside the macro. For example, the check for unsafe attributes would cause errors in 2024 when using proc-macros from older editions. This is partially related to https://github.com/rust-lang/rust/issues/132906. Unfortunately this is only a half fix for that issue. It fixes the error that happens in 2024, but does not fix the lint firing in 2021. I'm still trying to think of some way to fix that, but I'm running low on ideas.
2024-11-25Refactor `where` predicates, and reserve for attributes supportFrank King-24/+26
2024-11-25Rollup merge of #133105 - bvanjoi:issue-132743, r=petrochenkov许杰友 Jieyou Xu (Joe)-15/+17
only store valid proc macro item for doc link Fixes #132743 The definition item can be detected if it is exported in the doc, so store these items rather than skipping. r? `@petrochenkov`
2024-11-23Auto merge of #131859 - chriskrycho:update-trpl, r=onur-ozkanbors-1/+1
Update TRPL to add new Chapter 17: Async and Await - Add support to `rustbook` to pass through the `-L`/`--library-path` flag to `mdbook` so that references to the `trpl` crate - Build the `trpl` crate as part of the book tests. Make it straightforward to add other such book dependencies in the future if needed by implementing that in a fairly general way. - Update the submodule for the book to pull in the new chapter on async and await, as well as a number of other fixes. This will happen organically/automatically in a week, too, but this lets me group this change with the next one: - Update the compiler messages which reference the existing chapters 17–20, which are now chapters 18-21. There are only two, both previously referencing chapter 18. - Update the UI tests which reference the compiler message outputs.
2024-11-23Update tests for new TRPL chapter orderChris Krycho-1/+1
2024-11-23Rollup merge of #133286 - jieyouxu:bug-ourselves, r=compiler-errors许杰友 Jieyou Xu (Joe)-3/+3
Re-delay a resolve `bug` related to `Self`-ctor in patterns For the code pattern reported in <https://github.com/rust-lang/rust/issues/133272>, ```rs impl Foo { fn fun() { let S { ref Self } = todo!(); } } ``` <https://github.com/rust-lang/rust/pull/121208> converted this to a `span_bug` from a `span_delayed_bug` because this specific self-ctor code pattern lacked test coverage. It turns out this can be hit but we just lacked test coverage, so change it back to a `span_delayed_bug` and add a targeted test case. Follow-up to #121208, cc ``@nnethercote`` (very good exercise to expose our test coverage gaps). Fixes #133272.
2024-11-23Rollup merge of #132949 - clubby789:macro-rules-attr-derive, r=fmease许杰友 Jieyou Xu (Joe)-3/+31
Add specific diagnostic for using macro_rules macro as attribute/derive Fixes #132928
2024-11-23only store valid proc marco item for doc linkbohan-15/+17
2024-11-22Diagnostic for using macro_rules macro as attr/deriveclubby789-3/+31
2024-11-21Re-delay a resolve `bug`Jieyou Xu-3/+3
For the code pattern reported in <https://github.com/rust-lang/rust/issues/133272>, ```rs impl Foo { fn fun() { let S { ref Self } = todo!(); } } ``` <https://github.com/rust-lang/rust/pull/121208> converted this to a `span_bug` from a `span_delayed_bug` because this specific self-ctor code pattern lacked test coverage. It turns out this can be hit but we just lacked test coverage, so change it back to a `span_delayed_bug` and add a target tested case.
2024-11-20Use edition of `macro_rules` when compiling the macroEric Huss-1/+1
2024-11-20Store resolution for self and crate root module segmentsMichael Goulet-4/+10
2024-11-19Auto merge of #132761 - nnethercote:resolve-tweaks, r=petrochenkovbors-92/+51
Resolve tweaks A couple of small perf improvements, and some minor refactorings, all in `rustc_resolve`. r? `@petrochenkov`
2024-11-16Rollup merge of #132787 - maxcabrajac:fnctxt, r=petrochenkovMatthias Krüger-1/+1
Unify FnKind between AST visitors and make WalkItemKind more straight forward Unifying `FnKind` requires a bunch of changes to `WalkItemKind::walk` signature so I'll change them in one go related to #128974 r? `@petrochenkov`