Skip to content

Commit 83e4e18

Browse files
committed
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
2 parents fa724e5 + 243c6d6 commit 83e4e18

File tree

211 files changed

+727
-547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+727
-547
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Session.vim
2525
.favorites.json
2626
.settings/
2727
.vs/
28+
.dir-locals.el
2829

2930
## Tool
3031
.valgrindrc

compiler/rustc_const_eval/src/interpret/call.rs

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

compiler/rustc_error_codes/src/error_codes/E0038.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ trait, written in type positions) but this was a bit too confusing, so we now
55
write `dyn Trait`.
66

77
Some traits are not allowed to be used as trait object types. The traits that
8-
are allowed to be used as trait object types are called "object-safe" traits.
9-
Attempting to use a trait object type for a trait that is not object-safe will
10-
trigger error E0038.
8+
are allowed to be used as trait object types are called "dyn-compatible"[^1]
9+
traits. Attempting to use a trait object type for a trait that is not
10+
dyn-compatible will trigger error E0038.
1111

1212
Two general aspects of trait object types give rise to the restrictions:
1313

@@ -25,13 +25,16 @@ Two general aspects of trait object types give rise to the restrictions:
2525
objects with the same trait object type may point to vtables from different
2626
implementations.
2727

28-
The specific conditions that violate object-safety follow, most of which relate
29-
to missing size information and vtable polymorphism arising from these aspects.
28+
The specific conditions that violate dyn-compatibility follow, most of which
29+
relate to missing size information and vtable polymorphism arising from these
30+
aspects.
31+
32+
[^1]: Formerly known as "object-safe".
3033

3134
### The trait requires `Self: Sized`
3235

3336
Traits that are declared as `Trait: Sized` or which otherwise inherit a
34-
constraint of `Self:Sized` are not object-safe.
37+
constraint of `Self:Sized` are not dyn-compatible.
3538

3639
The reasoning behind this is somewhat subtle. It derives from the fact that Rust
3740
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
5861
to the rule that `dyn Trait` always implements `Trait`, Rust chooses to prohibit
5962
such a `dyn Trait` from existing at all.
6063

61-
Only unsized traits are considered object-safe.
64+
Only unsized traits are considered dyn-compatible.
6265

6366
Generally, `Self: Sized` is used to indicate that the trait should not be used
6467
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>) {
103106
}
104107
```
105108

106-
If only some methods aren't object-safe, you can add a `where Self: Sized` bound
107-
on them to mark them as explicitly unavailable to trait objects. The
109+
If only some methods aren't dyn-compatible, you can add a `where Self: Sized`
110+
bound on them to mark them as explicitly unavailable to trait objects. The
108111
functionality will still be available to all other implementers, including
109112
`Box<dyn Trait>` which is itself sized (assuming you `impl Trait for Box<dyn
110113
Trait>`).
@@ -117,7 +120,7 @@ trait Trait {
117120
```
118121

119122
Now, `foo()` can no longer be called on a trait object, but you will now be
120-
allowed to make a trait object, and that will be able to call any object-safe
123+
allowed to make a trait object, and that will be able to call any dyn-compatible
121124
methods. With such a bound, one can still call `foo()` on types implementing
122125
that trait that aren't behind trait objects.
123126

@@ -306,18 +309,18 @@ Here, the supertrait might have methods as follows:
306309

307310
```
308311
trait Super<A: ?Sized> {
309-
fn get_a(&self) -> &A; // note that this is object safe!
312+
fn get_a(&self) -> &A; // note that this is dyn-compatible!
310313
}
311314
```
312315

313316
If the trait `Trait` was deriving from something like `Super<String>` or
314317
`Super<T>` (where `Foo` itself is `Foo<T>`), this is okay, because given a type
315318
`get_a()` will definitely return an object of that type.
316319

317-
However, if it derives from `Super<Self>`, even though `Super` is object safe,
318-
the method `get_a()` would return an object of unknown type when called on the
319-
function. `Self` type parameters let us make object safe traits no longer safe,
320-
so they are forbidden when specifying supertraits.
320+
However, if it derives from `Super<Self>`, even though `Super` is
321+
dyn-compatible, the method `get_a()` would return an object of unknown type when
322+
called on the function. `Self` type parameters let us make dyn-compatible traits
323+
no longer compatible, so they are forbidden when specifying supertraits.
321324

322325
There's no easy fix for this. Generally, code will need to be refactored so that
323326
you no longer need to derive from `Super<Self>`.

compiler/rustc_error_codes/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ E0800: 0800,
623623
// E0314, // closure outlives stack frame
624624
// E0315, // cannot invoke closure outside of its lifetime
625625
// E0319, // trait impls for defaulted traits allowed just for structs/enums
626-
// E0372, // coherence not object safe
626+
// E0372, // coherence not dyn-compatible
627627
// E0385, // {} in an aliasable location
628628
// E0402, // cannot use an outer type parameter in this context
629629
// E0406, // merged into 420

compiler/rustc_feature/src/unstable.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,12 @@ declare_features! (
546546
(unstable, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554)),
547547
/// Allows `for<T>` binders in where-clauses
548548
(incomplete, non_lifetime_binders, "1.69.0", Some(108185)),
549-
/// Allows making `dyn Trait` well-formed even if `Trait` is not object safe.
549+
/// Allows making `dyn Trait` well-formed even if `Trait` is not dyn-compatible[^1].
550550
/// In that case, `dyn Trait: Trait` does not hold. Moreover, coercions and
551551
/// casts in safe Rust to `dyn Trait` for such a `Trait` is also forbidden.
552+
///
553+
/// [^1]: Formerly known as "object safe".
554+
// FIXME(dyn_compat_renaming): Rename feature.
552555
(unstable, object_safe_for_dispatch, "1.40.0", Some(43561)),
553556
/// Allows using enums in offset_of!
554557
(unstable, offset_of_enum, "1.75.0", Some(120141)),

compiler/rustc_hir_analysis/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ hir_analysis_unrecognized_intrinsic_function =
558558
.help = if you're adding an intrinsic, be sure to update `check_intrinsic_type`
559559
560560
hir_analysis_unused_associated_type_bounds =
561-
unnecessary associated type bound for not object safe associated type
561+
unnecessary associated type bound for dyn-incompatible associated type
562562
.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`
563563
.suggestion = remove this bound
564564

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ fn check_trait_item<'tcx>(
374374
hir::TraitItemKind::Type(_bounds, Some(ty)) => (None, ty.span),
375375
_ => (None, trait_item.span),
376376
};
377-
check_object_unsafe_self_trait_by_name(tcx, trait_item);
377+
check_dyn_incompatible_self_trait_by_name(tcx, trait_item);
378378
let mut res = check_associated_item(tcx, def_id, span, method_sig);
379379

380380
if matches!(trait_item.kind, hir::TraitItemKind::Fn(..)) {
@@ -838,9 +838,10 @@ fn could_be_self(trait_def_id: LocalDefId, ty: &hir::Ty<'_>) -> bool {
838838
}
839839
}
840840

841-
/// Detect when an object unsafe trait is referring to itself in one of its associated items.
842-
/// When this is done, suggest using `Self` instead.
843-
fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) {
841+
/// Detect when a dyn-incompatible trait is referring to itself in one of its associated items.
842+
///
843+
/// In such cases, suggest using `Self` instead.
844+
fn check_dyn_incompatible_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) {
844845
let (trait_name, trait_def_id) =
845846
match tcx.hir_node_by_def_id(tcx.hir().get_parent_item(item.hir_id()).def_id) {
846847
hir::Node::Item(item) => match item.kind {
@@ -872,7 +873,7 @@ fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem
872873
_ => {}
873874
}
874875
if !trait_should_be_self.is_empty() {
875-
if tcx.is_object_safe(trait_def_id) {
876+
if tcx.is_dyn_compatible(trait_def_id) {
876877
return;
877878
}
878879
let sugg = trait_should_be_self.iter().map(|span| (*span, "Self".to_string())).collect();

compiler/rustc_hir_analysis/src/coherence/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ fn check_object_overlap<'tcx>(
183183

184184
// check for overlap with the automatic `impl Trait for dyn Trait`
185185
if let ty::Dynamic(data, ..) = trait_ref.self_ty().kind() {
186-
// This is something like impl Trait1 for Trait2. Illegal
187-
// if Trait1 is a supertrait of Trait2 or Trait2 is not object safe.
186+
// This is something like `impl Trait1 for Trait2`. Illegal if
187+
// Trait1 is a supertrait of Trait2 or Trait2 is not dyn-compatible.
188188

189189
let component_def_ids = data.iter().flat_map(|predicate| {
190190
match predicate.skip_binder() {
@@ -197,7 +197,8 @@ fn check_object_overlap<'tcx>(
197197
});
198198

199199
for component_def_id in component_def_ids {
200-
if !tcx.is_object_safe(component_def_id) {
200+
if !tcx.is_dyn_compatible(component_def_id) {
201+
// FIXME(dyn_compat_renaming): Rename test and update comment.
201202
// Without the 'object_safe_for_dispatch' feature this is an error
202203
// which will be reported by wfcheck. Ignore it here.
203204
// This is tested by `coherence-impl-trait-for-trait-object-safe.rs`.

compiler/rustc_hir_analysis/src/coherence/orphan.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,16 @@ pub(crate) fn orphan_check_impl(
109109
//
110110
// auto trait AutoTrait {}
111111
//
112-
// trait ObjectSafeTrait {
112+
// trait DynCompatibleTrait {
113113
// fn f(&self) where Self: AutoTrait;
114114
// }
115115
//
116-
// We can allow f to be called on `dyn ObjectSafeTrait + AutoTrait`.
116+
// We can allow f to be called on `dyn DynCompatibleTrait + AutoTrait`.
117117
//
118118
// If we didn't deny `impl AutoTrait for dyn Trait`, it would be unsound
119-
// for the ObjectSafeTrait shown above to be object safe because someone
120-
// could take some type implementing ObjectSafeTrait but not AutoTrait,
121-
// unsize it to `dyn ObjectSafeTrait`, and call .f() which has no
119+
// for the `DynCompatibleTrait` shown above to be dyn-compatible because someone
120+
// could take some type implementing `DynCompatibleTrait` but not `AutoTrait`,
121+
// unsize it to `dyn DynCompatibleTrait`, and call `.f()` which has no
122122
// concrete implementation (issue #50781).
123123
enum LocalImpl {
124124
Allow,

compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs renamed to compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use rustc_middle::ty::{
1111
self, DynKind, ExistentialPredicateStableCmpExt as _, Ty, TyCtxt, TypeFoldable, Upcast,
1212
};
1313
use rustc_span::{ErrorGuaranteed, Span};
14-
use rustc_trait_selection::error_reporting::traits::report_object_safety_error;
15-
use rustc_trait_selection::traits::{self, hir_ty_lowering_object_safety_violations};
14+
use rustc_trait_selection::error_reporting::traits::report_dyn_incompatibility;
15+
use rustc_trait_selection::traits::{self, hir_ty_lowering_dyn_compatibility_violations};
1616
use smallvec::{SmallVec, smallvec};
1717
use tracing::{debug, instrument};
1818

@@ -99,19 +99,19 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
9999
return Ty::new_error(tcx, reported);
100100
}
101101

102-
// Check that there are no gross object safety violations;
102+
// Check that there are no gross dyn-compatibility violations;
103103
// most importantly, that the supertraits don't contain `Self`,
104104
// to avoid ICEs.
105105
for item in &regular_traits {
106-
let object_safety_violations =
107-
hir_ty_lowering_object_safety_violations(tcx, item.trait_ref().def_id());
108-
if !object_safety_violations.is_empty() {
109-
let reported = report_object_safety_error(
106+
let violations =
107+
hir_ty_lowering_dyn_compatibility_violations(tcx, item.trait_ref().def_id());
108+
if !violations.is_empty() {
109+
let reported = report_dyn_incompatibility(
110110
tcx,
111111
span,
112112
Some(hir_id),
113113
item.trait_ref().def_id(),
114-
&object_safety_violations,
114+
&violations,
115115
)
116116
.emit();
117117
return Ty::new_error(tcx, reported);
@@ -275,8 +275,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
275275
tcx.item_name(def_id),
276276
)
277277
.with_note(
278-
rustc_middle::traits::ObjectSafetyViolation::SupertraitSelf(smallvec![])
279-
.error_msg(),
278+
rustc_middle::traits::DynCompatibilityViolation::SupertraitSelf(
279+
smallvec![],
280+
)
281+
.error_msg(),
280282
)
281283
.emit();
282284
}

0 commit comments

Comments
 (0)