about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src
AgeCommit message (Collapse)AuthorLines
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-144/+108
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-23Improve some names.Nicholas Nethercote-1/+1
Lots of vectors of messages called `message` or `msg`. This commit pluralizes them. Note that `emit_message_default` and `emit_messages_default` both already existed, and both process a vector, so I renamed the former `emit_messages_default_inner` because it's called by the latter.
2023-12-23Give `DiagnosticBuilder` a default type.Nicholas Nethercote-4/+4
`IntoDiagnostic` defaults to `ErrorGuaranteed`, because errors are the most common diagnostic level. It makes sense to do likewise for the closely-related (and much more widely used) `DiagnosticBuilder` type, letting us write `DiagnosticBuilder<'a, ErrorGuaranteed>` as just `DiagnosticBuilder<'a>`. This cuts over 200 lines of code due to many multi-line things becoming single line things.
2023-12-22Auto merge of #118847 - eholk:for-await, r=compiler-errorsbors-4/+4
Add support for `for await` loops This adds support for `for await` loops. This includes parsing, desugaring in AST->HIR lowering, and adding some support functions to the library. Given a loop like: ```rust for await i in iter { ... } ``` this is desugared to something like: ```rust let mut iter = iter.into_async_iter(); while let Some(i) = loop { match core::pin::Pin::new(&mut iter).poll_next(cx) { Poll::Ready(i) => break i, Poll::Pending => yield, } } { ... } ``` This PR also adds a basic `IntoAsyncIterator` trait. This is partly for symmetry with the way `Iterator` and `IntoIterator` work. The other reason is that for async iterators it's helpful to have a place apart from the data structure being iterated over to store state. `IntoAsyncIterator` gives us a good place to do this. I've gated this feature behind `async_for_loop` and opened #118898 as the feature tracking issue. r? `@compiler-errors`
2023-12-22Auto merge of #119163 - fmease:refactor-ast-trait-bound-modifiers, ↵bors-3/+3
r=compiler-errors Refactor AST trait bound modifiers Instead of having two types to represent trait bound modifiers in the parser / the AST (`parser::ty::BoundModifiers` & `ast::TraitBoundModifier`), only to map one to the other later, just use `parser::ty::BoundModifiers` (moved & renamed to `ast::TraitBoundModifiers`). The struct type is more extensible and easier to deal with (see [here](https://github.com/rust-lang/rust/pull/119099/files#r1430749981) and [here](https://github.com/rust-lang/rust/pull/119099/files#r1430752116) for context) since it more closely models what it represents: A compound of two kinds of modifiers, constness and polarity. Modeling this as an enum (the now removed `ast::TraitBoundModifier`) meant one had to add a new variant per *combination* of modifier kind, which simply isn't scalable and which lead to a lot of explicit non-DRY matches. NB: `hir::TraitBoundModifier` being an enum is fine since HIR doesn't need to worry representing invalid modifier kind combinations as those get rejected during AST validation thereby immensely cutting down the number of possibilities.
2023-12-20Refactor AST trait bound modifiersLeón Orell Valerian Liehr-3/+3
2023-12-20resolve: Stop feeding visibilities for import list stemsVadim Petrochenkov-2/+7
2023-12-20Auto merge of #119136 - petrochenkov:feedvis3, r=WaffleLapkinbors-4/+1
resolve: Eagerly feed closure visibilities Also factor out all tcx-dependent operations performed for every created definition into `TyCtxt::create_def`. Addresses https://github.com/rust-lang/rust/pull/118657#discussion_r1421424277
2023-12-20resolve: Eagerly feed closure visibilitiesVadim Petrochenkov-4/+1
Also factor out all tcx-dependent operations performed for every created definition into `TyCtxt::create_def`
2023-12-19Plumb awaitness of for loopsEric Holk-4/+4
2023-12-19resolve: Feed visibilities for unresolved trait impl itemsVadim Petrochenkov-2/+8
2023-12-18Replace some instances of FxHashMap/FxHashSet with stable alternatives ↵Michael Woerister-2/+2
(mostly in rustc_hir and rustc_ast_lowering) Part of https://github.com/rust-lang/compiler-team/issues/533
2023-12-18Rename `Session::span_diagnostic` as `Session::dcx`.Nicholas Nethercote-4/+1
2023-12-18resolve: Replace visibility table in resolver outputs with query feedingVadim Petrochenkov-23/+28
Also feed missing visibilities for import stems and trait impl items, which were previously evaluated lazily.
2023-12-15NFC don't convert types to identical typesMatthias Krüger-2/+1
2023-12-12Rollup merge of #118889 - matthiaskrgr:compl_2023_2, r=WaffleLapkinJubilee-14/+5
more clippy::complexity fixes redundant_guards redundant_slicing filter_next needless_borrowed_reference useless_format
2023-12-12Rollup merge of #118884 - matthiaskrgr:auszweimacheins, r=NadrierilJubilee-1/+1
NFC: simplify merging of two vecs
2023-12-12more clippy::complexity fixesMatthias Krüger-14/+5
redundant_guards redundant_slicing filter_next needless_borrowed_reference useless_format
2023-12-12simplify merging of two vecsMatthias Krüger-1/+1
2023-12-12Rollup merge of #117914 - estebank:issue-85843, r=wesleywiserMatthias Krüger-12/+259
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-12-12Rollup merge of #118840 - matthiaskrgr:cloooooone, r=compiler-errorsMatthias Krüger-1/+1
remove some redundant clones
2023-12-11remove some redundant clonesMatthias Krüger-1/+1
2023-12-11Rollup merge of #118620 - petrochenkov:defeed2, r=compiler-errorsMatthias Krüger-39/+31
resolve: Use `def_kind` query to cleanup some code Follow up to https://github.com/rust-lang/rust/pull/118188. Similar attempts to use queries in resolver resulted in perf regressions in the past, so this needs a perf run first.
2023-12-08Introduce closure_id method on CoroutineKindMichael Goulet-12/+13
2023-12-08Auto merge of #118420 - compiler-errors:async-gen, r=eholkbors-29/+38
Introduce support for `async gen` blocks I'm delighted to demonstrate that `async gen` block are not very difficult to support. They're simply coroutines that yield `Poll<Option<T>>` and return `()`. **This PR is WIP and in draft mode for now** -- I'm mostly putting it up to show folks that it's possible. This PR needs a lang-team experiment associated with it or possible an RFC, since I don't think it falls under the jurisdiction of the `gen` RFC that was recently authored by oli (https://github.com/rust-lang/rfcs/pull/3513, https://github.com/rust-lang/rust/issues/117078). ### Technical note on the pre-generator-transform yield type: The reason that the underlying coroutines yield `Poll<Option<T>>` and not `Poll<T>` (which would make more sense, IMO, for the pre-transformed coroutine), is because the `TransformVisitor` that is used to turn coroutines into built-in state machine functions would have to destructure and reconstruct the latter into the former, which requires at least inserting a new basic block (for a `switchInt` terminator, to match on the `Poll` discriminant). This does mean that the desugaring (at the `rustc_ast_lowering` level) of `async gen` blocks is a bit more involved. However, since we already need to intercept both `.await` and `yield` operators, I don't consider it much of a technical burden. r? `@ghost`
2023-12-08Make some matches exhaustive to avoid bugs, fix toolsMichael Goulet-22/+26
2023-12-08Support async gen fnMichael Goulet-1/+2
2023-12-08coro_kind -> coroutine_kindMichael Goulet-7/+11
2023-12-08Auto merge of #118527 - Nadrieril:never_patterns_parse, r=compiler-errorsbors-1/+1
never_patterns: Parse match arms with no body Never patterns are meant to signal unreachable cases, and thus don't take bodies: ```rust let ptr: *const Option<!> = ...; match *ptr { None => { foo(); } Some(!), } ``` This PR makes rustc accept the above, and enforces that an arm has a body xor is a never pattern. This affects parsing of match arms even with the feature off, so this is delicate. (Plus this is my first non-trivial change to the parser). ~~The last commit is optional; it introduces a bit of churn to allow the new suggestions to be machine-applicable. There may be a better solution? I'm not sure.~~ EDIT: I removed that commit r? `@compiler-errors`
2023-12-06Auto merge of #118687 - matthiaskrgr:rollup-317ztgu, r=matthiaskrgrbors-4/+16
Rollup of 6 pull requests Successful merges: - #117981 (Remove deprecated `--check-cfg` syntax) - #118177 (Suppress warnings in LLVM wrapper when targeting MSVC) - #118317 (tip for define macro name after `macro_rules!`) - #118504 (Enforce `must_use` on associated types and RPITITs that have a must-use trait in bounds) - #118660 (rustc_arena: add `alloc_str`) - #118681 (Fix is_foreign_item for StableMIR instance ) r? `@ghost` `@rustbot` modify labels: rollup
2023-12-06tip for define macro name after `macro_rules!`bohan-4/+16
2023-12-06Use the glob binding in resolve_rustdoc_path processr0cky-0/+3
2023-12-05Auto merge of #118457 - eholk:genfn, r=compiler-errorsbors-12/+21
Add support for `gen fn` This builds on #116447 to add support for `gen fn` functions. For the most part we follow the same approach as desugaring `async fn`, but replacing `Future` with `Iterator` and `async {}` with `gen {}` for the body. The version implemented here uses the return type of a `gen fn` as the yield type. For example: ```rust gen fn count_to_three() -> i32 { yield 1; yield 2; yield 3; } ``` In the future, I think we should experiment with a syntax like `gen fn count_to_three() yield i32 { ... }`, but that can go in another PR. cc `@oli-obk` `@compiler-errors`
2023-12-05resolve: Use `def_kind` query to cleanup some codeVadim Petrochenkov-39/+31
2023-12-04Address code review feedbackEric Holk-6/+8
2023-12-04Structured `use` suggestion on privacy errorEsteban Küber-1/+86
When encoutering a privacy error on an item through a re-export that is accessible in an alternative path, provide a structured suggestion with that path. ``` error[E0603]: module import `mem` is private --> $DIR/private-std-reexport-suggest-public.rs:4:14 | LL | use foo::mem; | ^^^ private module import | note: the module import `mem` is defined here... --> $DIR/private-std-reexport-suggest-public.rs:8:9 | LL | use std::mem; | ^^^^^^^^ note: ...and refers to the module `mem` which is defined here --> $SRC_DIR/std/src/lib.rs:LL:COL | = note: you could import this help: import `mem` through the re-export | LL | use std::mem; | ~~~~~~~~ ``` Fix #42909.
2023-12-04Option<CoroutineKind>Eric Holk-11/+14
2023-12-04Merge Async and Gen into CoroutineKindEric Holk-8/+9
2023-12-04Lower return types for gen fn to impl IteratorEric Holk-1/+4
2023-12-03rustc: Harmonize `DefKind` and `DefPathData`Vadim Petrochenkov-77/+55
`DefPathData::(ClosureExpr,ImplTrait)` are renamed to match `DefKind::(Closure,OpaqueTy)`. `DefPathData::ImplTraitAssocTy` is replaced with `DefPathData::TypeNS(kw::Empty)` because both correspond to `DefKind::AssocTy`. It's possible that introducing `(DefKind,DefPathData)::AssocOpaqueTy` could be a better solution, but that would be a much more invasive change. Const generic parameters introduced for effects are moved from `DefPathData::TypeNS` to `DefPathData::ValueNS`, because constants are values. `DefPathData` is no longer passed to `create_def` functions to avoid redundancy.
2023-12-03Parse a pattern with no armNadrieril-1/+1
2023-12-02Auto merge of #118470 - nnethercote:cleanup-error-handlers, r=compiler-errorsbors-4/+4
Cleanup error handlers Mostly by making function naming more consistent. More to do after this, but this is enough for one PR. r? compiler-errors
2023-12-02Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_bug`.Nicholas Nethercote-4/+4
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug` follows the pattern used everywhere else: `span_err`, `span_warning`, etc.
2023-12-01vis note for no pub reexports glob importbohan-4/+14
2023-11-29Rollup merge of #118342 - compiler-errors:macro-generic-bang, r=estebankMatthias Krüger-6/+16
Dont suggest `!` for path in function call if it has generic args Fixes #118335
2023-11-28def collector: Set correct namespace in `DefPathData` for foreign typesVadim Petrochenkov-16/+10
2023-11-28resolve: Feed the `def_kind` query immediately on `DefId` creationVadim Petrochenkov-54/+112
2023-11-27Address unused tuple struct fields in the compilerJake Goulding-5/+3
2023-11-27Dont suggest `!` for path in function call if it has generic argsMichael Goulet-6/+16
2023-11-26merge `DefKind::Coroutine` into `DefKind::Closure`bohan-2/+1