From 719c8d40cc9fb024fbc48055ffdedb0370de0156 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 15 Feb 2021 10:11:37 +0100 Subject: [PATCH 1/6] Fix ES5 errors (IE11) --- src/librustdoc/html/static/main.js | 16 +++++++++++----- src/librustdoc/html/static/storage.js | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index ec89ae0228c5e..d6d3171afbffe 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -2908,10 +2908,14 @@ function defocusSearchBar() { ["⏎", "Go to active search result"], ["+", "Expand all sections"], ["-", "Collapse all sections"], - ].map(x => "
" + - x[0].split(" ") - .map((y, index) => (index & 1) === 0 ? "" + y + "" : " " + y + " ") - .join("") + "
" + x[1] + "
").join(""); + ].map(function(x) { + return "
" + + x[0].split(" ") + .map(function(y, index) { + return (index & 1) === 0 ? "" + y + "" : " " + y + " "; + }) + .join("") + "
" + x[1] + "
"; + }).join(""); var div_shortcuts = document.createElement("div"); addClass(div_shortcuts, "shortcuts"); div_shortcuts.innerHTML = "

Keyboard Shortcuts

" + shortcuts + "
"; @@ -2929,7 +2933,9 @@ function defocusSearchBar() { "You can look for items with an exact name by putting double quotes around \ your request: \"string\"", "Look for items inside another one by searching for a path: vec::Vec", - ].map(x => "

" + x + "

").join(""); + ].map(function(x) { + return "

" + x + "

"; + }).join(""); var div_infos = document.createElement("div"); addClass(div_infos, "infos"); div_infos.innerHTML = "

Search Tricks

" + infos; diff --git a/src/librustdoc/html/static/storage.js b/src/librustdoc/html/static/storage.js index a50ed5b662bf6..b8b6fcbaf3adc 100644 --- a/src/librustdoc/html/static/storage.js +++ b/src/librustdoc/html/static/storage.js @@ -157,7 +157,7 @@ var updateSystemTheme = (function() { if (!window.matchMedia) { // fallback to the CSS computed value return function() { - let cssTheme = getComputedStyle(document.documentElement) + var cssTheme = getComputedStyle(document.documentElement) .getPropertyValue('content'); switchTheme( From f2f7ffecd7aea20ddaedc7fa8ae45f1b15aad235 Mon Sep 17 00:00:00 2001 From: pierwill <19642016+pierwill@users.noreply.github.com> Date: Mon, 15 Feb 2021 10:02:03 -0800 Subject: [PATCH 2/6] Fix typo in rustc_infer::infer::UndoLog Also use double quotes. --- compiler/rustc_infer/src/infer/undo_log.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_infer/src/infer/undo_log.rs b/compiler/rustc_infer/src/infer/undo_log.rs index 2cfd6bb904c41..4be0e7948f70b 100644 --- a/compiler/rustc_infer/src/infer/undo_log.rs +++ b/compiler/rustc_infer/src/infer/undo_log.rs @@ -15,7 +15,7 @@ pub struct Snapshot<'tcx> { _marker: PhantomData<&'tcx ()>, } -/// Records the 'undo' data fora single operation that affects some form of inference variable. +/// Records the "undo" data for a single operation that affects some form of inference variable. pub(crate) enum UndoLog<'tcx> { TypeVariables(type_variable::UndoLog<'tcx>), ConstUnificationTable(sv::UndoLog>>), From 8192793d505dc9d665446792e44a9d5f7f357860 Mon Sep 17 00:00:00 2001 From: Jesus Rubio Date: Mon, 15 Feb 2021 19:16:39 +0100 Subject: [PATCH 3/6] Add long explanation for E0545 --- compiler/rustc_error_codes/src/error_codes.rs | 2 +- .../src/error_codes/E0545.md | 35 +++++++++++++++++++ .../unstable-attribute-allow-issue-0.stderr | 1 + .../stability-attribute-sanity-2.stderr | 2 +- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0545.md diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index d01c162b0c864..cccc0e0560012 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -286,6 +286,7 @@ E0538: include_str!("./error_codes/E0538.md"), E0539: include_str!("./error_codes/E0539.md"), E0541: include_str!("./error_codes/E0541.md"), E0542: include_str!("./error_codes/E0542.md"), +E0545: include_str!("./error_codes/E0545.md"), E0546: include_str!("./error_codes/E0546.md"), E0547: include_str!("./error_codes/E0547.md"), E0550: include_str!("./error_codes/E0550.md"), @@ -606,7 +607,6 @@ E0781: include_str!("./error_codes/E0781.md"), // E0540, // multiple rustc_deprecated attributes E0543, // missing 'reason' E0544, // multiple stability levels - E0545, // incorrect 'issue' // E0548, // replaced with a generic attribute input check // rustc_deprecated attribute must be paired with either stable or unstable // attribute diff --git a/compiler/rustc_error_codes/src/error_codes/E0545.md b/compiler/rustc_error_codes/src/error_codes/E0545.md new file mode 100644 index 0000000000000..9fb935a3ab1ab --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0545.md @@ -0,0 +1,35 @@ +The `issue` value is incorrect in a stability attribute. + +Erroneous code example: + +```compile_fail,E0545 +#![feature(staged_api)] +#![stable(since = "1.0.0", feature = "test")] + +#[unstable(feature = "_unstable_fn", issue = "0")] // invalid +fn _unstable_fn() {} + +#[rustc_const_unstable(feature = "_unstable_const_fn", issue = "0")] // invalid +fn _unstable_const_fn() {} +``` + +To fix this issue, you need to provide a correct value in the `issue` field. +Example: + +``` +#![feature(staged_api)] +#![stable(since = "1.0.0", feature = "test")] + +#[unstable(feature = "_unstable_fn", issue = "none")] // ok! +fn _unstable_fn() {} + +#[rustc_const_unstable(feature = "_unstable_const_fn", issue = "1")] // ok! +fn _unstable_const_fn() {} +``` + +See the [How Rust is Made and “Nightly Rust”][how-rust-made-nightly] appendix +of the Book and the [Stability attributes][stability-attributes] section of the +Rustc Dev Guide for more details. + +[how-rust-made-nightly]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html +[stability-attributes]: https://rustc-dev-guide.rust-lang.org/stability.html diff --git a/src/test/ui/feature-gates/unstable-attribute-allow-issue-0.stderr b/src/test/ui/feature-gates/unstable-attribute-allow-issue-0.stderr index 7bbaf92fc68c1..4ed42101af8e6 100644 --- a/src/test/ui/feature-gates/unstable-attribute-allow-issue-0.stderr +++ b/src/test/ui/feature-gates/unstable-attribute-allow-issue-0.stderr @@ -16,3 +16,4 @@ LL | #[unstable(feature = "unstable_test_feature", issue = "something")] error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0545`. diff --git a/src/test/ui/stability-attribute/stability-attribute-sanity-2.stderr b/src/test/ui/stability-attribute/stability-attribute-sanity-2.stderr index 3b82619189919..bd7b88da1584d 100644 --- a/src/test/ui/stability-attribute/stability-attribute-sanity-2.stderr +++ b/src/test/ui/stability-attribute/stability-attribute-sanity-2.stderr @@ -20,5 +20,5 @@ LL | #[unstable(feature = "a", issue = "no")] error: aborting due to 3 previous errors -Some errors have detailed explanations: E0538, E0541. +Some errors have detailed explanations: E0538, E0541, E0545. For more information about an error, try `rustc --explain E0538`. From 4390a61b6495765a04819130e3934ec671428bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 16 Feb 2021 00:30:06 +0100 Subject: [PATCH 4/6] avoid full-slicing slices If we already have a slice, there is no need to get another full-range slice from that, just use the original. clippy::redundant_slicing --- compiler/rustc_ast_lowering/src/item.rs | 2 +- compiler/rustc_ast_pretty/src/pprust/state.rs | 6 +++--- compiler/rustc_builtin_macros/src/format.rs | 2 +- .../rustc_builtin_macros/src/format_foreign.rs | 4 ++-- compiler/rustc_codegen_ssa/src/mir/block.rs | 2 +- compiler/rustc_hir_pretty/src/lib.rs | 4 ++-- .../infer/error_reporting/need_type_info.rs | 2 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 2 +- compiler/rustc_middle/src/hir/map/mod.rs | 18 +++++++++--------- .../rustc_middle/src/ty/query/on_disk_cache.rs | 2 +- compiler/rustc_resolve/src/late/diagnostics.rs | 2 +- compiler/rustc_target/src/spec/mod.rs | 2 +- compiler/rustc_typeck/src/astconv/errors.rs | 2 +- compiler/rustc_typeck/src/astconv/mod.rs | 2 +- .../rustc_typeck/src/check/fn_ctxt/_impl.rs | 2 +- .../rustc_typeck/src/check/method/suggest.rs | 2 +- compiler/rustc_typeck/src/collect.rs | 11 ++--------- src/bootstrap/flags.rs | 2 +- src/librustdoc/clean/mod.rs | 4 ++-- 19 files changed, 33 insertions(+), 40 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 1efe83cacea4a..097663ff1accd 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -135,7 +135,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let parent_generics = match self.items.get(&parent_hir_id).unwrap().kind { hir::ItemKind::Impl(hir::Impl { ref generics, .. }) - | hir::ItemKind::Trait(_, _, ref generics, ..) => &generics.params[..], + | hir::ItemKind::Trait(_, _, ref generics, ..) => generics.params, _ => &[], }; let lt_def_names = parent_generics.iter().filter_map(|param| match param.kind { diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 01e234c9be972..180402c24fb7b 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1681,7 +1681,7 @@ impl<'a> State<'a> { self.ibox(INDENT_UNIT); self.s.word("["); self.print_inner_attributes_inline(attrs); - self.commasep_exprs(Inconsistent, &exprs[..]); + self.commasep_exprs(Inconsistent, exprs); self.s.word("]"); self.end(); } @@ -1722,7 +1722,7 @@ impl<'a> State<'a> { self.print_inner_attributes_inline(attrs); self.commasep_cmnt( Consistent, - &fields[..], + fields, |s, field| { s.print_outer_attributes(&field.attrs); s.ibox(INDENT_UNIT); @@ -1757,7 +1757,7 @@ impl<'a> State<'a> { fn print_expr_tup(&mut self, exprs: &[P], attrs: &[ast::Attribute]) { self.popen(); self.print_inner_attributes_inline(attrs); - self.commasep_exprs(Inconsistent, &exprs[..]); + self.commasep_exprs(Inconsistent, exprs); if exprs.len() == 1 { self.s.word(","); } diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs index 85ca1da6f1daa..7e88b58c0e29d 100644 --- a/compiler/rustc_builtin_macros/src/format.rs +++ b/compiler/rustc_builtin_macros/src/format.rs @@ -270,7 +270,7 @@ impl<'a, 'b> Context<'a, 'b> { parse::ArgumentNamed(s) => Named(s), }; - let ty = Placeholder(match &arg.format.ty[..] { + let ty = Placeholder(match arg.format.ty { "" => "Display", "?" => "Debug", "e" => "LowerExp", diff --git a/compiler/rustc_builtin_macros/src/format_foreign.rs b/compiler/rustc_builtin_macros/src/format_foreign.rs index 0496c72cb0050..0cc520e5bd1f0 100644 --- a/compiler/rustc_builtin_macros/src/format_foreign.rs +++ b/compiler/rustc_builtin_macros/src/format_foreign.rs @@ -312,7 +312,7 @@ pub mod printf { return Some((Substitution::Escape, &s[start + 2..])); } - Cur::new_at(&s[..], start) + Cur::new_at(s, start) }; // This is meant to be a translation of the following regex: @@ -673,7 +673,7 @@ pub mod shell { _ => { /* fall-through */ } } - Cur::new_at(&s[..], start) + Cur::new_at(s, start) }; let at = at.at_next_cp()?; diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index c821908167870..9ce9066980066 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -709,7 +709,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let (tup, args) = args.split_last().unwrap(); (args, Some(tup)) } else { - (&args[..], None) + (args, None) }; 'make_args: for (i, arg) in first_args.iter().enumerate() { diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 4595855309fda..1f9133f2ccbf0 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -392,7 +392,7 @@ impl<'a> State<'a> { &f.decl, None, &f.generic_params, - &f.param_names[..], + f.param_names, ); } hir::TyKind::OpaqueDef(..) => self.s.word("/*impl Trait*/"), @@ -1200,7 +1200,7 @@ impl<'a> State<'a> { self.s.word("{"); self.commasep_cmnt( Consistent, - &fields[..], + fields, |s, field| { s.ibox(INDENT_UNIT); if !field.is_shorthand { diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index bd43d3c01e218..cb783847fd1cf 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -671,7 +671,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { if !impl_candidates.is_empty() && e.span.contains(span) { if let Some(expr) = exprs.first() { if let ExprKind::Path(hir::QPath::Resolved(_, path)) = expr.kind { - if let [path_segment] = &path.segments[..] { + if let [path_segment] = path.segments { let candidate_len = impl_candidates.len(); let suggestions = impl_candidates.iter().map(|candidate| { format!( diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 14ca51008bec5..94314464e085a 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -866,7 +866,7 @@ impl EncodeContext<'a, 'tcx> { fn encode_variances_of(&mut self, def_id: DefId) { debug!("EncodeContext::encode_variances_of({:?})", def_id); - record!(self.tables.variances[def_id] <- &self.tcx.variances_of(def_id)[..]); + record!(self.tables.variances[def_id] <- self.tcx.variances_of(def_id)); } fn encode_item_type(&mut self, def_id: DefId) { diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 251f8c0afe63d..4bc6dda0a5577 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -854,22 +854,22 @@ impl<'hir> Map<'hir> { /// corresponding to the node-ID. pub fn attrs(&self, id: HirId) -> &'hir [ast::Attribute] { self.find_entry(id).map_or(&[], |entry| match entry.node { - Node::Param(a) => &a.attrs[..], + Node::Param(a) => a.attrs, Node::Local(l) => &l.attrs[..], - Node::Item(i) => &i.attrs[..], - Node::ForeignItem(fi) => &fi.attrs[..], - Node::TraitItem(ref ti) => &ti.attrs[..], - Node::ImplItem(ref ii) => &ii.attrs[..], - Node::Variant(ref v) => &v.attrs[..], - Node::Field(ref f) => &f.attrs[..], + Node::Item(i) => i.attrs, + Node::ForeignItem(fi) => fi.attrs, + Node::TraitItem(ref ti) => ti.attrs, + Node::ImplItem(ref ii) => ii.attrs, + Node::Variant(ref v) => v.attrs, + Node::Field(ref f) => f.attrs, Node::Expr(ref e) => &*e.attrs, Node::Stmt(ref s) => s.kind.attrs(|id| self.item(id.id)), Node::Arm(ref a) => &*a.attrs, - Node::GenericParam(param) => ¶m.attrs[..], + Node::GenericParam(param) => param.attrs, // Unit/tuple structs/variants take the attributes straight from // the struct/variant definition. Node::Ctor(..) => self.attrs(self.get_parent_item(id)), - Node::Crate(item) => &item.attrs[..], + Node::Crate(item) => item.attrs, Node::MacroDef(def) => def.attrs, Node::AnonConst(..) | Node::PathSegment(..) diff --git a/compiler/rustc_middle/src/ty/query/on_disk_cache.rs b/compiler/rustc_middle/src/ty/query/on_disk_cache.rs index b41edb5deeb2c..efe047869330c 100644 --- a/compiler/rustc_middle/src/ty/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/ty/query/on_disk_cache.rs @@ -427,7 +427,7 @@ impl<'sess> OnDiskCache<'sess> { fn sorted_cnums_including_local_crate(tcx: TyCtxt<'_>) -> Vec { let mut cnums = vec![LOCAL_CRATE]; - cnums.extend_from_slice(&tcx.crates()[..]); + cnums.extend_from_slice(tcx.crates()); cnums.sort_unstable(); // Just to be sure... cnums.dedup(); diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index d2a693a568828..6457c6cee576f 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1105,7 +1105,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { } if let Some(items) = self.diagnostic_metadata.current_trait_assoc_items { - for assoc_item in &items[..] { + for assoc_item in items { if assoc_item.ident == ident { return Some(match &assoc_item.kind { ast::AssocItemKind::Const(..) => AssocSuggestion::AssocConst, diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 0e55c4ec0b7cb..c5dbd3ed08961 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1492,7 +1492,7 @@ impl Target { } ); ($key_name:ident = $json_name:expr, optional) => ( { let name = $json_name; - if let Some(o) = obj.find(&name[..]) { + if let Some(o) = obj.find(name) { base.$key_name = o .as_string() .map(|s| s.to_string() ); diff --git a/compiler/rustc_typeck/src/astconv/errors.rs b/compiler/rustc_typeck/src/astconv/errors.rs index 545c30169b91e..b5404c3a15ce0 100644 --- a/compiler/rustc_typeck/src/astconv/errors.rs +++ b/compiler/rustc_typeck/src/astconv/errors.rs @@ -237,7 +237,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } } if let ([], [bound]) = (&potential_assoc_types[..], &trait_bounds) { - match &bound.trait_ref.path.segments[..] { + match bound.trait_ref.path.segments { // FIXME: `trait_ref.path.span` can point to a full path with multiple // segments, even though `trait_ref.path.segments` is of length `1`. Work // around that bug here, even though it should be fixed elsewhere. diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index c9cc47b83e3d6..fb737ae7f5384 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -2374,7 +2374,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { crate::collect::placeholder_type_error( tcx, ident_span.map(|sp| sp.shrink_to_hi()), - &generics.params[..], + generics.params, visitor.0, true, hir_ty, diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index bc1a07801ae87..9e6c11d9dddbb 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -897,7 +897,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return ( path.res, opt_qself.as_ref().map(|qself| self.to_ty(qself)), - &path.segments[..], + path.segments, ); } QPath::TypeRelative(ref qself, ref segment) => (self.to_ty(qself), qself, segment), diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index d49c7cae8222b..885d961810be8 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -600,7 +600,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }); if let Some(hir::Node::Item(hir::Item { kind, .. })) = node { if let Some(g) = kind.generics() { - let key = match &g.where_clause.predicates[..] { + let key = match g.where_clause.predicates { [.., pred] => (pred.span().shrink_to_hi(), false), [] => ( g.where_clause diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index e24aa7d76f194..0d7ca70b944ad 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -229,14 +229,7 @@ fn reject_placeholder_type_signatures_in_item(tcx: TyCtxt<'tcx>, item: &'tcx hir let mut visitor = PlaceholderHirTyCollector::default(); visitor.visit_item(item); - placeholder_type_error( - tcx, - Some(generics.span), - &generics.params[..], - visitor.0, - suggest, - None, - ); + placeholder_type_error(tcx, Some(generics.span), generics.params, visitor.0, suggest, None); } impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { @@ -417,7 +410,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> { | hir::ItemKind::Struct(_, generics) | hir::ItemKind::Union(_, generics) => { let lt_name = get_new_lifetime_name(self.tcx, poly_trait_ref, generics); - let (lt_sp, sugg) = match &generics.params[..] { + let (lt_sp, sugg) = match generics.params { [] => (generics.span, format!("<{}>", lt_name)), [bound, ..] => { (bound.span.shrink_to_lo(), format!("{}, ", lt_name)) diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index 55062e11e029a..6044899c237e2 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -347,7 +347,7 @@ To learn more about a subcommand, run `./x.py -h`", }; // Done specifying what options are possible, so do the getopts parsing - let matches = opts.parse(&args[..]).unwrap_or_else(|e| { + let matches = opts.parse(args).unwrap_or_else(|e| { // Invalid argument/option format println!("\n{}\n", e); usage(1, &opts, false, &subcommand_help); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 7e7e417bb6544..2040a2edcd7e6 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -975,7 +975,7 @@ where { fn clean(&self, cx: &DocContext<'_>) -> FnDecl { FnDecl { - inputs: (&self.0.inputs[..], self.1).clean(cx), + inputs: (self.0.inputs, self.1).clean(cx), output: self.0.output.clean(cx), c_variadic: self.0.c_variadic, attrs: Attributes::default(), @@ -1939,7 +1939,7 @@ impl Clean for Symbol { impl Clean for hir::BareFnTy<'_> { fn clean(&self, cx: &DocContext<'_>) -> BareFunctionDecl { let (generic_params, decl) = enter_impl_trait(cx, || { - (self.generic_params.clean(cx), (&*self.decl, &self.param_names[..]).clean(cx)) + (self.generic_params.clean(cx), (&*self.decl, self.param_names).clean(cx)) }); BareFunctionDecl { unsafety: self.unsafety, abi: self.abi, decl, generic_params } } From 897cb610767741c0f49ff1e68cda41b521186003 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 16 Feb 2021 09:57:21 +0100 Subject: [PATCH 5/6] validation: fix invalid-fn-ptr error message --- compiler/rustc_mir/src/interpret/validity.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_mir/src/interpret/validity.rs b/compiler/rustc_mir/src/interpret/validity.rs index dac8ddccad67e..64e7a4d9ca758 100644 --- a/compiler/rustc_mir/src/interpret/validity.rs +++ b/compiler/rustc_mir/src/interpret/validity.rs @@ -586,8 +586,11 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' self.path, err_unsup!(ReadPointerAsBytes) => { "part of a pointer" } expected { "a proper pointer or integer value" }, ); + // Make sure we print a `ScalarMaybeUninit` (and not an `ImmTy`) in the error + // message below. + let value = value.to_scalar_or_uninit(); let _fn = try_validation!( - value.to_scalar().and_then(|ptr| self.ecx.memory.get_fn(ptr)), + value.check_init().and_then(|ptr| self.ecx.memory.get_fn(ptr)), self.path, err_ub!(DanglingIntPointer(..)) | err_ub!(InvalidFunctionPointer(..)) | From e5514efab25a4cefac730d6fb6d7917a4cf1cbb6 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 16 Feb 2021 11:14:34 +0100 Subject: [PATCH 6/6] add test --- .../const-eval/{ub-ref.rs => ub-ref-ptr.rs} | 11 ++++++ .../{ub-ref.stderr => ub-ref-ptr.stderr} | 36 +++++++++++++------ 2 files changed, 37 insertions(+), 10 deletions(-) rename src/test/ui/consts/const-eval/{ub-ref.rs => ub-ref-ptr.rs} (83%) rename src/test/ui/consts/const-eval/{ub-ref.stderr => ub-ref-ptr.stderr} (77%) diff --git a/src/test/ui/consts/const-eval/ub-ref.rs b/src/test/ui/consts/const-eval/ub-ref-ptr.rs similarity index 83% rename from src/test/ui/consts/const-eval/ub-ref.rs rename to src/test/ui/consts/const-eval/ub-ref-ptr.rs index e8b101fed6d2f..f6075987d178d 100644 --- a/src/test/ui/consts/const-eval/ub-ref.rs +++ b/src/test/ui/consts/const-eval/ub-ref-ptr.rs @@ -3,6 +3,12 @@ use std::mem; +#[repr(C)] +union MaybeUninit { + uninit: (), + init: T, +} + const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; //~^ ERROR it is undefined behavior to use this value //~| type validation failed: encountered an unaligned reference (required 2 byte alignment but found 1) @@ -35,4 +41,9 @@ const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; //~^ ERROR it is undefined behavior to use this value +const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init }; +//~^ ERROR it is undefined behavior to use this value +const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init }; +//~^ ERROR it is undefined behavior to use this value + fn main() {} diff --git a/src/test/ui/consts/const-eval/ub-ref.stderr b/src/test/ui/consts/const-eval/ub-ref-ptr.stderr similarity index 77% rename from src/test/ui/consts/const-eval/ub-ref.stderr rename to src/test/ui/consts/const-eval/ub-ref-ptr.stderr index 429ae69eabfdb..7d76c5cb43fe0 100644 --- a/src/test/ui/consts/const-eval/ub-ref.stderr +++ b/src/test/ui/consts/const-eval/ub-ref-ptr.stderr @@ -1,5 +1,5 @@ error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref.rs:6:1 + --> $DIR/ub-ref-ptr.rs:12:1 | LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered an unaligned reference (required 2 byte alignment but found 1) @@ -7,7 +7,7 @@ LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) }; = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref.rs:10:1 + --> $DIR/ub-ref-ptr.rs:16:1 | LL | const UNALIGNED_BOX: Box = unsafe { mem::transmute(&[0u8; 4]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered an unaligned box (required 2 byte alignment but found 1) @@ -15,7 +15,7 @@ LL | const UNALIGNED_BOX: Box = unsafe { mem::transmute(&[0u8; 4]) }; = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref.rs:14:1 + --> $DIR/ub-ref-ptr.rs:20:1 | LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a NULL reference @@ -23,7 +23,7 @@ LL | const NULL: &u16 = unsafe { mem::transmute(0usize) }; = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref.rs:17:1 + --> $DIR/ub-ref-ptr.rs:23:1 | LL | const NULL_BOX: Box = unsafe { mem::transmute(0usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a NULL box @@ -31,7 +31,7 @@ LL | const NULL_BOX: Box = unsafe { mem::transmute(0usize) }; = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref.rs:23:1 + --> $DIR/ub-ref-ptr.rs:29:1 | LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc14, but expected initialized plain (non-pointer) bytes @@ -39,7 +39,7 @@ LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) }; = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref.rs:26:1 + --> $DIR/ub-ref-ptr.rs:32:1 | LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at ., but expected plain (non-pointer) bytes @@ -47,7 +47,7 @@ LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }]; = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref.rs:29:1 + --> $DIR/ub-ref-ptr.rs:35:1 | LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at ., but expected plain (non-pointer) bytes @@ -55,7 +55,7 @@ LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[us = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref.rs:32:1 + --> $DIR/ub-ref-ptr.rs:38:1 | LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a dangling reference (created from integer) @@ -63,13 +63,29 @@ LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) }; = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. error[E0080]: it is undefined behavior to use this value - --> $DIR/ub-ref.rs:35:1 + --> $DIR/ub-ref-ptr.rs:41:1 | LL | const USIZE_AS_BOX: Box = unsafe { mem::transmute(1337usize) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a dangling box (created from integer) | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. -error: aborting due to 9 previous errors +error[E0080]: it is undefined behavior to use this value + --> $DIR/ub-ref-ptr.rs:44:1 + | +LL | const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized raw pointer + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. + +error[E0080]: it is undefined behavior to use this value + --> $DIR/ub-ref-ptr.rs:46:1 + | +LL | const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes, but expected a function pointer + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. + +error: aborting due to 11 previous errors For more information about this error, try `rustc --explain E0080`.