Skip to content

Commit 5120f64

Browse files
committed
Add #[rustc_no_implicit_autorefs] and apply it to std methods
1 parent e08b80c commit 5120f64

File tree

7 files changed

+20
-0
lines changed

7 files changed

+20
-0
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

+4
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
877877
EncodeCrossCrate::Yes,
878878
"#[rustc_never_returns_null_ptr] is used to mark functions returning non-null pointers."
879879
),
880+
rustc_attr!(
881+
rustc_no_implicit_autorefs, AttributeType::Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes,
882+
"#[rustc_no_implicit_autorefs] is used to mark functions that should not autorefs in raw pointers context."
883+
),
880884
rustc_attr!(
881885
rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
882886
"#![rustc_coherence_is_core] allows inherent methods on builtin types, only intended to be used in `core`."

compiler/rustc_passes/src/check_attr.rs

+3
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
162162
[sym::rustc_never_returns_null_ptr, ..] => {
163163
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
164164
}
165+
[sym::rustc_no_implicit_autorefs, ..] => {
166+
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
167+
}
165168
[sym::rustc_legacy_const_generics, ..] => {
166169
self.check_rustc_legacy_const_generics(hir_id, attr, span, target, item)
167170
}

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,7 @@ symbols! {
16511651
rustc_must_implement_one_of,
16521652
rustc_never_returns_null_ptr,
16531653
rustc_never_type_options,
1654+
rustc_no_implicit_autorefs,
16541655
rustc_no_mir_inline,
16551656
rustc_nonnull_optimization_guaranteed,
16561657
rustc_nounwind,

library/alloc/src/string.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,7 @@ impl String {
17491749
#[must_use]
17501750
#[stable(feature = "rust1", since = "1.0.0")]
17511751
#[rustc_confusables("length", "size")]
1752+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
17521753
pub fn len(&self) -> usize {
17531754
self.vec.len()
17541755
}
@@ -1767,6 +1768,7 @@ impl String {
17671768
#[inline]
17681769
#[must_use]
17691770
#[stable(feature = "rust1", since = "1.0.0")]
1771+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
17701772
pub fn is_empty(&self) -> bool {
17711773
self.len() == 0
17721774
}

library/core/src/ops/index.rs

+2
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

+6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ impl<T> [T] {
112112
#[stable(feature = "rust1", since = "1.0.0")]
113113
#[rustc_const_stable(feature = "const_slice_len", since = "1.39.0")]
114114
#[rustc_allow_const_fn_unstable(ptr_metadata)]
115+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
115116
#[inline]
116117
#[must_use]
117118
pub const fn len(&self) -> usize {
@@ -131,6 +132,7 @@ impl<T> [T] {
131132
/// ```
132133
#[stable(feature = "rust1", since = "1.0.0")]
133134
#[rustc_const_stable(feature = "const_slice_is_empty", since = "1.39.0")]
135+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
134136
#[inline]
135137
#[must_use]
136138
pub const fn is_empty(&self) -> bool {
@@ -591,6 +593,7 @@ impl<T> [T] {
591593
/// assert_eq!(None, v.get(0..4));
592594
/// ```
593595
#[stable(feature = "rust1", since = "1.0.0")]
596+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
594597
#[inline]
595598
#[must_use]
596599
pub fn get<I>(&self, index: I) -> Option<&I::Output>
@@ -616,6 +619,7 @@ impl<T> [T] {
616619
/// assert_eq!(x, &[0, 42, 2]);
617620
/// ```
618621
#[stable(feature = "rust1", since = "1.0.0")]
622+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
619623
#[inline]
620624
#[must_use]
621625
pub fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
@@ -653,6 +657,7 @@ impl<T> [T] {
653657
/// }
654658
/// ```
655659
#[stable(feature = "rust1", since = "1.0.0")]
660+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
656661
#[inline]
657662
#[must_use]
658663
pub unsafe fn get_unchecked<I>(&self, index: I) -> &I::Output
@@ -695,6 +700,7 @@ impl<T> [T] {
695700
/// assert_eq!(x, &[1, 13, 4]);
696701
/// ```
697702
#[stable(feature = "rust1", since = "1.0.0")]
703+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
698704
#[inline]
699705
#[must_use]
700706
pub unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut I::Output

library/core/src/str/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ impl str {
134134
/// ```
135135
#[stable(feature = "rust1", since = "1.0.0")]
136136
#[rustc_const_stable(feature = "const_str_len", since = "1.39.0")]
137+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
137138
#[must_use]
138139
#[inline]
139140
pub const fn len(&self) -> usize {
@@ -153,6 +154,7 @@ impl str {
153154
/// ```
154155
#[stable(feature = "rust1", since = "1.0.0")]
155156
#[rustc_const_stable(feature = "const_str_is_empty", since = "1.39.0")]
157+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
156158
#[must_use]
157159
#[inline]
158160
pub const fn is_empty(&self) -> bool {

0 commit comments

Comments
 (0)