Skip to content

Commit 30f0108

Browse files
Add fundamental to trait def
1 parent 959a2eb commit 30f0108

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

compiler/rustc_hir_analysis/src/collect.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
12011201

12021202
let is_marker = tcx.has_attr(def_id, sym::marker);
12031203
let rustc_coinductive = tcx.has_attr(def_id, sym::rustc_coinductive);
1204+
let is_fundamental = tcx.has_attr(def_id, sym::fundamental);
12041205

12051206
// FIXME: We could probably do way better attribute validation here.
12061207
let mut skip_array_during_method_dispatch = false;
@@ -1352,6 +1353,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
13521353
has_auto_impl: is_auto,
13531354
is_marker,
13541355
is_coinductive: rustc_coinductive || is_auto,
1356+
is_fundamental,
13551357
skip_array_during_method_dispatch,
13561358
skip_boxed_slice_during_method_dispatch,
13571359
specialization_kind,

compiler/rustc_middle/src/ty/trait_def.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct TraitDef {
3131
/// and thus `impl`s of it are allowed to overlap.
3232
pub is_marker: bool,
3333

34-
/// If `true`, then this trait has to `#[rustc_coinductive]` attribute or
34+
/// If `true`, then this trait has the `#[rustc_coinductive]` attribute or
3535
/// is an auto trait. This indicates that trait solver cycles involving an
3636
/// `X: ThisTrait` goal are accepted.
3737
///
@@ -40,6 +40,11 @@ pub struct TraitDef {
4040
/// also have already switched to the new trait solver.
4141
pub is_coinductive: bool,
4242

43+
/// If `true`, then this trait has the `#[fundamental]` attribute. This
44+
/// affects how conherence computes whether a trait may have trait implementations
45+
/// added in the future.
46+
pub is_fundamental: bool,
47+
4348
/// If `true`, then this trait has the `#[rustc_skip_during_method_dispatch(array)]`
4449
/// attribute, indicating that editions before 2021 should not consider this trait
4550
/// during method dispatch if the receiver is an array.

compiler/rustc_trait_selection/src/traits/coherence.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ pub fn trait_ref_is_local_or_fundamental<'tcx>(
666666
tcx: TyCtxt<'tcx>,
667667
trait_ref: ty::TraitRef<'tcx>,
668668
) -> bool {
669-
trait_ref.def_id.is_local() || tcx.has_attr(trait_ref.def_id, sym::fundamental)
669+
trait_ref.def_id.is_local() || tcx.trait_def(trait_ref.def_id).is_fundamental
670670
}
671671

672672
#[derive(Debug, Copy, Clone)]

0 commit comments

Comments
 (0)