Skip to content

Commit 7f716ba

Browse files
authored
Rollup merge of rust-lang#103003 - TaKO8Ki:fix-102989, r=compiler-errors
Fix `suggest_floating_point_literal` ICE Fixes rust-lang#102989
2 parents 3966066 + 5378677 commit 7f716ba

File tree

3 files changed

+100
-13
lines changed

3 files changed

+100
-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

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//~ ERROR can't find crate for `profiler_builtins`
2+
// compile-flags: -Cinstrument-coverage
3+
// normalize-stderr-test "loaded from .*libcore-.*.rlib" -> "loaded from SYSROOT/libcore-*.rlib"
4+
5+
#![no_core]
6+
#![feature(no_core, lang_items)]
7+
#[lang="sized"]
8+
trait Sized { } //~ ERROR found duplicate lang item `sized`
9+
10+
fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
11+
//~^ ERROR `self` parameter is only allowed in associated functions
12+
//~| ERROR cannot find type `Struct` in this scope
13+
//~| ERROR mismatched types
14+
let x = x << 1;
15+
//~^ ERROR the size for values of type `{integer}` cannot be known at compilation time
16+
//~| ERROR cannot find value `x` in this scope
17+
}
18+
19+
fn main() {}
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
error: `self` parameter is only allowed in associated functions
2+
--> $DIR/issue-102989.rs:10: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:10: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:14:13
17+
|
18+
LL | let x = x << 1;
19+
| ^ help: a local variable with a similar name exists: `f`
20+
21+
error: `profiler_builtins` crate (required by compiler options) is not compatible with crate attribute `#![no_core]`
22+
23+
error[E0463]: can't find crate for `profiler_builtins`
24+
|
25+
= note: the compiler may have been built without the profiler runtime
26+
27+
error[E0152]: found duplicate lang item `sized`
28+
--> $DIR/issue-102989.rs:8:1
29+
|
30+
LL | trait Sized { }
31+
| ^^^^^^^^^^^
32+
|
33+
= note: the lang item is first defined in crate `core`.
34+
= note: first definition in `core` loaded from SYSROOT/libcore-*.rlib
35+
= note: second definition in the local crate (`issue_102989`)
36+
37+
error: `#[panic_handler]` function required, but not found
38+
39+
error: language item required, but not found: `eh_personality`
40+
|
41+
= note: this can occur when a binary crate with `#![no_std]` is compiled for a target where `eh_personality` is defined in the standard library
42+
= help: you may be able to compile for a target that doesn't need `eh_personality`, specify a target with `--target` or in `.cargo/config`
43+
44+
error[E0277]: the size for values of type `{integer}` cannot be known at compilation time
45+
--> $DIR/issue-102989.rs:14:15
46+
|
47+
LL | let x = x << 1;
48+
| ^^ doesn't have a size known at compile-time
49+
|
50+
= help: the trait `core::marker::Sized` is not implemented for `{integer}`
51+
52+
error[E0308]: mismatched types
53+
--> $DIR/issue-102989.rs:10:42
54+
|
55+
LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
56+
| ---------- ^^^^ expected `&u32`, found `()`
57+
| |
58+
| implicitly returns `()` as its body has no tail or `return` expression
59+
|
60+
note: consider returning one of these bindings
61+
--> $DIR/issue-102989.rs:10:30
62+
|
63+
LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
64+
| ^
65+
...
66+
LL | let x = x << 1;
67+
| ^
68+
69+
error: aborting due to 10 previous errors
70+
71+
Some errors have detailed explanations: E0152, E0277, E0308, E0412, E0425, E0463.
72+
For more information about an error, try `rustc --explain E0152`.

0 commit comments

Comments
 (0)