Skip to content

Commit 3fb1f3f

Browse files
committed
Add #[rustc_no_implicit_autorefs] and apply it to std methods
1 parent 07292cc commit 3fb1f3f

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
@@ -896,6 +896,10 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
896896
EncodeCrossCrate::Yes,
897897
"#[rustc_never_returns_null_ptr] is used to mark functions returning non-null pointers."
898898
),
899+
rustc_attr!(
900+
rustc_no_implicit_autorefs, AttributeType::Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes,
901+
"#[rustc_no_implicit_autorefs] is used to mark functions that should not autorefs in raw pointers context."
902+
),
899903
rustc_attr!(
900904
rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
901905
"#![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
@@ -179,6 +179,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
179179
[sym::rustc_as_ptr, ..] => {
180180
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
181181
}
182+
[sym::rustc_no_implicit_autorefs, ..] => {
183+
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
184+
}
182185
[sym::rustc_never_returns_null_ptr, ..] => {
183186
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
184187
}

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,7 @@ symbols! {
17871787
rustc_must_implement_one_of,
17881788
rustc_never_returns_null_ptr,
17891789
rustc_never_type_options,
1790+
rustc_no_implicit_autorefs,
17901791
rustc_no_mir_inline,
17911792
rustc_nonnull_optimization_guaranteed,
17921793
rustc_nounwind,

library/alloc/src/string.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,7 @@ impl String {
18021802
#[stable(feature = "rust1", since = "1.0.0")]
18031803
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
18041804
#[rustc_confusables("length", "size")]
1805+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
18051806
pub const fn len(&self) -> usize {
18061807
self.vec.len()
18071808
}
@@ -1821,6 +1822,7 @@ impl String {
18211822
#[must_use]
18221823
#[stable(feature = "rust1", since = "1.0.0")]
18231824
#[rustc_const_unstable(feature = "const_vec_string_slice", issue = "129041")]
1825+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
18241826
pub const fn is_empty(&self) -> bool {
18251827
self.len() == 0
18261828
}

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
@@ -110,6 +110,7 @@ impl<T> [T] {
110110
#[lang = "slice_len_fn"]
111111
#[stable(feature = "rust1", since = "1.0.0")]
112112
#[rustc_const_stable(feature = "const_slice_len", since = "1.39.0")]
113+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
113114
#[inline]
114115
#[must_use]
115116
pub const fn len(&self) -> usize {
@@ -129,6 +130,7 @@ impl<T> [T] {
129130
/// ```
130131
#[stable(feature = "rust1", since = "1.0.0")]
131132
#[rustc_const_stable(feature = "const_slice_is_empty", since = "1.39.0")]
133+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
132134
#[inline]
133135
#[must_use]
134136
pub const fn is_empty(&self) -> bool {
@@ -589,6 +591,7 @@ impl<T> [T] {
589591
/// assert_eq!(None, v.get(0..4));
590592
/// ```
591593
#[stable(feature = "rust1", since = "1.0.0")]
594+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
592595
#[inline]
593596
#[must_use]
594597
pub fn get<I>(&self, index: I) -> Option<&I::Output>
@@ -614,6 +617,7 @@ impl<T> [T] {
614617
/// assert_eq!(x, &[0, 42, 2]);
615618
/// ```
616619
#[stable(feature = "rust1", since = "1.0.0")]
620+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
617621
#[inline]
618622
#[must_use]
619623
pub fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
@@ -651,6 +655,7 @@ impl<T> [T] {
651655
/// }
652656
/// ```
653657
#[stable(feature = "rust1", since = "1.0.0")]
658+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
654659
#[inline]
655660
#[must_use]
656661
pub unsafe fn get_unchecked<I>(&self, index: I) -> &I::Output
@@ -693,6 +698,7 @@ impl<T> [T] {
693698
/// assert_eq!(x, &[1, 13, 4]);
694699
/// ```
695700
#[stable(feature = "rust1", since = "1.0.0")]
701+
#[cfg_attr(not(bootstrap), rustc_no_implicit_autorefs)]
696702
#[inline]
697703
#[must_use]
698704
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
@@ -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)