diff options
| author | y21 <30553356+y21@users.noreply.github.com> | 2024-03-29 16:24:07 +0100 |
|---|---|---|
| committer | y21 <30553356+y21@users.noreply.github.com> | 2024-03-29 16:24:07 +0100 |
| commit | 9f5d31ef862489ea87bf3e52812d05b1a700de47 (patch) | |
| tree | 5dd807e0022ac0362de374848350606a57416672 | |
| parent | 124e68bef8be61aa151ff33bea325c832728146f (diff) | |
| download | rust-9f5d31ef862489ea87bf3e52812d05b1a700de47.tar.gz rust-9f5d31ef862489ea87bf3e52812d05b1a700de47.zip | |
clear `DefId` when an expression's type changes to non-adt
| -rw-r--r-- | clippy_utils/src/ty/type_certainty/mod.rs | 2 | ||||
| -rw-r--r-- | tests/ui/crashes/ice-12585.rs | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/clippy_utils/src/ty/type_certainty/mod.rs b/clippy_utils/src/ty/type_certainty/mod.rs index 7913926928f..ad50786eece 100644 --- a/clippy_utils/src/ty/type_certainty/mod.rs +++ b/clippy_utils/src/ty/type_certainty/mod.rs @@ -90,7 +90,7 @@ fn expr_type_certainty(cx: &LateContext<'_>, expr: &Expr<'_>) -> Certainty { if let Some(def_id) = adt_def_id(expr_ty) { certainty.with_def_id(def_id) } else { - certainty + certainty.clear_def_id() } } diff --git a/tests/ui/crashes/ice-12585.rs b/tests/ui/crashes/ice-12585.rs new file mode 100644 index 00000000000..7928115c0a9 --- /dev/null +++ b/tests/ui/crashes/ice-12585.rs @@ -0,0 +1,26 @@ +#![allow(clippy::unit_arg)] + +struct One { + x: i32, +} +struct Two { + x: i32, +} + +struct Product {} + +impl Product { + pub fn a_method(self, _: ()) {} +} + +fn from_array(_: [i32; 2]) -> Product { + todo!() +} + +pub fn main() { + let one = One { x: 1 }; + let two = Two { x: 2 }; + + let product = from_array([one.x, two.x]); + product.a_method(<()>::default()); +} |
