Auto merge of #130946 - matthiaskrgr:rollup-ia4mf0y, r=matthiaskrgr

Rollup of 6 pull requests

Successful merges:

 - #130718 (Cleanup some known-bug issues)
 - #130730 (Reorganize Test Headers)
 - #130826 (Compiler: Rename "object safe" to "dyn compatible")
 - #130915 (fix typo in triagebot.toml)
 - #130926 (Update cc to 1.1.22 in library/)
 - #130932 (etc: Add sample rust-analyzer configs for eglot & helix)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2024-09-27 21:23:29 +00:00
commit 83e4e18896
211 changed files with 747 additions and 567 deletions

1
.gitignore vendored
View File

@ -25,6 +25,7 @@ Session.vim
.favorites.json
.settings/
.vs/
.dir-locals.el
## Tool
.valgrindrc

View File

@ -598,7 +598,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
// codegen'd / interpreted as virtual calls through the vtable.
ty::InstanceKind::Virtual(def_id, idx) => {
let mut args = args.to_vec();
// We have to implement all "object safe receivers". So we have to go search for a
// We have to implement all "dyn-compatible receivers". So we have to go search for a
// pointer or `dyn Trait` type, but it could be wrapped in newtypes. So recursively
// unwrap those newtypes until we are there.
// An `InPlace` does nothing here, we keep the original receiver intact. We can't

View File

@ -5,9 +5,9 @@ trait, written in type positions) but this was a bit too confusing, so we now
write `dyn Trait`.
Some traits are not allowed to be used as trait object types. The traits that
are allowed to be used as trait object types are called "object-safe" traits.
Attempting to use a trait object type for a trait that is not object-safe will
trigger error E0038.
are allowed to be used as trait object types are called "dyn-compatible"[^1]
traits. Attempting to use a trait object type for a trait that is not
dyn-compatible will trigger error E0038.
Two general aspects of trait object types give rise to the restrictions:
@ -25,13 +25,16 @@ Two general aspects of trait object types give rise to the restrictions:
objects with the same trait object type may point to vtables from different
implementations.
The specific conditions that violate object-safety follow, most of which relate
to missing size information and vtable polymorphism arising from these aspects.
The specific conditions that violate dyn-compatibility follow, most of which
relate to missing size information and vtable polymorphism arising from these
aspects.
[^1]: Formerly known as "object-safe".
### The trait requires `Self: Sized`
Traits that are declared as `Trait: Sized` or which otherwise inherit a
constraint of `Self:Sized` are not object-safe.
constraint of `Self:Sized` are not dyn-compatible.
The reasoning behind this is somewhat subtle. It derives from the fact that Rust
requires (and defines) that every trait object type `dyn Trait` automatically
@ -58,7 +61,7 @@ implement a sized trait like `Trait:Sized`. So, rather than allow an exception
to the rule that `dyn Trait` always implements `Trait`, Rust chooses to prohibit
such a `dyn Trait` from existing at all.
Only unsized traits are considered object-safe.
Only unsized traits are considered dyn-compatible.
Generally, `Self: Sized` is used to indicate that the trait should not be used
as a trait object. If the trait comes from your own crate, consider removing
@ -103,8 +106,8 @@ fn call_foo(x: Box<dyn Trait>) {
}
```
If only some methods aren't object-safe, you can add a `where Self: Sized` bound
on them to mark them as explicitly unavailable to trait objects. The
If only some methods aren't dyn-compatible, you can add a `where Self: Sized`
bound on them to mark them as explicitly unavailable to trait objects. The
functionality will still be available to all other implementers, including
`Box<dyn Trait>` which is itself sized (assuming you `impl Trait for Box<dyn
Trait>`).
@ -117,7 +120,7 @@ trait Trait {
```
Now, `foo()` can no longer be called on a trait object, but you will now be
allowed to make a trait object, and that will be able to call any object-safe
allowed to make a trait object, and that will be able to call any dyn-compatible
methods. With such a bound, one can still call `foo()` on types implementing
that trait that aren't behind trait objects.
@ -306,7 +309,7 @@ Here, the supertrait might have methods as follows:
```
trait Super<A: ?Sized> {
fn get_a(&self) -> &A; // note that this is object safe!
fn get_a(&self) -> &A; // note that this is dyn-compatible!
}
```
@ -314,10 +317,10 @@ If the trait `Trait` was deriving from something like `Super<String>` or
`Super<T>` (where `Foo` itself is `Foo<T>`), this is okay, because given a type
`get_a()` will definitely return an object of that type.
However, if it derives from `Super<Self>`, even though `Super` is object safe,
the method `get_a()` would return an object of unknown type when called on the
function. `Self` type parameters let us make object safe traits no longer safe,
so they are forbidden when specifying supertraits.
However, if it derives from `Super<Self>`, even though `Super` is
dyn-compatible, the method `get_a()` would return an object of unknown type when
called on the function. `Self` type parameters let us make dyn-compatible traits
no longer compatible, so they are forbidden when specifying supertraits.
There's no easy fix for this. Generally, code will need to be refactored so that
you no longer need to derive from `Super<Self>`.

View File

@ -623,7 +623,7 @@ E0800: 0800,
// E0314, // closure outlives stack frame
// E0315, // cannot invoke closure outside of its lifetime
// E0319, // trait impls for defaulted traits allowed just for structs/enums
// E0372, // coherence not object safe
// E0372, // coherence not dyn-compatible
// E0385, // {} in an aliasable location
// E0402, // cannot use an outer type parameter in this context
// E0406, // merged into 420

View File

@ -546,9 +546,12 @@ declare_features! (
(unstable, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554)),
/// Allows `for<T>` binders in where-clauses
(incomplete, non_lifetime_binders, "1.69.0", Some(108185)),
/// Allows making `dyn Trait` well-formed even if `Trait` is not object safe.
/// 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)),

View File

@ -558,7 +558,7 @@ hir_analysis_unrecognized_intrinsic_function =
.help = if you're adding an intrinsic, be sure to update `check_intrinsic_type`
hir_analysis_unused_associated_type_bounds =
unnecessary associated type bound for not object safe associated type
unnecessary associated type bound for dyn-incompatible associated type
.note = this associated type has a `where Self: Sized` bound, and while the associated type can be specified, it cannot be used because trait objects are never `Sized`
.suggestion = remove this bound

View File

@ -374,7 +374,7 @@ fn check_trait_item<'tcx>(
hir::TraitItemKind::Type(_bounds, Some(ty)) => (None, ty.span),
_ => (None, trait_item.span),
};
check_object_unsafe_self_trait_by_name(tcx, trait_item);
check_dyn_incompatible_self_trait_by_name(tcx, trait_item);
let mut res = check_associated_item(tcx, def_id, span, method_sig);
if matches!(trait_item.kind, hir::TraitItemKind::Fn(..)) {
@ -838,9 +838,10 @@ fn could_be_self(trait_def_id: LocalDefId, ty: &hir::Ty<'_>) -> bool {
}
}
/// Detect when an object unsafe trait is referring to itself in one of its associated items.
/// When this is done, suggest using `Self` instead.
fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) {
/// Detect when a dyn-incompatible trait is referring to itself in one of its associated items.
///
/// In such cases, suggest using `Self` instead.
fn check_dyn_incompatible_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) {
let (trait_name, trait_def_id) =
match tcx.hir_node_by_def_id(tcx.hir().get_parent_item(item.hir_id()).def_id) {
hir::Node::Item(item) => match item.kind {
@ -872,7 +873,7 @@ fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem
_ => {}
}
if !trait_should_be_self.is_empty() {
if tcx.is_object_safe(trait_def_id) {
if tcx.is_dyn_compatible(trait_def_id) {
return;
}
let sugg = trait_should_be_self.iter().map(|span| (*span, "Self".to_string())).collect();

View File

@ -183,8 +183,8 @@ fn check_object_overlap<'tcx>(
// check for overlap with the automatic `impl Trait for dyn Trait`
if let ty::Dynamic(data, ..) = trait_ref.self_ty().kind() {
// This is something like impl Trait1 for Trait2. Illegal
// if Trait1 is a supertrait of Trait2 or Trait2 is not object safe.
// This is something like `impl Trait1 for Trait2`. Illegal if
// Trait1 is a supertrait of Trait2 or Trait2 is not dyn-compatible.
let component_def_ids = data.iter().flat_map(|predicate| {
match predicate.skip_binder() {
@ -197,7 +197,8 @@ fn check_object_overlap<'tcx>(
});
for component_def_id in component_def_ids {
if !tcx.is_object_safe(component_def_id) {
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
// which will be reported by wfcheck. Ignore it here.
// This is tested by `coherence-impl-trait-for-trait-object-safe.rs`.

View File

@ -109,16 +109,16 @@ pub(crate) fn orphan_check_impl(
//
// auto trait AutoTrait {}
//
// trait ObjectSafeTrait {
// trait DynCompatibleTrait {
// fn f(&self) where Self: AutoTrait;
// }
//
// We can allow f to be called on `dyn ObjectSafeTrait + AutoTrait`.
// We can allow f to be called on `dyn DynCompatibleTrait + AutoTrait`.
//
// If we didn't deny `impl AutoTrait for dyn Trait`, it would be unsound
// for the ObjectSafeTrait shown above to be object safe because someone
// could take some type implementing ObjectSafeTrait but not AutoTrait,
// unsize it to `dyn ObjectSafeTrait`, and call .f() which has no
// for the `DynCompatibleTrait` shown above to be dyn-compatible because someone
// could take some type implementing `DynCompatibleTrait` but not `AutoTrait`,
// unsize it to `dyn DynCompatibleTrait`, and call `.f()` which has no
// concrete implementation (issue #50781).
enum LocalImpl {
Allow,

View File

@ -11,8 +11,8 @@ use rustc_middle::ty::{
self, DynKind, ExistentialPredicateStableCmpExt as _, Ty, TyCtxt, TypeFoldable, Upcast,
};
use rustc_span::{ErrorGuaranteed, Span};
use rustc_trait_selection::error_reporting::traits::report_object_safety_error;
use rustc_trait_selection::traits::{self, hir_ty_lowering_object_safety_violations};
use rustc_trait_selection::error_reporting::traits::report_dyn_incompatibility;
use rustc_trait_selection::traits::{self, hir_ty_lowering_dyn_compatibility_violations};
use smallvec::{SmallVec, smallvec};
use tracing::{debug, instrument};
@ -99,19 +99,19 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
return Ty::new_error(tcx, reported);
}
// Check that there are no gross object safety violations;
// Check that there are no gross dyn-compatibility violations;
// most importantly, that the supertraits don't contain `Self`,
// to avoid ICEs.
for item in &regular_traits {
let object_safety_violations =
hir_ty_lowering_object_safety_violations(tcx, item.trait_ref().def_id());
if !object_safety_violations.is_empty() {
let reported = report_object_safety_error(
let violations =
hir_ty_lowering_dyn_compatibility_violations(tcx, item.trait_ref().def_id());
if !violations.is_empty() {
let reported = report_dyn_incompatibility(
tcx,
span,
Some(hir_id),
item.trait_ref().def_id(),
&object_safety_violations,
&violations,
)
.emit();
return Ty::new_error(tcx, reported);
@ -275,8 +275,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
tcx.item_name(def_id),
)
.with_note(
rustc_middle::traits::ObjectSafetyViolation::SupertraitSelf(smallvec![])
.error_msg(),
rustc_middle::traits::DynCompatibilityViolation::SupertraitSelf(
smallvec![],
)
.error_msg(),
)
.emit();
}

View File

@ -19,9 +19,9 @@ use rustc_session::parse::feature_err;
use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::symbol::{Ident, kw, sym};
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol};
use rustc_trait_selection::error_reporting::traits::report_object_safety_error;
use rustc_trait_selection::error_reporting::traits::report_dyn_incompatibility;
use rustc_trait_selection::traits::{
FulfillmentError, TraitAliasExpansionInfo, object_safety_violations_for_assoc_item,
FulfillmentError, TraitAliasExpansionInfo, dyn_compatibility_violations_for_assoc_item,
};
use crate::errors::{
@ -739,7 +739,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// Account for things like `dyn Foo + 'a`, like in tests `issue-22434.rs` and
// `issue-22560.rs`.
let mut trait_bound_spans: Vec<Span> = vec![];
let mut object_safety_violations = false;
let mut dyn_compatibility_violations = false;
for (span, items) in &associated_types {
if !items.is_empty() {
trait_bound_spans.push(*span);
@ -750,14 +750,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
names_len += 1;
let violations =
object_safety_violations_for_assoc_item(tcx, trait_def_id, *assoc_item);
dyn_compatibility_violations_for_assoc_item(tcx, trait_def_id, *assoc_item);
if !violations.is_empty() {
report_object_safety_error(tcx, *span, None, trait_def_id, &violations).emit();
object_safety_violations = true;
report_dyn_incompatibility(tcx, *span, None, trait_def_id, &violations).emit();
dyn_compatibility_violations = true;
}
}
}
if object_safety_violations {
if dyn_compatibility_violations {
return;
}

View File

@ -77,7 +77,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
if self_ty.span.can_be_used_for_suggestions()
&& !self.maybe_suggest_impl_trait(self_ty, &mut diag)
{
// FIXME: Only emit this suggestion if the trait is object safe.
// FIXME: Only emit this suggestion if the trait is dyn-compatible.
diag.multipart_suggestion_verbose(label, sugg, Applicability::MachineApplicable);
}
// Check if the impl trait that we are considering is an impl of a local trait.
@ -89,7 +89,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
lint.primary_message("trait objects without an explicit `dyn` are deprecated");
if self_ty.span.can_be_used_for_suggestions() {
lint.multipart_suggestion_verbose(
"if this is an object-safe trait, use `dyn`",
"if this is a dyn-compatible trait, use `dyn`",
sugg,
Applicability::MachineApplicable,
);
@ -196,7 +196,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let mut is_downgradable = true;
// Check if trait object is safe for suggesting dynamic dispatch.
let is_object_safe = match self_ty.kind {
let is_dyn_compatible = match self_ty.kind {
hir::TyKind::TraitObject(objects, ..) => {
objects.iter().all(|(o, _)| match o.trait_ref.path.res {
Res::Def(DefKind::Trait, id) => {
@ -204,7 +204,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// For recursive traits, don't downgrade the error. (#119652)
is_downgradable = false;
}
tcx.is_object_safe(id)
tcx.is_dyn_compatible(id)
}
_ => false,
})
@ -221,8 +221,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
if let hir::FnRetTy::Return(ty) = sig.decl.output
&& ty.peel_refs().hir_id == self_ty.hir_id
{
let pre = if !is_object_safe {
format!("`{trait_name}` is not object safe, ")
let pre = if !is_dyn_compatible {
format!("`{trait_name}` is dyn-incompatible, ")
} else {
String::new()
};
@ -234,7 +234,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
diag.multipart_suggestion_verbose(msg, impl_sugg, Applicability::MachineApplicable);
// Suggest `Box<dyn Trait>` for return type
if is_object_safe {
if is_dyn_compatible {
// If the return type is `&Trait`, we don't want
// the ampersand to be displayed in the `Box<dyn Trait>`
// suggestion.
@ -253,7 +253,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
Applicability::MachineApplicable,
);
} else if is_downgradable {
// We'll emit the object safety error already, with a structured suggestion.
// We'll emit the dyn-compatibility error already, with a structured suggestion.
diag.downgrade_to_delayed_bug();
}
return true;
@ -276,10 +276,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
impl_sugg,
Applicability::MachineApplicable,
);
if !is_object_safe {
diag.note(format!("`{trait_name}` it is not object safe, so it can't be `dyn`"));
if !is_dyn_compatible {
diag.note(format!("`{trait_name}` it is dyn-incompatible, so it can't be `dyn`"));
if is_downgradable {
// We'll emit the object safety error already, with a structured suggestion.
// We'll emit the dyn-compatibility error already, with a structured suggestion.
diag.downgrade_to_delayed_bug();
}
} else {

View File

@ -15,10 +15,10 @@
mod bounds;
mod cmse;
mod dyn_compatibility;
pub mod errors;
pub mod generics;
mod lint;
mod object_safety;
use std::slice;

View File

@ -655,7 +655,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
return Err(TypeError::Mismatch);
}
// Object safety violations or miscellaneous.
// Dyn-compatibility violations or miscellaneous.
Err(err) => {
self.err_ctxt().report_selection_error(obligation.clone(), &obligation, &err);
// Treat this like an obligation and follow through

View File

@ -757,7 +757,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// give us a `QPath::TypeRelative` with a trait object as
// `qself`. In that case, we want to avoid registering a WF obligation
// for `dyn MyTrait`, since we don't actually need the trait
// to be object-safe.
// to be dyn-compatible.
// We manually call `register_wf_obligation` in the success path
// below.
let ty = self.lowerer().lower_ty(qself);

View File

@ -50,7 +50,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
| ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(..))
| ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(..))
| ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(..))
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::DynCompatible(..)
| ty::PredicateKind::NormalizesTo(..)
| ty::PredicateKind::AliasRelate(..)
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))

View File

@ -292,7 +292,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
// distinct types (e.g., if `Self` appeared as an
// argument type), but those cases have already
// been ruled out when we deemed the trait to be
// "object safe".
// "dyn-compatible".
let original_poly_trait_ref = principal.with_self_ty(this.tcx, object_ty);
let upcast_poly_trait_ref = this.upcast(original_poly_trait_ref, trait_def_id);
let upcast_trait_ref =

View File

@ -779,8 +779,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
});
// It is illegal to invoke a method on a trait instance that refers to
// the `Self` type. An [`ObjectSafetyViolation::SupertraitSelf`] error
// will be reported by `object_safety.rs` if the method refers to the
// the `Self` type. An [`DynCompatibilityViolation::SupertraitSelf`] error
// will be reported by `dyn_compatibility.rs` if the method refers to the
// `Self` type anywhere other than the receiver. Here, we use a
// instantiation that replaces `Self` with the object type itself. Hence,
// a `&self` method will wind up with an argument type like `&dyn Trait`.

View File

@ -912,7 +912,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
let traits = tcx.traits(LOCAL_CRATE);
for &tr in traits {
if !tcx.is_object_safe(tr) {
if !tcx.is_dyn_compatible(tr) {
continue;
}

View File

@ -514,7 +514,7 @@ lint_mixed_script_confusables =
.includes_note = the usage includes {$includes}
.note = please recheck to make sure their usages are indeed what you want
lint_multiple_supertrait_upcastable = `{$ident}` is object-safe and has multiple supertraits
lint_multiple_supertrait_upcastable = `{$ident}` is dyn-compatible and has multiple supertraits
lint_named_argument_used_positionally = named argument `{$named_arg_name}` is not used by name
.label_named_arg = this named argument is referred to by position in formatting string

View File

@ -4,7 +4,7 @@ use rustc_session::{declare_lint, declare_lint_pass};
use crate::{LateContext, LateLintPass, LintContext};
declare_lint! {
/// The `multiple_supertrait_upcastable` lint detects when an object-safe trait has multiple
/// The `multiple_supertrait_upcastable` lint detects when a dyn-compatible trait has multiple
/// supertraits.
///
/// ### Example
@ -28,7 +28,7 @@ declare_lint! {
/// additional overhead is justified.
pub MULTIPLE_SUPERTRAIT_UPCASTABLE,
Allow,
"detect when an object-safe trait has multiple supertraits",
"detect when a dyn-compatible trait has multiple supertraits",
@feature_gate = multiple_supertrait_upcastable;
}
@ -37,10 +37,10 @@ declare_lint_pass!(MultipleSupertraitUpcastable => [MULTIPLE_SUPERTRAIT_UPCASTAB
impl<'tcx> LateLintPass<'tcx> for MultipleSupertraitUpcastable {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
let def_id = item.owner_id.to_def_id();
// NOTE(nbdd0121): use `object_safety_violations` instead of `is_object_safe` because
// NOTE(nbdd0121): use `object_safety_violations` instead of `is_dyn_compatible` because
// the latter will report `where_clause_object_safety` lint.
if let hir::ItemKind::Trait(_, _, _, _, _) = item.kind
&& cx.tcx.is_object_safe(def_id)
&& cx.tcx.is_dyn_compatible(def_id)
{
let direct_super_traits_iter = cx
.tcx

View File

@ -83,7 +83,7 @@ macro_rules! arena_types {
>,
[] effective_visibilities: rustc_middle::middle::privacy::EffectiveVisibilities,
[] upvars_mentioned: rustc_data_structures::fx::FxIndexMap<rustc_hir::HirId, rustc_hir::Upvar>,
[] object_safety_violations: rustc_middle::traits::ObjectSafetyViolation,
[] dyn_compatibility_violations: rustc_middle::traits::DynCompatibilityViolation,
[] codegen_unit: rustc_middle::mir::mono::CodegenUnit<'tcx>,
[decode] attribute: rustc_ast::Attribute,
[] name_set: rustc_data_structures::unord::UnordSet<rustc_span::symbol::Symbol>,

View File

@ -70,8 +70,8 @@ use crate::traits::query::{
MethodAutoderefStepsResult, NoSolution, NormalizationResult, OutlivesBound,
};
use crate::traits::{
CodegenObligationError, EvaluationResult, ImplSource, ObjectSafetyViolation, ObligationCause,
OverflowError, WellFormedLoc, specialization_graph,
CodegenObligationError, DynCompatibilityViolation, EvaluationResult, ImplSource,
ObligationCause, OverflowError, WellFormedLoc, specialization_graph,
};
use crate::ty::fast_reject::SimplifiedType;
use crate::ty::layout::ValidityRequirement;
@ -1344,11 +1344,11 @@ rustc_queries! {
cache_on_disk_if { true }
ensure_forwards_result_if_red
}
query object_safety_violations(trait_id: DefId) -> &'tcx [ObjectSafetyViolation] {
desc { |tcx| "determining object safety of trait `{}`", tcx.def_path_str(trait_id) }
query dyn_compatibility_violations(trait_id: DefId) -> &'tcx [DynCompatibilityViolation] {
desc { |tcx| "determining dyn-compatibility of trait `{}`", tcx.def_path_str(trait_id) }
}
query is_object_safe(trait_id: DefId) -> bool {
desc { |tcx| "checking if trait `{}` is object safe", tcx.def_path_str(trait_id) }
query is_dyn_compatible(trait_id: DefId) -> bool {
desc { |tcx| "checking if trait `{}` is dyn-compatible", tcx.def_path_str(trait_id) }
}
/// Gets the ParameterEnvironment for a given item; this environment

View File

@ -556,8 +556,8 @@ pub enum SelectionError<'tcx> {
/// (which for closures includes the "input" type params) and they
/// didn't resolve. See `confirm_poly_trait_refs` for more.
SignatureMismatch(Box<SignatureMismatchData<'tcx>>),
/// The trait pointed by `DefId` is not object safe.
TraitNotObjectSafe(DefId),
/// The trait pointed by `DefId` is dyn-incompatible.
TraitDynIncompatible(DefId),
/// A given constant couldn't be evaluated.
NotConstEvaluatable(NotConstEvaluatable),
/// Exceeded the recursion depth during type projection.
@ -690,7 +690,7 @@ pub struct ImplSourceUserDefinedData<'tcx, N> {
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, HashStable, PartialOrd, Ord)]
pub enum ObjectSafetyViolation {
pub enum DynCompatibilityViolation {
/// `Self: Sized` declared on the trait.
SizedSelf(SmallVec<[Span; 1]>),
@ -711,11 +711,11 @@ pub enum ObjectSafetyViolation {
GAT(Symbol, Span),
}
impl ObjectSafetyViolation {
impl DynCompatibilityViolation {
pub fn error_msg(&self) -> Cow<'static, str> {
match self {
ObjectSafetyViolation::SizedSelf(_) => "it requires `Self: Sized`".into(),
ObjectSafetyViolation::SupertraitSelf(ref spans) => {
DynCompatibilityViolation::SizedSelf(_) => "it requires `Self: Sized`".into(),
DynCompatibilityViolation::SupertraitSelf(ref spans) => {
if spans.iter().any(|sp| *sp != DUMMY_SP) {
"it uses `Self` as a type parameter".into()
} else {
@ -723,81 +723,87 @@ impl ObjectSafetyViolation {
.into()
}
}
ObjectSafetyViolation::SupertraitNonLifetimeBinder(_) => {
DynCompatibilityViolation::SupertraitNonLifetimeBinder(_) => {
"where clause cannot reference non-lifetime `for<...>` variables".into()
}
ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod(_), _) => {
DynCompatibilityViolation::Method(name, MethodViolationCode::StaticMethod(_), _) => {
format!("associated function `{name}` has no `self` parameter").into()
}
ObjectSafetyViolation::Method(
DynCompatibilityViolation::Method(
name,
MethodViolationCode::ReferencesSelfInput(_),
DUMMY_SP,
) => format!("method `{name}` references the `Self` type in its parameters").into(),
ObjectSafetyViolation::Method(name, MethodViolationCode::ReferencesSelfInput(_), _) => {
format!("method `{name}` references the `Self` type in this parameter").into()
}
ObjectSafetyViolation::Method(name, MethodViolationCode::ReferencesSelfOutput, _) => {
format!("method `{name}` references the `Self` type in its return type").into()
}
ObjectSafetyViolation::Method(
DynCompatibilityViolation::Method(
name,
MethodViolationCode::ReferencesSelfInput(_),
_,
) => format!("method `{name}` references the `Self` type in this parameter").into(),
DynCompatibilityViolation::Method(
name,
MethodViolationCode::ReferencesSelfOutput,
_,
) => format!("method `{name}` references the `Self` type in its return type").into(),
DynCompatibilityViolation::Method(
name,
MethodViolationCode::ReferencesImplTraitInTrait(_),
_,
) => {
format!("method `{name}` references an `impl Trait` type in its return type").into()
}
ObjectSafetyViolation::Method(name, MethodViolationCode::AsyncFn, _) => {
DynCompatibilityViolation::Method(name, MethodViolationCode::AsyncFn, _) => {
format!("method `{name}` is `async`").into()
}
ObjectSafetyViolation::Method(
DynCompatibilityViolation::Method(
name,
MethodViolationCode::WhereClauseReferencesSelf,
_,
) => format!("method `{name}` references the `Self` type in its `where` clause").into(),
ObjectSafetyViolation::Method(name, MethodViolationCode::Generic, _) => {
DynCompatibilityViolation::Method(name, MethodViolationCode::Generic, _) => {
format!("method `{name}` has generic type parameters").into()
}
ObjectSafetyViolation::Method(
DynCompatibilityViolation::Method(
name,
MethodViolationCode::UndispatchableReceiver(_),
_,
) => format!("method `{name}`'s `self` parameter cannot be dispatched on").into(),
ObjectSafetyViolation::AssocConst(name, DUMMY_SP) => {
DynCompatibilityViolation::AssocConst(name, DUMMY_SP) => {
format!("it contains associated `const` `{name}`").into()
}
ObjectSafetyViolation::AssocConst(..) => "it contains this associated `const`".into(),
ObjectSafetyViolation::GAT(name, _) => {
DynCompatibilityViolation::AssocConst(..) => {
"it contains this associated `const`".into()
}
DynCompatibilityViolation::GAT(name, _) => {
format!("it contains the generic associated type `{name}`").into()
}
}
}
pub fn solution(&self) -> ObjectSafetyViolationSolution {
pub fn solution(&self) -> DynCompatibilityViolationSolution {
match self {
ObjectSafetyViolation::SizedSelf(_)
| ObjectSafetyViolation::SupertraitSelf(_)
| ObjectSafetyViolation::SupertraitNonLifetimeBinder(..) => {
ObjectSafetyViolationSolution::None
DynCompatibilityViolation::SizedSelf(_)
| DynCompatibilityViolation::SupertraitSelf(_)
| DynCompatibilityViolation::SupertraitNonLifetimeBinder(..) => {
DynCompatibilityViolationSolution::None
}
ObjectSafetyViolation::Method(
DynCompatibilityViolation::Method(
name,
MethodViolationCode::StaticMethod(Some((add_self_sugg, make_sized_sugg))),
_,
) => ObjectSafetyViolationSolution::AddSelfOrMakeSized {
) => DynCompatibilityViolationSolution::AddSelfOrMakeSized {
name: *name,
add_self_sugg: add_self_sugg.clone(),
make_sized_sugg: make_sized_sugg.clone(),
},
ObjectSafetyViolation::Method(
DynCompatibilityViolation::Method(
name,
MethodViolationCode::UndispatchableReceiver(Some(span)),
_,
) => ObjectSafetyViolationSolution::ChangeToRefSelf(*name, *span),
ObjectSafetyViolation::AssocConst(name, _)
| ObjectSafetyViolation::GAT(name, _)
| ObjectSafetyViolation::Method(name, ..) => {
ObjectSafetyViolationSolution::MoveToAnotherTrait(*name)
) => DynCompatibilityViolationSolution::ChangeToRefSelf(*name, *span),
DynCompatibilityViolation::AssocConst(name, _)
| DynCompatibilityViolation::GAT(name, _)
| DynCompatibilityViolation::Method(name, ..) => {
DynCompatibilityViolationSolution::MoveToAnotherTrait(*name)
}
}
}
@ -806,12 +812,12 @@ impl ObjectSafetyViolation {
// When `span` comes from a separate crate, it'll be `DUMMY_SP`. Treat it as `None` so
// diagnostics use a `note` instead of a `span_label`.
match self {
ObjectSafetyViolation::SupertraitSelf(spans)
| ObjectSafetyViolation::SizedSelf(spans)
| ObjectSafetyViolation::SupertraitNonLifetimeBinder(spans) => spans.clone(),
ObjectSafetyViolation::AssocConst(_, span)
| ObjectSafetyViolation::GAT(_, span)
| ObjectSafetyViolation::Method(_, _, span)
DynCompatibilityViolation::SupertraitSelf(spans)
| DynCompatibilityViolation::SizedSelf(spans)
| DynCompatibilityViolation::SupertraitNonLifetimeBinder(spans) => spans.clone(),
DynCompatibilityViolation::AssocConst(_, span)
| DynCompatibilityViolation::GAT(_, span)
| DynCompatibilityViolation::Method(_, _, span)
if *span != DUMMY_SP =>
{
smallvec![*span]
@ -822,7 +828,7 @@ impl ObjectSafetyViolation {
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum ObjectSafetyViolationSolution {
pub enum DynCompatibilityViolationSolution {
None,
AddSelfOrMakeSized {
name: Symbol,
@ -833,11 +839,11 @@ pub enum ObjectSafetyViolationSolution {
MoveToAnotherTrait(Symbol),
}
impl ObjectSafetyViolationSolution {
impl DynCompatibilityViolationSolution {
pub fn add_to<G: EmissionGuarantee>(self, err: &mut Diag<'_, G>) {
match self {
ObjectSafetyViolationSolution::None => {}
ObjectSafetyViolationSolution::AddSelfOrMakeSized {
DynCompatibilityViolationSolution::None => {}
DynCompatibilityViolationSolution::AddSelfOrMakeSized {
name,
add_self_sugg,
make_sized_sugg,
@ -860,7 +866,7 @@ impl ObjectSafetyViolationSolution {
Applicability::MaybeIncorrect,
);
}
ObjectSafetyViolationSolution::ChangeToRefSelf(name, span) => {
DynCompatibilityViolationSolution::ChangeToRefSelf(name, span) => {
err.span_suggestion(
span,
format!("consider changing method `{name}`'s `self` parameter to be `&self`"),
@ -868,14 +874,14 @@ impl ObjectSafetyViolationSolution {
Applicability::MachineApplicable,
);
}
ObjectSafetyViolationSolution::MoveToAnotherTrait(name) => {
DynCompatibilityViolationSolution::MoveToAnotherTrait(name) => {
err.help(format!("consider moving `{name}` to another trait"));
}
}
}
}
/// Reasons a method might not be object-safe.
/// Reasons a method might not be dyn-compatible.
#[derive(Clone, Debug, PartialEq, Eq, Hash, HashStable, PartialOrd, Ord)]
pub enum MethodViolationCode {
/// e.g., `fn foo()`

View File

@ -527,8 +527,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
self.trait_is_alias(trait_def_id)
}
fn trait_is_object_safe(self, trait_def_id: DefId) -> bool {
self.is_object_safe(trait_def_id)
fn trait_is_dyn_compatible(self, trait_def_id: DefId) -> bool {
self.is_dyn_compatible(trait_def_id)
}
fn trait_is_fundamental(self, def_id: DefId) -> bool {

View File

@ -301,7 +301,7 @@ impl FlagComputation {
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(arg)) => {
self.add_args(slice::from_ref(&arg));
}
ty::PredicateKind::ObjectSafe(_def_id) => {}
ty::PredicateKind::DynCompatible(_def_id) => {}
ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(uv)) => {
self.add_const(uv);
}

View File

@ -50,7 +50,7 @@ pub enum ReifyReason {
/// * A vtable entry is directly converted to a function call (e.g. creating a fn ptr from a
/// method on a `dyn` object).
/// * A function with `#[track_caller]` is converted to a function pointer
/// * If KCFI is enabled, creating a function pointer from a method on an object-safe trait.
/// * If KCFI is enabled, creating a function pointer from a method on a dyn-compatible trait.
/// This includes the case of converting `::call`-like methods on closure-likes to function
/// pointers.
FnPtr,

View File

@ -36,7 +36,7 @@ pub type PolyProjectionPredicate<'tcx> = ty::Binder<'tcx, ProjectionPredicate<'t
/// A statement that can be proven by a trait solver. This includes things that may
/// show up in where clauses, such as trait predicates and projection predicates,
/// and also things that are emitted as part of type checking such as `ObjectSafe`
/// and also things that are emitted as part of type checking such as `DynCompatible`
/// predicate which is emitted when a type is coerced to a trait object.
///
/// Use this rather than `PredicateKind`, whenever possible.
@ -147,7 +147,7 @@ impl<'tcx> Predicate<'tcx> {
| PredicateKind::Clause(ClauseKind::TypeOutlives(_))
| PredicateKind::Clause(ClauseKind::Projection(_))
| PredicateKind::Clause(ClauseKind::ConstArgHasType(..))
| PredicateKind::ObjectSafe(_)
| PredicateKind::DynCompatible(_)
| PredicateKind::Subtype(_)
| PredicateKind::Coerce(_)
| PredicateKind::Clause(ClauseKind::ConstEvaluatable(_))
@ -647,7 +647,7 @@ impl<'tcx> Predicate<'tcx> {
| PredicateKind::Coerce(..)
| PredicateKind::Clause(ClauseKind::RegionOutlives(..))
| PredicateKind::Clause(ClauseKind::WellFormed(..))
| PredicateKind::ObjectSafe(..)
| PredicateKind::DynCompatible(..)
| PredicateKind::Clause(ClauseKind::TypeOutlives(..))
| PredicateKind::Clause(ClauseKind::ConstEvaluatable(..))
| PredicateKind::ConstEquate(..)
@ -667,7 +667,7 @@ impl<'tcx> Predicate<'tcx> {
| PredicateKind::Coerce(..)
| PredicateKind::Clause(ClauseKind::RegionOutlives(..))
| PredicateKind::Clause(ClauseKind::WellFormed(..))
| PredicateKind::ObjectSafe(..)
| PredicateKind::DynCompatible(..)
| PredicateKind::Clause(ClauseKind::TypeOutlives(..))
| PredicateKind::Clause(ClauseKind::ConstEvaluatable(..))
| PredicateKind::ConstEquate(..)

View File

@ -3088,8 +3088,8 @@ define_print! {
}
ty::PredicateKind::Subtype(predicate) => p!(print(predicate)),
ty::PredicateKind::Coerce(predicate) => p!(print(predicate)),
ty::PredicateKind::ObjectSafe(trait_def_id) => {
p!("the trait `", print_def_path(trait_def_id, &[]), "` is object-safe")
ty::PredicateKind::DynCompatible(trait_def_id) => {
p!("the trait `", print_def_path(trait_def_id, &[]), "` is dyn-compatible")
}
ty::PredicateKind::ConstEquate(c1, c2) => {
p!("the constant `", print(c1), "` equals `", print(c2), "`")

View File

@ -1602,7 +1602,7 @@ impl<'tcx> ExplicitSelf<'tcx> {
/// `Other`.
/// This is mainly used to require the arbitrary_self_types feature
/// in the case of `Other`, to improve error messages in the common cases,
/// and to make `Other` non-object-safe.
/// and to make `Other` dyn-incompatible.
///
/// Examples:
///

View File

@ -120,7 +120,7 @@
//! #### Unsizing Casts
//! A subtle way of introducing use edges is by casting to a trait object.
//! Since the resulting fat-pointer contains a reference to a vtable, we need to
//! instantiate all object-safe methods of the trait, as we need to store
//! instantiate all dyn-compatible methods of the trait, as we need to store
//! pointers to these functions even if they never get called anywhere. This can
//! be seen as a special case of taking a function reference.
//!

View File

@ -639,8 +639,8 @@ where
ty::Dynamic(bounds, ..) => bounds,
};
// Do not consider built-in object impls for non-object-safe types.
if bounds.principal_def_id().is_some_and(|def_id| !cx.trait_is_object_safe(def_id)) {
// Do not consider built-in object impls for dyn-incompatible types.
if bounds.principal_def_id().is_some_and(|def_id| !cx.trait_is_dyn_compatible(def_id)) {
return;
}

View File

@ -423,8 +423,8 @@ where
ty::PredicateKind::Coerce(predicate) => {
self.compute_coerce_goal(Goal { param_env, predicate })
}
ty::PredicateKind::ObjectSafe(trait_def_id) => {
self.compute_object_safe_goal(trait_def_id)
ty::PredicateKind::DynCompatible(trait_def_id) => {
self.compute_dyn_compatible_goal(trait_def_id)
}
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(arg)) => {
self.compute_well_formed_goal(Goal { param_env, predicate: arg })

View File

@ -111,8 +111,8 @@ where
}
}
fn compute_object_safe_goal(&mut self, trait_def_id: I::DefId) -> QueryResult<I> {
if self.cx().trait_is_object_safe(trait_def_id) {
fn compute_dyn_compatible_goal(&mut self, trait_def_id: I::DefId) -> QueryResult<I> {
if self.cx().trait_is_dyn_compatible(trait_def_id) {
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
} else {
Err(NoSolution)

View File

@ -832,8 +832,8 @@ where
let cx = self.cx();
let Goal { predicate: (a_ty, _), .. } = goal;
// Can only unsize to an object-safe trait.
if b_data.principal_def_id().is_some_and(|def_id| !cx.trait_is_object_safe(def_id)) {
// Can only unsize to an dyn-compatible trait.
if b_data.principal_def_id().is_some_and(|def_id| !cx.trait_is_dyn_compatible(def_id)) {
return Err(NoSolution);
}

View File

@ -475,7 +475,7 @@ fn implemented_method<'tcx>(
} else {
return None;
};
let vtable_possible =
traits::is_vtable_safe_method(tcx, trait_id, trait_method) && tcx.is_object_safe(trait_id);
let vtable_possible = traits::is_vtable_safe_method(tcx, trait_id, trait_method)
&& tcx.is_dyn_compatible(trait_id);
vtable_possible.then_some((trait_ref, method_id, ancestor))
}

View File

@ -633,8 +633,8 @@ impl<'tcx> Stable<'tcx> for ty::PredicateKind<'tcx> {
PredicateKind::Clause(clause_kind) => {
stable_mir::ty::PredicateKind::Clause(clause_kind.stable(tables))
}
PredicateKind::ObjectSafe(did) => {
stable_mir::ty::PredicateKind::ObjectSafe(tables.trait_def(*did))
PredicateKind::DynCompatible(did) => {
stable_mir::ty::PredicateKind::DynCompatible(tables.trait_def(*did))
}
PredicateKind::Subtype(subtype_predicate) => {
stable_mir::ty::PredicateKind::SubType(subtype_predicate.stable(tables))

View File

@ -38,7 +38,7 @@ use super::{
};
use crate::error_reporting::TypeErrCtxt;
use crate::error_reporting::infer::TyCategory;
use crate::error_reporting::traits::report_object_safety_error;
use crate::error_reporting::traits::report_dyn_incompatibility;
use crate::errors::{
AsyncClosureNotFn, ClosureFnMutLabel, ClosureFnOnceLabel, ClosureKindMismatch,
};
@ -47,7 +47,7 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
use crate::traits::{
MismatchedProjectionTypes, NormalizeExt, Obligation, ObligationCause, ObligationCauseCode,
ObligationCtxt, Overflow, PredicateObligation, SelectionError, SignatureMismatch,
TraitNotObjectSafe, elaborate,
TraitDynIncompatible, elaborate,
};
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
@ -568,9 +568,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
)
}
ty::PredicateKind::ObjectSafe(trait_def_id) => {
let violations = self.tcx.object_safety_violations(trait_def_id);
report_object_safety_error(self.tcx, span, None, trait_def_id, violations)
ty::PredicateKind::DynCompatible(trait_def_id) => {
let violations = self.tcx.dyn_compatibility_violations(trait_def_id);
report_dyn_incompatibility(self.tcx, span, None, trait_def_id, violations)
}
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(ty)) => {
@ -645,9 +645,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
def_id,
),
TraitNotObjectSafe(did) => {
let violations = self.tcx.object_safety_violations(did);
report_object_safety_error(self.tcx, span, None, did, violations)
TraitDynIncompatible(did) => {
let violations = self.tcx.dyn_compatibility_violations(did);
report_dyn_incompatibility(self.tcx, span, None, did, violations)
}
SelectionError::NotConstEvaluatable(NotConstEvaluatable::MentionsInfer) => {

View File

@ -12,8 +12,8 @@ use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::Visitor;
use rustc_hir::{self as hir, LangItem};
use rustc_infer::traits::{
ObjectSafetyViolation, Obligation, ObligationCause, ObligationCauseCode, PredicateObligation,
SelectionError,
DynCompatibilityViolation, Obligation, ObligationCause, ObligationCauseCode,
PredicateObligation, SelectionError,
};
use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths};
use rustc_middle::ty::{self, Ty, TyCtxt};
@ -406,12 +406,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}
}
pub fn report_object_safety_error<'tcx>(
pub fn report_dyn_incompatibility<'tcx>(
tcx: TyCtxt<'tcx>,
span: Span,
hir_id: Option<hir::HirId>,
trait_def_id: DefId,
violations: &[ObjectSafetyViolation],
violations: &[DynCompatibilityViolation],
) -> Diag<'tcx> {
let trait_str = tcx.def_path_str(trait_def_id);
let trait_span = tcx.hir().get_if_local(trait_def_id).and_then(|node| match node {
@ -449,12 +449,12 @@ pub fn report_object_safety_error<'tcx>(
let mut multi_span = vec![];
let mut messages = vec![];
for violation in violations {
if let ObjectSafetyViolation::SizedSelf(sp) = &violation
if let DynCompatibilityViolation::SizedSelf(sp) = &violation
&& !sp.is_empty()
{
// Do not report `SizedSelf` without spans pointing at `SizedSelf` obligations
// with a `Span`.
reported_violations.insert(ObjectSafetyViolation::SizedSelf(vec![].into()));
reported_violations.insert(DynCompatibilityViolation::SizedSelf(vec![].into()));
}
if reported_violations.insert(violation.clone()) {
let spans = violation.spans();
@ -481,9 +481,10 @@ pub fn report_object_safety_error<'tcx>(
for (span, msg) in iter::zip(multi_span, messages) {
note_span.push_span_label(span, msg);
}
// FIXME(dyn_compat_renaming): Update the URL.
err.span_note(
note_span,
"for a trait to be \"object safe\" it needs to allow building a vtable to allow the call \
"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 \
<https://doc.rust-lang.org/reference/items/traits.html#object-safety>",
);

View File

@ -275,7 +275,7 @@ fn fulfillment_error_for_no_solution<'tcx>(
FulfillmentErrorCode::Subtype(expected_found, TypeError::Sorts(expected_found))
}
ty::PredicateKind::Clause(_)
| ty::PredicateKind::ObjectSafe(_)
| ty::PredicateKind::DynCompatible(_)
| ty::PredicateKind::Ambiguous => {
FulfillmentErrorCode::Select(SelectionError::Unimplemented)
}

View File

@ -802,7 +802,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
| ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
| ty::PredicateKind::NormalizesTo(..)
| ty::PredicateKind::AliasRelate(..)
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::DynCompatible(..)
| ty::PredicateKind::Subtype(..)
// FIXME(generic_const_exprs): you can absolutely add this as a where clauses
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))

View File

@ -28,43 +28,43 @@ use tracing::{debug, instrument};
use super::elaborate;
use crate::infer::TyCtxtInferExt;
pub use crate::traits::ObjectSafetyViolation;
pub use crate::traits::DynCompatibilityViolation;
use crate::traits::query::evaluate_obligation::InferCtxtExt;
use crate::traits::{MethodViolationCode, Obligation, ObligationCause, util};
/// Returns the object safety violations that affect HIR ty lowering.
/// Returns the dyn-compatibility violations that affect HIR ty lowering.
///
/// Currently that is `Self` in supertraits. This is needed
/// because `object_safety_violations` can't be used during
/// because `dyn_compatibility_violations` can't be used during
/// type collection.
#[instrument(level = "debug", skip(tcx))]
pub fn hir_ty_lowering_object_safety_violations(
#[instrument(level = "debug", skip(tcx), ret)]
pub fn hir_ty_lowering_dyn_compatibility_violations(
tcx: TyCtxt<'_>,
trait_def_id: DefId,
) -> Vec<ObjectSafetyViolation> {
) -> Vec<DynCompatibilityViolation> {
debug_assert!(tcx.generics_of(trait_def_id).has_self);
let violations = tcx
.supertrait_def_ids(trait_def_id)
tcx.supertrait_def_ids(trait_def_id)
.map(|def_id| predicates_reference_self(tcx, def_id, true))
.filter(|spans| !spans.is_empty())
.map(ObjectSafetyViolation::SupertraitSelf)
.collect();
debug!(?violations);
violations
.map(DynCompatibilityViolation::SupertraitSelf)
.collect()
}
fn object_safety_violations(tcx: TyCtxt<'_>, trait_def_id: DefId) -> &'_ [ObjectSafetyViolation] {
fn dyn_compatibility_violations(
tcx: TyCtxt<'_>,
trait_def_id: DefId,
) -> &'_ [DynCompatibilityViolation] {
debug_assert!(tcx.generics_of(trait_def_id).has_self);
debug!("object_safety_violations: {:?}", trait_def_id);
debug!("dyn_compatibility_violations: {:?}", trait_def_id);
tcx.arena.alloc_from_iter(
tcx.supertrait_def_ids(trait_def_id)
.flat_map(|def_id| object_safety_violations_for_trait(tcx, def_id)),
.flat_map(|def_id| dyn_compatibility_violations_for_trait(tcx, def_id)),
)
}
fn is_object_safe(tcx: TyCtxt<'_>, trait_def_id: DefId) -> bool {
tcx.object_safety_violations(trait_def_id).is_empty()
fn is_dyn_compatible(tcx: TyCtxt<'_>, trait_def_id: DefId) -> bool {
tcx.dyn_compatibility_violations(trait_def_id).is_empty()
}
/// We say a method is *vtable safe* if it can be invoked on a trait
@ -82,34 +82,35 @@ pub fn is_vtable_safe_method(tcx: TyCtxt<'_>, trait_def_id: DefId, method: ty::A
virtual_call_violations_for_method(tcx, trait_def_id, method).is_empty()
}
fn object_safety_violations_for_trait(
#[instrument(level = "debug", skip(tcx), ret)]
fn dyn_compatibility_violations_for_trait(
tcx: TyCtxt<'_>,
trait_def_id: DefId,
) -> Vec<ObjectSafetyViolation> {
) -> Vec<DynCompatibilityViolation> {
// Check assoc items for violations.
let mut violations: Vec<_> = tcx
.associated_items(trait_def_id)
.in_definition_order()
.flat_map(|&item| object_safety_violations_for_assoc_item(tcx, trait_def_id, item))
.flat_map(|&item| dyn_compatibility_violations_for_assoc_item(tcx, trait_def_id, item))
.collect();
// Check the trait itself.
if trait_has_sized_self(tcx, trait_def_id) {
// We don't want to include the requirement from `Sized` itself to be `Sized` in the list.
let spans = get_sized_bounds(tcx, trait_def_id);
violations.push(ObjectSafetyViolation::SizedSelf(spans));
violations.push(DynCompatibilityViolation::SizedSelf(spans));
}
let spans = predicates_reference_self(tcx, trait_def_id, false);
if !spans.is_empty() {
violations.push(ObjectSafetyViolation::SupertraitSelf(spans));
violations.push(DynCompatibilityViolation::SupertraitSelf(spans));
}
let spans = bounds_reference_self(tcx, trait_def_id);
if !spans.is_empty() {
violations.push(ObjectSafetyViolation::SupertraitSelf(spans));
violations.push(DynCompatibilityViolation::SupertraitSelf(spans));
}
let spans = super_predicates_have_non_lifetime_binders(tcx, trait_def_id);
if !spans.is_empty() {
violations.push(ObjectSafetyViolation::SupertraitNonLifetimeBinder(spans));
violations.push(DynCompatibilityViolation::SupertraitNonLifetimeBinder(spans));
}
if violations.is_empty() {
@ -120,11 +121,6 @@ fn object_safety_violations_for_trait(
}
}
debug!(
"object_safety_violations_for_trait(trait_def_id={:?}) = {:?}",
trait_def_id, violations
);
violations
}
@ -296,13 +292,13 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
})
}
/// Returns `Some(_)` if this item makes the containing trait not object safe.
/// Returns `Some(_)` if this item makes the containing trait dyn-incompatible.
#[instrument(level = "debug", skip(tcx), ret)]
pub fn object_safety_violations_for_assoc_item(
pub fn dyn_compatibility_violations_for_assoc_item(
tcx: TyCtxt<'_>,
trait_def_id: DefId,
item: ty::AssocItem,
) -> Vec<ObjectSafetyViolation> {
) -> Vec<DynCompatibilityViolation> {
// Any item that has a `Self : Sized` requisite is otherwise
// exempt from the regulations.
if tcx.generics_require_sized_self(item.def_id) {
@ -310,10 +306,10 @@ pub fn object_safety_violations_for_assoc_item(
}
match item.kind {
// Associated consts are never object safe, as they can't have `where` bounds yet at all,
// Associated consts are never dyn-compatible, as they can't have `where` bounds yet at all,
// and associated const bounds in trait objects aren't a thing yet either.
ty::AssocKind::Const => {
vec![ObjectSafetyViolation::AssocConst(item.name, item.ident(tcx).span)]
vec![DynCompatibilityViolation::AssocConst(item.name, item.ident(tcx).span)]
}
ty::AssocKind::Fn => virtual_call_violations_for_method(tcx, trait_def_id, item)
.into_iter()
@ -330,16 +326,16 @@ pub fn object_safety_violations_for_assoc_item(
_ => item.ident(tcx).span,
};
ObjectSafetyViolation::Method(item.name, v, span)
DynCompatibilityViolation::Method(item.name, v, span)
})
.collect(),
// Associated types can only be object safe if they have `Self: Sized` bounds.
// Associated types can only be dyn-compatible if they have `Self: Sized` bounds.
ty::AssocKind::Type => {
if !tcx.features().generic_associated_types_extended
&& !tcx.generics_of(item.def_id).is_own_empty()
&& !item.is_impl_trait_in_trait()
{
vec![ObjectSafetyViolation::GAT(item.name, item.ident(tcx).span)]
vec![DynCompatibilityViolation::GAT(item.name, item.ident(tcx).span)]
} else {
// We will permit associated types if they are explicitly mentioned in the trait object.
// We can't check this here, as here we only check if it is guaranteed to not be possible.
@ -351,8 +347,8 @@ pub fn object_safety_violations_for_assoc_item(
/// Returns `Some(_)` if this method cannot be called on a trait
/// object; this does not necessarily imply that the enclosing trait
/// is not object safe, because the method might have a where clause
/// `Self:Sized`.
/// is dyn-incompatible, because the method might have a where clause
/// `Self: Sized`.
fn virtual_call_violations_for_method<'tcx>(
tcx: TyCtxt<'tcx>,
trait_def_id: DefId,
@ -932,8 +928,8 @@ fn contains_illegal_impl_trait_in_trait<'tcx>(
pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers {
object_safety_violations,
is_object_safe,
dyn_compatibility_violations,
is_dyn_compatible,
generics_require_sized_self,
..*providers
};

View File

@ -363,7 +363,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
| ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(_))
| ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
| ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_))
| ty::PredicateKind::ObjectSafe(_)
| ty::PredicateKind::DynCompatible(_)
| ty::PredicateKind::Subtype(_)
| ty::PredicateKind::Coerce(_)
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
@ -418,8 +418,8 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
)
}
ty::PredicateKind::ObjectSafe(trait_def_id) => {
if !self.selcx.tcx().is_object_safe(trait_def_id) {
ty::PredicateKind::DynCompatible(trait_def_id) => {
if !self.selcx.tcx().is_dyn_compatible(trait_def_id) {
ProcessResult::Error(FulfillmentErrorCode::Select(Unimplemented))
} else {
ProcessResult::Changed(vec![])

View File

@ -5,11 +5,11 @@
pub mod auto_trait;
pub(crate) mod coherence;
pub mod const_evaluatable;
mod dyn_compatibility;
mod engine;
mod fulfill;
pub mod misc;
pub mod normalize;
mod object_safety;
pub mod outlives_bounds;
pub mod project;
pub mod query;
@ -43,13 +43,13 @@ pub use self::coherence::{
InCrate, IsFirstInputType, OrphanCheckErr, OrphanCheckMode, OverlapResult, UncoveredTyParams,
add_placeholder_note, orphan_check_trait_ref, overlapping_impls,
};
pub use self::dyn_compatibility::{
DynCompatibilityViolation, dyn_compatibility_violations_for_assoc_item,
hir_ty_lowering_dyn_compatibility_violations, is_vtable_safe_method,
};
pub use self::engine::{ObligationCtxt, TraitEngineExt};
pub use self::fulfill::{FulfillmentContext, OldSolverError, PendingPredicateObligation};
pub use self::normalize::NormalizeExt;
pub use self::object_safety::{
ObjectSafetyViolation, hir_ty_lowering_object_safety_violations, is_vtable_safe_method,
object_safety_violations_for_assoc_item,
};
pub use self::project::{normalize_inherent_projection, normalize_projection_ty};
pub use self::select::{
EvaluationCache, EvaluationResult, IntercrateAmbiguityCause, OverflowError, SelectionCache,
@ -593,7 +593,7 @@ fn is_impossible_associated_item(
}
pub fn provide(providers: &mut Providers) {
object_safety::provide(providers);
dyn_compatibility::provide(providers);
vtable::provide(providers);
*providers = Providers {
specialization_graph_of: specialize::specialization_graph_provider,

View File

@ -113,7 +113,7 @@ pub fn compute_implied_outlives_bounds_inner<'tcx>(
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::Coerce(..)
| ty::PredicateKind::Clause(ty::ClauseKind::Projection(..))
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::DynCompatible(..)
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::Ambiguous
@ -217,7 +217,7 @@ pub fn compute_implied_outlives_bounds_compat_inner<'tcx>(
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::Coerce(..)
| ty::PredicateKind::Clause(ty::ClauseKind::Projection(..))
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::DynCompatible(..)
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::Ambiguous

View File

@ -883,7 +883,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
if let Some(principal) = data.principal() {
if !self.infcx.tcx.features().object_safe_for_dispatch {
principal.with_self_ty(self.tcx(), self_ty)
} else if self.tcx().is_object_safe(principal.def_id()) {
} else if self.tcx().is_dyn_compatible(principal.def_id()) {
principal.with_self_ty(self.tcx(), self_ty)
} else {
return;

View File

@ -30,7 +30,7 @@ use crate::traits::util::{self, closure_trait_ref_and_return_type};
use crate::traits::{
ImplDerivedCause, ImplSource, ImplSourceUserDefinedData, Normalized, Obligation,
ObligationCause, PolyTraitObligation, PredicateObligation, Selection, SelectionError,
SignatureMismatch, TraitNotObjectSafe, TraitObligation, Unimplemented,
SignatureMismatch, TraitDynIncompatible, TraitObligation, Unimplemented,
};
impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
@ -630,7 +630,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation.cause.span,
"GATs in trait object shouldn't have been considered",
);
return Err(SelectionError::TraitNotObjectSafe(trait_predicate.trait_ref.def_id));
return Err(SelectionError::TraitDynIncompatible(trait_predicate.trait_ref.def_id));
}
// This maybe belongs in wf, but that can't (doesn't) handle
@ -1187,11 +1187,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ImplSource::Builtin(BuiltinImplSource::Misc, obligations)
}
// `T` -> `Trait`
// `T` -> `dyn Trait`
(_, &ty::Dynamic(data, r, ty::Dyn)) => {
let mut object_dids = data.auto_traits().chain(data.principal_def_id());
if let Some(did) = object_dids.find(|did| !tcx.is_object_safe(*did)) {
return Err(TraitNotObjectSafe(did));
if let Some(did) = object_dids.find(|did| !tcx.is_dyn_compatible(*did)) {
return Err(TraitDynIncompatible(did));
}
let predicate_to_obligation = |predicate| {

View File

@ -772,8 +772,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
Ok(EvaluatedToOkModuloRegions)
}
ty::PredicateKind::ObjectSafe(trait_def_id) => {
if self.tcx().is_object_safe(trait_def_id) {
ty::PredicateKind::DynCompatible(trait_def_id) => {
if self.tcx().is_dyn_compatible(trait_def_id) {
Ok(EvaluatedToOk)
} else {
Ok(EvaluatedToErr)

View File

@ -838,7 +838,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
self.cause(ObligationCauseCode::WellFormed(None)),
self.recursion_depth,
self.param_env,
ty::Binder::dummy(ty::PredicateKind::ObjectSafe(principal)),
ty::Binder::dummy(ty::PredicateKind::DynCompatible(principal)),
));
}
}

View File

@ -59,7 +59,7 @@ fn not_outlives_predicate(p: ty::Predicate<'_>) -> bool {
| ty::PredicateKind::NormalizesTo(..)
| ty::PredicateKind::AliasRelate(..)
| ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(..))
| ty::PredicateKind::ObjectSafe(..)
| ty::PredicateKind::DynCompatible(..)
| ty::PredicateKind::Subtype(..)
| ty::PredicateKind::Coerce(..)
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))

View File

@ -255,7 +255,7 @@ pub trait Interner:
fn trait_is_alias(self, trait_def_id: Self::DefId) -> bool;
fn trait_is_object_safe(self, trait_def_id: Self::DefId) -> bool;
fn trait_is_dyn_compatible(self, trait_def_id: Self::DefId) -> bool;
fn trait_is_fundamental(self, def_id: Self::DefId) -> bool;

View File

@ -46,8 +46,8 @@ pub enum PredicateKind<I: Interner> {
/// Prove a clause
Clause(ClauseKind<I>),
/// Trait must be object-safe.
ObjectSafe(I::DefId),
/// Trait must be dyn-compatible.
DynCompatible(I::DefId),
/// `T1 <: T2`
///
@ -128,8 +128,8 @@ impl<I: Interner> fmt::Debug for PredicateKind<I> {
PredicateKind::Clause(a) => a.fmt(f),
PredicateKind::Subtype(pair) => pair.fmt(f),
PredicateKind::Coerce(pair) => pair.fmt(f),
PredicateKind::ObjectSafe(trait_def_id) => {
write!(f, "ObjectSafe({trait_def_id:?})")
PredicateKind::DynCompatible(trait_def_id) => {
write!(f, "DynCompatible({trait_def_id:?})")
}
PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({c1:?}, {c2:?})"),
PredicateKind::Ambiguous => write!(f, "Ambiguous"),

View File

@ -1420,7 +1420,7 @@ pub struct GenericPredicates {
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub enum PredicateKind {
Clause(ClauseKind),
ObjectSafe(TraitDef),
DynCompatible(TraitDef),
SubType(SubtypePredicate),
Coerce(CoercePredicate),
ConstEquate(TyConst, TyConst),

View File

@ -42,9 +42,12 @@ checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f"
[[package]]
name = "cc"
version = "1.0.99"
version = "1.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695"
checksum = "9540e661f81799159abee814118cc139a2004b3a3aa3ea37724a1b66530b90e0"
dependencies = [
"shlex",
]
[[package]]
name = "cfg-if"
@ -312,6 +315,12 @@ dependencies = [
"std",
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "std"
version = "0.0.0"

View File

@ -0,0 +1,29 @@
((rustic-mode
.((eglot-workspace-configuration
. (:rust-analyzer
( :check ( :invocationLocation "root"
:invocationStrategy "once"
:overrideCommand ["python3"
"x.py"
"check"
"--json-output"])
:linkedProjects ["Cargo.toml"
"src/tools/x/Cargo.toml"
"src/bootstrap/Cargo.toml"
"src/tools/rust-analyzer/Cargo.toml"
"compiler/rustc_codegen_cranelift/Cargo.toml"
"compiler/rustc_codegen_gcc/Cargo.toml"]
:rustfmt ( :overrideCommand ["build/host/rustfmt/bin/rustfmt"
"--edition=2021"])
:procMacro ( :server "build/host/stage0/libexec/rust-analyzer-proc-macro-srv"
:enable t)
:cargo ( :buildScripts ( :enable t
:invocationLocation "root"
:invocationStrategy "once"
:overrideCommand ["python3"
"x.py"
"check"
"--json-output"])
:sysrootSrc "./library"
:extraEnv (:RUSTC_BOOTSTRAP "1"))
:rustc ( :source "./Cargo.toml" )))))))

View File

@ -0,0 +1,49 @@
[language-server.rust-analyzer.config]
linkedProjects = [
"Cargo.toml",
"src/tools/x/Cargo.toml",
"src/bootstrap/Cargo.toml",
"src/tools/rust-analyzer/Cargo.toml",
"compiler/rustc_codegen_cranelift/Cargo.toml",
"compiler/rustc_codegen_gcc/Cargo.toml"
]
[language-server.rust-analyzer.config.check]
invocationLocation = "root"
invocationStrategy = "once"
overrideCommand = [
"python3",
"x.py",
"check",
"--json-output",
]
[language-server.rust-analyzer.config.rustfmt]
overrideCommand = [
"build-rust-analyzer/host/rustfmt/bin/rustfmt",
"--edition=2021"
]
[language-server.rust-analyzer.config.procMacro]
server = "build-rust-analyzer/host/stage0/libexec/rust-analyzer-proc-macro-srv"
enable = true
[language-server.rust-analyzer.config.rustc]
source = "./Cargo.toml"
[language-server.rust-analyzer.config.cargo]
sysrootSrc = "./library"
[language-server.rust-analyzer.config.cargo.extraEnv]
RUSTC_BOOTSTRAP = "1"
[language-server.rust-analyzer.config.cargo.buildScripts]
enable = true
invocationLocation = "root"
invocationStrategy = "once"
overrideCommand = [
"python3",
"x.py",
"check",
"--json-output",
]

View File

@ -1480,7 +1480,7 @@ impl Trait {
tcx.trait_def(self.def_id).safety
}
pub(crate) fn is_object_safe(&self, tcx: TyCtxt<'_>) -> bool {
tcx.is_object_safe(self.def_id)
tcx.is_dyn_compatible(self.def_id)
}
}

View File

@ -481,6 +481,7 @@ const PERMITTED_STDLIB_DEPENDENCIES: &[&str] = &[
"rand_core",
"rand_xorshift",
"rustc-demangle",
"shlex",
"unicode-width",
"unwinding",
"wasi",

View File

@ -98,7 +98,7 @@ error[E0038]: the trait `X` cannot be made into an object
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
| ^^^^^^^^^^^^^^^^^^^^ `X` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
|
LL | trait X {

View File

@ -300,7 +300,7 @@ error[E0038]: the trait `SVec` cannot be made into an object
LL | pub fn next<'a, T>(s: &'a mut dyn SVec<Item = T, Output = T>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `SVec` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/issue-105742.rs:14:17
|
LL | pub trait SVec: Index<

View File

@ -4,7 +4,7 @@ error[E0038]: the trait `Trait` cannot be made into an object
LL | impl dyn Trait {
| ^^^^^^^^^ `Trait` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/associated-const-in-trait.rs:4:11
|
LL | trait Trait {
@ -19,7 +19,7 @@ error[E0038]: the trait `Trait` cannot be made into an object
LL | const fn n() -> usize { Self::N }
| ^^^^ `Trait` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/associated-const-in-trait.rs:4:11
|
LL | trait Trait {

View File

@ -4,7 +4,7 @@ error[E0038]: the trait `Bar` cannot be made into an object
LL | impl dyn Bar {}
| ^^^^^^^ `Bar` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/issue-48027.rs:2:11
|
LL | trait Bar {

View File

@ -5,7 +5,7 @@ LL | fn f(_: impl Trait<T = Copy>) {}
| ^^^^^^^^ `Copy` cannot be made into an object
|
= note: the trait cannot be made into an object because it requires `Self: Sized`
= note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
= 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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
error[E0225]: only auto traits can be used as additional traits in a trait object
--> $DIR/suggest-assoc-ty-bound-on-eq-bound.rs:10:42
@ -24,7 +24,7 @@ error[E0038]: the trait `Eq` cannot be made into an object
LL | fn g(_: impl Trait<T = std::fmt::Debug + Eq>) {}
| ^^^^^^^^^^^^^^^^^^^^ `Eq` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/cmp.rs:LL:COL
|
= note: the trait cannot be made into an object because it uses `Self` as a type parameter

View File

@ -4,7 +4,7 @@ error[E0038]: the trait `AsyncFnMut` cannot be made into an object
LL | fn foo(x: &dyn async Fn()) {}
| ^^^^^^^^^^ `AsyncFnMut` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
|
= note: the trait cannot be made into an object because it contains the generic associated type `CallRefFuture`
@ -19,7 +19,7 @@ error[E0038]: the trait `AsyncFnMut` cannot be made into an object
LL | fn foo(x: &dyn async Fn()) {}
| ^^^^^^^^^^ `AsyncFnMut` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
|
= note: the trait cannot be made into an object because it contains the generic associated type `CallRefFuture`
@ -35,7 +35,7 @@ error[E0038]: the trait `AsyncFnMut` cannot be made into an object
LL | fn foo(x: &dyn async Fn()) {}
| ^^^^^^^^^^ `AsyncFnMut` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
|
= note: the trait cannot be made into an object because it contains the generic associated type `CallRefFuture`
@ -51,7 +51,7 @@ error[E0038]: the trait `AsyncFn` cannot be made into an object
LL | fn foo(x: &dyn async Fn()) {}
| ^^^^^^^^^^^^^^ `AsyncFn` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/ops/async_function.rs:LL:COL
|
= note: the trait cannot be made into an object because it contains the generic associated type `CallRefFuture`

View File

@ -1,5 +1,4 @@
//@ check-fail
//@ known-bug: #102682
//@ known-bug: #130935
//@ edition: 2021
use std::fmt::Debug;

View File

@ -1,5 +1,5 @@
error[E0311]: the parameter type `T` may not live long enough
--> $DIR/async-generics-and-bounds.rs:9:5
--> $DIR/async-generics-and-bounds.rs:8:5
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^^^^^^^^^^^^^-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -13,7 +13,7 @@ LL | async fn foo<'a>(&'a self) -> &'a (T, U) where T: Debug + Sized, U: Has
| ++++ ++ ++ +++++++
error[E0311]: the parameter type `U` may not live long enough
--> $DIR/async-generics-and-bounds.rs:9:5
--> $DIR/async-generics-and-bounds.rs:8:5
|
LL | async fn foo(&self) -> &(T, U) where T: Debug + Sized, U: Hash;
| ^^^^^^^^^^^^^-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -1,5 +1,4 @@
//@ check-fail
//@ known-bug: #102682
//@ known-bug: #130935
//@ edition: 2021
trait MyTrait<T, U> {

View File

@ -1,5 +1,5 @@
error[E0311]: the parameter type `T` may not live long enough
--> $DIR/async-generics.rs:6:5
--> $DIR/async-generics.rs:5:5
|
LL | async fn foo(&self) -> &(T, U);
| ^^^^^^^^^^^^^-^^^^^^^^^^^^^^^^^
@ -13,7 +13,7 @@ LL | async fn foo<'a>(&'a self) -> &'a (T, U) where T: 'a;
| ++++ ++ ++ +++++++++++
error[E0311]: the parameter type `U` may not live long enough
--> $DIR/async-generics.rs:6:5
--> $DIR/async-generics.rs:5:5
|
LL | async fn foo(&self) -> &(T, U);
| ^^^^^^^^^^^^^-^^^^^^^^^^^^^^^^^

View File

@ -4,7 +4,7 @@ error[E0038]: the trait `Foo` cannot be made into an object
LL | let x: &dyn Foo = todo!();
| ^^^^^^^^ `Foo` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/object-safety.rs:5:14
|
LL | trait Foo {

View File

@ -4,7 +4,7 @@ error[E0038]: the trait `Foo` cannot be made into an object
LL | async fn foo(self: &dyn Foo) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Foo` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/inference_var_self_argument.rs:5:14
|
LL | trait Foo {

View File

@ -1,2 +1,5 @@
pub trait Trait0<T, U, V> {}
pub trait Trait1<T, U> {}
pub trait Trait2<T, U> {
type Assoc;
}

View File

@ -4,7 +4,7 @@ error[E0038]: the trait `NotObjectSafe` cannot be made into an object
LL | impl NotObjectSafe for dyn NotObjectSafe { }
| ^^^^^^^^^^^^^^^^^ `NotObjectSafe` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/coherence-impl-trait-for-trait-object-safe.rs:6:43
|
LL | trait NotObjectSafe { fn eq(&self, other: Self); }

View File

@ -1,7 +1,7 @@
//@ revisions: old next
//@[next] compile-flags: -Znext-solver
// A regression test for #105787
// A (partial) regression test for #105787
// Using the higher ranked projection hack to prevent us from replacing the projection
// with an inference variable.

View File

@ -0,0 +1,15 @@
warning[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`B`)
--> $DIR/orphan-check-alias.rs:21:6
|
LL | impl<T> foreign::Trait2<B, T> for <T as Id>::Assoc {
| ^ type parameter `T` must be covered by another type when it appears before the first local type (`B`)
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #124559 <https://github.com/rust-lang/rust/issues/124559>
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type
= note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait<T1, ..., Tn> for T0`, where `T0` is the first and `Tn` is the last
= note: `#[warn(uncovered_param_in_projection)]` on by default
warning: 1 warning emitted
For more information about this error, try `rustc --explain E0210`.

View File

@ -0,0 +1,15 @@
warning[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`B`)
--> $DIR/orphan-check-alias.rs:21:6
|
LL | impl<T> foreign::Trait2<B, T> for <T as Id>::Assoc {
| ^ type parameter `T` must be covered by another type when it appears before the first local type (`B`)
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #124559 <https://github.com/rust-lang/rust/issues/124559>
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type
= note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait<T1, ..., Tn> for T0`, where `T0` is the first and `Tn` is the last
= note: `#[warn(uncovered_param_in_projection)]` on by default
warning: 1 warning emitted
For more information about this error, try `rustc --explain E0210`.

View File

@ -0,0 +1,25 @@
// Alias might not cover type parameters.
//@ revisions: classic next
//@[next] compile-flags: -Znext-solver
//@ aux-crate:foreign=parametrized-trait.rs
//@ edition:2021
//@ known-bug: #99554
//@ check-pass
trait Id {
type Assoc;
}
impl<T> Id for T {
type Assoc = T;
}
pub struct B;
impl<T> foreign::Trait2<B, T> for <T as Id>::Assoc {
type Assoc = usize;
}
fn main() {}

View File

@ -4,7 +4,7 @@ error[E0038]: the trait `ConstParamTy_` cannot be made into an object
LL | fn foo(a: &dyn ConstParamTy_) {}
| ^^^^^^^^^^^^^^^^^ `ConstParamTy_` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/cmp.rs:LL:COL
|
= note: the trait cannot be made into an object because it uses `Self` as a type parameter
@ -19,7 +19,7 @@ error[E0038]: the trait `UnsizedConstParamTy` cannot be made into an object
LL | fn bar(a: &dyn UnsizedConstParamTy) {}
| ^^^^^^^^^^^^^^^^^^^^^^^ `UnsizedConstParamTy` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $SRC_DIR/core/src/cmp.rs:LL:COL
|
= note: the trait cannot be made into an object because it uses `Self` as a type parameter

View File

@ -98,7 +98,7 @@ error[E0038]: the trait `X` cannot be made into an object
LL | fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
| ^^^^^^^^^^^^^^^^^^^^ `X` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/issue-102768.rs:5:10
|
LL | trait X {

View File

@ -4,7 +4,7 @@ error[E0038]: the trait `Foo` cannot be made into an object
LL | fn use_dyn(v: &dyn Foo) {
| ^^^^^^^ `Foo` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/object-safety-err-ret.rs:8:8
|
LL | trait Foo {
@ -22,7 +22,7 @@ error[E0038]: the trait `Foo` cannot be made into an object
LL | v.test();
| ^^^^^^^^ `Foo` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/object-safety-err-ret.rs:8:8
|
LL | trait Foo {

View File

@ -4,7 +4,7 @@ error[E0038]: the trait `Foo` cannot be made into an object
LL | fn use_dyn(v: &dyn Foo) {
| ^^^^^^^ `Foo` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/object-safety-err-where-bounds.rs:8:8
|
LL | trait Foo {
@ -20,7 +20,7 @@ error[E0038]: the trait `Foo` cannot be made into an object
LL | v.test();
| ^^^^^^^^ `Foo` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/object-safety-err-where-bounds.rs:8:8
|
LL | trait Foo {

View File

@ -24,7 +24,7 @@ error[E0038]: the trait `Trait` cannot be made into an object
LL | trait Trait<const N: Trait = bar> {
| ^^^^^ `Trait` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/not_wf_param_in_rpitit.rs:11:14
|
LL | trait Trait<const N: Trait = bar> {
@ -47,7 +47,7 @@ error[E0038]: the trait `Trait` cannot be made into an object
LL | trait Trait<const N: Trait = bar> {
| ^^^^^^^^^^^^^^^^^^^^ `Trait` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/not_wf_param_in_rpitit.rs:11:14
|
LL | trait Trait<const N: Trait = bar> {
@ -78,7 +78,7 @@ error[E0038]: the trait `Trait` cannot be made into an object
LL | trait Trait<const N: Trait = bar> {
| ^^^^^^^^^^^^^^^^^^^^ `Trait` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/not_wf_param_in_rpitit.rs:11:14
|
LL | trait Trait<const N: Trait = bar> {

View File

@ -1,5 +1,5 @@
warning: constant evaluation is taking a long time
--> $DIR/ctfe-simple-loop.rs:9:5
--> $DIR/ctfe-simple-loop.rs:10:5
|
LL | / while index < n {
LL | |
@ -10,7 +10,7 @@ LL | | }
| |_____^ the const evaluator is currently interpreting this expression
|
help: the constant being evaluated
--> $DIR/ctfe-simple-loop.rs:19:1
--> $DIR/ctfe-simple-loop.rs:20:1
|
LL | const Y: u32 = simple_loop(35);
| ^^^^^^^^^^^^

View File

@ -1,9 +1,10 @@
//@ check-pass
//@ revisions: warn allow
//@ compile-flags: -Z tiny-const-eval-limit
#![cfg_attr(warn, warn(long_running_const_eval))]
#![cfg_attr(allow, allow(long_running_const_eval))]
//@ compile-flags: -Z tiny-const-eval-limit
const fn simple_loop(n: u32) -> u32 {
let mut index = 0;
while index < n {

View File

@ -1,29 +1,5 @@
warning: constant evaluation is taking a long time
--> $DIR/ctfe-simple-loop.rs:9:5
|
LL | / while index < n {
LL | |
LL | |
LL | |
LL | | index = index + 1;
LL | | }
| |_____^
|
= note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
If your compilation actually takes a long time, you can safely allow the lint.
help: the constant being evaluated
--> $DIR/ctfe-simple-loop.rs:18:1
|
LL | const X: u32 = simple_loop(19);
| ^^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/ctfe-simple-loop.rs:3:24
|
LL | #![cfg_attr(warn, warn(long_running_const_eval))]
| ^^^^^^^^^^^^^^^^^^^^^^^
warning: constant evaluation is taking a long time
--> $DIR/ctfe-simple-loop.rs:9:5
--> $DIR/ctfe-simple-loop.rs:10:5
|
LL | / while index < n {
LL | |
@ -38,11 +14,35 @@ LL | | }
help: the constant being evaluated
--> $DIR/ctfe-simple-loop.rs:19:1
|
LL | const X: u32 = simple_loop(19);
| ^^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/ctfe-simple-loop.rs:5:24
|
LL | #![cfg_attr(warn, warn(long_running_const_eval))]
| ^^^^^^^^^^^^^^^^^^^^^^^
warning: constant evaluation is taking a long time
--> $DIR/ctfe-simple-loop.rs:10:5
|
LL | / while index < n {
LL | |
LL | |
LL | |
LL | | index = index + 1;
LL | | }
| |_____^
|
= note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
If your compilation actually takes a long time, you can safely allow the lint.
help: the constant being evaluated
--> $DIR/ctfe-simple-loop.rs:20:1
|
LL | const Y: u32 = simple_loop(35);
| ^^^^^^^^^^^^
warning: constant evaluation is taking a long time
--> $DIR/ctfe-simple-loop.rs:9:5
--> $DIR/ctfe-simple-loop.rs:10:5
|
LL | / while index < n {
LL | |
@ -53,7 +53,7 @@ LL | | }
| |_____^ the const evaluator is currently interpreting this expression
|
help: the constant being evaluated
--> $DIR/ctfe-simple-loop.rs:19:1
--> $DIR/ctfe-simple-loop.rs:20:1
|
LL | const Y: u32 = simple_loop(35);
| ^^^^^^^^^^^^

View File

@ -1,8 +1,8 @@
//@ check-pass
//@ compile-flags: -Z tiny-const-eval-limit -Z deduplicate-diagnostics=yes
#![allow(long_running_const_eval)]
//@ compile-flags: -Z tiny-const-eval-limit -Z deduplicate-diagnostics=yes
const FOO: () = {
let mut i = 0;
loop {

View File

@ -11,7 +11,7 @@ const REF_INTERIOR_MUT: &usize = {
//~| ERROR the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time
//~| ERROR the size for values of type `(dyn Sync + 'static)` cannot be known at compilation time
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
//~| HELP if this is an object-safe trait, use `dyn`
//~| HELP if this is a dyn-compatible trait, use `dyn`
//~| HELP the trait `Sized` is not implemented for `(dyn Sync + 'static)`
//~| HELP the trait `Sized` is not implemented for `(dyn Sync + 'static)`
unsafe { &*(&FOO as *const _ as *const usize) }

View File

@ -18,7 +18,7 @@ LL | static FOO: Sync = AtomicUsize::new(0);
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `#[warn(bare_trait_objects)]` on by default
help: if this is an object-safe trait, use `dyn`
help: if this is a dyn-compatible trait, use `dyn`
|
LL | static FOO: dyn Sync = AtomicUsize::new(0);
| +++

View File

@ -182,7 +182,7 @@ LL | type H = Fn(u8) -> (u8)::Output;
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `#[warn(bare_trait_objects)]` on by default
help: if this is an object-safe trait, use `dyn`
help: if this is a dyn-compatible trait, use `dyn`
|
LL | type H = <dyn Fn(u8) -> (u8)>::Output;
| ++++ +

View File

@ -27,7 +27,7 @@ LL | let _: &Copy + 'static;
| ^^^^^ `Copy` cannot be made into an object
|
= note: the trait cannot be made into an object because it requires `Self: Sized`
= note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
= 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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
error: aborting due to 3 previous errors

View File

@ -11,7 +11,7 @@ note: the lint level is defined here
|
LL | #[deny(bare_trait_objects)]
| ^^^^^^^^^^^^^^^^^^
help: if this is an object-safe trait, use `dyn`
help: if this is a dyn-compatible trait, use `dyn`
|
LL | fn function(x: &dyn SomeTrait, y: Box<SomeTrait>) {
| +++
@ -24,7 +24,7 @@ LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) {
|
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: if this is an object-safe trait, use `dyn`
help: if this is a dyn-compatible trait, use `dyn`
|
LL | fn function(x: &SomeTrait, y: Box<dyn SomeTrait>) {
| +++
@ -37,7 +37,7 @@ LL | let _x: &SomeTrait = todo!();
|
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: if this is an object-safe trait, use `dyn`
help: if this is a dyn-compatible trait, use `dyn`
|
LL | let _x: &dyn SomeTrait = todo!();
| +++

View File

@ -11,7 +11,7 @@ note: the lint level is defined here
|
LL | #![deny(bare_trait_objects)]
| ^^^^^^^^^^^^^^^^^^
help: if this is an object-safe trait, use `dyn`
help: if this is a dyn-compatible trait, use `dyn`
|
LL | <dyn fmt::Debug>::fmt(self, f)
| +++

View File

@ -4,7 +4,7 @@ error[E0038]: the trait `Trait` cannot be made into an object
LL | fn call_foo(x: Box<dyn Trait>) {
| ^^^^^^^^^ `Trait` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/E0038.rs:2:22
|
LL | trait Trait {
@ -19,7 +19,7 @@ error[E0038]: the trait `Trait` cannot be made into an object
LL | let y = x.foo();
| ^^^^^^^ `Trait` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/E0038.rs:2:22
|
LL | trait Trait {

View File

@ -7,7 +7,7 @@ LL | let _ = MyIterator::next;
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `#[warn(bare_trait_objects)]` on by default
help: if this is an object-safe trait, use `dyn`
help: if this is a dyn-compatible trait, use `dyn`
|
LL | let _ = <dyn MyIterator>::next;
| ++++ +

View File

@ -7,7 +7,7 @@ LL | fn ptr(self: Ptr<Self>);
LL | Ptr(Box::new(4)) as Ptr<dyn Trait>;
| ^^^^^^^^^^^^^^ `Trait` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/feature-gate-dispatch-from-dyn-missing-impl.rs:25:18
|
LL | trait Trait {
@ -25,7 +25,7 @@ LL | fn ptr(self: Ptr<Self>);
LL | Ptr(Box::new(4)) as Ptr<dyn Trait>;
| ^^^^^^^^^^^^^^^^ `Trait` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/feature-gate-dispatch-from-dyn-missing-impl.rs:25:18
|
LL | trait Trait {

View File

@ -4,7 +4,7 @@ error[E0038]: the trait `NonObjectSafe1` cannot be made into an object
LL | fn takes_non_object_safe_ref<T>(obj: &dyn NonObjectSafe1) {
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe1` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/feature-gate-object_safe_for_dispatch.rs:4:23
|
LL | trait NonObjectSafe1: Sized {}
@ -18,7 +18,7 @@ error[E0038]: the trait `NonObjectSafe2` cannot be made into an object
LL | fn return_non_object_safe_ref() -> &'static dyn NonObjectSafe2 {
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe2` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/feature-gate-object_safe_for_dispatch.rs:7:8
|
LL | trait NonObjectSafe2 {
@ -40,7 +40,7 @@ error[E0038]: the trait `NonObjectSafe3` cannot be made into an object
LL | fn takes_non_object_safe_box(obj: Box<dyn NonObjectSafe3>) {
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe3` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/feature-gate-object_safe_for_dispatch.rs:11:8
|
LL | trait NonObjectSafe3 {
@ -55,7 +55,7 @@ error[E0038]: the trait `NonObjectSafe4` cannot be made into an object
LL | fn return_non_object_safe_rc() -> std::rc::Rc<dyn NonObjectSafe4> {
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe4` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/feature-gate-object_safe_for_dispatch.rs:15:22
|
LL | trait NonObjectSafe4 {
@ -70,7 +70,7 @@ error[E0038]: the trait `NonObjectSafe1` cannot be made into an object
LL | impl Trait for dyn NonObjectSafe1 {}
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe1` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/feature-gate-object_safe_for_dispatch.rs:4:23
|
LL | trait NonObjectSafe1: Sized {}

View File

@ -1,5 +1,5 @@
//@ check-fail
//@ known-bug: unknown
//@ known-bug: #100013
//@ edition: 2021
// We really should accept this, but we need implied bounds between the regions

View File

@ -1,5 +1,5 @@
//@ check-fail
//@ known-bug: #87735, #88526
//@ known-bug: unknown
// This should pass, but we need an extension of implied bounds (probably).

View File

@ -1,5 +1,5 @@
//@ check-fail
//@ known-bug: unknown
//@ known-bug: #91762
// We almost certainly want this to pass, but
// it's particularly difficult currently, because we need a way of specifying

View File

@ -42,7 +42,7 @@ error[E0038]: the trait `X` cannot be made into an object
LL | fn _f(arg : Box<dyn for<'a> X<Y<'x> = &'a [u32]>>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `X` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/gat-in-trait-path-undeclared-lifetime.rs:2:8
|
LL | trait X {

View File

@ -4,7 +4,7 @@ error[E0038]: the trait `Foo` cannot be made into an object
LL | fn f(_arg : Box<dyn for<'a> Foo<A<'a> = &'a ()>>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Foo` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/gat-in-trait-path.rs:10:10
|
LL | trait Foo {
@ -22,7 +22,7 @@ error[E0038]: the trait `Foo` cannot be made into an object
LL | f(Box::new(foo));
| ^^^^^^^^^^^^^ `Foo` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/gat-in-trait-path.rs:10:10
|
LL | trait Foo {
@ -40,7 +40,7 @@ error[E0038]: the trait `Foo` cannot be made into an object
LL | f(Box::new(foo));
| ^^^^^^^^^^^^^ `Foo` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
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 <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/gat-in-trait-path.rs:10:10
|
LL | trait Foo {

Some files were not shown because too many files have changed in this diff Show More