Skip to content

Rollup of 4 pull requests #95176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
@@ -287,7 +287,7 @@ declare_features! (
/// Allows `extern "x86-interrupt" fn()`.
(active, abi_x86_interrupt, "1.17.0", Some(40180), None),
/// Allows additional const parameter types, such as `&'static str` or user defined types
(incomplete, adt_const_params, "1.56.0", Some(44580), None),
(incomplete, adt_const_params, "1.56.0", Some(95174), None),
/// Allows defining an `#[alloc_error_handler]`.
(active, alloc_error_handler, "1.29.0", Some(51540), None),
/// Allows explicit discriminants on non-unit enum variants.
24 changes: 10 additions & 14 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
@@ -196,8 +196,7 @@ impl CheckAttrVisitor<'_> {
fn inline_attr_str_error_with_macro_def(&self, hir_id: HirId, attr: &Attribute, sym: &str) {
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
lint.build(&format!(
"`#[{}]` is ignored on struct fields, match arms and macro defs",
sym,
"`#[{sym}]` is ignored on struct fields, match arms and macro defs",
))
.warn(
"this was previously accepted by the compiler but is \
@@ -214,7 +213,7 @@ impl CheckAttrVisitor<'_> {

fn inline_attr_str_error_without_macro_def(&self, hir_id: HirId, attr: &Attribute, sym: &str) {
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
lint.build(&format!("`#[{}]` is ignored on struct fields and match arms", sym))
lint.build(&format!("`#[{sym}]` is ignored on struct fields and match arms"))
.warn(
"this was previously accepted by the compiler but is \
being phased out; it will become a hard error in \
@@ -721,7 +720,7 @@ impl CheckAttrVisitor<'_> {
.sess
.struct_span_err(
meta.name_value_literal_span().unwrap_or_else(|| meta.span()),
&format!("`{}` is not a valid identifier", doc_keyword),
&format!("`{doc_keyword}` is not a valid identifier"),
)
.emit();
return false;
@@ -805,8 +804,7 @@ impl CheckAttrVisitor<'_> {
.struct_span_err(
meta.span(),
&format!(
"`#![doc({} = \"...\")]` isn't allowed as a crate-level attribute",
attr_name,
"`#![doc({attr_name} = \"...\")]` isn't allowed as a crate-level attribute",
),
)
.emit();
@@ -1035,8 +1033,7 @@ impl CheckAttrVisitor<'_> {
attr.meta().unwrap().span,
"use `doc = include_str!` instead",
format!(
"#{}[doc = include_str!(\"{}\")]",
inner, value
"#{inner}[doc = include_str!(\"{value}\")]",
),
applicability,
);
@@ -1230,7 +1227,7 @@ impl CheckAttrVisitor<'_> {
if let Some(value) = attr.value_str() {
diag.span_help(
attr.span,
&format!(r#"try `#[link(name = "{}")]` instead"#, value),
&format!(r#"try `#[link(name = "{value}")]` instead"#),
);
} else {
diag.span_help(attr.span, r#"try `#[link(name = "...")]` instead"#);
@@ -1518,15 +1515,14 @@ impl CheckAttrVisitor<'_> {
};
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
lint.build(&format!(
"`#[no_mangle]` has no effect on a foreign {}",
foreign_item_kind
"`#[no_mangle]` has no effect on a foreign {foreign_item_kind}"
))
.warn(
"this was previously accepted by the compiler but is \
being phased out; it will become a hard error in \
a future release!",
)
.span_label(span, format!("foreign {}", foreign_item_kind))
.span_label(span, format!("foreign {foreign_item_kind}"))
.note("symbol names in extern blocks are not mangled")
.span_suggestion(
attr.span,
@@ -1692,9 +1688,9 @@ impl CheckAttrVisitor<'_> {
hint.span(),
E0517,
"{}",
&format!("attribute should be applied to {} {}", article, allowed_targets)
&format!("attribute should be applied to {article} {allowed_targets}")
)
.span_label(span, &format!("not {} {}", article, allowed_targets))
.span_label(span, &format!("not {article} {allowed_targets}"))
.emit();
}

4 changes: 1 addition & 3 deletions compiler/rustc_passes/src/check_const.rs
Original file line number Diff line number Diff line change
@@ -80,8 +80,7 @@ impl<'tcx> hir::itemlikevisit::ItemLikeVisitor<'tcx> for CheckConstTraitVisitor<
/// of the trait being implemented; as those provided functions can be non-const.
fn visit_item<'hir>(&mut self, item: &'hir hir::Item<'hir>) {
let _: Option<_> = try {
if let hir::ItemKind::Impl(ref imp) = item.kind {
if let hir::Constness::Const = imp.constness {
if let hir::ItemKind::Impl(ref imp) = item.kind && let hir::Constness::Const = imp.constness {
let trait_def_id = imp.of_trait.as_ref()?.trait_def_id()?;
let ancestors = self
.tcx
@@ -132,7 +131,6 @@ impl<'tcx> hir::itemlikevisit::ItemLikeVisitor<'tcx> for CheckConstTraitVisitor<
.note(&format!("`{}` not implemented", to_implement.join("`, `")))
.emit();
}
}
}
};
}
7 changes: 3 additions & 4 deletions compiler/rustc_passes/src/diagnostic_items.rs
Original file line number Diff line number Diff line change
@@ -61,10 +61,9 @@ fn collect_item(tcx: TyCtxt<'_>, items: &mut DiagnosticItems, name: Symbol, item
if let Some(original_def_id) = items.name_to_id.insert(name, item_def_id) {
if original_def_id != item_def_id {
let mut err = match tcx.hir().span_if_local(item_def_id) {
Some(span) => tcx.sess.struct_span_err(
span,
&format!("duplicate diagnostic item found: `{}`.", name),
),
Some(span) => tcx
.sess
.struct_span_err(span, &format!("duplicate diagnostic item found: `{name}`.")),
None => tcx.sess.struct_err(&format!(
"duplicate diagnostic item in crate `{}`: `{}`.",
tcx.crate_name(item_def_id.krate),
52 changes: 23 additions & 29 deletions compiler/rustc_passes/src/entry.rs
Original file line number Diff line number Diff line change
@@ -148,33 +148,29 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) -> Option<(De
} else if let Some((def_id, _)) = visitor.attr_main_fn {
Some((def_id.to_def_id(), EntryFnType::Main))
} else {
if let Some(main_def) = tcx.resolutions(()).main_def {
if let Some(def_id) = main_def.opt_fn_def_id() {
// non-local main imports are handled below
if let Some(def_id) = def_id.as_local() {
if matches!(tcx.hir().find_by_def_id(def_id), Some(Node::ForeignItem(_))) {
tcx.sess
.struct_span_err(
tcx.def_span(def_id),
"the `main` function cannot be declared in an `extern` block",
)
.emit();
return None;
}
}

if main_def.is_import && !tcx.features().imported_main {
let span = main_def.span;
feature_err(
&tcx.sess.parse_sess,
sym::imported_main,
span,
"using an imported function as entry point `main` is experimental",
if let Some(main_def) = tcx.resolutions(()).main_def && let Some(def_id) = main_def.opt_fn_def_id() {
// non-local main imports are handled below
if let Some(def_id) = def_id.as_local() && matches!(tcx.hir().find_by_def_id(def_id), Some(Node::ForeignItem(_))) {
tcx.sess
.struct_span_err(
tcx.def_span(def_id),
"the `main` function cannot be declared in an `extern` block",
)
.emit();
}
return Some((def_id, EntryFnType::Main));
return None;
}

if main_def.is_import && !tcx.features().imported_main {
let span = main_def.span;
feature_err(
&tcx.sess.parse_sess,
sym::imported_main,
span,
"using an imported function as entry point `main` is experimental",
)
.emit();
}
return Some((def_id, EntryFnType::Main));
}
no_main_err(tcx, visitor);
None
@@ -225,11 +221,9 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
err.note(&note);
}

if let Some(main_def) = tcx.resolutions(()).main_def {
if main_def.opt_fn_def_id().is_none() {
// There is something at `crate::main`, but it is not a function definition.
err.span_label(main_def.span, "non-function item at `crate::main` is found");
}
if let Some(main_def) = tcx.resolutions(()).main_def && main_def.opt_fn_def_id().is_none(){
// There is something at `crate::main`, but it is not a function definition.
err.span_label(main_def.span, "non-function item at `crate::main` is found");
}

if tcx.sess.teach(&err.get_code().unwrap()) {
52 changes: 24 additions & 28 deletions compiler/rustc_passes/src/intrinsicck.rs
Original file line number Diff line number Diff line change
@@ -79,27 +79,25 @@ impl<'tcx> ExprVisitor<'tcx> {
// Special-case transmuting from `typeof(function)` and
// `Option<typeof(function)>` to present a clearer error.
let from = unpack_option_like(self.tcx, from);
if let (&ty::FnDef(..), SizeSkeleton::Known(size_to)) = (from.kind(), sk_to) {
if size_to == Pointer.size(&self.tcx) {
struct_span_err!(self.tcx.sess, span, E0591, "can't transmute zero-sized type")
.note(&format!("source type: {}", from))
.note(&format!("target type: {}", to))
.help("cast with `as` to a pointer instead")
.emit();
return;
}
if let (&ty::FnDef(..), SizeSkeleton::Known(size_to)) = (from.kind(), sk_to) && size_to == Pointer.size(&self.tcx) {
struct_span_err!(self.tcx.sess, span, E0591, "can't transmute zero-sized type")
.note(&format!("source type: {from}"))
.note(&format!("target type: {to}"))
.help("cast with `as` to a pointer instead")
.emit();
return;
}
}

// Try to display a sensible error with as much information as possible.
let skeleton_string = |ty: Ty<'tcx>, sk| match sk {
Ok(SizeSkeleton::Known(size)) => format!("{} bits", size.bits()),
Ok(SizeSkeleton::Pointer { tail, .. }) => format!("pointer to `{}`", tail),
Ok(SizeSkeleton::Pointer { tail, .. }) => format!("pointer to `{tail}`"),
Err(LayoutError::Unknown(bad)) => {
if bad == ty {
"this type does not have a fixed size".to_owned()
} else {
format!("size can vary because of {}", bad)
format!("size can vary because of {bad}")
}
}
Err(err) => err.to_string(),
@@ -113,7 +111,7 @@ impl<'tcx> ExprVisitor<'tcx> {
or dependently-sized types"
);
if from == to {
err.note(&format!("`{}` does not have a fixed size", from));
err.note(&format!("`{from}` does not have a fixed size"));
} else {
err.note(&format!("source type: `{}` ({})", from, skeleton_string(from, sk_from)))
.note(&format!("target type: `{}` ({})", to, skeleton_string(to, sk_to)));
@@ -201,7 +199,7 @@ impl<'tcx> ExprVisitor<'tcx> {
_ => None,
};
let Some(asm_ty) = asm_ty else {
let msg = &format!("cannot use value of type `{}` for inline assembly", ty);
let msg = &format!("cannot use value of type `{ty}` for inline assembly");
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
err.note(
"only integers, floats, SIMD vectors, pointers and function pointers \
@@ -216,7 +214,7 @@ impl<'tcx> ExprVisitor<'tcx> {
if !ty.is_copy_modulo_regions(self.tcx.at(DUMMY_SP), self.param_env) {
let msg = "arguments for inline assembly must be copyable";
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
err.note(&format!("`{}` does not implement the Copy trait", ty));
err.note(&format!("`{ty}` does not implement the Copy trait"));
err.emit();
}

@@ -237,7 +235,7 @@ impl<'tcx> ExprVisitor<'tcx> {
in_expr.span,
&format!("type `{}`", self.typeck_results.expr_ty_adjusted(in_expr)),
);
err.span_label(expr.span, &format!("type `{}`", ty));
err.span_label(expr.span, &format!("type `{ty}`"));
err.note(
"asm inout arguments must have the same type, \
unless they are both pointers or integers of the same size",
@@ -256,7 +254,7 @@ impl<'tcx> ExprVisitor<'tcx> {
let reg_class = reg.reg_class();
let supported_tys = reg_class.supported_types(asm_arch);
let Some((_, feature)) = supported_tys.iter().find(|&&(t, _)| t == asm_ty) else {
let msg = &format!("type `{}` cannot be used with this register class", ty);
let msg = &format!("type `{ty}` cannot be used with this register class");
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
let supported_tys: Vec<_> =
supported_tys.iter().map(|(t, _)| t.to_string()).collect();
@@ -326,12 +324,10 @@ impl<'tcx> ExprVisitor<'tcx> {
let mut err = lint.build(msg);
err.span_label(expr.span, "for this argument");
err.help(&format!(
"use the `{}` modifier to have the register formatted as `{}`",
suggested_modifier, suggested_result,
"use the `{suggested_modifier}` modifier to have the register formatted as `{suggested_result}`",
));
err.help(&format!(
"or use the `{}` modifier to keep the default formatting of `{}`",
default_modifier, default_result,
"or use the `{default_modifier}` modifier to keep the default formatting of `{default_result}`",
));
err.emit();
},
@@ -509,14 +505,14 @@ impl<'tcx> Visitor<'tcx> for ExprVisitor<'tcx> {
match expr.kind {
hir::ExprKind::Path(ref qpath) => {
let res = self.typeck_results.qpath_res(qpath, expr.hir_id);
if let Res::Def(DefKind::Fn, did) = res {
if self.def_id_is_transmute(did) {
let typ = self.typeck_results.node_type(expr.hir_id);
let sig = typ.fn_sig(self.tcx);
let from = sig.inputs().skip_binder()[0];
let to = sig.output().skip_binder();
self.check_transmute(expr.span, from, to);
}
if let Res::Def(DefKind::Fn, did) = res
&& self.def_id_is_transmute(did)
{
let typ = self.typeck_results.node_type(expr.hir_id);
let sig = typ.fn_sig(self.tcx);
let from = sig.inputs().skip_binder()[0];
let to = sig.output().skip_binder();
self.check_transmute(expr.span, from, to);
}
}

8 changes: 5 additions & 3 deletions src/doc/unstable-book/src/compiler-flags/check-cfg.md
Original file line number Diff line number Diff line change
@@ -92,8 +92,6 @@ and `cfg!(name = "value")` call. It will check that the `"value"` specified is p
list of expected values. If `"value"` is not in it, then `rustc` will report an `unexpected_cfgs`
lint diagnostic. The default diagnostic level for this lint is `Warn`.
The form `values()` is an error, because it does not specify a condition name.
To enable checking of values, but to provide an empty set of valid values, use this form:
```bash
@@ -104,13 +102,17 @@ The `--check-cfg values(...)` option can be repeated, both for the same conditio
different names. If it is repeated for the same condition name, then the sets of values for that
condition are merged together.
If `values()` is specified, then `rustc` will enable the checking of well-known values defined
by itself. Note that it's necessary to specify the `values()` form to enable the checking of
well known values, specifying the other forms doesn't implicitly enable it.
## Examples
Consider this command line:
```bash
rustc --check-cfg 'names(feature)' \
--check-cfg 'values(feature,"lion","zebra")' \
--check-cfg 'values(feature, "lion", "zebra")' \
--cfg 'feature="lion"' -Z unstable-options \
example.rs
```
7 changes: 0 additions & 7 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
@@ -400,7 +400,6 @@ nav.sub {
.source .sidebar > *:not(#sidebar-toggle) {
opacity: 0;
visibility: hidden;
transition: opacity 0.5s;
}

.source .sidebar.expanded {
@@ -1677,12 +1676,6 @@ details.rustdoc-toggle[open] > summary.hideme::after {
display: none;
}

/* It doesn't render well on mobile because of the layout, so better only have the transition
on desktop. */
.rustdoc.source .sidebar {
transition: width .5s;
}

.source .sidebar.expanded {
width: 300px;
}
1 change: 0 additions & 1 deletion src/test/rustdoc-gui/code-sidebar-toggle.goml
Original file line number Diff line number Diff line change
@@ -3,6 +3,5 @@ goto: file://|DOC_PATH|/test_docs/index.html
click: ".srclink"
wait-for: "#sidebar-toggle"
click: "#sidebar-toggle"
wait-for: 500
fail: true
assert-css: ("#source-sidebar", { "left": "-300px" })
2 changes: 1 addition & 1 deletion src/test/ui/consts/refs_check_const_eq-issue-88384.stderr
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ LL | #![feature(adt_const_params)]
| ^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information

warning: 1 warning emitted

2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0771.stderr
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ LL | #![feature(adt_const_params)]
| ^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information

error[E0771]: use of non-static lifetime `'a` in const generic
--> $DIR/E0771.rs:4:41
40 changes: 1 addition & 39 deletions src/test/ui/issues/issue-28561.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// check-pass
#[derive(Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, Clone, Copy)]
struct Array<T> {
f00: [T; 00],
f01: [T; 01],
@@ -36,44 +36,6 @@ struct Array<T> {
f32: [T; 32],
}

// FIXME(#44580): merge with `Array` once `[T; N]: Clone` where `T: Clone`
#[derive(Clone, Copy)]
struct CopyArray<T: Copy> {
f00: [T; 00],
f01: [T; 01],
f02: [T; 02],
f03: [T; 03],
f04: [T; 04],
f05: [T; 05],
f06: [T; 06],
f07: [T; 07],
f08: [T; 08],
f09: [T; 09],
f10: [T; 10],
f11: [T; 11],
f12: [T; 12],
f13: [T; 13],
f14: [T; 14],
f15: [T; 15],
f16: [T; 16],
f17: [T; 17],
f18: [T; 18],
f19: [T; 19],
f20: [T; 20],
f21: [T; 21],
f22: [T; 22],
f23: [T; 23],
f24: [T; 24],
f25: [T; 25],
f26: [T; 26],
f27: [T; 27],
f28: [T; 28],
f29: [T; 29],
f30: [T; 30],
f31: [T; 31],
f32: [T; 32],
}

#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
struct Fn<A, B, C, D, E, F, G, H, I, J, K, L> {
f00: fn(),