Fix misattributed type inference error span for index expressions#156885
Conversation
This comment has been minimized.
This comment has been minimized.
When an index expression with an ambiguous type (e.g. `arr[idx.into()]`) appears inside a cast or binary operation, the type inference error was incorrectly attributed to the outer expression instead of the `.into()` call. Resolve the index sub-expression type first so the error points at the actual ambiguous site.
09f69f4 to
d061dcb
Compare
|
r? compiler |
Can you explain how you reached that conclusion please? It will make it easier to review this PR. Thanks! |
|
sure. afaict everything that's unresolved here traces back to one variable: the return type of
that bare what actually convinced me it's the right span: plain one wrinkle: forcing the index span through |
|
r? compiler |
|
This change feels somewhat dubious to me, you're introducing additional calls to I'm not sure what the right way to do this diagnostic improvement is though |
|
yeah, i think you're right. i was looking at this as mostly span routing, but the binop bit is the one i like least, tbh. it adds a new force point while overloaded binop return handling is still going. the cast case is less bad since cast checks already run after fallback, but it still changes the order by resolving the index operand before the existing cast operand resolve. imo i should back this version out and avoid resolving i'll try that direction. also going to see if i can minimize a case that would have kept compiling without the early index resolve, since idk how convincing this is without a regression test. |
Adjust ambiguous index diagnostics without adding new index operand resolution points. Keep invalid operator and mismatched operand diagnostics on the operator while still pointing valid ambiguous index cases at the index operand.
|
@BoxyUwU pushed an update. i kept the same basic reasoning from my earlier comment, but changed the implementation after your point about structurally_resolve_type. the patch no longer force-resolves the index operand type. in cast.rs, it only changes the span used by the existing cast-expression resolution when the outer index expr and the index operand are both still plain inference vars. for binops, i moved this into the final fulfillment-error adjustment path instead of doing anything during operator lookup. so it only changes the diagnostic span after we already have an ambiguity. it also checks the surrounding operator shape before blaming .into(). i added a few regression cases too, mostly because this was where the first pass got too broad. the plain 0 + [1, 2, 3][bad_idx.into()] case still lands on .into(), but bad operator shapes like true + ... and 0u64 + [1i32, ...][bad_idx.into()] stay on the operator. shifts are covered as well with 1u32 << [0u8][bad_idx.into()], since the rhs does not have to be the same type there. i also kept a String + &str-ish case as a sanity check. one tradeoff is that the cast/binop cases do not keep the old fq-path help from the force-resolution version. imo that is better than adding a new resolution point just to get a nicer suggestion. |
|
@bors r+ thanks :D |
…us-type-span, r=BoxyUwU Fix misattributed type inference error span for index expressions If `arr[idx.into()]` appears inside a cast or binary op, the type inference error gets blamed on the wrong expression. **Before:** - `[1, 2, 3][bad_idx.into()] as i32` → error points at `[1, 2, 3][bad_idx.into()]` (the whole indexing expr) - `0 + [1, 2, 3][bad_idx.into()]` → error points at `+` **After:** - Both cases point at `.into()`, which is where the ambiguity actually is. In `cast.rs`, before resolving the cast expression type, we check if it's an index with an unresolved index type. If so, resolve the index sub-expression first at its own span so the error lands there. If that already errored, skip the broader resolution to avoid duplicates. In `op.rs`, after writing the method call for an overloaded binary op, if the return type still has inference variables and the RHS is an index expression, force resolution of the index type at its span. Fixes rust-lang#156738 r? compiler
…uwer Rollup of 16 pull requests Successful merges: - #156885 (Fix misattributed type inference error span for index expressions) - #157271 (simplify some `proc_macro` things) - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit) - #157921 (trait solver: Resolve region vars in max universe) - #157960 (delegation: add support for infers in generics) - #158105 (Extract all instance shim variants into new `ShimKind` enum) - #158207 (Resolver: local/external split of `resolve_ident_in_module_non_globs_unadjusted` ) - #158279 (Follow goto and drop when linting unreachable code) - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`) - #158020 (Update mingw-w64 C toolchain) - #158222 (format: ignore println newline in foreign format hints) - #158223 (Move target checking for #[lang] to the attribute parser) - #158252 (Use `cfg_select` in `std::os`) - #158257 ( fix escaping placeholder check in next solver normalization folder) - #158274 (triagebot: Stop pinging myself) - #158282 (slice_split_once: bounds check optimization note) Failed merges: - #158256 (Avoid parser panics bubbling out to proc macros)
…us-type-span, r=BoxyUwU Fix misattributed type inference error span for index expressions If `arr[idx.into()]` appears inside a cast or binary op, the type inference error gets blamed on the wrong expression. **Before:** - `[1, 2, 3][bad_idx.into()] as i32` → error points at `[1, 2, 3][bad_idx.into()]` (the whole indexing expr) - `0 + [1, 2, 3][bad_idx.into()]` → error points at `+` **After:** - Both cases point at `.into()`, which is where the ambiguity actually is. In `cast.rs`, before resolving the cast expression type, we check if it's an index with an unresolved index type. If so, resolve the index sub-expression first at its own span so the error lands there. If that already errored, skip the broader resolution to avoid duplicates. In `op.rs`, after writing the method call for an overloaded binary op, if the return type still has inference variables and the RHS is an index expression, force resolution of the index type at its span. Fixes rust-lang#156738 r? compiler
…us-type-span, r=BoxyUwU Fix misattributed type inference error span for index expressions If `arr[idx.into()]` appears inside a cast or binary op, the type inference error gets blamed on the wrong expression. **Before:** - `[1, 2, 3][bad_idx.into()] as i32` → error points at `[1, 2, 3][bad_idx.into()]` (the whole indexing expr) - `0 + [1, 2, 3][bad_idx.into()]` → error points at `+` **After:** - Both cases point at `.into()`, which is where the ambiguity actually is. In `cast.rs`, before resolving the cast expression type, we check if it's an index with an unresolved index type. If so, resolve the index sub-expression first at its own span so the error lands there. If that already errored, skip the broader resolution to avoid duplicates. In `op.rs`, after writing the method call for an overloaded binary op, if the return type still has inference variables and the RHS is an index expression, force resolution of the index type at its span. Fixes rust-lang#156738 r? compiler
…uwer Rollup of 23 pull requests Successful merges: - #158315 (`rust-analyzer` subtree update) - #155739 (Add temporary scope to assert_eq and assert_ne) - #156885 (Fix misattributed type inference error span for index expressions) - #157271 (simplify some `proc_macro` things) - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit) - #157921 (trait solver: Resolve region vars in max universe) - #157960 (delegation: add support for infers in generics) - #157983 (Lift the same-signature restriction for `extern "tail"`) - #158105 (Extract all instance shim variants into new `ShimKind` enum) - #158207 (Resolver: local/external split of `resolve_ident_in_module_non_globs_unadjusted` ) - #158279 (Follow goto and drop when linting unreachable code) - #157527 (Move derive tests into their dedicated folder) - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`) - #158020 (Update mingw-w64 C toolchain) - #158222 (format: ignore println newline in foreign format hints) - #158223 (Move target checking for #[lang] to the attribute parser) - #158252 (Use `cfg_select` in `std::os`) - #158257 ( fix escaping placeholder check in next solver normalization folder) - #158263 (Only load the feature list once in the entire resolver) - #158274 (triagebot: Stop pinging myself) - #158282 (slice_split_once: bounds check optimization note) - #158300 (Improve unknown crate_type diagnostic suggestions) - #158304 (mailmap: update mu001999) Failed merges: - #158256 (Avoid parser panics bubbling out to proc macros)
…us-type-span, r=BoxyUwU Fix misattributed type inference error span for index expressions If `arr[idx.into()]` appears inside a cast or binary op, the type inference error gets blamed on the wrong expression. **Before:** - `[1, 2, 3][bad_idx.into()] as i32` → error points at `[1, 2, 3][bad_idx.into()]` (the whole indexing expr) - `0 + [1, 2, 3][bad_idx.into()]` → error points at `+` **After:** - Both cases point at `.into()`, which is where the ambiguity actually is. In `cast.rs`, before resolving the cast expression type, we check if it's an index with an unresolved index type. If so, resolve the index sub-expression first at its own span so the error lands there. If that already errored, skip the broader resolution to avoid duplicates. In `op.rs`, after writing the method call for an overloaded binary op, if the return type still has inference variables and the RHS is an index expression, force resolution of the index type at its span. Fixes rust-lang#156738 r? compiler
Rollup of 27 pull requests Successful merges: - #158315 (`rust-analyzer` subtree update) - #155739 (Add temporary scope to assert_eq and assert_ne) - #156885 (Fix misattributed type inference error span for index expressions) - #157271 (simplify some `proc_macro` things) - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit) - #157921 (trait solver: Resolve region vars in max universe) - #157960 (delegation: add support for infers in generics) - #157983 (Lift the same-signature restriction for `extern "tail"`) - #158053 (Optimize network address parser) - #158105 (Extract all instance shim variants into new `ShimKind` enum) - #158207 (Resolver: local/external split of `resolve_ident_in_module_non_globs_unadjusted` ) - #158279 (Follow goto and drop when linting unreachable code) - #157527 (Move derive tests into their dedicated folder) - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`) - #158020 (Update mingw-w64 C toolchain) - #158039 (c-variadic: test that we use equality up to free lifetimes) - #158222 (format: ignore println newline in foreign format hints) - #158223 (Move target checking for #[lang] to the attribute parser) - #158252 (Use `cfg_select` in `std::os`) - #158257 ( fix escaping placeholder check in next solver normalization folder) - #158263 (Only load the feature list once in the entire resolver) - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use) - #158274 (triagebot: Stop pinging myself) - #158282 (slice_split_once: bounds check optimization note) - #158300 (Improve unknown crate_type diagnostic suggestions) - #158304 (mailmap: update mu001999) - #158309 (Update `rustc-literal-escaper` version to `0.0.8`) Failed merges: - #158256 (Avoid parser panics bubbling out to proc macros)
…us-type-span, r=BoxyUwU Fix misattributed type inference error span for index expressions If `arr[idx.into()]` appears inside a cast or binary op, the type inference error gets blamed on the wrong expression. **Before:** - `[1, 2, 3][bad_idx.into()] as i32` → error points at `[1, 2, 3][bad_idx.into()]` (the whole indexing expr) - `0 + [1, 2, 3][bad_idx.into()]` → error points at `+` **After:** - Both cases point at `.into()`, which is where the ambiguity actually is. In `cast.rs`, before resolving the cast expression type, we check if it's an index with an unresolved index type. If so, resolve the index sub-expression first at its own span so the error lands there. If that already errored, skip the broader resolution to avoid duplicates. In `op.rs`, after writing the method call for an overloaded binary op, if the return type still has inference variables and the RHS is an index expression, force resolution of the index type at its span. Fixes rust-lang#156738 r? compiler
Rollup of 35 pull requests Successful merges: - #158315 (`rust-analyzer` subtree update) - #158336 (Stop excluding `stdarch` test crates from `rust-src`) - #155739 (Add temporary scope to assert_eq and assert_ne) - #156885 (Fix misattributed type inference error span for index expressions) - #157271 (simplify some `proc_macro` things) - #157419 (move rustc_type_ir Term things to term_kind.rs) - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit) - #157921 (trait solver: Resolve region vars in max universe) - #157960 (delegation: add support for infers in generics) - #157983 (Lift the same-signature restriction for `extern "tail"`) - #158053 (Optimize network address parser) - #158105 (Extract all instance shim variants into new `ShimKind` enum) - #158207 (Resolver: local/external split of `resolve_ident_in_module_non_globs_unadjusted` ) - #158279 (Follow goto and drop when linting unreachable code) - #157527 (Move derive tests into their dedicated folder) - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`) - #157939 (Reorganize `tests/ui/issues` [8/N]) - #157946 (Make `char::is_private_use` and `char::is_assigned` unstably public) - #158003 (Reorganize `tests/ui/issues` [9/N]) - #158020 (Update mingw-w64 C toolchain) - #158039 (c-variadic: test that we use equality up to free lifetimes) - #158060 (Reorganize `tests/ui/issues` [10/N]) - #158222 (format: ignore println newline in foreign format hints) - #158223 (Move target checking for #[lang] to the attribute parser) - #158252 (Use `cfg_select` in `std::os`) - #158263 (Only load the feature list once in the entire resolver) - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use) - #158272 (Reorganize `tests/ui/issues` [13/N]) - #158274 (triagebot: Stop pinging myself) - #158282 (slice_split_once: bounds check optimization note) - #158300 (Improve unknown crate_type diagnostic suggestions) - #158304 (mailmap: update mu001999) - #158309 (Update `rustc-literal-escaper` version to `0.0.8`) - #158314 (Fix incorrect unsafe debug assertion in unchecked_div_exact) - #158326 (Add `io::ErrorKind::TooManyOpenFiles`)
Rollup of 35 pull requests Successful merges: - #158315 (`rust-analyzer` subtree update) - #158336 (Stop excluding `stdarch` test crates from `rust-src`) - #155739 (Add temporary scope to assert_eq and assert_ne) - #156885 (Fix misattributed type inference error span for index expressions) - #157271 (simplify some `proc_macro` things) - #157419 (move rustc_type_ir Term things to term_kind.rs) - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit) - #157921 (trait solver: Resolve region vars in max universe) - #157960 (delegation: add support for infers in generics) - #157983 (Lift the same-signature restriction for `extern "tail"`) - #158053 (Optimize network address parser) - #158105 (Extract all instance shim variants into new `ShimKind` enum) - #158207 (Resolver: local/external split of `resolve_ident_in_module_non_globs_unadjusted` ) - #158279 (Follow goto and drop when linting unreachable code) - #157527 (Move derive tests into their dedicated folder) - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`) - #157939 (Reorganize `tests/ui/issues` [8/N]) - #157946 (Make `char::is_private_use` and `char::is_assigned` unstably public) - #158003 (Reorganize `tests/ui/issues` [9/N]) - #158020 (Update mingw-w64 C toolchain) - #158039 (c-variadic: test that we use equality up to free lifetimes) - #158060 (Reorganize `tests/ui/issues` [10/N]) - #158222 (format: ignore println newline in foreign format hints) - #158223 (Move target checking for #[lang] to the attribute parser) - #158252 (Use `cfg_select` in `std::os`) - #158263 (Only load the feature list once in the entire resolver) - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use) - #158272 (Reorganize `tests/ui/issues` [13/N]) - #158274 (triagebot: Stop pinging myself) - #158282 (slice_split_once: bounds check optimization note) - #158300 (Improve unknown crate_type diagnostic suggestions) - #158304 (mailmap: update mu001999) - #158309 (Update `rustc-literal-escaper` version to `0.0.8`) - #158314 (Fix incorrect unsafe debug assertion in unchecked_div_exact) - #158326 (Add `io::ErrorKind::TooManyOpenFiles`)
Rollup of 35 pull requests Successful merges: - #158315 (`rust-analyzer` subtree update) - #158336 (Stop excluding `stdarch` test crates from `rust-src`) - #155739 (Add temporary scope to assert_eq and assert_ne) - #156885 (Fix misattributed type inference error span for index expressions) - #157271 (simplify some `proc_macro` things) - #157419 (move rustc_type_ir Term things to term_kind.rs) - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit) - #157921 (trait solver: Resolve region vars in max universe) - #157960 (delegation: add support for infers in generics) - #157983 (Lift the same-signature restriction for `extern "tail"`) - #158053 (Optimize network address parser) - #158105 (Extract all instance shim variants into new `ShimKind` enum) - #158207 (Resolver: local/external split of `resolve_ident_in_module_non_globs_unadjusted` ) - #158279 (Follow goto and drop when linting unreachable code) - #157527 (Move derive tests into their dedicated folder) - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`) - #157939 (Reorganize `tests/ui/issues` [8/N]) - #157946 (Make `char::is_private_use` and `char::is_assigned` unstably public) - #158003 (Reorganize `tests/ui/issues` [9/N]) - #158020 (Update mingw-w64 C toolchain) - #158039 (c-variadic: test that we use equality up to free lifetimes) - #158060 (Reorganize `tests/ui/issues` [10/N]) - #158222 (format: ignore println newline in foreign format hints) - #158223 (Move target checking for #[lang] to the attribute parser) - #158252 (Use `cfg_select` in `std::os`) - #158263 (Only load the feature list once in the entire resolver) - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use) - #158272 (Reorganize `tests/ui/issues` [13/N]) - #158274 (triagebot: Stop pinging myself) - #158282 (slice_split_once: bounds check optimization note) - #158300 (Improve unknown crate_type diagnostic suggestions) - #158304 (mailmap: update mu001999) - #158309 (Update `rustc-literal-escaper` version to `0.0.8`) - #158314 (Fix incorrect unsafe debug assertion in unchecked_div_exact) - #158326 (Add `io::ErrorKind::TooManyOpenFiles`)
Rollup of 35 pull requests Successful merges: - #158315 (`rust-analyzer` subtree update) - #158336 (Stop excluding `stdarch` test crates from `rust-src`) - #155739 (Add temporary scope to assert_eq and assert_ne) - #156885 (Fix misattributed type inference error span for index expressions) - #157271 (simplify some `proc_macro` things) - #157419 (move rustc_type_ir Term things to term_kind.rs) - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit) - #157921 (trait solver: Resolve region vars in max universe) - #157960 (delegation: add support for infers in generics) - #157983 (Lift the same-signature restriction for `extern "tail"`) - #158053 (Optimize network address parser) - #158105 (Extract all instance shim variants into new `ShimKind` enum) - #158207 (Resolver: local/external split of `resolve_ident_in_module_non_globs_unadjusted` ) - #158279 (Follow goto and drop when linting unreachable code) - #157527 (Move derive tests into their dedicated folder) - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`) - #157939 (Reorganize `tests/ui/issues` [8/N]) - #157946 (Make `char::is_private_use` and `char::is_assigned` unstably public) - #158003 (Reorganize `tests/ui/issues` [9/N]) - #158020 (Update mingw-w64 C toolchain) - #158039 (c-variadic: test that we use equality up to free lifetimes) - #158060 (Reorganize `tests/ui/issues` [10/N]) - #158222 (format: ignore println newline in foreign format hints) - #158223 (Move target checking for #[lang] to the attribute parser) - #158252 (Use `cfg_select` in `std::os`) - #158263 (Only load the feature list once in the entire resolver) - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use) - #158272 (Reorganize `tests/ui/issues` [13/N]) - #158274 (triagebot: Stop pinging myself) - #158282 (slice_split_once: bounds check optimization note) - #158300 (Improve unknown crate_type diagnostic suggestions) - #158304 (mailmap: update mu001999) - #158309 (Update `rustc-literal-escaper` version to `0.0.8`) - #158314 (Fix incorrect unsafe debug assertion in unchecked_div_exact) - #158326 (Add `io::ErrorKind::TooManyOpenFiles`)
…us-type-span, r=BoxyUwU Fix misattributed type inference error span for index expressions If `arr[idx.into()]` appears inside a cast or binary op, the type inference error gets blamed on the wrong expression. **Before:** - `[1, 2, 3][bad_idx.into()] as i32` → error points at `[1, 2, 3][bad_idx.into()]` (the whole indexing expr) - `0 + [1, 2, 3][bad_idx.into()]` → error points at `+` **After:** - Both cases point at `.into()`, which is where the ambiguity actually is. In `cast.rs`, before resolving the cast expression type, we check if it's an index with an unresolved index type. If so, resolve the index sub-expression first at its own span so the error lands there. If that already errored, skip the broader resolution to avoid duplicates. In `op.rs`, after writing the method call for an overloaded binary op, if the return type still has inference variables and the RHS is an index expression, force resolution of the index type at its span. Fixes rust-lang#156738 r? compiler
Rollup of 35 pull requests Successful merges: - #158315 (`rust-analyzer` subtree update) - #158336 (Stop excluding `stdarch` test crates from `rust-src`) - #155739 (Add temporary scope to assert_eq and assert_ne) - #156885 (Fix misattributed type inference error span for index expressions) - #157271 (simplify some `proc_macro` things) - #157419 (move rustc_type_ir Term things to term_kind.rs) - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit) - #157921 (trait solver: Resolve region vars in max universe) - #157960 (delegation: add support for infers in generics) - #157983 (Lift the same-signature restriction for `extern "tail"`) - #158053 (Optimize network address parser) - #158105 (Extract all instance shim variants into new `ShimKind` enum) - #158207 (Resolver: local/external split of `resolve_ident_in_module_non_globs_unadjusted` ) - #158279 (Follow goto and drop when linting unreachable code) - #157527 (Move derive tests into their dedicated folder) - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`) - #157939 (Reorganize `tests/ui/issues` [8/N]) - #157946 (Make `char::is_private_use` and `char::is_assigned` unstably public) - #158003 (Reorganize `tests/ui/issues` [9/N]) - #158020 (Update mingw-w64 C toolchain) - #158039 (c-variadic: test that we use equality up to free lifetimes) - #158060 (Reorganize `tests/ui/issues` [10/N]) - #158222 (format: ignore println newline in foreign format hints) - #158223 (Move target checking for #[lang] to the attribute parser) - #158252 (Use `cfg_select` in `std::os`) - #158263 (Only load the feature list once in the entire resolver) - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use) - #158272 (Reorganize `tests/ui/issues` [13/N]) - #158274 (triagebot: Stop pinging myself) - #158282 (slice_split_once: bounds check optimization note) - #158300 (Improve unknown crate_type diagnostic suggestions) - #158304 (mailmap: update mu001999) - #158309 (Update `rustc-literal-escaper` version to `0.0.8`) - #158314 (Fix incorrect unsafe debug assertion in unchecked_div_exact) - #158326 (Add `io::ErrorKind::TooManyOpenFiles`)
Rollup of 35 pull requests Successful merges: - #158315 (`rust-analyzer` subtree update) - #158336 (Stop excluding `stdarch` test crates from `rust-src`) - #155739 (Add temporary scope to assert_eq and assert_ne) - #156885 (Fix misattributed type inference error span for index expressions) - #157271 (simplify some `proc_macro` things) - #157419 (move rustc_type_ir Term things to term_kind.rs) - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit) - #157921 (trait solver: Resolve region vars in max universe) - #157960 (delegation: add support for infers in generics) - #157983 (Lift the same-signature restriction for `extern "tail"`) - #158053 (Optimize network address parser) - #158105 (Extract all instance shim variants into new `ShimKind` enum) - #158207 (Resolver: local/external split of `resolve_ident_in_module_non_globs_unadjusted` ) - #158279 (Follow goto and drop when linting unreachable code) - #157527 (Move derive tests into their dedicated folder) - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`) - #157939 (Reorganize `tests/ui/issues` [8/N]) - #157946 (Make `char::is_private_use` and `char::is_assigned` unstably public) - #158003 (Reorganize `tests/ui/issues` [9/N]) - #158020 (Update mingw-w64 C toolchain) - #158039 (c-variadic: test that we use equality up to free lifetimes) - #158060 (Reorganize `tests/ui/issues` [10/N]) - #158222 (format: ignore println newline in foreign format hints) - #158223 (Move target checking for #[lang] to the attribute parser) - #158252 (Use `cfg_select` in `std::os`) - #158263 (Only load the feature list once in the entire resolver) - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use) - #158272 (Reorganize `tests/ui/issues` [13/N]) - #158274 (triagebot: Stop pinging myself) - #158282 (slice_split_once: bounds check optimization note) - #158300 (Improve unknown crate_type diagnostic suggestions) - #158304 (mailmap: update mu001999) - #158309 (Update `rustc-literal-escaper` version to `0.0.8`) - #158314 (Fix incorrect unsafe debug assertion in unchecked_div_exact) - #158326 (Add `io::ErrorKind::TooManyOpenFiles`)
Rollup of 35 pull requests Successful merges: - #158315 (`rust-analyzer` subtree update) - #158336 (Stop excluding `stdarch` test crates from `rust-src`) - #155739 (Add temporary scope to assert_eq and assert_ne) - #156885 (Fix misattributed type inference error span for index expressions) - #157271 (simplify some `proc_macro` things) - #157419 (move rustc_type_ir Term things to term_kind.rs) - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit) - #157921 (trait solver: Resolve region vars in max universe) - #157960 (delegation: add support for infers in generics) - #157983 (Lift the same-signature restriction for `extern "tail"`) - #158053 (Optimize network address parser) - #158105 (Extract all instance shim variants into new `ShimKind` enum) - #158207 (Resolver: local/external split of `resolve_ident_in_module_non_globs_unadjusted` ) - #158279 (Follow goto and drop when linting unreachable code) - #157527 (Move derive tests into their dedicated folder) - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`) - #157939 (Reorganize `tests/ui/issues` [8/N]) - #157946 (Make `char::is_private_use` and `char::is_assigned` unstably public) - #158003 (Reorganize `tests/ui/issues` [9/N]) - #158020 (Update mingw-w64 C toolchain) - #158039 (c-variadic: test that we use equality up to free lifetimes) - #158060 (Reorganize `tests/ui/issues` [10/N]) - #158222 (format: ignore println newline in foreign format hints) - #158223 (Move target checking for #[lang] to the attribute parser) - #158252 (Use `cfg_select` in `std::os`) - #158263 (Only load the feature list once in the entire resolver) - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use) - #158272 (Reorganize `tests/ui/issues` [13/N]) - #158274 (triagebot: Stop pinging myself) - #158282 (slice_split_once: bounds check optimization note) - #158300 (Improve unknown crate_type diagnostic suggestions) - #158304 (mailmap: update mu001999) - #158309 (Update `rustc-literal-escaper` version to `0.0.8`) - #158314 (Fix incorrect unsafe debug assertion in unchecked_div_exact) - #158326 (Add `io::ErrorKind::TooManyOpenFiles`)
Rollup merge of #156885 - Dnreikronos:fix/index-expr-ambiguous-type-span, r=BoxyUwU Fix misattributed type inference error span for index expressions If `arr[idx.into()]` appears inside a cast or binary op, the type inference error gets blamed on the wrong expression. **Before:** - `[1, 2, 3][bad_idx.into()] as i32` → error points at `[1, 2, 3][bad_idx.into()]` (the whole indexing expr) - `0 + [1, 2, 3][bad_idx.into()]` → error points at `+` **After:** - Both cases point at `.into()`, which is where the ambiguity actually is. In `cast.rs`, before resolving the cast expression type, we check if it's an index with an unresolved index type. If so, resolve the index sub-expression first at its own span so the error lands there. If that already errored, skip the broader resolution to avoid duplicates. In `op.rs`, after writing the method call for an overloaded binary op, if the return type still has inference variables and the RHS is an index expression, force resolution of the index type at its span. Fixes #156738 r? compiler
|
@rust-timer build 1b9799c |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (1b9799c): comparison URL. Overall result: ❌✅ regressions and improvements - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 4.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 1.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 503.101s -> 505.385s (0.45%) |
If
arr[idx.into()]appears inside a cast or binary op, the type inference error gets blamed on the wrong expression.Before:
[1, 2, 3][bad_idx.into()] as i32→ error points at[1, 2, 3][bad_idx.into()](the whole indexing expr)0 + [1, 2, 3][bad_idx.into()]→ error points at+After:
.into(), which is where the ambiguity actually is.In
cast.rs, before resolving the cast expression type, we check if it's an index with an unresolved index type. If so, resolve the index sub-expression first at its own span so the error lands there. If that already errored, skip the broader resolution to avoid duplicates.In
op.rs, after writing the method call for an overloaded binary op, if the return type still has inference variables and the RHS is an index expression, force resolution of the index type at its span.Fixes #156738
r? compiler