Skip to content

Commit db9c21f

Browse files
committed
Auto merge of #115909 - Dylan-DPC:rollup-uf96r2d, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #114965 (Remove Drop impl of mpsc Receiver and (Sync)Sender) - #115434 (make `Debug` impl for `ascii::Char` match that of `char`) - #115477 (Stabilize the `Saturating` type) - #115611 (add diagnostic for raw identifiers in format string) - #115654 (improve PassMode docs) - #115862 (Migrate `compiler/rustc_hir_typeck/src/callee.rs` to translatable diagnostics) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8ed1d4a + f082f1d commit db9c21f

File tree

34 files changed

+640
-434
lines changed

34 files changed

+640
-434
lines changed

compiler/rustc_builtin_macros/messages.ftl

+4-2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ builtin_macros_format_positional_after_named = positional arguments cannot follo
137137
.label = positional arguments must be before named arguments
138138
.named_args = named argument
139139
140+
builtin_macros_format_remove_raw_ident = remove the `r#`
141+
140142
builtin_macros_format_requires_string = requires at least a format string argument
141143
142144
builtin_macros_format_string_invalid = invalid format string: {$desc}
@@ -165,6 +167,8 @@ builtin_macros_format_unused_arg = {$named ->
165167
builtin_macros_format_unused_args = multiple unused formatting arguments
166168
.label = multiple missing formatting specifiers
167169
170+
builtin_macros_format_use_positional = consider using a positional formatting argument instead
171+
168172
builtin_macros_global_asm_clobber_abi = `clobber_abi` cannot be used with `global_asm!`
169173
170174
builtin_macros_invalid_crate_attribute = invalid crate attribute
@@ -205,8 +209,6 @@ builtin_macros_requires_cfg_pattern =
205209
206210
builtin_macros_should_panic = functions using `#[should_panic]` must return `()`
207211
208-
builtin_macros_sugg = consider using a positional formatting argument instead
209-
210212
builtin_macros_test_arg_non_lifetime = functions used as tests can not have any non-lifetime generic parameters
211213
212214
builtin_macros_test_args = functions used as tests can not have any arguments

compiler/rustc_builtin_macros/src/errors.rs

+23-12
Original file line numberDiff line numberDiff line change
@@ -539,18 +539,29 @@ pub(crate) struct InvalidFormatStringLabel {
539539
}
540540

541541
#[derive(Subdiagnostic)]
542-
#[multipart_suggestion(
543-
builtin_macros_sugg,
544-
style = "verbose",
545-
applicability = "machine-applicable"
546-
)]
547-
pub(crate) struct InvalidFormatStringSuggestion {
548-
#[suggestion_part(code = "{len}")]
549-
pub(crate) captured: Span,
550-
pub(crate) len: String,
551-
#[suggestion_part(code = ", {arg}")]
552-
pub(crate) span: Span,
553-
pub(crate) arg: String,
542+
pub(crate) enum InvalidFormatStringSuggestion {
543+
#[multipart_suggestion(
544+
builtin_macros_format_use_positional,
545+
style = "verbose",
546+
applicability = "machine-applicable"
547+
)]
548+
UsePositional {
549+
#[suggestion_part(code = "{len}")]
550+
captured: Span,
551+
len: String,
552+
#[suggestion_part(code = ", {arg}")]
553+
span: Span,
554+
arg: String,
555+
},
556+
#[suggestion(
557+
builtin_macros_format_remove_raw_ident,
558+
code = "",
559+
applicability = "machine-applicable"
560+
)]
561+
RemoveRawIdent {
562+
#[primary_span]
563+
span: Span,
564+
},
554565
}
555566

556567
#[derive(Diagnostic)]

compiler/rustc_builtin_macros/src/format.rs

+23-14
Original file line numberDiff line numberDiff line change
@@ -260,20 +260,29 @@ fn make_format_args(
260260
if let Some((label, span)) = err.secondary_label && is_source_literal {
261261
e.label_ = Some(errors::InvalidFormatStringLabel { span: fmt_span.from_inner(InnerSpan::new(span.start, span.end)), label } );
262262
}
263-
if err.should_be_replaced_with_positional_argument {
264-
let captured_arg_span =
265-
fmt_span.from_inner(InnerSpan::new(err.span.start, err.span.end));
266-
if let Ok(arg) = ecx.source_map().span_to_snippet(captured_arg_span) {
267-
let span = match args.unnamed_args().last() {
268-
Some(arg) => arg.expr.span,
269-
None => fmt_span,
270-
};
271-
e.sugg_ = Some(errors::InvalidFormatStringSuggestion {
272-
captured: captured_arg_span,
273-
len: args.unnamed_args().len().to_string(),
274-
span: span.shrink_to_hi(),
275-
arg,
276-
});
263+
match err.suggestion {
264+
parse::Suggestion::None => {}
265+
parse::Suggestion::UsePositional => {
266+
let captured_arg_span =
267+
fmt_span.from_inner(InnerSpan::new(err.span.start, err.span.end));
268+
if let Ok(arg) = ecx.source_map().span_to_snippet(captured_arg_span) {
269+
let span = match args.unnamed_args().last() {
270+
Some(arg) => arg.expr.span,
271+
None => fmt_span,
272+
};
273+
e.sugg_ = Some(errors::InvalidFormatStringSuggestion::UsePositional {
274+
captured: captured_arg_span,
275+
len: args.unnamed_args().len().to_string(),
276+
span: span.shrink_to_hi(),
277+
arg,
278+
});
279+
}
280+
}
281+
parse::Suggestion::RemoveRawIdent(span) => {
282+
if is_source_literal {
283+
let span = fmt_span.from_inner(InnerSpan::new(span.start, span.end));
284+
e.sugg_ = Some(errors::InvalidFormatStringSuggestion::RemoveRawIdent { span })
285+
}
277286
}
278287
}
279288
ecx.emit_err(e);

compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
100100
}
101101
_ => unreachable!("{:?}", self.layout.abi),
102102
},
103-
PassMode::Cast(ref cast, pad_i32) => {
103+
PassMode::Cast { ref cast, pad_i32 } => {
104104
assert!(!pad_i32, "padding support not yet implemented");
105105
cast_target_to_abi_params(cast)
106106
}
107-
PassMode::Indirect { attrs, extra_attrs: None, on_stack } => {
107+
PassMode::Indirect { attrs, meta_attrs: None, on_stack } => {
108108
if on_stack {
109109
// Abi requires aligning struct size to pointer size
110110
let size = self.layout.size.align_to(tcx.data_layout.pointer_align.abi);
@@ -117,11 +117,11 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
117117
smallvec![apply_arg_attrs_to_abi_param(AbiParam::new(pointer_ty(tcx)), attrs)]
118118
}
119119
}
120-
PassMode::Indirect { attrs, extra_attrs: Some(extra_attrs), on_stack } => {
120+
PassMode::Indirect { attrs, meta_attrs: Some(meta_attrs), on_stack } => {
121121
assert!(!on_stack);
122122
smallvec![
123123
apply_arg_attrs_to_abi_param(AbiParam::new(pointer_ty(tcx)), attrs),
124-
apply_arg_attrs_to_abi_param(AbiParam::new(pointer_ty(tcx)), extra_attrs),
124+
apply_arg_attrs_to_abi_param(AbiParam::new(pointer_ty(tcx)), meta_attrs),
125125
]
126126
}
127127
}
@@ -148,14 +148,14 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
148148
}
149149
_ => unreachable!("{:?}", self.layout.abi),
150150
},
151-
PassMode::Cast(ref cast, _) => {
151+
PassMode::Cast { ref cast, .. } => {
152152
(None, cast_target_to_abi_params(cast).into_iter().collect())
153153
}
154-
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack } => {
154+
PassMode::Indirect { attrs: _, meta_attrs: None, on_stack } => {
155155
assert!(!on_stack);
156156
(Some(AbiParam::special(pointer_ty(tcx), ArgumentPurpose::StructReturn)), vec![])
157157
}
158-
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => {
158+
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
159159
unreachable!("unsized return value")
160160
}
161161
}
@@ -229,7 +229,7 @@ pub(super) fn adjust_arg_for_abi<'tcx>(
229229
let (a, b) = arg.load_scalar_pair(fx);
230230
smallvec![a, b]
231231
}
232-
PassMode::Cast(ref cast, _) => to_casted_value(fx, arg, cast),
232+
PassMode::Cast { ref cast, .. } => to_casted_value(fx, arg, cast),
233233
PassMode::Indirect { .. } => {
234234
if is_owned {
235235
match arg.force_stack(fx) {
@@ -287,14 +287,14 @@ pub(super) fn cvalue_for_param<'tcx>(
287287
assert_eq!(block_params.len(), 2, "{:?}", block_params);
288288
Some(CValue::by_val_pair(block_params[0], block_params[1], arg_abi.layout))
289289
}
290-
PassMode::Cast(ref cast, _) => {
290+
PassMode::Cast { ref cast, .. } => {
291291
Some(from_casted_value(fx, &block_params, arg_abi.layout, cast))
292292
}
293-
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
293+
PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => {
294294
assert_eq!(block_params.len(), 1, "{:?}", block_params);
295295
Some(CValue::by_ref(Pointer::new(block_params[0]), arg_abi.layout))
296296
}
297-
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => {
297+
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
298298
assert_eq!(block_params.len(), 2, "{:?}", block_params);
299299
Some(CValue::by_ref_unsized(
300300
Pointer::new(block_params[0]),

compiler/rustc_codegen_cranelift/src/abi/returning.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(super) fn codegen_return_param<'tcx>(
1313
block_params_iter: &mut impl Iterator<Item = Value>,
1414
) -> CPlace<'tcx> {
1515
let (ret_place, ret_param): (_, SmallVec<[_; 2]>) = match fx.fn_abi.as_ref().unwrap().ret.mode {
16-
PassMode::Ignore | PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast(..) => {
16+
PassMode::Ignore | PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast { .. } => {
1717
let is_ssa =
1818
ssa_analyzed[RETURN_PLACE].is_ssa(fx, fx.fn_abi.as_ref().unwrap().ret.layout.ty);
1919
(
@@ -26,15 +26,15 @@ pub(super) fn codegen_return_param<'tcx>(
2626
smallvec![],
2727
)
2828
}
29-
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
29+
PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => {
3030
let ret_param = block_params_iter.next().unwrap();
3131
assert_eq!(fx.bcx.func.dfg.value_type(ret_param), fx.pointer_type);
3232
(
3333
CPlace::for_ptr(Pointer::new(ret_param), fx.fn_abi.as_ref().unwrap().ret.layout),
3434
smallvec![ret_param],
3535
)
3636
}
37-
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => {
37+
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
3838
unreachable!("unsized return value")
3939
}
4040
};
@@ -62,7 +62,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx>(
6262
) {
6363
let (ret_temp_place, return_ptr) = match ret_arg_abi.mode {
6464
PassMode::Ignore => (None, None),
65-
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
65+
PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => {
6666
if let Some(ret_ptr) = ret_place.try_to_ptr() {
6767
// This is an optimization to prevent unnecessary copies of the return value when
6868
// the return place is already a memory place as opposed to a register.
@@ -73,10 +73,10 @@ pub(super) fn codegen_with_call_return_arg<'tcx>(
7373
(Some(place), Some(place.to_ptr().get_addr(fx)))
7474
}
7575
}
76-
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => {
76+
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
7777
unreachable!("unsized return value")
7878
}
79-
PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast(..) => (None, None),
79+
PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast { .. } => (None, None),
8080
};
8181

8282
let call_inst = f(fx, return_ptr);
@@ -93,21 +93,21 @@ pub(super) fn codegen_with_call_return_arg<'tcx>(
9393
ret_place
9494
.write_cvalue(fx, CValue::by_val_pair(ret_val_a, ret_val_b, ret_arg_abi.layout));
9595
}
96-
PassMode::Cast(ref cast, _) => {
96+
PassMode::Cast { ref cast, .. } => {
9797
let results =
9898
fx.bcx.inst_results(call_inst).iter().copied().collect::<SmallVec<[Value; 2]>>();
9999
let result =
100100
super::pass_mode::from_casted_value(fx, &results, ret_place.layout(), cast);
101101
ret_place.write_cvalue(fx, result);
102102
}
103-
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
103+
PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => {
104104
if let Some(ret_temp_place) = ret_temp_place {
105105
// If ret_temp_place is None, it is not necessary to copy the return value.
106106
let ret_temp_value = ret_temp_place.to_cvalue(fx);
107107
ret_place.write_cvalue(fx, ret_temp_value);
108108
}
109109
}
110-
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => {
110+
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
111111
unreachable!("unsized return value")
112112
}
113113
}
@@ -116,10 +116,10 @@ pub(super) fn codegen_with_call_return_arg<'tcx>(
116116
/// Codegen a return instruction with the right return value(s) if any.
117117
pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, '_>) {
118118
match fx.fn_abi.as_ref().unwrap().ret.mode {
119-
PassMode::Ignore | PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
119+
PassMode::Ignore | PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => {
120120
fx.bcx.ins().return_(&[]);
121121
}
122-
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => {
122+
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
123123
unreachable!("unsized return value")
124124
}
125125
PassMode::Direct(_) => {
@@ -132,7 +132,7 @@ pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, '_>) {
132132
let (ret_val_a, ret_val_b) = place.to_cvalue(fx).load_scalar_pair(fx);
133133
fx.bcx.ins().return_(&[ret_val_a, ret_val_b]);
134134
}
135-
PassMode::Cast(ref cast, _) => {
135+
PassMode::Cast { ref cast, .. } => {
136136
let place = fx.get_local_place(RETURN_PLACE);
137137
let ret_val = place.to_cvalue(fx);
138138
let ret_vals = super::pass_mode::to_casted_value(fx, ret_val, cast);

compiler/rustc_codegen_gcc/src/abi.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
113113
match self.ret.mode {
114114
PassMode::Ignore => cx.type_void(),
115115
PassMode::Direct(_) | PassMode::Pair(..) => self.ret.layout.immediate_gcc_type(cx),
116-
PassMode::Cast(ref cast, _) => cast.gcc_type(cx),
116+
PassMode::Cast { ref cast, .. } => cast.gcc_type(cx),
117117
PassMode::Indirect { .. } => {
118118
argument_tys.push(cx.type_ptr_to(self.ret.memory_ty(cx)));
119119
cx.type_void()
@@ -129,21 +129,21 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
129129
argument_tys.push(arg.layout.scalar_pair_element_gcc_type(cx, 1));
130130
continue;
131131
}
132-
PassMode::Indirect { extra_attrs: Some(_), .. } => {
132+
PassMode::Indirect { meta_attrs: Some(_), .. } => {
133133
unimplemented!();
134134
}
135-
PassMode::Cast(ref cast, pad_i32) => {
135+
PassMode::Cast { ref cast, pad_i32 } => {
136136
// add padding
137137
if pad_i32 {
138138
argument_tys.push(Reg::i32().gcc_type(cx));
139139
}
140140
cast.gcc_type(cx)
141141
}
142-
PassMode::Indirect { extra_attrs: None, on_stack: true, .. } => {
142+
PassMode::Indirect { meta_attrs: None, on_stack: true, .. } => {
143143
on_stack_param_indices.insert(argument_tys.len());
144144
arg.memory_ty(cx)
145145
},
146-
PassMode::Indirect { extra_attrs: None, on_stack: false, .. } => cx.type_ptr_to(arg.memory_ty(cx)),
146+
PassMode::Indirect { meta_attrs: None, on_stack: false, .. } => cx.type_ptr_to(arg.memory_ty(cx)),
147147
};
148148
argument_tys.push(arg_ty);
149149
}

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
144144
sym::volatile_load | sym::unaligned_volatile_load => {
145145
let tp_ty = fn_args.type_at(0);
146146
let mut ptr = args[0].immediate();
147-
if let PassMode::Cast(ty, _) = &fn_abi.ret.mode {
147+
if let PassMode::Cast { cast: ty, .. } = &fn_abi.ret.mode {
148148
ptr = self.pointercast(ptr, self.type_ptr_to(ty.gcc_type(self)));
149149
}
150150
let load = self.volatile_load(ptr.get_type(), ptr);
@@ -353,7 +353,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
353353
};
354354

355355
if !fn_abi.ret.is_ignore() {
356-
if let PassMode::Cast(ty, _) = &fn_abi.ret.mode {
356+
if let PassMode::Cast { cast: ty, .. } = &fn_abi.ret.mode {
357357
let ptr_llty = self.type_ptr_to(ty.gcc_type(self));
358358
let ptr = self.pointercast(result.llval, ptr_llty);
359359
self.store(llval, ptr, result.align);
@@ -449,7 +449,7 @@ impl<'gcc, 'tcx> ArgAbiExt<'gcc, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
449449
else if self.is_unsized_indirect() {
450450
bug!("unsized `ArgAbi` must be handled through `store_fn_arg`");
451451
}
452-
else if let PassMode::Cast(ref cast, _) = self.mode {
452+
else if let PassMode::Cast { ref cast, .. } = self.mode {
453453
// FIXME(eddyb): Figure out when the simpler Store is safe, clang
454454
// uses it for i16 -> {i8, i8}, but not for i24 -> {i8, i8, i8}.
455455
let can_store_through_cast_ptr = false;
@@ -511,10 +511,10 @@ impl<'gcc, 'tcx> ArgAbiExt<'gcc, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
511511
PassMode::Pair(..) => {
512512
OperandValue::Pair(next(), next()).store(bx, dst);
513513
},
514-
PassMode::Indirect { extra_attrs: Some(_), .. } => {
514+
PassMode::Indirect { meta_attrs: Some(_), .. } => {
515515
OperandValue::Ref(next(), Some(next()), self.layout.align.abi).store(bx, dst);
516516
},
517-
PassMode::Direct(_) | PassMode::Indirect { extra_attrs: None, .. } | PassMode::Cast(..) => {
517+
PassMode::Direct(_) | PassMode::Indirect { meta_attrs: None, .. } | PassMode::Cast { .. } => {
518518
let next_arg = next();
519519
self.store(bx, next_arg, dst);
520520
},

0 commit comments

Comments
 (0)