diff options
| author | Michael Goulet <michael@errs.io> | 2023-06-13 22:31:25 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2023-06-20 04:38:46 +0000 |
| commit | 91e5c3f2e5d0a20ffc9b2e80ea049e77d5721da0 (patch) | |
| tree | 87b9e516ddd5caf9ef411647c97b9855ea13a40e | |
| parent | 657d3f43a9802a3e119c1acf6467ddc0eb41e0be (diff) | |
| download | rust-91e5c3f2e5d0a20ffc9b2e80ea049e77d5721da0.tar.gz rust-91e5c3f2e5d0a20ffc9b2e80ea049e77d5721da0.zip | |
Make rustc_deny_explicit_impl only local as well
| -rw-r--r-- | compiler/rustc_feature/src/builtin_attrs.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/coherence/mod.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/collect.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/trait_def.rs | 3 |
4 files changed, 8 insertions, 4 deletions
diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 566f856258a..0e7deef0cff 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -705,7 +705,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ "#[rustc_allow_incoherent_impl] has to be added to all impl items of an incoherent inherent impl." ), rustc_attr!( - rustc_deny_explicit_impl, AttributeType::Normal, template!(Word), ErrorFollowing, @only_local: false, + rustc_deny_explicit_impl, AttributeType::Normal, template!(Word), ErrorFollowing, @only_local: true, "#[rustc_deny_explicit_impl] enforces that a trait can have no user-provided impls" ), rustc_attr!( diff --git a/compiler/rustc_hir_analysis/src/coherence/mod.rs b/compiler/rustc_hir_analysis/src/coherence/mod.rs index 4524b87a418..5097f43607e 100644 --- a/compiler/rustc_hir_analysis/src/coherence/mod.rs +++ b/compiler/rustc_hir_analysis/src/coherence/mod.rs @@ -10,7 +10,6 @@ use rustc_errors::{error_code, struct_span_err}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::query::Providers; use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt}; -use rustc_span::sym; use rustc_trait_selection::traits; mod builtin; @@ -44,7 +43,7 @@ fn enforce_trait_manually_implementable( let impl_header_span = tcx.def_span(impl_def_id); // Disallow *all* explicit impls of traits marked `#[rustc_deny_explicit_impl]` - if tcx.has_attr(trait_def_id, sym::rustc_deny_explicit_impl) { + if tcx.trait_def(trait_def_id).deny_explicit_impl { let trait_name = tcx.item_name(trait_def_id); let mut err = struct_span_err!( tcx.sess, diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 96cbe975f36..17a180a7eb2 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -986,6 +986,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef { no_dups.then_some(list) }); let do_not_implement_via_object = tcx.has_attr(def_id, sym::rustc_do_not_implement_via_object); + let deny_explicit_impl = tcx.has_attr(def_id, sym::rustc_deny_explicit_impl); ty::TraitDef { def_id: def_id.to_def_id(), @@ -997,7 +998,8 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef { skip_array_during_method_dispatch, specialization_kind, must_implement_one_of, - do_not_implement_via_object, + implement_via_object, + deny_explicit_impl, } } diff --git a/compiler/rustc_middle/src/ty/trait_def.rs b/compiler/rustc_middle/src/ty/trait_def.rs index 14352307094..325e156fba5 100644 --- a/compiler/rustc_middle/src/ty/trait_def.rs +++ b/compiler/rustc_middle/src/ty/trait_def.rs @@ -57,6 +57,9 @@ pub struct TraitDef { /// denied. This only applies to built-in trait, and is marked via /// `#[rustc_do_not_implement_via_object]`. pub do_not_implement_via_object: bool, + + /// Whether a trait is fully built-in, and any implementation is disallowed. + pub deny_explicit_impl: bool, } /// Whether this trait is treated specially by the standard library |
