From 6edd86d58e5f8f35de441c3b461d1b1f5e818e1c Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 11 Sep 2024 12:07:24 +0100 Subject: [PATCH 01/16] tests: add test for #105111 Enabling a tied feature should not enable the other feature automatically. This was fixed by something in #128796, probably #128221 or #128679. --- ...tied-features-no-implication-1.paca.stderr | 4 +++ ...tied-features-no-implication-1.pacg.stderr | 4 +++ .../tied-features-no-implication-1.rs | 20 +++++++++++++ .../tied-features-no-implication.paca.stderr | 4 +++ .../tied-features-no-implication.pacg.stderr | 14 +++++++++ .../tied-features-no-implication.rs | 29 +++++++++++++++++++ 6 files changed, 75 insertions(+) create mode 100644 tests/ui/target-feature/tied-features-no-implication-1.paca.stderr create mode 100644 tests/ui/target-feature/tied-features-no-implication-1.pacg.stderr create mode 100644 tests/ui/target-feature/tied-features-no-implication-1.rs create mode 100644 tests/ui/target-feature/tied-features-no-implication.paca.stderr create mode 100644 tests/ui/target-feature/tied-features-no-implication.pacg.stderr create mode 100644 tests/ui/target-feature/tied-features-no-implication.rs diff --git a/tests/ui/target-feature/tied-features-no-implication-1.paca.stderr b/tests/ui/target-feature/tied-features-no-implication-1.paca.stderr new file mode 100644 index 0000000000000..bf211fbee2f3a --- /dev/null +++ b/tests/ui/target-feature/tied-features-no-implication-1.paca.stderr @@ -0,0 +1,4 @@ +error: the target features paca, pacg must all be either enabled or disabled together + +error: aborting due to 1 previous error + diff --git a/tests/ui/target-feature/tied-features-no-implication-1.pacg.stderr b/tests/ui/target-feature/tied-features-no-implication-1.pacg.stderr new file mode 100644 index 0000000000000..bf211fbee2f3a --- /dev/null +++ b/tests/ui/target-feature/tied-features-no-implication-1.pacg.stderr @@ -0,0 +1,4 @@ +error: the target features paca, pacg must all be either enabled or disabled together + +error: aborting due to 1 previous error + diff --git a/tests/ui/target-feature/tied-features-no-implication-1.rs b/tests/ui/target-feature/tied-features-no-implication-1.rs new file mode 100644 index 0000000000000..0473ca319b8f0 --- /dev/null +++ b/tests/ui/target-feature/tied-features-no-implication-1.rs @@ -0,0 +1,20 @@ +//@ revisions: paca pacg +//@ compile-flags: --crate-type=rlib --target=aarch64-unknown-linux-gnu +//@ needs-llvm-components: aarch64 +//@[paca] compile-flags: -Ctarget-feature=+paca +//@[paca] error-pattern: the target features paca, pacg must all be either enabled or disabled together +//@[pacg] compile-flags: -Ctarget-feature=+pacg +//@[paca] error-pattern: the target features paca, pacg must all be either enabled or disabled together +#![feature(no_core, lang_items)] +#![no_core] + +#[lang="sized"] +trait Sized {} + +// In this test, demonstrate that +paca and +pacg both result in the tied feature error if there +// isn't something causing an error. +// See tied-features-no-implication.rs + +#[cfg(target_feature = "pacg")] +pub unsafe fn foo() { +} diff --git a/tests/ui/target-feature/tied-features-no-implication.paca.stderr b/tests/ui/target-feature/tied-features-no-implication.paca.stderr new file mode 100644 index 0000000000000..bf211fbee2f3a --- /dev/null +++ b/tests/ui/target-feature/tied-features-no-implication.paca.stderr @@ -0,0 +1,4 @@ +error: the target features paca, pacg must all be either enabled or disabled together + +error: aborting due to 1 previous error + diff --git a/tests/ui/target-feature/tied-features-no-implication.pacg.stderr b/tests/ui/target-feature/tied-features-no-implication.pacg.stderr new file mode 100644 index 0000000000000..0e31dea24ea4d --- /dev/null +++ b/tests/ui/target-feature/tied-features-no-implication.pacg.stderr @@ -0,0 +1,14 @@ +error[E0428]: the name `foo` is defined multiple times + --> $DIR/tied-features-no-implication.rs:28:1 + | +LL | fn foo() {} + | -------- previous definition of the value `foo` here +... +LL | pub unsafe fn foo() { + | ^^^^^^^^^^^^^^^^^^^ `foo` redefined here + | + = note: `foo` must be defined only once in the value namespace of this module + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0428`. diff --git a/tests/ui/target-feature/tied-features-no-implication.rs b/tests/ui/target-feature/tied-features-no-implication.rs new file mode 100644 index 0000000000000..157b50bb0d329 --- /dev/null +++ b/tests/ui/target-feature/tied-features-no-implication.rs @@ -0,0 +1,29 @@ +//@ revisions: paca pacg +//@ compile-flags: --crate-type=rlib --target=aarch64-unknown-linux-gnu +//@ needs-llvm-components: aarch64 +//@[paca] compile-flags: -Ctarget-feature=+paca +//@[paca] error-pattern: the target features paca, pacg must all be either enabled or disabled together +//@[pacg] compile-flags: -Ctarget-feature=+pacg +//@[pacg] error-pattern: the name `foo` is defined multiple times +#![feature(no_core, lang_items)] +#![no_core] + +#[lang="sized"] +trait Sized {} + +// Can't use `compile_error!` here without `core`/`std` but requiring these makes this test only +// work if you have libcore built in the sysroot for `aarch64-unknown-linux-gnu`. Can't run this +// test on any aarch64 platform because they all have different default available features - as +// written, this test depends on `aarch64-unknown-linux-gnu` having -paca,-pacg by default. +// Cause a multiple definition error instead. +fn foo() {} + +// Enabling one of the tied features does not imply the other is enabled. +// +// With +paca, this multiple definition doesn't cause an error because +paca hasn't implied +// +pacg. With +pacg, the multiple definition error is emitted (and the tied feature error would +// be). + +#[cfg(target_feature = "pacg")] +pub unsafe fn foo() { +} From 207bc77e15acc9444bf6c3e74fa46607490a8e8a Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 11 Sep 2024 13:57:12 +0100 Subject: [PATCH 02/16] codegen_ssa: consolidate tied feature checking `rustc_codegen_llvm` and `rustc_codegen_gcc` duplicated logic for checking if tied target features were partially enabled. This commit consolidates these checks into `rustc_codegen_ssa` in the `codegen_fn_attrs` query, which also is run pre-monomorphisation for each function, which ensures that this check is run for unused functions, as would be expected. --- compiler/rustc_codegen_gcc/messages.ftl | 3 -- compiler/rustc_codegen_gcc/src/attributes.rs | 22 +-------- compiler/rustc_codegen_gcc/src/errors.rs | 36 --------------- compiler/rustc_codegen_gcc/src/gcc_util.rs | 24 ++-------- compiler/rustc_codegen_llvm/messages.ftl | 6 --- compiler/rustc_codegen_llvm/src/attributes.rs | 23 +--------- compiler/rustc_codegen_llvm/src/errors.rs | 24 ---------- compiler/rustc_codegen_llvm/src/llvm_util.rs | 26 ++--------- compiler/rustc_codegen_ssa/messages.ftl | 5 +++ .../rustc_codegen_ssa/src/codegen_attrs.rs | 45 ++++++++++++++++++- compiler/rustc_codegen_ssa/src/errors.rs | 26 ++++++++++- tests/ui/target-feature/tied-features.rs | 9 ++-- tests/ui/target-feature/tied-features.stderr | 14 ++++-- 13 files changed, 100 insertions(+), 163 deletions(-) diff --git a/compiler/rustc_codegen_gcc/messages.ftl b/compiler/rustc_codegen_gcc/messages.ftl index 0235384445e71..bbae59ea7a55a 100644 --- a/compiler/rustc_codegen_gcc/messages.ftl +++ b/compiler/rustc_codegen_gcc/messages.ftl @@ -8,9 +8,6 @@ codegen_gcc_invalid_minimum_alignment = codegen_gcc_lto_not_supported = LTO is not supported. You may get a linker error. -codegen_gcc_tied_target_features = the target features {$features} must all be either enabled or disabled together - .help = add the missing features in a `target_feature` attribute - codegen_gcc_unwinding_inline_asm = GCC backend does not support unwinding from inline asm diff --git a/compiler/rustc_codegen_gcc/src/attributes.rs b/compiler/rustc_codegen_gcc/src/attributes.rs index 5fdf2680aac88..d20e13e15b944 100644 --- a/compiler/rustc_codegen_gcc/src/attributes.rs +++ b/compiler/rustc_codegen_gcc/src/attributes.rs @@ -7,11 +7,9 @@ use rustc_attr::InstructionSetAttr; #[cfg(feature = "master")] use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::ty; -use rustc_span::symbol::sym; use crate::context::CodegenCx; -use crate::errors::TiedTargetFeatures; -use crate::gcc_util::{check_tied_features, to_gcc_features}; +use crate::gcc_util::to_gcc_features; /// Get GCC attribute for the provided inline heuristic. #[cfg(feature = "master")] @@ -72,26 +70,10 @@ pub fn from_fn_attrs<'gcc, 'tcx>( } } - let function_features = codegen_fn_attrs + let mut function_features = codegen_fn_attrs .target_features .iter() .map(|features| features.name.as_str()) - .collect::>(); - - if let Some(features) = check_tied_features( - cx.tcx.sess, - &function_features.iter().map(|features| (*features, true)).collect(), - ) { - let span = cx - .tcx - .get_attr(instance.def_id(), sym::target_feature) - .map_or_else(|| cx.tcx.def_span(instance.def_id()), |a| a.span); - cx.tcx.dcx().create_err(TiedTargetFeatures { features: features.join(", "), span }).emit(); - return; - } - - let mut function_features = function_features - .iter() .flat_map(|feat| to_gcc_features(cx.tcx.sess, feat).into_iter()) .chain(codegen_fn_attrs.instruction_set.iter().map(|x| match *x { InstructionSetAttr::ArmA32 => "-thumb-mode", // TODO(antoyo): support removing feature. diff --git a/compiler/rustc_codegen_gcc/src/errors.rs b/compiler/rustc_codegen_gcc/src/errors.rs index 6bada3d334ce4..dc1895f437b52 100644 --- a/compiler/rustc_codegen_gcc/src/errors.rs +++ b/compiler/rustc_codegen_gcc/src/errors.rs @@ -1,9 +1,6 @@ -use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level}; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::Span; -use crate::fluent_generated as fluent; - #[derive(Diagnostic)] #[diag(codegen_gcc_unknown_ctarget_feature_prefix)] #[note] @@ -45,15 +42,6 @@ pub(crate) struct InvalidMinimumAlignment { pub err: String, } -#[derive(Diagnostic)] -#[diag(codegen_gcc_tied_target_features)] -#[help] -pub(crate) struct TiedTargetFeatures { - #[primary_span] - pub span: Span, - pub features: String, -} - #[derive(Diagnostic)] #[diag(codegen_gcc_copy_bitcode)] pub(crate) struct CopyBitcode { @@ -78,27 +66,3 @@ pub(crate) struct LtoDylib; pub(crate) struct LtoBitcodeFromRlib { pub gcc_err: String, } - -pub(crate) struct TargetFeatureDisableOrEnable<'a> { - pub features: &'a [&'a str], - pub span: Option, - pub missing_features: Option, -} - -#[derive(Subdiagnostic)] -#[help(codegen_gcc_missing_features)] -pub(crate) struct MissingFeatures; - -impl Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> { - fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> { - let mut diag = Diag::new(dcx, level, fluent::codegen_gcc_target_feature_disable_or_enable); - if let Some(span) = self.span { - diag.span(span); - }; - if let Some(missing_features) = self.missing_features { - diag.subdiagnostic(missing_features); - } - diag.arg("features", self.features.join(", ")); - diag - } -} diff --git a/compiler/rustc_codegen_gcc/src/gcc_util.rs b/compiler/rustc_codegen_gcc/src/gcc_util.rs index 01dd1a8856aab..3104088e0d5e9 100644 --- a/compiler/rustc_codegen_gcc/src/gcc_util.rs +++ b/compiler/rustc_codegen_gcc/src/gcc_util.rs @@ -1,15 +1,14 @@ #[cfg(feature = "master")] use gccjit::Context; +use rustc_codegen_ssa::codegen_attrs::check_tied_features; +use rustc_codegen_ssa::errors::TargetFeatureDisableOrEnable; use rustc_data_structures::fx::FxHashMap; use rustc_middle::bug; use rustc_session::Session; use rustc_target::target_features::RUSTC_SPECIFIC_FEATURES; use smallvec::{SmallVec, smallvec}; -use crate::errors::{ - PossibleFeature, TargetFeatureDisableOrEnable, UnknownCTargetFeature, - UnknownCTargetFeaturePrefix, -}; +use crate::errors::{PossibleFeature, UnknownCTargetFeature, UnknownCTargetFeaturePrefix}; /// The list of GCC features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`, /// `--target` and similar). @@ -185,23 +184,6 @@ pub fn to_gcc_features<'a>(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2]> } } -// Given a map from target_features to whether they are enabled or disabled, -// ensure only valid combinations are allowed. -pub fn check_tied_features( - sess: &Session, - features: &FxHashMap<&str, bool>, -) -> Option<&'static [&'static str]> { - for tied in sess.target.tied_target_features() { - // Tied features must be set to the same value, or not set at all - let mut tied_iter = tied.iter(); - let enabled = features.get(tied_iter.next().unwrap()); - if tied_iter.any(|feature| enabled != features.get(feature)) { - return Some(tied); - } - } - None -} - fn arch_to_gcc(name: &str) -> &str { match name { "M68020" => "68020", diff --git a/compiler/rustc_codegen_llvm/messages.ftl b/compiler/rustc_codegen_llvm/messages.ftl index df2198df14b6a..0950e4bb26bac 100644 --- a/compiler/rustc_codegen_llvm/messages.ftl +++ b/compiler/rustc_codegen_llvm/messages.ftl @@ -33,9 +33,6 @@ codegen_llvm_lto_proc_macro = lto cannot be used for `proc-macro` crate type wit codegen_llvm_mismatch_data_layout = data-layout for target `{$rustc_target}`, `{$rustc_layout}`, differs from LLVM target's `{$llvm_target}` default layout, `{$llvm_layout}` -codegen_llvm_missing_features = - add the missing features in a `target_feature` attribute - codegen_llvm_multiple_source_dicompileunit = multiple source DICompileUnits found codegen_llvm_multiple_source_dicompileunit_with_llvm_err = multiple source DICompileUnits found: {$llvm_err} @@ -63,9 +60,6 @@ codegen_llvm_serialize_module_with_llvm_err = failed to serialize module {$name} codegen_llvm_symbol_already_defined = symbol `{$symbol_name}` is already defined -codegen_llvm_target_feature_disable_or_enable = - the target features {$features} must all be either enabled or disabled together - codegen_llvm_target_machine = could not create LLVM TargetMachine for triple: {$triple} codegen_llvm_target_machine_with_llvm_err = could not create LLVM TargetMachine for triple: {$triple}: {$llvm_err} diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 489259da85646..2c5ec9dad59f1 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -6,12 +6,11 @@ use rustc_hir::def_id::DefId; use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, PatchableFunctionEntry}; use rustc_middle::ty::{self, TyCtxt}; use rustc_session::config::{BranchProtection, FunctionReturn, OptLevel, PAuthKey, PacRet}; -use rustc_span::symbol::sym; use rustc_target::spec::{FramePointer, SanitizerSet, StackProbeType, StackProtector}; use smallvec::SmallVec; use crate::context::CodegenCx; -use crate::errors::{MissingFeatures, SanitizerMemtagRequiresMte, TargetFeatureDisableOrEnable}; +use crate::errors::SanitizerMemtagRequiresMte; use crate::llvm::AttributePlace::Function; use crate::llvm::{self, AllocKindFlags, Attribute, AttributeKind, AttributePlace, MemoryEffects}; use crate::value::Value; @@ -502,26 +501,6 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>( let function_features = codegen_fn_attrs.target_features.iter().map(|f| f.name.as_str()).collect::>(); - if let Some(f) = llvm_util::check_tied_features( - cx.tcx.sess, - &function_features.iter().map(|f| (*f, true)).collect(), - ) { - let span = cx - .tcx - .get_attrs(instance.def_id(), sym::target_feature) - .next() - .map_or_else(|| cx.tcx.def_span(instance.def_id()), |a| a.span); - cx.tcx - .dcx() - .create_err(TargetFeatureDisableOrEnable { - features: f, - span: Some(span), - missing_features: Some(MissingFeatures), - }) - .emit(); - return; - } - let function_features = function_features .iter() // Convert to LLVMFeatures and filter out unavailable ones diff --git a/compiler/rustc_codegen_llvm/src/errors.rs b/compiler/rustc_codegen_llvm/src/errors.rs index bb481d2a30856..0d436e1891ece 100644 --- a/compiler/rustc_codegen_llvm/src/errors.rs +++ b/compiler/rustc_codegen_llvm/src/errors.rs @@ -80,30 +80,6 @@ impl Diagnostic<'_, G> for ParseTargetMachineConfig<'_> { } } -pub(crate) struct TargetFeatureDisableOrEnable<'a> { - pub features: &'a [&'a str], - pub span: Option, - pub missing_features: Option, -} - -#[derive(Subdiagnostic)] -#[help(codegen_llvm_missing_features)] -pub(crate) struct MissingFeatures; - -impl Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> { - fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> { - let mut diag = Diag::new(dcx, level, fluent::codegen_llvm_target_feature_disable_or_enable); - if let Some(span) = self.span { - diag.span(span); - }; - if let Some(missing_features) = self.missing_features { - diag.subdiagnostic(missing_features); - } - diag.arg("features", self.features.join(", ")); - diag - } -} - #[derive(Diagnostic)] #[diag(codegen_llvm_lto_disallowed)] pub(crate) struct LtoDisallowed; diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 71fd7afb148c4..79820ee0cdb8e 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -6,6 +6,7 @@ use std::{ptr, slice, str}; use libc::c_int; use rustc_codegen_ssa::base::wants_wasm_eh; +use rustc_codegen_ssa::codegen_attrs::check_tied_features; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::small_c_str::SmallCStr; use rustc_data_structures::unord::UnordSet; @@ -19,8 +20,8 @@ use rustc_target::target_features::{RUSTC_SPECIAL_FEATURES, RUSTC_SPECIFIC_FEATU use crate::back::write::create_informational_target_machine; use crate::errors::{ - FixedX18InvalidArch, InvalidTargetFeaturePrefix, PossibleFeature, TargetFeatureDisableOrEnable, - UnknownCTargetFeature, UnknownCTargetFeaturePrefix, UnstableCTargetFeature, + FixedX18InvalidArch, InvalidTargetFeaturePrefix, PossibleFeature, UnknownCTargetFeature, + UnknownCTargetFeaturePrefix, UnstableCTargetFeature, }; use crate::llvm; @@ -272,25 +273,6 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option, -) -> Option<&'static [&'static str]> { - if !features.is_empty() { - for tied in sess.target.tied_target_features() { - // Tied features must be set to the same value, or not set at all - let mut tied_iter = tied.iter(); - let enabled = features.get(tied_iter.next().unwrap()); - if tied_iter.any(|f| enabled != features.get(f)) { - return Some(tied); - } - } - } - None -} - /// Used to generate cfg variables and apply features /// Must express features in the way Rust understands them pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec { @@ -676,7 +658,7 @@ pub(crate) fn global_llvm_features( features.extend(feats); if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) { - sess.dcx().emit_err(TargetFeatureDisableOrEnable { + sess.dcx().emit_err(rustc_codegen_ssa::errors::TargetFeatureDisableOrEnable { features: f, span: None, missing_features: None, diff --git a/compiler/rustc_codegen_ssa/messages.ftl b/compiler/rustc_codegen_ssa/messages.ftl index 9091602d75b71..cce5e8b1398d4 100644 --- a/compiler/rustc_codegen_ssa/messages.ftl +++ b/compiler/rustc_codegen_ssa/messages.ftl @@ -183,6 +183,8 @@ codegen_ssa_metadata_object_file_write = error writing metadata object file: {$e codegen_ssa_missing_cpp_build_tool_component = or a necessary component may be missing from the "C++ build tools" workload +codegen_ssa_missing_features = add the missing features in a `target_feature` attribute + codegen_ssa_missing_memory_ordering = Atomic intrinsic missing memory ordering codegen_ssa_missing_query_depgraph = @@ -238,6 +240,9 @@ codegen_ssa_stripping_debug_info_failed = stripping debug info with `{$util}` fa codegen_ssa_symbol_file_write_failure = failed to write symbols file: {$error} +codegen_ssa_target_feature_disable_or_enable = + the target features {$features} must all be either enabled or disabled together + codegen_ssa_target_feature_safe_trait = `#[target_feature(..)]` cannot be applied to safe trait method .label = cannot be applied to safe trait method .label_def = not an `unsafe` function diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index e99c3a462711c..a27f983c99a7b 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -1,5 +1,6 @@ use rustc_ast::{MetaItemKind, NestedMetaItem, ast, attr}; use rustc_attr::{InlineAttr, InstructionSetAttr, OptimizeAttr, list_contains_name}; +use rustc_data_structures::fx::FxHashMap; use rustc_errors::codes::*; use rustc_errors::{DiagMessage, SubdiagMessage, struct_span_code_err}; use rustc_hir as hir; @@ -13,13 +14,13 @@ use rustc_middle::middle::codegen_fn_attrs::{ use rustc_middle::mir::mono::Linkage; use rustc_middle::query::Providers; use rustc_middle::ty::{self as ty, TyCtxt}; -use rustc_session::lint; use rustc_session::parse::feature_err; +use rustc_session::{Session, lint}; use rustc_span::symbol::Ident; use rustc_span::{Span, sym}; use rustc_target::spec::{SanitizerSet, abi}; -use crate::errors; +use crate::errors::{self, MissingFeatures, TargetFeatureDisableOrEnable}; use crate::target_features::{check_target_feature_trait_unsafe, from_target_feature}; fn linkage_by_name(tcx: TyCtxt<'_>, def_id: LocalDefId, name: &str) -> Linkage { @@ -662,9 +663,49 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { } } + if let Some(features) = check_tied_features( + tcx.sess, + &codegen_fn_attrs + .target_features + .iter() + .map(|features| (features.name.as_str(), true)) + .collect(), + ) { + let span = tcx + .get_attrs(did, sym::target_feature) + .next() + .map_or_else(|| tcx.def_span(did), |a| a.span); + tcx.dcx() + .create_err(TargetFeatureDisableOrEnable { + features, + span: Some(span), + missing_features: Some(MissingFeatures), + }) + .emit(); + } + codegen_fn_attrs } +/// Given a map from target_features to whether they are enabled or disabled, ensure only valid +/// combinations are allowed. +pub fn check_tied_features( + sess: &Session, + features: &FxHashMap<&str, bool>, +) -> Option<&'static [&'static str]> { + if !features.is_empty() { + for tied in sess.target.tied_target_features() { + // Tied features must be set to the same value, or not set at all + let mut tied_iter = tied.iter(); + let enabled = features.get(tied_iter.next().unwrap()); + if tied_iter.any(|f| enabled != features.get(f)) { + return Some(tied); + } + } + } + None +} + /// Checks if the provided DefId is a method in a trait impl for a trait which has track_caller /// applied to the method prototype. fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool { diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index 08b326e3ac3c6..bc80f51f31c2d 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -9,7 +9,7 @@ use rustc_errors::codes::*; use rustc_errors::{ Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg, Level, }; -use rustc_macros::Diagnostic; +use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_middle::ty::Ty; use rustc_middle::ty::layout::LayoutError; use rustc_span::{Span, Symbol}; @@ -1068,3 +1068,27 @@ pub(crate) struct ErrorCreatingImportLibrary<'a> { pub lib_name: &'a str, pub error: String, } + +pub struct TargetFeatureDisableOrEnable<'a> { + pub features: &'a [&'a str], + pub span: Option, + pub missing_features: Option, +} + +#[derive(Subdiagnostic)] +#[help(codegen_ssa_missing_features)] +pub struct MissingFeatures; + +impl Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> { + fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> { + let mut diag = Diag::new(dcx, level, fluent::codegen_ssa_target_feature_disable_or_enable); + if let Some(span) = self.span { + diag.span(span); + }; + if let Some(missing_features) = self.missing_features { + diag.subdiagnostic(missing_features); + } + diag.arg("features", self.features.join(", ")); + diag + } +} diff --git a/tests/ui/target-feature/tied-features.rs b/tests/ui/target-feature/tied-features.rs index e36649d8eb1a9..c6cdf21a3e3f7 100644 --- a/tests/ui/target-feature/tied-features.rs +++ b/tests/ui/target-feature/tied-features.rs @@ -1,4 +1,3 @@ -//@ build-fail //@ compile-flags: --crate-type=rlib --target=aarch64-unknown-linux-gnu //@ needs-llvm-components: aarch64 #![feature(no_core, lang_items)] @@ -7,7 +6,6 @@ #[lang="sized"] trait Sized {} -// FIXME: this should not need to be public. pub fn main() { #[target_feature(enable = "pacg")] //~^ ERROR must all be either enabled or disabled together @@ -25,10 +23,15 @@ pub fn main() { //~^ ERROR must all be either enabled or disabled together unsafe fn foo() {} - #[target_feature(enable = "paca,pacg")] unsafe fn bar() {} #[target_feature(enable = "paca")] #[target_feature(enable = "pacg")] unsafe fn baz() {} + +// Confirm that functions which do not end up collected for monomorphisation will still error. + +#[target_feature(enable = "paca")] +//~^ ERROR must all be either enabled or disabled together +unsafe fn unused() {} diff --git a/tests/ui/target-feature/tied-features.stderr b/tests/ui/target-feature/tied-features.stderr index 525c9084330d4..8d677735e8460 100644 --- a/tests/ui/target-feature/tied-features.stderr +++ b/tests/ui/target-feature/tied-features.stderr @@ -1,5 +1,5 @@ error: the target features paca, pacg must all be either enabled or disabled together - --> $DIR/tied-features.rs:12:5 + --> $DIR/tied-features.rs:10:5 | LL | #[target_feature(enable = "pacg")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7,12 +7,20 @@ LL | #[target_feature(enable = "pacg")] = help: add the missing features in a `target_feature` attribute error: the target features paca, pacg must all be either enabled or disabled together - --> $DIR/tied-features.rs:24:1 + --> $DIR/tied-features.rs:22:1 | LL | #[target_feature(enable = "paca")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: add the missing features in a `target_feature` attribute -error: aborting due to 2 previous errors +error: the target features paca, pacg must all be either enabled or disabled together + --> $DIR/tied-features.rs:35:1 + | +LL | #[target_feature(enable = "paca")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add the missing features in a `target_feature` attribute + +error: aborting due to 3 previous errors From 461b49d96dd012dd13e172a166b7dad9ed7543d9 Mon Sep 17 00:00:00 2001 From: ultrabear Date: Wed, 18 Sep 2024 19:16:28 -0700 Subject: [PATCH 03/16] stabilize `{slice,array}::from_mut` --- library/core/src/array/mod.rs | 3 ++- library/core/src/lib.rs | 2 -- library/core/src/slice/raw.rs | 3 ++- library/core/tests/lib.rs | 2 -- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 24c42bc85dd91..a95046162d284 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -146,7 +146,8 @@ pub const fn from_ref(s: &T) -> &[T; 1] { /// Converts a mutable reference to `T` into a mutable reference to an array of length 1 (without copying). #[stable(feature = "array_from_ref", since = "1.53.0")] -#[rustc_const_unstable(feature = "const_array_from_ref", issue = "90206")] +#[rustc_const_stable(feature = "const_array_from_ref", since = "CURRENT_RUSTC_VERSION")] +#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))] pub const fn from_mut(s: &mut T) -> &mut [T; 1] { // SAFETY: Converting `&mut T` to `&mut [T; 1]` is sound. unsafe { &mut *(s as *mut T).cast::<[T; 1]>() } diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index e323e88f26141..96ab5755328e1 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -114,7 +114,6 @@ #![feature(const_align_offset)] #![feature(const_alloc_layout)] #![feature(const_arguments_as_str)] -#![feature(const_array_from_ref)] #![feature(const_array_into_iter_constructors)] #![feature(const_bigint_helper_methods)] #![feature(const_black_box)] @@ -145,7 +144,6 @@ #![feature(const_replace)] #![feature(const_size_of_val)] #![feature(const_size_of_val_raw)] -#![feature(const_slice_from_ref)] #![feature(const_strict_overflow_ops)] #![feature(const_swap)] #![feature(const_try)] diff --git a/library/core/src/slice/raw.rs b/library/core/src/slice/raw.rs index 84e916b9a84e7..998f9360332ff 100644 --- a/library/core/src/slice/raw.rs +++ b/library/core/src/slice/raw.rs @@ -204,7 +204,8 @@ pub const fn from_ref(s: &T) -> &[T] { /// Converts a reference to T into a slice of length 1 (without copying). #[stable(feature = "from_ref", since = "1.28.0")] -#[rustc_const_unstable(feature = "const_slice_from_ref", issue = "90206")] +#[rustc_const_stable(feature = "const_slice_from_ref", since = "CURRENT_RUSTC_VERSION")] +#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))] #[must_use] pub const fn from_mut(s: &mut T) -> &mut [T] { array::from_mut(s) diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 196e91ee3e926..0d4ec96f8426f 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -16,7 +16,6 @@ #![feature(clone_to_uninit)] #![feature(const_align_of_val_raw)] #![feature(const_align_offset)] -#![feature(const_array_from_ref)] #![feature(const_black_box)] #![feature(const_hash)] #![feature(const_heap)] @@ -31,7 +30,6 @@ #![feature(const_pointer_is_aligned)] #![feature(const_ptr_write)] #![feature(const_result)] -#![feature(const_slice_from_ref)] #![feature(const_three_way_compare)] #![feature(const_trait_impl)] #![feature(core_intrinsics)] From becf664e4930ce59fb01905e4c6af38c2df5382e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Wed, 9 Oct 2024 18:52:28 +0800 Subject: [PATCH 04/16] Match std RUSTFLAGS for host and target for `mir-opt` test --- src/bootstrap/src/core/build_steps/test.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 7a49b68b91e65..5bf4f19b3c417 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -1697,7 +1697,11 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the builder.ensure(TestHelpers { target: compiler.host }); // ensure that `libproc_macro` is available on the host. - builder.ensure(compile::Std::new(compiler, compiler.host)); + if suite == "mir-opt" { + builder.ensure(compile::Std::new_for_mir_opt_tests(compiler, compiler.host)); + } else { + builder.ensure(compile::Std::new(compiler, compiler.host)); + } // As well as the target if suite != "mir-opt" { From 62b24ea7c53aec6f8176fed05d0acee926b76bdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Wed, 9 Oct 2024 20:19:36 +0200 Subject: [PATCH 05/16] Compiler: Replace remaining occurrences of "object safe" with "dyn compatible" --- .../src/traits/dyn_compatibility.rs | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs index d5d7681a8d608..191eda4d34752 100644 --- a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs +++ b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs @@ -1,12 +1,8 @@ -//! "Object safety" refers to the ability for a trait to be converted -//! to an object. In general, traits may only be converted to an -//! object if all of their methods meet certain criteria. In particular, -//! they must: +//! "Dyn-compatibility"[^1] refers to the ability for a trait to be converted +//! to a trait object. In general, traits may only be converted to a trait +//! object if certain criteria are met. //! -//! - have a suitable receiver from which we can extract a vtable and coerce to a "thin" version -//! that doesn't contain the vtable; -//! - not reference the erased type `Self` except for in this receiver; -//! - not have generic type parameters. +//! [^1]: Formerly known as "object safety". use std::iter; use std::ops::ControlFlow; @@ -506,8 +502,8 @@ fn virtual_call_violations_for_method<'tcx>( /// This code checks that `receiver_is_dispatchable` is correctly implemented. /// -/// This check is outlined from the object safety check to avoid cycles with -/// layout computation, which relies on knowing whether methods are object safe. +/// This check is outlined from the dyn-compatibility check to avoid cycles with +/// layout computation, which relies on knowing whether methods are dyn-compatible. fn check_receiver_correct<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, method: ty::AssocItem) { if !is_vtable_safe_method(tcx, trait_def_id, method) { return; @@ -644,7 +640,7 @@ fn object_ty_for_trait<'tcx>( /// a pointer. /// /// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result -/// in a new check that `Trait` is object safe, creating a cycle (until object_safe_for_dispatch +/// in a new check that `Trait` is dyn-compatible, creating a cycle (until object_safe_for_dispatch /// is stabilized, see tracking issue ). /// Instead, we fudge a little by introducing a new type parameter `U` such that /// `Self: Unsize` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`. @@ -865,7 +861,7 @@ impl<'tcx> TypeVisitor> for IllegalSelfTypeVisitor<'tcx> { } fn visit_const(&mut self, ct: ty::Const<'tcx>) -> Self::Result { - // Constants can only influence object safety if they are generic and reference `Self`. + // Constants can only influence dyn-compatibility if they are generic and reference `Self`. // This is only possible for unevaluated constants, so we walk these here. self.tcx.expand_abstract_consts(ct).super_visit_with(self) } From 2e7a52b22fe222316a48093547f6312252c20f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Wed, 9 Oct 2024 18:37:30 +0200 Subject: [PATCH 06/16] Rename feature object_safe_for_dispatch to dyn_compatible_for_dispatch --- compiler/rustc_feature/src/removed.rs | 4 ++ compiler/rustc_feature/src/unstable.rs | 15 ++-- .../rustc_hir_analysis/src/coherence/mod.rs | 2 +- compiler/rustc_span/src/symbol.rs | 1 + .../src/traits/dyn_compatibility.rs | 6 +- .../src/traits/select/candidate_assembly.rs | 2 +- .../rustc_trait_selection/src/traits/wf.rs | 2 +- tests/crashes/120241-2.rs | 2 +- tests/crashes/120241.rs | 2 +- tests/crashes/120482.rs | 2 +- tests/crashes/125512.rs | 2 +- tests/crashes/128176.rs | 2 +- tests/crashes/130521.rs | 2 +- .../coherence-unsafe-trait-object-impl.rs | 2 +- ...eature-gate-dyn_compatible_for_dispatch.rs | 41 +++++++++++ ...e-gate-dyn_compatible_for_dispatch.stderr} | 70 +++++++++---------- .../feature-gate-object_safe_for_dispatch.rs | 41 ----------- ...-bound.dyn_compatible_for_dispatch.stderr} | 0 .../ui/kindck/kindck-inherited-copy-bound.rs | 8 +-- ...consts.dyn_compatible_for_dispatch.stderr} | 0 .../object-safety-associated-consts.rs | 4 +- ...nerics.dyn_compatible_for_dispatch.stderr} | 0 .../object-safety/object-safety-generics.rs | 8 +-- ...s-Self.dyn_compatible_for_dispatch.stderr} | 0 .../object-safety-mentions-Self.rs | 4 +- ...static.dyn_compatible_for_dispatch.stderr} | 0 .../object-safety/object-safety-no-static.rs | 4 +- ...ized-2.dyn_compatible_for_dispatch.stderr} | 0 .../ui/object-safety/object-safety-sized-2.rs | 4 +- ...-sized.dyn_compatible_for_dispatch.stderr} | 0 tests/ui/object-safety/object-safety-sized.rs | 4 +- .../downcast-unsafe-trait-objects.rs | 2 +- ...al-self-impl-for-unsafe-obj.current.stderr | 0 ...anual-self-impl-for-unsafe-obj.next.stderr | 0 .../manual-self-impl-for-unsafe-obj.rs | 2 +- .../static-dispatch-unsafe-object.rs | 2 +- ...t-safe.dyn_compatible_for_dispatch.stderr} | 0 .../arbitrary-self-types-not-object-safe.rs | 6 +- tests/ui/suggestions/issue-104328.rs | 2 +- .../ui/wf/wf-convert-unsafe-trait-obj-box.rs | 2 +- tests/ui/wf/wf-convert-unsafe-trait-obj.rs | 2 +- tests/ui/wf/wf-unsafe-trait-obj-match.rs | 2 +- 42 files changed, 130 insertions(+), 124 deletions(-) create mode 100644 tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.rs rename tests/ui/feature-gates/{feature-gate-object_safe_for_dispatch.stderr => feature-gate-dyn_compatible_for_dispatch.stderr} (50%) delete mode 100644 tests/ui/feature-gates/feature-gate-object_safe_for_dispatch.rs rename tests/ui/kindck/{kindck-inherited-copy-bound.object_safe_for_dispatch.stderr => kindck-inherited-copy-bound.dyn_compatible_for_dispatch.stderr} (100%) rename tests/ui/object-safety/{object-safety-associated-consts.object_safe_for_dispatch.stderr => object-safety-associated-consts.dyn_compatible_for_dispatch.stderr} (100%) rename tests/ui/object-safety/{object-safety-generics.object_safe_for_dispatch.stderr => object-safety-generics.dyn_compatible_for_dispatch.stderr} (100%) rename tests/ui/object-safety/{object-safety-mentions-Self.object_safe_for_dispatch.stderr => object-safety-mentions-Self.dyn_compatible_for_dispatch.stderr} (100%) rename tests/ui/object-safety/{object-safety-no-static.object_safe_for_dispatch.stderr => object-safety-no-static.dyn_compatible_for_dispatch.stderr} (100%) rename tests/ui/object-safety/{object-safety-sized-2.object_safe_for_dispatch.stderr => object-safety-sized-2.dyn_compatible_for_dispatch.stderr} (100%) rename tests/ui/object-safety/{object-safety-sized.object_safe_for_dispatch.stderr => object-safety-sized.dyn_compatible_for_dispatch.stderr} (100%) rename tests/ui/rfcs/{rfc-2027-object-safe-for-dispatch => rfc-2027-dyn-compatible-for-dispatch}/downcast-unsafe-trait-objects.rs (90%) rename tests/ui/rfcs/{rfc-2027-object-safe-for-dispatch => rfc-2027-dyn-compatible-for-dispatch}/manual-self-impl-for-unsafe-obj.current.stderr (100%) rename tests/ui/rfcs/{rfc-2027-object-safe-for-dispatch => rfc-2027-dyn-compatible-for-dispatch}/manual-self-impl-for-unsafe-obj.next.stderr (100%) rename tests/ui/rfcs/{rfc-2027-object-safe-for-dispatch => rfc-2027-dyn-compatible-for-dispatch}/manual-self-impl-for-unsafe-obj.rs (97%) rename tests/ui/rfcs/{rfc-2027-object-safe-for-dispatch => rfc-2027-dyn-compatible-for-dispatch}/static-dispatch-unsafe-object.rs (94%) rename tests/ui/self/{arbitrary-self-types-not-object-safe.object_safe_for_dispatch.stderr => arbitrary-self-types-not-object-safe.dyn_compatible_for_dispatch.stderr} (100%) diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs index 0cd0963d4e328..c275ad31b87bf 100644 --- a/compiler/rustc_feature/src/removed.rs +++ b/compiler/rustc_feature/src/removed.rs @@ -154,6 +154,10 @@ declare_features! ( /// then removed. But there was no utility storing it separately, so now /// it's in this list. (removed, no_stack_check, "1.0.0", None, None), + /// Allows making `dyn Trait` well-formed even if `Trait` is not dyn-compatible (object safe). + /// Renamed to `dyn_compatible_for_dispatch`. + (removed, object_safe_for_dispatch, "CURRENT_RUSTC_VERSION", Some(43561), + Some("renamed to `dyn_compatible_for_dispatch`")), /// Allows using `#[on_unimplemented(..)]` on traits. /// (Moved to `rustc_attrs`.) (removed, on_unimplemented, "1.40.0", None, None), diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index c5530097e9606..110ffa75b0523 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -259,6 +259,14 @@ declare_features! ( (unstable, doc_notable_trait, "1.52.0", Some(45040)), /// Allows using the `may_dangle` attribute (RFC 1327). (unstable, dropck_eyepatch, "1.10.0", Some(34761)), + /// Allows making `dyn Trait` well-formed even if `Trait` is not dyn-compatible[^1]. + /// In that case, `dyn Trait: Trait` does not hold. Moreover, coercions and + /// casts in safe Rust to `dyn Trait` for such a `Trait` is also forbidden. + /// + /// Renamed from `object_safe_for_dispatch`. + /// + /// [^1]: Formerly known as "object safe". + (unstable, dyn_compatible_for_dispatch, "CURRENT_RUSTC_VERSION", Some(43561)), /// Allows using the `#[fundamental]` attribute. (unstable, fundamental, "1.0.0", Some(29635)), /// Allows using `#[link_name="llvm.*"]`. @@ -544,13 +552,6 @@ declare_features! ( (unstable, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554)), /// Allows `for` binders in where-clauses (incomplete, non_lifetime_binders, "1.69.0", Some(108185)), - /// Allows making `dyn Trait` well-formed even if `Trait` is not dyn-compatible[^1]. - /// In that case, `dyn Trait: Trait` does not hold. Moreover, coercions and - /// casts in safe Rust to `dyn Trait` for such a `Trait` is also forbidden. - /// - /// [^1]: Formerly known as "object safe". - // FIXME(dyn_compat_renaming): Rename feature. - (unstable, object_safe_for_dispatch, "1.40.0", Some(43561)), /// Allows using enums in offset_of! (unstable, offset_of_enum, "1.75.0", Some(120141)), /// Allows using fields with slice type in offset_of! diff --git a/compiler/rustc_hir_analysis/src/coherence/mod.rs b/compiler/rustc_hir_analysis/src/coherence/mod.rs index 69d3642644709..eea5a16ac6fd3 100644 --- a/compiler/rustc_hir_analysis/src/coherence/mod.rs +++ b/compiler/rustc_hir_analysis/src/coherence/mod.rs @@ -199,7 +199,7 @@ fn check_object_overlap<'tcx>( for component_def_id in component_def_ids { if !tcx.is_dyn_compatible(component_def_id) { // FIXME(dyn_compat_renaming): Rename test and update comment. - // Without the 'object_safe_for_dispatch' feature this is an error + // Without the 'dyn_compatible_for_dispatch' feature this is an error // which will be reported by wfcheck. Ignore it here. // This is tested by `coherence-impl-trait-for-trait-object-safe.rs`. // With the feature enabled, the trait is not implemented automatically, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index e8aa129c6cdbe..9e2df84830987 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -776,6 +776,7 @@ symbols! { dropck_eyepatch, dropck_parametricity, dylib, + dyn_compatible_for_dispatch, dyn_metadata, dyn_star, dyn_trait, diff --git a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs index 191eda4d34752..45e7de942fb61 100644 --- a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs +++ b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs @@ -639,8 +639,8 @@ fn object_ty_for_trait<'tcx>( /// contained by the trait object, because the object that needs to be coerced is behind /// a pointer. /// -/// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result -/// in a new check that `Trait` is dyn-compatible, creating a cycle (until object_safe_for_dispatch +/// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result in +/// a new check that `Trait` is dyn-compatible, creating a cycle (until dyn_compatible_for_dispatch /// is stabilized, see tracking issue ). /// Instead, we fudge a little by introducing a new type parameter `U` such that /// `Self: Unsize` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`. @@ -674,7 +674,7 @@ fn receiver_is_dispatchable<'tcx>( // the type `U` in the query // use a bogus type parameter to mimic a forall(U) query using u32::MAX for now. - // FIXME(mikeyhew) this is a total hack. Once object_safe_for_dispatch is stabilized, we can + // FIXME(mikeyhew) this is a total hack. Once dyn_compatible_for_dispatch is stabilized, we can // replace this with `dyn Trait` let unsized_self_ty: Ty<'tcx> = Ty::new_param(tcx, u32::MAX, Symbol::intern("RustaceansAreAwesome")); diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 084b61115dbcf..20adda6f0de29 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -881,7 +881,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } if let Some(principal) = data.principal() { - if !self.infcx.tcx.features().object_safe_for_dispatch { + if !self.infcx.tcx.features().dyn_compatible_for_dispatch { principal.with_self_ty(self.tcx(), self_ty) } else if self.tcx().is_dyn_compatible(principal.def_id()) { principal.with_self_ty(self.tcx(), self_ty) diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 7e140ecfee08b..a849cdfe1257a 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -829,7 +829,7 @@ impl<'a, 'tcx> TypeVisitor> for WfPredicates<'a, 'tcx> { // obligations that don't refer to Self and // checking those - let defer_to_coercion = tcx.features().object_safe_for_dispatch; + let defer_to_coercion = tcx.features().dyn_compatible_for_dispatch; if !defer_to_coercion { if let Some(principal) = data.principal_def_id() { diff --git a/tests/crashes/120241-2.rs b/tests/crashes/120241-2.rs index 9c4a3a50293e3..91ec33620908e 100644 --- a/tests/crashes/120241-2.rs +++ b/tests/crashes/120241-2.rs @@ -1,6 +1,6 @@ //@ known-bug: #120241 //@ edition:2021 -#![feature(object_safe_for_dispatch)] +#![feature(dyn_compatible_for_dispatch)] #![feature(unsized_fn_params)] fn guard(_s: Copy) -> bool { diff --git a/tests/crashes/120241.rs b/tests/crashes/120241.rs index f18347a006cb6..b4fcb903714db 100644 --- a/tests/crashes/120241.rs +++ b/tests/crashes/120241.rs @@ -1,6 +1,6 @@ //@ known-bug: #120241 //@ edition:2021 -#![feature(object_safe_for_dispatch)] +#![feature(dyn_compatible_for_dispatch)] trait B { fn f(a: A) -> A; diff --git a/tests/crashes/120482.rs b/tests/crashes/120482.rs index 6cbc2009c5f63..a395855d796f1 100644 --- a/tests/crashes/120482.rs +++ b/tests/crashes/120482.rs @@ -1,6 +1,6 @@ //@ known-bug: #120482 //@ edition:2021 -#![feature(object_safe_for_dispatch)] +#![feature(dyn_compatible_for_dispatch)] trait B { fn bar(&self, x: &Self); diff --git a/tests/crashes/125512.rs b/tests/crashes/125512.rs index 1672b24a11437..37dbdf2f32f85 100644 --- a/tests/crashes/125512.rs +++ b/tests/crashes/125512.rs @@ -1,6 +1,6 @@ //@ known-bug: rust-lang/rust#125512 //@ edition:2021 -#![feature(object_safe_for_dispatch)] +#![feature(dyn_compatible_for_dispatch)] trait B { fn f(a: A) -> A; } diff --git a/tests/crashes/128176.rs b/tests/crashes/128176.rs index 70fada4f0fec2..970ad9ff2cd55 100644 --- a/tests/crashes/128176.rs +++ b/tests/crashes/128176.rs @@ -1,7 +1,7 @@ //@ known-bug: rust-lang/rust#128176 #![feature(generic_const_exprs)] -#![feature(object_safe_for_dispatch)] +#![feature(dyn_compatible_for_dispatch)] trait X { type Y; } diff --git a/tests/crashes/130521.rs b/tests/crashes/130521.rs index 2d30b658024e0..7c078ab579094 100644 --- a/tests/crashes/130521.rs +++ b/tests/crashes/130521.rs @@ -1,6 +1,6 @@ //@ known-bug: #130521 -#![feature(object_safe_for_dispatch)] +#![feature(dyn_compatible_for_dispatch)] struct Vtable(dyn Cap); trait Cap<'a> {} diff --git a/tests/ui/coherence/coherence-unsafe-trait-object-impl.rs b/tests/ui/coherence/coherence-unsafe-trait-object-impl.rs index 9859a226efd00..16baf0958a674 100644 --- a/tests/ui/coherence/coherence-unsafe-trait-object-impl.rs +++ b/tests/ui/coherence/coherence-unsafe-trait-object-impl.rs @@ -1,7 +1,7 @@ // Check that unsafe trait object do not implement themselves // automatically -#![feature(object_safe_for_dispatch)] +#![feature(dyn_compatible_for_dispatch)] trait Trait: Sized { fn call(&self); diff --git a/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.rs b/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.rs new file mode 100644 index 0000000000000..2dbba370a51e5 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.rs @@ -0,0 +1,41 @@ +// Test that the use of the dyn-incompatible trait objects +// are gated by the `dyn_compatible_for_dispatch` feature gate. + +trait DynIncompatible1: Sized {} + +trait DynIncompatible2 { + fn static_fn() {} +} + +trait DynIncompatible3 { + fn foo(&self); +} + +trait DynIncompatible4 { + fn foo(&self, s: &Self); +} + +fn takes_non_object_safe_ref(obj: &dyn DynIncompatible1) { + //~^ ERROR E0038 +} + +fn return_non_object_safe_ref() -> &'static dyn DynIncompatible2 { + //~^ ERROR E0038 + loop {} +} + +fn takes_non_object_safe_box(obj: Box) { + //~^ ERROR E0038 +} + +fn return_non_object_safe_rc() -> std::rc::Rc { + //~^ ERROR E0038 + loop {} +} + +trait Trait {} + +impl Trait for dyn DynIncompatible1 {} +//~^ ERROR E0038 + +fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-object_safe_for_dispatch.stderr b/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.stderr similarity index 50% rename from tests/ui/feature-gates/feature-gate-object_safe_for_dispatch.stderr rename to tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.stderr index fd5ed9c40f7ab..3cb73dfd52c68 100644 --- a/tests/ui/feature-gates/feature-gate-object_safe_for_dispatch.stderr +++ b/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.stderr @@ -1,28 +1,28 @@ -error[E0038]: the trait `NonObjectSafe1` cannot be made into an object - --> $DIR/feature-gate-object_safe_for_dispatch.rs:18:39 +error[E0038]: the trait `DynIncompatible1` cannot be made into an object + --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:18:39 | -LL | fn takes_non_object_safe_ref(obj: &dyn NonObjectSafe1) { - | ^^^^^^^^^^^^^^^^^^ `NonObjectSafe1` cannot be made into an object +LL | fn takes_non_object_safe_ref(obj: &dyn DynIncompatible1) { + | ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible1` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/feature-gate-object_safe_for_dispatch.rs:4:23 + --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:4:25 | -LL | trait NonObjectSafe1: Sized {} - | -------------- ^^^^^ ...because it requires `Self: Sized` +LL | trait DynIncompatible1: Sized {} + | ---------------- ^^^^^ ...because it requires `Self: Sized` | | | this trait cannot be made into an object... -error[E0038]: the trait `NonObjectSafe2` cannot be made into an object - --> $DIR/feature-gate-object_safe_for_dispatch.rs:22:45 +error[E0038]: the trait `DynIncompatible2` cannot be made into an object + --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:22:45 | -LL | fn return_non_object_safe_ref() -> &'static dyn NonObjectSafe2 { - | ^^^^^^^^^^^^^^^^^^ `NonObjectSafe2` cannot be made into an object +LL | fn return_non_object_safe_ref() -> &'static dyn DynIncompatible2 { + | ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible2` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/feature-gate-object_safe_for_dispatch.rs:7:8 + --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:7:8 | -LL | trait NonObjectSafe2 { - | -------------- this trait cannot be made into an object... +LL | trait DynIncompatible2 { + | ---------------- this trait cannot be made into an object... LL | fn static_fn() {} | ^^^^^^^^^ ...because associated function `static_fn` has no `self` parameter help: consider turning `static_fn` into a method by giving it a `&self` argument @@ -34,47 +34,47 @@ help: alternatively, consider constraining `static_fn` so it does not apply to t LL | fn static_fn() where Self: Sized {} | +++++++++++++++++ -error[E0038]: the trait `NonObjectSafe3` cannot be made into an object - --> $DIR/feature-gate-object_safe_for_dispatch.rs:27:39 +error[E0038]: the trait `DynIncompatible3` cannot be made into an object + --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:27:39 | -LL | fn takes_non_object_safe_box(obj: Box) { - | ^^^^^^^^^^^^^^^^^^ `NonObjectSafe3` cannot be made into an object +LL | fn takes_non_object_safe_box(obj: Box) { + | ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible3` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/feature-gate-object_safe_for_dispatch.rs:11:8 + --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:11:8 | -LL | trait NonObjectSafe3 { - | -------------- this trait cannot be made into an object... +LL | trait DynIncompatible3 { + | ---------------- this trait cannot be made into an object... LL | fn foo(&self); | ^^^ ...because method `foo` has generic type parameters = help: consider moving `foo` to another trait -error[E0038]: the trait `NonObjectSafe4` cannot be made into an object - --> $DIR/feature-gate-object_safe_for_dispatch.rs:31:47 +error[E0038]: the trait `DynIncompatible4` cannot be made into an object + --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:31:47 | -LL | fn return_non_object_safe_rc() -> std::rc::Rc { - | ^^^^^^^^^^^^^^^^^^ `NonObjectSafe4` cannot be made into an object +LL | fn return_non_object_safe_rc() -> std::rc::Rc { + | ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible4` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/feature-gate-object_safe_for_dispatch.rs:15:22 + --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:15:22 | -LL | trait NonObjectSafe4 { - | -------------- this trait cannot be made into an object... +LL | trait DynIncompatible4 { + | ---------------- this trait cannot be made into an object... LL | fn foo(&self, s: &Self); | ^^^^^ ...because method `foo` references the `Self` type in this parameter = help: consider moving `foo` to another trait -error[E0038]: the trait `NonObjectSafe1` cannot be made into an object - --> $DIR/feature-gate-object_safe_for_dispatch.rs:38:16 +error[E0038]: the trait `DynIncompatible1` cannot be made into an object + --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:38:16 | -LL | impl Trait for dyn NonObjectSafe1 {} - | ^^^^^^^^^^^^^^^^^^ `NonObjectSafe1` cannot be made into an object +LL | impl Trait for dyn DynIncompatible1 {} + | ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible1` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/feature-gate-object_safe_for_dispatch.rs:4:23 + --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:4:25 | -LL | trait NonObjectSafe1: Sized {} - | -------------- ^^^^^ ...because it requires `Self: Sized` +LL | trait DynIncompatible1: Sized {} + | ---------------- ^^^^^ ...because it requires `Self: Sized` | | | this trait cannot be made into an object... diff --git a/tests/ui/feature-gates/feature-gate-object_safe_for_dispatch.rs b/tests/ui/feature-gates/feature-gate-object_safe_for_dispatch.rs deleted file mode 100644 index 37348e476d408..0000000000000 --- a/tests/ui/feature-gates/feature-gate-object_safe_for_dispatch.rs +++ /dev/null @@ -1,41 +0,0 @@ -// Test that the use of the non object-safe trait objects -// are gated by `object_safe_for_dispatch` feature gate. - -trait NonObjectSafe1: Sized {} - -trait NonObjectSafe2 { - fn static_fn() {} -} - -trait NonObjectSafe3 { - fn foo(&self); -} - -trait NonObjectSafe4 { - fn foo(&self, s: &Self); -} - -fn takes_non_object_safe_ref(obj: &dyn NonObjectSafe1) { - //~^ ERROR E0038 -} - -fn return_non_object_safe_ref() -> &'static dyn NonObjectSafe2 { - //~^ ERROR E0038 - loop {} -} - -fn takes_non_object_safe_box(obj: Box) { - //~^ ERROR E0038 -} - -fn return_non_object_safe_rc() -> std::rc::Rc { - //~^ ERROR E0038 - loop {} -} - -trait Trait {} - -impl Trait for dyn NonObjectSafe1 {} -//~^ ERROR E0038 - -fn main() {} diff --git a/tests/ui/kindck/kindck-inherited-copy-bound.object_safe_for_dispatch.stderr b/tests/ui/kindck/kindck-inherited-copy-bound.dyn_compatible_for_dispatch.stderr similarity index 100% rename from tests/ui/kindck/kindck-inherited-copy-bound.object_safe_for_dispatch.stderr rename to tests/ui/kindck/kindck-inherited-copy-bound.dyn_compatible_for_dispatch.stderr diff --git a/tests/ui/kindck/kindck-inherited-copy-bound.rs b/tests/ui/kindck/kindck-inherited-copy-bound.rs index c785736f42e4b..dda95229ddf00 100644 --- a/tests/ui/kindck/kindck-inherited-copy-bound.rs +++ b/tests/ui/kindck/kindck-inherited-copy-bound.rs @@ -1,8 +1,8 @@ // Test that Copy bounds inherited by trait are checked. // -//@ revisions: curr object_safe_for_dispatch +//@ revisions: curr dyn_compatible_for_dispatch -#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))] +#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))] use std::any::Any; @@ -19,7 +19,7 @@ fn take_param(foo: &T) { } fn a() { let x: Box<_> = Box::new(3); take_param(&x); //[curr]~ ERROR E0277 - //[object_safe_for_dispatch]~^ ERROR E0277 + //[dyn_compatible_for_dispatch]~^ ERROR E0277 } fn b() { @@ -28,7 +28,7 @@ fn b() { let z = &x as &dyn Foo; //[curr]~^ ERROR E0038 //[curr]~| ERROR E0038 - //[object_safe_for_dispatch]~^^^ ERROR E0038 + //[dyn_compatible_for_dispatch]~^^^ ERROR E0038 } fn main() { } diff --git a/tests/ui/object-safety/object-safety-associated-consts.object_safe_for_dispatch.stderr b/tests/ui/object-safety/object-safety-associated-consts.dyn_compatible_for_dispatch.stderr similarity index 100% rename from tests/ui/object-safety/object-safety-associated-consts.object_safe_for_dispatch.stderr rename to tests/ui/object-safety/object-safety-associated-consts.dyn_compatible_for_dispatch.stderr diff --git a/tests/ui/object-safety/object-safety-associated-consts.rs b/tests/ui/object-safety/object-safety-associated-consts.rs index a090214bbb404..fc7b372b782a4 100644 --- a/tests/ui/object-safety/object-safety-associated-consts.rs +++ b/tests/ui/object-safety/object-safety-associated-consts.rs @@ -1,9 +1,9 @@ // Check that we correctly prevent users from making trait objects // from traits with associated consts. // -//@ revisions: curr object_safe_for_dispatch +//@ revisions: curr dyn_compatible_for_dispatch -#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))] +#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))] trait Bar { const X: usize; diff --git a/tests/ui/object-safety/object-safety-generics.object_safe_for_dispatch.stderr b/tests/ui/object-safety/object-safety-generics.dyn_compatible_for_dispatch.stderr similarity index 100% rename from tests/ui/object-safety/object-safety-generics.object_safe_for_dispatch.stderr rename to tests/ui/object-safety/object-safety-generics.dyn_compatible_for_dispatch.stderr diff --git a/tests/ui/object-safety/object-safety-generics.rs b/tests/ui/object-safety/object-safety-generics.rs index f005a689ac45c..b51555aa500c5 100644 --- a/tests/ui/object-safety/object-safety-generics.rs +++ b/tests/ui/object-safety/object-safety-generics.rs @@ -1,9 +1,9 @@ // Check that we correctly prevent users from making trait objects // from traits with generic methods, unless `where Self : Sized` is // present. -//@ revisions: curr object_safe_for_dispatch +//@ revisions: curr dyn_compatible_for_dispatch -#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))] +#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))] trait Bar { @@ -18,14 +18,14 @@ trait Quux { fn make_bar(t: &T) -> &dyn Bar { //[curr]~^ ERROR E0038 t - //[object_safe_for_dispatch]~^ ERROR E0038 + //[dyn_compatible_for_dispatch]~^ ERROR E0038 //[curr]~^^ ERROR E0038 } fn make_bar_explicit(t: &T) -> &dyn Bar { //[curr]~^ ERROR E0038 t as &dyn Bar - //[object_safe_for_dispatch]~^ ERROR E0038 + //[dyn_compatible_for_dispatch]~^ ERROR E0038 //[curr]~^^ ERROR E0038 //[curr]~| ERROR E0038 } diff --git a/tests/ui/object-safety/object-safety-mentions-Self.object_safe_for_dispatch.stderr b/tests/ui/object-safety/object-safety-mentions-Self.dyn_compatible_for_dispatch.stderr similarity index 100% rename from tests/ui/object-safety/object-safety-mentions-Self.object_safe_for_dispatch.stderr rename to tests/ui/object-safety/object-safety-mentions-Self.dyn_compatible_for_dispatch.stderr diff --git a/tests/ui/object-safety/object-safety-mentions-Self.rs b/tests/ui/object-safety/object-safety-mentions-Self.rs index 1311faf97bc36..84c229e252d30 100644 --- a/tests/ui/object-safety/object-safety-mentions-Self.rs +++ b/tests/ui/object-safety/object-safety-mentions-Self.rs @@ -2,9 +2,9 @@ // form traits that make use of `Self` in an argument or return // position, unless `where Self : Sized` is present.. // -//@ revisions: curr object_safe_for_dispatch +//@ revisions: curr dyn_compatible_for_dispatch -#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))] +#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))] trait Bar { diff --git a/tests/ui/object-safety/object-safety-no-static.object_safe_for_dispatch.stderr b/tests/ui/object-safety/object-safety-no-static.dyn_compatible_for_dispatch.stderr similarity index 100% rename from tests/ui/object-safety/object-safety-no-static.object_safe_for_dispatch.stderr rename to tests/ui/object-safety/object-safety-no-static.dyn_compatible_for_dispatch.stderr diff --git a/tests/ui/object-safety/object-safety-no-static.rs b/tests/ui/object-safety/object-safety-no-static.rs index 4f4e03d734e8e..54af16fe18eb6 100644 --- a/tests/ui/object-safety/object-safety-no-static.rs +++ b/tests/ui/object-safety/object-safety-no-static.rs @@ -1,9 +1,9 @@ // Check that we correctly prevent users from making trait objects // from traits with static methods. // -//@ revisions: curr object_safe_for_dispatch +//@ revisions: curr dyn_compatible_for_dispatch -#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))] +#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))] trait Foo { fn foo() {} diff --git a/tests/ui/object-safety/object-safety-sized-2.object_safe_for_dispatch.stderr b/tests/ui/object-safety/object-safety-sized-2.dyn_compatible_for_dispatch.stderr similarity index 100% rename from tests/ui/object-safety/object-safety-sized-2.object_safe_for_dispatch.stderr rename to tests/ui/object-safety/object-safety-sized-2.dyn_compatible_for_dispatch.stderr diff --git a/tests/ui/object-safety/object-safety-sized-2.rs b/tests/ui/object-safety/object-safety-sized-2.rs index cfb5d588d70df..f5edd287f24d8 100644 --- a/tests/ui/object-safety/object-safety-sized-2.rs +++ b/tests/ui/object-safety/object-safety-sized-2.rs @@ -1,9 +1,9 @@ // Check that we correctly prevent users from making trait objects // from traits where `Self : Sized`. // -//@ revisions: curr object_safe_for_dispatch +//@ revisions: curr dyn_compatible_for_dispatch -#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))] +#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))] trait Bar where Self : Sized diff --git a/tests/ui/object-safety/object-safety-sized.object_safe_for_dispatch.stderr b/tests/ui/object-safety/object-safety-sized.dyn_compatible_for_dispatch.stderr similarity index 100% rename from tests/ui/object-safety/object-safety-sized.object_safe_for_dispatch.stderr rename to tests/ui/object-safety/object-safety-sized.dyn_compatible_for_dispatch.stderr diff --git a/tests/ui/object-safety/object-safety-sized.rs b/tests/ui/object-safety/object-safety-sized.rs index f4d6c945b33d5..4c4fe3f8f2593 100644 --- a/tests/ui/object-safety/object-safety-sized.rs +++ b/tests/ui/object-safety/object-safety-sized.rs @@ -1,9 +1,9 @@ // Check that we correctly prevent users from making trait objects // from traits where `Self : Sized`. // -//@ revisions: curr object_safe_for_dispatch +//@ revisions: curr dyn_compatible_for_dispatch -#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))] +#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))] trait Bar: Sized { fn bar(&self, t: T); diff --git a/tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/downcast-unsafe-trait-objects.rs b/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/downcast-unsafe-trait-objects.rs similarity index 90% rename from tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/downcast-unsafe-trait-objects.rs rename to tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/downcast-unsafe-trait-objects.rs index d4337dcb16543..e9206789756e7 100644 --- a/tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/downcast-unsafe-trait-objects.rs +++ b/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/downcast-unsafe-trait-objects.rs @@ -3,7 +3,7 @@ // //@ check-pass -#![feature(object_safe_for_dispatch)] +#![feature(dyn_compatible_for_dispatch)] trait Trait: Sized {} diff --git a/tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/manual-self-impl-for-unsafe-obj.current.stderr b/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.current.stderr similarity index 100% rename from tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/manual-self-impl-for-unsafe-obj.current.stderr rename to tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.current.stderr diff --git a/tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/manual-self-impl-for-unsafe-obj.next.stderr b/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.next.stderr similarity index 100% rename from tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/manual-self-impl-for-unsafe-obj.next.stderr rename to tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.next.stderr diff --git a/tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/manual-self-impl-for-unsafe-obj.rs b/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.rs similarity index 97% rename from tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/manual-self-impl-for-unsafe-obj.rs rename to tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.rs index a020d91fb1407..37e6f948ad118 100644 --- a/tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/manual-self-impl-for-unsafe-obj.rs +++ b/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.rs @@ -5,7 +5,7 @@ //@[next] compile-flags: -Znext-solver //@ run-pass -#![feature(object_safe_for_dispatch)] +#![feature(dyn_compatible_for_dispatch)] trait Bad { fn stat() -> char { diff --git a/tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/static-dispatch-unsafe-object.rs b/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/static-dispatch-unsafe-object.rs similarity index 94% rename from tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/static-dispatch-unsafe-object.rs rename to tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/static-dispatch-unsafe-object.rs index cbf76a6830b8f..c38928a9f44e9 100644 --- a/tests/ui/rfcs/rfc-2027-object-safe-for-dispatch/static-dispatch-unsafe-object.rs +++ b/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/static-dispatch-unsafe-object.rs @@ -3,7 +3,7 @@ // //@ check-pass -#![feature(object_safe_for_dispatch)] +#![feature(dyn_compatible_for_dispatch)] trait Statics { fn plain() {} diff --git a/tests/ui/self/arbitrary-self-types-not-object-safe.object_safe_for_dispatch.stderr b/tests/ui/self/arbitrary-self-types-not-object-safe.dyn_compatible_for_dispatch.stderr similarity index 100% rename from tests/ui/self/arbitrary-self-types-not-object-safe.object_safe_for_dispatch.stderr rename to tests/ui/self/arbitrary-self-types-not-object-safe.dyn_compatible_for_dispatch.stderr diff --git a/tests/ui/self/arbitrary-self-types-not-object-safe.rs b/tests/ui/self/arbitrary-self-types-not-object-safe.rs index 0053eb5f73948..940b2f1e8e2fa 100644 --- a/tests/ui/self/arbitrary-self-types-not-object-safe.rs +++ b/tests/ui/self/arbitrary-self-types-not-object-safe.rs @@ -1,6 +1,6 @@ -//@ revisions: curr object_safe_for_dispatch +//@ revisions: curr dyn_compatible_for_dispatch -#![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))] +#![cfg_attr(dyn_compatible_for_dispatch, feature(dyn_compatible_for_dispatch))] use std::rc::Rc; @@ -33,7 +33,7 @@ fn make_foo() { let x = Rc::new(5usize) as Rc; //[curr]~^ ERROR E0038 //[curr]~| ERROR E0038 - //[object_safe_for_dispatch]~^^^ ERROR E0038 + //[dyn_compatible_for_dispatch]~^^^ ERROR E0038 } fn make_bar() { diff --git a/tests/ui/suggestions/issue-104328.rs b/tests/ui/suggestions/issue-104328.rs index c3707baf79fc3..2b0fbdb8d35bb 100644 --- a/tests/ui/suggestions/issue-104328.rs +++ b/tests/ui/suggestions/issue-104328.rs @@ -1,4 +1,4 @@ -#![feature(object_safe_for_dispatch)] +#![feature(dyn_compatible_for_dispatch)] trait Foo { fn f() {} diff --git a/tests/ui/wf/wf-convert-unsafe-trait-obj-box.rs b/tests/ui/wf/wf-convert-unsafe-trait-obj-box.rs index ffdb49a3be5c7..e32b04c471524 100644 --- a/tests/ui/wf/wf-convert-unsafe-trait-obj-box.rs +++ b/tests/ui/wf/wf-convert-unsafe-trait-obj-box.rs @@ -1,7 +1,7 @@ // Check that we do not allow casts or coercions // to object unsafe trait objects inside a Box -#![feature(object_safe_for_dispatch)] +#![feature(dyn_compatible_for_dispatch)] trait Trait: Sized {} diff --git a/tests/ui/wf/wf-convert-unsafe-trait-obj.rs b/tests/ui/wf/wf-convert-unsafe-trait-obj.rs index 143b854ed6b2d..6f38635281983 100644 --- a/tests/ui/wf/wf-convert-unsafe-trait-obj.rs +++ b/tests/ui/wf/wf-convert-unsafe-trait-obj.rs @@ -1,7 +1,7 @@ // Check that we do not allow casts or coercions // to object unsafe trait objects by ref -#![feature(object_safe_for_dispatch)] +#![feature(dyn_compatible_for_dispatch)] trait Trait: Sized {} diff --git a/tests/ui/wf/wf-unsafe-trait-obj-match.rs b/tests/ui/wf/wf-unsafe-trait-obj-match.rs index c8731a8ecafa4..07e90538b85dd 100644 --- a/tests/ui/wf/wf-unsafe-trait-obj-match.rs +++ b/tests/ui/wf/wf-unsafe-trait-obj-match.rs @@ -1,7 +1,7 @@ // Check that we do not allow coercions to object // unsafe trait objects in match arms -#![feature(object_safe_for_dispatch)] +#![feature(dyn_compatible_for_dispatch)] trait Trait: Sized {} From 20cebae31203a9781f99081b075abe0dc2504a98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Wed, 9 Oct 2024 23:31:01 +0200 Subject: [PATCH 07/16] UI tests: Rename "object safe" to "dyn compatible" --- src/tools/tidy/src/issues.txt | 4 -- tests/ui/allocator/dyn-compatible.rs | 13 ++++ tests/ui/allocator/object-safe.rs | 13 ---- ....rs => entails-sized-dyn-compatibility.rs} | 12 ++-- ...{object-safety.rs => dyn-compatibility.rs} | 0 ...safety.stderr => dyn-compatibility.stderr} | 4 +- ...ce-impl-trait-for-trait-dyn-compatible.rs} | 6 +- ...impl-trait-for-trait-dyn-compatible.stderr | 27 +++++++ ...ce-impl-trait-for-trait-object-safe.stderr | 27 ------- ...rs => const_param_ty_dyn_compatibility.rs} | 0 ...> const_param_ty_dyn_compatibility.stderr} | 4 +- ...rr-ret.rs => dyn-compatibility-err-ret.rs} | 0 ...tderr => dyn-compatibility-err-ret.stderr} | 8 +-- ... => dyn-compatibility-err-where-bounds.rs} | 0 ...dyn-compatibility-err-where-bounds.stderr} | 8 +-- ...r.rs => dyn-compatibility-ok-infer-err.rs} | 0 ... => dyn-compatibility-ok-infer-err.stderr} | 8 +-- ...t-safety-ok.rs => dyn-compatibility-ok.rs} | 0 .../almost-supertrait-associated-type.rs | 2 +- .../almost-supertrait-associated-type.stderr | 0 .../assoc_const_bounds.rs | 0 .../assoc_const_bounds_sized.rs | 0 .../assoc_type_bounds.rs | 0 .../assoc_type_bounds.stderr | 0 .../assoc_type_bounds2.rs | 0 .../assoc_type_bounds2.stderr | 0 .../assoc_type_bounds_implicit_sized.fixed | 0 .../assoc_type_bounds_implicit_sized.rs | 0 .../assoc_type_bounds_implicit_sized.stderr | 0 .../assoc_type_bounds_sized.rs | 0 .../assoc_type_bounds_sized_others.rs | 0 .../assoc_type_bounds_sized_others.stderr | 0 .../assoc_type_bounds_sized_unnecessary.rs | 0 ...assoc_type_bounds_sized_unnecessary.stderr | 0 .../assoc_type_bounds_sized_used.rs | 0 .../assoc_type_bounds_sized_used.stderr | 0 .../associated-consts.curr.stderr} | 8 +-- ...consts.dyn_compatible_for_dispatch.stderr} | 4 +- .../associated-consts.rs} | 0 .../avoid-ice-on-warning-2.new.stderr | 0 .../avoid-ice-on-warning-2.old.stderr | 0 .../avoid-ice-on-warning-2.rs | 0 .../avoid-ice-on-warning-3.new.stderr | 0 .../avoid-ice-on-warning-3.old.stderr | 0 .../avoid-ice-on-warning-3.rs | 0 .../avoid-ice-on-warning.new.stderr | 0 .../avoid-ice-on-warning.old.stderr | 0 .../avoid-ice-on-warning.rs | 0 .../bare-trait-dont-suggest-dyn.new.fixed | 0 .../bare-trait-dont-suggest-dyn.new.stderr | 0 .../bare-trait-dont-suggest-dyn.old.stderr | 0 .../bare-trait-dont-suggest-dyn.rs | 0 .../bounds.rs} | 2 +- .../bounds.stderr} | 4 +- .../by-value-self-use.rs} | 2 +- .../by-value-self-use.stderr} | 2 +- .../by-value-self.rs} | 2 +- .../call-when-assoc-ty-is-sized.rs | 0 .../elaborated-predicates-ordering.rs} | 1 + .../erroneous_signature.rs | 0 .../erroneous_signature.stderr | 0 .../generics.curr.stderr} | 20 +++--- ...nerics.dyn_compatible_for_dispatch.stderr} | 8 +-- .../generics.rs} | 0 ...s-multiple_supertrait_upcastable-check.rs} | 1 + .../item-bounds-can-reference-self.rs | 0 ...mention-correct-dyn-incompatible-trait.rs} | 2 + ...ion-correct-dyn-incompatible-trait.stderr} | 8 +-- .../mentions-Self-in-super-predicates.rs} | 0 .../mentions-Self-in-super-predicates.stderr} | 12 ++-- .../mentions-Self.curr.stderr} | 16 ++--- ...s-Self.dyn_compatible_for_dispatch.stderr} | 8 +-- .../mentions-Self.rs} | 0 .../missing-assoc-type.rs} | 0 .../missing-assoc-type.stderr} | 16 ++--- .../no-static.curr.stderr} | 12 ++-- ...static.dyn_compatible_for_dispatch.stderr} | 4 +- .../no-static.rs} | 0 .../phantom-fn.rs} | 2 +- ...t-in-fn-inputs-and-outputs-issue-125139.rs | 0 ...-fn-inputs-and-outputs-issue-125139.stderr | 0 .../sized-2.curr.stderr} | 8 +-- ...ized-2.dyn_compatible_for_dispatch.stderr} | 4 +- .../sized-2.rs} | 0 .../sized.curr.stderr} | 8 +-- .../sized.dyn_compatible_for_dispatch.stderr} | 4 +- .../sized.rs} | 0 .../supertrait-mentions-GAT.rs} | 0 .../supertrait-mentions-GAT.stderr} | 8 +-- .../supertrait-mentions-Self.rs} | 0 .../supertrait-mentions-Self.stderr} | 8 +-- ...chable-receiver-and-wc-references-Self.rs} | 5 +- ...le-receiver-and-wc-references-Self.stderr} | 12 ++-- ...ure-gate-dispatch-from-dyn-missing-impl.rs | 2 +- ...eature-gate-dyn_compatible_for_dispatch.rs | 8 +-- ...re-gate-dyn_compatible_for_dispatch.stderr | 24 +++---- .../generic-associated-types/trait-objects.rs | 2 +- ...ble-trait-in-return-position-dyn-trait.rs} | 11 +-- ...trait-in-return-position-dyn-trait.stderr} | 72 +++++++++---------- ...le-trait-in-return-position-impl-trait.rs} | 16 ++--- ...rait-in-return-position-impl-trait.stderr} | 12 ++-- ...ilities-during-dyn-compatibility-check.rs} | 0 ...ies-during-dyn-compatibility-check.stderr} | 16 ++--- ...ty-sized.rs => dyn-compatibility-sized.rs} | 0 ...{object-safety.rs => dyn-compatibility.rs} | 0 ...safety.stderr => dyn-compatibility.stderr} | 16 ++--- tests/ui/issues/issue-58734.rs | 8 +-- .../downcast-unsafe-trait-objects.rs | 2 +- .../manual-self-impl-for-unsafe-obj.rs | 2 +- tests/ui/sanitizer/cfi/async-closures.rs | 2 +- ...y-self-types-dyn-incompatible.curr.stderr} | 8 +-- ...atible.dyn_compatible_for_dispatch.stderr} | 4 +- ... arbitrary-self-types-dyn-incompatible.rs} | 0 ...itrary_self_types_pointers_and_wrappers.rs | 6 +- ...compatibility-sized-self-by-value-self.rs} | 2 +- ...ompatibility-sized-self-generic-method.rs} | 2 +- ...n-compatibility-sized-self-return-Self.rs} | 2 +- tests/ui/specialization/issue-44861.rs | 8 +-- ...not-object-safe.rs => dyn-incompatible.rs} | 0 ...dyn-incompatible-trait-references-self.rs} | 0 ...incompatible-trait-references-self.stderr} | 14 ++-- ...trait-should-use-self-2021-without-dyn.rs} | 0 ...t-should-use-self-2021-without-dyn.stderr} | 30 ++++---- ...ncompatible-trait-should-use-self-2021.rs} | 0 ...patible-trait-should-use-self-2021.stderr} | 12 ++-- ...dyn-incompatible-trait-should-use-self.rs} | 0 ...incompatible-trait-should-use-self.stderr} | 12 ++-- ...atible-trait-should-use-where-sized.fixed} | 0 ...ompatible-trait-should-use-where-sized.rs} | 0 ...tible-trait-should-use-where-sized.stderr} | 6 +- tests/ui/suggestions/issue-98500.rs | 6 +- tests/ui/suggestions/issue-98500.stderr | 2 +- tests/ui/traits/alias/no-duplicates.rs | 4 +- tests/ui/traits/alias/no-extra-traits.rs | 2 +- tests/ui/traits/alias/object-wf.rs | 4 +- ...ect-unsafety.rs => dyn-incompatibility.rs} | 0 ...fety.stderr => dyn-incompatibility.stderr} | 10 +-- ...ety.rs => supertrait-dyn-compatibility.rs} | 0 ...rr => supertrait-dyn-compatibility.stderr} | 14 ++-- tests/ui/traits/object/print_vtable_sizes.rs | 2 +- tests/ui/traits/object/safety.rs | 2 +- ...ect-safe.rs => vtable-dyn-incompatible.rs} | 2 +- ....stderr => vtable-dyn-incompatible.stderr} | 2 +- tests/ui/traits/wf-object/no-duplicates.rs | 4 +- tests/ui/traits/wf-object/reverse-order.rs | 2 +- ...by-value-trait-dyn-compatibility-rpass.rs} | 0 ...e-trait-dyn-compatibility-with-default.rs} | 0 ...rs => by-value-trait-dyn-compatibility.rs} | 0 ...> by-value-trait-dyn-compatibility.stderr} | 4 +- ... wf-convert-dyn-incompat-trait-obj-box.rs} | 2 +- ...convert-dyn-incompat-trait-obj-box.stderr} | 12 ++-- ...s => wf-convert-dyn-incompat-trait-obj.rs} | 2 +- ... wf-convert-dyn-incompat-trait-obj.stderr} | 12 ++-- ....rs => wf-dyn-incompat-trait-obj-match.rs} | 0 ...=> wf-dyn-incompat-trait-obj-match.stderr} | 10 +-- ...-object-safe.rs => wf-dyn-incompatible.rs} | 2 +- ...safe.stderr => wf-dyn-incompatible.stderr} | 4 +- 157 files changed, 366 insertions(+), 364 deletions(-) create mode 100644 tests/ui/allocator/dyn-compatible.rs delete mode 100644 tests/ui/allocator/object-safe.rs rename tests/ui/associated-type-bounds/{entails-sized-object-safety.rs => entails-sized-dyn-compatibility.rs} (67%) rename tests/ui/async-await/in-trait/{object-safety.rs => dyn-compatibility.rs} (100%) rename tests/ui/async-await/in-trait/{object-safety.stderr => dyn-compatibility.stderr} (90%) rename tests/ui/coherence/{coherence-impl-trait-for-trait-object-safe.rs => coherence-impl-trait-for-trait-dyn-compatible.rs} (54%) create mode 100644 tests/ui/coherence/coherence-impl-trait-for-trait-dyn-compatible.stderr delete mode 100644 tests/ui/coherence/coherence-impl-trait-for-trait-object-safe.stderr rename tests/ui/const-generics/adt_const_params/{const_param_ty_object_safety.rs => const_param_ty_dyn_compatibility.rs} (100%) rename tests/ui/const-generics/adt_const_params/{const_param_ty_object_safety.stderr => const_param_ty_dyn_compatibility.stderr} (93%) rename tests/ui/const-generics/generic_const_exprs/{object-safety-err-ret.rs => dyn-compatibility-err-ret.rs} (100%) rename tests/ui/const-generics/generic_const_exprs/{object-safety-err-ret.stderr => dyn-compatibility-err-ret.stderr} (91%) rename tests/ui/const-generics/generic_const_exprs/{object-safety-err-where-bounds.rs => dyn-compatibility-err-where-bounds.rs} (100%) rename tests/ui/const-generics/generic_const_exprs/{object-safety-err-where-bounds.stderr => dyn-compatibility-err-where-bounds.stderr} (88%) rename tests/ui/const-generics/generic_const_exprs/{object-safety-ok-infer-err.rs => dyn-compatibility-ok-infer-err.rs} (100%) rename tests/ui/const-generics/generic_const_exprs/{object-safety-ok-infer-err.stderr => dyn-compatibility-ok-infer-err.stderr} (85%) rename tests/ui/const-generics/generic_const_exprs/{object-safety-ok.rs => dyn-compatibility-ok.rs} (100%) rename tests/ui/{object-safety => dyn-compatibility}/almost-supertrait-associated-type.rs (95%) rename tests/ui/{object-safety => dyn-compatibility}/almost-supertrait-associated-type.stderr (100%) rename tests/ui/{object-safety => dyn-compatibility}/assoc_const_bounds.rs (100%) rename tests/ui/{object-safety => dyn-compatibility}/assoc_const_bounds_sized.rs (100%) rename tests/ui/{object-safety => dyn-compatibility}/assoc_type_bounds.rs (100%) rename tests/ui/{object-safety => dyn-compatibility}/assoc_type_bounds.stderr (100%) rename tests/ui/{object-safety => dyn-compatibility}/assoc_type_bounds2.rs (100%) rename tests/ui/{object-safety => dyn-compatibility}/assoc_type_bounds2.stderr (100%) rename tests/ui/{object-safety => dyn-compatibility}/assoc_type_bounds_implicit_sized.fixed (100%) rename tests/ui/{object-safety => dyn-compatibility}/assoc_type_bounds_implicit_sized.rs (100%) rename tests/ui/{object-safety => dyn-compatibility}/assoc_type_bounds_implicit_sized.stderr (100%) rename tests/ui/{object-safety => dyn-compatibility}/assoc_type_bounds_sized.rs (100%) rename tests/ui/{object-safety => dyn-compatibility}/assoc_type_bounds_sized_others.rs (100%) rename tests/ui/{object-safety => dyn-compatibility}/assoc_type_bounds_sized_others.stderr (100%) rename tests/ui/{object-safety => dyn-compatibility}/assoc_type_bounds_sized_unnecessary.rs (100%) rename tests/ui/{object-safety => dyn-compatibility}/assoc_type_bounds_sized_unnecessary.stderr (100%) rename tests/ui/{object-safety => dyn-compatibility}/assoc_type_bounds_sized_used.rs (100%) rename tests/ui/{object-safety => dyn-compatibility}/assoc_type_bounds_sized_used.stderr (100%) rename tests/ui/{object-safety/object-safety-associated-consts.curr.stderr => dyn-compatibility/associated-consts.curr.stderr} (86%) rename tests/ui/{object-safety/object-safety-associated-consts.dyn_compatible_for_dispatch.stderr => dyn-compatibility/associated-consts.dyn_compatible_for_dispatch.stderr} (87%) rename tests/ui/{object-safety/object-safety-associated-consts.rs => dyn-compatibility/associated-consts.rs} (100%) rename tests/ui/{object-safety => dyn-compatibility}/avoid-ice-on-warning-2.new.stderr (100%) rename tests/ui/{object-safety => dyn-compatibility}/avoid-ice-on-warning-2.old.stderr (100%) rename tests/ui/{object-safety => dyn-compatibility}/avoid-ice-on-warning-2.rs (100%) rename tests/ui/{object-safety => dyn-compatibility}/avoid-ice-on-warning-3.new.stderr (100%) rename tests/ui/{object-safety => dyn-compatibility}/avoid-ice-on-warning-3.old.stderr (100%) rename tests/ui/{object-safety => dyn-compatibility}/avoid-ice-on-warning-3.rs (100%) rename tests/ui/{object-safety => dyn-compatibility}/avoid-ice-on-warning.new.stderr (100%) rename tests/ui/{object-safety => dyn-compatibility}/avoid-ice-on-warning.old.stderr (100%) rename tests/ui/{object-safety => dyn-compatibility}/avoid-ice-on-warning.rs (100%) rename tests/ui/{object-safety => dyn-compatibility}/bare-trait-dont-suggest-dyn.new.fixed (100%) rename tests/ui/{object-safety => dyn-compatibility}/bare-trait-dont-suggest-dyn.new.stderr (100%) rename tests/ui/{object-safety => dyn-compatibility}/bare-trait-dont-suggest-dyn.old.stderr (100%) rename tests/ui/{object-safety => dyn-compatibility}/bare-trait-dont-suggest-dyn.rs (100%) rename tests/ui/{object-safety/object-safety-bounds.rs => dyn-compatibility/bounds.rs} (72%) rename tests/ui/{object-safety/object-safety-bounds.stderr => dyn-compatibility/bounds.stderr} (89%) rename tests/ui/{object-safety/object-safety-by-value-self-use.rs => dyn-compatibility/by-value-self-use.rs} (79%) rename tests/ui/{object-safety/object-safety-by-value-self-use.stderr => dyn-compatibility/by-value-self-use.stderr} (83%) rename tests/ui/{object-safety/object-safety-by-value-self.rs => dyn-compatibility/by-value-self.rs} (90%) rename tests/ui/{object-safety => dyn-compatibility}/call-when-assoc-ty-is-sized.rs (100%) rename tests/ui/{object-safety/issue-102933.rs => dyn-compatibility/elaborated-predicates-ordering.rs} (93%) rename tests/ui/{object-safety => dyn-compatibility}/erroneous_signature.rs (100%) rename tests/ui/{object-safety => dyn-compatibility}/erroneous_signature.stderr (100%) rename tests/ui/{object-safety/object-safety-generics.curr.stderr => dyn-compatibility/generics.curr.stderr} (88%) rename tests/ui/{object-safety/object-safety-generics.dyn_compatible_for_dispatch.stderr => dyn-compatibility/generics.dyn_compatible_for_dispatch.stderr} (89%) rename tests/ui/{object-safety/object-safety-generics.rs => dyn-compatibility/generics.rs} (100%) rename tests/ui/{object-safety/issue-106247.rs => dyn-compatibility/impossible-predicates-multiple_supertrait_upcastable-check.rs} (73%) rename tests/ui/{object-safety => dyn-compatibility}/item-bounds-can-reference-self.rs (100%) rename tests/ui/{object-safety/issue-19538.rs => dyn-compatibility/mention-correct-dyn-incompatible-trait.rs} (90%) rename tests/ui/{object-safety/issue-19538.stderr => dyn-compatibility/mention-correct-dyn-incompatible-trait.stderr} (87%) rename tests/ui/{object-safety/object-safety-issue-22040.rs => dyn-compatibility/mentions-Self-in-super-predicates.rs} (100%) rename tests/ui/{object-safety/object-safety-issue-22040.stderr => dyn-compatibility/mentions-Self-in-super-predicates.stderr} (87%) rename tests/ui/{object-safety/object-safety-mentions-Self.curr.stderr => dyn-compatibility/mentions-Self.curr.stderr} (88%) rename tests/ui/{object-safety/object-safety-mentions-Self.dyn_compatible_for_dispatch.stderr => dyn-compatibility/mentions-Self.dyn_compatible_for_dispatch.stderr} (88%) rename tests/ui/{object-safety/object-safety-mentions-Self.rs => dyn-compatibility/mentions-Self.rs} (100%) rename tests/ui/{traits/object/object-unsafe-missing-assoc-type.rs => dyn-compatibility/missing-assoc-type.rs} (100%) rename tests/ui/{traits/object/object-unsafe-missing-assoc-type.stderr => dyn-compatibility/missing-assoc-type.stderr} (86%) rename tests/ui/{object-safety/object-safety-no-static.curr.stderr => dyn-compatibility/no-static.curr.stderr} (92%) rename tests/ui/{object-safety/object-safety-no-static.dyn_compatible_for_dispatch.stderr => dyn-compatibility/no-static.dyn_compatible_for_dispatch.stderr} (93%) rename tests/ui/{object-safety/object-safety-no-static.rs => dyn-compatibility/no-static.rs} (100%) rename tests/ui/{object-safety/object-safety-phantom-fn.rs => dyn-compatibility/phantom-fn.rs} (92%) rename tests/ui/{object-safety => dyn-compatibility}/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.rs (100%) rename tests/ui/{object-safety => dyn-compatibility}/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.stderr (100%) rename tests/ui/{object-safety/object-safety-sized-2.curr.stderr => dyn-compatibility/sized-2.curr.stderr} (88%) rename tests/ui/{object-safety/object-safety-sized-2.dyn_compatible_for_dispatch.stderr => dyn-compatibility/sized-2.dyn_compatible_for_dispatch.stderr} (89%) rename tests/ui/{object-safety/object-safety-sized-2.rs => dyn-compatibility/sized-2.rs} (100%) rename tests/ui/{object-safety/object-safety-sized.curr.stderr => dyn-compatibility/sized.curr.stderr} (88%) rename tests/ui/{object-safety/object-safety-sized.dyn_compatible_for_dispatch.stderr => dyn-compatibility/sized.dyn_compatible_for_dispatch.stderr} (89%) rename tests/ui/{object-safety/object-safety-sized.rs => dyn-compatibility/sized.rs} (100%) rename tests/ui/{object-safety/object-safety-supertrait-mentions-GAT.rs => dyn-compatibility/supertrait-mentions-GAT.rs} (100%) rename tests/ui/{object-safety/object-safety-supertrait-mentions-GAT.stderr => dyn-compatibility/supertrait-mentions-GAT.stderr} (86%) rename tests/ui/{object-safety/object-safety-supertrait-mentions-Self.rs => dyn-compatibility/supertrait-mentions-Self.rs} (100%) rename tests/ui/{object-safety/object-safety-supertrait-mentions-Self.stderr => dyn-compatibility/supertrait-mentions-Self.stderr} (86%) rename tests/ui/{object-safety/issue-102762.rs => dyn-compatibility/undispatchable-receiver-and-wc-references-Self.rs} (79%) rename tests/ui/{object-safety/issue-102762.stderr => dyn-compatibility/undispatchable-receiver-and-wc-references-Self.stderr} (87%) rename tests/ui/impl-trait/{object-unsafe-trait-in-return-position-dyn-trait.rs => dyn-incompatible-trait-in-return-position-dyn-trait.rs} (59%) rename tests/ui/impl-trait/{object-unsafe-trait-in-return-position-dyn-trait.stderr => dyn-incompatible-trait-in-return-position-dyn-trait.stderr} (62%) rename tests/ui/impl-trait/{object-unsafe-trait-in-return-position-impl-trait.rs => dyn-incompatible-trait-in-return-position-impl-trait.rs} (61%) rename tests/ui/impl-trait/{object-unsafe-trait-in-return-position-impl-trait.stderr => dyn-incompatible-trait-in-return-position-impl-trait.stderr} (54%) rename tests/ui/impl-trait/in-trait/{cycle-effective-visibilities-during-object-safety.rs => cycle-effective-visibilities-during-dyn-compatibility-check.rs} (100%) rename tests/ui/impl-trait/in-trait/{cycle-effective-visibilities-during-object-safety.stderr => cycle-effective-visibilities-during-dyn-compatibility-check.stderr} (82%) rename tests/ui/impl-trait/in-trait/{object-safety-sized.rs => dyn-compatibility-sized.rs} (100%) rename tests/ui/impl-trait/in-trait/{object-safety.rs => dyn-compatibility.rs} (100%) rename tests/ui/impl-trait/in-trait/{object-safety.stderr => dyn-compatibility.stderr} (91%) rename tests/ui/self/{arbitrary-self-types-not-object-safe.curr.stderr => arbitrary-self-types-dyn-incompatible.curr.stderr} (89%) rename tests/ui/self/{arbitrary-self-types-not-object-safe.dyn_compatible_for_dispatch.stderr => arbitrary-self-types-dyn-incompatible.dyn_compatible_for_dispatch.stderr} (90%) rename tests/ui/self/{arbitrary-self-types-not-object-safe.rs => arbitrary-self-types-dyn-incompatible.rs} (100%) rename tests/ui/self/{object-safety-sized-self-by-value-self.rs => dyn-compatibility-sized-self-by-value-self.rs} (90%) rename tests/ui/self/{object-safety-sized-self-generic-method.rs => dyn-compatibility-sized-self-generic-method.rs} (90%) rename tests/ui/self/{object-safety-sized-self-return-Self.rs => dyn-compatibility-sized-self-return-Self.rs} (90%) rename tests/ui/suggestions/auxiliary/{not-object-safe.rs => dyn-incompatible.rs} (100%) rename tests/ui/suggestions/{object-unsafe-trait-references-self.rs => dyn-incompatible-trait-references-self.rs} (100%) rename tests/ui/suggestions/{object-unsafe-trait-references-self.stderr => dyn-incompatible-trait-references-self.stderr} (87%) rename tests/ui/suggestions/{object-unsafe-trait-should-use-self-2021-without-dyn.rs => dyn-incompatible-trait-should-use-self-2021-without-dyn.rs} (100%) rename tests/ui/suggestions/{object-unsafe-trait-should-use-self-2021-without-dyn.stderr => dyn-incompatible-trait-should-use-self-2021-without-dyn.stderr} (83%) rename tests/ui/suggestions/{object-unsafe-trait-should-use-self-2021.rs => dyn-incompatible-trait-should-use-self-2021.rs} (100%) rename tests/ui/suggestions/{object-unsafe-trait-should-use-self-2021.stderr => dyn-incompatible-trait-should-use-self-2021.stderr} (85%) rename tests/ui/suggestions/{object-unsafe-trait-should-use-self.rs => dyn-incompatible-trait-should-use-self.rs} (100%) rename tests/ui/suggestions/{object-unsafe-trait-should-use-self.stderr => dyn-incompatible-trait-should-use-self.stderr} (86%) rename tests/ui/suggestions/{object-unsafe-trait-should-use-where-sized.fixed => dyn-incompatible-trait-should-use-where-sized.fixed} (100%) rename tests/ui/suggestions/{object-unsafe-trait-should-use-where-sized.rs => dyn-incompatible-trait-should-use-where-sized.rs} (100%) rename tests/ui/suggestions/{object-unsafe-trait-should-use-where-sized.stderr => dyn-incompatible-trait-should-use-where-sized.stderr} (89%) rename tests/ui/traits/next-solver/{object-unsafety.rs => dyn-incompatibility.rs} (100%) rename tests/ui/traits/next-solver/{object-unsafety.stderr => dyn-incompatibility.stderr} (90%) rename tests/ui/traits/non_lifetime_binders/{supertrait-object-safety.rs => supertrait-dyn-compatibility.rs} (100%) rename tests/ui/traits/non_lifetime_binders/{supertrait-object-safety.stderr => supertrait-dyn-compatibility.stderr} (88%) rename tests/ui/traits/vtable/{vtable-non-object-safe.rs => vtable-dyn-incompatible.rs} (78%) rename tests/ui/traits/vtable/{vtable-non-object-safe.stderr => vtable-dyn-incompatible.stderr} (92%) rename tests/ui/unsized-locals/{by-value-trait-object-safety-rpass.rs => by-value-trait-dyn-compatibility-rpass.rs} (100%) rename tests/ui/unsized-locals/{by-value-trait-object-safety-withdefault.rs => by-value-trait-dyn-compatibility-with-default.rs} (100%) rename tests/ui/unsized-locals/{by-value-trait-object-safety.rs => by-value-trait-dyn-compatibility.rs} (100%) rename tests/ui/unsized-locals/{by-value-trait-object-safety.stderr => by-value-trait-dyn-compatibility.stderr} (84%) rename tests/ui/wf/{wf-convert-unsafe-trait-obj-box.rs => wf-convert-dyn-incompat-trait-obj-box.rs} (87%) rename tests/ui/wf/{wf-convert-unsafe-trait-obj-box.stderr => wf-convert-dyn-incompat-trait-obj-box.stderr} (86%) rename tests/ui/wf/{wf-convert-unsafe-trait-obj.rs => wf-convert-dyn-incompat-trait-obj.rs} (87%) rename tests/ui/wf/{wf-convert-unsafe-trait-obj.stderr => wf-convert-dyn-incompat-trait-obj.stderr} (87%) rename tests/ui/wf/{wf-unsafe-trait-obj-match.rs => wf-dyn-incompat-trait-obj-match.rs} (100%) rename tests/ui/wf/{wf-unsafe-trait-obj-match.stderr => wf-dyn-incompat-trait-obj-match.stderr} (89%) rename tests/ui/wf/{wf-object-safe.rs => wf-dyn-incompatible.rs} (57%) rename tests/ui/wf/{wf-object-safe.stderr => wf-dyn-incompatible.stderr} (90%) diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index 86cae849b9782..92aafc5a98e8a 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -3173,10 +3173,6 @@ ui/nll/user-annotations/issue-55241.rs ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.rs ui/nll/user-annotations/issue-57731-ascibed-coupled-types.rs ui/numbers-arithmetic/issue-8460.rs -ui/object-safety/issue-102762.rs -ui/object-safety/issue-102933.rs -ui/object-safety/issue-106247.rs -ui/object-safety/issue-19538.rs ui/on-unimplemented/issue-104140.rs ui/or-patterns/issue-64879-trailing-before-guard.rs ui/or-patterns/issue-67514-irrefutable-param.rs diff --git a/tests/ui/allocator/dyn-compatible.rs b/tests/ui/allocator/dyn-compatible.rs new file mode 100644 index 0000000000000..9d8235e58d929 --- /dev/null +++ b/tests/ui/allocator/dyn-compatible.rs @@ -0,0 +1,13 @@ +//@ run-pass + +// Check that `Allocator` is dyn-compatible, this allows for polymorphic allocators + +#![feature(allocator_api)] + +use std::alloc::{Allocator, System}; + +fn ensure_dyn_compatible(_: &dyn Allocator) {} + +fn main() { + ensure_dyn_compatible(&System); +} diff --git a/tests/ui/allocator/object-safe.rs b/tests/ui/allocator/object-safe.rs deleted file mode 100644 index 1c1f4fe0bf6ce..0000000000000 --- a/tests/ui/allocator/object-safe.rs +++ /dev/null @@ -1,13 +0,0 @@ -//@ run-pass - -// Check that `Allocator` is object safe, this allows for polymorphic allocators - -#![feature(allocator_api)] - -use std::alloc::{Allocator, System}; - -fn ensure_object_safe(_: &dyn Allocator) {} - -fn main() { - ensure_object_safe(&System); -} diff --git a/tests/ui/associated-type-bounds/entails-sized-object-safety.rs b/tests/ui/associated-type-bounds/entails-sized-dyn-compatibility.rs similarity index 67% rename from tests/ui/associated-type-bounds/entails-sized-object-safety.rs rename to tests/ui/associated-type-bounds/entails-sized-dyn-compatibility.rs index ad2cbe4820981..943df68493fb1 100644 --- a/tests/ui/associated-type-bounds/entails-sized-object-safety.rs +++ b/tests/ui/associated-type-bounds/entails-sized-dyn-compatibility.rs @@ -4,21 +4,21 @@ trait Tr1: Sized { type As1; } trait Tr2<'a>: Sized { type As2; } trait ObjTr1 { fn foo() -> Self where Self: Tr1; } -fn _assert_obj_safe_1(_: Box) {} +fn _assert_dyn_compat_1(_: Box) {} trait ObjTr2 { fn foo() -> Self where Self: Tr1; } -fn _assert_obj_safe_2(_: Box) {} +fn _assert_dyn_compat_2(_: Box) {} trait ObjTr3 { fn foo() -> Self where Self: Tr1 + 'static + Copy>; } -fn _assert_obj_safe_3(_: Box) {} +fn _assert_dyn_compat_3(_: Box) {} trait ObjTr4 { fn foo() -> Self where Self: Tr1 Tr2<'a>>; } -fn _assert_obj_safe_4(_: Box) {} +fn _assert_dyn_compat_4(_: Box) {} trait ObjTr5 { fn foo() -> Self where for<'a> Self: Tr1>; } -fn _assert_obj_safe_5(_: Box) {} +fn _assert_dyn_compat_5(_: Box) {} trait ObjTr6 { fn foo() -> Self where Self: for<'a> Tr1 Tr2<'b>>>; } -fn _assert_obj_safe_6(_: Box) {} +fn _assert_dyn_compat_6(_: Box) {} fn main() {} diff --git a/tests/ui/async-await/in-trait/object-safety.rs b/tests/ui/async-await/in-trait/dyn-compatibility.rs similarity index 100% rename from tests/ui/async-await/in-trait/object-safety.rs rename to tests/ui/async-await/in-trait/dyn-compatibility.rs diff --git a/tests/ui/async-await/in-trait/object-safety.stderr b/tests/ui/async-await/in-trait/dyn-compatibility.stderr similarity index 90% rename from tests/ui/async-await/in-trait/object-safety.stderr rename to tests/ui/async-await/in-trait/dyn-compatibility.stderr index 8e73abab9335f..5cc3b6800ddbc 100644 --- a/tests/ui/async-await/in-trait/object-safety.stderr +++ b/tests/ui/async-await/in-trait/dyn-compatibility.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-safety.rs:9:12 + --> $DIR/dyn-compatibility.rs:9:12 | LL | let x: &dyn Foo = todo!(); | ^^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety.rs:5:14 + --> $DIR/dyn-compatibility.rs:5:14 | LL | trait Foo { | --- this trait cannot be made into an object... diff --git a/tests/ui/coherence/coherence-impl-trait-for-trait-object-safe.rs b/tests/ui/coherence/coherence-impl-trait-for-trait-dyn-compatible.rs similarity index 54% rename from tests/ui/coherence/coherence-impl-trait-for-trait-object-safe.rs rename to tests/ui/coherence/coherence-impl-trait-for-trait-dyn-compatible.rs index bce3b0fd729fe..f41d3a783abca 100644 --- a/tests/ui/coherence/coherence-impl-trait-for-trait-object-safe.rs +++ b/tests/ui/coherence/coherence-impl-trait-for-trait-dyn-compatible.rs @@ -1,10 +1,10 @@ // Test that we give suitable error messages when the user attempts to // impl a trait `Trait` for its own object type. -// If the trait is not object-safe, we give a more tailored message +// If the trait is dyn-incompatible, we give a more tailored message // because we're such schnuckels: -trait NotObjectSafe { fn eq(&self, other: Self); } -impl NotObjectSafe for dyn NotObjectSafe { } +trait DynIncompatible { fn eq(&self, other: Self); } +impl DynIncompatible for dyn DynIncompatible { } //~^ ERROR E0038 //~| ERROR E0046 diff --git a/tests/ui/coherence/coherence-impl-trait-for-trait-dyn-compatible.stderr b/tests/ui/coherence/coherence-impl-trait-for-trait-dyn-compatible.stderr new file mode 100644 index 0000000000000..542be2dbc305c --- /dev/null +++ b/tests/ui/coherence/coherence-impl-trait-for-trait-dyn-compatible.stderr @@ -0,0 +1,27 @@ +error[E0038]: the trait `DynIncompatible` cannot be made into an object + --> $DIR/coherence-impl-trait-for-trait-dyn-compatible.rs:7:26 + | +LL | impl DynIncompatible for dyn DynIncompatible { } + | ^^^^^^^^^^^^^^^^^^^ `DynIncompatible` cannot be made into an object + | +note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/coherence-impl-trait-for-trait-dyn-compatible.rs:6:45 + | +LL | trait DynIncompatible { fn eq(&self, other: Self); } + | --------------- ^^^^ ...because method `eq` references the `Self` type in this parameter + | | + | this trait cannot be made into an object... + = help: consider moving `eq` to another trait + +error[E0046]: not all trait items implemented, missing: `eq` + --> $DIR/coherence-impl-trait-for-trait-dyn-compatible.rs:7:1 + | +LL | trait DynIncompatible { fn eq(&self, other: Self); } + | -------------------------- `eq` from trait +LL | impl DynIncompatible for dyn DynIncompatible { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `eq` in implementation + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0038, E0046. +For more information about an error, try `rustc --explain E0038`. diff --git a/tests/ui/coherence/coherence-impl-trait-for-trait-object-safe.stderr b/tests/ui/coherence/coherence-impl-trait-for-trait-object-safe.stderr deleted file mode 100644 index ce65e079ab45a..0000000000000 --- a/tests/ui/coherence/coherence-impl-trait-for-trait-object-safe.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error[E0038]: the trait `NotObjectSafe` cannot be made into an object - --> $DIR/coherence-impl-trait-for-trait-object-safe.rs:7:24 - | -LL | impl NotObjectSafe for dyn NotObjectSafe { } - | ^^^^^^^^^^^^^^^^^ `NotObjectSafe` cannot be made into an object - | -note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/coherence-impl-trait-for-trait-object-safe.rs:6:43 - | -LL | trait NotObjectSafe { fn eq(&self, other: Self); } - | ------------- ^^^^ ...because method `eq` references the `Self` type in this parameter - | | - | this trait cannot be made into an object... - = help: consider moving `eq` to another trait - -error[E0046]: not all trait items implemented, missing: `eq` - --> $DIR/coherence-impl-trait-for-trait-object-safe.rs:7:1 - | -LL | trait NotObjectSafe { fn eq(&self, other: Self); } - | -------------------------- `eq` from trait -LL | impl NotObjectSafe for dyn NotObjectSafe { } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `eq` in implementation - -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0038, E0046. -For more information about an error, try `rustc --explain E0038`. diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_dyn_compatibility.rs similarity index 100% rename from tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.rs rename to tests/ui/const-generics/adt_const_params/const_param_ty_dyn_compatibility.rs diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_dyn_compatibility.stderr similarity index 93% rename from tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.stderr rename to tests/ui/const-generics/adt_const_params/const_param_ty_dyn_compatibility.stderr index 831b40887ac42..84281eb53c946 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.stderr +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_dyn_compatibility.stderr @@ -1,5 +1,5 @@ error[E0038]: the trait `ConstParamTy_` cannot be made into an object - --> $DIR/const_param_ty_object_safety.rs:6:12 + --> $DIR/const_param_ty_dyn_compatibility.rs:6:12 | LL | fn foo(a: &dyn ConstParamTy_) {} | ^^^^^^^^^^^^^^^^^ `ConstParamTy_` cannot be made into an object @@ -14,7 +14,7 @@ LL | fn foo(a: &impl ConstParamTy_) {} | ~~~~ error[E0038]: the trait `UnsizedConstParamTy` cannot be made into an object - --> $DIR/const_param_ty_object_safety.rs:9:12 + --> $DIR/const_param_ty_dyn_compatibility.rs:9:12 | LL | fn bar(a: &dyn UnsizedConstParamTy) {} | ^^^^^^^^^^^^^^^^^^^^^^^ `UnsizedConstParamTy` cannot be made into an object diff --git a/tests/ui/const-generics/generic_const_exprs/object-safety-err-ret.rs b/tests/ui/const-generics/generic_const_exprs/dyn-compatibility-err-ret.rs similarity index 100% rename from tests/ui/const-generics/generic_const_exprs/object-safety-err-ret.rs rename to tests/ui/const-generics/generic_const_exprs/dyn-compatibility-err-ret.rs diff --git a/tests/ui/const-generics/generic_const_exprs/object-safety-err-ret.stderr b/tests/ui/const-generics/generic_const_exprs/dyn-compatibility-err-ret.stderr similarity index 91% rename from tests/ui/const-generics/generic_const_exprs/object-safety-err-ret.stderr rename to tests/ui/const-generics/generic_const_exprs/dyn-compatibility-err-ret.stderr index fb57da42bb297..d2017615e67db 100644 --- a/tests/ui/const-generics/generic_const_exprs/object-safety-err-ret.stderr +++ b/tests/ui/const-generics/generic_const_exprs/dyn-compatibility-err-ret.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-safety-err-ret.rs:17:16 + --> $DIR/dyn-compatibility-err-ret.rs:17:16 | LL | fn use_dyn(v: &dyn Foo) { | ^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-err-ret.rs:8:8 + --> $DIR/dyn-compatibility-err-ret.rs:8:8 | LL | trait Foo { | --- this trait cannot be made into an object... @@ -17,13 +17,13 @@ LL | fn test(&self) -> [u8; bar::()]; = help: only type `()` implements the trait, consider using it directly instead error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-safety-err-ret.rs:18:5 + --> $DIR/dyn-compatibility-err-ret.rs:18:5 | LL | v.test(); | ^^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-err-ret.rs:8:8 + --> $DIR/dyn-compatibility-err-ret.rs:8:8 | LL | trait Foo { | --- this trait cannot be made into an object... diff --git a/tests/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.rs b/tests/ui/const-generics/generic_const_exprs/dyn-compatibility-err-where-bounds.rs similarity index 100% rename from tests/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.rs rename to tests/ui/const-generics/generic_const_exprs/dyn-compatibility-err-where-bounds.rs diff --git a/tests/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.stderr b/tests/ui/const-generics/generic_const_exprs/dyn-compatibility-err-where-bounds.stderr similarity index 88% rename from tests/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.stderr rename to tests/ui/const-generics/generic_const_exprs/dyn-compatibility-err-where-bounds.stderr index 831bda7129542..26ca2d4df5ffc 100644 --- a/tests/ui/const-generics/generic_const_exprs/object-safety-err-where-bounds.stderr +++ b/tests/ui/const-generics/generic_const_exprs/dyn-compatibility-err-where-bounds.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-safety-err-where-bounds.rs:15:16 + --> $DIR/dyn-compatibility-err-where-bounds.rs:15:16 | LL | fn use_dyn(v: &dyn Foo) { | ^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-err-where-bounds.rs:8:8 + --> $DIR/dyn-compatibility-err-where-bounds.rs:8:8 | LL | trait Foo { | --- this trait cannot be made into an object... @@ -15,13 +15,13 @@ LL | fn test(&self) where [u8; bar::()]: Sized; = help: only type `()` implements the trait, consider using it directly instead error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-safety-err-where-bounds.rs:17:5 + --> $DIR/dyn-compatibility-err-where-bounds.rs:17:5 | LL | v.test(); | ^^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-err-where-bounds.rs:8:8 + --> $DIR/dyn-compatibility-err-where-bounds.rs:8:8 | LL | trait Foo { | --- this trait cannot be made into an object... diff --git a/tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs b/tests/ui/const-generics/generic_const_exprs/dyn-compatibility-ok-infer-err.rs similarity index 100% rename from tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.rs rename to tests/ui/const-generics/generic_const_exprs/dyn-compatibility-ok-infer-err.rs diff --git a/tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.stderr b/tests/ui/const-generics/generic_const_exprs/dyn-compatibility-ok-infer-err.stderr similarity index 85% rename from tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.stderr rename to tests/ui/const-generics/generic_const_exprs/dyn-compatibility-ok-infer-err.stderr index d1e1c976da664..a124fbc60920d 100644 --- a/tests/ui/const-generics/generic_const_exprs/object-safety-ok-infer-err.stderr +++ b/tests/ui/const-generics/generic_const_exprs/dyn-compatibility-ok-infer-err.stderr @@ -1,11 +1,11 @@ error[E0284]: type annotations needed - --> $DIR/object-safety-ok-infer-err.rs:19:5 + --> $DIR/dyn-compatibility-ok-infer-err.rs:19:5 | LL | use_dyn(&()); | ^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `use_dyn` | note: required by a const generic parameter in `use_dyn` - --> $DIR/object-safety-ok-infer-err.rs:14:12 + --> $DIR/dyn-compatibility-ok-infer-err.rs:14:12 | LL | fn use_dyn(v: &dyn Foo) where [u8; N + 1]: Sized { | ^^^^^^^^^^^^^^ required by this const generic parameter in `use_dyn` @@ -15,7 +15,7 @@ LL | use_dyn::(&()); | +++++ error[E0284]: type annotations needed - --> $DIR/object-safety-ok-infer-err.rs:19:5 + --> $DIR/dyn-compatibility-ok-infer-err.rs:19:5 | LL | use_dyn(&()); | ^^^^^^^ --- type must be known at this point @@ -23,7 +23,7 @@ LL | use_dyn(&()); | cannot infer the value of the const parameter `N` declared on the function `use_dyn` | note: required for `()` to implement `Foo<_>` - --> $DIR/object-safety-ok-infer-err.rs:8:22 + --> $DIR/dyn-compatibility-ok-infer-err.rs:8:22 | LL | impl Foo for () { | -------------- ^^^^^^ ^^ diff --git a/tests/ui/const-generics/generic_const_exprs/object-safety-ok.rs b/tests/ui/const-generics/generic_const_exprs/dyn-compatibility-ok.rs similarity index 100% rename from tests/ui/const-generics/generic_const_exprs/object-safety-ok.rs rename to tests/ui/const-generics/generic_const_exprs/dyn-compatibility-ok.rs diff --git a/tests/ui/object-safety/almost-supertrait-associated-type.rs b/tests/ui/dyn-compatibility/almost-supertrait-associated-type.rs similarity index 95% rename from tests/ui/object-safety/almost-supertrait-associated-type.rs rename to tests/ui/dyn-compatibility/almost-supertrait-associated-type.rs index 963cdff526ee6..83076f7d5fc3b 100644 --- a/tests/ui/object-safety/almost-supertrait-associated-type.rs +++ b/tests/ui/dyn-compatibility/almost-supertrait-associated-type.rs @@ -1,5 +1,5 @@ // Test for fixed unsoundness in #126079. -// Enforces that the associated types that are object safe +// Enforces that the associated types that are dyn-compatible. use std::marker::PhantomData; diff --git a/tests/ui/object-safety/almost-supertrait-associated-type.stderr b/tests/ui/dyn-compatibility/almost-supertrait-associated-type.stderr similarity index 100% rename from tests/ui/object-safety/almost-supertrait-associated-type.stderr rename to tests/ui/dyn-compatibility/almost-supertrait-associated-type.stderr diff --git a/tests/ui/object-safety/assoc_const_bounds.rs b/tests/ui/dyn-compatibility/assoc_const_bounds.rs similarity index 100% rename from tests/ui/object-safety/assoc_const_bounds.rs rename to tests/ui/dyn-compatibility/assoc_const_bounds.rs diff --git a/tests/ui/object-safety/assoc_const_bounds_sized.rs b/tests/ui/dyn-compatibility/assoc_const_bounds_sized.rs similarity index 100% rename from tests/ui/object-safety/assoc_const_bounds_sized.rs rename to tests/ui/dyn-compatibility/assoc_const_bounds_sized.rs diff --git a/tests/ui/object-safety/assoc_type_bounds.rs b/tests/ui/dyn-compatibility/assoc_type_bounds.rs similarity index 100% rename from tests/ui/object-safety/assoc_type_bounds.rs rename to tests/ui/dyn-compatibility/assoc_type_bounds.rs diff --git a/tests/ui/object-safety/assoc_type_bounds.stderr b/tests/ui/dyn-compatibility/assoc_type_bounds.stderr similarity index 100% rename from tests/ui/object-safety/assoc_type_bounds.stderr rename to tests/ui/dyn-compatibility/assoc_type_bounds.stderr diff --git a/tests/ui/object-safety/assoc_type_bounds2.rs b/tests/ui/dyn-compatibility/assoc_type_bounds2.rs similarity index 100% rename from tests/ui/object-safety/assoc_type_bounds2.rs rename to tests/ui/dyn-compatibility/assoc_type_bounds2.rs diff --git a/tests/ui/object-safety/assoc_type_bounds2.stderr b/tests/ui/dyn-compatibility/assoc_type_bounds2.stderr similarity index 100% rename from tests/ui/object-safety/assoc_type_bounds2.stderr rename to tests/ui/dyn-compatibility/assoc_type_bounds2.stderr diff --git a/tests/ui/object-safety/assoc_type_bounds_implicit_sized.fixed b/tests/ui/dyn-compatibility/assoc_type_bounds_implicit_sized.fixed similarity index 100% rename from tests/ui/object-safety/assoc_type_bounds_implicit_sized.fixed rename to tests/ui/dyn-compatibility/assoc_type_bounds_implicit_sized.fixed diff --git a/tests/ui/object-safety/assoc_type_bounds_implicit_sized.rs b/tests/ui/dyn-compatibility/assoc_type_bounds_implicit_sized.rs similarity index 100% rename from tests/ui/object-safety/assoc_type_bounds_implicit_sized.rs rename to tests/ui/dyn-compatibility/assoc_type_bounds_implicit_sized.rs diff --git a/tests/ui/object-safety/assoc_type_bounds_implicit_sized.stderr b/tests/ui/dyn-compatibility/assoc_type_bounds_implicit_sized.stderr similarity index 100% rename from tests/ui/object-safety/assoc_type_bounds_implicit_sized.stderr rename to tests/ui/dyn-compatibility/assoc_type_bounds_implicit_sized.stderr diff --git a/tests/ui/object-safety/assoc_type_bounds_sized.rs b/tests/ui/dyn-compatibility/assoc_type_bounds_sized.rs similarity index 100% rename from tests/ui/object-safety/assoc_type_bounds_sized.rs rename to tests/ui/dyn-compatibility/assoc_type_bounds_sized.rs diff --git a/tests/ui/object-safety/assoc_type_bounds_sized_others.rs b/tests/ui/dyn-compatibility/assoc_type_bounds_sized_others.rs similarity index 100% rename from tests/ui/object-safety/assoc_type_bounds_sized_others.rs rename to tests/ui/dyn-compatibility/assoc_type_bounds_sized_others.rs diff --git a/tests/ui/object-safety/assoc_type_bounds_sized_others.stderr b/tests/ui/dyn-compatibility/assoc_type_bounds_sized_others.stderr similarity index 100% rename from tests/ui/object-safety/assoc_type_bounds_sized_others.stderr rename to tests/ui/dyn-compatibility/assoc_type_bounds_sized_others.stderr diff --git a/tests/ui/object-safety/assoc_type_bounds_sized_unnecessary.rs b/tests/ui/dyn-compatibility/assoc_type_bounds_sized_unnecessary.rs similarity index 100% rename from tests/ui/object-safety/assoc_type_bounds_sized_unnecessary.rs rename to tests/ui/dyn-compatibility/assoc_type_bounds_sized_unnecessary.rs diff --git a/tests/ui/object-safety/assoc_type_bounds_sized_unnecessary.stderr b/tests/ui/dyn-compatibility/assoc_type_bounds_sized_unnecessary.stderr similarity index 100% rename from tests/ui/object-safety/assoc_type_bounds_sized_unnecessary.stderr rename to tests/ui/dyn-compatibility/assoc_type_bounds_sized_unnecessary.stderr diff --git a/tests/ui/object-safety/assoc_type_bounds_sized_used.rs b/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.rs similarity index 100% rename from tests/ui/object-safety/assoc_type_bounds_sized_used.rs rename to tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.rs diff --git a/tests/ui/object-safety/assoc_type_bounds_sized_used.stderr b/tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.stderr similarity index 100% rename from tests/ui/object-safety/assoc_type_bounds_sized_used.stderr rename to tests/ui/dyn-compatibility/assoc_type_bounds_sized_used.stderr diff --git a/tests/ui/object-safety/object-safety-associated-consts.curr.stderr b/tests/ui/dyn-compatibility/associated-consts.curr.stderr similarity index 86% rename from tests/ui/object-safety/object-safety-associated-consts.curr.stderr rename to tests/ui/dyn-compatibility/associated-consts.curr.stderr index 3c070f17c82ad..17d184942c701 100644 --- a/tests/ui/object-safety/object-safety-associated-consts.curr.stderr +++ b/tests/ui/dyn-compatibility/associated-consts.curr.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-associated-consts.rs:12:31 + --> $DIR/associated-consts.rs:12:31 | LL | fn make_bar(t: &T) -> &dyn Bar { | ^^^^^^^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-associated-consts.rs:9:11 + --> $DIR/associated-consts.rs:9:11 | LL | trait Bar { | --- this trait cannot be made into an object... @@ -14,13 +14,13 @@ LL | const X: usize; = help: consider moving `X` to another trait error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-associated-consts.rs:14:5 + --> $DIR/associated-consts.rs:14:5 | LL | t | ^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-associated-consts.rs:9:11 + --> $DIR/associated-consts.rs:9:11 | LL | trait Bar { | --- this trait cannot be made into an object... diff --git a/tests/ui/object-safety/object-safety-associated-consts.dyn_compatible_for_dispatch.stderr b/tests/ui/dyn-compatibility/associated-consts.dyn_compatible_for_dispatch.stderr similarity index 87% rename from tests/ui/object-safety/object-safety-associated-consts.dyn_compatible_for_dispatch.stderr rename to tests/ui/dyn-compatibility/associated-consts.dyn_compatible_for_dispatch.stderr index 5b98cc35505c6..cc5120232c244 100644 --- a/tests/ui/object-safety/object-safety-associated-consts.dyn_compatible_for_dispatch.stderr +++ b/tests/ui/dyn-compatibility/associated-consts.dyn_compatible_for_dispatch.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-associated-consts.rs:14:5 + --> $DIR/associated-consts.rs:14:5 | LL | t | ^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-associated-consts.rs:9:11 + --> $DIR/associated-consts.rs:9:11 | LL | trait Bar { | --- this trait cannot be made into an object... diff --git a/tests/ui/object-safety/object-safety-associated-consts.rs b/tests/ui/dyn-compatibility/associated-consts.rs similarity index 100% rename from tests/ui/object-safety/object-safety-associated-consts.rs rename to tests/ui/dyn-compatibility/associated-consts.rs diff --git a/tests/ui/object-safety/avoid-ice-on-warning-2.new.stderr b/tests/ui/dyn-compatibility/avoid-ice-on-warning-2.new.stderr similarity index 100% rename from tests/ui/object-safety/avoid-ice-on-warning-2.new.stderr rename to tests/ui/dyn-compatibility/avoid-ice-on-warning-2.new.stderr diff --git a/tests/ui/object-safety/avoid-ice-on-warning-2.old.stderr b/tests/ui/dyn-compatibility/avoid-ice-on-warning-2.old.stderr similarity index 100% rename from tests/ui/object-safety/avoid-ice-on-warning-2.old.stderr rename to tests/ui/dyn-compatibility/avoid-ice-on-warning-2.old.stderr diff --git a/tests/ui/object-safety/avoid-ice-on-warning-2.rs b/tests/ui/dyn-compatibility/avoid-ice-on-warning-2.rs similarity index 100% rename from tests/ui/object-safety/avoid-ice-on-warning-2.rs rename to tests/ui/dyn-compatibility/avoid-ice-on-warning-2.rs diff --git a/tests/ui/object-safety/avoid-ice-on-warning-3.new.stderr b/tests/ui/dyn-compatibility/avoid-ice-on-warning-3.new.stderr similarity index 100% rename from tests/ui/object-safety/avoid-ice-on-warning-3.new.stderr rename to tests/ui/dyn-compatibility/avoid-ice-on-warning-3.new.stderr diff --git a/tests/ui/object-safety/avoid-ice-on-warning-3.old.stderr b/tests/ui/dyn-compatibility/avoid-ice-on-warning-3.old.stderr similarity index 100% rename from tests/ui/object-safety/avoid-ice-on-warning-3.old.stderr rename to tests/ui/dyn-compatibility/avoid-ice-on-warning-3.old.stderr diff --git a/tests/ui/object-safety/avoid-ice-on-warning-3.rs b/tests/ui/dyn-compatibility/avoid-ice-on-warning-3.rs similarity index 100% rename from tests/ui/object-safety/avoid-ice-on-warning-3.rs rename to tests/ui/dyn-compatibility/avoid-ice-on-warning-3.rs diff --git a/tests/ui/object-safety/avoid-ice-on-warning.new.stderr b/tests/ui/dyn-compatibility/avoid-ice-on-warning.new.stderr similarity index 100% rename from tests/ui/object-safety/avoid-ice-on-warning.new.stderr rename to tests/ui/dyn-compatibility/avoid-ice-on-warning.new.stderr diff --git a/tests/ui/object-safety/avoid-ice-on-warning.old.stderr b/tests/ui/dyn-compatibility/avoid-ice-on-warning.old.stderr similarity index 100% rename from tests/ui/object-safety/avoid-ice-on-warning.old.stderr rename to tests/ui/dyn-compatibility/avoid-ice-on-warning.old.stderr diff --git a/tests/ui/object-safety/avoid-ice-on-warning.rs b/tests/ui/dyn-compatibility/avoid-ice-on-warning.rs similarity index 100% rename from tests/ui/object-safety/avoid-ice-on-warning.rs rename to tests/ui/dyn-compatibility/avoid-ice-on-warning.rs diff --git a/tests/ui/object-safety/bare-trait-dont-suggest-dyn.new.fixed b/tests/ui/dyn-compatibility/bare-trait-dont-suggest-dyn.new.fixed similarity index 100% rename from tests/ui/object-safety/bare-trait-dont-suggest-dyn.new.fixed rename to tests/ui/dyn-compatibility/bare-trait-dont-suggest-dyn.new.fixed diff --git a/tests/ui/object-safety/bare-trait-dont-suggest-dyn.new.stderr b/tests/ui/dyn-compatibility/bare-trait-dont-suggest-dyn.new.stderr similarity index 100% rename from tests/ui/object-safety/bare-trait-dont-suggest-dyn.new.stderr rename to tests/ui/dyn-compatibility/bare-trait-dont-suggest-dyn.new.stderr diff --git a/tests/ui/object-safety/bare-trait-dont-suggest-dyn.old.stderr b/tests/ui/dyn-compatibility/bare-trait-dont-suggest-dyn.old.stderr similarity index 100% rename from tests/ui/object-safety/bare-trait-dont-suggest-dyn.old.stderr rename to tests/ui/dyn-compatibility/bare-trait-dont-suggest-dyn.old.stderr diff --git a/tests/ui/object-safety/bare-trait-dont-suggest-dyn.rs b/tests/ui/dyn-compatibility/bare-trait-dont-suggest-dyn.rs similarity index 100% rename from tests/ui/object-safety/bare-trait-dont-suggest-dyn.rs rename to tests/ui/dyn-compatibility/bare-trait-dont-suggest-dyn.rs diff --git a/tests/ui/object-safety/object-safety-bounds.rs b/tests/ui/dyn-compatibility/bounds.rs similarity index 72% rename from tests/ui/object-safety/object-safety-bounds.rs rename to tests/ui/dyn-compatibility/bounds.rs index 44bd369324a4b..1e04d11c516cb 100644 --- a/tests/ui/object-safety/object-safety-bounds.rs +++ b/tests/ui/dyn-compatibility/bounds.rs @@ -1,4 +1,4 @@ -// Traits with bounds mentioning `Self` are not object safe +// Traits with bounds mentioning `Self` are dyn-incompatible. trait X { type U: PartialEq; diff --git a/tests/ui/object-safety/object-safety-bounds.stderr b/tests/ui/dyn-compatibility/bounds.stderr similarity index 89% rename from tests/ui/object-safety/object-safety-bounds.stderr rename to tests/ui/dyn-compatibility/bounds.stderr index 96a81a69639bd..9231d524fd173 100644 --- a/tests/ui/object-safety/object-safety-bounds.stderr +++ b/tests/ui/dyn-compatibility/bounds.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `X` cannot be made into an object - --> $DIR/object-safety-bounds.rs:7:15 + --> $DIR/bounds.rs:7:15 | LL | fn f() -> Box> { | ^^^^^^^^^^^^^^ `X` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-bounds.rs:4:13 + --> $DIR/bounds.rs:4:13 | LL | trait X { | - this trait cannot be made into an object... diff --git a/tests/ui/object-safety/object-safety-by-value-self-use.rs b/tests/ui/dyn-compatibility/by-value-self-use.rs similarity index 79% rename from tests/ui/object-safety/object-safety-by-value-self-use.rs rename to tests/ui/dyn-compatibility/by-value-self-use.rs index 8e93c538217bb..3c04ec0cd888c 100644 --- a/tests/ui/object-safety/object-safety-by-value-self-use.rs +++ b/tests/ui/dyn-compatibility/by-value-self-use.rs @@ -1,4 +1,4 @@ -// Check that while a trait with by-value self is object-safe, we +// Check that while a trait with by-value self is dyn-compatible, we // can't actually invoke it from an object (yet...?). #![feature(rustc_attrs)] diff --git a/tests/ui/object-safety/object-safety-by-value-self-use.stderr b/tests/ui/dyn-compatibility/by-value-self-use.stderr similarity index 83% rename from tests/ui/object-safety/object-safety-by-value-self-use.stderr rename to tests/ui/dyn-compatibility/by-value-self-use.stderr index 1701f6059a8ee..14785b982a39e 100644 --- a/tests/ui/object-safety/object-safety-by-value-self-use.stderr +++ b/tests/ui/dyn-compatibility/by-value-self-use.stderr @@ -1,5 +1,5 @@ error[E0161]: cannot move a value of type `dyn Bar` - --> $DIR/object-safety-by-value-self-use.rs:15:5 + --> $DIR/by-value-self-use.rs:15:5 | LL | t.bar() | ^ the size of `dyn Bar` cannot be statically determined diff --git a/tests/ui/object-safety/object-safety-by-value-self.rs b/tests/ui/dyn-compatibility/by-value-self.rs similarity index 90% rename from tests/ui/object-safety/object-safety-by-value-self.rs rename to tests/ui/dyn-compatibility/by-value-self.rs index 0d20032327cae..a057a7ff0b57a 100644 --- a/tests/ui/object-safety/object-safety-by-value-self.rs +++ b/tests/ui/dyn-compatibility/by-value-self.rs @@ -1,4 +1,4 @@ -// Check that a trait with by-value self is considered object-safe. +// Check that a trait with by-value self is considered dyn-compatible. //@ build-pass (FIXME(62277): could be check-pass?) #![allow(dead_code)] diff --git a/tests/ui/object-safety/call-when-assoc-ty-is-sized.rs b/tests/ui/dyn-compatibility/call-when-assoc-ty-is-sized.rs similarity index 100% rename from tests/ui/object-safety/call-when-assoc-ty-is-sized.rs rename to tests/ui/dyn-compatibility/call-when-assoc-ty-is-sized.rs diff --git a/tests/ui/object-safety/issue-102933.rs b/tests/ui/dyn-compatibility/elaborated-predicates-ordering.rs similarity index 93% rename from tests/ui/object-safety/issue-102933.rs rename to tests/ui/dyn-compatibility/elaborated-predicates-ordering.rs index aa678fea17620..d3c3963a673d5 100644 --- a/tests/ui/object-safety/issue-102933.rs +++ b/tests/ui/dyn-compatibility/elaborated-predicates-ordering.rs @@ -1,4 +1,5 @@ //@ check-pass +// issue: rust-lang/rust#102933 use std::future::Future; diff --git a/tests/ui/object-safety/erroneous_signature.rs b/tests/ui/dyn-compatibility/erroneous_signature.rs similarity index 100% rename from tests/ui/object-safety/erroneous_signature.rs rename to tests/ui/dyn-compatibility/erroneous_signature.rs diff --git a/tests/ui/object-safety/erroneous_signature.stderr b/tests/ui/dyn-compatibility/erroneous_signature.stderr similarity index 100% rename from tests/ui/object-safety/erroneous_signature.stderr rename to tests/ui/dyn-compatibility/erroneous_signature.stderr diff --git a/tests/ui/object-safety/object-safety-generics.curr.stderr b/tests/ui/dyn-compatibility/generics.curr.stderr similarity index 88% rename from tests/ui/object-safety/object-safety-generics.curr.stderr rename to tests/ui/dyn-compatibility/generics.curr.stderr index 7528785d90b47..c63db38a080b4 100644 --- a/tests/ui/object-safety/object-safety-generics.curr.stderr +++ b/tests/ui/dyn-compatibility/generics.curr.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-generics.rs:18:31 + --> $DIR/generics.rs:18:31 | LL | fn make_bar(t: &T) -> &dyn Bar { | ^^^^^^^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-generics.rs:10:8 + --> $DIR/generics.rs:10:8 | LL | trait Bar { | --- this trait cannot be made into an object... @@ -14,13 +14,13 @@ LL | fn bar(&self, t: T); = help: consider moving `bar` to another trait error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-generics.rs:25:40 + --> $DIR/generics.rs:25:40 | LL | fn make_bar_explicit(t: &T) -> &dyn Bar { | ^^^^^^^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-generics.rs:10:8 + --> $DIR/generics.rs:10:8 | LL | trait Bar { | --- this trait cannot be made into an object... @@ -29,13 +29,13 @@ LL | fn bar(&self, t: T); = help: consider moving `bar` to another trait error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-generics.rs:20:5 + --> $DIR/generics.rs:20:5 | LL | t | ^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-generics.rs:10:8 + --> $DIR/generics.rs:10:8 | LL | trait Bar { | --- this trait cannot be made into an object... @@ -45,13 +45,13 @@ LL | fn bar(&self, t: T); = note: required for the cast from `&T` to `&dyn Bar` error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-generics.rs:27:10 + --> $DIR/generics.rs:27:10 | LL | t as &dyn Bar | ^^^^^^^^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-generics.rs:10:8 + --> $DIR/generics.rs:10:8 | LL | trait Bar { | --- this trait cannot be made into an object... @@ -60,13 +60,13 @@ LL | fn bar(&self, t: T); = help: consider moving `bar` to another trait error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-generics.rs:27:5 + --> $DIR/generics.rs:27:5 | LL | t as &dyn Bar | ^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-generics.rs:10:8 + --> $DIR/generics.rs:10:8 | LL | trait Bar { | --- this trait cannot be made into an object... diff --git a/tests/ui/object-safety/object-safety-generics.dyn_compatible_for_dispatch.stderr b/tests/ui/dyn-compatibility/generics.dyn_compatible_for_dispatch.stderr similarity index 89% rename from tests/ui/object-safety/object-safety-generics.dyn_compatible_for_dispatch.stderr rename to tests/ui/dyn-compatibility/generics.dyn_compatible_for_dispatch.stderr index 4686b994b33ed..ba2546ef2dc5c 100644 --- a/tests/ui/object-safety/object-safety-generics.dyn_compatible_for_dispatch.stderr +++ b/tests/ui/dyn-compatibility/generics.dyn_compatible_for_dispatch.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-generics.rs:20:5 + --> $DIR/generics.rs:20:5 | LL | t | ^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-generics.rs:10:8 + --> $DIR/generics.rs:10:8 | LL | trait Bar { | --- this trait cannot be made into an object... @@ -15,13 +15,13 @@ LL | fn bar(&self, t: T); = note: required for the cast from `&T` to `&dyn Bar` error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-generics.rs:27:5 + --> $DIR/generics.rs:27:5 | LL | t as &dyn Bar | ^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-generics.rs:10:8 + --> $DIR/generics.rs:10:8 | LL | trait Bar { | --- this trait cannot be made into an object... diff --git a/tests/ui/object-safety/object-safety-generics.rs b/tests/ui/dyn-compatibility/generics.rs similarity index 100% rename from tests/ui/object-safety/object-safety-generics.rs rename to tests/ui/dyn-compatibility/generics.rs diff --git a/tests/ui/object-safety/issue-106247.rs b/tests/ui/dyn-compatibility/impossible-predicates-multiple_supertrait_upcastable-check.rs similarity index 73% rename from tests/ui/object-safety/issue-106247.rs rename to tests/ui/dyn-compatibility/impossible-predicates-multiple_supertrait_upcastable-check.rs index 20a451a59a164..c2b8ecc141d7d 100644 --- a/tests/ui/object-safety/issue-106247.rs +++ b/tests/ui/dyn-compatibility/impossible-predicates-multiple_supertrait_upcastable-check.rs @@ -1,4 +1,5 @@ //@ check-pass +// issue: rust-lang/rust#106247 pub trait Trait { fn method(&self) where Self: Sync; diff --git a/tests/ui/object-safety/item-bounds-can-reference-self.rs b/tests/ui/dyn-compatibility/item-bounds-can-reference-self.rs similarity index 100% rename from tests/ui/object-safety/item-bounds-can-reference-self.rs rename to tests/ui/dyn-compatibility/item-bounds-can-reference-self.rs diff --git a/tests/ui/object-safety/issue-19538.rs b/tests/ui/dyn-compatibility/mention-correct-dyn-incompatible-trait.rs similarity index 90% rename from tests/ui/object-safety/issue-19538.rs rename to tests/ui/dyn-compatibility/mention-correct-dyn-incompatible-trait.rs index 7054ef41b1c82..1289d2d7874aa 100644 --- a/tests/ui/object-safety/issue-19538.rs +++ b/tests/ui/dyn-compatibility/mention-correct-dyn-incompatible-trait.rs @@ -1,3 +1,5 @@ +// issue: rust-lang/rust#19538 + trait Foo { fn foo(&self, val: T); } diff --git a/tests/ui/object-safety/issue-19538.stderr b/tests/ui/dyn-compatibility/mention-correct-dyn-incompatible-trait.stderr similarity index 87% rename from tests/ui/object-safety/issue-19538.stderr rename to tests/ui/dyn-compatibility/mention-correct-dyn-incompatible-trait.stderr index 3dbe389686a44..7378ec023c926 100644 --- a/tests/ui/object-safety/issue-19538.stderr +++ b/tests/ui/dyn-compatibility/mention-correct-dyn-incompatible-trait.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/issue-19538.rs:17:15 + --> $DIR/mention-correct-dyn-incompatible-trait.rs:19:15 | LL | let test: &mut dyn Bar = &mut thing; | ^^^^^^^^^^^^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/issue-19538.rs:2:8 + --> $DIR/mention-correct-dyn-incompatible-trait.rs:4:8 | LL | fn foo(&self, val: T); | ^^^ ...because method `foo` has generic type parameters @@ -16,13 +16,13 @@ LL | trait Bar: Foo { } = help: only type `Thing` implements the trait, consider using it directly instead error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/issue-19538.rs:17:30 + --> $DIR/mention-correct-dyn-incompatible-trait.rs:19:30 | LL | let test: &mut dyn Bar = &mut thing; | ^^^^^^^^^^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/issue-19538.rs:2:8 + --> $DIR/mention-correct-dyn-incompatible-trait.rs:4:8 | LL | fn foo(&self, val: T); | ^^^ ...because method `foo` has generic type parameters diff --git a/tests/ui/object-safety/object-safety-issue-22040.rs b/tests/ui/dyn-compatibility/mentions-Self-in-super-predicates.rs similarity index 100% rename from tests/ui/object-safety/object-safety-issue-22040.rs rename to tests/ui/dyn-compatibility/mentions-Self-in-super-predicates.rs diff --git a/tests/ui/object-safety/object-safety-issue-22040.stderr b/tests/ui/dyn-compatibility/mentions-Self-in-super-predicates.stderr similarity index 87% rename from tests/ui/object-safety/object-safety-issue-22040.stderr rename to tests/ui/dyn-compatibility/mentions-Self-in-super-predicates.stderr index e5723f12258fe..7578edce7d19e 100644 --- a/tests/ui/object-safety/object-safety-issue-22040.stderr +++ b/tests/ui/dyn-compatibility/mentions-Self-in-super-predicates.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Expr` cannot be made into an object - --> $DIR/object-safety-issue-22040.rs:12:23 + --> $DIR/mentions-Self-in-super-predicates.rs:12:23 | LL | elements: Vec>, | ^^^^^^^^^^^^^ `Expr` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-issue-22040.rs:5:21 + --> $DIR/mentions-Self-in-super-predicates.rs:5:21 | LL | trait Expr: Debug + PartialEq { | ---- ^^^^^^^^^ ...because it uses `Self` as a type parameter @@ -14,13 +14,13 @@ LL | trait Expr: Debug + PartialEq { = help: only type `SExpr<'x>` implements the trait, consider using it directly instead error[E0038]: the trait `Expr` cannot be made into an object - --> $DIR/object-safety-issue-22040.rs:38:16 + --> $DIR/mentions-Self-in-super-predicates.rs:38:16 | LL | let a: Box = Box::new(SExpr::new()); | ^^^^^^^^ `Expr` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-issue-22040.rs:5:21 + --> $DIR/mentions-Self-in-super-predicates.rs:5:21 | LL | trait Expr: Debug + PartialEq { | ---- ^^^^^^^^^ ...because it uses `Self` as a type parameter @@ -29,13 +29,13 @@ LL | trait Expr: Debug + PartialEq { = help: only type `SExpr<'x>` implements the trait, consider using it directly instead error[E0038]: the trait `Expr` cannot be made into an object - --> $DIR/object-safety-issue-22040.rs:40:16 + --> $DIR/mentions-Self-in-super-predicates.rs:40:16 | LL | let b: Box = Box::new(SExpr::new()); | ^^^^^^^^ `Expr` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-issue-22040.rs:5:21 + --> $DIR/mentions-Self-in-super-predicates.rs:5:21 | LL | trait Expr: Debug + PartialEq { | ---- ^^^^^^^^^ ...because it uses `Self` as a type parameter diff --git a/tests/ui/object-safety/object-safety-mentions-Self.curr.stderr b/tests/ui/dyn-compatibility/mentions-Self.curr.stderr similarity index 88% rename from tests/ui/object-safety/object-safety-mentions-Self.curr.stderr rename to tests/ui/dyn-compatibility/mentions-Self.curr.stderr index 7efb6ec3542d0..434e41cf2182d 100644 --- a/tests/ui/object-safety/object-safety-mentions-Self.curr.stderr +++ b/tests/ui/dyn-compatibility/mentions-Self.curr.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-mentions-Self.rs:22:31 + --> $DIR/mentions-Self.rs:22:31 | LL | fn make_bar(t: &T) -> &dyn Bar { | ^^^^^^^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-mentions-Self.rs:11:22 + --> $DIR/mentions-Self.rs:11:22 | LL | trait Bar { | --- this trait cannot be made into an object... @@ -14,13 +14,13 @@ LL | fn bar(&self, x: &Self); = help: consider moving `bar` to another trait error[E0038]: the trait `Baz` cannot be made into an object - --> $DIR/object-safety-mentions-Self.rs:28:31 + --> $DIR/mentions-Self.rs:28:31 | LL | fn make_baz(t: &T) -> &dyn Baz { | ^^^^^^^ `Baz` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-mentions-Self.rs:15:22 + --> $DIR/mentions-Self.rs:15:22 | LL | trait Baz { | --- this trait cannot be made into an object... @@ -29,13 +29,13 @@ LL | fn baz(&self) -> Self; = help: consider moving `baz` to another trait error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-mentions-Self.rs:24:5 + --> $DIR/mentions-Self.rs:24:5 | LL | t | ^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-mentions-Self.rs:11:22 + --> $DIR/mentions-Self.rs:11:22 | LL | trait Bar { | --- this trait cannot be made into an object... @@ -45,13 +45,13 @@ LL | fn bar(&self, x: &Self); = note: required for the cast from `&T` to `&dyn Bar` error[E0038]: the trait `Baz` cannot be made into an object - --> $DIR/object-safety-mentions-Self.rs:30:5 + --> $DIR/mentions-Self.rs:30:5 | LL | t | ^ `Baz` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-mentions-Self.rs:15:22 + --> $DIR/mentions-Self.rs:15:22 | LL | trait Baz { | --- this trait cannot be made into an object... diff --git a/tests/ui/object-safety/object-safety-mentions-Self.dyn_compatible_for_dispatch.stderr b/tests/ui/dyn-compatibility/mentions-Self.dyn_compatible_for_dispatch.stderr similarity index 88% rename from tests/ui/object-safety/object-safety-mentions-Self.dyn_compatible_for_dispatch.stderr rename to tests/ui/dyn-compatibility/mentions-Self.dyn_compatible_for_dispatch.stderr index d0efb9c587e4e..dc2d1f87eb737 100644 --- a/tests/ui/object-safety/object-safety-mentions-Self.dyn_compatible_for_dispatch.stderr +++ b/tests/ui/dyn-compatibility/mentions-Self.dyn_compatible_for_dispatch.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-mentions-Self.rs:24:5 + --> $DIR/mentions-Self.rs:24:5 | LL | t | ^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-mentions-Self.rs:11:22 + --> $DIR/mentions-Self.rs:11:22 | LL | trait Bar { | --- this trait cannot be made into an object... @@ -15,13 +15,13 @@ LL | fn bar(&self, x: &Self); = note: required for the cast from `&T` to `&dyn Bar` error[E0038]: the trait `Baz` cannot be made into an object - --> $DIR/object-safety-mentions-Self.rs:30:5 + --> $DIR/mentions-Self.rs:30:5 | LL | t | ^ `Baz` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-mentions-Self.rs:15:22 + --> $DIR/mentions-Self.rs:15:22 | LL | trait Baz { | --- this trait cannot be made into an object... diff --git a/tests/ui/object-safety/object-safety-mentions-Self.rs b/tests/ui/dyn-compatibility/mentions-Self.rs similarity index 100% rename from tests/ui/object-safety/object-safety-mentions-Self.rs rename to tests/ui/dyn-compatibility/mentions-Self.rs diff --git a/tests/ui/traits/object/object-unsafe-missing-assoc-type.rs b/tests/ui/dyn-compatibility/missing-assoc-type.rs similarity index 100% rename from tests/ui/traits/object/object-unsafe-missing-assoc-type.rs rename to tests/ui/dyn-compatibility/missing-assoc-type.rs diff --git a/tests/ui/traits/object/object-unsafe-missing-assoc-type.stderr b/tests/ui/dyn-compatibility/missing-assoc-type.stderr similarity index 86% rename from tests/ui/traits/object/object-unsafe-missing-assoc-type.stderr rename to tests/ui/dyn-compatibility/missing-assoc-type.stderr index 9258b38f26c3a..f8450ba212d03 100644 --- a/tests/ui/traits/object/object-unsafe-missing-assoc-type.stderr +++ b/tests/ui/dyn-compatibility/missing-assoc-type.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-unsafe-missing-assoc-type.rs:5:16 + --> $DIR/missing-assoc-type.rs:5:16 | LL | fn bar(x: &dyn Foo) {} | ^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-missing-assoc-type.rs:2:10 + --> $DIR/missing-assoc-type.rs:2:10 | LL | trait Foo { | --- this trait cannot be made into an object... @@ -14,13 +14,13 @@ LL | type Bar; = help: consider moving `Bar` to another trait error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-unsafe-missing-assoc-type.rs:5:16 + --> $DIR/missing-assoc-type.rs:5:16 | LL | fn bar(x: &dyn Foo) {} | ^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-missing-assoc-type.rs:2:10 + --> $DIR/missing-assoc-type.rs:2:10 | LL | trait Foo { | --- this trait cannot be made into an object... @@ -30,13 +30,13 @@ LL | type Bar; = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-unsafe-missing-assoc-type.rs:5:16 + --> $DIR/missing-assoc-type.rs:5:16 | LL | fn bar(x: &dyn Foo) {} | ^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-missing-assoc-type.rs:2:10 + --> $DIR/missing-assoc-type.rs:2:10 | LL | trait Foo { | --- this trait cannot be made into an object... @@ -46,13 +46,13 @@ LL | type Bar; = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-unsafe-missing-assoc-type.rs:5:12 + --> $DIR/missing-assoc-type.rs:5:12 | LL | fn bar(x: &dyn Foo) {} | ^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-missing-assoc-type.rs:2:10 + --> $DIR/missing-assoc-type.rs:2:10 | LL | trait Foo { | --- this trait cannot be made into an object... diff --git a/tests/ui/object-safety/object-safety-no-static.curr.stderr b/tests/ui/dyn-compatibility/no-static.curr.stderr similarity index 92% rename from tests/ui/object-safety/object-safety-no-static.curr.stderr rename to tests/ui/dyn-compatibility/no-static.curr.stderr index 91c3d89602e86..584db77985566 100644 --- a/tests/ui/object-safety/object-safety-no-static.curr.stderr +++ b/tests/ui/dyn-compatibility/no-static.curr.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-safety-no-static.rs:12:22 + --> $DIR/no-static.rs:12:22 | LL | fn diverges() -> Box { | ^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-no-static.rs:9:8 + --> $DIR/no-static.rs:9:8 | LL | trait Foo { | --- this trait cannot be made into an object... @@ -22,13 +22,13 @@ LL | fn foo() where Self: Sized {} | +++++++++++++++++ error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-safety-no-static.rs:22:12 + --> $DIR/no-static.rs:22:12 | LL | let b: Box = Box::new(Bar); | ^^^^^^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-no-static.rs:9:8 + --> $DIR/no-static.rs:9:8 | LL | trait Foo { | --- this trait cannot be made into an object... @@ -45,13 +45,13 @@ LL | fn foo() where Self: Sized {} | +++++++++++++++++ error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-safety-no-static.rs:22:27 + --> $DIR/no-static.rs:22:27 | LL | let b: Box = Box::new(Bar); | ^^^^^^^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-no-static.rs:9:8 + --> $DIR/no-static.rs:9:8 | LL | trait Foo { | --- this trait cannot be made into an object... diff --git a/tests/ui/object-safety/object-safety-no-static.dyn_compatible_for_dispatch.stderr b/tests/ui/dyn-compatibility/no-static.dyn_compatible_for_dispatch.stderr similarity index 93% rename from tests/ui/object-safety/object-safety-no-static.dyn_compatible_for_dispatch.stderr rename to tests/ui/dyn-compatibility/no-static.dyn_compatible_for_dispatch.stderr index 52f6865b6f3cb..f2deb3b8d84b9 100644 --- a/tests/ui/object-safety/object-safety-no-static.dyn_compatible_for_dispatch.stderr +++ b/tests/ui/dyn-compatibility/no-static.dyn_compatible_for_dispatch.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-safety-no-static.rs:22:27 + --> $DIR/no-static.rs:22:27 | LL | let b: Box = Box::new(Bar); | ^^^^^^^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-no-static.rs:9:8 + --> $DIR/no-static.rs:9:8 | LL | trait Foo { | --- this trait cannot be made into an object... diff --git a/tests/ui/object-safety/object-safety-no-static.rs b/tests/ui/dyn-compatibility/no-static.rs similarity index 100% rename from tests/ui/object-safety/object-safety-no-static.rs rename to tests/ui/dyn-compatibility/no-static.rs diff --git a/tests/ui/object-safety/object-safety-phantom-fn.rs b/tests/ui/dyn-compatibility/phantom-fn.rs similarity index 92% rename from tests/ui/object-safety/object-safety-phantom-fn.rs rename to tests/ui/dyn-compatibility/phantom-fn.rs index 1019c24859fba..9e410da82eed5 100644 --- a/tests/ui/object-safety/object-safety-phantom-fn.rs +++ b/tests/ui/dyn-compatibility/phantom-fn.rs @@ -1,4 +1,4 @@ -// Check that `Self` appearing in a phantom fn does not make a trait not object safe. +// Check that `Self` appearing in a phantom fn does not make a trait dyn-incompatible. //@ build-pass (FIXME(62277): could be check-pass?) #![allow(dead_code)] diff --git a/tests/ui/object-safety/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.rs b/tests/ui/dyn-compatibility/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.rs similarity index 100% rename from tests/ui/object-safety/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.rs rename to tests/ui/dyn-compatibility/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.rs diff --git a/tests/ui/object-safety/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.stderr b/tests/ui/dyn-compatibility/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.stderr similarity index 100% rename from tests/ui/object-safety/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.stderr rename to tests/ui/dyn-compatibility/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.stderr diff --git a/tests/ui/object-safety/object-safety-sized-2.curr.stderr b/tests/ui/dyn-compatibility/sized-2.curr.stderr similarity index 88% rename from tests/ui/object-safety/object-safety-sized-2.curr.stderr rename to tests/ui/dyn-compatibility/sized-2.curr.stderr index 4ce7ac5704e42..1017fde53d313 100644 --- a/tests/ui/object-safety/object-safety-sized-2.curr.stderr +++ b/tests/ui/dyn-compatibility/sized-2.curr.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-sized-2.rs:14:31 + --> $DIR/sized-2.rs:14:31 | LL | fn make_bar(t: &T) -> &dyn Bar { | ^^^^^^^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-sized-2.rs:9:18 + --> $DIR/sized-2.rs:9:18 | LL | trait Bar | --- this trait cannot be made into an object... @@ -13,13 +13,13 @@ LL | where Self : Sized | ^^^^^ ...because it requires `Self: Sized` error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-sized-2.rs:16:5 + --> $DIR/sized-2.rs:16:5 | LL | t | ^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-sized-2.rs:9:18 + --> $DIR/sized-2.rs:9:18 | LL | trait Bar | --- this trait cannot be made into an object... diff --git a/tests/ui/object-safety/object-safety-sized-2.dyn_compatible_for_dispatch.stderr b/tests/ui/dyn-compatibility/sized-2.dyn_compatible_for_dispatch.stderr similarity index 89% rename from tests/ui/object-safety/object-safety-sized-2.dyn_compatible_for_dispatch.stderr rename to tests/ui/dyn-compatibility/sized-2.dyn_compatible_for_dispatch.stderr index 99066c104b7cb..534cf0f1b033f 100644 --- a/tests/ui/object-safety/object-safety-sized-2.dyn_compatible_for_dispatch.stderr +++ b/tests/ui/dyn-compatibility/sized-2.dyn_compatible_for_dispatch.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-sized-2.rs:16:5 + --> $DIR/sized-2.rs:16:5 | LL | t | ^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-sized-2.rs:9:18 + --> $DIR/sized-2.rs:9:18 | LL | trait Bar | --- this trait cannot be made into an object... diff --git a/tests/ui/object-safety/object-safety-sized-2.rs b/tests/ui/dyn-compatibility/sized-2.rs similarity index 100% rename from tests/ui/object-safety/object-safety-sized-2.rs rename to tests/ui/dyn-compatibility/sized-2.rs diff --git a/tests/ui/object-safety/object-safety-sized.curr.stderr b/tests/ui/dyn-compatibility/sized.curr.stderr similarity index 88% rename from tests/ui/object-safety/object-safety-sized.curr.stderr rename to tests/ui/dyn-compatibility/sized.curr.stderr index b61f968d90210..613833aad12ee 100644 --- a/tests/ui/object-safety/object-safety-sized.curr.stderr +++ b/tests/ui/dyn-compatibility/sized.curr.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-sized.rs:12:32 + --> $DIR/sized.rs:12:32 | LL | fn make_bar(t: &T) -> &dyn Bar { | ^^^^^^^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-sized.rs:8:12 + --> $DIR/sized.rs:8:12 | LL | trait Bar: Sized { | --- ^^^^^ ...because it requires `Self: Sized` @@ -13,13 +13,13 @@ LL | trait Bar: Sized { | this trait cannot be made into an object... error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-sized.rs:14:5 + --> $DIR/sized.rs:14:5 | LL | t | ^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-sized.rs:8:12 + --> $DIR/sized.rs:8:12 | LL | trait Bar: Sized { | --- ^^^^^ ...because it requires `Self: Sized` diff --git a/tests/ui/object-safety/object-safety-sized.dyn_compatible_for_dispatch.stderr b/tests/ui/dyn-compatibility/sized.dyn_compatible_for_dispatch.stderr similarity index 89% rename from tests/ui/object-safety/object-safety-sized.dyn_compatible_for_dispatch.stderr rename to tests/ui/dyn-compatibility/sized.dyn_compatible_for_dispatch.stderr index 5ce713375a49a..cf847bc157785 100644 --- a/tests/ui/object-safety/object-safety-sized.dyn_compatible_for_dispatch.stderr +++ b/tests/ui/dyn-compatibility/sized.dyn_compatible_for_dispatch.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Bar` cannot be made into an object - --> $DIR/object-safety-sized.rs:14:5 + --> $DIR/sized.rs:14:5 | LL | t | ^ `Bar` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-sized.rs:8:12 + --> $DIR/sized.rs:8:12 | LL | trait Bar: Sized { | --- ^^^^^ ...because it requires `Self: Sized` diff --git a/tests/ui/object-safety/object-safety-sized.rs b/tests/ui/dyn-compatibility/sized.rs similarity index 100% rename from tests/ui/object-safety/object-safety-sized.rs rename to tests/ui/dyn-compatibility/sized.rs diff --git a/tests/ui/object-safety/object-safety-supertrait-mentions-GAT.rs b/tests/ui/dyn-compatibility/supertrait-mentions-GAT.rs similarity index 100% rename from tests/ui/object-safety/object-safety-supertrait-mentions-GAT.rs rename to tests/ui/dyn-compatibility/supertrait-mentions-GAT.rs diff --git a/tests/ui/object-safety/object-safety-supertrait-mentions-GAT.stderr b/tests/ui/dyn-compatibility/supertrait-mentions-GAT.stderr similarity index 86% rename from tests/ui/object-safety/object-safety-supertrait-mentions-GAT.stderr rename to tests/ui/dyn-compatibility/supertrait-mentions-GAT.stderr index 4d44627e77926..ac5a5b28d94d4 100644 --- a/tests/ui/object-safety/object-safety-supertrait-mentions-GAT.stderr +++ b/tests/ui/dyn-compatibility/supertrait-mentions-GAT.stderr @@ -1,14 +1,14 @@ error[E0311]: the parameter type `Self` may not live long enough | note: ...that is required by this bound - --> $DIR/object-safety-supertrait-mentions-GAT.rs:6:15 + --> $DIR/supertrait-mentions-GAT.rs:6:15 | LL | Self: 'a; | ^^ = help: consider adding an explicit lifetime bound `Self: 'a`... error: associated item referring to unboxed trait object for its own trait - --> $DIR/object-safety-supertrait-mentions-GAT.rs:10:20 + --> $DIR/supertrait-mentions-GAT.rs:10:20 | LL | trait SuperTrait: for<'a> GatTrait = T> { | ---------- in this trait @@ -21,13 +21,13 @@ LL | fn c(&self) -> Self; | ~~~~ error[E0038]: the trait `SuperTrait` cannot be made into an object - --> $DIR/object-safety-supertrait-mentions-GAT.rs:10:20 + --> $DIR/supertrait-mentions-GAT.rs:10:20 | LL | fn c(&self) -> dyn SuperTrait; | ^^^^^^^^^^^^^^^^^ `SuperTrait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-supertrait-mentions-GAT.rs:4:10 + --> $DIR/supertrait-mentions-GAT.rs:4:10 | LL | type Gat<'a> | ^^^ ...because it contains the generic associated type `Gat` diff --git a/tests/ui/object-safety/object-safety-supertrait-mentions-Self.rs b/tests/ui/dyn-compatibility/supertrait-mentions-Self.rs similarity index 100% rename from tests/ui/object-safety/object-safety-supertrait-mentions-Self.rs rename to tests/ui/dyn-compatibility/supertrait-mentions-Self.rs diff --git a/tests/ui/object-safety/object-safety-supertrait-mentions-Self.stderr b/tests/ui/dyn-compatibility/supertrait-mentions-Self.stderr similarity index 86% rename from tests/ui/object-safety/object-safety-supertrait-mentions-Self.stderr rename to tests/ui/dyn-compatibility/supertrait-mentions-Self.stderr index b1a70fb859d7f..6474b115c4628 100644 --- a/tests/ui/object-safety/object-safety-supertrait-mentions-Self.stderr +++ b/tests/ui/dyn-compatibility/supertrait-mentions-Self.stderr @@ -1,11 +1,11 @@ error[E0277]: the size for values of type `Self` cannot be known at compilation time - --> $DIR/object-safety-supertrait-mentions-Self.rs:8:13 + --> $DIR/supertrait-mentions-Self.rs:8:13 | LL | trait Baz : Bar { | ^^^^^^^^^ doesn't have a size known at compile-time | note: required by an implicit `Sized` bound in `Bar` - --> $DIR/object-safety-supertrait-mentions-Self.rs:4:11 + --> $DIR/supertrait-mentions-Self.rs:4:11 | LL | trait Bar { | ^ required by the implicit `Sized` requirement on this type parameter in `Bar` @@ -19,13 +19,13 @@ LL | trait Bar { | ++++++++ error[E0038]: the trait `Baz` cannot be made into an object - --> $DIR/object-safety-supertrait-mentions-Self.rs:16:31 + --> $DIR/supertrait-mentions-Self.rs:16:31 | LL | fn make_baz(t: &T) -> &dyn Baz { | ^^^^^^^ `Baz` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety-supertrait-mentions-Self.rs:8:13 + --> $DIR/supertrait-mentions-Self.rs:8:13 | LL | trait Baz : Bar { | --- ^^^^^^^^^ ...because it uses `Self` as a type parameter diff --git a/tests/ui/object-safety/issue-102762.rs b/tests/ui/dyn-compatibility/undispatchable-receiver-and-wc-references-Self.rs similarity index 79% rename from tests/ui/object-safety/issue-102762.rs rename to tests/ui/dyn-compatibility/undispatchable-receiver-and-wc-references-Self.rs index 576f73e08bcf9..5c71bd7769ce1 100644 --- a/tests/ui/object-safety/issue-102762.rs +++ b/tests/ui/dyn-compatibility/undispatchable-receiver-and-wc-references-Self.rs @@ -1,7 +1,8 @@ //@ compile-flags: --crate-type=lib // This test checks that the `where_clauses_object_safety` lint does not cause -// other object safety *hard errors* to be suppressed, because we currently -// only emit one object safety error per trait... +// other dyn-compatibility *hard errors* to be suppressed, because we currently +// only emit one dyn-compatibility error per trait... +// issue: rust-lang/rust#102762 use std::future::Future; use std::pin::Pin; diff --git a/tests/ui/object-safety/issue-102762.stderr b/tests/ui/dyn-compatibility/undispatchable-receiver-and-wc-references-Self.stderr similarity index 87% rename from tests/ui/object-safety/issue-102762.stderr rename to tests/ui/dyn-compatibility/undispatchable-receiver-and-wc-references-Self.stderr index 05451eb8399cf..8d62ac9d923f9 100644 --- a/tests/ui/object-safety/issue-102762.stderr +++ b/tests/ui/dyn-compatibility/undispatchable-receiver-and-wc-references-Self.stderr @@ -1,5 +1,5 @@ error[E0038]: the trait `Fetcher` cannot be made into an object - --> $DIR/issue-102762.rs:18:21 + --> $DIR/undispatchable-receiver-and-wc-references-Self.rs:19:21 | LL | fn get<'a>(self: &'a Box) -> Pin> + 'a>> | ------------- help: consider changing method `get`'s `self` parameter to be `&self`: `&Self` @@ -8,7 +8,7 @@ LL | fn fetcher() -> Box { | ^^^^^^^^^^^ `Fetcher` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/issue-102762.rs:10:22 + --> $DIR/undispatchable-receiver-and-wc-references-Self.rs:11:22 | LL | pub trait Fetcher: Send + Sync { | ------- this trait cannot be made into an object... @@ -16,7 +16,7 @@ LL | fn get<'a>(self: &'a Box) -> Pin> | ^^^^^^^^^^^^^ ...because method `get`'s `self` parameter cannot be dispatched on error[E0038]: the trait `Fetcher` cannot be made into an object - --> $DIR/issue-102762.rs:24:19 + --> $DIR/undispatchable-receiver-and-wc-references-Self.rs:25:19 | LL | fn get<'a>(self: &'a Box) -> Pin> + 'a>> | ------------- help: consider changing method `get`'s `self` parameter to be `&self`: `&Self` @@ -25,7 +25,7 @@ LL | let fetcher = fetcher(); | ^^^^^^^^^ `Fetcher` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/issue-102762.rs:10:22 + --> $DIR/undispatchable-receiver-and-wc-references-Self.rs:11:22 | LL | pub trait Fetcher: Send + Sync { | ------- this trait cannot be made into an object... @@ -33,7 +33,7 @@ LL | fn get<'a>(self: &'a Box) -> Pin> | ^^^^^^^^^^^^^ ...because method `get`'s `self` parameter cannot be dispatched on error[E0038]: the trait `Fetcher` cannot be made into an object - --> $DIR/issue-102762.rs:26:13 + --> $DIR/undispatchable-receiver-and-wc-references-Self.rs:27:13 | LL | fn get<'a>(self: &'a Box) -> Pin> + 'a>> | ------------- help: consider changing method `get`'s `self` parameter to be `&self`: `&Self` @@ -42,7 +42,7 @@ LL | let _ = fetcher.get(); | ^^^^^^^^^^^^^ `Fetcher` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/issue-102762.rs:10:22 + --> $DIR/undispatchable-receiver-and-wc-references-Self.rs:11:22 | LL | pub trait Fetcher: Send + Sync { | ------- this trait cannot be made into an object... diff --git a/tests/ui/feature-gates/feature-gate-dispatch-from-dyn-missing-impl.rs b/tests/ui/feature-gates/feature-gate-dispatch-from-dyn-missing-impl.rs index 23857cbaca85e..3c9e903d4ba00 100644 --- a/tests/ui/feature-gates/feature-gate-dispatch-from-dyn-missing-impl.rs +++ b/tests/ui/feature-gates/feature-gate-dispatch-from-dyn-missing-impl.rs @@ -1,4 +1,4 @@ -// Check that a self parameter type requires a DispatchFromDyn impl to be object safe +// Check that a self parameter type requires a DispatchFromDyn impl to be dyn-compatible. #![feature(arbitrary_self_types, unsize, coerce_unsized)] diff --git a/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.rs b/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.rs index 2dbba370a51e5..e38ab66dbe549 100644 --- a/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.rs +++ b/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.rs @@ -15,20 +15,20 @@ trait DynIncompatible4 { fn foo(&self, s: &Self); } -fn takes_non_object_safe_ref(obj: &dyn DynIncompatible1) { +fn takes_dyn_incompatible_ref(obj: &dyn DynIncompatible1) { //~^ ERROR E0038 } -fn return_non_object_safe_ref() -> &'static dyn DynIncompatible2 { +fn return_dyn_incompatible_ref() -> &'static dyn DynIncompatible2 { //~^ ERROR E0038 loop {} } -fn takes_non_object_safe_box(obj: Box) { +fn takes_dyn_incompatible_box(obj: Box) { //~^ ERROR E0038 } -fn return_non_object_safe_rc() -> std::rc::Rc { +fn return_dyn_incompatible_rc() -> std::rc::Rc { //~^ ERROR E0038 loop {} } diff --git a/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.stderr b/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.stderr index 3cb73dfd52c68..ed021c154a5b8 100644 --- a/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.stderr +++ b/tests/ui/feature-gates/feature-gate-dyn_compatible_for_dispatch.stderr @@ -1,8 +1,8 @@ error[E0038]: the trait `DynIncompatible1` cannot be made into an object - --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:18:39 + --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:18:40 | -LL | fn takes_non_object_safe_ref(obj: &dyn DynIncompatible1) { - | ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible1` cannot be made into an object +LL | fn takes_dyn_incompatible_ref(obj: &dyn DynIncompatible1) { + | ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible1` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:4:25 @@ -13,10 +13,10 @@ LL | trait DynIncompatible1: Sized {} | this trait cannot be made into an object... error[E0038]: the trait `DynIncompatible2` cannot be made into an object - --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:22:45 + --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:22:46 | -LL | fn return_non_object_safe_ref() -> &'static dyn DynIncompatible2 { - | ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible2` cannot be made into an object +LL | fn return_dyn_incompatible_ref() -> &'static dyn DynIncompatible2 { + | ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible2` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:7:8 @@ -35,10 +35,10 @@ LL | fn static_fn() where Self: Sized {} | +++++++++++++++++ error[E0038]: the trait `DynIncompatible3` cannot be made into an object - --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:27:39 + --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:27:40 | -LL | fn takes_non_object_safe_box(obj: Box) { - | ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible3` cannot be made into an object +LL | fn takes_dyn_incompatible_box(obj: Box) { + | ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible3` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:11:8 @@ -50,10 +50,10 @@ LL | fn foo(&self); = help: consider moving `foo` to another trait error[E0038]: the trait `DynIncompatible4` cannot be made into an object - --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:31:47 + --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:31:48 | -LL | fn return_non_object_safe_rc() -> std::rc::Rc { - | ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible4` cannot be made into an object +LL | fn return_dyn_incompatible_rc() -> std::rc::Rc { + | ^^^^^^^^^^^^^^^^^^^^ `DynIncompatible4` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit --> $DIR/feature-gate-dyn_compatible_for_dispatch.rs:15:22 diff --git a/tests/ui/generic-associated-types/trait-objects.rs b/tests/ui/generic-associated-types/trait-objects.rs index 277ffcc1f0dd3..743a3df0acc81 100644 --- a/tests/ui/generic-associated-types/trait-objects.rs +++ b/tests/ui/generic-associated-types/trait-objects.rs @@ -6,7 +6,7 @@ trait StreamingIterator { type Item<'a> where Self: 'a; fn size_hint(&self) -> (usize, Option); - // Uncommenting makes `StreamingIterator` not object safe + // Uncommenting makes `StreamingIterator` dyn-incompatible. // fn next(&mut self) -> Self::Item<'_>; } diff --git a/tests/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.rs b/tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.rs similarity index 59% rename from tests/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.rs rename to tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.rs index 068f7d3eea6da..76dbb05f53d66 100644 --- a/tests/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.rs +++ b/tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.rs @@ -1,24 +1,25 @@ #![allow(bare_trait_objects)] -trait NotObjectSafe { + +trait DynIncompatible { fn foo() -> Self; } struct A; struct B; -impl NotObjectSafe for A { +impl DynIncompatible for A { fn foo() -> Self { A } } -impl NotObjectSafe for B { +impl DynIncompatible for B { fn foo() -> Self { B } } -fn car() -> dyn NotObjectSafe { //~ ERROR the trait `NotObjectSafe` cannot be made into an object +fn car() -> dyn DynIncompatible { //~ ERROR the trait `DynIncompatible` cannot be made into an object //~^ ERROR return type cannot have an unboxed trait object if true { return A; @@ -26,7 +27,7 @@ fn car() -> dyn NotObjectSafe { //~ ERROR the trait `NotObjectSafe` cannot be ma B } -fn cat() -> Box { //~ ERROR the trait `NotObjectSafe` cannot be made into an +fn cat() -> Box { //~ ERROR the trait `DynIncompatible` cannot be made into an if true { return Box::new(A); //~ ERROR cannot be made into an object } diff --git a/tests/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr b/tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.stderr similarity index 62% rename from tests/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr rename to tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.stderr index 2a36824e29254..576bd909cbc7d 100644 --- a/tests/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr +++ b/tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-dyn-trait.stderr @@ -1,17 +1,17 @@ -error[E0038]: the trait `NotObjectSafe` cannot be made into an object - --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:21:13 +error[E0038]: the trait `DynIncompatible` cannot be made into an object + --> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:22:13 | -LL | fn car() -> dyn NotObjectSafe { - | ^^^^^^^^^^^^^^^^^ `NotObjectSafe` cannot be made into an object +LL | fn car() -> dyn DynIncompatible { + | ^^^^^^^^^^^^^^^^^^^ `DynIncompatible` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:3:8 + --> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:4:8 | -LL | trait NotObjectSafe { - | ------------- this trait cannot be made into an object... +LL | trait DynIncompatible { + | --------------- this trait cannot be made into an object... LL | fn foo() -> Self; | ^^^ ...because associated function `foo` has no `self` parameter - = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `NotObjectSafe` for this new enum and using it instead: + = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `DynIncompatible` for this new enum and using it instead: A B help: consider turning `foo` into a method by giving it a `&self` argument @@ -23,20 +23,20 @@ help: alternatively, consider constraining `foo` so it does not apply to trait o LL | fn foo() -> Self where Self: Sized; | +++++++++++++++++ -error[E0038]: the trait `NotObjectSafe` cannot be made into an object - --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:29:17 +error[E0038]: the trait `DynIncompatible` cannot be made into an object + --> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:30:17 | -LL | fn cat() -> Box { - | ^^^^^^^^^^^^^^^^^ `NotObjectSafe` cannot be made into an object +LL | fn cat() -> Box { + | ^^^^^^^^^^^^^^^^^^^ `DynIncompatible` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:3:8 + --> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:4:8 | -LL | trait NotObjectSafe { - | ------------- this trait cannot be made into an object... +LL | trait DynIncompatible { + | --------------- this trait cannot be made into an object... LL | fn foo() -> Self; | ^^^ ...because associated function `foo` has no `self` parameter - = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `NotObjectSafe` for this new enum and using it instead: + = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `DynIncompatible` for this new enum and using it instead: A B help: consider turning `foo` into a method by giving it a `&self` argument @@ -49,15 +49,15 @@ LL | fn foo() -> Self where Self: Sized; | +++++++++++++++++ error[E0746]: return type cannot have an unboxed trait object - --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:21:13 + --> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:22:13 | -LL | fn car() -> dyn NotObjectSafe { - | ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time +LL | fn car() -> dyn DynIncompatible { + | ^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: if there were a single returned type, you could use `impl Trait` instead help: box the return type, and wrap all of the returned values in `Box::new` | -LL ~ fn car() -> Box { +LL ~ fn car() -> Box { LL | LL | if true { LL ~ return Box::new(A); @@ -65,23 +65,23 @@ LL | } LL ~ Box::new(B) | -error[E0038]: the trait `NotObjectSafe` cannot be made into an object - --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:31:16 +error[E0038]: the trait `DynIncompatible` cannot be made into an object + --> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:32:16 | LL | return Box::new(A); - | ^^^^^^^^^^^ `NotObjectSafe` cannot be made into an object + | ^^^^^^^^^^^ `DynIncompatible` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:3:8 + --> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:4:8 | -LL | trait NotObjectSafe { - | ------------- this trait cannot be made into an object... +LL | trait DynIncompatible { + | --------------- this trait cannot be made into an object... LL | fn foo() -> Self; | ^^^ ...because associated function `foo` has no `self` parameter - = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `NotObjectSafe` for this new enum and using it instead: + = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `DynIncompatible` for this new enum and using it instead: A B - = note: required for the cast from `Box` to `Box<(dyn NotObjectSafe + 'static)>` + = note: required for the cast from `Box` to `Box<(dyn DynIncompatible + 'static)>` help: consider turning `foo` into a method by giving it a `&self` argument | LL | fn foo(&self) -> Self; @@ -91,23 +91,23 @@ help: alternatively, consider constraining `foo` so it does not apply to trait o LL | fn foo() -> Self where Self: Sized; | +++++++++++++++++ -error[E0038]: the trait `NotObjectSafe` cannot be made into an object - --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:33:5 +error[E0038]: the trait `DynIncompatible` cannot be made into an object + --> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:34:5 | LL | Box::new(B) - | ^^^^^^^^^^^ `NotObjectSafe` cannot be made into an object + | ^^^^^^^^^^^ `DynIncompatible` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:3:8 + --> $DIR/dyn-incompatible-trait-in-return-position-dyn-trait.rs:4:8 | -LL | trait NotObjectSafe { - | ------------- this trait cannot be made into an object... +LL | trait DynIncompatible { + | --------------- this trait cannot be made into an object... LL | fn foo() -> Self; | ^^^ ...because associated function `foo` has no `self` parameter - = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `NotObjectSafe` for this new enum and using it instead: + = help: the following types implement the trait, consider defining an enum where each variant holds one of these types, implementing `DynIncompatible` for this new enum and using it instead: A B - = note: required for the cast from `Box` to `Box<(dyn NotObjectSafe + 'static)>` + = note: required for the cast from `Box` to `Box<(dyn DynIncompatible + 'static)>` help: consider turning `foo` into a method by giving it a `&self` argument | LL | fn foo(&self) -> Self; diff --git a/tests/ui/impl-trait/object-unsafe-trait-in-return-position-impl-trait.rs b/tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-impl-trait.rs similarity index 61% rename from tests/ui/impl-trait/object-unsafe-trait-in-return-position-impl-trait.rs rename to tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-impl-trait.rs index 503515013b9ab..25a901e4ff350 100644 --- a/tests/ui/impl-trait/object-unsafe-trait-in-return-position-impl-trait.rs +++ b/tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-impl-trait.rs @@ -1,42 +1,42 @@ -trait NotObjectSafe { +trait DynIncompatible { fn foo() -> Self; } -trait ObjectSafe { +trait DynCompatible { fn bar(&self); } struct A; struct B; -impl NotObjectSafe for A { +impl DynIncompatible for A { fn foo() -> Self { A } } -impl NotObjectSafe for B { +impl DynIncompatible for B { fn foo() -> Self { B } } -impl ObjectSafe for A { +impl DynCompatible for A { fn bar(&self) {} } -impl ObjectSafe for B { +impl DynCompatible for B { fn bar(&self) {} } -fn can() -> impl NotObjectSafe { +fn can() -> impl DynIncompatible { if true { return A; } B //~ ERROR mismatched types } -fn cat() -> impl ObjectSafe { +fn cat() -> impl DynCompatible { if true { return A; } diff --git a/tests/ui/impl-trait/object-unsafe-trait-in-return-position-impl-trait.stderr b/tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-impl-trait.stderr similarity index 54% rename from tests/ui/impl-trait/object-unsafe-trait-in-return-position-impl-trait.stderr rename to tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-impl-trait.stderr index e5147bcea1662..6a485881bfccb 100644 --- a/tests/ui/impl-trait/object-unsafe-trait-in-return-position-impl-trait.stderr +++ b/tests/ui/impl-trait/dyn-incompatible-trait-in-return-position-impl-trait.stderr @@ -1,17 +1,17 @@ error[E0308]: mismatched types - --> $DIR/object-unsafe-trait-in-return-position-impl-trait.rs:36:5 + --> $DIR/dyn-incompatible-trait-in-return-position-impl-trait.rs:36:5 | -LL | fn can() -> impl NotObjectSafe { - | ------------------ expected `A` because of return type +LL | fn can() -> impl DynIncompatible { + | -------------------- expected `A` because of return type ... LL | B | ^ expected `A`, found `B` error[E0308]: mismatched types - --> $DIR/object-unsafe-trait-in-return-position-impl-trait.rs:43:5 + --> $DIR/dyn-incompatible-trait-in-return-position-impl-trait.rs:43:5 | -LL | fn cat() -> impl ObjectSafe { - | --------------- expected `A` because of return type +LL | fn cat() -> impl DynCompatible { + | ------------------ expected `A` because of return type ... LL | B | ^ expected `A`, found `B` diff --git a/tests/ui/impl-trait/in-trait/cycle-effective-visibilities-during-object-safety.rs b/tests/ui/impl-trait/in-trait/cycle-effective-visibilities-during-dyn-compatibility-check.rs similarity index 100% rename from tests/ui/impl-trait/in-trait/cycle-effective-visibilities-during-object-safety.rs rename to tests/ui/impl-trait/in-trait/cycle-effective-visibilities-during-dyn-compatibility-check.rs diff --git a/tests/ui/impl-trait/in-trait/cycle-effective-visibilities-during-object-safety.stderr b/tests/ui/impl-trait/in-trait/cycle-effective-visibilities-during-dyn-compatibility-check.stderr similarity index 82% rename from tests/ui/impl-trait/in-trait/cycle-effective-visibilities-during-object-safety.stderr rename to tests/ui/impl-trait/in-trait/cycle-effective-visibilities-during-dyn-compatibility-check.stderr index af624e2a75871..a975b6204aa5a 100644 --- a/tests/ui/impl-trait/in-trait/cycle-effective-visibilities-during-object-safety.stderr +++ b/tests/ui/impl-trait/in-trait/cycle-effective-visibilities-during-dyn-compatibility-check.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `&dyn MyTrait: MyTrait` is not satisfied - --> $DIR/cycle-effective-visibilities-during-object-safety.rs:20:22 + --> $DIR/cycle-effective-visibilities-during-dyn-compatibility-check.rs:20:22 | LL | MyTrait::foo(&self) | ------------ ^^^^^ the trait `MyTrait` is not implemented for `&dyn MyTrait` @@ -9,13 +9,13 @@ LL | MyTrait::foo(&self) = help: the trait `MyTrait` is implemented for `Outer` error[E0038]: the trait `MyTrait` cannot be made into an object - --> $DIR/cycle-effective-visibilities-during-object-safety.rs:20:9 + --> $DIR/cycle-effective-visibilities-during-dyn-compatibility-check.rs:20:9 | LL | MyTrait::foo(&self) | ^^^^^^^^^^^^ `MyTrait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/cycle-effective-visibilities-during-object-safety.rs:5:22 + --> $DIR/cycle-effective-visibilities-during-dyn-compatibility-check.rs:5:22 | LL | trait MyTrait { | ------- this trait cannot be made into an object... @@ -25,7 +25,7 @@ LL | fn foo(&self) -> impl Marker; = help: only type `Outer` implements the trait, consider using it directly instead error[E0277]: the trait bound `&dyn MyTrait: MyTrait` is not satisfied - --> $DIR/cycle-effective-visibilities-during-object-safety.rs:20:9 + --> $DIR/cycle-effective-visibilities-during-dyn-compatibility-check.rs:20:9 | LL | MyTrait::foo(&self) | ^^^^^^^^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `&dyn MyTrait` @@ -33,13 +33,13 @@ LL | MyTrait::foo(&self) = help: the trait `MyTrait` is implemented for `Outer` error[E0038]: the trait `MyTrait` cannot be made into an object - --> $DIR/cycle-effective-visibilities-during-object-safety.rs:16:6 + --> $DIR/cycle-effective-visibilities-during-dyn-compatibility-check.rs:16:6 | LL | impl dyn MyTrait { | ^^^^^^^^^^^ `MyTrait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/cycle-effective-visibilities-during-object-safety.rs:5:22 + --> $DIR/cycle-effective-visibilities-during-dyn-compatibility-check.rs:5:22 | LL | trait MyTrait { | ------- this trait cannot be made into an object... @@ -49,13 +49,13 @@ LL | fn foo(&self) -> impl Marker; = help: only type `Outer` implements the trait, consider using it directly instead error[E0038]: the trait `MyTrait` cannot be made into an object - --> $DIR/cycle-effective-visibilities-during-object-safety.rs:18:15 + --> $DIR/cycle-effective-visibilities-during-dyn-compatibility-check.rs:18:15 | LL | fn other(&self) -> impl Marker { | ^^^^ `MyTrait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/cycle-effective-visibilities-during-object-safety.rs:5:22 + --> $DIR/cycle-effective-visibilities-during-dyn-compatibility-check.rs:5:22 | LL | trait MyTrait { | ------- this trait cannot be made into an object... diff --git a/tests/ui/impl-trait/in-trait/object-safety-sized.rs b/tests/ui/impl-trait/in-trait/dyn-compatibility-sized.rs similarity index 100% rename from tests/ui/impl-trait/in-trait/object-safety-sized.rs rename to tests/ui/impl-trait/in-trait/dyn-compatibility-sized.rs diff --git a/tests/ui/impl-trait/in-trait/object-safety.rs b/tests/ui/impl-trait/in-trait/dyn-compatibility.rs similarity index 100% rename from tests/ui/impl-trait/in-trait/object-safety.rs rename to tests/ui/impl-trait/in-trait/dyn-compatibility.rs diff --git a/tests/ui/impl-trait/in-trait/object-safety.stderr b/tests/ui/impl-trait/in-trait/dyn-compatibility.stderr similarity index 91% rename from tests/ui/impl-trait/in-trait/object-safety.stderr rename to tests/ui/impl-trait/in-trait/dyn-compatibility.stderr index e2f23bca621c6..115cb014b8c34 100644 --- a/tests/ui/impl-trait/in-trait/object-safety.stderr +++ b/tests/ui/impl-trait/in-trait/dyn-compatibility.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-safety.rs:14:33 + --> $DIR/dyn-compatibility.rs:14:33 | LL | let i = Box::new(42_u32) as Box; | ^^^^^^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety.rs:4:22 + --> $DIR/dyn-compatibility.rs:4:22 | LL | trait Foo { | --- this trait cannot be made into an object... @@ -15,13 +15,13 @@ LL | fn baz(&self) -> impl Debug; = help: only type `u32` implements the trait, consider using it directly instead error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-safety.rs:17:15 + --> $DIR/dyn-compatibility.rs:17:15 | LL | let s = i.baz(); | ^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety.rs:4:22 + --> $DIR/dyn-compatibility.rs:4:22 | LL | trait Foo { | --- this trait cannot be made into an object... @@ -31,13 +31,13 @@ LL | fn baz(&self) -> impl Debug; = help: only type `u32` implements the trait, consider using it directly instead error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-safety.rs:17:13 + --> $DIR/dyn-compatibility.rs:17:13 | LL | let s = i.baz(); | ^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety.rs:4:22 + --> $DIR/dyn-compatibility.rs:4:22 | LL | trait Foo { | --- this trait cannot be made into an object... @@ -47,13 +47,13 @@ LL | fn baz(&self) -> impl Debug; = help: only type `u32` implements the trait, consider using it directly instead error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/object-safety.rs:14:13 + --> $DIR/dyn-compatibility.rs:14:13 | LL | let i = Box::new(42_u32) as Box; | ^^^^^^^^^^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-safety.rs:4:22 + --> $DIR/dyn-compatibility.rs:4:22 | LL | trait Foo { | --- this trait cannot be made into an object... diff --git a/tests/ui/issues/issue-58734.rs b/tests/ui/issues/issue-58734.rs index c838fde5d73b6..9b630666baf85 100644 --- a/tests/ui/issues/issue-58734.rs +++ b/tests/ui/issues/issue-58734.rs @@ -1,22 +1,22 @@ trait Trait { fn exists(self) -> (); - fn not_object_safe() -> Self; + fn dyn_incompatible() -> Self; } impl Trait for () { fn exists(self) -> () { } - fn not_object_safe() -> Self { + fn dyn_incompatible() -> Self { () } } fn main() { - // object-safe or not, this call is OK + // dyn-compatible or not, this call is OK Trait::exists(()); - // no object safety error + // no dyn-compatibility error Trait::nonexistent(()); //~^ ERROR no function or associated item named `nonexistent` found //~| WARN trait objects without an explicit `dyn` are deprecated diff --git a/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/downcast-unsafe-trait-objects.rs b/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/downcast-unsafe-trait-objects.rs index e9206789756e7..b1b2dcf3eb9fd 100644 --- a/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/downcast-unsafe-trait-objects.rs +++ b/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/downcast-unsafe-trait-objects.rs @@ -1,4 +1,4 @@ -// Check that we if we get ahold of an object unsafe trait +// Check that we if we get ahold of a dyn-incompatible trait // object with auto traits and lifetimes, we can downcast it // //@ check-pass diff --git a/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.rs b/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.rs index 37e6f948ad118..425dc130d4587 100644 --- a/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.rs +++ b/tests/ui/rfcs/rfc-2027-dyn-compatible-for-dispatch/manual-self-impl-for-unsafe-obj.rs @@ -1,4 +1,4 @@ -// Check that we can manually implement an object-unsafe trait for its trait object. +// Check that we can manually implement a dyn-incompatible trait for its trait object. //@ revisions: current next //@ ignore-compare-mode-next-solver (explicit revisions) diff --git a/tests/ui/sanitizer/cfi/async-closures.rs b/tests/ui/sanitizer/cfi/async-closures.rs index d94f2992d8428..4eaa44cfa3f47 100644 --- a/tests/ui/sanitizer/cfi/async-closures.rs +++ b/tests/ui/sanitizer/cfi/async-closures.rs @@ -21,7 +21,7 @@ use std::ops::AsyncFn; #[inline(never)] fn identity(x: T) -> T { x } -// We can't actually create a `dyn AsyncFn()`, because it's not object-safe, but we should check +// We can't actually create a `dyn AsyncFn()`, because it's dyn-incompatible, but we should check // that we don't bug out when we encounter one. fn main() { diff --git a/tests/ui/self/arbitrary-self-types-not-object-safe.curr.stderr b/tests/ui/self/arbitrary-self-types-dyn-incompatible.curr.stderr similarity index 89% rename from tests/ui/self/arbitrary-self-types-not-object-safe.curr.stderr rename to tests/ui/self/arbitrary-self-types-dyn-incompatible.curr.stderr index e2d73fc08f6d7..2eb7597d5c105 100644 --- a/tests/ui/self/arbitrary-self-types-not-object-safe.curr.stderr +++ b/tests/ui/self/arbitrary-self-types-dyn-incompatible.curr.stderr @@ -1,5 +1,5 @@ error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/arbitrary-self-types-not-object-safe.rs:33:32 + --> $DIR/arbitrary-self-types-dyn-incompatible.rs:33:32 | LL | fn foo(self: &Rc) -> usize; | --------- help: consider changing method `foo`'s `self` parameter to be `&self`: `&Self` @@ -8,7 +8,7 @@ LL | let x = Rc::new(5usize) as Rc; | ^^^^^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/arbitrary-self-types-not-object-safe.rs:8:18 + --> $DIR/arbitrary-self-types-dyn-incompatible.rs:8:18 | LL | trait Foo { | --- this trait cannot be made into an object... @@ -17,7 +17,7 @@ LL | fn foo(self: &Rc) -> usize; = help: only type `usize` implements the trait, consider using it directly instead error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/arbitrary-self-types-not-object-safe.rs:33:13 + --> $DIR/arbitrary-self-types-dyn-incompatible.rs:33:13 | LL | fn foo(self: &Rc) -> usize; | --------- help: consider changing method `foo`'s `self` parameter to be `&self`: `&Self` @@ -26,7 +26,7 @@ LL | let x = Rc::new(5usize) as Rc; | ^^^^^^^^^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/arbitrary-self-types-not-object-safe.rs:8:18 + --> $DIR/arbitrary-self-types-dyn-incompatible.rs:8:18 | LL | trait Foo { | --- this trait cannot be made into an object... diff --git a/tests/ui/self/arbitrary-self-types-not-object-safe.dyn_compatible_for_dispatch.stderr b/tests/ui/self/arbitrary-self-types-dyn-incompatible.dyn_compatible_for_dispatch.stderr similarity index 90% rename from tests/ui/self/arbitrary-self-types-not-object-safe.dyn_compatible_for_dispatch.stderr rename to tests/ui/self/arbitrary-self-types-dyn-incompatible.dyn_compatible_for_dispatch.stderr index fda07765c6620..02af692c4a352 100644 --- a/tests/ui/self/arbitrary-self-types-not-object-safe.dyn_compatible_for_dispatch.stderr +++ b/tests/ui/self/arbitrary-self-types-dyn-incompatible.dyn_compatible_for_dispatch.stderr @@ -1,5 +1,5 @@ error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/arbitrary-self-types-not-object-safe.rs:33:13 + --> $DIR/arbitrary-self-types-dyn-incompatible.rs:33:13 | LL | fn foo(self: &Rc) -> usize; | --------- help: consider changing method `foo`'s `self` parameter to be `&self`: `&Self` @@ -8,7 +8,7 @@ LL | let x = Rc::new(5usize) as Rc; | ^^^^^^^^^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/arbitrary-self-types-not-object-safe.rs:8:18 + --> $DIR/arbitrary-self-types-dyn-incompatible.rs:8:18 | LL | trait Foo { | --- this trait cannot be made into an object... diff --git a/tests/ui/self/arbitrary-self-types-not-object-safe.rs b/tests/ui/self/arbitrary-self-types-dyn-incompatible.rs similarity index 100% rename from tests/ui/self/arbitrary-self-types-not-object-safe.rs rename to tests/ui/self/arbitrary-self-types-dyn-incompatible.rs diff --git a/tests/ui/self/arbitrary_self_types_pointers_and_wrappers.rs b/tests/ui/self/arbitrary_self_types_pointers_and_wrappers.rs index d7149002e7bca..76d7754384ebe 100644 --- a/tests/ui/self/arbitrary_self_types_pointers_and_wrappers.rs +++ b/tests/ui/self/arbitrary_self_types_pointers_and_wrappers.rs @@ -50,9 +50,9 @@ impl, U> DispatchFromDyn> for Wrapper {} trait Trait { - // This method isn't object-safe yet. Unsized by-value `self` is object-safe (but not callable - // without unsized_locals), but wrappers arond `Self` currently are not. - // FIXME (mikeyhew) uncomment this when unsized rvalues object-safety is implemented + // This method isn't dyn-compatible yet. Unsized by-value `self` is dyn-compatible (but not + // callable without unsized_locals), but wrappers arond `Self` currently are not. + // FIXME (mikeyhew) uncomment this when unsized rvalues dyn-compatibility is implemented // fn wrapper(self: Wrapper) -> i32; fn ptr_wrapper(self: Ptr>) -> i32; fn wrapper_ptr(self: Wrapper>) -> i32; diff --git a/tests/ui/self/object-safety-sized-self-by-value-self.rs b/tests/ui/self/dyn-compatibility-sized-self-by-value-self.rs similarity index 90% rename from tests/ui/self/object-safety-sized-self-by-value-self.rs rename to tests/ui/self/dyn-compatibility-sized-self-by-value-self.rs index d902812eb9a67..658371c95e2f5 100644 --- a/tests/ui/self/object-safety-sized-self-by-value-self.rs +++ b/tests/ui/self/dyn-compatibility-sized-self-by-value-self.rs @@ -1,6 +1,6 @@ //@ run-pass #![allow(unused_mut)] -// Check that a trait is still object-safe (and usable) if it has +// Check that a trait is still dyn-compatible (and usable) if it has // methods with by-value self so long as they require `Self : Sized`. diff --git a/tests/ui/self/object-safety-sized-self-generic-method.rs b/tests/ui/self/dyn-compatibility-sized-self-generic-method.rs similarity index 90% rename from tests/ui/self/object-safety-sized-self-generic-method.rs rename to tests/ui/self/dyn-compatibility-sized-self-generic-method.rs index 7a2ebd2cb7935..a7b5013694ff2 100644 --- a/tests/ui/self/object-safety-sized-self-generic-method.rs +++ b/tests/ui/self/dyn-compatibility-sized-self-generic-method.rs @@ -1,6 +1,6 @@ //@ run-pass #![allow(unused_variables)] -// Check that a trait is still object-safe (and usable) if it has +// Check that a trait is still dyn-compatible (and usable) if it has // generic methods so long as they require `Self : Sized`. diff --git a/tests/ui/self/object-safety-sized-self-return-Self.rs b/tests/ui/self/dyn-compatibility-sized-self-return-Self.rs similarity index 90% rename from tests/ui/self/object-safety-sized-self-return-Self.rs rename to tests/ui/self/dyn-compatibility-sized-self-return-Self.rs index 9fc3f85677223..a15f4fd781360 100644 --- a/tests/ui/self/object-safety-sized-self-return-Self.rs +++ b/tests/ui/self/dyn-compatibility-sized-self-return-Self.rs @@ -1,5 +1,5 @@ //@ run-pass -// Check that a trait is still object-safe (and usable) if it has +// Check that a trait is still dyn-compatible (and usable) if it has // methods that return `Self` so long as they require `Self : Sized`. diff --git a/tests/ui/specialization/issue-44861.rs b/tests/ui/specialization/issue-44861.rs index 79d9b9490d09d..9d6517e613a22 100644 --- a/tests/ui/specialization/issue-44861.rs +++ b/tests/ui/specialization/issue-44861.rs @@ -12,9 +12,9 @@ pub trait Smartass { type Data2: CoerceUnsized<*const [u8]>; } -pub trait MaybeObjectSafe {} +pub trait MaybeDynCompatible {} -impl MaybeObjectSafe for () {} +impl MaybeDynCompatible for () {} impl Smartass for T { type Data = ::Data2; @@ -26,7 +26,7 @@ impl Smartass for () { type Data2 = *const [u8; 1]; } -impl Smartass for dyn MaybeObjectSafe { +impl Smartass for dyn MaybeDynCompatible { type Data = *const [u8]; type Data2 = *const [u8; 0]; } @@ -35,6 +35,6 @@ impl CoerceUnsized> for S where ::Data: std::ops::CoerceUnsized<::Data> {} -pub fn conv(s: SmartassPtr<()>) -> SmartassPtr { +pub fn conv(s: SmartassPtr<()>) -> SmartassPtr { s } diff --git a/tests/ui/suggestions/auxiliary/not-object-safe.rs b/tests/ui/suggestions/auxiliary/dyn-incompatible.rs similarity index 100% rename from tests/ui/suggestions/auxiliary/not-object-safe.rs rename to tests/ui/suggestions/auxiliary/dyn-incompatible.rs diff --git a/tests/ui/suggestions/object-unsafe-trait-references-self.rs b/tests/ui/suggestions/dyn-incompatible-trait-references-self.rs similarity index 100% rename from tests/ui/suggestions/object-unsafe-trait-references-self.rs rename to tests/ui/suggestions/dyn-incompatible-trait-references-self.rs diff --git a/tests/ui/suggestions/object-unsafe-trait-references-self.stderr b/tests/ui/suggestions/dyn-incompatible-trait-references-self.stderr similarity index 87% rename from tests/ui/suggestions/object-unsafe-trait-references-self.stderr rename to tests/ui/suggestions/dyn-incompatible-trait-references-self.stderr index c00bb3efbf640..242c44abd9d66 100644 --- a/tests/ui/suggestions/object-unsafe-trait-references-self.stderr +++ b/tests/ui/suggestions/dyn-incompatible-trait-references-self.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Trait` cannot be made into an object - --> $DIR/object-unsafe-trait-references-self.rs:9:12 + --> $DIR/dyn-incompatible-trait-references-self.rs:9:12 | LL | fn bar(x: &dyn Trait) {} | ^^^^^^^^^ `Trait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-trait-references-self.rs:2:22 + --> $DIR/dyn-incompatible-trait-references-self.rs:2:22 | LL | trait Trait { | ----- this trait cannot be made into an object... @@ -18,13 +18,13 @@ LL | fn bat(&self) -> Self {} = help: consider moving `bat` to another trait error[E0038]: the trait `Other` cannot be made into an object - --> $DIR/object-unsafe-trait-references-self.rs:13:12 + --> $DIR/dyn-incompatible-trait-references-self.rs:13:12 | LL | fn foo(x: &dyn Other) {} | ^^^^^^^^^ `Other` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-trait-references-self.rs:11:14 + --> $DIR/dyn-incompatible-trait-references-self.rs:11:14 | LL | trait Other: Sized {} | ----- ^^^^^ ...because it requires `Self: Sized` @@ -32,7 +32,7 @@ LL | trait Other: Sized {} | this trait cannot be made into an object... error[E0277]: the size for values of type `Self` cannot be known at compilation time - --> $DIR/object-unsafe-trait-references-self.rs:2:22 + --> $DIR/dyn-incompatible-trait-references-self.rs:2:22 | LL | fn baz(&self, _: Self) {} | ^^^^ doesn't have a size known at compile-time @@ -48,7 +48,7 @@ LL | fn baz(&self, _: &Self) {} | + error[E0308]: mismatched types - --> $DIR/object-unsafe-trait-references-self.rs:4:27 + --> $DIR/dyn-incompatible-trait-references-self.rs:4:27 | LL | trait Trait { | ----------- expected this type parameter @@ -60,7 +60,7 @@ LL | fn bat(&self) -> Self {} found unit type `()` error[E0277]: the size for values of type `Self` cannot be known at compilation time - --> $DIR/object-unsafe-trait-references-self.rs:4:22 + --> $DIR/dyn-incompatible-trait-references-self.rs:4:22 | LL | fn bat(&self) -> Self {} | ^^^^ doesn't have a size known at compile-time diff --git a/tests/ui/suggestions/object-unsafe-trait-should-use-self-2021-without-dyn.rs b/tests/ui/suggestions/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs similarity index 100% rename from tests/ui/suggestions/object-unsafe-trait-should-use-self-2021-without-dyn.rs rename to tests/ui/suggestions/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs diff --git a/tests/ui/suggestions/object-unsafe-trait-should-use-self-2021-without-dyn.stderr b/tests/ui/suggestions/dyn-incompatible-trait-should-use-self-2021-without-dyn.stderr similarity index 83% rename from tests/ui/suggestions/object-unsafe-trait-should-use-self-2021-without-dyn.stderr rename to tests/ui/suggestions/dyn-incompatible-trait-should-use-self-2021-without-dyn.stderr index a17f821ebec48..5330438258488 100644 --- a/tests/ui/suggestions/object-unsafe-trait-should-use-self-2021-without-dyn.stderr +++ b/tests/ui/suggestions/dyn-incompatible-trait-should-use-self-2021-without-dyn.stderr @@ -1,5 +1,5 @@ error: associated item referring to unboxed trait object for its own trait - --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:4:13 + --> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:4:13 | LL | trait A: Sized { | - in this trait @@ -12,13 +12,13 @@ LL | fn f(a: Self) -> Self; | ~~~~ ~~~~ error[E0038]: the trait `A` cannot be made into an object - --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:4:13 + --> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:4:13 | LL | fn f(a: A) -> A; | ^ `A` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:3:10 + --> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:3:10 | LL | trait A: Sized { | - ^^^^^ ...because it requires `Self: Sized` @@ -26,7 +26,7 @@ LL | trait A: Sized { | this trait cannot be made into an object... error: associated item referring to unboxed trait object for its own trait - --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:11:13 + --> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:11:13 | LL | trait B { | - in this trait @@ -39,13 +39,13 @@ LL | fn f(b: Self) -> Self; | ~~~~ ~~~~ error[E0038]: the trait `B` cannot be made into an object - --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:11:13 + --> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:11:13 | LL | fn f(b: B) -> B; | ^ `B` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:11:8 + --> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:11:8 | LL | trait B { | - this trait cannot be made into an object... @@ -61,7 +61,7 @@ LL | fn f(b: B) -> B where Self: Sized; | +++++++++++++++++ error: associated item referring to unboxed trait object for its own trait - --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:18:20 + --> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:18:20 | LL | trait C { | - in this trait @@ -74,7 +74,7 @@ LL | fn f(&self, c: Self) -> Self; | ~~~~ ~~~~ error[E0038]: the trait `C` cannot be made into an object - --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:18:20 + --> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:18:20 | LL | fn f(&self, c: C) -> C; | ----- ^ `C` cannot be made into an object @@ -82,7 +82,7 @@ LL | fn f(&self, c: C) -> C; | help: consider changing method `f`'s `self` parameter to be `&self` (notice the capitalization): `&Self` | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:18:10 + --> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:18:10 | LL | trait C { | - this trait cannot be made into an object... @@ -90,7 +90,7 @@ LL | fn f(&self, c: C) -> C; | ^^^^^ ...because method `f`'s `self` parameter cannot be dispatched on error[E0782]: trait objects must include the `dyn` keyword - --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:4:13 + --> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:4:13 | LL | fn f(a: A) -> A; | ^ @@ -106,7 +106,7 @@ LL | fn f(a: impl A) -> A; | ++++ error[E0782]: trait objects must include the `dyn` keyword - --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:4:19 + --> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:4:19 | LL | fn f(a: A) -> A; | ^ @@ -117,7 +117,7 @@ LL | fn f(a: A) -> impl A; | ++++ error[E0782]: trait objects must include the `dyn` keyword - --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:11:13 + --> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:11:13 | LL | fn f(b: B) -> B; | ^ @@ -133,7 +133,7 @@ LL | fn f(b: impl B) -> B; | ++++ error[E0782]: trait objects must include the `dyn` keyword - --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:11:19 + --> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:11:19 | LL | fn f(b: B) -> B; | ^ @@ -144,7 +144,7 @@ LL | fn f(b: B) -> impl B; | ++++ error[E0782]: trait objects must include the `dyn` keyword - --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:18:20 + --> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:18:20 | LL | fn f(&self, c: C) -> C; | ^ @@ -160,7 +160,7 @@ LL | fn f(&self, c: impl C) -> C; | ++++ error[E0782]: trait objects must include the `dyn` keyword - --> $DIR/object-unsafe-trait-should-use-self-2021-without-dyn.rs:18:26 + --> $DIR/dyn-incompatible-trait-should-use-self-2021-without-dyn.rs:18:26 | LL | fn f(&self, c: C) -> C; | ^ diff --git a/tests/ui/suggestions/object-unsafe-trait-should-use-self-2021.rs b/tests/ui/suggestions/dyn-incompatible-trait-should-use-self-2021.rs similarity index 100% rename from tests/ui/suggestions/object-unsafe-trait-should-use-self-2021.rs rename to tests/ui/suggestions/dyn-incompatible-trait-should-use-self-2021.rs diff --git a/tests/ui/suggestions/object-unsafe-trait-should-use-self-2021.stderr b/tests/ui/suggestions/dyn-incompatible-trait-should-use-self-2021.stderr similarity index 85% rename from tests/ui/suggestions/object-unsafe-trait-should-use-self-2021.stderr rename to tests/ui/suggestions/dyn-incompatible-trait-should-use-self-2021.stderr index a7d36d9ebee5d..5e0d1a1445230 100644 --- a/tests/ui/suggestions/object-unsafe-trait-should-use-self-2021.stderr +++ b/tests/ui/suggestions/dyn-incompatible-trait-should-use-self-2021.stderr @@ -1,5 +1,5 @@ error: associated item referring to unboxed trait object for its own trait - --> $DIR/object-unsafe-trait-should-use-self-2021.rs:4:13 + --> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:4:13 | LL | trait A: Sized { | - in this trait @@ -12,13 +12,13 @@ LL | fn f(a: Self) -> Self; | ~~~~ ~~~~ error[E0038]: the trait `A` cannot be made into an object - --> $DIR/object-unsafe-trait-should-use-self-2021.rs:4:13 + --> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:4:13 | LL | fn f(a: dyn A) -> dyn A; | ^^^^^ `A` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-trait-should-use-self-2021.rs:3:10 + --> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:3:10 | LL | trait A: Sized { | - ^^^^^ ...because it requires `Self: Sized` @@ -26,7 +26,7 @@ LL | trait A: Sized { | this trait cannot be made into an object... error: associated item referring to unboxed trait object for its own trait - --> $DIR/object-unsafe-trait-should-use-self-2021.rs:9:13 + --> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:9:13 | LL | trait B { | - in this trait @@ -39,13 +39,13 @@ LL | fn f(a: Self) -> Self; | ~~~~ ~~~~ error[E0038]: the trait `B` cannot be made into an object - --> $DIR/object-unsafe-trait-should-use-self-2021.rs:9:13 + --> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:9:13 | LL | fn f(a: dyn B) -> dyn B; | ^^^^^ `B` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-trait-should-use-self-2021.rs:9:8 + --> $DIR/dyn-incompatible-trait-should-use-self-2021.rs:9:8 | LL | trait B { | - this trait cannot be made into an object... diff --git a/tests/ui/suggestions/object-unsafe-trait-should-use-self.rs b/tests/ui/suggestions/dyn-incompatible-trait-should-use-self.rs similarity index 100% rename from tests/ui/suggestions/object-unsafe-trait-should-use-self.rs rename to tests/ui/suggestions/dyn-incompatible-trait-should-use-self.rs diff --git a/tests/ui/suggestions/object-unsafe-trait-should-use-self.stderr b/tests/ui/suggestions/dyn-incompatible-trait-should-use-self.stderr similarity index 86% rename from tests/ui/suggestions/object-unsafe-trait-should-use-self.stderr rename to tests/ui/suggestions/dyn-incompatible-trait-should-use-self.stderr index 28952933c644f..93f6ea2b12e67 100644 --- a/tests/ui/suggestions/object-unsafe-trait-should-use-self.stderr +++ b/tests/ui/suggestions/dyn-incompatible-trait-should-use-self.stderr @@ -1,5 +1,5 @@ error: associated item referring to unboxed trait object for its own trait - --> $DIR/object-unsafe-trait-should-use-self.rs:3:13 + --> $DIR/dyn-incompatible-trait-should-use-self.rs:3:13 | LL | trait A: Sized { | - in this trait @@ -12,13 +12,13 @@ LL | fn f(a: Self) -> Self; | ~~~~ ~~~~ error[E0038]: the trait `A` cannot be made into an object - --> $DIR/object-unsafe-trait-should-use-self.rs:3:13 + --> $DIR/dyn-incompatible-trait-should-use-self.rs:3:13 | LL | fn f(a: A) -> A; | ^ `A` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-trait-should-use-self.rs:2:10 + --> $DIR/dyn-incompatible-trait-should-use-self.rs:2:10 | LL | trait A: Sized { | - ^^^^^ ...because it requires `Self: Sized` @@ -26,7 +26,7 @@ LL | trait A: Sized { | this trait cannot be made into an object... error: associated item referring to unboxed trait object for its own trait - --> $DIR/object-unsafe-trait-should-use-self.rs:8:13 + --> $DIR/dyn-incompatible-trait-should-use-self.rs:8:13 | LL | trait B { | - in this trait @@ -39,13 +39,13 @@ LL | fn f(a: Self) -> Self; | ~~~~ ~~~~ error[E0038]: the trait `B` cannot be made into an object - --> $DIR/object-unsafe-trait-should-use-self.rs:8:13 + --> $DIR/dyn-incompatible-trait-should-use-self.rs:8:13 | LL | fn f(a: B) -> B; | ^ `B` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-trait-should-use-self.rs:8:8 + --> $DIR/dyn-incompatible-trait-should-use-self.rs:8:8 | LL | trait B { | - this trait cannot be made into an object... diff --git a/tests/ui/suggestions/object-unsafe-trait-should-use-where-sized.fixed b/tests/ui/suggestions/dyn-incompatible-trait-should-use-where-sized.fixed similarity index 100% rename from tests/ui/suggestions/object-unsafe-trait-should-use-where-sized.fixed rename to tests/ui/suggestions/dyn-incompatible-trait-should-use-where-sized.fixed diff --git a/tests/ui/suggestions/object-unsafe-trait-should-use-where-sized.rs b/tests/ui/suggestions/dyn-incompatible-trait-should-use-where-sized.rs similarity index 100% rename from tests/ui/suggestions/object-unsafe-trait-should-use-where-sized.rs rename to tests/ui/suggestions/dyn-incompatible-trait-should-use-where-sized.rs diff --git a/tests/ui/suggestions/object-unsafe-trait-should-use-where-sized.stderr b/tests/ui/suggestions/dyn-incompatible-trait-should-use-where-sized.stderr similarity index 89% rename from tests/ui/suggestions/object-unsafe-trait-should-use-where-sized.stderr rename to tests/ui/suggestions/dyn-incompatible-trait-should-use-where-sized.stderr index 5e3a0290d42c0..beafd7c2ab00f 100644 --- a/tests/ui/suggestions/object-unsafe-trait-should-use-where-sized.stderr +++ b/tests/ui/suggestions/dyn-incompatible-trait-should-use-where-sized.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Trait` cannot be made into an object - --> $DIR/object-unsafe-trait-should-use-where-sized.rs:9:12 + --> $DIR/dyn-incompatible-trait-should-use-where-sized.rs:9:12 | LL | fn bar(x: &dyn Trait) {} | ^^^^^^^^^ `Trait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/object-unsafe-trait-should-use-where-sized.rs:5:8 + --> $DIR/dyn-incompatible-trait-should-use-where-sized.rs:5:8 | LL | trait Trait { | ----- this trait cannot be made into an object... @@ -27,7 +27,7 @@ LL | fn bar(self: &Self) {} | ~~~~~ error[E0307]: invalid `self` parameter type: `()` - --> $DIR/object-unsafe-trait-should-use-where-sized.rs:6:18 + --> $DIR/dyn-incompatible-trait-should-use-where-sized.rs:6:18 | LL | fn bar(self: ()) {} | ^^ diff --git a/tests/ui/suggestions/issue-98500.rs b/tests/ui/suggestions/issue-98500.rs index b6fd9e7c23fe3..289b16abf4b37 100644 --- a/tests/ui/suggestions/issue-98500.rs +++ b/tests/ui/suggestions/issue-98500.rs @@ -1,9 +1,9 @@ -//@ aux-build:not-object-safe.rs +//@ aux-build:dyn-incompatible.rs -extern crate not_object_safe; +extern crate dyn_incompatible; pub trait B where - Self: not_object_safe::A, + Self: dyn_incompatible::A, { fn f2(&self); } diff --git a/tests/ui/suggestions/issue-98500.stderr b/tests/ui/suggestions/issue-98500.stderr index c4b446763afe5..d7136ec1a649f 100644 --- a/tests/ui/suggestions/issue-98500.stderr +++ b/tests/ui/suggestions/issue-98500.stderr @@ -5,7 +5,7 @@ LL | struct S(Box); | ^^^^^ `B` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/auxiliary/not-object-safe.rs:4:8 + --> $DIR/auxiliary/dyn-incompatible.rs:4:8 | LL | fn f(); | ^ ...because associated function `f` has no `self` parameter diff --git a/tests/ui/traits/alias/no-duplicates.rs b/tests/ui/traits/alias/no-duplicates.rs index 88feb89170dd3..d0829ab4cecbf 100644 --- a/tests/ui/traits/alias/no-duplicates.rs +++ b/tests/ui/traits/alias/no-duplicates.rs @@ -1,4 +1,4 @@ -// The purpose of this test is to demonstrate that duplicating object safe traits +// The purpose of this test is to demonstrate that duplicating dyn-compatible traits // that are not auto traits is rejected with trait aliases even though one could // reasonably accept this. @@ -6,7 +6,7 @@ use std::marker::Unpin; -// Some arbitrary object-safe trait: +// Some arbitrary dyn-compatible trait: trait Obj {} // Nest a few levels deep: diff --git a/tests/ui/traits/alias/no-extra-traits.rs b/tests/ui/traits/alias/no-extra-traits.rs index 4dad8c0f87349..f3d35a8cd034d 100644 --- a/tests/ui/traits/alias/no-extra-traits.rs +++ b/tests/ui/traits/alias/no-extra-traits.rs @@ -5,7 +5,7 @@ use std::marker::Unpin; -// Some arbitrary object-safe traits: +// Some arbitrary dyn-compatible traits: trait ObjA {} trait ObjB {} diff --git a/tests/ui/traits/alias/object-wf.rs b/tests/ui/traits/alias/object-wf.rs index 3abffd22d142f..a14cfea3bd7ad 100644 --- a/tests/ui/traits/alias/object-wf.rs +++ b/tests/ui/traits/alias/object-wf.rs @@ -20,7 +20,7 @@ fn _f0() { let _: Box; } -// Include object safe traits: +// Include dyn-compatible traits: fn _f1() { let _: Box; @@ -28,7 +28,7 @@ fn _f1() { let _: Box; } -// And when the object safe trait is in a trait alias: +// And when the dyn-compatible trait is in a trait alias: trait _2 = Obj; diff --git a/tests/ui/traits/next-solver/object-unsafety.rs b/tests/ui/traits/next-solver/dyn-incompatibility.rs similarity index 100% rename from tests/ui/traits/next-solver/object-unsafety.rs rename to tests/ui/traits/next-solver/dyn-incompatibility.rs diff --git a/tests/ui/traits/next-solver/object-unsafety.stderr b/tests/ui/traits/next-solver/dyn-incompatibility.stderr similarity index 90% rename from tests/ui/traits/next-solver/object-unsafety.stderr rename to tests/ui/traits/next-solver/dyn-incompatibility.stderr index 75d0ce244132e..7f2c0646ef501 100644 --- a/tests/ui/traits/next-solver/object-unsafety.stderr +++ b/tests/ui/traits/next-solver/dyn-incompatibility.stderr @@ -1,12 +1,12 @@ error[E0277]: the trait bound `T: Copy` is not satisfied in `dyn Setup` - --> $DIR/object-unsafety.rs:12:12 + --> $DIR/dyn-incompatibility.rs:12:12 | LL | copy::>(t) | ^^^^^^^^^^^^^^^^^ within `dyn Setup`, the trait `Copy` is not implemented for `T`, which is required by `dyn Setup: Setup` | = note: required because it appears within the type `dyn Setup` note: required by a bound in `copy` - --> $DIR/object-unsafety.rs:7:12 + --> $DIR/dyn-incompatibility.rs:7:12 | LL | fn copy(from: &U::From) -> U::From { | ^^^^^ required by this bound in `copy` @@ -16,7 +16,7 @@ LL | pub fn copy_any(t: &T) -> T { | +++++++++++++++++++ error[E0308]: mismatched types - --> $DIR/object-unsafety.rs:12:31 + --> $DIR/dyn-incompatibility.rs:12:31 | LL | copy::>(t) | ------------------------- ^ types differ @@ -26,13 +26,13 @@ LL | copy::>(t) = note: expected reference `& as Setup>::From` found reference `&T` note: function defined here - --> $DIR/object-unsafety.rs:7:4 + --> $DIR/dyn-incompatibility.rs:7:4 | LL | fn copy(from: &U::From) -> U::From { | ^^^^ -------------- error[E0277]: the trait bound `T: Copy` is not satisfied in `dyn Setup` - --> $DIR/object-unsafety.rs:12:5 + --> $DIR/dyn-incompatibility.rs:12:5 | LL | copy::>(t) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `dyn Setup`, the trait `Copy` is not implemented for `T`, which is required by `dyn Setup: Setup` diff --git a/tests/ui/traits/non_lifetime_binders/supertrait-object-safety.rs b/tests/ui/traits/non_lifetime_binders/supertrait-dyn-compatibility.rs similarity index 100% rename from tests/ui/traits/non_lifetime_binders/supertrait-object-safety.rs rename to tests/ui/traits/non_lifetime_binders/supertrait-dyn-compatibility.rs diff --git a/tests/ui/traits/non_lifetime_binders/supertrait-object-safety.stderr b/tests/ui/traits/non_lifetime_binders/supertrait-dyn-compatibility.stderr similarity index 88% rename from tests/ui/traits/non_lifetime_binders/supertrait-object-safety.stderr rename to tests/ui/traits/non_lifetime_binders/supertrait-dyn-compatibility.stderr index 0854ea28150fb..dd2dca74f9087 100644 --- a/tests/ui/traits/non_lifetime_binders/supertrait-object-safety.stderr +++ b/tests/ui/traits/non_lifetime_binders/supertrait-dyn-compatibility.stderr @@ -1,5 +1,5 @@ warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/supertrait-object-safety.rs:1:12 + --> $DIR/supertrait-dyn-compatibility.rs:1:12 | LL | #![feature(non_lifetime_binders)] | ^^^^^^^^^^^^^^^^^^^^ @@ -8,13 +8,13 @@ LL | #![feature(non_lifetime_binders)] = note: `#[warn(incomplete_features)]` on by default error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/supertrait-object-safety.rs:19:23 + --> $DIR/supertrait-dyn-compatibility.rs:19:23 | LL | let x: &dyn Foo = &(); | ^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/supertrait-object-safety.rs:4:12 + --> $DIR/supertrait-dyn-compatibility.rs:4:12 | LL | trait Foo: for Bar {} | --- ^^^^^^^^^^^^^ ...because where clause cannot reference non-lifetime `for<...>` variables @@ -24,13 +24,13 @@ LL | trait Foo: for Bar {} = note: required for the cast from `&()` to `&dyn Foo` error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/supertrait-object-safety.rs:19:12 + --> $DIR/supertrait-dyn-compatibility.rs:19:12 | LL | let x: &dyn Foo = &(); | ^^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/supertrait-object-safety.rs:4:12 + --> $DIR/supertrait-dyn-compatibility.rs:4:12 | LL | trait Foo: for Bar {} | --- ^^^^^^^^^^^^^ ...because where clause cannot reference non-lifetime `for<...>` variables @@ -39,13 +39,13 @@ LL | trait Foo: for Bar {} = help: only type `()` implements the trait, consider using it directly instead error[E0038]: the trait `Foo` cannot be made into an object - --> $DIR/supertrait-object-safety.rs:22:5 + --> $DIR/supertrait-dyn-compatibility.rs:22:5 | LL | needs_bar(x); | ^^^^^^^^^ `Foo` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/supertrait-object-safety.rs:4:12 + --> $DIR/supertrait-dyn-compatibility.rs:4:12 | LL | trait Foo: for Bar {} | --- ^^^^^^^^^^^^^ ...because where clause cannot reference non-lifetime `for<...>` variables diff --git a/tests/ui/traits/object/print_vtable_sizes.rs b/tests/ui/traits/object/print_vtable_sizes.rs index 684458d079e5e..2b1745da5f308 100644 --- a/tests/ui/traits/object/print_vtable_sizes.rs +++ b/tests/ui/traits/object/print_vtable_sizes.rs @@ -7,7 +7,7 @@ trait A: AsRef<[T::V]> + AsMut<[T::V]> {} trait B: AsRef + AsRef + AsRef + AsRef {} trait C { - fn x() {} // not object safe, shouldn't be reported + fn x() {} // not dyn-compatible, shouldn't be reported } // This does not have any upcasting cost, diff --git a/tests/ui/traits/object/safety.rs b/tests/ui/traits/object/safety.rs index f43d332d69637..f4abcf8542e5f 100644 --- a/tests/ui/traits/object/safety.rs +++ b/tests/ui/traits/object/safety.rs @@ -1,4 +1,4 @@ -// Check that static methods are not object-safe. +// Check that static methods render the trait dyn-incompatible. trait Tr { fn foo(); diff --git a/tests/ui/traits/vtable/vtable-non-object-safe.rs b/tests/ui/traits/vtable/vtable-dyn-incompatible.rs similarity index 78% rename from tests/ui/traits/vtable/vtable-non-object-safe.rs rename to tests/ui/traits/vtable/vtable-dyn-incompatible.rs index f98af0f23b732..64a8138bdcfb3 100644 --- a/tests/ui/traits/vtable/vtable-non-object-safe.rs +++ b/tests/ui/traits/vtable/vtable-dyn-incompatible.rs @@ -1,7 +1,7 @@ //@ build-fail #![feature(rustc_attrs)] -// Ensure that non-object-safe methods in Iterator does not generate +// Ensure that dyn-incompatible methods in Iterator does not generate // vtable entries. #[rustc_dump_vtable] diff --git a/tests/ui/traits/vtable/vtable-non-object-safe.stderr b/tests/ui/traits/vtable/vtable-dyn-incompatible.stderr similarity index 92% rename from tests/ui/traits/vtable/vtable-non-object-safe.stderr rename to tests/ui/traits/vtable/vtable-dyn-incompatible.stderr index 53eef5d0b13ca..e442c3eac00ea 100644 --- a/tests/ui/traits/vtable/vtable-non-object-safe.stderr +++ b/tests/ui/traits/vtable/vtable-dyn-incompatible.stderr @@ -7,7 +7,7 @@ error: vtable entries for ` as A>`: [ Method( as Iterator>::advance_by), Method( as Iterator>::nth), ] - --> $DIR/vtable-non-object-safe.rs:8:1 + --> $DIR/vtable-dyn-incompatible.rs:8:1 | LL | trait A: Iterator {} | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/traits/wf-object/no-duplicates.rs b/tests/ui/traits/wf-object/no-duplicates.rs index 678ede58296a4..83544064ce210 100644 --- a/tests/ui/traits/wf-object/no-duplicates.rs +++ b/tests/ui/traits/wf-object/no-duplicates.rs @@ -1,7 +1,7 @@ -// The purpose of this test is to demonstrate that duplicating object safe traits +// The purpose of this test is to demonstrate that duplicating dyn-compatible traits // that are not auto-traits is rejected even though one could reasonably accept this. -// Some arbitrary object-safe trait: +// Some arbitrary dyn-compatible trait: trait Obj {} // Demonstrate that recursive expansion of trait aliases doesn't affect stable behavior: diff --git a/tests/ui/traits/wf-object/reverse-order.rs b/tests/ui/traits/wf-object/reverse-order.rs index b8f2aae89663b..99c727cc332b2 100644 --- a/tests/ui/traits/wf-object/reverse-order.rs +++ b/tests/ui/traits/wf-object/reverse-order.rs @@ -2,7 +2,7 @@ // Ensure that `dyn $($AutoTrait)+ ObjSafe` is well-formed. -// Some arbitrary object-safe trait: +// Some arbitrary dyn-compatible trait: trait Obj {} type _0 = dyn Unpin; diff --git a/tests/ui/unsized-locals/by-value-trait-object-safety-rpass.rs b/tests/ui/unsized-locals/by-value-trait-dyn-compatibility-rpass.rs similarity index 100% rename from tests/ui/unsized-locals/by-value-trait-object-safety-rpass.rs rename to tests/ui/unsized-locals/by-value-trait-dyn-compatibility-rpass.rs diff --git a/tests/ui/unsized-locals/by-value-trait-object-safety-withdefault.rs b/tests/ui/unsized-locals/by-value-trait-dyn-compatibility-with-default.rs similarity index 100% rename from tests/ui/unsized-locals/by-value-trait-object-safety-withdefault.rs rename to tests/ui/unsized-locals/by-value-trait-dyn-compatibility-with-default.rs diff --git a/tests/ui/unsized-locals/by-value-trait-object-safety.rs b/tests/ui/unsized-locals/by-value-trait-dyn-compatibility.rs similarity index 100% rename from tests/ui/unsized-locals/by-value-trait-object-safety.rs rename to tests/ui/unsized-locals/by-value-trait-dyn-compatibility.rs diff --git a/tests/ui/unsized-locals/by-value-trait-object-safety.stderr b/tests/ui/unsized-locals/by-value-trait-dyn-compatibility.stderr similarity index 84% rename from tests/ui/unsized-locals/by-value-trait-object-safety.stderr rename to tests/ui/unsized-locals/by-value-trait-dyn-compatibility.stderr index 6a93464febb10..223624cfca4dd 100644 --- a/tests/ui/unsized-locals/by-value-trait-object-safety.stderr +++ b/tests/ui/unsized-locals/by-value-trait-dyn-compatibility.stderr @@ -1,5 +1,5 @@ warning: the feature `unsized_locals` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/by-value-trait-object-safety.rs:1:12 + --> $DIR/by-value-trait-dyn-compatibility.rs:1:12 | LL | #![feature(unsized_locals)] | ^^^^^^^^^^^^^^ @@ -8,7 +8,7 @@ LL | #![feature(unsized_locals)] = note: `#[warn(incomplete_features)]` on by default error: the `foo` method cannot be invoked on a trait object - --> $DIR/by-value-trait-object-safety.rs:20:7 + --> $DIR/by-value-trait-dyn-compatibility.rs:20:7 | LL | Self: Sized; | ----- this has a `Sized` requirement diff --git a/tests/ui/wf/wf-convert-unsafe-trait-obj-box.rs b/tests/ui/wf/wf-convert-dyn-incompat-trait-obj-box.rs similarity index 87% rename from tests/ui/wf/wf-convert-unsafe-trait-obj-box.rs rename to tests/ui/wf/wf-convert-dyn-incompat-trait-obj-box.rs index e32b04c471524..26292a1d218c9 100644 --- a/tests/ui/wf/wf-convert-unsafe-trait-obj-box.rs +++ b/tests/ui/wf/wf-convert-dyn-incompat-trait-obj-box.rs @@ -1,5 +1,5 @@ // Check that we do not allow casts or coercions -// to object unsafe trait objects inside a Box +// to dyn-incompatible trait objects inside a Box #![feature(dyn_compatible_for_dispatch)] diff --git a/tests/ui/wf/wf-convert-unsafe-trait-obj-box.stderr b/tests/ui/wf/wf-convert-dyn-incompat-trait-obj-box.stderr similarity index 86% rename from tests/ui/wf/wf-convert-unsafe-trait-obj-box.stderr rename to tests/ui/wf/wf-convert-dyn-incompat-trait-obj-box.stderr index 2565e25a24297..38426545bc8cb 100644 --- a/tests/ui/wf/wf-convert-unsafe-trait-obj-box.stderr +++ b/tests/ui/wf/wf-convert-dyn-incompat-trait-obj-box.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Trait` cannot be made into an object - --> $DIR/wf-convert-unsafe-trait-obj-box.rs:16:33 + --> $DIR/wf-convert-dyn-incompat-trait-obj-box.rs:16:33 | LL | let t_box: Box = Box::new(S); | ^^^^^^^^^^^ `Trait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/wf-convert-unsafe-trait-obj-box.rs:6:14 + --> $DIR/wf-convert-dyn-incompat-trait-obj-box.rs:6:14 | LL | trait Trait: Sized {} | ----- ^^^^^ ...because it requires `Self: Sized` @@ -15,13 +15,13 @@ LL | trait Trait: Sized {} = note: required for the cast from `Box` to `Box` error[E0038]: the trait `Trait` cannot be made into an object - --> $DIR/wf-convert-unsafe-trait-obj-box.rs:17:15 + --> $DIR/wf-convert-dyn-incompat-trait-obj-box.rs:17:15 | LL | takes_box(Box::new(S)); | ^^^^^^^^^^^ `Trait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/wf-convert-unsafe-trait-obj-box.rs:6:14 + --> $DIR/wf-convert-dyn-incompat-trait-obj-box.rs:6:14 | LL | trait Trait: Sized {} | ----- ^^^^^ ...because it requires `Self: Sized` @@ -31,13 +31,13 @@ LL | trait Trait: Sized {} = note: required for the cast from `Box` to `Box<(dyn Trait + 'static)>` error[E0038]: the trait `Trait` cannot be made into an object - --> $DIR/wf-convert-unsafe-trait-obj-box.rs:15:5 + --> $DIR/wf-convert-dyn-incompat-trait-obj-box.rs:15:5 | LL | Box::new(S) as Box; | ^^^^^^^^^^^ `Trait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/wf-convert-unsafe-trait-obj-box.rs:6:14 + --> $DIR/wf-convert-dyn-incompat-trait-obj-box.rs:6:14 | LL | trait Trait: Sized {} | ----- ^^^^^ ...because it requires `Self: Sized` diff --git a/tests/ui/wf/wf-convert-unsafe-trait-obj.rs b/tests/ui/wf/wf-convert-dyn-incompat-trait-obj.rs similarity index 87% rename from tests/ui/wf/wf-convert-unsafe-trait-obj.rs rename to tests/ui/wf/wf-convert-dyn-incompat-trait-obj.rs index 6f38635281983..ec4bb2897f9dc 100644 --- a/tests/ui/wf/wf-convert-unsafe-trait-obj.rs +++ b/tests/ui/wf/wf-convert-dyn-incompat-trait-obj.rs @@ -1,5 +1,5 @@ // Check that we do not allow casts or coercions -// to object unsafe trait objects by ref +// to dyn-incompatible trait objects by ref #![feature(dyn_compatible_for_dispatch)] diff --git a/tests/ui/wf/wf-convert-unsafe-trait-obj.stderr b/tests/ui/wf/wf-convert-dyn-incompat-trait-obj.stderr similarity index 87% rename from tests/ui/wf/wf-convert-unsafe-trait-obj.stderr rename to tests/ui/wf/wf-convert-dyn-incompat-trait-obj.stderr index 97f6bcd0428b6..94259aa5b0aa8 100644 --- a/tests/ui/wf/wf-convert-unsafe-trait-obj.stderr +++ b/tests/ui/wf/wf-convert-dyn-incompat-trait-obj.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `Trait` cannot be made into an object - --> $DIR/wf-convert-unsafe-trait-obj.rs:16:25 + --> $DIR/wf-convert-dyn-incompat-trait-obj.rs:16:25 | LL | let t: &dyn Trait = &S; | ^^ `Trait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/wf-convert-unsafe-trait-obj.rs:6:14 + --> $DIR/wf-convert-dyn-incompat-trait-obj.rs:6:14 | LL | trait Trait: Sized {} | ----- ^^^^^ ...because it requires `Self: Sized` @@ -15,13 +15,13 @@ LL | trait Trait: Sized {} = note: required for the cast from `&S` to `&dyn Trait` error[E0038]: the trait `Trait` cannot be made into an object - --> $DIR/wf-convert-unsafe-trait-obj.rs:17:17 + --> $DIR/wf-convert-dyn-incompat-trait-obj.rs:17:17 | LL | takes_trait(&S); | ^^ `Trait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/wf-convert-unsafe-trait-obj.rs:6:14 + --> $DIR/wf-convert-dyn-incompat-trait-obj.rs:6:14 | LL | trait Trait: Sized {} | ----- ^^^^^ ...because it requires `Self: Sized` @@ -31,13 +31,13 @@ LL | trait Trait: Sized {} = note: required for the cast from `&S` to `&dyn Trait` error[E0038]: the trait `Trait` cannot be made into an object - --> $DIR/wf-convert-unsafe-trait-obj.rs:15:5 + --> $DIR/wf-convert-dyn-incompat-trait-obj.rs:15:5 | LL | &S as &dyn Trait; | ^^ `Trait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/wf-convert-unsafe-trait-obj.rs:6:14 + --> $DIR/wf-convert-dyn-incompat-trait-obj.rs:6:14 | LL | trait Trait: Sized {} | ----- ^^^^^ ...because it requires `Self: Sized` diff --git a/tests/ui/wf/wf-unsafe-trait-obj-match.rs b/tests/ui/wf/wf-dyn-incompat-trait-obj-match.rs similarity index 100% rename from tests/ui/wf/wf-unsafe-trait-obj-match.rs rename to tests/ui/wf/wf-dyn-incompat-trait-obj-match.rs diff --git a/tests/ui/wf/wf-unsafe-trait-obj-match.stderr b/tests/ui/wf/wf-dyn-incompat-trait-obj-match.stderr similarity index 89% rename from tests/ui/wf/wf-unsafe-trait-obj-match.stderr rename to tests/ui/wf/wf-dyn-incompat-trait-obj-match.stderr index edbdec6a5efc6..d7366e12256a2 100644 --- a/tests/ui/wf/wf-unsafe-trait-obj-match.stderr +++ b/tests/ui/wf/wf-dyn-incompat-trait-obj-match.stderr @@ -1,5 +1,5 @@ error[E0308]: `match` arms have incompatible types - --> $DIR/wf-unsafe-trait-obj-match.rs:23:17 + --> $DIR/wf-dyn-incompat-trait-obj-match.rs:23:17 | LL | / match opt() { LL | | Some(()) => &S, @@ -13,13 +13,13 @@ LL | | } found reference `&R` error[E0038]: the trait `Trait` cannot be made into an object - --> $DIR/wf-unsafe-trait-obj-match.rs:26:21 + --> $DIR/wf-dyn-incompat-trait-obj-match.rs:26:21 | LL | Some(()) => &S, | ^^ `Trait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/wf-unsafe-trait-obj-match.rs:6:14 + --> $DIR/wf-dyn-incompat-trait-obj-match.rs:6:14 | LL | trait Trait: Sized {} | ----- ^^^^^ ...because it requires `Self: Sized` @@ -31,7 +31,7 @@ LL | trait Trait: Sized {} = note: required for the cast from `&S` to `&dyn Trait` error[E0038]: the trait `Trait` cannot be made into an object - --> $DIR/wf-unsafe-trait-obj-match.rs:25:25 + --> $DIR/wf-dyn-incompat-trait-obj-match.rs:25:25 | LL | let t: &dyn Trait = match opt() { | _________________________^ @@ -41,7 +41,7 @@ LL | | }; | |_____^ `Trait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/wf-unsafe-trait-obj-match.rs:6:14 + --> $DIR/wf-dyn-incompat-trait-obj-match.rs:6:14 | LL | trait Trait: Sized {} | ----- ^^^^^ ...because it requires `Self: Sized` diff --git a/tests/ui/wf/wf-object-safe.rs b/tests/ui/wf/wf-dyn-incompatible.rs similarity index 57% rename from tests/ui/wf/wf-object-safe.rs rename to tests/ui/wf/wf-dyn-incompatible.rs index 42e6917551fd9..16e7ca1cbc618 100644 --- a/tests/ui/wf/wf-object-safe.rs +++ b/tests/ui/wf/wf-dyn-incompatible.rs @@ -1,4 +1,4 @@ -// Check that object-safe traits are not WF when used as object types. +// Check that dyn-incompatible traits are not WF when used as trait object types. // Issue #21953. trait A { diff --git a/tests/ui/wf/wf-object-safe.stderr b/tests/ui/wf/wf-dyn-incompatible.stderr similarity index 90% rename from tests/ui/wf/wf-object-safe.stderr rename to tests/ui/wf/wf-dyn-incompatible.stderr index 7c14f3d2f8bf6..cf016b63c7405 100644 --- a/tests/ui/wf/wf-object-safe.stderr +++ b/tests/ui/wf/wf-dyn-incompatible.stderr @@ -1,11 +1,11 @@ error[E0038]: the trait `A` cannot be made into an object - --> $DIR/wf-object-safe.rs:9:13 + --> $DIR/wf-dyn-incompatible.rs:9:13 | LL | let _x: &dyn A; | ^^^^^^ `A` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/wf-object-safe.rs:5:23 + --> $DIR/wf-dyn-incompatible.rs:5:23 | LL | trait A { | - this trait cannot be made into an object... From b12dc2091012d1e8074ccea0ffe6ac16de1ba802 Mon Sep 17 00:00:00 2001 From: Manuel Drehwald Date: Thu, 10 Oct 2024 11:38:28 +0200 Subject: [PATCH 08/16] add config to explicitely test rustc with autodiff/enzyme disabled --- src/tools/compiletest/src/command-list.rs | 1 + src/tools/compiletest/src/header/cfg.rs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/tools/compiletest/src/command-list.rs b/src/tools/compiletest/src/command-list.rs index 53db55d0c10ff..ab57320b4d910 100644 --- a/src/tools/compiletest/src/command-list.rs +++ b/src/tools/compiletest/src/command-list.rs @@ -49,6 +49,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[ "ignore-eabi", "ignore-emscripten", "ignore-endian-big", + "ignore-enzyme", "ignore-freebsd", "ignore-fuchsia", "ignore-gdb", diff --git a/src/tools/compiletest/src/header/cfg.rs b/src/tools/compiletest/src/header/cfg.rs index 6e351aa27b909..b9314f0abbbc8 100644 --- a/src/tools/compiletest/src/header/cfg.rs +++ b/src/tools/compiletest/src/header/cfg.rs @@ -166,6 +166,12 @@ pub(super) fn parse_cfg_name_directive<'a>( message: "when the target vendor is Apple" } + condition! { + name: "enzyme", + condition: config.has_enzyme, + message: "when rustc is built with LLVM Enzyme" + } + // Technically the locally built compiler uses the "dev" channel rather than the "nightly" // channel, even though most people don't know or won't care about it. To avoid confusion, we // treat the "dev" channel as the "nightly" channel when processing the directive. From 1edff466e19c4e2e2f8035de5a25d8a2dc2fef96 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 10 Oct 2024 11:46:11 +0200 Subject: [PATCH 09/16] Avoid redundant additions to PATH when linking --- compiler/rustc_session/src/session.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index d67e69fe0fb72..27879d817b208 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -454,6 +454,8 @@ impl Session { let bin_path = filesearch::make_target_bin_path(&self.sysroot, config::host_triple()); let fallback_sysroot_paths = filesearch::sysroot_candidates() .into_iter() + // Ignore sysroot candidate if it was the same as the sysroot path we just used. + .filter(|sysroot| *sysroot != self.sysroot) .map(|sysroot| filesearch::make_target_bin_path(&sysroot, config::host_triple())); let search_paths = std::iter::once(bin_path).chain(fallback_sysroot_paths); From 2900c58a02c48da60a2d2d45613acf25164efa2b Mon Sep 17 00:00:00 2001 From: Kajetan Puchalski Date: Thu, 19 Sep 2024 08:28:09 +0000 Subject: [PATCH 10/16] stdarch: Bump stdarch submodule --- library/stdarch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/stdarch b/library/stdarch index ace72223a0e32..c881fe3231b39 160000 --- a/library/stdarch +++ b/library/stdarch @@ -1 +1 @@ -Subproject commit ace72223a0e321c1b0a37b5862aa756fe8ab5111 +Subproject commit c881fe3231b3947a4766aa15a26a93022fbb8723 From 335f67b6527cbeb576151dab1dadec161eaede45 Mon Sep 17 00:00:00 2001 From: Kajetan Puchalski Date: Tue, 3 Sep 2024 13:51:54 +0100 Subject: [PATCH 11/16] rustc_target: Add sme-b16b16 as an explicit aarch64 target feature LLVM 20 split out what used to be called b16b16 and correspond to aarch64 FEAT_SVE_B16B16 into sve-b16b16 and sme-b16b16. Add sme-b16b16 as an explicit feature and update the codegen accordingly. --- compiler/rustc_codegen_llvm/src/llvm_util.rs | 4 +++- compiler/rustc_target/src/target_features.rs | 4 +++- library/std/tests/run-time-detect.rs | 1 + tests/ui/check-cfg/mix.stderr | 2 +- tests/ui/check-cfg/well-known-values.stderr | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index bd847cd0068e5..8290e1a95441b 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -247,7 +247,9 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option Some(LLVMFeature::new("perfmon")), ("aarch64", "paca") => Some(LLVMFeature::new("pauth")), ("aarch64", "pacg") => Some(LLVMFeature::new("pauth")), - ("aarch64", "sve-b16b16") => Some(LLVMFeature::new("b16b16")), + // Before LLVM 20 those two features were packaged together as b16b16 + ("aarch64", "sve-b16b16") if get_version().0 < 20 => Some(LLVMFeature::new("b16b16")), + ("aarch64", "sme-b16b16") if get_version().0 < 20 => Some(LLVMFeature::new("b16b16")), ("aarch64", "flagm2") => Some(LLVMFeature::new("altnzcv")), // Rust ties fp and neon together. ("aarch64", "neon") => { diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs index 0a98b363b1a6e..e92366d5c5c3f 100644 --- a/compiler/rustc_target/src/target_features.rs +++ b/compiler/rustc_target/src/target_features.rs @@ -191,6 +191,8 @@ const AARCH64_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ ("sm4", Stable, &["neon"]), // FEAT_SME ("sme", Unstable(sym::aarch64_unstable_target_feature), &["bf16"]), + // FEAT_SME_B16B16 + ("sme-b16b16", Unstable(sym::aarch64_unstable_target_feature), &["bf16", "sme2", "sve-b16b16"]), // FEAT_SME_F16F16 ("sme-f16f16", Unstable(sym::aarch64_unstable_target_feature), &["sme2"]), // FEAT_SME_F64F64 @@ -227,7 +229,7 @@ const AARCH64_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ // // "For backwards compatibility, Neon and VFP are required in the latest architectures." ("sve", Stable, &["neon"]), - // FEAT_SVE_B16B16 (SVE or SME Instructions) + // FEAT_SVE_B16B16 (SVE or SME Z-targeting instructions) ("sve-b16b16", Unstable(sym::aarch64_unstable_target_feature), &["bf16"]), // FEAT_SVE2 ("sve2", Stable, &["sve"]), diff --git a/library/std/tests/run-time-detect.rs b/library/std/tests/run-time-detect.rs index dcd5cd7f6b9c7..dd14c0266aa4d 100644 --- a/library/std/tests/run-time-detect.rs +++ b/library/std/tests/run-time-detect.rs @@ -82,6 +82,7 @@ fn aarch64_linux() { println!("sha2: {}", is_aarch64_feature_detected!("sha2")); println!("sha3: {}", is_aarch64_feature_detected!("sha3")); println!("sm4: {}", is_aarch64_feature_detected!("sm4")); + println!("sme-b16b16: {}", is_aarch64_feature_detected!("sme-b16b16")); println!("sme-f16f16: {}", is_aarch64_feature_detected!("sme-f16f16")); println!("sme-f64f64: {}", is_aarch64_feature_detected!("sme-f64f64")); println!("sme-f8f16: {}", is_aarch64_feature_detected!("sme-f8f16")); diff --git a/tests/ui/check-cfg/mix.stderr b/tests/ui/check-cfg/mix.stderr index 7726c2d52f571..c21016e929093 100644 --- a/tests/ui/check-cfg/mix.stderr +++ b/tests/ui/check-cfg/mix.stderr @@ -251,7 +251,7 @@ warning: unexpected `cfg` condition value: `zebra` LL | cfg!(target_feature = "zebra"); | ^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, and `avx512vpopcntdq` and 244 more + = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, and `avx512vpopcntdq` and 245 more = note: see for more information about checking conditional configuration warning: 27 warnings emitted diff --git a/tests/ui/check-cfg/well-known-values.stderr b/tests/ui/check-cfg/well-known-values.stderr index c6d403104ea6b..da790bbd52859 100644 --- a/tests/ui/check-cfg/well-known-values.stderr +++ b/tests/ui/check-cfg/well-known-values.stderr @@ -174,7 +174,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` LL | target_feature = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, `avx512vpopcntdq`, `avxifma`, `avxneconvert`, `avxvnni`, `avxvnniint16`, `avxvnniint8`, `backchain`, `bf16`, `bmi1`, `bmi2`, `bti`, `bulk-memory`, `c`, `cache`, `cmpxchg16b`, `crc`, `crt-static`, `cssc`, `d`, `d32`, `dit`, `doloop`, `dotprod`, `dpb`, `dpb2`, `dsp`, `dsp1e2`, `dspe60`, `e`, `e1`, `e2`, `ecv`, `edsp`, `elrw`, `ermsb`, `exception-handling`, `extended-const`, `f`, `f16c`, `f32mm`, `f64mm`, `faminmax`, `fcma`, `fdivdu`, `fhm`, `flagm`, `flagm2`, `float1e2`, `float1e3`, `float3e4`, `float7e60`, `floate1`, `fma`, `fp-armv8`, `fp16`, `fp64`, `fp8`, `fp8dot2`, `fp8dot4`, `fp8fma`, `fpuv2_df`, `fpuv2_sf`, `fpuv3_df`, `fpuv3_hf`, `fpuv3_hi`, `fpuv3_sf`, `frecipe`, `frintts`, `fxsr`, `gfni`, `hard-float`, `hard-float-abi`, `hard-tp`, `hbc`, `high-registers`, `hvx`, `hvx-length128b`, `hwdiv`, `i8mm`, `jsconv`, `lahfsahf`, `lasx`, `lbt`, `lor`, `lse`, `lse128`, `lse2`, `lsx`, `lut`, `lvz`, `lzcnt`, `m`, `mclass`, `mops`, `movbe`, `mp`, `mp1e2`, `msa`, `mte`, `multivalue`, `mutable-globals`, `neon`, `nontrapping-fptoint`, `nvic`, `paca`, `pacg`, `pan`, `partword-atomics`, `pclmulqdq`, `pmuv3`, `popcnt`, `power10-vector`, `power8-altivec`, `power8-vector`, `power9-altivec`, `power9-vector`, `prfchw`, `quadword-atomics`, `rand`, `ras`, `rclass`, `rcpc`, `rcpc2`, `rcpc3`, `rdm`, `rdrand`, `rdseed`, `reference-types`, `relax`, `relaxed-simd`, `rtm`, `sb`, `sha`, `sha2`, `sha3`, `sha512`, `sign-ext`, `simd128`, `sm3`, `sm4`, `sme`, `sme-f16f16`, `sme-f64f64`, `sme-f8f16`, `sme-f8f32`, `sme-fa64`, `sme-i16i64`, `sme-lutv2`, `sme2`, `sme2p1`, `spe`, `ssbs`, `sse`, `sse2`, `sse3`, `sse4.1`, `sse4.2`, `sse4a`, `ssse3`, `ssve-fp8dot2`, `ssve-fp8dot4`, `ssve-fp8fma`, `sve`, `sve-b16b16`, `sve2`, `sve2-aes`, `sve2-bitperm`, `sve2-sha3`, `sve2-sm4`, `sve2p1`, `tbm`, `thumb-mode`, `thumb2`, `tme`, `trust`, `trustzone`, `ual`, `unaligned-scalar-mem`, `v`, `v5te`, `v6`, `v6k`, `v6t2`, `v7`, `v8`, `v8.1a`, `v8.2a`, `v8.3a`, `v8.4a`, `v8.5a`, `v8.6a`, `v8.7a`, `v8.8a`, `v8.9a`, `v9.1a`, `v9.2a`, `v9.3a`, `v9.4a`, `v9.5a`, `v9a`, `vaes`, `vdsp2e60f`, `vdspv1`, `vdspv2`, `vector`, `vfp2`, `vfp3`, `vfp4`, `vh`, `virt`, `virtualization`, `vpclmulqdq`, `vsx`, `wfxt`, `xop`, `xsave`, `xsavec`, `xsaveopt`, `xsaves`, `zaamo`, `zabha`, `zalrsc`, `zba`, `zbb`, `zbc`, `zbkb`, `zbkc`, `zbkx`, `zbs`, `zdinx`, `zfh`, `zfhmin`, `zfinx`, `zhinx`, `zhinxmin`, `zk`, `zkn`, `zknd`, `zkne`, `zknh`, `zkr`, `zks`, `zksed`, `zksh`, and `zkt` + = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `amx-bf16`, `amx-complex`, `amx-fp16`, `amx-int8`, `amx-tile`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, `avx512vpopcntdq`, `avxifma`, `avxneconvert`, `avxvnni`, `avxvnniint16`, `avxvnniint8`, `backchain`, `bf16`, `bmi1`, `bmi2`, `bti`, `bulk-memory`, `c`, `cache`, `cmpxchg16b`, `crc`, `crt-static`, `cssc`, `d`, `d32`, `dit`, `doloop`, `dotprod`, `dpb`, `dpb2`, `dsp`, `dsp1e2`, `dspe60`, `e`, `e1`, `e2`, `ecv`, `edsp`, `elrw`, `ermsb`, `exception-handling`, `extended-const`, `f`, `f16c`, `f32mm`, `f64mm`, `faminmax`, `fcma`, `fdivdu`, `fhm`, `flagm`, `flagm2`, `float1e2`, `float1e3`, `float3e4`, `float7e60`, `floate1`, `fma`, `fp-armv8`, `fp16`, `fp64`, `fp8`, `fp8dot2`, `fp8dot4`, `fp8fma`, `fpuv2_df`, `fpuv2_sf`, `fpuv3_df`, `fpuv3_hf`, `fpuv3_hi`, `fpuv3_sf`, `frecipe`, `frintts`, `fxsr`, `gfni`, `hard-float`, `hard-float-abi`, `hard-tp`, `hbc`, `high-registers`, `hvx`, `hvx-length128b`, `hwdiv`, `i8mm`, `jsconv`, `lahfsahf`, `lasx`, `lbt`, `lor`, `lse`, `lse128`, `lse2`, `lsx`, `lut`, `lvz`, `lzcnt`, `m`, `mclass`, `mops`, `movbe`, `mp`, `mp1e2`, `msa`, `mte`, `multivalue`, `mutable-globals`, `neon`, `nontrapping-fptoint`, `nvic`, `paca`, `pacg`, `pan`, `partword-atomics`, `pclmulqdq`, `pmuv3`, `popcnt`, `power10-vector`, `power8-altivec`, `power8-vector`, `power9-altivec`, `power9-vector`, `prfchw`, `quadword-atomics`, `rand`, `ras`, `rclass`, `rcpc`, `rcpc2`, `rcpc3`, `rdm`, `rdrand`, `rdseed`, `reference-types`, `relax`, `relaxed-simd`, `rtm`, `sb`, `sha`, `sha2`, `sha3`, `sha512`, `sign-ext`, `simd128`, `sm3`, `sm4`, `sme`, `sme-b16b16`, `sme-f16f16`, `sme-f64f64`, `sme-f8f16`, `sme-f8f32`, `sme-fa64`, `sme-i16i64`, `sme-lutv2`, `sme2`, `sme2p1`, `spe`, `ssbs`, `sse`, `sse2`, `sse3`, `sse4.1`, `sse4.2`, `sse4a`, `ssse3`, `ssve-fp8dot2`, `ssve-fp8dot4`, `ssve-fp8fma`, `sve`, `sve-b16b16`, `sve2`, `sve2-aes`, `sve2-bitperm`, `sve2-sha3`, `sve2-sm4`, `sve2p1`, `tbm`, `thumb-mode`, `thumb2`, `tme`, `trust`, `trustzone`, `ual`, `unaligned-scalar-mem`, `v`, `v5te`, `v6`, `v6k`, `v6t2`, `v7`, `v8`, `v8.1a`, `v8.2a`, `v8.3a`, `v8.4a`, `v8.5a`, `v8.6a`, `v8.7a`, `v8.8a`, `v8.9a`, `v9.1a`, `v9.2a`, `v9.3a`, `v9.4a`, `v9.5a`, `v9a`, `vaes`, `vdsp2e60f`, `vdspv1`, `vdspv2`, `vector`, `vfp2`, `vfp3`, `vfp4`, `vh`, `virt`, `virtualization`, `vpclmulqdq`, `vsx`, `wfxt`, `xop`, `xsave`, `xsavec`, `xsaveopt`, `xsaves`, `zaamo`, `zabha`, `zalrsc`, `zba`, `zbb`, `zbc`, `zbkb`, `zbkc`, `zbkx`, `zbs`, `zdinx`, `zfh`, `zfhmin`, `zfinx`, `zhinx`, `zhinxmin`, `zk`, `zkn`, `zknd`, `zkne`, `zknh`, `zkr`, `zks`, `zksed`, `zksh`, and `zkt` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` From b7297ac4407e25f7872cd061246196cd4c8b485b Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 29 Sep 2024 13:08:48 -0400 Subject: [PATCH 12/16] Add gate for precise capturing in traits --- compiler/rustc_ast_lowering/src/lib.rs | 19 ++++++++++++++----- compiler/rustc_feature/src/unstable.rs | 2 ++ compiler/rustc_span/src/symbol.rs | 1 + ...eature-gate-precise_capturing_in_traits.rs | 6 ++++++ ...re-gate-precise_capturing_in_traits.stderr | 13 +++++++++++++ .../forgot-to-capture-type.stderr | 3 +++ .../precise-capturing/redundant.rpitit.stderr | 6 ++++++ ...itit-captures-more-method-lifetimes.stderr | 3 +++ .../precise-capturing/rpitit.stderr | 3 +++ .../precise-capturing/self-capture.stderr | 3 +++ 10 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 tests/ui/feature-gates/feature-gate-precise_capturing_in_traits.rs create mode 100644 tests/ui/feature-gates/feature-gate-precise_capturing_in_traits.stderr diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index b26797f42032f..35af4d63cc760 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1573,11 +1573,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // Feature gate for RPITIT + use<..> match origin { rustc_hir::OpaqueTyOrigin::FnReturn { in_trait_or_impl: Some(_), .. } => { - if let Some(span) = bounds.iter().find_map(|bound| match *bound { - ast::GenericBound::Use(_, span) => Some(span), - _ => None, - }) { - self.tcx.dcx().emit_err(errors::NoPreciseCapturesOnRpitit { span }); + if !self.tcx.features().precise_capturing_in_traits + && let Some(span) = bounds.iter().find_map(|bound| match *bound { + ast::GenericBound::Use(_, span) => Some(span), + _ => None, + }) + { + let mut diag = + self.tcx.dcx().create_err(errors::NoPreciseCapturesOnRpitit { span }); + add_feature_diagnostics( + &mut diag, + self.tcx.sess, + sym::precise_capturing_in_traits, + ); + diag.emit(); } } _ => {} diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 380e36fe40566..19a6960cf4d88 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -565,6 +565,8 @@ declare_features! ( (incomplete, pin_ergonomics, "CURRENT_RUSTC_VERSION", Some(130494)), /// Allows postfix match `expr.match { ... }` (unstable, postfix_match, "1.79.0", Some(121618)), + /// Allows `use<..>` precise capturign on impl Trait in traits. + (unstable, precise_capturing_in_traits, "CURRENT_RUSTC_VERSION", Some(130044)), /// Allows macro attributes on expressions, statements and non-inline modules. (unstable, proc_macro_hygiene, "1.30.0", Some(54727)), /// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024. diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 1527600e764c0..683f59a89995e 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1479,6 +1479,7 @@ symbols! { powif64, pre_dash_lto: "pre-lto", precise_capturing, + precise_capturing_in_traits, precise_pointer_size_matching, pref_align_of, prefetch_read_data, diff --git a/tests/ui/feature-gates/feature-gate-precise_capturing_in_traits.rs b/tests/ui/feature-gates/feature-gate-precise_capturing_in_traits.rs new file mode 100644 index 0000000000000..308b41dfc68ab --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-precise_capturing_in_traits.rs @@ -0,0 +1,6 @@ +trait Foo { + fn test() -> impl Sized + use; + //~^ ERROR `use<...>` precise capturing syntax is currently not allowed in return-position +} + +fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-precise_capturing_in_traits.stderr b/tests/ui/feature-gates/feature-gate-precise_capturing_in_traits.stderr new file mode 100644 index 0000000000000..b2c6bf61124d9 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-precise_capturing_in_traits.stderr @@ -0,0 +1,13 @@ +error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits + --> $DIR/feature-gate-precise_capturing_in_traits.rs:2:31 + | +LL | fn test() -> impl Sized + use; + | ^^^^^^^^^ + | + = note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope + = note: see issue #130044 for more information + = help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 1 previous error + diff --git a/tests/ui/impl-trait/precise-capturing/forgot-to-capture-type.stderr b/tests/ui/impl-trait/precise-capturing/forgot-to-capture-type.stderr index d9be9d543e450..23d6a3bd11e82 100644 --- a/tests/ui/impl-trait/precise-capturing/forgot-to-capture-type.stderr +++ b/tests/ui/impl-trait/precise-capturing/forgot-to-capture-type.stderr @@ -5,6 +5,9 @@ LL | fn bar() -> impl Sized + use<>; | ^^^^^ | = note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope + = note: see issue #130044 for more information + = help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: `impl Trait` must mention all type parameters in scope in `use<...>` --> $DIR/forgot-to-capture-type.rs:1:23 diff --git a/tests/ui/impl-trait/precise-capturing/redundant.rpitit.stderr b/tests/ui/impl-trait/precise-capturing/redundant.rpitit.stderr index 213888356e572..27f8ff92d3e65 100644 --- a/tests/ui/impl-trait/precise-capturing/redundant.rpitit.stderr +++ b/tests/ui/impl-trait/precise-capturing/redundant.rpitit.stderr @@ -5,6 +5,9 @@ LL | fn in_trait() -> impl Sized + use<'a, Self>; | ^^^^^^^^^^^^^ | = note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope + = note: see issue #130044 for more information + = help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits --> $DIR/redundant.rs:21:35 @@ -13,6 +16,9 @@ LL | fn in_trait() -> impl Sized + use<'a> {} | ^^^^^^^ | = note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope + = note: see issue #130044 for more information + = help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: aborting due to 2 previous errors diff --git a/tests/ui/impl-trait/precise-capturing/rpitit-captures-more-method-lifetimes.stderr b/tests/ui/impl-trait/precise-capturing/rpitit-captures-more-method-lifetimes.stderr index b390a23eef414..ffd9646a4038b 100644 --- a/tests/ui/impl-trait/precise-capturing/rpitit-captures-more-method-lifetimes.stderr +++ b/tests/ui/impl-trait/precise-capturing/rpitit-captures-more-method-lifetimes.stderr @@ -5,6 +5,9 @@ LL | fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use; | ^^^^^^^^^ | = note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope + = note: see issue #130044 for more information + = help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: return type captures more lifetimes than trait definition --> $DIR/rpitit-captures-more-method-lifetimes.rs:11:40 diff --git a/tests/ui/impl-trait/precise-capturing/rpitit.stderr b/tests/ui/impl-trait/precise-capturing/rpitit.stderr index 5a120df9f047a..c162875f327cc 100644 --- a/tests/ui/impl-trait/precise-capturing/rpitit.stderr +++ b/tests/ui/impl-trait/precise-capturing/rpitit.stderr @@ -5,6 +5,9 @@ LL | fn hello() -> impl PartialEq + use; | ^^^^^^^^^ | = note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope + = note: see issue #130044 for more information + = help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list --> $DIR/rpitit.rs:9:19 diff --git a/tests/ui/impl-trait/precise-capturing/self-capture.stderr b/tests/ui/impl-trait/precise-capturing/self-capture.stderr index c1974600f30c5..45ebc429d88a7 100644 --- a/tests/ui/impl-trait/precise-capturing/self-capture.stderr +++ b/tests/ui/impl-trait/precise-capturing/self-capture.stderr @@ -5,6 +5,9 @@ LL | fn bar<'a>() -> impl Sized + use; | ^^^^^^^^^ | = note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope + = note: see issue #130044 for more information + = help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: aborting due to 1 previous error From a7dc98733da8b84cfc21a538541a41803c4529a0 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 29 Sep 2024 13:41:13 -0400 Subject: [PATCH 13/16] Add variances to RPITITs --- .../rustc_hir_analysis/src/variance/mod.rs | 49 +++++++++++++-- compiler/rustc_metadata/src/rmeta/encoder.rs | 5 +- compiler/rustc_middle/src/ty/context.rs | 4 ++ compiler/rustc_type_ir/src/interner.rs | 2 + compiler/rustc_type_ir/src/relate.rs | 10 ++++ tests/ui/impl-trait/in-trait/variance.rs | 23 ++++---- tests/ui/impl-trait/in-trait/variance.stderr | 34 +++++++---- .../forgot-to-capture-type.rs | 3 +- .../forgot-to-capture-type.stderr | 17 +----- .../precise-capturing/redundant.normal.stderr | 20 ------- .../precise-capturing/redundant.rpitit.stderr | 24 -------- .../impl-trait/precise-capturing/redundant.rs | 15 +++-- .../precise-capturing/redundant.stderr | 36 +++++++++++ .../rpitit-captures-more-method-lifetimes.rs | 5 +- ...itit-captures-more-method-lifetimes.stderr | 23 ++------ .../rpitit-impl-captures-too-much.rs | 14 +++++ .../rpitit-impl-captures-too-much.stderr | 17 ++++++ .../ui/impl-trait/precise-capturing/rpitit.rs | 31 +++++++--- .../precise-capturing/rpitit.stderr | 59 ++++++++----------- .../precise-capturing/self-capture.rs | 5 +- .../precise-capturing/self-capture.stderr | 13 ---- 21 files changed, 241 insertions(+), 168 deletions(-) delete mode 100644 tests/ui/impl-trait/precise-capturing/redundant.normal.stderr delete mode 100644 tests/ui/impl-trait/precise-capturing/redundant.rpitit.stderr create mode 100644 tests/ui/impl-trait/precise-capturing/redundant.stderr create mode 100644 tests/ui/impl-trait/precise-capturing/rpitit-impl-captures-too-much.rs create mode 100644 tests/ui/impl-trait/precise-capturing/rpitit-impl-captures-too-much.stderr delete mode 100644 tests/ui/impl-trait/precise-capturing/self-capture.stderr diff --git a/compiler/rustc_hir_analysis/src/variance/mod.rs b/compiler/rustc_hir_analysis/src/variance/mod.rs index 12bb9a3f9e0f3..02cfb57b836f6 100644 --- a/compiler/rustc_hir_analysis/src/variance/mod.rs +++ b/compiler/rustc_hir_analysis/src/variance/mod.rs @@ -5,6 +5,7 @@ use itertools::Itertools; use rustc_arena::DroplessArena; +use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::query::Providers; @@ -63,8 +64,29 @@ fn variances_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Variance] { let crate_map = tcx.crate_variances(()); return crate_map.variances.get(&item_def_id.to_def_id()).copied().unwrap_or(&[]); } + DefKind::AssocTy => match tcx.opt_rpitit_info(item_def_id.to_def_id()) { + Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => { + return variance_of_opaque( + tcx, + opaque_def_id.expect_local(), + ForceCaptureTraitArgs::Yes, + ); + } + None | Some(ty::ImplTraitInTraitData::Impl { .. }) => {} + }, DefKind::OpaqueTy => { - return variance_of_opaque(tcx, item_def_id); + let force_capture_trait_args = if let hir::OpaqueTyOrigin::FnReturn { + parent: _, + in_trait_or_impl: Some(hir::RpitContext::Trait), + } = + tcx.hir_node_by_def_id(item_def_id).expect_opaque_ty().origin + { + ForceCaptureTraitArgs::Yes + } else { + ForceCaptureTraitArgs::No + }; + + return variance_of_opaque(tcx, item_def_id, force_capture_trait_args); } _ => {} } @@ -73,8 +95,18 @@ fn variances_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Variance] { span_bug!(tcx.def_span(item_def_id), "asked to compute variance for wrong kind of item"); } +#[derive(Debug, Copy, Clone)] +enum ForceCaptureTraitArgs { + Yes, + No, +} + #[instrument(level = "trace", skip(tcx), ret)] -fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Variance] { +fn variance_of_opaque( + tcx: TyCtxt<'_>, + item_def_id: LocalDefId, + force_capture_trait_args: ForceCaptureTraitArgs, +) -> &[ty::Variance] { let generics = tcx.generics_of(item_def_id); // Opaque types may only use regions that are bound. So for @@ -115,9 +147,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc #[instrument(level = "trace", skip(self), ret)] fn visit_ty(&mut self, t: Ty<'tcx>) { match t.kind() { - ty::Alias(_, ty::AliasTy { def_id, args, .. }) - if matches!(self.tcx.def_kind(*def_id), DefKind::OpaqueTy) => - { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { self.visit_opaque(*def_id, args); } _ => t.super_visit_with(self), @@ -135,6 +165,15 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc let mut generics = generics; while let Some(def_id) = generics.parent { generics = tcx.generics_of(def_id); + + // Don't mark trait params generic if we're in an RPITIT. + if matches!(force_capture_trait_args, ForceCaptureTraitArgs::Yes) + && generics.parent.is_none() + { + debug_assert_eq!(tcx.def_kind(def_id), DefKind::Trait); + break; + } + for param in &generics.own_params { match param.kind { ty::GenericParamDefKind::Lifetime => { diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 610c682d3a461..afe03531861c9 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1100,9 +1100,12 @@ fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: Def | DefKind::Fn | DefKind::Ctor(..) | DefKind::AssocFn => true, + DefKind::AssocTy => { + // Only encode variances for RPITITs (for traits) + matches!(tcx.opt_rpitit_info(def_id), Some(ty::ImplTraitInTraitData::Trait { .. })) + } DefKind::Mod | DefKind::Field - | DefKind::AssocTy | DefKind::AssocConst | DefKind::TyParam | DefKind::ConstParam diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 90265f67bc1f6..590e1d336f340 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -539,6 +539,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> { self.trait_def(trait_def_id).implement_via_object } + fn is_impl_trait_in_trait(self, def_id: DefId) -> bool { + self.is_impl_trait_in_trait(def_id) + } + fn delay_bug(self, msg: impl ToString) -> ErrorGuaranteed { self.dcx().span_delayed_bug(DUMMY_SP, msg.to_string()) } diff --git a/compiler/rustc_type_ir/src/interner.rs b/compiler/rustc_type_ir/src/interner.rs index a72e7b482a6fd..f06017d7e5c35 100644 --- a/compiler/rustc_type_ir/src/interner.rs +++ b/compiler/rustc_type_ir/src/interner.rs @@ -261,6 +261,8 @@ pub trait Interner: fn trait_may_be_implemented_via_object(self, trait_def_id: Self::DefId) -> bool; + fn is_impl_trait_in_trait(self, def_id: Self::DefId) -> bool; + fn delay_bug(self, msg: impl ToString) -> Self::ErrorGuaranteed; fn is_general_coroutine(self, coroutine_def_id: Self::DefId) -> bool; diff --git a/compiler/rustc_type_ir/src/relate.rs b/compiler/rustc_type_ir/src/relate.rs index 1302906adab1f..e1f3e493e36e3 100644 --- a/compiler/rustc_type_ir/src/relate.rs +++ b/compiler/rustc_type_ir/src/relate.rs @@ -254,6 +254,16 @@ impl Relate for ty::AliasTy { b.args, false, // do not fetch `type_of(a_def_id)`, as it will cause a cycle )?, + ty::Projection if relation.cx().is_impl_trait_in_trait(a.def_id) => { + relate_args_with_variances( + relation, + a.def_id, + relation.cx().variances_of(a.def_id), + a.args, + b.args, + false, // do not fetch `type_of(a_def_id)`, as it will cause a cycle + )? + } ty::Projection | ty::Weak | ty::Inherent => { relate_args_invariantly(relation, a.args, b.args)? } diff --git a/tests/ui/impl-trait/in-trait/variance.rs b/tests/ui/impl-trait/in-trait/variance.rs index 0ac44bf7546c2..19905c608e3b5 100644 --- a/tests/ui/impl-trait/in-trait/variance.rs +++ b/tests/ui/impl-trait/in-trait/variance.rs @@ -1,22 +1,25 @@ -#![feature(rustc_attrs)] +#![feature(rustc_attrs, precise_capturing_in_traits)] #![allow(internal_features)] #![rustc_variance_of_opaques] -trait Captures<'a> {} -impl Captures<'_> for T {} - trait Foo<'i> { fn implicit_capture_early<'a: 'a>() -> impl Sized {} - //~^ [Self: o, 'i: *, 'a: *, 'a: o, 'i: o] + //~^ [Self: o, 'i: o, 'a: *, 'a: o, 'i: o] + + fn explicit_capture_early<'a: 'a>() -> impl Sized + use<'i, 'a, Self> {} + //~^ [Self: o, 'i: o, 'a: *, 'i: o, 'a: o] - fn explicit_capture_early<'a: 'a>() -> impl Sized + Captures<'a> {} - //~^ [Self: o, 'i: *, 'a: *, 'a: o, 'i: o] + fn not_captured_early<'a: 'a>() -> impl Sized + use<'i, Self> {} + //~^ [Self: o, 'i: o, 'a: *, 'i: o] fn implicit_capture_late<'a>(_: &'a ()) -> impl Sized {} - //~^ [Self: o, 'i: *, 'a: o, 'i: o] + //~^ [Self: o, 'i: o, 'a: o, 'i: o] + + fn explicit_capture_late<'a>(_: &'a ()) -> impl Sized + use<'i, 'a, Self> {} + //~^ [Self: o, 'i: o, 'i: o, 'a: o] - fn explicit_capture_late<'a>(_: &'a ()) -> impl Sized + Captures<'a> {} - //~^ [Self: o, 'i: *, 'a: o, 'i: o] + fn not_cpatured_late<'a>(_: &'a ()) -> impl Sized + use<'i, Self> {} + //~^ [Self: o, 'i: o, 'i: o] } fn main() {} diff --git a/tests/ui/impl-trait/in-trait/variance.stderr b/tests/ui/impl-trait/in-trait/variance.stderr index 54e0afbaa950d..f65174e1c358c 100644 --- a/tests/ui/impl-trait/in-trait/variance.stderr +++ b/tests/ui/impl-trait/in-trait/variance.stderr @@ -1,26 +1,38 @@ -error: [Self: o, 'i: *, 'a: *, 'a: o, 'i: o] - --> $DIR/variance.rs:9:44 +error: [Self: o, 'i: o, 'a: *, 'a: o, 'i: o] + --> $DIR/variance.rs:6:44 | LL | fn implicit_capture_early<'a: 'a>() -> impl Sized {} | ^^^^^^^^^^ -error: [Self: o, 'i: *, 'a: *, 'a: o, 'i: o] - --> $DIR/variance.rs:12:44 +error: [Self: o, 'i: o, 'a: *, 'i: o, 'a: o] + --> $DIR/variance.rs:9:44 + | +LL | fn explicit_capture_early<'a: 'a>() -> impl Sized + use<'i, 'a, Self> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: [Self: o, 'i: o, 'a: *, 'i: o] + --> $DIR/variance.rs:12:40 | -LL | fn explicit_capture_early<'a: 'a>() -> impl Sized + Captures<'a> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn not_captured_early<'a: 'a>() -> impl Sized + use<'i, Self> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: [Self: o, 'i: *, 'a: o, 'i: o] +error: [Self: o, 'i: o, 'a: o, 'i: o] --> $DIR/variance.rs:15:48 | LL | fn implicit_capture_late<'a>(_: &'a ()) -> impl Sized {} | ^^^^^^^^^^ -error: [Self: o, 'i: *, 'a: o, 'i: o] +error: [Self: o, 'i: o, 'i: o, 'a: o] --> $DIR/variance.rs:18:48 | -LL | fn explicit_capture_late<'a>(_: &'a ()) -> impl Sized + Captures<'a> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn explicit_capture_late<'a>(_: &'a ()) -> impl Sized + use<'i, 'a, Self> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: [Self: o, 'i: o, 'i: o] + --> $DIR/variance.rs:21:44 + | +LL | fn not_cpatured_late<'a>(_: &'a ()) -> impl Sized + use<'i, Self> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 4 previous errors +error: aborting due to 6 previous errors diff --git a/tests/ui/impl-trait/precise-capturing/forgot-to-capture-type.rs b/tests/ui/impl-trait/precise-capturing/forgot-to-capture-type.rs index 9d68819f657db..6c2477c9744ab 100644 --- a/tests/ui/impl-trait/precise-capturing/forgot-to-capture-type.rs +++ b/tests/ui/impl-trait/precise-capturing/forgot-to-capture-type.rs @@ -1,10 +1,11 @@ +#![feature(precise_capturing_in_traits)] + fn type_param() -> impl Sized + use<> {} //~^ ERROR `impl Trait` must mention all type parameters in scope trait Foo { fn bar() -> impl Sized + use<>; //~^ ERROR `impl Trait` must mention the `Self` type of the trait - //~| ERROR `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits } fn main() {} diff --git a/tests/ui/impl-trait/precise-capturing/forgot-to-capture-type.stderr b/tests/ui/impl-trait/precise-capturing/forgot-to-capture-type.stderr index 23d6a3bd11e82..93b44a0c18c27 100644 --- a/tests/ui/impl-trait/precise-capturing/forgot-to-capture-type.stderr +++ b/tests/ui/impl-trait/precise-capturing/forgot-to-capture-type.stderr @@ -1,16 +1,5 @@ -error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits - --> $DIR/forgot-to-capture-type.rs:5:30 - | -LL | fn bar() -> impl Sized + use<>; - | ^^^^^ - | - = note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope - = note: see issue #130044 for more information - = help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - error: `impl Trait` must mention all type parameters in scope in `use<...>` - --> $DIR/forgot-to-capture-type.rs:1:23 + --> $DIR/forgot-to-capture-type.rs:3:23 | LL | fn type_param() -> impl Sized + use<> {} | - ^^^^^^^^^^^^^^^^^^ @@ -20,7 +9,7 @@ LL | fn type_param() -> impl Sized + use<> {} = note: currently, all type parameters are required to be mentioned in the precise captures list error: `impl Trait` must mention the `Self` type of the trait in `use<...>` - --> $DIR/forgot-to-capture-type.rs:5:17 + --> $DIR/forgot-to-capture-type.rs:7:17 | LL | trait Foo { | --------- `Self` type parameter is implicitly captured by this `impl Trait` @@ -29,5 +18,5 @@ LL | fn bar() -> impl Sized + use<>; | = note: currently, all type parameters are required to be mentioned in the precise captures list -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors diff --git a/tests/ui/impl-trait/precise-capturing/redundant.normal.stderr b/tests/ui/impl-trait/precise-capturing/redundant.normal.stderr deleted file mode 100644 index d1bcbaa33ae2b..0000000000000 --- a/tests/ui/impl-trait/precise-capturing/redundant.normal.stderr +++ /dev/null @@ -1,20 +0,0 @@ -warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant - --> $DIR/redundant.rs:5:19 - | -LL | fn hello<'a>() -> impl Sized + use<'a> {} - | ^^^^^^^^^^^^^------- - | | - | help: remove the `use<...>` syntax - | - = note: `#[warn(impl_trait_redundant_captures)]` on by default - -warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant - --> $DIR/redundant.rs:10:27 - | -LL | fn inherent(&self) -> impl Sized + use<'_> {} - | ^^^^^^^^^^^^^------- - | | - | help: remove the `use<...>` syntax - -warning: 2 warnings emitted - diff --git a/tests/ui/impl-trait/precise-capturing/redundant.rpitit.stderr b/tests/ui/impl-trait/precise-capturing/redundant.rpitit.stderr deleted file mode 100644 index 27f8ff92d3e65..0000000000000 --- a/tests/ui/impl-trait/precise-capturing/redundant.rpitit.stderr +++ /dev/null @@ -1,24 +0,0 @@ -error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits - --> $DIR/redundant.rs:16:35 - | -LL | fn in_trait() -> impl Sized + use<'a, Self>; - | ^^^^^^^^^^^^^ - | - = note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope - = note: see issue #130044 for more information - = help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits - --> $DIR/redundant.rs:21:35 - | -LL | fn in_trait() -> impl Sized + use<'a> {} - | ^^^^^^^ - | - = note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope - = note: see issue #130044 for more information - = help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error: aborting due to 2 previous errors - diff --git a/tests/ui/impl-trait/precise-capturing/redundant.rs b/tests/ui/impl-trait/precise-capturing/redundant.rs index 4a08ffb61be03..e19d935f5b0d4 100644 --- a/tests/ui/impl-trait/precise-capturing/redundant.rs +++ b/tests/ui/impl-trait/precise-capturing/redundant.rs @@ -1,25 +1,24 @@ //@ compile-flags: -Zunstable-options --edition=2024 -//@ revisions: normal rpitit -//@[normal] check-pass +//@ check-pass + +#![feature(precise_capturing_in_traits)] fn hello<'a>() -> impl Sized + use<'a> {} -//[normal]~^ WARN all possible in-scope parameters are already captured +//~^ WARN all possible in-scope parameters are already captured struct Inherent; impl Inherent { fn inherent(&self) -> impl Sized + use<'_> {} - //[normal]~^ WARN all possible in-scope parameters are already captured + //~^ WARN all possible in-scope parameters are already captured } -#[cfg(rpitit)] trait Test<'a> { fn in_trait() -> impl Sized + use<'a, Self>; - //[rpitit]~^ ERROR `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits + //~^ WARN all possible in-scope parameters are already captured } -#[cfg(rpitit)] impl<'a> Test<'a> for () { fn in_trait() -> impl Sized + use<'a> {} - //[rpitit]~^ ERROR `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits + //~^ WARN all possible in-scope parameters are already captured } fn main() {} diff --git a/tests/ui/impl-trait/precise-capturing/redundant.stderr b/tests/ui/impl-trait/precise-capturing/redundant.stderr new file mode 100644 index 0000000000000..274d9d2375f7d --- /dev/null +++ b/tests/ui/impl-trait/precise-capturing/redundant.stderr @@ -0,0 +1,36 @@ +warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant + --> $DIR/redundant.rs:6:19 + | +LL | fn hello<'a>() -> impl Sized + use<'a> {} + | ^^^^^^^^^^^^^------- + | | + | help: remove the `use<...>` syntax + | + = note: `#[warn(impl_trait_redundant_captures)]` on by default + +warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant + --> $DIR/redundant.rs:11:27 + | +LL | fn inherent(&self) -> impl Sized + use<'_> {} + | ^^^^^^^^^^^^^------- + | | + | help: remove the `use<...>` syntax + +warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant + --> $DIR/redundant.rs:16:22 + | +LL | fn in_trait() -> impl Sized + use<'a, Self>; + | ^^^^^^^^^^^^^------------- + | | + | help: remove the `use<...>` syntax + +warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant + --> $DIR/redundant.rs:20:22 + | +LL | fn in_trait() -> impl Sized + use<'a> {} + | ^^^^^^^^^^^^^------- + | | + | help: remove the `use<...>` syntax + +warning: 4 warnings emitted + diff --git a/tests/ui/impl-trait/precise-capturing/rpitit-captures-more-method-lifetimes.rs b/tests/ui/impl-trait/precise-capturing/rpitit-captures-more-method-lifetimes.rs index 062351afecbdf..b39c1408c0509 100644 --- a/tests/ui/impl-trait/precise-capturing/rpitit-captures-more-method-lifetimes.rs +++ b/tests/ui/impl-trait/precise-capturing/rpitit-captures-more-method-lifetimes.rs @@ -2,13 +2,14 @@ // trait definition, which is not allowed. Due to the default lifetime capture // rules of RPITITs, this is only doable if we use precise capturing. +#![feature(precise_capturing_in_traits)] + pub trait Foo { fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use; - //~^ ERROR `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits } impl Foo for () { - fn bar<'im: 'im>(&'im mut self) -> impl Sized + 'im {} + fn bar<'im: 'im>(&'im mut self) -> impl Sized + use<'im> {} //~^ ERROR return type captures more lifetimes than trait definition } diff --git a/tests/ui/impl-trait/precise-capturing/rpitit-captures-more-method-lifetimes.stderr b/tests/ui/impl-trait/precise-capturing/rpitit-captures-more-method-lifetimes.stderr index ffd9646a4038b..45f755d3cc1be 100644 --- a/tests/ui/impl-trait/precise-capturing/rpitit-captures-more-method-lifetimes.stderr +++ b/tests/ui/impl-trait/precise-capturing/rpitit-captures-more-method-lifetimes.stderr @@ -1,28 +1,17 @@ -error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits - --> $DIR/rpitit-captures-more-method-lifetimes.rs:6:53 - | -LL | fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use; - | ^^^^^^^^^ - | - = note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope - = note: see issue #130044 for more information - = help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - error: return type captures more lifetimes than trait definition - --> $DIR/rpitit-captures-more-method-lifetimes.rs:11:40 + --> $DIR/rpitit-captures-more-method-lifetimes.rs:12:40 | -LL | fn bar<'im: 'im>(&'im mut self) -> impl Sized + 'im {} - | --- ^^^^^^^^^^^^^^^^ +LL | fn bar<'im: 'im>(&'im mut self) -> impl Sized + use<'im> {} + | --- ^^^^^^^^^^^^^^^^^^^^^ | | | this lifetime was captured | note: hidden type must only reference lifetimes captured by this impl trait - --> $DIR/rpitit-captures-more-method-lifetimes.rs:6:40 + --> $DIR/rpitit-captures-more-method-lifetimes.rs:8:40 | LL | fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use; | ^^^^^^^^^^^^^^^^^^^^^^ - = note: hidden type inferred to be `impl Sized + 'im` + = note: hidden type inferred to be `impl Sized` -error: aborting due to 2 previous errors +error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/precise-capturing/rpitit-impl-captures-too-much.rs b/tests/ui/impl-trait/precise-capturing/rpitit-impl-captures-too-much.rs new file mode 100644 index 0000000000000..b16b0522d6e11 --- /dev/null +++ b/tests/ui/impl-trait/precise-capturing/rpitit-impl-captures-too-much.rs @@ -0,0 +1,14 @@ +#![feature(precise_capturing_in_traits)] + +struct Invariant<'a>(&'a mut &'a mut ()); + +trait Trait { + fn hello(self_: Invariant<'_>) -> impl Sized + use; +} + +impl Trait for () { + fn hello(self_: Invariant<'_>) -> impl Sized + use<'_> {} + //~^ ERROR return type captures more lifetimes than trait definition +} + +fn main() {} diff --git a/tests/ui/impl-trait/precise-capturing/rpitit-impl-captures-too-much.stderr b/tests/ui/impl-trait/precise-capturing/rpitit-impl-captures-too-much.stderr new file mode 100644 index 0000000000000..e1856b929106e --- /dev/null +++ b/tests/ui/impl-trait/precise-capturing/rpitit-impl-captures-too-much.stderr @@ -0,0 +1,17 @@ +error: return type captures more lifetimes than trait definition + --> $DIR/rpitit-impl-captures-too-much.rs:10:39 + | +LL | fn hello(self_: Invariant<'_>) -> impl Sized + use<'_> {} + | -- ^^^^^^^^^^^^^^^^^^^^ + | | + | this lifetime was captured + | +note: hidden type must only reference lifetimes captured by this impl trait + --> $DIR/rpitit-impl-captures-too-much.rs:6:39 + | +LL | fn hello(self_: Invariant<'_>) -> impl Sized + use; + | ^^^^^^^^^^^^^^^^^^^^^^ + = note: hidden type inferred to be `impl Sized` + +error: aborting due to 1 previous error + diff --git a/tests/ui/impl-trait/precise-capturing/rpitit.rs b/tests/ui/impl-trait/precise-capturing/rpitit.rs index feeeb1461e827..3f887e8e47f1c 100644 --- a/tests/ui/impl-trait/precise-capturing/rpitit.rs +++ b/tests/ui/impl-trait/precise-capturing/rpitit.rs @@ -1,19 +1,34 @@ -//@ known-bug: unknown - // RPITITs don't have variances in their GATs, so they always relate invariantly // and act as if they capture all their args. // To fix this soundly, we need to make sure that all the trait header args // remain captured, since they affect trait selection. -trait Foo<'a> { - fn hello() -> impl PartialEq + use; +#![feature(precise_capturing_in_traits)] + +fn eq_types(_: T, _: T) {} + +trait TraitLt<'a: 'a> { + fn hello() -> impl Sized + use; + //~^ ERROR `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list +} +fn trait_lt<'a, 'b, T: for<'r> TraitLt<'r>> () { + eq_types( + //~^ ERROR lifetime may not live long enough + //~| ERROR lifetime may not live long enough + >::hello(), + >::hello(), + ); } -fn test<'a, 'b, T: for<'r> Foo<'r>>() { - PartialEq::eq( - &>::hello(), - &>::hello(), +trait MethodLt { + fn hello<'a: 'a>() -> impl Sized + use; +} +fn method_lt<'a, 'b, T: MethodLt> () { + eq_types( + T::hello::<'a>(), + T::hello::<'b>(), ); + // Good! } fn main() {} diff --git a/tests/ui/impl-trait/precise-capturing/rpitit.stderr b/tests/ui/impl-trait/precise-capturing/rpitit.stderr index c162875f327cc..8c219bb04a278 100644 --- a/tests/ui/impl-trait/precise-capturing/rpitit.stderr +++ b/tests/ui/impl-trait/precise-capturing/rpitit.stderr @@ -1,47 +1,40 @@ -error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits - --> $DIR/rpitit.rs:9:36 - | -LL | fn hello() -> impl PartialEq + use; - | ^^^^^^^^^ - | - = note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope - = note: see issue #130044 for more information - = help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - error: `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list - --> $DIR/rpitit.rs:9:19 + --> $DIR/rpitit.rs:11:19 | -LL | trait Foo<'a> { - | -- this lifetime parameter is captured -LL | fn hello() -> impl PartialEq + use; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime captured due to being mentioned in the bounds of the `impl Trait` +LL | trait TraitLt<'a: 'a> { + | -- this lifetime parameter is captured +LL | fn hello() -> impl Sized + use; + | ^^^^^^^^^^^^^^^^^^^^^^ lifetime captured due to being mentioned in the bounds of the `impl Trait` error: lifetime may not live long enough - --> $DIR/rpitit.rs:13:5 + --> $DIR/rpitit.rs:15:5 | -LL | fn test<'a, 'b, T: for<'r> Foo<'r>>() { - | -- -- lifetime `'b` defined here - | | - | lifetime `'a` defined here -LL | / PartialEq::eq( -LL | | &>::hello(), -LL | | &>::hello(), +LL | fn trait_lt<'a, 'b, T: for<'r> TraitLt<'r>> () { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | / eq_types( +LL | | +LL | | +LL | | >::hello(), +LL | | >::hello(), LL | | ); | |_____^ argument requires that `'a` must outlive `'b` | = help: consider adding the following bound: `'a: 'b` error: lifetime may not live long enough - --> $DIR/rpitit.rs:13:5 + --> $DIR/rpitit.rs:15:5 | -LL | fn test<'a, 'b, T: for<'r> Foo<'r>>() { - | -- -- lifetime `'b` defined here - | | - | lifetime `'a` defined here -LL | / PartialEq::eq( -LL | | &>::hello(), -LL | | &>::hello(), +LL | fn trait_lt<'a, 'b, T: for<'r> TraitLt<'r>> () { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | / eq_types( +LL | | +LL | | +LL | | >::hello(), +LL | | >::hello(), LL | | ); | |_____^ argument requires that `'b` must outlive `'a` | @@ -49,5 +42,5 @@ LL | | ); help: `'a` and `'b` must be the same: replace one with the other -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors diff --git a/tests/ui/impl-trait/precise-capturing/self-capture.rs b/tests/ui/impl-trait/precise-capturing/self-capture.rs index a61a7f06edc1d..15985da50b55e 100644 --- a/tests/ui/impl-trait/precise-capturing/self-capture.rs +++ b/tests/ui/impl-trait/precise-capturing/self-capture.rs @@ -1,6 +1,9 @@ +//@ check-pass + +#![feature(precise_capturing_in_traits)] + trait Foo { fn bar<'a>() -> impl Sized + use; - //~^ ERROR `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits } fn main() {} diff --git a/tests/ui/impl-trait/precise-capturing/self-capture.stderr b/tests/ui/impl-trait/precise-capturing/self-capture.stderr deleted file mode 100644 index 45ebc429d88a7..0000000000000 --- a/tests/ui/impl-trait/precise-capturing/self-capture.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits - --> $DIR/self-capture.rs:2:34 - | -LL | fn bar<'a>() -> impl Sized + use; - | ^^^^^^^^^ - | - = note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope - = note: see issue #130044 for more information - = help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error: aborting due to 1 previous error - From 36076ecdc726c4e1104e70df2d142f39501a4f48 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 29 Sep 2024 13:49:32 -0400 Subject: [PATCH 14/16] Clarify implicit captures for RPITIT --- compiler/rustc_hir_analysis/messages.ftl | 3 +++ .../rustc_hir_analysis/src/check/check.rs | 25 ++++++++++++------- .../src/errors/precise_captures.rs | 9 +++++++ .../precise-capturing/rpitit.stderr | 4 +-- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl index c73826c489f96..a80dc87c62242 100644 --- a/compiler/rustc_hir_analysis/messages.ftl +++ b/compiler/rustc_hir_analysis/messages.ftl @@ -259,6 +259,9 @@ hir_analysis_late_bound_lifetime_in_apit = `impl Trait` can only mention lifetim hir_analysis_late_bound_type_in_apit = `impl Trait` can only mention type parameters from an fn or impl .label = type parameter declared here +hir_analysis_lifetime_implicitly_captured = `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list + .param_label = all lifetime parameters originating from a trait are captured implicitly + hir_analysis_lifetime_must_be_first = lifetime parameter `{$name}` must be listed before non-lifetime parameters .label = move the lifetime before this parameter diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index eb62ff86c7179..d0063b449f894 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -589,15 +589,22 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe param_span: tcx.def_span(def_id), }); } else { - // If the `use_span` is actually just the param itself, then we must - // have not duplicated the lifetime but captured the original. - // The "effective" `use_span` will be the span of the opaque itself, - // and the param span will be the def span of the param. - tcx.dcx().emit_err(errors::LifetimeNotCaptured { - opaque_span, - use_span: opaque_span, - param_span: use_span, - }); + if tcx.def_kind(tcx.parent(param.def_id)) == DefKind::Trait { + tcx.dcx().emit_err(errors::LifetimeImplicitlyCaptured { + opaque_span, + param_span: tcx.def_span(param.def_id), + }); + } else { + // If the `use_span` is actually just the param itself, then we must + // have not duplicated the lifetime but captured the original. + // The "effective" `use_span` will be the span of the opaque itself, + // and the param span will be the def span of the param. + tcx.dcx().emit_err(errors::LifetimeNotCaptured { + opaque_span, + use_span: opaque_span, + param_span: use_span, + }); + } } continue; } diff --git a/compiler/rustc_hir_analysis/src/errors/precise_captures.rs b/compiler/rustc_hir_analysis/src/errors/precise_captures.rs index b6cffb90805b3..8a83866b7fa46 100644 --- a/compiler/rustc_hir_analysis/src/errors/precise_captures.rs +++ b/compiler/rustc_hir_analysis/src/errors/precise_captures.rs @@ -34,6 +34,15 @@ pub(crate) struct LifetimeNotCaptured { pub opaque_span: Span, } +#[derive(Diagnostic)] +#[diag(hir_analysis_lifetime_implicitly_captured)] +pub(crate) struct LifetimeImplicitlyCaptured { + #[primary_span] + pub opaque_span: Span, + #[label(hir_analysis_param_label)] + pub param_span: Span, +} + #[derive(Diagnostic)] #[diag(hir_analysis_bad_precise_capture)] pub(crate) struct BadPreciseCapture { diff --git a/tests/ui/impl-trait/precise-capturing/rpitit.stderr b/tests/ui/impl-trait/precise-capturing/rpitit.stderr index 8c219bb04a278..498eae54a1c68 100644 --- a/tests/ui/impl-trait/precise-capturing/rpitit.stderr +++ b/tests/ui/impl-trait/precise-capturing/rpitit.stderr @@ -2,9 +2,9 @@ error: `impl Trait` captures lifetime parameter, but it is not mentioned in `use --> $DIR/rpitit.rs:11:19 | LL | trait TraitLt<'a: 'a> { - | -- this lifetime parameter is captured + | -- all lifetime parameters originating from a trait are captured implicitly LL | fn hello() -> impl Sized + use; - | ^^^^^^^^^^^^^^^^^^^^^^ lifetime captured due to being mentioned in the bounds of the `impl Trait` + | ^^^^^^^^^^^^^^^^^^^^^^ error: lifetime may not live long enough --> $DIR/rpitit.rs:15:5 From 322c4bdac595e7689dcf08b847d0bd4d82a4bad9 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 29 Sep 2024 13:49:53 -0400 Subject: [PATCH 15/16] Don't fire refinement lint if there are errors --- .../rustc_hir_analysis/src/check/compare_impl_item/refine.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs index 80334c6efe7d6..2d6b9813271e2 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs @@ -64,6 +64,10 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>( return; }; + if hidden_tys.items().any(|(_, &ty)| ty.skip_binder().references_error()) { + return; + } + let mut collector = ImplTraitInTraitCollector { tcx, types: FxIndexSet::default() }; trait_m_sig.visit_with(&mut collector); From 82433eeedf3d009262f1dc5d8f73d6c13acad7fc Mon Sep 17 00:00:00 2001 From: Julia Ryan Date: Thu, 10 Oct 2024 12:35:26 -0700 Subject: [PATCH 16/16] Update .mailmap --- .mailmap | 1 + 1 file changed, 1 insertion(+) diff --git a/.mailmap b/.mailmap index 0f58762e0233c..dc5bfe6d5fc76 100644 --- a/.mailmap +++ b/.mailmap @@ -312,6 +312,7 @@ Josh Driver Josh Holmer Josh Stone Josh Stone +Julia Ryan Julian Knodt jumbatm <30644300+jumbatm@users.noreply.github.com> Junyoung Cho