about summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src/path.rs
AgeCommit message (Collapse)AuthorLines
2025-08-09remove `P`Deadbeef-1/+1
2025-06-03Overhaul `UsePath`.Nicholas Nethercote-4/+4
`UsePath` contains a `SmallVec<[Res; 3]>`. This holds up to three `Res` results, one per namespace (type, value, or macro). `lower_import_res` takes a `PerNS<Option<Res<NodeId>>>` result and lowers it into the `SmallVec`. This is pretty weird. The input `PerNS` makes it clear which `Res` belongs to which namespace, but the `SmallVec` throws that information away. And code that operates on the `SmallVec` tends to use iteration (or even just grabbing the first entry!) without knowing which namespace the `Res` belongs to. Even weirder! Also, `SmallVec` is an overly flexible type to use here, because it can contain any number of elements (even though it's optimized for 3 in this case). This commit changes `UsePath` so it also contains a `PerNS<Option<Res<HirId>>>`. This type preserves more information and is more self-documenting. The commit also changes a lot of the use sites to access the result for a particular namespace. E.g. if you're looking up a trait, it will be in the `Res` for the type namespace if it's present; it's silly to look in the `Res` for the value namespace or macro namespace. Overall I find the new code much easier to understand. However, some use sites still iterate. These now use `present_items` because that filters out the `None` results. Also, `redundant_pub_crate.rs` gets a bigger change. A `UseKind:ListStem` item gets no `Res` results, which means the old `all` call in `is_not_macro_export` would succeed (because `all` succeeds on an empty iterator) and the `ListStem` would be ignored. This is what we want, but was more by luck than design. The new code detects `ListStem` explicitly. The commit generalizes the name of that function accordingly. Finally, the commit also removes the `use_path` arena, because `PerNS<Option<Res>>` impls `Copy` (unlike `SmallVec`) and it can be allocated in the arena shared by all `Copy` types.
2025-05-02Handle `Path<>` better in error messages.Nicholas Nethercote-13/+17
`Path<>` needs to be distinguished from `Path<T>`. This commit does that, improving some error messages.
2025-04-23Extend HIR to track the source and syntax of a lifetimeJake Goulding-7/+10
An upcoming lint will want to be able to know if a lifetime is hidden (e.g. `&u8`, `ContainsLifetime`) or anonymous: (e.g. `&'_ u8`, `ContainsLifetime<'_>`). It will also want to know if the lifetime is related to a reference (`&u8`) or a path (`ContainsLifetime`).
2025-04-22Use `is_lang_item` and `as_lang_item` instead of handrolling their logicOli Scherer-9/+5
2025-04-14Use `newtype_index!`-generated types more idiomaticallyYotam Ofek-2/+1
2025-03-28Don't use `kw::Empty` in `hir::Lifetime::ident`.Nicholas Nethercote-5/+2
`hir::Lifetime::ident` currently sometimes uses `kw::Empty` for elided lifetimes and sometimes uses `kw::UnderscoreLifetime`, and the distinction is used when creating some error suggestions, e.g. in `Lifetime::suggestion` and `ImplicitLifetimeFinder::visit_ty`. I found this *really* confusing, and it took me a while to understand what was going on. This commit replaces all uses of `kw::Empty` in `hir::Lifetime::ident` with `kw::UnderscoreLifetime`. It adds a new field `hir::Lifetime::is_path_anon` that mostly replaces the old empty/underscore distinction and makes things much clearer. Some other notable changes: - Adds a big comment to `Lifetime` talking about permissable field values. - Adds some assertions in `new_named_lifetime` about what ident values are permissible for the different `LifetimeRes` values. - Adds a `Lifetime::new` constructor that does some checking to make sure the `is_elided` and `is_anonymous` states are valid. - `add_static_impl_trait_suggestion` now looks at `Lifetime::res` instead of the ident when creating the suggestion. This is the one case where `is_path_anon` doesn't replace the old empty/underscore distinction. - A couple of minor pretty-printing improvements.
2025-03-03Provide more context on resolve error caused from incorrect RTNEsteban Küber-1/+0
When encountering a resolve E0575 error for an associated method (when a type was expected), see if it could have been an intended return type notation bound. ``` error[E0575]: expected associated type, found associated function `Trait::method` --> $DIR/bad-inputs-and-output.rs:31:36 | LL | fn foo_qualified<T: Trait>() where <T as Trait>::method(i32): Send {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ not a associated type | help: you might have meant to use the return type notation syntax | LL - fn foo_qualified<T: Trait>() where <T as Trait>::method(i32): Send {} LL + fn foo_qualified<T: Trait>() where T::method(..): Send {} | ```
2025-02-28Tweak invalid RTN errorsEsteban Küber-13/+21
Make suggestions verbose. When encountering `method(type)` bound, suggest `method(..)` instead of `method()`. ``` error: argument types not allowed with return type notation --> $DIR/bad-inputs-and-output.rs:9:23 | LL | fn foo<T: Trait<method(i32): Send>>() {} | ^^^^^ | help: remove the input types | LL - fn foo<T: Trait<method(i32): Send>>() {} LL + fn foo<T: Trait<method(..): Send>>() {} | ``` When encountering both return type and arg list that isn't `..`, suggest replacing both. ``` error: return type not allowed with return type notation --> $DIR/bad-inputs-and-output.rs:12:25 | LL | fn bar<T: Trait<method() -> (): Send>>() {} | ^^^^^^ | help: use the right argument notation and remove the return type | LL - fn bar<T: Trait<method() -> (): Send>>() {} LL + fn bar<T: Trait<method(..): Send>>() {} | ``` When encountering a return type, suggest removing it including the leading whitespace. ``` error: return type not allowed with return type notation --> $DIR/bad-inputs-and-output.rs:24:45 | LL | fn bay_path<T: Trait>() where T::method(..) -> (): Send {} | ^^^^^ | help: remove the return type | LL - fn bay_path<T: Trait>() where T::method(..) -> (): Send {} LL + fn bay_path<T: Trait>() where T::method(..): Send {} | ```
2025-02-03tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc`Askar Safin-4/+5
2025-01-23Split hir `TyKind` and `ConstArgKind` in two and update `hir::Visitor`Boxy-1/+3
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+1
`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-10-29Rollup merge of #131375 - klensy:clone_on_ref_ptr, r=cjgillotJubilee-1/+1
compiler: apply clippy::clone_on_ref_ptr for CI Apply lint https://rust-lang.github.io/rust-clippy/master/index.html#/clone_on_ref_ptr for compiler, also see https://github.com/rust-lang/rust/pull/131225#discussion_r1790109443. Some Arc's can be misplaced with Lrc's, sorry. https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/enable.20more.20clippy.20lints.20for.20compiler.20.28and.5Cor.20std.29
2024-10-28fix clippy::clone_on_ref_ptr for compilerklensy-1/+1
2024-10-27Move an impl-Trait check from AST validation to AST loweringLeón Orell Valerian Liehr-3/+16
2024-10-23nightly feature tracking: get rid of the per-feature bool fieldsRalf Jung-2/+2
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-4/+4
2024-09-20Add missing diagnostics and flesh out testsMichael Goulet-7/+8
2024-09-20Implement RTN in resolve_bound_vars and HIR ty loweringMichael Goulet-3/+2
2024-09-20Conditionally allow lowering RTN (..) in pathsMichael Goulet-4/+62
2024-08-26Rename ParenthesizedGenericArgs to GenericArgsModeMichael Goulet-19/+18
2024-07-29Reformat `use` declarations.Nicholas Nethercote-11/+10
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-23Gate AsyncFn* under async_closure featureMichael Goulet-7/+15
2024-07-03Rollup merge of #127092 - compiler-errors:rtn-dots-redux, r=estebankMatthias Krüger-1/+14
Change return-type-notation to use `(..)` Aligns the syntax with the current wording of [RFC 3654](https://github.com/rust-lang/rfcs/pull/3654). Also implements rustfmt support (along with making a match exhaustive). Tracking: * https://github.com/rust-lang/rust/issues/109417
2024-06-28Make sure we deny unimplemented RTN on qpath segmentsMichael Goulet-3/+13
2024-06-28Change RTN to use .. againMichael Goulet-0/+3
2024-06-28implement new effects desugaringDeadbeef-9/+0
2024-05-30Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanupLeón Orell Valerian Liehr-14/+17
2024-04-30Remove `extern crate tracing` from numerous crates.Nicholas Nethercote-0/+1
2024-03-08Simplify ImplTraitContextMichael Goulet-1/+1
2024-02-07No need to take ImplTraitContext by refMichael Goulet-8/+8
2024-02-06Rollup merge of #120609 - petrochenkov:nousestem2, r=compiler-errorsMatthias Krüger-0/+1
hir: Stop keeping prefixes for most of `use` list stems And make sure all other imports have non-empty resolution lists. Addresses one of FIXMEs in https://github.com/rust-lang/rust/pull/120206.
2024-02-03hir: Stop keeping prefixes for most of `use` list stemsVadim Petrochenkov-0/+1
And make sure all other imports have non-empty resolution lists.
2024-01-31Error on incorrect item kind in async boundMichael Goulet-9/+20
2024-01-31Add async bound modifier to enable async Fn boundsMichael Goulet-9/+78
2023-12-27Introduce `const Trait` (always-const trait bounds)León Orell Valerian Liehr-2/+2
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-2/+2
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-18Auto merge of #119069 - matthiaskrgr:rollup-xxk4m30, r=matthiaskrgrbors-1/+4
Rollup of 5 pull requests Successful merges: - #118852 (coverage: Skip instrumenting a function if no spans were extracted from MIR) - #118905 ([AIX] Fix XCOFF metadata) - #118967 (Add better ICE messages for some undescriptive panics) - #119051 (Replace `FileAllocationInfo` with `FileEndOfFileInfo`) - #119059 (Deny `~const` trait bounds in inherent impl headers) r? `@ghost` `@rustbot` modify labels: rollup
2023-12-18Rename `Session::span_diagnostic` as `Session::dcx`.Nicholas Nethercote-1/+1
2023-12-15Add better ICE messages for some undescriptive panicsRoss Smyth-1/+4
2023-12-08Support async gen fnMichael Goulet-1/+1
2023-12-04Address code review feedbackEric Holk-3/+3
2023-12-04Lower return types for gen fn to impl IteratorEric Holk-4/+5
2023-12-02Inline and remove `LoweringContext::handler()`.Nicholas Nethercote-1/+1
It has a single call site.
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-3/+3
`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-08-06lower impl const to bind to host effect paramDeadbeef-1/+12
2023-05-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-1/+1
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-04-10Remove `..` from return type notationMichael Goulet-13/+0
2023-03-28Add `(..)` syntax for RTNMichael Goulet-5/+25
2023-03-28ParenthesizedGenericArgs::{Ok -> ParenSugar}Michael Goulet-4/+4