From 237d62588ddb4b7a93f3f5c61ea9253eba30ed5d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 19 Mar 2022 16:59:56 +0100 Subject: [PATCH 1/4] Remove animation on source sidebar --- src/librustdoc/html/static/css/rustdoc.css | 7 ------- src/test/rustdoc-gui/code-sidebar-toggle.goml | 1 - 2 files changed, 8 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 67adaa8702d85..ee265b8c4b543 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -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; } diff --git a/src/test/rustdoc-gui/code-sidebar-toggle.goml b/src/test/rustdoc-gui/code-sidebar-toggle.goml index 1818f0dbcdf41..867db056948b6 100644 --- a/src/test/rustdoc-gui/code-sidebar-toggle.goml +++ b/src/test/rustdoc-gui/code-sidebar-toggle.goml @@ -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" }) From c6c14a040dc33663a3e14f1e8a3d0938c65e7ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20BRANSTETT?= Date: Mon, 21 Mar 2022 12:59:46 +0100 Subject: [PATCH 2/4] Update unstable book with the new `values()` form for check-cfg --- src/doc/unstable-book/src/compiler-flags/check-cfg.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/doc/unstable-book/src/compiler-flags/check-cfg.md b/src/doc/unstable-book/src/compiler-flags/check-cfg.md index d7345ad0c33f2..486b3d4414f3a 100644 --- a/src/doc/unstable-book/src/compiler-flags/check-cfg.md +++ b/src/doc/unstable-book/src/compiler-flags/check-cfg.md @@ -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 ``` From 726206696edc87e96360f26a91b94fca5bf6f511 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Fri, 18 Mar 2022 22:48:21 +0900 Subject: [PATCH 3/4] use `format-args-capture` and remove unnecessary nested if blocks in some parts of rustc_passes break before the `&&` Update compiler/rustc_passes/src/check_const.rs Co-authored-by: bjorn3 --- compiler/rustc_passes/src/check_attr.rs | 24 ++++----- compiler/rustc_passes/src/check_const.rs | 4 +- compiler/rustc_passes/src/diagnostic_items.rs | 7 ++- compiler/rustc_passes/src/entry.rs | 52 ++++++++----------- compiler/rustc_passes/src/intrinsicck.rs | 52 +++++++++---------- 5 files changed, 61 insertions(+), 78 deletions(-) diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index ebf6678d3ad37..4f9e1d3fa3bca 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -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(); } diff --git a/compiler/rustc_passes/src/check_const.rs b/compiler/rustc_passes/src/check_const.rs index 0fdbdb7b08d00..0e04a2cfb11ad 100644 --- a/compiler/rustc_passes/src/check_const.rs +++ b/compiler/rustc_passes/src/check_const.rs @@ -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(); } - } } }; } diff --git a/compiler/rustc_passes/src/diagnostic_items.rs b/compiler/rustc_passes/src/diagnostic_items.rs index 30a0071f0f2e5..9cbb7917e9a32 100644 --- a/compiler/rustc_passes/src/diagnostic_items.rs +++ b/compiler/rustc_passes/src/diagnostic_items.rs @@ -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), diff --git a/compiler/rustc_passes/src/entry.rs b/compiler/rustc_passes/src/entry.rs index f5040a373c296..5a1373ad1a218 100644 --- a/compiler/rustc_passes/src/entry.rs +++ b/compiler/rustc_passes/src/entry.rs @@ -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(¬e); } - 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()) { diff --git a/compiler/rustc_passes/src/intrinsicck.rs b/compiler/rustc_passes/src/intrinsicck.rs index 6316f3b845914..027eac16bad30 100644 --- a/compiler/rustc_passes/src/intrinsicck.rs +++ b/compiler/rustc_passes/src/intrinsicck.rs @@ -79,27 +79,25 @@ impl<'tcx> ExprVisitor<'tcx> { // Special-case transmuting from `typeof(function)` and // `Option` 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); } } From e8890aad62dbb399b90542e6719d050665ab1c9a Mon Sep 17 00:00:00 2001 From: lcnr Date: Mon, 21 Mar 2022 16:33:15 +0100 Subject: [PATCH 4/4] move `adt_const_params` to its own tracking issue --- compiler/rustc_feature/src/active.rs | 2 +- .../refs_check_const_eq-issue-88384.stderr | 2 +- src/test/ui/error-codes/E0771.stderr | 2 +- src/test/ui/issues/issue-28561.rs | 40 +------------------ 4 files changed, 4 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 02cdaa3b95840..feef7295254a9 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -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. diff --git a/src/test/ui/consts/refs_check_const_eq-issue-88384.stderr b/src/test/ui/consts/refs_check_const_eq-issue-88384.stderr index 55928b495b24c..f2bad2f552759 100644 --- a/src/test/ui/consts/refs_check_const_eq-issue-88384.stderr +++ b/src/test/ui/consts/refs_check_const_eq-issue-88384.stderr @@ -5,7 +5,7 @@ LL | #![feature(adt_const_params)] | ^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information + = note: see issue #95174 for more information warning: 1 warning emitted diff --git a/src/test/ui/error-codes/E0771.stderr b/src/test/ui/error-codes/E0771.stderr index 730a7ef1284b6..5a16d5845a60e 100644 --- a/src/test/ui/error-codes/E0771.stderr +++ b/src/test/ui/error-codes/E0771.stderr @@ -5,7 +5,7 @@ LL | #![feature(adt_const_params)] | ^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default - = note: see issue #44580 for more information + = note: see issue #95174 for more information error[E0771]: use of non-static lifetime `'a` in const generic --> $DIR/E0771.rs:4:41 diff --git a/src/test/ui/issues/issue-28561.rs b/src/test/ui/issues/issue-28561.rs index 1241fb0b1f85f..beb12c36dcafa 100644 --- a/src/test/ui/issues/issue-28561.rs +++ b/src/test/ui/issues/issue-28561.rs @@ -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 { f00: [T; 00], f01: [T; 01], @@ -36,44 +36,6 @@ struct Array { f32: [T; 32], } -// FIXME(#44580): merge with `Array` once `[T; N]: Clone` where `T: Clone` -#[derive(Clone, Copy)] -struct CopyArray { - 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 { f00: fn(),