about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src
AgeCommit message (Collapse)AuthorLines
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
2023-11-25Rollup merge of #118288 - compiler-errors:is_some_and, r=lqd,dtolnayMichael Goulet-1/+1
Use `is_{some,ok}_and` more in the compiler slightly more fluent-reading code
2023-11-25Rollup merge of #118158 - nnethercote:reduce-fluent-boilerplate, ↵Michael Goulet-5/+2
r=compiler-errors Reduce fluent boilerplate Best reviewed one commit at a time. r? `@davidtwco`
2023-11-26Use `rustc_fluent_macro::fluent_messages!` directly.Nicholas Nethercote-2/+1
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-26Avoid need for `{D,Subd}iagnosticMessage` imports.Nicholas Nethercote-3/+1
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-25is_{some,ok}_andMichael Goulet-1/+1
2023-11-25resolve: Avoid clones of `MacroData`Vadim Petrochenkov-55/+52
And move declarative macro compilation to an earlier point in def collector, which is required for #118188.
2023-11-24Auto merge of #117934 - Young-Flash:dev, r=petrochenkovbors-3/+12
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-23feat: make let_binding_suggestion more reasonableYoung-Flash-3/+12
2023-11-23Auto merge of #118065 - estebank:core-not-found-404, r=TaKO8Kibors-0/+9
When failing to import `core`, suggest `std`
2023-11-22When failing to import `core`, suggest `std`Esteban Küber-0/+9
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-25/+25
`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-20let-chain fmtEsteban Küber-31/+24
2023-11-20Rely in resolve and not on path name for `&str` -> `String` suggestionEsteban Küber-49/+54
2023-11-20Do not consider traits as ownable in suggestionEsteban Küber-7/+55
2023-11-20Account for '_ in lifetime suggestionEsteban Küber-4/+15
2023-11-20Suggest 'a when trait object assoc type has '_Esteban Küber-12/+21
2023-11-20Fix incorrect lifetime suggestionEsteban Küber-2/+2
2023-11-20Tweak wordingEsteban Küber-4/+4
2023-11-20Account for impl Trait in lifetime suggestionEsteban Küber-5/+72
When encountering ```rust fn g(mut x: impl Iterator<Item = &()>) -> Option<&()> { /* */ } ``` Suggest ```rust fn g<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&'a ()> { /* */ } ```