Skip to content

Commit 4070857

Browse files
committed
Add #[rustc_no_implicit_autorefs] and apply it to std methods
1 parent 0b16baa commit 4070857

File tree

7 files changed

+20
-0
lines changed

7 files changed

+20
-0
lines changed

Diff for: compiler/rustc_feature/src/builtin_attrs.rs

+4
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
882882
EncodeCrossCrate::Yes,
883883
"#[rustc_never_returns_null_ptr] is used to mark functions returning non-null pointers."
884884
),
885+
rustc_attr!(
886+
rustc_no_implicit_autorefs, AttributeType::Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes,
887+
"#[rustc_no_implicit_autorefs] is used to mark functions that should not autorefs in raw pointers context."
888+
),
885889
rustc_attr!(
886890
rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
887891
"#![rustc_coherence_is_core] allows inherent methods on builtin types, only intended to be used in `core`."

Diff for: compiler/rustc_passes/src/check_attr.rs

+3
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
164164
[sym::rustc_never_returns_null_ptr, ..] => {
165165
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
166166
}
167+
[sym::rustc_no_implicit_autorefs, ..] => {
168+
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
169+
}
167170
[sym::rustc_legacy_const_generics, ..] => {
168171
self.check_rustc_legacy_const_generics(hir_id, attr, span, target, item)
169172
}

Diff for: compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,7 @@ symbols! {
17021702
rustc_must_implement_one_of,
17031703
rustc_never_returns_null_ptr,
17041704
rustc_never_type_options,
1705+
rustc_no_implicit_autorefs,
17051706
rustc_no_mir_inline,
17061707
rustc_nonnull_optimization_guaranteed,
17071708
rustc_nounwind,

Diff for: library/alloc/src/string.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,7 @@ impl String {
18171817
#[stable(feature = "rust1", since = "1.0.0")]
18181818
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
18191819
#[rustc_confusables("length", "size")]
1820+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
18201821
pub const fn len(&self) -> usize {
18211822
self.vec.len()
18221823
}
@@ -1836,6 +1837,7 @@ impl String {
18361837
#[must_use]
18371838
#[stable(feature = "rust1", since = "1.0.0")]
18381839
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
1840+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
18391841
pub const fn is_empty(&self) -> bool {
18401842
self.len() == 0
18411843
}

Diff for: 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
}

Diff for: library/core/src/slice/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ impl<T> [T] {
111111
#[lang = "slice_len_fn"]
112112
#[stable(feature = "rust1", since = "1.0.0")]
113113
#[rustc_const_stable(feature = "const_slice_len", since = "1.39.0")]
114+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
114115
#[inline]
115116
#[must_use]
116117
pub const fn len(&self) -> usize {
@@ -130,6 +131,7 @@ impl<T> [T] {
130131
/// ```
131132
#[stable(feature = "rust1", since = "1.0.0")]
132133
#[rustc_const_stable(feature = "const_slice_is_empty", since = "1.39.0")]
134+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
133135
#[inline]
134136
#[must_use]
135137
pub const fn is_empty(&self) -> bool {
@@ -598,6 +600,7 @@ impl<T> [T] {
598600
/// assert_eq!(None, v.get(0..4));
599601
/// ```
600602
#[stable(feature = "rust1", since = "1.0.0")]
603+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
601604
#[inline]
602605
#[must_use]
603606
pub fn get<I>(&self, index: I) -> Option<&I::Output>
@@ -623,6 +626,7 @@ impl<T> [T] {
623626
/// assert_eq!(x, &[0, 42, 2]);
624627
/// ```
625628
#[stable(feature = "rust1", since = "1.0.0")]
629+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
626630
#[inline]
627631
#[must_use]
628632
pub fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
@@ -660,6 +664,7 @@ impl<T> [T] {
660664
/// }
661665
/// ```
662666
#[stable(feature = "rust1", since = "1.0.0")]
667+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
663668
#[inline]
664669
#[must_use]
665670
pub unsafe fn get_unchecked<I>(&self, index: I) -> &I::Output
@@ -702,6 +707,7 @@ impl<T> [T] {
702707
/// assert_eq!(x, &[1, 13, 4]);
703708
/// ```
704709
#[stable(feature = "rust1", since = "1.0.0")]
710+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
705711
#[inline]
706712
#[must_use]
707713
pub unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut I::Output

Diff for: library/core/src/str/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ impl str {
135135
#[stable(feature = "rust1", since = "1.0.0")]
136136
#[rustc_const_stable(feature = "const_str_len", since = "1.39.0")]
137137
#[cfg_attr(not(test), rustc_diagnostic_item = "str_len")]
138+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
138139
#[must_use]
139140
#[inline]
140141
pub const fn len(&self) -> usize {
@@ -154,6 +155,7 @@ impl str {
154155
/// ```
155156
#[stable(feature = "rust1", since = "1.0.0")]
156157
#[rustc_const_stable(feature = "const_str_is_empty", since = "1.39.0")]
158+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
157159
#[must_use]
158160
#[inline]
159161
pub const fn is_empty(&self) -> bool {

0 commit comments

Comments
 (0)