diff --git a/compiler/rustc_ast/src/util/literal.rs b/compiler/rustc_ast/src/util/literal.rs index 9c6ad47427d21..8a41aec081901 100644 --- a/compiler/rustc_ast/src/util/literal.rs +++ b/compiler/rustc_ast/src/util/literal.rs @@ -57,7 +57,7 @@ impl LitKind { // string in the token. let s = symbol.as_str(); let symbol = - if s.contains(&['\\', '\r'][..]) { + if s.contains(&['\\', '\r']) { let mut buf = String::with_capacity(s.len()); let mut error = Ok(()); unescape_literal(&s, Mode::Str, &mut |_, unescaped_char| { diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index ad539f2564d4c..5eaec79c4ed0c 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -347,7 +347,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { if let Some(modifiers) = nested_meta.value_str() { for modifier in modifiers.as_str().split(',') { - if let Some(modifier) = modifier.strip_prefix(&['+', '-'][..]) { + if let Some(modifier) = modifier.strip_prefix(&['+', '-']) { macro_rules! gate_modifier { ($($name:literal => $feature:ident)*) => { $(if modifier == $name { let msg = concat!("`#[link(modifiers=\"", $name, "\")]` is unstable"); @@ -383,7 +383,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } ast::ItemKind::Fn(..) => { - if self.sess.contains_name(&i.attrs[..], sym::start) { + if self.sess.contains_name(&i.attrs, sym::start) { gate_feature_post!( &self, start, @@ -396,7 +396,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } ast::ItemKind::Struct(..) => { - for attr in self.sess.filter_by_name(&i.attrs[..], sym::repr) { + for attr in self.sess.filter_by_name(&i.attrs, sym::repr) { for item in attr.meta_item_list().unwrap_or_else(Vec::new) { if item.has_name(sym::simd) { gate_feature_post!( diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 6c70cafb01fab..2e51144769359 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -499,7 +499,7 @@ pub trait PrintState<'a>: std::ops::Deref + std::ops::Dere ast::MetaItemKind::List(ref items) => { self.print_path(&item.path, false, 0); self.popen(); - self.commasep(Consistent, &items[..], |s, i| s.print_meta_list_item(i)); + self.commasep(Consistent, &items, |s, i| s.print_meta_list_item(i)); self.pclose(); } } @@ -997,7 +997,7 @@ impl<'a> State<'a> { } ast::TyKind::Tup(ref elts) => { self.popen(); - self.commasep(Inconsistent, &elts[..], |s, ty| s.print_type(ty)); + self.commasep(Inconsistent, &elts, |s, ty| s.print_type(ty)); if elts.len() == 1 { self.word(","); } @@ -1017,10 +1017,10 @@ impl<'a> State<'a> { ast::TyKind::Path(Some(ref qself), ref path) => self.print_qpath(path, qself, false), ast::TyKind::TraitObject(ref bounds, syntax) => { let prefix = if syntax == ast::TraitObjectSyntax::Dyn { "dyn" } else { "" }; - self.print_type_bounds(prefix, &bounds[..]); + self.print_type_bounds(prefix, &bounds); } ast::TyKind::ImplTrait(_, ref bounds) => { - self.print_type_bounds("impl", &bounds[..]); + self.print_type_bounds("impl", &bounds); } ast::TyKind::Array(ref ty, ref length) => { self.word("["); @@ -1339,7 +1339,7 @@ impl<'a> State<'a> { real_bounds.push(b.clone()); } } - self.print_type_bounds(":", &real_bounds[..]); + self.print_type_bounds(":", &real_bounds); self.print_where_clause(&generics.where_clause); self.word(" "); self.bopen(); @@ -1368,7 +1368,7 @@ impl<'a> State<'a> { } } self.nbsp(); - self.print_type_bounds("=", &real_bounds[..]); + self.print_type_bounds("=", &real_bounds); self.print_where_clause(&generics.where_clause); self.word(";"); } @@ -1960,10 +1960,10 @@ impl<'a> State<'a> { self.print_expr_tup(exprs); } ast::ExprKind::Call(ref func, ref args) => { - self.print_expr_call(func, &args[..]); + self.print_expr_call(func, &args); } ast::ExprKind::MethodCall(ref segment, ref args, _) => { - self.print_expr_method_call(segment, &args[..]); + self.print_expr_method_call(segment, &args); } ast::ExprKind::Binary(op, ref lhs, ref rhs) => { self.print_expr_binary(op, lhs, rhs); @@ -2440,11 +2440,11 @@ impl<'a> State<'a> { self.print_path(path, true, 0); } self.popen(); - self.commasep(Inconsistent, &elts[..], |s, p| s.print_pat(p)); + self.commasep(Inconsistent, &elts, |s, p| s.print_pat(p)); self.pclose(); } PatKind::Or(ref pats) => { - self.strsep("|", true, Inconsistent, &pats[..], |s, p| s.print_pat(p)); + self.strsep("|", true, Inconsistent, &pats, |s, p| s.print_pat(p)); } PatKind::Path(None, ref path) => { self.print_path(path, true, 0); @@ -2462,7 +2462,7 @@ impl<'a> State<'a> { self.word_space("{"); self.commasep_cmnt( Consistent, - &fields[..], + &fields, |s, f| { s.cbox(INDENT_UNIT); if !f.is_shorthand { @@ -2485,7 +2485,7 @@ impl<'a> State<'a> { } PatKind::Tuple(ref elts) => { self.popen(); - self.commasep(Inconsistent, &elts[..], |s, p| s.print_pat(p)); + self.commasep(Inconsistent, &elts, |s, p| s.print_pat(p)); if elts.len() == 1 { self.word(","); } @@ -2527,7 +2527,7 @@ impl<'a> State<'a> { } PatKind::Slice(ref elts) => { self.word("["); - self.commasep(Inconsistent, &elts[..], |s, p| s.print_pat(p)); + self.commasep(Inconsistent, &elts, |s, p| s.print_pat(p)); self.word("]"); } PatKind::Rest => self.word(".."), @@ -2836,7 +2836,7 @@ impl<'a> State<'a> { self.print_path(&tree.prefix, false, 0); self.word("::{"); } - self.commasep(Inconsistent, &items[..], |this, &(ref tree, _)| { + self.commasep(Inconsistent, &items, |this, &(ref tree, _)| { this.print_use_tree(tree) }); self.word("}"); diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs index b374769cbea25..9ae1584fcbf6a 100644 --- a/compiler/rustc_builtin_macros/src/asm.rs +++ b/compiler/rustc_builtin_macros/src/asm.rs @@ -712,7 +712,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option Some(idx), None => { let msg = format!("there is no argument named `{}`", name); - ecx.struct_span_err(span, &msg[..]).emit(); + ecx.struct_span_err(span, &msg).emit(); None } }, diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index 1427a2aada3fc..985c45e225388 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -766,8 +766,8 @@ impl<'a> TraitDef<'a> { self, struct_def, type_ident, - &self_args[..], - &nonself_args[..], + &self_args, + &nonself_args, ) } else { method_def.expand_struct_method_body( @@ -775,8 +775,8 @@ impl<'a> TraitDef<'a> { self, struct_def, type_ident, - &self_args[..], - &nonself_args[..], + &self_args, + &nonself_args, use_temporaries, ) }; @@ -815,8 +815,8 @@ impl<'a> TraitDef<'a> { self, enum_def, type_ident, - &self_args[..], - &nonself_args[..], + &self_args, + &nonself_args, ) } else { method_def.expand_enum_method_body( @@ -825,7 +825,7 @@ impl<'a> TraitDef<'a> { enum_def, type_ident, self_args, - &nonself_args[..], + &nonself_args, ) }; @@ -1217,7 +1217,7 @@ impl<'a> MethodDef<'a> { let vi_idents = self_arg_names .iter() .map(|name| { - let vi_suffix = format!("{}_vi", &name[..]); + let vi_suffix = format!("{}_vi", name); Ident::from_str_and_span(&vi_suffix, span) }) .collect::>(); @@ -1226,7 +1226,7 @@ impl<'a> MethodDef<'a> { // delegated expression that handles the catch-all case, // using `__variants_tuple` to drive logic if necessary. let catch_all_substructure = - EnumNonMatchingCollapsed(self_arg_idents, &variants[..], &vi_idents[..]); + EnumNonMatchingCollapsed(self_arg_idents, &variants, &vi_idents); let first_fieldless = variants.iter().find(|v| v.data.fields().is_empty()); @@ -1261,7 +1261,7 @@ impl<'a> MethodDef<'a> { idents }; for self_arg_name in &self_arg_names[1..] { - let (p, idents) = mk_self_pat(cx, &self_arg_name[..]); + let (p, idents) = mk_self_pat(cx, &self_arg_name); subpats.push(p); self_pats_idents.push(idents); } diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs index 62a55c0e49ed0..34cc43968163f 100644 --- a/compiler/rustc_builtin_macros/src/format.rs +++ b/compiler/rustc_builtin_macros/src/format.rs @@ -549,7 +549,7 @@ impl<'a, 'b> Context<'a, 'b> { } else { self.fmtsp }; - let mut err = self.ecx.struct_span_err(sp, &msg[..]); + let mut err = self.ecx.struct_span_err(sp, &msg); err.note(&format!( "did you intend to capture a variable `{}` from \ diff --git a/compiler/rustc_codegen_gcc/src/back/write.rs b/compiler/rustc_codegen_gcc/src/back/write.rs index c3e3847823d91..4962d01615256 100644 --- a/compiler/rustc_codegen_gcc/src/back/write.rs +++ b/compiler/rustc_codegen_gcc/src/back/write.rs @@ -32,7 +32,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext, _diag_han if config.emit_asm { let _timer = cgcx .prof - .generic_activity_with_arg("LLVM_module_codegen_emit_asm", &module.name[..]); + .generic_activity_with_arg("LLVM_module_codegen_emit_asm", &*module.name); let path = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name); context.compile_to_file(OutputKind::Assembler, path.to_str().expect("path to str")); } @@ -41,7 +41,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext, _diag_han EmitObj::ObjectCode(_) => { let _timer = cgcx .prof - .generic_activity_with_arg("LLVM_module_codegen_emit_obj", &module.name[..]); + .generic_activity_with_arg("LLVM_module_codegen_emit_obj", &*module.name); match &*module.name { "std_example.7rcbfp3g-cgu.15" => { println!("Dumping reproducer {}", module.name); diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs index f3c3a17490811..ee31f2e60a97e 100644 --- a/compiler/rustc_codegen_llvm/src/asm.rs +++ b/compiler/rustc_codegen_llvm/src/asm.rs @@ -477,7 +477,7 @@ pub(crate) fn inline_asm_call( .collect::>(); debug!("Asm Output Type: {:?}", output); - let fty = bx.cx.type_func(&argtys[..], output); + let fty = bx.cx.type_func(&argtys, output); unsafe { // Ask LLVM to verify that the constraints are well-formed. let constraints_ok = llvm::LLVMRustInlineAsmVerify(fty, cons.as_ptr().cast(), cons.len()); diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs index 97780de9ba4af..f6c40f1689e9e 100644 --- a/compiler/rustc_codegen_llvm/src/back/lto.rs +++ b/compiler/rustc_codegen_llvm/src/back/lto.rs @@ -587,7 +587,7 @@ pub(crate) fn run_pass_manager( config: &ModuleConfig, thin: bool, ) -> Result<(), FatalError> { - let _timer = cgcx.prof.extra_verbose_generic_activity("LLVM_lto_optimize", &module.name[..]); + let _timer = cgcx.prof.extra_verbose_generic_activity("LLVM_lto_optimize", &*module.name); // Now we have one massive module inside of llmod. Time to run the // LTO-specific optimization passes that LLVM provides. diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 460a8cc69128e..fa4fad30830d9 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -510,7 +510,7 @@ pub(crate) unsafe fn optimize( module: &ModuleCodegen, config: &ModuleConfig, ) -> Result<(), FatalError> { - let _timer = cgcx.prof.generic_activity_with_arg("LLVM_module_optimize", &module.name[..]); + let _timer = cgcx.prof.generic_activity_with_arg("LLVM_module_optimize", &*module.name); let llmod = module.module_llvm.llmod(); let llcx = &*module.module_llvm.llcx; @@ -663,14 +663,14 @@ pub(crate) unsafe fn optimize( { let _timer = cgcx.prof.extra_verbose_generic_activity( "LLVM_module_optimize_function_passes", - &module.name[..], + &*module.name, ); llvm::LLVMRustRunFunctionPassManager(fpm, llmod); } { let _timer = cgcx.prof.extra_verbose_generic_activity( "LLVM_module_optimize_module_passes", - &module.name[..], + &*module.name, ); llvm::LLVMRunPassManager(mpm, llmod); } @@ -733,7 +733,7 @@ pub(crate) unsafe fn codegen( module: ModuleCodegen, config: &ModuleConfig, ) -> Result { - let _timer = cgcx.prof.generic_activity_with_arg("LLVM_module_codegen", &module.name[..]); + let _timer = cgcx.prof.generic_activity_with_arg("LLVM_module_codegen", &*module.name); { let llmod = module.module_llvm.llmod(); let llcx = &*module.module_llvm.llcx; @@ -782,7 +782,7 @@ pub(crate) unsafe fn codegen( if config.bitcode_needed() { let _timer = cgcx .prof - .generic_activity_with_arg("LLVM_module_codegen_make_bitcode", &module.name[..]); + .generic_activity_with_arg("LLVM_module_codegen_make_bitcode", &*module.name); let thin = ThinBuffer::new(llmod); let data = thin.data(); @@ -795,10 +795,9 @@ pub(crate) unsafe fn codegen( } if config.emit_bc || config.emit_obj == EmitObj::Bitcode { - let _timer = cgcx.prof.generic_activity_with_arg( - "LLVM_module_codegen_emit_bitcode", - &module.name[..], - ); + let _timer = cgcx + .prof + .generic_activity_with_arg("LLVM_module_codegen_emit_bitcode", &*module.name); if let Err(e) = fs::write(&bc_out, data) { let msg = format!("failed to write bytecode to {}: {}", bc_out.display(), e); diag_handler.err(&msg); @@ -806,18 +805,16 @@ pub(crate) unsafe fn codegen( } if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full) { - let _timer = cgcx.prof.generic_activity_with_arg( - "LLVM_module_codegen_embed_bitcode", - &module.name[..], - ); + let _timer = cgcx + .prof + .generic_activity_with_arg("LLVM_module_codegen_embed_bitcode", &*module.name); embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data); } } if config.emit_ir { - let _timer = cgcx - .prof - .generic_activity_with_arg("LLVM_module_codegen_emit_ir", &module.name[..]); + let _timer = + cgcx.prof.generic_activity_with_arg("LLVM_module_codegen_emit_ir", &*module.name); let out = cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, module_name); let out_c = path_to_c_string(&out); @@ -866,9 +863,8 @@ pub(crate) unsafe fn codegen( } if config.emit_asm { - let _timer = cgcx - .prof - .generic_activity_with_arg("LLVM_module_codegen_emit_asm", &module.name[..]); + let _timer = + cgcx.prof.generic_activity_with_arg("LLVM_module_codegen_emit_asm", &*module.name); let path = cgcx.output_filenames.temp_path(OutputType::Assembly, module_name); // We can't use the same module for asm and object code output, @@ -898,7 +894,7 @@ pub(crate) unsafe fn codegen( EmitObj::ObjectCode(_) => { let _timer = cgcx .prof - .generic_activity_with_arg("LLVM_module_codegen_emit_obj", &module.name[..]); + .generic_activity_with_arg("LLVM_module_codegen_emit_obj", &*module.name); let dwo_out = cgcx.output_filenames.temp_path_dwo(module_name); let dwo_out = match cgcx.split_debuginfo { diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index 73a8d46443163..d0ed978124313 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -120,7 +120,7 @@ impl CodegenCx<'ll, 'tcx> { !null_terminated as Bool, ); let sym = self.generate_local_symbol_name("str"); - let g = self.define_global(&sym[..], self.val_ty(sc)).unwrap_or_else(|| { + let g = self.define_global(&sym, self.val_ty(sc)).unwrap_or_else(|| { bug!("symbol `{}` is already defined", sym); }); llvm::LLVMSetInitializer(g, sc); diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index b154ced42f0d6..50a68ae49d50c 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -225,7 +225,7 @@ impl CodegenCx<'ll, 'tcx> { let gv = match kind { Some(kind) if !self.tcx.sess.fewer_names() => { let name = self.generate_local_symbol_name(kind); - let gv = self.define_global(&name[..], self.val_ty(cv)).unwrap_or_else(|| { + let gv = self.define_global(&name, self.val_ty(cv)).unwrap_or_else(|| { bug!("symbol `{}` is already defined", name); }); llvm::LLVMRustSetLinkage(gv, llvm::Linkage::PrivateLinkage); diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs index 0390caaec33e5..d2af1b247e86e 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs @@ -89,7 +89,7 @@ pub fn finalize<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) { }); let filenames_size = filenames_buffer.len(); - let filenames_val = cx.const_bytes(&filenames_buffer[..]); + let filenames_val = cx.const_bytes(&filenames_buffer); let filenames_ref = coverageinfo::hash_bytes(filenames_buffer); // Generate the LLVM IR representation of the coverage map and store it in a well-known global @@ -238,7 +238,7 @@ fn save_function_record( ) { // Concatenate the encoded coverage mappings let coverage_mapping_size = coverage_mapping_buffer.len(); - let coverage_mapping_val = cx.const_bytes(&coverage_mapping_buffer[..]); + let coverage_mapping_val = cx.const_bytes(&coverage_mapping_buffer); let func_name_hash = coverageinfo::hash_str(&mangled_function_name); let func_name_hash_val = cx.const_u64(func_name_hash); diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 10c7bb2eaea94..cc39332d198f0 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -456,7 +456,7 @@ fn vec_slice_metadata( let metadata = composite_type_metadata( cx, slice_ptr_type, - &slice_type_name[..], + &slice_type_name, unique_type_id, member_descriptions, NO_SCOPE_METADATA, @@ -579,7 +579,7 @@ fn trait_pointer_metadata( composite_type_metadata( cx, trait_object_type.unwrap_or(trait_type), - &trait_type_name[..], + &trait_type_name, unique_type_id, member_descriptions, containing_scope, @@ -2398,7 +2398,7 @@ fn set_members_of_composite_type( let type_params = compute_type_parameters(cx, composite_type); unsafe { - let type_array = create_DIArray(DIB(cx), &member_metadata[..]); + let type_array = create_DIArray(DIB(cx), &member_metadata); llvm::LLVMRustDICompositeTypeReplaceArrays( DIB(cx), composite_type_metadata, @@ -2437,7 +2437,7 @@ fn compute_type_parameters(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> &'ll DIAr }) .collect(); - return create_DIArray(DIB(cx), &template_params[..]); + return create_DIArray(DIB(cx), &template_params); } } return create_DIArray(DIB(cx), &[]); diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 2a6bf7d9b1a4d..b801a7c131443 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -474,7 +474,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { vec![] }; - create_DIArray(DIB(cx), &template_params[..]) + create_DIArray(DIB(cx), &template_params) } fn get_parameter_names(cx: &CodegenCx<'_, '_>, generics: &ty::Generics) -> Vec { diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 2d6904af207d1..d6af6104155a1 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -677,11 +677,11 @@ impl WorkItem { fn start_profiling<'a>(&self, cgcx: &'a CodegenContext) -> TimingGuard<'a> { match *self { WorkItem::Optimize(ref m) => { - cgcx.prof.generic_activity_with_arg("codegen_module_optimize", &m.name[..]) + cgcx.prof.generic_activity_with_arg("codegen_module_optimize", &*m.name) } WorkItem::CopyPostLtoArtifacts(ref m) => cgcx .prof - .generic_activity_with_arg("codegen_copy_artifacts_from_incr_cache", &m.name[..]), + .generic_activity_with_arg("codegen_copy_artifacts_from_incr_cache", &*m.name), WorkItem::LTO(ref m) => { cgcx.prof.generic_activity_with_arg("codegen_module_perform_lto", m.name()) } diff --git a/compiler/rustc_codegen_ssa/src/common.rs b/compiler/rustc_codegen_ssa/src/common.rs index 1fa60612d26a3..2df58ecc9f68a 100644 --- a/compiler/rustc_codegen_ssa/src/common.rs +++ b/compiler/rustc_codegen_ssa/src/common.rs @@ -122,8 +122,8 @@ pub fn langcall(tcx: TyCtxt<'_>, span: Option, msg: &str, li: LangItem) -> tcx.lang_items().require(li).unwrap_or_else(|s| { let msg = format!("{} {}", msg, s); match span { - Some(span) => tcx.sess.span_fatal(span, &msg[..]), - None => tcx.sess.fatal(&msg[..]), + Some(span) => tcx.sess.span_fatal(span, &msg), + None => tcx.sess.fatal(&msg), } }) } diff --git a/compiler/rustc_const_eval/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs index 00208574c555e..df177fd9679d5 100644 --- a/compiler/rustc_const_eval/src/interpret/terminator.rs +++ b/compiler/rustc_const_eval/src/interpret/terminator.rs @@ -103,7 +103,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { self.eval_fn_call( fn_val, abi, - &args[..], + &args, ret, match (cleanup, caller_can_unwind) { (Some(cleanup), true) => StackPopUnwind::Cleanup(*cleanup), diff --git a/compiler/rustc_data_structures/src/fingerprint.rs b/compiler/rustc_data_structures/src/fingerprint.rs index c0c0e7be3ca85..c9af35da4bcef 100644 --- a/compiler/rustc_data_structures/src/fingerprint.rs +++ b/compiler/rustc_data_structures/src/fingerprint.rs @@ -142,7 +142,7 @@ impl_stable_hash_via_hash!(Fingerprint); impl Encodable for Fingerprint { #[inline] fn encode(&self, s: &mut E) -> Result<(), E::Error> { - s.emit_raw_bytes(&self.to_le_bytes()[..])?; + s.emit_raw_bytes(&self.to_le_bytes())?; Ok(()) } } @@ -151,7 +151,7 @@ impl Decodable for Fingerprint { #[inline] fn decode(d: &mut D) -> Result { let mut bytes = [0u8; 16]; - d.read_raw_bytes_into(&mut bytes[..])?; + d.read_raw_bytes_into(&mut bytes)?; Ok(Fingerprint::from_le_bytes(bytes)) } } diff --git a/compiler/rustc_data_structures/src/functor.rs b/compiler/rustc_data_structures/src/functor.rs index 71ff762c714bf..a3d3f988344c6 100644 --- a/compiler/rustc_data_structures/src/functor.rs +++ b/compiler/rustc_data_structures/src/functor.rs @@ -34,38 +34,43 @@ impl IdFunctor for Vec { type Inner = T; #[inline] - fn try_map_id(mut self, mut f: F) -> Result + fn try_map_id(self, mut f: F) -> Result where F: FnMut(Self::Inner) -> Result, { - // FIXME: We don't really care about panics here and leak - // far more than we should, but that should be fine for now. - let len = self.len(); - unsafe { - self.set_len(0); - let start = self.as_mut_ptr(); - for i in 0..len { - let p = start.add(i); - match f(p.read()) { - Ok(val) => p.write(val), - Err(err) => { - // drop all other elements in self - // (current element was "moved" into the call to f) - for j in (0..i).chain(i + 1..len) { - start.add(j).drop_in_place(); - } + struct HoleVec { + vec: Vec>, + hole: Option, + } - // returning will drop self, releasing the allocation - // (len is 0 so elements will not be re-dropped) - return Err(err); + impl Drop for HoleVec { + fn drop(&mut self) { + unsafe { + for (index, slot) in self.vec.iter_mut().enumerate() { + if self.hole != Some(index) { + mem::ManuallyDrop::drop(slot); + } } } } - // Even if we encountered an error, set the len back - // so we don't leak memory. - self.set_len(len); } - Ok(self) + + unsafe { + let (ptr, length, capacity) = self.into_raw_parts(); + let vec = Vec::from_raw_parts(ptr.cast(), length, capacity); + let mut hole_vec = HoleVec { vec, hole: None }; + + for (index, slot) in hole_vec.vec.iter_mut().enumerate() { + hole_vec.hole = Some(index); + let original = mem::ManuallyDrop::take(slot); + let mapped = f(original)?; + *slot = mem::ManuallyDrop::new(mapped); + hole_vec.hole = None; + } + + mem::forget(hole_vec); + Ok(Vec::from_raw_parts(ptr, length, capacity)) + } } } diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index e17724b72f8b8..181e5180d53d5 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -23,6 +23,7 @@ #![feature(once_cell)] #![feature(test)] #![feature(thread_id_value)] +#![feature(vec_into_raw_parts)] #![allow(rustc::default_hash_types)] #![deny(unaligned_references)] diff --git a/compiler/rustc_data_structures/src/profiling.rs b/compiler/rustc_data_structures/src/profiling.rs index c21939209fc3b..fd6ff086b08cd 100644 --- a/compiler/rustc_data_structures/src/profiling.rs +++ b/compiler/rustc_data_structures/src/profiling.rs @@ -649,7 +649,7 @@ impl Drop for VerboseTimingGuard<'_> { fn drop(&mut self) { if let Some((start_time, start_rss, ref message)) = self.start_and_message { let end_rss = get_resident_set_size(); - print_time_passes_entry(&message[..], start_time.elapsed(), start_rss, end_rss); + print_time_passes_entry(&message, start_time.elapsed(), start_rss, end_rss); } } } diff --git a/compiler/rustc_data_structures/src/small_c_str.rs b/compiler/rustc_data_structures/src/small_c_str.rs index 4a089398ce61e..33e72914e19e3 100644 --- a/compiler/rustc_data_structures/src/small_c_str.rs +++ b/compiler/rustc_data_structures/src/small_c_str.rs @@ -46,7 +46,7 @@ impl SmallCStr { #[inline] pub fn as_c_str(&self) -> &ffi::CStr { - unsafe { ffi::CStr::from_bytes_with_nul_unchecked(&self.data[..]) } + unsafe { ffi::CStr::from_bytes_with_nul_unchecked(&self.data) } } #[inline] diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 537a10e98e59d..8065911afb9da 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -253,7 +253,7 @@ fn generic_extension<'cx>( for (i, lhs) in lhses.iter().enumerate() { // try each arm's matchers let lhs_tt = match *lhs { - mbe::TokenTree::Delimited(_, ref delim) => &delim.tts[..], + mbe::TokenTree::Delimited(_, ref delim) => &delim.tts, _ => cx.span_bug(sp, "malformed macro lhs"), }; @@ -353,7 +353,7 @@ fn generic_extension<'cx>( for lhs in lhses { // try each arm's matchers let lhs_tt = match *lhs { - mbe::TokenTree::Delimited(_, ref delim) => &delim.tts[..], + mbe::TokenTree::Delimited(_, ref delim) => &delim.tts, _ => continue, }; if let Success(_) = @@ -677,11 +677,11 @@ impl FirstSets { first.replace_with(tt.clone()); } TokenTree::Delimited(span, ref delimited) => { - build_recur(sets, &delimited.tts[..]); + build_recur(sets, &delimited.tts); first.replace_with(delimited.open_tt(span)); } TokenTree::Sequence(sp, ref seq_rep) => { - let subfirst = build_recur(sets, &seq_rep.tts[..]); + let subfirst = build_recur(sets, &seq_rep.tts); match sets.first.entry(sp.entire()) { Entry::Vacant(vac) => { @@ -748,7 +748,7 @@ impl FirstSets { let subfirst = match self.first.get(&sp.entire()) { Some(&Some(ref subfirst)) => subfirst, Some(&None) => { - subfirst_owned = self.first(&seq_rep.tts[..]); + subfirst_owned = self.first(&seq_rep.tts); &subfirst_owned } None => { diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index 88e1623012ba0..01a7f7266172c 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -175,12 +175,12 @@ pub(super) fn transcribe<'a>( )); } - LockstepIterSize::Contradiction(ref msg) => { + LockstepIterSize::Contradiction(msg) => { // FIXME: this really ought to be caught at macro definition time... It // happens when two meta-variables are used in the same repetition in a // sequence, but they come from different sequence matchers and repeat // different amounts. - return Err(cx.struct_span_err(seq.span(), &msg[..])); + return Err(cx.struct_span_err(seq.span(), &msg)); } LockstepIterSize::Constraint(len, _) => { diff --git a/compiler/rustc_graphviz/src/lib.rs b/compiler/rustc_graphviz/src/lib.rs index 27390fd2e4d91..edb8bd503e1d0 100644 --- a/compiler/rustc_graphviz/src/lib.rs +++ b/compiler/rustc_graphviz/src/lib.rs @@ -659,7 +659,7 @@ where } writeln!(text, ";").unwrap(); - w.write_all(&text[..])?; + w.write_all(&text)?; text.clear(); } @@ -684,7 +684,7 @@ where } writeln!(text, ";").unwrap(); - w.write_all(&text[..])?; + w.write_all(&text)?; text.clear(); } diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index c3601d0997c23..65cdf10f9016a 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -316,7 +316,7 @@ impl<'a> State<'a> { } hir::TyKind::Tup(ref elts) => { self.popen(); - self.commasep(Inconsistent, &elts[..], |s, ty| s.print_type(&ty)); + self.commasep(Inconsistent, &elts, |s, ty| s.print_type(&ty)); if elts.len() == 1 { self.word(","); } @@ -1860,7 +1860,7 @@ impl<'a> State<'a> { self.commasep(Inconsistent, &elts[ddpos..], |s, p| s.print_pat(&p)); } } else { - self.commasep(Inconsistent, &elts[..], |s, p| s.print_pat(&p)); + self.commasep(Inconsistent, &elts, |s, p| s.print_pat(&p)); } self.pclose(); } @@ -1873,7 +1873,7 @@ impl<'a> State<'a> { self.word_space("{"); self.commasep_cmnt( Consistent, - &fields[..], + &fields, |s, f| { s.cbox(INDENT_UNIT); if !f.is_shorthand { @@ -1895,7 +1895,7 @@ impl<'a> State<'a> { self.word("}"); } PatKind::Or(ref pats) => { - self.strsep("|", true, Inconsistent, &pats[..], |s, p| s.print_pat(&p)); + self.strsep("|", true, Inconsistent, &pats, |s, p| s.print_pat(&p)); } PatKind::Tuple(ref elts, ddpos) => { self.popen(); @@ -1956,7 +1956,7 @@ impl<'a> State<'a> { } PatKind::Slice(ref before, ref slice, ref after) => { self.word("["); - self.commasep(Inconsistent, &before[..], |s, p| s.print_pat(&p)); + self.commasep(Inconsistent, &before, |s, p| s.print_pat(&p)); if let Some(ref p) = *slice { if !before.is_empty() { self.word_space(","); @@ -1971,7 +1971,7 @@ impl<'a> State<'a> { self.word_space(","); } } - self.commasep(Inconsistent, &after[..], |s, p| s.print_pat(&p)); + self.commasep(Inconsistent, &after, |s, p| s.print_pat(&p)); self.word("]"); } } diff --git a/compiler/rustc_incremental/src/persist/load.rs b/compiler/rustc_incremental/src/persist/load.rs index 9c6e2aeb50a76..b36bf89c9d339 100644 --- a/compiler/rustc_incremental/src/persist/load.rs +++ b/compiler/rustc_incremental/src/persist/load.rs @@ -151,7 +151,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture { compilation session directory: {}", e ); - sess.fatal(&msg[..]) + sess.fatal(&msg) }); for swp in work_products { diff --git a/compiler/rustc_lint/src/non_fmt_panic.rs b/compiler/rustc_lint/src/non_fmt_panic.rs index 4a9b27e89b199..30506445ebb5e 100644 --- a/compiler/rustc_lint/src/non_fmt_panic.rs +++ b/compiler/rustc_lint/src/non_fmt_panic.rs @@ -207,7 +207,7 @@ fn check_panic_str<'tcx>( arg: &'tcx hir::Expr<'tcx>, fmt: &str, ) { - if !fmt.contains(&['{', '}'][..]) { + if !fmt.contains(&['{', '}']) { // No brace, no problem. return; } diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index bd5cda15b91ab..9adf9406f09b4 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -132,7 +132,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> { if let Some(modifiers) = item.value_str() { let span = item.name_value_literal_span().unwrap(); for modifier in modifiers.as_str().split(',') { - let (modifier, value) = match modifier.strip_prefix(&['+', '-'][..]) { + let (modifier, value) = match modifier.strip_prefix(&['+', '-']) { Some(m) => (m, modifier.starts_with('+')), None => { sess.span_err( diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 514a49d7e2ce2..94e7376ddb216 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -2119,7 +2119,7 @@ impl EncodedMetadata { #[inline] pub fn raw_data(&self) -> &[u8] { - &self.raw_data[..] + &self.raw_data } } diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index 06b42320049f0..f48e27e02cdc5 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -530,6 +530,6 @@ impl CodegenUnitNameBuilder<'tcx> { write!(cgu_name, ".{}", special_suffix).unwrap(); } - Symbol::intern(&cgu_name[..]) + Symbol::intern(&cgu_name) } } diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs index d52b6a8bc7587..51e4afaf2204a 100644 --- a/compiler/rustc_middle/src/mir/terminator.rs +++ b/compiler/rustc_middle/src/mir/terminator.rs @@ -342,7 +342,7 @@ impl<'tcx> TerminatorKind<'tcx> { | InlineAsm { destination: Some(ref t), cleanup: Some(ref u), .. } => { Some(t).into_iter().chain(slice::from_ref(u)) } - SwitchInt { ref targets, .. } => None.into_iter().chain(&targets.targets[..]), + SwitchInt { ref targets, .. } => None.into_iter().chain(&targets.targets), FalseEdge { ref real_target, ref imaginary_target } => { Some(real_target).into_iter().chain(slice::from_ref(imaginary_target)) } @@ -380,7 +380,7 @@ impl<'tcx> TerminatorKind<'tcx> { | InlineAsm { destination: Some(ref mut t), cleanup: Some(ref mut u), .. } => { Some(t).into_iter().chain(slice::from_mut(u)) } - SwitchInt { ref mut targets, .. } => None.into_iter().chain(&mut targets.targets[..]), + SwitchInt { ref mut targets, .. } => None.into_iter().chain(&mut targets.targets), FalseEdge { ref mut real_target, ref mut imaginary_target } => { Some(real_target).into_iter().chain(slice::from_mut(imaginary_target)) } diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 49a64cb246ad0..33ddc4f954a28 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -587,18 +587,18 @@ impl<'tcx, N> ImplSource<'tcx, N> { pub fn borrow_nested_obligations(&self) -> &[N] { match &self { ImplSource::UserDefined(i) => &i.nested[..], - ImplSource::Param(n, _) => &n[..], - ImplSource::Builtin(i) => &i.nested[..], - ImplSource::AutoImpl(d) => &d.nested[..], - ImplSource::Closure(c) => &c.nested[..], - ImplSource::Generator(c) => &c.nested[..], - ImplSource::Object(d) => &d.nested[..], - ImplSource::FnPointer(d) => &d.nested[..], + ImplSource::Param(n, _) => &n, + ImplSource::Builtin(i) => &i.nested, + ImplSource::AutoImpl(d) => &d.nested, + ImplSource::Closure(c) => &c.nested, + ImplSource::Generator(c) => &c.nested, + ImplSource::Object(d) => &d.nested, + ImplSource::FnPointer(d) => &d.nested, ImplSource::DiscriminantKind(ImplSourceDiscriminantKindData) | ImplSource::Pointee(ImplSourcePointeeData) | ImplSource::ConstDrop(ImplSourceConstDropData) => &[], - ImplSource::TraitAlias(d) => &d.nested[..], - ImplSource::TraitUpcasting(d) => &d.nested[..], + ImplSource::TraitAlias(d) => &d.nested, + ImplSource::TraitUpcasting(d) => &d.nested, } } diff --git a/compiler/rustc_middle/src/ty/list.rs b/compiler/rustc_middle/src/ty/list.rs index 1dceda6c7aad0..adba7d131592e 100644 --- a/compiler/rustc_middle/src/ty/list.rs +++ b/compiler/rustc_middle/src/ty/list.rs @@ -1,7 +1,5 @@ use crate::arena::Arena; - use rustc_serialize::{Encodable, Encoder}; - use std::alloc::Layout; use std::cmp::Ordering; use std::fmt; @@ -12,49 +10,69 @@ use std::ops::Deref; use std::ptr; use std::slice; -extern "C" { - /// A dummy type used to force `List` to be unsized while not requiring references to it be wide - /// pointers. - type OpaqueListContents; -} - -/// A wrapper for slices with the additional invariant -/// that the slice is interned and no other slice with -/// the same contents can exist in the same context. -/// This means we can use pointer for both -/// equality comparisons and hashing. -/// -/// Unlike slices, the types contained in `List` are expected to be `Copy` -/// and iterating over a `List` returns `T` instead of a reference. -/// -/// Note: `Slice` was already taken by the `Ty`. +/// `List` is a bit like `&[T]`, but with some critical differences. +/// - IMPORTANT: Every `List` is *required* to have unique contents. The +/// type's correctness relies on this, *but it does not enforce it*. +/// Therefore, any code that creates a `List` must ensure uniqueness +/// itself. In practice this is achieved by interning. +/// - The length is stored within the `List`, so `&List` is a thin +/// pointer. +/// - Because of this, you cannot get a `List` that is a sub-list of another +/// `List`. You can get a sub-slice `&[T]`, however. +/// - `List` can be used with `CopyTaggedPtr`, which is useful within +/// structs whose size must be minimized. +/// - Because of the uniqueness assumption, we can use the address of a +/// `List` for faster equality comparisons and hashing. +/// - `T` must be `Copy`. This lets `List` be stored in a dropless arena and +/// iterators return a `T` rather than a `&T`. +/// - `T` must not be zero-sized. #[repr(C)] pub struct List { len: usize, + + /// Although this claims to be a zero-length array, in practice `len` + /// elements are actually present. data: [T; 0], + opaque: OpaqueListContents, } -unsafe impl<'a, T: 'a> rustc_data_structures::tagged_ptr::Pointer for &'a List { - const BITS: usize = std::mem::align_of::().trailing_zeros() as usize; - #[inline] - fn into_usize(self) -> usize { - self as *const List as usize - } - #[inline] - unsafe fn from_usize(ptr: usize) -> Self { - &*(ptr as *const List) - } - unsafe fn with_ref R>(ptr: usize, f: F) -> R { - // Self: Copy so this is fine - let ptr = Self::from_usize(ptr); - f(&ptr) - } +extern "C" { + /// A dummy type used to force `List` to be unsized while not requiring + /// references to it be wide pointers. + type OpaqueListContents; } -unsafe impl Sync for List {} +impl List { + /// Returns a reference to the (unique, static) empty list. + #[inline(always)] + pub fn empty<'a>() -> &'a List { + #[repr(align(64))] + struct MaxAlign; + + assert!(mem::align_of::() <= mem::align_of::()); + + #[repr(C)] + struct InOrder(T, U); + + // The empty slice is static and contains a single `0` usize (for the + // length) that is 64-byte aligned, thus featuring the necessary + // trailing padding for elements with up to 64-byte alignment. + static EMPTY_SLICE: InOrder = InOrder(0, MaxAlign); + unsafe { &*(&EMPTY_SLICE as *const _ as *const List) } + } +} impl List { + /// Allocates a list from `arena` and copies the contents of `slice` into it. + /// + /// WARNING: the contents *must be unique*, such that no list with these + /// contents has been previously created. If not, operations such as `eq` + /// and `hash` might give incorrect results. + /// + /// Panics if `T` is `Drop`, or `T` is zero-sized, or the slice is empty + /// (because the empty list exists statically, and is available via + /// `empty()`). #[inline] pub(super) fn from_arena<'tcx>(arena: &'tcx Arena<'tcx>, slice: &[T]) -> &'tcx List { assert!(!mem::needs_drop::()); @@ -73,7 +91,7 @@ impl List { .cast::() .copy_from_nonoverlapping(slice.as_ptr(), slice.len()); - &mut *mem + &*mem } } @@ -107,11 +125,24 @@ impl> Encodable for &List { } } +impl PartialEq for List { + #[inline] + fn eq(&self, other: &List) -> bool { + // Pointer equality implies list equality (due to the unique contents + // assumption). + ptr::eq(self, other) + } +} + +impl Eq for List {} + impl Ord for List where T: Ord, { fn cmp(&self, other: &List) -> Ordering { + // Pointer equality implies list equality (due to the unique contents + // assumption), but the contents must be compared otherwise. if self == other { Ordering::Equal } else { <[T] as Ord>::cmp(&**self, &**other) } } } @@ -121,6 +152,8 @@ where T: PartialOrd, { fn partial_cmp(&self, other: &List) -> Option { + // Pointer equality implies list equality (due to the unique contents + // assumption), but the contents must be compared otherwise. if self == other { Some(Ordering::Equal) } else { @@ -129,17 +162,11 @@ where } } -impl PartialEq for List { - #[inline] - fn eq(&self, other: &List) -> bool { - ptr::eq(self, other) - } -} -impl Eq for List {} - impl Hash for List { #[inline] fn hash(&self, s: &mut H) { + // Pointer hashing is sufficient (due to the unique contents + // assumption). (self as *const List).hash(s) } } @@ -168,13 +195,24 @@ impl<'a, T: Copy> IntoIterator for &'a List { } } -impl List { - #[inline(always)] - pub fn empty<'a>() -> &'a List { - #[repr(align(64), C)] - struct EmptySlice([u8; 64]); - static EMPTY_SLICE: EmptySlice = EmptySlice([0; 64]); - assert!(mem::align_of::() <= 64); - unsafe { &*(&EMPTY_SLICE as *const _ as *const List) } +unsafe impl Sync for List {} + +unsafe impl<'a, T: 'a> rustc_data_structures::tagged_ptr::Pointer for &'a List { + const BITS: usize = std::mem::align_of::().trailing_zeros() as usize; + + #[inline] + fn into_usize(self) -> usize { + self as *const List as usize + } + + #[inline] + unsafe fn from_usize(ptr: usize) -> &'a List { + &*(ptr as *const List) + } + + unsafe fn with_ref R>(ptr: usize, f: F) -> R { + // `Self` is `&'a List` which impls `Copy`, so this is fine. + let ptr = Self::from_usize(ptr); + f(&ptr) } } diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 8e2e6eaee58ef..25beed1ecf9c7 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -306,7 +306,7 @@ impl<'a> Parser<'a> { } } - let expect = tokens_to_string(&expected[..]); + let expect = tokens_to_string(&expected); let actual = super::token_descr(&self.token); let (msg_exp, (label_sp, label_exp)) = if expected.len() > 1 { let short_expect = if expected.len() > 6 { @@ -909,7 +909,7 @@ impl<'a> Parser<'a> { // So far we have parsed `foo Parser<'a> { // Consume the fn call arguments. let modifiers = [(token::OpenDelim(token::Paren), 1), (token::CloseDelim(token::Paren), -1)]; - self.consume_tts(1, &modifiers[..]); + self.consume_tts(1, &modifiers); if self.token.kind == token::Eof { // Not entirely sure that what we consumed were fn arguments, rollback. diff --git a/compiler/rustc_query_impl/src/on_disk_cache.rs b/compiler/rustc_query_impl/src/on_disk_cache.rs index 552906aac31a7..c42decdccff35 100644 --- a/compiler/rustc_query_impl/src/on_disk_cache.rs +++ b/compiler/rustc_query_impl/src/on_disk_cache.rs @@ -158,7 +158,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> { // Wrap in a scope so we can borrow `data`. let footer: Footer = { - let mut decoder = opaque::Decoder::new(&data[..], start_pos); + let mut decoder = opaque::Decoder::new(&data, start_pos); // Decode the *position* of the footer, which can be found in the // last 8 bytes of the file. diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 87e8e57611765..5df8a4103b74f 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1735,7 +1735,7 @@ fn parse_native_lib_modifiers( ) -> (NativeLibKind, Option) { let mut verbatim = None; for modifier in modifiers.split(',') { - let (modifier, value) = match modifier.strip_prefix(&['+', '-'][..]) { + let (modifier, value) = match modifier.strip_prefix(&['+', '-']) { Some(m) => (m, modifier.starts_with('+')), None => early_error( error_format, @@ -2027,7 +2027,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { let unparsed_crate_types = matches.opt_strs("crate-type"); let crate_types = parse_crate_types_from_list(unparsed_crate_types) - .unwrap_or_else(|e| early_error(error_format, &e[..])); + .unwrap_or_else(|e| early_error(error_format, &e)); let mut debugging_opts = DebuggingOptions::build(matches, error_format); let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format); @@ -2151,7 +2151,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { let mut search_paths = vec![]; for s in &matches.opt_strs("L") { - search_paths.push(SearchPath::from_cli_opt(&s[..], error_format)); + search_paths.push(SearchPath::from_cli_opt(&s, error_format)); } let libs = parse_libs(matches, error_format); diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index ea3d3363b8065..2934368dfeb89 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -1383,7 +1383,7 @@ impl Encodable for SourceFile { // Encode the first element. lines[0].encode(s)?; - let diff_iter = lines[..].array_windows().map(|&[fst, snd]| snd - fst); + let diff_iter = lines.array_windows().map(|&[fst, snd]| snd - fst); match bytes_per_diff { 1 => { @@ -1506,7 +1506,7 @@ impl SourceFile { assert!(end_pos <= u32::MAX as usize); let (lines, multibyte_chars, non_narrow_chars) = - analyze_source_file::analyze_source_file(&src[..], start_pos); + analyze_source_file::analyze_source_file(&src, start_pos); SourceFile { name, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs index 6128c119b6b76..d9a5aea4d95fc 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs @@ -231,7 +231,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { if let Ok(Some(command)) = OnUnimplementedDirective::of_item(self.tcx, trait_ref.def_id, def_id) { - command.evaluate(self.tcx, trait_ref, &flags[..]) + command.evaluate(self.tcx, trait_ref, &flags) } else { OnUnimplementedNote::default() } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 2e87d6fdd3dc2..d0b61b2430862 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -804,7 +804,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } else if let ObligationCauseCode::BindingObligation(_, _) | ObligationCauseCode::ItemObligation(_) = &*code { - try_borrowing(*poly_trait_ref, &never_suggest_borrow[..]) + try_borrowing(*poly_trait_ref, &never_suggest_borrow) } else { false } @@ -1132,7 +1132,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { "; let has_dyn = snippet.split_whitespace().next().map_or(false, |s| s == "dyn"); - let trait_obj = if has_dyn { &snippet[4..] } else { &snippet[..] }; + let trait_obj = if has_dyn { &snippet[4..] } else { &snippet }; if only_never_return { // No return paths, probably using `panic!()` or similar. // Suggest `-> T`, `-> impl Trait`, and if `Trait` is object safe, `-> Box`. diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 08261fedd4a25..427268d6d63f7 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -1350,7 +1350,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { tcx, span, item.trait_ref().def_id(), - &object_safety_violations[..], + &object_safety_violations, ) .emit(); return tcx.ty_error(); diff --git a/compiler/rustc_typeck/src/check/callee.rs b/compiler/rustc_typeck/src/check/callee.rs index 635ed93819319..e67ee1cab3df2 100644 --- a/compiler/rustc_typeck/src/check/callee.rs +++ b/compiler/rustc_typeck/src/check/callee.rs @@ -496,7 +496,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { call_expr.span, call_expr, fn_sig.inputs(), - &expected_arg_tys[..], + &expected_arg_tys, arg_exprs, fn_sig.c_variadic, TupleArgumentsFlag::DontTupleArguments, diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index a02a7d7cbfeb2..e82ff9cf2dd88 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -1436,7 +1436,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { >::create_substs_for_generic_args( tcx, def_id, - &[][..], + &[], has_self, self_ty, &arg_count, diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 74d7f0a80b6ca..4cb597cb6d6c7 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -54,13 +54,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let err_inputs = match tuple_arguments { DontTupleArguments => err_inputs, - TupleArguments => vec![self.tcx.intern_tup(&err_inputs[..])], + TupleArguments => vec![self.tcx.intern_tup(&err_inputs)], }; self.check_argument_types( sp, expr, - &err_inputs[..], + &err_inputs, &[], args_no_rcvr, false, @@ -324,7 +324,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.point_at_type_arg_instead_of_call_if_possible(errors, expr); self.point_at_arg_instead_of_call_if_possible( errors, - &final_arg_types[..], + &final_arg_types, expr, sp, &args, diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index 9fd7e8c4daa20..9ccf354db736f 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -1372,7 +1372,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { if applicable_candidates.len() > 1 { if let Some(pick) = - self.collapse_candidates_to_trait_pick(self_ty, &applicable_candidates[..]) + self.collapse_candidates_to_trait_pick(self_ty, &applicable_candidates) { return Some(Ok(pick)); } diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index ad38885dbd8bd..e9ec0674cb795 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -1344,7 +1344,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if candidates.len() > limit { msg.push_str(&format!("\nand {} others", candidates.len() - limit)); } - err.note(&msg[..]); + err.note(&msg); } } diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 67a3053c60786..fda96e49eb967 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -2998,9 +2998,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { ) .emit(); InlineAttr::None - } else if list_contains_name(&items[..], sym::always) { + } else if list_contains_name(&items, sym::always) { InlineAttr::Always - } else if list_contains_name(&items[..], sym::never) { + } else if list_contains_name(&items, sym::never) { InlineAttr::Never } else { struct_span_err!( @@ -3034,9 +3034,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { if items.len() != 1 { err(attr.span, "expected one argument"); OptimizeAttr::None - } else if list_contains_name(&items[..], sym::size) { + } else if list_contains_name(&items, sym::size) { OptimizeAttr::Size - } else if list_contains_name(&items[..], sym::speed) { + } else if list_contains_name(&items, sym::speed) { OptimizeAttr::Speed } else { err(items[0].span(), "invalid argument"); diff --git a/library/core/src/hint.rs b/library/core/src/hint.rs index 95798879155c5..f49aefea81bac 100644 --- a/library/core/src/hint.rs +++ b/library/core/src/hint.rs @@ -137,6 +137,11 @@ pub fn spin_loop() { unsafe { crate::arch::arm::__yield() }; } } + + #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] + { + crate::arch::riscv::pause(); + } } /// An identity function that *__hints__* to the compiler to be maximally pessimistic about what diff --git a/library/stdarch b/library/stdarch index cfba59fccd90b..b70ae88ef2a6c 160000 --- a/library/stdarch +++ b/library/stdarch @@ -1 +1 @@ -Subproject commit cfba59fccd90b3b52a614120834320f764ab08d1 +Subproject commit b70ae88ef2a6c83acad0a1e83d5bd78f9655fd05 diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 1691de93bdda2..9943e23b9281c 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -976,6 +976,7 @@ fn item_typedef( // associated items from the aliased type (see discussion in #32077), but // we need #14072 to make sense of the generics. render_assoc_items(w, cx, it, def_id, AssocItemRender::All); + document_type_layout(w, cx, def_id); } fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Union) { diff --git a/src/test/rustdoc/type-layout.rs b/src/test/rustdoc/type-layout.rs index 0868486fa59cd..4eea9809ac58f 100644 --- a/src/test/rustdoc/type-layout.rs +++ b/src/test/rustdoc/type-layout.rs @@ -50,6 +50,18 @@ pub struct GenericLifetimes<'a>(&'a str); // @has - '(unsized)' pub struct Unsized([u8]); +// @has type_layout/type.TypeAlias.html 'Size: ' +// @has - ' bytes' +pub type TypeAlias = X; + +// @has type_layout/type.GenericTypeAlias.html 'Size: ' +// @has - '8 bytes' +pub type GenericTypeAlias = (Generic<(u32, ())>, Generic); + +// Regression test for the rustdoc equivalent of #85103. +// @has type_layout/type.Edges.html 'Encountered an error during type layout; the type failed to be normalized.' +pub type Edges<'a, E> = std::borrow::Cow<'a, [E]>; + // @!has type_layout/trait.MyTrait.html 'Size: ' pub trait MyTrait {} diff --git a/src/test/ui/const-generics/issues/issue-79674.rs b/src/test/ui/const-generics/issues/issue-79674.rs new file mode 100644 index 0000000000000..2f196533dd88c --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-79674.rs @@ -0,0 +1,28 @@ +#![feature(const_fn_trait_bound, generic_const_exprs)] +#![allow(incomplete_features)] + +trait MiniTypeId { + const TYPE_ID: u64; +} + +impl MiniTypeId for T { + const TYPE_ID: u64 = 0; +} + +enum Lift {} + +trait IsFalse {} +impl IsFalse for Lift {} + +const fn is_same_type() -> bool { + T::TYPE_ID == U::TYPE_ID +} + +fn requires_distinct(_a: A, _b: B) where + A: MiniTypeId, B: MiniTypeId, + Lift<{is_same_type::()}>: IsFalse {} + +fn main() { + requires_distinct("str", 12); + //~^ ERROR mismatched types +} diff --git a/src/test/ui/const-generics/issues/issue-79674.stderr b/src/test/ui/const-generics/issues/issue-79674.stderr new file mode 100644 index 0000000000000..8c029289cbb0d --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-79674.stderr @@ -0,0 +1,12 @@ +error[E0308]: mismatched types + --> $DIR/issue-79674.rs:26:5 + | +LL | requires_distinct("str", 12); + | ^^^^^^^^^^^^^^^^^ expected `true`, found `false` + | + = note: expected type `true` + found type `false` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/issues/issue-83765.rs b/src/test/ui/const-generics/issues/issue-83765.rs new file mode 100644 index 0000000000000..68536348d3884 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-83765.rs @@ -0,0 +1,115 @@ +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +trait TensorDimension { + const DIM : usize; + const ISSCALAR : bool = Self::DIM == 0; + fn is_scalar(&self) -> bool {Self::ISSCALAR} +} + +trait TensorSize : TensorDimension { + fn size(&self) -> [usize;Self::DIM]; + fn inbounds(&self,index : [usize;Self::DIM]) -> bool { + index.iter().zip(self.size().iter()).all(|(i,s)| i < s) + } +} + + +trait Broadcastable: TensorSize + Sized { + type Element; + fn bget(&self, index:[usize;Self::DIM]) -> Option; + fn lazy_updim(&self, size : [usize;NEWDIM] ) -> + LazyUpdim + { + assert!(NEWDIM >= Self::DIM, + "Updimmed tensor cannot have fewer indices than the initial one."); + LazyUpdim {size,reference:&self} + } + fn bmap T>(&self,foo : F) -> BMap{ + BMap {reference:self,closure : foo} + } +} + + +struct LazyUpdim<'a,T : Broadcastable,const OLDDIM : usize, const DIM : usize> { + size : [usize;DIM], + reference : &'a T +} + +impl<'a,T : Broadcastable,const DIM : usize> TensorDimension for LazyUpdim<'a,T,{T::DIM},DIM> { + const DIM : usize = DIM; +} + +impl<'a,T : Broadcastable,const DIM : usize> TensorSize for LazyUpdim<'a,T,{T::DIM},DIM> { + fn size(&self) -> [usize;DIM] {self.size} + //~^ ERROR method not compatible with trait +} + +impl<'a,T : Broadcastable,const DIM : usize> Broadcastable for LazyUpdim<'a,T,{T::DIM},DIM> +{ + type Element = T::Element; + fn bget(&self,index:[usize;DIM]) -> Option { + //~^ ERROR method not compatible with trait + assert!(DIM >= T::DIM); + if !self.inbounds(index) {return None} + //~^ ERROR unconstrained generic constant + //~| ERROR mismatched types + let size = self.size(); + //~^ ERROR unconstrained generic constant + let newindex : [usize;T::DIM] = Default::default(); + //~^ ERROR the trait bound `[usize; _]: Default` is not satisfied + self.reference.bget(newindex) + } +} + +struct BMap<'a,R, T : Broadcastable, F : Fn(T::Element) -> R , const DIM: usize> { + reference : &'a T, + closure : F +} + +impl<'a,R, T : Broadcastable, F : Fn(T::Element) -> R, + const DIM: usize> TensorDimension for BMap<'a,R,T,F,DIM> { + + const DIM : usize = DIM; +} +impl<'a,R, T : Broadcastable, F : Fn(T::Element) -> R , + const DIM: usize> TensorSize for BMap<'a,R,T,F,DIM> { + + fn size(&self) -> [usize;DIM] {self.reference.size()} + //~^ ERROR unconstrained generic constant + //~| ERROR mismatched types + //~| ERROR method not compatible with trait +} + +impl<'a,R, T : Broadcastable, F : Fn(T::Element) -> R , + const DIM: usize> Broadcastable for BMap<'a,R,T,F,DIM> { + + type Element = R; + fn bget(&self,index:[usize;DIM]) -> Option { + //~^ ERROR method not compatible with trait + self.reference.bget(index).map(&self.closure) + //~^ ERROR unconstrained generic constant + //~| ERROR mismatched types + } +} + +impl TensorDimension for Vec { + const DIM : usize = 1; +} +impl TensorSize for Vec { + fn size(&self) -> [usize;1] {[self.len()]} +} +impl Broadcastable for Vec { + type Element = T; + fn bget(& self,index : [usize;1]) -> Option { + self.get(index[0]).cloned() + } +} + +fn main() { + let v = vec![1,2,3]; + let bv = v.lazy_updim([3,4]); + let bbv = bv.bmap(|x| x*x); + + println!("The size of v is {:?}",bbv.bget([0,2]).expect("Out of bounds.")); +} diff --git a/src/test/ui/const-generics/issues/issue-83765.stderr b/src/test/ui/const-generics/issues/issue-83765.stderr new file mode 100644 index 0000000000000..a49f850717f8a --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-83765.stderr @@ -0,0 +1,130 @@ +error[E0308]: method not compatible with trait + --> $DIR/issue-83765.rs:44:5 + | +LL | fn size(&self) -> [usize;DIM] {self.size} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM` + | + = note: expected type `Self::DIM` + found type `DIM` + +error[E0308]: method not compatible with trait + --> $DIR/issue-83765.rs:51:5 + | +LL | fn bget(&self,index:[usize;DIM]) -> Option { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM` + | + = note: expected type `Self::DIM` + found type `DIM` + +error[E0308]: method not compatible with trait + --> $DIR/issue-83765.rs:78:5 + | +LL | fn size(&self) -> [usize;DIM] {self.reference.size()} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM` + | + = note: expected type `Self::DIM` + found type `DIM` + +error[E0308]: method not compatible with trait + --> $DIR/issue-83765.rs:88:5 + | +LL | fn bget(&self,index:[usize;DIM]) -> Option { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM` + | + = note: expected type `Self::DIM` + found type `DIM` + +error: unconstrained generic constant + --> $DIR/issue-83765.rs:54:18 + | +LL | if !self.inbounds(index) {return None} + | ^^^^^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); Self::DIM]:` +note: required by a bound in `TensorSize::inbounds` + --> $DIR/issue-83765.rs:12:38 + | +LL | fn inbounds(&self,index : [usize;Self::DIM]) -> bool { + | ^^^^^^^^^ required by this bound in `TensorSize::inbounds` + +error[E0308]: mismatched types + --> $DIR/issue-83765.rs:54:27 + | +LL | if !self.inbounds(index) {return None} + | ^^^^^ expected `Self::DIM`, found `DIM` + | + = note: expected type `Self::DIM` + found type `DIM` + +error: unconstrained generic constant + --> $DIR/issue-83765.rs:57:25 + | +LL | let size = self.size(); + | ^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); Self::DIM]:` +note: required by a bound in `TensorSize::size` + --> $DIR/issue-83765.rs:11:30 + | +LL | fn size(&self) -> [usize;Self::DIM]; + | ^^^^^^^^^ required by this bound in `TensorSize::size` + +error[E0277]: the trait bound `[usize; _]: Default` is not satisfied + --> $DIR/issue-83765.rs:59:41 + | +LL | let newindex : [usize;T::DIM] = Default::default(); + | ^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `[usize; _]` + | +help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement + | +LL | impl<'a,T : Broadcastable,const DIM : usize> Broadcastable for LazyUpdim<'a,T,{T::DIM},DIM> where [usize; _]: Default + | +++++++++++++++++++++++++ + +error: unconstrained generic constant + --> $DIR/issue-83765.rs:78:51 + | +LL | fn size(&self) -> [usize;DIM] {self.reference.size()} + | ^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); Self::DIM]:` +note: required by a bound in `TensorSize::size` + --> $DIR/issue-83765.rs:11:30 + | +LL | fn size(&self) -> [usize;Self::DIM]; + | ^^^^^^^^^ required by this bound in `TensorSize::size` + +error[E0308]: mismatched types + --> $DIR/issue-83765.rs:78:36 + | +LL | fn size(&self) -> [usize;DIM] {self.reference.size()} + | ^^^^^^^^^^^^^^^^^^^^^ expected `DIM`, found `Self::DIM` + | + = note: expected type `DIM` + found type `Self::DIM` + +error: unconstrained generic constant + --> $DIR/issue-83765.rs:90:24 + | +LL | self.reference.bget(index).map(&self.closure) + | ^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); Self::DIM]:` +note: required by a bound in `Broadcastable::bget` + --> $DIR/issue-83765.rs:20:33 + | +LL | fn bget(&self, index:[usize;Self::DIM]) -> Option; + | ^^^^^^^^^ required by this bound in `Broadcastable::bget` + +error[E0308]: mismatched types + --> $DIR/issue-83765.rs:90:29 + | +LL | self.reference.bget(index).map(&self.closure) + | ^^^^^ expected `Self::DIM`, found `DIM` + | + = note: expected type `Self::DIM` + found type `DIM` + +error: aborting due to 12 previous errors + +Some errors have detailed explanations: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/const-generics/issues/issue-86033.rs b/src/test/ui/const-generics/issues/issue-86033.rs new file mode 100644 index 0000000000000..cf08f722fbb80 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-86033.rs @@ -0,0 +1,20 @@ +// check-pass + +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +pub trait IsTrue {} +impl IsTrue for () {} + +pub trait IsZST {} + +impl IsZST for T +where + (): IsTrue<{ std::mem::size_of::() == 0 }> +{} + +fn _func() -> impl IsZST { + || {} +} + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-88468.rs b/src/test/ui/const-generics/issues/issue-88468.rs new file mode 100644 index 0000000000000..914047236ab5d --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-88468.rs @@ -0,0 +1,13 @@ +// check-pass + +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] + +pub struct Assert(); +pub trait IsTrue {} +impl IsTrue for Assert {} + +pub trait IsNotZST {} +impl IsNotZST for T where Assert<{ std::mem::size_of::() > 0 }>: IsTrue {} + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-90318.rs b/src/test/ui/const-generics/issues/issue-90318.rs new file mode 100644 index 0000000000000..0c640a5ef7136 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-90318.rs @@ -0,0 +1,32 @@ +#![feature(const_type_id)] +#![feature(generic_const_exprs)] +#![feature(core_intrinsics)] +#![allow(incomplete_features)] + +use std::any::TypeId; + +struct If; +pub trait True {} +impl True for If {} + +fn consume(_val: T) +where + If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + //~^ ERROR: overly complex generic constant + //~| ERROR: calls in constants are limited to constant functions +{ +} + +fn test() +where + If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + //~^ ERROR: overly complex generic constant + //~| ERROR: calls in constants are limited to constant functions +{ +} + +fn main() { + let a = (); + consume(0i32); + consume(a); +} diff --git a/src/test/ui/const-generics/issues/issue-90318.stderr b/src/test/ui/const-generics/issues/issue-90318.stderr new file mode 100644 index 0000000000000..2b8afe2ef09ed --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-90318.stderr @@ -0,0 +1,37 @@ +error: overly complex generic constant + --> $DIR/issue-90318.rs:14:8 + | +LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + | ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | borrowing is not supported in generic constants + | + = help: consider moving this anonymous constant into a `const` function + = note: this operation may be supported in the future + +error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants + --> $DIR/issue-90318.rs:14:10 + | +LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: overly complex generic constant + --> $DIR/issue-90318.rs:22:8 + | +LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + | ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | borrowing is not supported in generic constants + | + = help: consider moving this anonymous constant into a `const` function + = note: this operation may be supported in the future + +error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants + --> $DIR/issue-90318.rs:22:10 + | +LL | If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0015`.