Skip to content

Commit 3c17c84

Browse files
committed
Auto merge of rust-lang#95180 - matthiaskrgr:rollup-ai1ch2s, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#95074 (Refactor: use `format-args-capture` and remove unnecessary nested if blocks in some parts of `rust_passes`) - rust-lang#95085 (Return err instead of ICE) - rust-lang#95116 (Add needs-* directives to many tests) - rust-lang#95129 (Remove animation on source sidebar) - rust-lang#95166 (Update the unstable book with the new `values()` form of check-cfg) - rust-lang#95175 (move `adt_const_params` to its own tracking issue) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 44628f7 + 44200a9 commit 3c17c84

40 files changed

+250
-222
lines changed

compiler/rustc_feature/src/active.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ declare_features! (
287287
/// Allows `extern "x86-interrupt" fn()`.
288288
(active, abi_x86_interrupt, "1.17.0", Some(40180), None),
289289
/// Allows additional const parameter types, such as `&'static str` or user defined types
290-
(incomplete, adt_const_params, "1.56.0", Some(44580), None),
290+
(incomplete, adt_const_params, "1.56.0", Some(95174), None),
291291
/// Allows defining an `#[alloc_error_handler]`.
292292
(active, alloc_error_handler, "1.29.0", Some(51540), None),
293293
/// Allows explicit discriminants on non-unit enum variants.

compiler/rustc_passes/src/check_attr.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ impl CheckAttrVisitor<'_> {
196196
fn inline_attr_str_error_with_macro_def(&self, hir_id: HirId, attr: &Attribute, sym: &str) {
197197
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
198198
lint.build(&format!(
199-
"`#[{}]` is ignored on struct fields, match arms and macro defs",
200-
sym,
199+
"`#[{sym}]` is ignored on struct fields, match arms and macro defs",
201200
))
202201
.warn(
203202
"this was previously accepted by the compiler but is \
@@ -214,7 +213,7 @@ impl CheckAttrVisitor<'_> {
214213

215214
fn inline_attr_str_error_without_macro_def(&self, hir_id: HirId, attr: &Attribute, sym: &str) {
216215
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
217-
lint.build(&format!("`#[{}]` is ignored on struct fields and match arms", sym))
216+
lint.build(&format!("`#[{sym}]` is ignored on struct fields and match arms"))
218217
.warn(
219218
"this was previously accepted by the compiler but is \
220219
being phased out; it will become a hard error in \
@@ -721,7 +720,7 @@ impl CheckAttrVisitor<'_> {
721720
.sess
722721
.struct_span_err(
723722
meta.name_value_literal_span().unwrap_or_else(|| meta.span()),
724-
&format!("`{}` is not a valid identifier", doc_keyword),
723+
&format!("`{doc_keyword}` is not a valid identifier"),
725724
)
726725
.emit();
727726
return false;
@@ -805,8 +804,7 @@ impl CheckAttrVisitor<'_> {
805804
.struct_span_err(
806805
meta.span(),
807806
&format!(
808-
"`#![doc({} = \"...\")]` isn't allowed as a crate-level attribute",
809-
attr_name,
807+
"`#![doc({attr_name} = \"...\")]` isn't allowed as a crate-level attribute",
810808
),
811809
)
812810
.emit();
@@ -1035,8 +1033,7 @@ impl CheckAttrVisitor<'_> {
10351033
attr.meta().unwrap().span,
10361034
"use `doc = include_str!` instead",
10371035
format!(
1038-
"#{}[doc = include_str!(\"{}\")]",
1039-
inner, value
1036+
"#{inner}[doc = include_str!(\"{value}\")]",
10401037
),
10411038
applicability,
10421039
);
@@ -1230,7 +1227,7 @@ impl CheckAttrVisitor<'_> {
12301227
if let Some(value) = attr.value_str() {
12311228
diag.span_help(
12321229
attr.span,
1233-
&format!(r#"try `#[link(name = "{}")]` instead"#, value),
1230+
&format!(r#"try `#[link(name = "{value}")]` instead"#),
12341231
);
12351232
} else {
12361233
diag.span_help(attr.span, r#"try `#[link(name = "...")]` instead"#);
@@ -1518,15 +1515,14 @@ impl CheckAttrVisitor<'_> {
15181515
};
15191516
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
15201517
lint.build(&format!(
1521-
"`#[no_mangle]` has no effect on a foreign {}",
1522-
foreign_item_kind
1518+
"`#[no_mangle]` has no effect on a foreign {foreign_item_kind}"
15231519
))
15241520
.warn(
15251521
"this was previously accepted by the compiler but is \
15261522
being phased out; it will become a hard error in \
15271523
a future release!",
15281524
)
1529-
.span_label(span, format!("foreign {}", foreign_item_kind))
1525+
.span_label(span, format!("foreign {foreign_item_kind}"))
15301526
.note("symbol names in extern blocks are not mangled")
15311527
.span_suggestion(
15321528
attr.span,
@@ -1692,9 +1688,9 @@ impl CheckAttrVisitor<'_> {
16921688
hint.span(),
16931689
E0517,
16941690
"{}",
1695-
&format!("attribute should be applied to {} {}", article, allowed_targets)
1691+
&format!("attribute should be applied to {article} {allowed_targets}")
16961692
)
1697-
.span_label(span, &format!("not {} {}", article, allowed_targets))
1693+
.span_label(span, &format!("not {article} {allowed_targets}"))
16981694
.emit();
16991695
}
17001696

compiler/rustc_passes/src/check_const.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ impl<'tcx> hir::itemlikevisit::ItemLikeVisitor<'tcx> for CheckConstTraitVisitor<
8080
/// of the trait being implemented; as those provided functions can be non-const.
8181
fn visit_item<'hir>(&mut self, item: &'hir hir::Item<'hir>) {
8282
let _: Option<_> = try {
83-
if let hir::ItemKind::Impl(ref imp) = item.kind {
84-
if let hir::Constness::Const = imp.constness {
83+
if let hir::ItemKind::Impl(ref imp) = item.kind && let hir::Constness::Const = imp.constness {
8584
let trait_def_id = imp.of_trait.as_ref()?.trait_def_id()?;
8685
let ancestors = self
8786
.tcx
@@ -132,7 +131,6 @@ impl<'tcx> hir::itemlikevisit::ItemLikeVisitor<'tcx> for CheckConstTraitVisitor<
132131
.note(&format!("`{}` not implemented", to_implement.join("`, `")))
133132
.emit();
134133
}
135-
}
136134
}
137135
};
138136
}

compiler/rustc_passes/src/diagnostic_items.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,9 @@ fn collect_item(tcx: TyCtxt<'_>, items: &mut DiagnosticItems, name: Symbol, item
6161
if let Some(original_def_id) = items.name_to_id.insert(name, item_def_id) {
6262
if original_def_id != item_def_id {
6363
let mut err = match tcx.hir().span_if_local(item_def_id) {
64-
Some(span) => tcx.sess.struct_span_err(
65-
span,
66-
&format!("duplicate diagnostic item found: `{}`.", name),
67-
),
64+
Some(span) => tcx
65+
.sess
66+
.struct_span_err(span, &format!("duplicate diagnostic item found: `{name}`.")),
6867
None => tcx.sess.struct_err(&format!(
6968
"duplicate diagnostic item in crate `{}`: `{}`.",
7069
tcx.crate_name(item_def_id.krate),

compiler/rustc_passes/src/entry.rs

+23-29
Original file line numberDiff line numberDiff line change
@@ -148,33 +148,29 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) -> Option<(De
148148
} else if let Some((def_id, _)) = visitor.attr_main_fn {
149149
Some((def_id.to_def_id(), EntryFnType::Main))
150150
} else {
151-
if let Some(main_def) = tcx.resolutions(()).main_def {
152-
if let Some(def_id) = main_def.opt_fn_def_id() {
153-
// non-local main imports are handled below
154-
if let Some(def_id) = def_id.as_local() {
155-
if matches!(tcx.hir().find_by_def_id(def_id), Some(Node::ForeignItem(_))) {
156-
tcx.sess
157-
.struct_span_err(
158-
tcx.def_span(def_id),
159-
"the `main` function cannot be declared in an `extern` block",
160-
)
161-
.emit();
162-
return None;
163-
}
164-
}
165-
166-
if main_def.is_import && !tcx.features().imported_main {
167-
let span = main_def.span;
168-
feature_err(
169-
&tcx.sess.parse_sess,
170-
sym::imported_main,
171-
span,
172-
"using an imported function as entry point `main` is experimental",
151+
if let Some(main_def) = tcx.resolutions(()).main_def && let Some(def_id) = main_def.opt_fn_def_id() {
152+
// non-local main imports are handled below
153+
if let Some(def_id) = def_id.as_local() && matches!(tcx.hir().find_by_def_id(def_id), Some(Node::ForeignItem(_))) {
154+
tcx.sess
155+
.struct_span_err(
156+
tcx.def_span(def_id),
157+
"the `main` function cannot be declared in an `extern` block",
173158
)
174159
.emit();
175-
}
176-
return Some((def_id, EntryFnType::Main));
160+
return None;
177161
}
162+
163+
if main_def.is_import && !tcx.features().imported_main {
164+
let span = main_def.span;
165+
feature_err(
166+
&tcx.sess.parse_sess,
167+
sym::imported_main,
168+
span,
169+
"using an imported function as entry point `main` is experimental",
170+
)
171+
.emit();
172+
}
173+
return Some((def_id, EntryFnType::Main));
178174
}
179175
no_main_err(tcx, visitor);
180176
None
@@ -225,11 +221,9 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
225221
err.note(&note);
226222
}
227223

228-
if let Some(main_def) = tcx.resolutions(()).main_def {
229-
if main_def.opt_fn_def_id().is_none() {
230-
// There is something at `crate::main`, but it is not a function definition.
231-
err.span_label(main_def.span, "non-function item at `crate::main` is found");
232-
}
224+
if let Some(main_def) = tcx.resolutions(()).main_def && main_def.opt_fn_def_id().is_none(){
225+
// There is something at `crate::main`, but it is not a function definition.
226+
err.span_label(main_def.span, "non-function item at `crate::main` is found");
233227
}
234228

235229
if tcx.sess.teach(&err.get_code().unwrap()) {

compiler/rustc_passes/src/intrinsicck.rs

+24-28
Original file line numberDiff line numberDiff line change
@@ -79,27 +79,25 @@ impl<'tcx> ExprVisitor<'tcx> {
7979
// Special-case transmuting from `typeof(function)` and
8080
// `Option<typeof(function)>` to present a clearer error.
8181
let from = unpack_option_like(self.tcx, from);
82-
if let (&ty::FnDef(..), SizeSkeleton::Known(size_to)) = (from.kind(), sk_to) {
83-
if size_to == Pointer.size(&self.tcx) {
84-
struct_span_err!(self.tcx.sess, span, E0591, "can't transmute zero-sized type")
85-
.note(&format!("source type: {}", from))
86-
.note(&format!("target type: {}", to))
87-
.help("cast with `as` to a pointer instead")
88-
.emit();
89-
return;
90-
}
82+
if let (&ty::FnDef(..), SizeSkeleton::Known(size_to)) = (from.kind(), sk_to) && size_to == Pointer.size(&self.tcx) {
83+
struct_span_err!(self.tcx.sess, span, E0591, "can't transmute zero-sized type")
84+
.note(&format!("source type: {from}"))
85+
.note(&format!("target type: {to}"))
86+
.help("cast with `as` to a pointer instead")
87+
.emit();
88+
return;
9189
}
9290
}
9391

9492
// Try to display a sensible error with as much information as possible.
9593
let skeleton_string = |ty: Ty<'tcx>, sk| match sk {
9694
Ok(SizeSkeleton::Known(size)) => format!("{} bits", size.bits()),
97-
Ok(SizeSkeleton::Pointer { tail, .. }) => format!("pointer to `{}`", tail),
95+
Ok(SizeSkeleton::Pointer { tail, .. }) => format!("pointer to `{tail}`"),
9896
Err(LayoutError::Unknown(bad)) => {
9997
if bad == ty {
10098
"this type does not have a fixed size".to_owned()
10199
} else {
102-
format!("size can vary because of {}", bad)
100+
format!("size can vary because of {bad}")
103101
}
104102
}
105103
Err(err) => err.to_string(),
@@ -113,7 +111,7 @@ impl<'tcx> ExprVisitor<'tcx> {
113111
or dependently-sized types"
114112
);
115113
if from == to {
116-
err.note(&format!("`{}` does not have a fixed size", from));
114+
err.note(&format!("`{from}` does not have a fixed size"));
117115
} else {
118116
err.note(&format!("source type: `{}` ({})", from, skeleton_string(from, sk_from)))
119117
.note(&format!("target type: `{}` ({})", to, skeleton_string(to, sk_to)));
@@ -201,7 +199,7 @@ impl<'tcx> ExprVisitor<'tcx> {
201199
_ => None,
202200
};
203201
let Some(asm_ty) = asm_ty else {
204-
let msg = &format!("cannot use value of type `{}` for inline assembly", ty);
202+
let msg = &format!("cannot use value of type `{ty}` for inline assembly");
205203
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
206204
err.note(
207205
"only integers, floats, SIMD vectors, pointers and function pointers \
@@ -216,7 +214,7 @@ impl<'tcx> ExprVisitor<'tcx> {
216214
if !ty.is_copy_modulo_regions(self.tcx.at(DUMMY_SP), self.param_env) {
217215
let msg = "arguments for inline assembly must be copyable";
218216
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
219-
err.note(&format!("`{}` does not implement the Copy trait", ty));
217+
err.note(&format!("`{ty}` does not implement the Copy trait"));
220218
err.emit();
221219
}
222220

@@ -237,7 +235,7 @@ impl<'tcx> ExprVisitor<'tcx> {
237235
in_expr.span,
238236
&format!("type `{}`", self.typeck_results.expr_ty_adjusted(in_expr)),
239237
);
240-
err.span_label(expr.span, &format!("type `{}`", ty));
238+
err.span_label(expr.span, &format!("type `{ty}`"));
241239
err.note(
242240
"asm inout arguments must have the same type, \
243241
unless they are both pointers or integers of the same size",
@@ -256,7 +254,7 @@ impl<'tcx> ExprVisitor<'tcx> {
256254
let reg_class = reg.reg_class();
257255
let supported_tys = reg_class.supported_types(asm_arch);
258256
let Some((_, feature)) = supported_tys.iter().find(|&&(t, _)| t == asm_ty) else {
259-
let msg = &format!("type `{}` cannot be used with this register class", ty);
257+
let msg = &format!("type `{ty}` cannot be used with this register class");
260258
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
261259
let supported_tys: Vec<_> =
262260
supported_tys.iter().map(|(t, _)| t.to_string()).collect();
@@ -326,12 +324,10 @@ impl<'tcx> ExprVisitor<'tcx> {
326324
let mut err = lint.build(msg);
327325
err.span_label(expr.span, "for this argument");
328326
err.help(&format!(
329-
"use the `{}` modifier to have the register formatted as `{}`",
330-
suggested_modifier, suggested_result,
327+
"use the `{suggested_modifier}` modifier to have the register formatted as `{suggested_result}`",
331328
));
332329
err.help(&format!(
333-
"or use the `{}` modifier to keep the default formatting of `{}`",
334-
default_modifier, default_result,
330+
"or use the `{default_modifier}` modifier to keep the default formatting of `{default_result}`",
335331
));
336332
err.emit();
337333
},
@@ -509,14 +505,14 @@ impl<'tcx> Visitor<'tcx> for ExprVisitor<'tcx> {
509505
match expr.kind {
510506
hir::ExprKind::Path(ref qpath) => {
511507
let res = self.typeck_results.qpath_res(qpath, expr.hir_id);
512-
if let Res::Def(DefKind::Fn, did) = res {
513-
if self.def_id_is_transmute(did) {
514-
let typ = self.typeck_results.node_type(expr.hir_id);
515-
let sig = typ.fn_sig(self.tcx);
516-
let from = sig.inputs().skip_binder()[0];
517-
let to = sig.output().skip_binder();
518-
self.check_transmute(expr.span, from, to);
519-
}
508+
if let Res::Def(DefKind::Fn, did) = res
509+
&& self.def_id_is_transmute(did)
510+
{
511+
let typ = self.typeck_results.node_type(expr.hir_id);
512+
let sig = typ.fn_sig(self.tcx);
513+
let from = sig.inputs().skip_binder()[0];
514+
let to = sig.output().skip_binder();
515+
self.check_transmute(expr.span, from, to);
520516
}
521517
}
522518

0 commit comments

Comments
 (0)