Skip to content

Commit 1438902

Browse files
authored
Unrolled build for rust-lang#133620
Rollup merge of rust-lang#133620 - dev-ardi:simplify-hir_typeck_pass_to_variadic_function, r=compiler-errors Simplify hir_typeck_pass_to_variadic_function r? ``@compiler-errors`` This reworks a bit how the diagnostic is generated so that it does the same as rust-lang#133538 The `help` is useless now so I removed it
2 parents e48ddd8 + ce98bf3 commit 1438902

File tree

5 files changed

+69
-27
lines changed

5 files changed

+69
-27
lines changed

Diff for: compiler/rustc_hir_typeck/messages.ftl

-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ hir_typeck_option_result_copied = use `{$def_path}::copied` to copy the value in
146146
147147
hir_typeck_pass_to_variadic_function = can't pass `{$ty}` to variadic function
148148
.suggestion = cast the value to `{$cast_ty}`
149-
.help = cast the value to `{$cast_ty}`
150149
.teach_help = certain types, like `{$ty}`, must be casted before passing them to a variadic function, because of arcane ABI rules dictated by the C standard
151150
152151
hir_typeck_ptr_cast_add_auto_to_object = adding {$traits_len ->

Diff for: compiler/rustc_hir_typeck/src/errors.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -789,11 +789,8 @@ pub(crate) struct PassToVariadicFunction<'a, 'tcx> {
789789
pub span: Span,
790790
pub ty: Ty<'tcx>,
791791
pub cast_ty: &'a str,
792-
#[suggestion(code = "{replace}", applicability = "machine-applicable")]
793-
pub sugg_span: Option<Span>,
794-
pub replace: String,
795-
#[help]
796-
pub help: bool,
792+
#[suggestion(code = " as {cast_ty}", applicability = "machine-applicable", style = "verbose")]
793+
pub sugg_span: Span,
797794
#[note(hir_typeck_teach_help)]
798795
pub(crate) teach: bool,
799796
}

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -440,20 +440,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
440440
ty: Ty<'tcx>,
441441
cast_ty: &str,
442442
) {
443-
let (sugg_span, replace, help) =
444-
if let Ok(snippet) = sess.source_map().span_to_snippet(span) {
445-
(Some(span), format!("{snippet} as {cast_ty}"), false)
446-
} else {
447-
(None, "".to_string(), true)
448-
};
449-
450443
sess.dcx().emit_err(errors::PassToVariadicFunction {
451444
span,
452445
ty,
453446
cast_ty,
454-
help,
455-
replace,
456-
sugg_span,
447+
sugg_span: span.shrink_to_hi(),
457448
teach: sess.teach(E0617),
458449
});
459450
}

Diff for: tests/ui/c-variadic/variadic-ffi-1.stderr

+36-6
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,67 @@ error[E0617]: can't pass `f32` to variadic function
6262
--> $DIR/variadic-ffi-1.rs:28:19
6363
|
6464
LL | foo(1, 2, 3f32);
65-
| ^^^^ help: cast the value to `c_double`: `3f32 as c_double`
65+
| ^^^^
66+
|
67+
help: cast the value to `c_double`
68+
|
69+
LL | foo(1, 2, 3f32 as c_double);
70+
| +++++++++++
6671

6772
error[E0617]: can't pass `bool` to variadic function
6873
--> $DIR/variadic-ffi-1.rs:29:19
6974
|
7075
LL | foo(1, 2, true);
71-
| ^^^^ help: cast the value to `c_int`: `true as c_int`
76+
| ^^^^
77+
|
78+
help: cast the value to `c_int`
79+
|
80+
LL | foo(1, 2, true as c_int);
81+
| ++++++++
7282

7383
error[E0617]: can't pass `i8` to variadic function
7484
--> $DIR/variadic-ffi-1.rs:30:19
7585
|
7686
LL | foo(1, 2, 1i8);
77-
| ^^^ help: cast the value to `c_int`: `1i8 as c_int`
87+
| ^^^
88+
|
89+
help: cast the value to `c_int`
90+
|
91+
LL | foo(1, 2, 1i8 as c_int);
92+
| ++++++++
7893

7994
error[E0617]: can't pass `u8` to variadic function
8095
--> $DIR/variadic-ffi-1.rs:31:19
8196
|
8297
LL | foo(1, 2, 1u8);
83-
| ^^^ help: cast the value to `c_uint`: `1u8 as c_uint`
98+
| ^^^
99+
|
100+
help: cast the value to `c_uint`
101+
|
102+
LL | foo(1, 2, 1u8 as c_uint);
103+
| +++++++++
84104

85105
error[E0617]: can't pass `i16` to variadic function
86106
--> $DIR/variadic-ffi-1.rs:32:19
87107
|
88108
LL | foo(1, 2, 1i16);
89-
| ^^^^ help: cast the value to `c_int`: `1i16 as c_int`
109+
| ^^^^
110+
|
111+
help: cast the value to `c_int`
112+
|
113+
LL | foo(1, 2, 1i16 as c_int);
114+
| ++++++++
90115

91116
error[E0617]: can't pass `u16` to variadic function
92117
--> $DIR/variadic-ffi-1.rs:33:19
93118
|
94119
LL | foo(1, 2, 1u16);
95-
| ^^^^ help: cast the value to `c_uint`: `1u16 as c_uint`
120+
| ^^^^
121+
|
122+
help: cast the value to `c_uint`
123+
|
124+
LL | foo(1, 2, 1u16 as c_uint);
125+
| +++++++++
96126

97127
error: aborting due to 11 previous errors
98128

Diff for: tests/ui/error-codes/E0617.stderr

+30-5
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,56 @@ error[E0617]: can't pass `f32` to variadic function
22
--> $DIR/E0617.rs:7:36
33
|
44
LL | printf(::std::ptr::null(), 0f32);
5-
| ^^^^ help: cast the value to `c_double`: `0f32 as c_double`
5+
| ^^^^
6+
|
7+
help: cast the value to `c_double`
8+
|
9+
LL | printf(::std::ptr::null(), 0f32 as c_double);
10+
| +++++++++++
611

712
error[E0617]: can't pass `i8` to variadic function
813
--> $DIR/E0617.rs:10:36
914
|
1015
LL | printf(::std::ptr::null(), 0i8);
11-
| ^^^ help: cast the value to `c_int`: `0i8 as c_int`
16+
| ^^^
17+
|
18+
help: cast the value to `c_int`
19+
|
20+
LL | printf(::std::ptr::null(), 0i8 as c_int);
21+
| ++++++++
1222

1323
error[E0617]: can't pass `i16` to variadic function
1424
--> $DIR/E0617.rs:13:36
1525
|
1626
LL | printf(::std::ptr::null(), 0i16);
17-
| ^^^^ help: cast the value to `c_int`: `0i16 as c_int`
27+
| ^^^^
28+
|
29+
help: cast the value to `c_int`
30+
|
31+
LL | printf(::std::ptr::null(), 0i16 as c_int);
32+
| ++++++++
1833

1934
error[E0617]: can't pass `u8` to variadic function
2035
--> $DIR/E0617.rs:16:36
2136
|
2237
LL | printf(::std::ptr::null(), 0u8);
23-
| ^^^ help: cast the value to `c_uint`: `0u8 as c_uint`
38+
| ^^^
39+
|
40+
help: cast the value to `c_uint`
41+
|
42+
LL | printf(::std::ptr::null(), 0u8 as c_uint);
43+
| +++++++++
2444

2545
error[E0617]: can't pass `u16` to variadic function
2646
--> $DIR/E0617.rs:19:36
2747
|
2848
LL | printf(::std::ptr::null(), 0u16);
29-
| ^^^^ help: cast the value to `c_uint`: `0u16 as c_uint`
49+
| ^^^^
50+
|
51+
help: cast the value to `c_uint`
52+
|
53+
LL | printf(::std::ptr::null(), 0u16 as c_uint);
54+
| +++++++++
3055

3156
error[E0617]: can't pass a function item to a variadic function
3257
--> $DIR/E0617.rs:22:36

0 commit comments

Comments
 (0)