Skip to content

Commit 91e5c3f

Browse files
Make rustc_deny_explicit_impl only local as well
1 parent 657d3f4 commit 91e5c3f

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
705705
"#[rustc_allow_incoherent_impl] has to be added to all impl items of an incoherent inherent impl."
706706
),
707707
rustc_attr!(
708-
rustc_deny_explicit_impl, AttributeType::Normal, template!(Word), ErrorFollowing, @only_local: false,
708+
rustc_deny_explicit_impl, AttributeType::Normal, template!(Word), ErrorFollowing, @only_local: true,
709709
"#[rustc_deny_explicit_impl] enforces that a trait can have no user-provided impls"
710710
),
711711
rustc_attr!(

compiler/rustc_hir_analysis/src/coherence/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc_errors::{error_code, struct_span_err};
1010
use rustc_hir::def_id::{DefId, LocalDefId};
1111
use rustc_middle::query::Providers;
1212
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
13-
use rustc_span::sym;
1413
use rustc_trait_selection::traits;
1514

1615
mod builtin;
@@ -44,7 +43,7 @@ fn enforce_trait_manually_implementable(
4443
let impl_header_span = tcx.def_span(impl_def_id);
4544

4645
// Disallow *all* explicit impls of traits marked `#[rustc_deny_explicit_impl]`
47-
if tcx.has_attr(trait_def_id, sym::rustc_deny_explicit_impl) {
46+
if tcx.trait_def(trait_def_id).deny_explicit_impl {
4847
let trait_name = tcx.item_name(trait_def_id);
4948
let mut err = struct_span_err!(
5049
tcx.sess,

compiler/rustc_hir_analysis/src/collect.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
986986
no_dups.then_some(list)
987987
});
988988
let do_not_implement_via_object = tcx.has_attr(def_id, sym::rustc_do_not_implement_via_object);
989+
let deny_explicit_impl = tcx.has_attr(def_id, sym::rustc_deny_explicit_impl);
989990

990991
ty::TraitDef {
991992
def_id: def_id.to_def_id(),
@@ -997,7 +998,8 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
997998
skip_array_during_method_dispatch,
998999
specialization_kind,
9991000
must_implement_one_of,
1000-
do_not_implement_via_object,
1001+
implement_via_object,
1002+
deny_explicit_impl,
10011003
}
10021004
}
10031005

compiler/rustc_middle/src/ty/trait_def.rs

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ pub struct TraitDef {
5757
/// denied. This only applies to built-in trait, and is marked via
5858
/// `#[rustc_do_not_implement_via_object]`.
5959
pub do_not_implement_via_object: bool,
60+
61+
/// Whether a trait is fully built-in, and any implementation is disallowed.
62+
pub deny_explicit_impl: bool,
6063
}
6164

6265
/// Whether this trait is treated specially by the standard library

0 commit comments

Comments
 (0)