Skip to content

Commit 65dca11

Browse files
authored
Rollup merge of #103003 - TaKO8Ki:fix-102989, r=compiler-errors
Fix `suggest_floating_point_literal` ICE Fixes #102989
2 parents b79ad57 + 062ea9c commit 65dca11

File tree

3 files changed

+84
-13
lines changed

3 files changed

+84
-13
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -2937,19 +2937,15 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
29372937
ObligationCauseCode::BinOp { rhs_span: Some(span), is_lit, .. } if *is_lit => span,
29382938
_ => return,
29392939
};
2940-
match (
2941-
trait_ref.skip_binder().self_ty().kind(),
2942-
trait_ref.skip_binder().substs.type_at(1).kind(),
2943-
) {
2944-
(ty::Float(_), ty::Infer(InferTy::IntVar(_))) => {
2945-
err.span_suggestion_verbose(
2946-
rhs_span.shrink_to_hi(),
2947-
"consider using a floating-point literal by writing it with `.0`",
2948-
".0",
2949-
Applicability::MaybeIncorrect,
2950-
);
2951-
}
2952-
_ => {}
2940+
if let ty::Float(_) = trait_ref.skip_binder().self_ty().kind()
2941+
&& let ty::Infer(InferTy::IntVar(_)) = trait_ref.skip_binder().substs.type_at(1).kind()
2942+
{
2943+
err.span_suggestion_verbose(
2944+
rhs_span.shrink_to_hi(),
2945+
"consider using a floating-point literal by writing it with `.0`",
2946+
".0",
2947+
Applicability::MaybeIncorrect,
2948+
);
29532949
}
29542950
}
29552951

src/test/ui/traits/issue-102989.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// normalize-stderr-test "loaded from .*libcore-.*.rlib" -> "loaded from SYSROOT/libcore-*.rlib"
2+
3+
#![feature(lang_items)]
4+
#[lang="sized"]
5+
trait Sized { } //~ ERROR found duplicate lang item `sized`
6+
7+
fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
8+
//~^ ERROR `self` parameter is only allowed in associated functions
9+
//~| ERROR cannot find type `Struct` in this scope
10+
//~| ERROR mismatched types
11+
let x = x << 1;
12+
//~^ ERROR the size for values of type `{integer}` cannot be known at compilation time
13+
//~| ERROR cannot find value `x` in this scope
14+
}
15+
16+
fn main() {}
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
error: `self` parameter is only allowed in associated functions
2+
--> $DIR/issue-102989.rs:7:15
3+
|
4+
LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
5+
| ^^^^ not semantically valid as function parameter
6+
|
7+
= note: associated functions are those in `impl` or `trait` definitions
8+
9+
error[E0412]: cannot find type `Struct` in this scope
10+
--> $DIR/issue-102989.rs:7:22
11+
|
12+
LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
13+
| ^^^^^^ not found in this scope
14+
15+
error[E0425]: cannot find value `x` in this scope
16+
--> $DIR/issue-102989.rs:11:13
17+
|
18+
LL | let x = x << 1;
19+
| ^ help: a local variable with a similar name exists: `f`
20+
21+
error[E0152]: found duplicate lang item `sized`
22+
--> $DIR/issue-102989.rs:5:1
23+
|
24+
LL | trait Sized { }
25+
| ^^^^^^^^^^^
26+
|
27+
= note: the lang item is first defined in crate `core` (which `std` depends on)
28+
= note: first definition in `core` loaded from SYSROOT/libcore-*.rlib
29+
= note: second definition in the local crate (`issue_102989`)
30+
31+
error[E0277]: the size for values of type `{integer}` cannot be known at compilation time
32+
--> $DIR/issue-102989.rs:11:15
33+
|
34+
LL | let x = x << 1;
35+
| ^^ doesn't have a size known at compile-time
36+
|
37+
= help: the trait `std::marker::Sized` is not implemented for `{integer}`
38+
39+
error[E0308]: mismatched types
40+
--> $DIR/issue-102989.rs:7:42
41+
|
42+
LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
43+
| ---------- ^^^^ expected `&u32`, found `()`
44+
| |
45+
| implicitly returns `()` as its body has no tail or `return` expression
46+
|
47+
note: consider returning one of these bindings
48+
--> $DIR/issue-102989.rs:7:30
49+
|
50+
LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
51+
| ^
52+
...
53+
LL | let x = x << 1;
54+
| ^
55+
56+
error: aborting due to 6 previous errors
57+
58+
Some errors have detailed explanations: E0152, E0277, E0308, E0412, E0425.
59+
For more information about an error, try `rustc --explain E0152`.

0 commit comments

Comments
 (0)