1
Fork 0

Make rustc_deny_explicit_impl only local as well

This commit is contained in:
Michael Goulet 2023-06-13 22:31:25 +00:00
parent 657d3f43a9
commit 91e5c3f2e5
4 changed files with 8 additions and 4 deletions

View file

@ -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_allow_incoherent_impl] has to be added to all impl items of an incoherent inherent impl."
), ),
rustc_attr!( 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_deny_explicit_impl] enforces that a trait can have no user-provided impls"
), ),
rustc_attr!( rustc_attr!(

View file

@ -10,7 +10,6 @@ use rustc_errors::{error_code, struct_span_err};
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt}; use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
use rustc_span::sym;
use rustc_trait_selection::traits; use rustc_trait_selection::traits;
mod builtin; mod builtin;
@ -44,7 +43,7 @@ fn enforce_trait_manually_implementable(
let impl_header_span = tcx.def_span(impl_def_id); let impl_header_span = tcx.def_span(impl_def_id);
// Disallow *all* explicit impls of traits marked `#[rustc_deny_explicit_impl]` // 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 trait_name = tcx.item_name(trait_def_id);
let mut err = struct_span_err!( let mut err = struct_span_err!(
tcx.sess, tcx.sess,

View file

@ -986,6 +986,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
no_dups.then_some(list) no_dups.then_some(list)
}); });
let do_not_implement_via_object = tcx.has_attr(def_id, sym::rustc_do_not_implement_via_object); 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 { ty::TraitDef {
def_id: def_id.to_def_id(), 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, skip_array_during_method_dispatch,
specialization_kind, specialization_kind,
must_implement_one_of, must_implement_one_of,
do_not_implement_via_object, implement_via_object,
deny_explicit_impl,
} }
} }

View file

@ -57,6 +57,9 @@ pub struct TraitDef {
/// denied. This only applies to built-in trait, and is marked via /// denied. This only applies to built-in trait, and is marked via
/// `#[rustc_do_not_implement_via_object]`. /// `#[rustc_do_not_implement_via_object]`.
pub do_not_implement_via_object: bool, 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 /// Whether this trait is treated specially by the standard library