Skip to content

Commit bf6bb78

Browse files
committed
Add #[rustc_no_implicit_autorefs] and apply it to std methods
1 parent af4a5a1 commit bf6bb78

File tree

7 files changed

+20
-0
lines changed

7 files changed

+20
-0
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
809809
EncodeCrossCrate::Yes,
810810
"#[rustc_never_returns_null_ptr] is used to mark functions returning non-null pointers."
811811
),
812+
rustc_attr!(
813+
rustc_no_implicit_autorefs, AttributeType::Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes,
814+
"#[rustc_no_implicit_autorefs] is used to mark functions that should not autorefs in raw pointers context."
815+
),
812816
rustc_attr!(
813817
rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
814818
"#![rustc_coherence_is_core] allows inherent methods on builtin types, only intended to be used in `core`."

compiler/rustc_passes/src/check_attr.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
156156
sym::rustc_never_returns_null_ptr => {
157157
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
158158
}
159+
sym::rustc_no_implicit_autorefs => {
160+
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
161+
}
159162
sym::rustc_legacy_const_generics => {
160163
self.check_rustc_legacy_const_generics(hir_id, attr, span, target, item)
161164
}

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,7 @@ symbols! {
15821582
rustc_must_implement_one_of,
15831583
rustc_never_returns_null_ptr,
15841584
rustc_never_type_options,
1585+
rustc_no_implicit_autorefs,
15851586
rustc_no_mir_inline,
15861587
rustc_nonnull_optimization_guaranteed,
15871588
rustc_nounwind,

library/alloc/src/string.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,7 @@ impl String {
17551755
#[must_use]
17561756
#[stable(feature = "rust1", since = "1.0.0")]
17571757
#[rustc_confusables("length", "size")]
1758+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
17581759
pub fn len(&self) -> usize {
17591760
self.vec.len()
17601761
}
@@ -1773,6 +1774,7 @@ impl String {
17731774
#[inline]
17741775
#[must_use]
17751776
#[stable(feature = "rust1", since = "1.0.0")]
1777+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
17761778
pub fn is_empty(&self) -> bool {
17771779
self.len() == 0
17781780
}

library/core/src/ops/index.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub trait Index<Idx: ?Sized> {
6767
///
6868
/// May panic if the index is out of bounds.
6969
#[stable(feature = "rust1", since = "1.0.0")]
70+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
7071
#[track_caller]
7172
fn index(&self, index: Idx) -> &Self::Output;
7273
}
@@ -171,6 +172,7 @@ pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
171172
///
172173
/// May panic if the index is out of bounds.
173174
#[stable(feature = "rust1", since = "1.0.0")]
175+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
174176
#[track_caller]
175177
fn index_mut(&mut self, index: Idx) -> &mut Self::Output;
176178
}

library/core/src/slice/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ impl<T> [T] {
133133
#[stable(feature = "rust1", since = "1.0.0")]
134134
#[rustc_const_stable(feature = "const_slice_len", since = "1.39.0")]
135135
#[rustc_allow_const_fn_unstable(ptr_metadata)]
136+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
136137
#[inline]
137138
#[must_use]
138139
pub const fn len(&self) -> usize {
@@ -152,6 +153,7 @@ impl<T> [T] {
152153
/// ```
153154
#[stable(feature = "rust1", since = "1.0.0")]
154155
#[rustc_const_stable(feature = "const_slice_is_empty", since = "1.39.0")]
156+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
155157
#[inline]
156158
#[must_use]
157159
pub const fn is_empty(&self) -> bool {
@@ -612,6 +614,7 @@ impl<T> [T] {
612614
/// assert_eq!(None, v.get(0..4));
613615
/// ```
614616
#[stable(feature = "rust1", since = "1.0.0")]
617+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
615618
#[inline]
616619
#[must_use]
617620
pub fn get<I>(&self, index: I) -> Option<&I::Output>
@@ -637,6 +640,7 @@ impl<T> [T] {
637640
/// assert_eq!(x, &[0, 42, 2]);
638641
/// ```
639642
#[stable(feature = "rust1", since = "1.0.0")]
643+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
640644
#[inline]
641645
#[must_use]
642646
pub fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
@@ -674,6 +678,7 @@ impl<T> [T] {
674678
/// }
675679
/// ```
676680
#[stable(feature = "rust1", since = "1.0.0")]
681+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
677682
#[inline]
678683
#[must_use]
679684
pub unsafe fn get_unchecked<I>(&self, index: I) -> &I::Output
@@ -716,6 +721,7 @@ impl<T> [T] {
716721
/// assert_eq!(x, &[1, 13, 4]);
717722
/// ```
718723
#[stable(feature = "rust1", since = "1.0.0")]
724+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
719725
#[inline]
720726
#[must_use]
721727
pub unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut I::Output

library/core/src/str/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ impl str {
155155
/// ```
156156
#[stable(feature = "rust1", since = "1.0.0")]
157157
#[rustc_const_stable(feature = "const_str_len", since = "1.39.0")]
158+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
158159
#[must_use]
159160
#[inline]
160161
pub const fn len(&self) -> usize {
@@ -174,6 +175,7 @@ impl str {
174175
/// ```
175176
#[stable(feature = "rust1", since = "1.0.0")]
176177
#[rustc_const_stable(feature = "const_str_is_empty", since = "1.39.0")]
178+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
177179
#[must_use]
178180
#[inline]
179181
pub const fn is_empty(&self) -> bool {

0 commit comments

Comments
 (0)