about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/late
AgeCommit message (Collapse)AuthorLines
2023-12-23Give `DiagnosticBuilder` a default type.Nicholas Nethercote-1/+1
`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-1/+1
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-20Refactor AST trait bound modifiersLeón Orell Valerian Liehr-3/+3
2023-12-19Plumb awaitness of for loopsEric Holk-1/+1
2023-12-12Rollup merge of #118889 - matthiaskrgr:compl_2023_2, r=WaffleLapkinJubilee-8/+3
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-8/+3
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-11-27Dont suggest `!` for path in function call if it has generic argsMichael Goulet-6/+16
2023-11-25is_{some,ok}_andMichael Goulet-1/+1
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-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-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 ()> { /* */ } ```
2023-11-20On borrow return type, suggest borrowing from arg or owned return typeEsteban Küber-12/+126
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-11-19fix rebaseEsteban Küber-1/+4
2023-11-19review commentsEsteban Küber-22/+13
2023-11-19Account for number of arguments in suggestionEsteban Küber-5/+24
2023-11-19fix tidyEsteban Küber-1/+1
2023-11-19Suggest using builder on curly brace struct called as fnEsteban Küber-165/+178
2023-11-19Do not suggest struct literal when fields are privateEsteban Küber-35/+64
2023-11-19On private tuple struct, suggest `Default::default` when possibleEsteban Küber-1/+56
2023-11-19Don't sort `span_suggestions`, leave that to callerEsteban Küber-5/+9
2023-11-19When encountering struct fn call literal with private fields, suggest all ↵Esteban Küber-16/+74
builders When encountering code like `Box(42)`, suggest `Box::new(42)` and *all* other associated functions that return `-> Box<T>`.
2023-11-17On resolve error of `[rest..]`, suggest `[rest @ ..]`Esteban Küber-0/+27
When writing a pattern to collect multiple entries of a slice in a single binding, it is easy to misremember or typo the appropriate syntax to do so, instead writing the experimental `X..` pattern syntax. When we encounter a resolve error because `X` isn't available, we suggest `X @ ..` as an alternative. ``` error[E0425]: cannot find value `rest` in this scope --> $DIR/range-pattern-meant-to-be-slice-rest-pattern.rs:3:13 | LL | [1, rest..] => println!("{rest:?}"), | ^^^^ not found in this scope | help: if you meant to collect the rest of the slice in `rest`, use the at operator | LL | [1, rest @ ..] => println!("{rest:?}"), | + ``` Fix #88404.
2023-10-26Suggest assoc fn `new` when trying to build tuple struct with private fieldsEsteban Küber-1/+20
Fix #22488.
2023-10-13Format all the let chains in compilerMichael Goulet-75/+91
2023-09-29Auto merge of #116089 - estebank:issue-115992-2, r=compiler-errorsbors-21/+69
When suggesting `self.x` for `S { x }`, use `S { x: self.x }` Fix #115992. r? `@compiler-errors` Follow up to #116086.
2023-09-27fix clippy::{redundant_guards, useless_format}Matthias Krüger-1/+1
2023-09-26Don't store lazyness in DefKindMichael Goulet-2/+2
2023-09-25Point at field definition when unresolved name exists in `Self`Esteban Küber-7/+7
2023-09-25When suggesting `self.x` for `S { x }`, use `S { x: self.x }`Esteban Küber-14/+62
Tweak output. Fix #115992.
2023-09-23Tweak wording and logicEsteban Küber-5/+10
2023-09-23When encountering method on `Self` that we can't suggest, mention itEsteban Küber-30/+28
2023-09-23More accurate suggestion for `self.` and `Self::`Esteban Küber-5/+12
Fix #115992.
2023-08-08fix: not insert missing lifetime for `ConstParamTy`bohan-2/+4
2023-08-08Rollup merge of #114566 - fmease:type-alias-laziness-is-crate-specific, ↵Matthias Krüger-2/+2
r=oli-obk Store the laziness of type aliases in their `DefKind` Previously, we would treat paths referring to type aliases as *lazy* type aliases if the current crate had lazy type aliases enabled independently of whether the crate which the alias was defined in had the feature enabled or not. With this PR, the laziness of a type alias depends on the crate it is defined in. This generally makes more sense to me especially if / once lazy type aliases become the default in a new edition and we need to think about *edition interoperability*: Consider the hypothetical case where the dependency crate has an older edition (and thus eager type aliases), it exports a type alias with bounds & a where-clause (which are void but technically valid), the dependent crate has the latest edition (and thus lazy type aliases) and it uses that type alias. Arguably, the bounds should *not* be checked since at any time, the dependency crate should be allowed to change the bounds at will with a *non*-major version bump & without negatively affecting downstream crates. As for the reverse case (dependency: lazy type aliases, dependent: eager type aliases), I guess it rules out anything from slight confusion to mild annoyance from upstream crate authors that would be caused by the compiler ignoring the bounds of their type aliases in downstream crates with older editions. --- This fixes #114468 since before, my assumption that the type alias associated with a given weak projection was lazy (and therefore had its variances computed) did not necessarily hold in cross-crate scenarios (which [I kinda had a hunch about](https://github.com/rust-lang/rust/pull/114253#discussion_r1278608099)) as outlined above. Now it does hold. `@rustbot` label F-lazy_type_alias r? `@oli-obk`
2023-08-07Store the laziness of type aliases in the DefKindLeón Orell Valerian Liehr-2/+2
2023-08-06refactor on span_look_aheadyukang-10/+10
2023-08-02trivial style fixyukang-30/+27
2023-07-30inline format!() args up to and including rustc_codegen_llvmMatthias Krüger-35/+27
2023-07-28Resolve generic const itemsLeón Orell Valerian Liehr-0/+8