Skip to content

Commit 45f3514

Browse files
committed
Add #[rustc_no_implicit_autorefs] and apply it to std methods
1 parent ac385a5 commit 45f3514

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
@@ -157,6 +157,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
157157
sym::rustc_never_returns_null_ptr => {
158158
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
159159
}
160+
sym::rustc_no_implicit_autorefs => {
161+
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
162+
}
160163
sym::rustc_legacy_const_generics => {
161164
self.check_rustc_legacy_const_generics(hir_id, attr, span, target, item)
162165
}

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,7 @@ symbols! {
16051605
rustc_must_implement_one_of,
16061606
rustc_never_returns_null_ptr,
16071607
rustc_never_type_options,
1608+
rustc_no_implicit_autorefs,
16081609
rustc_no_mir_inline,
16091610
rustc_nonnull_optimization_guaranteed,
16101611
rustc_nounwind,

library/alloc/src/string.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,7 @@ impl String {
17531753
#[must_use]
17541754
#[stable(feature = "rust1", since = "1.0.0")]
17551755
#[rustc_confusables("length", "size")]
1756+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
17561757
pub fn len(&self) -> usize {
17571758
self.vec.len()
17581759
}
@@ -1771,6 +1772,7 @@ impl String {
17711772
#[inline]
17721773
#[must_use]
17731774
#[stable(feature = "rust1", since = "1.0.0")]
1775+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
17741776
pub fn is_empty(&self) -> bool {
17751777
self.len() == 0
17761778
}

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)