Repository navigation
Rustc pull update - #2753
Merged
Merged
Rustc pull update#2753
Conversation
Fix accidental type inference in array coercion Fixes rust-lang/rust#136420. If the expectation of array element is a type variable, we should avoid resolving it to the first element's type and wait until LUB coercion is completed. We create a free type variable instead which is only used in this `CoerceMany`. [`check_expr_match`](https://github.com/rust-lang/rust/blob/847e3ee6b0e614937eee4e6d8f61094411eadcc0/compiler/rustc_hir_typeck/src/_match.rs#L72) and [`check_expr_if`](https://github.com/rust-lang/rust/blob/847e3ee6b0e614937eee4e6d8f61094411eadcc0/compiler/rustc_hir_typeck/src/expr.rs#L1329) where `CoerceMany` is also used do the [same](https://github.com/rust-lang/rust/blob/847e3ee6b0e614937eee4e6d8f61094411eadcc0/compiler/rustc_hir_typeck/src/expectation.rs#L50). ### [FCP Proposal](rust-lang/rust#140283 (comment)): > Array expressions normally lub their element expressions' types to ensure that things like `[5, 5_u8]` work and don't result in type mismatches. When invoking a generic function `fn foo<T>(_: [T; N])` with an array expression, we end up with an infer var for the element type of the array in the signature. So when typecking the first array element we compare its type with the infer var and thus subsequently require all other elements to be the same type. > > This PR changes that to instead fall back to "not knowing" that the argument type is array of infer var, but just having an infer var for the entire argument. Thus we typeck the array expression normally, lubbing the element expressions, and then in the end comparing the array expression's type with the array of infer var type. > > Things like > > ```rust > fn foo() {} > fn bar() {} > fn f<T>(_: [T; 2]) {} > > f([foo, bar]); > ``` > > and > > ```rust > struct Foo; > struct Bar; > trait Trait {} > impl Trait for Foo {} > impl Trait for Bar {} > fn f<T>(_: [T; 2]) {} > > f([&Foo, &Bar as &dyn Trait]); > ``` ### Remaining inconsistency with `if` and `match`(rust-lang/rust#145048): The typeck of array always uses the element coercion target type as the expectation of element exprs while `if` and `match` use `NoExpectation` if the expected type is an infer var. This causes that array doesn't support nested coercion. ```rust fn foo() {} fn bar() {} fn main() { let _ = [foo, if false { bar } else { foo }]; // type mismatch when trying to coerce `bar` into `foo` in if-then branch coercion. } ``` But we can't simply change this behavior to be the same as `if` and `match` since [many code](rust-lang/rust#140283 (comment)) depends on using the first element's type as expectation.
rustc-dev-guide subtree update Subtree update of `rustc-dev-guide` to e03697d. Created using https://github.com/rust-lang/josh-sync. r? @ghost
Rollup of 5 pull requests Successful merges: - rust-lang/rust#151777 ( Reduce generics use in the query system.) - rust-lang/rust#151808 (Document a safety condition for `TypedArena::alloc_raw_slice`) - rust-lang/rust#151811 (Fix false positive in unused_parens caused by break) - rust-lang/rust#151817 (Fix missing syntax context in lifetime hygiene debug output) - rust-lang/rust#151844 (rustc-dev-guide subtree update)
Fix lockfile update script Fixes rust-lang/rust#151354 (comment) Now passes `shellcheck` cc @ehuss
constify `Iterator`, take IV Like its predecessors (rust-lang/rust#92433, rust-lang/rust#102225, rust-lang/rust#106541), this PR allows one to make `Iterator` implementations `const`, and thus enables the ability to have `for` loops in `const` contexts. I've also included constifying `Option as IntoIterator`, `option::IntoIter as Iterator` as a minimal dogfooding example. But unlike its predecessors, it uses a new attribute (not unsound anymore!) that prevents any `Iterator` extension methods from being called. This is intentionally made minimal for an initial approval, the fun stuff like `.fold`, `Range as Iterator` could be done later. cc @rust-lang/wg-const-eval, cc @oli-obk to review the compiler parts cc rust-lang/rust#92476
resolve: Remove `force` parameter from `resolve_ident_in_scope` `force == true` is used for turning `Determinacy::Undetermined` into `Determinacy::Determined` during error recovery. It's only needed in two places: - `resolve_macro_or_delegation_path` - the normal case - `resolve_path_with_ribs` - obscure case, only when resolving visibilities and only for improving diagnostics in `tests\ui\resolve\visibility-indeterminate.rs`, I'm not actually sure if we should keep it In other cases `Determinacy::Undetermined` is just ignored or can be propagated.
…uwer Rollup of 2 pull requests Successful merges: - rust-lang/rust#151281 (constify `Iterator`, take IV) - rust-lang/rust#151873 (resolve: Remove `force` parameter from `resolve_ident_in_scope`)
This updates the rust-version file to 44e34e1ac6d7e69b40856cf1403d3da145319c30.
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: rust-lang/rust@44e34e1 Filtered ref: e740092 Upstream diff: rust-lang/rust@370143f...44e34e1 This merge was created using https://github.com/rust-lang/josh-sync.
Collaborator
|
Thanks for the PR. If you have write access, feel free to merge this PR if it does not need reviews. You can request a review using |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Latest update from rustc.