Skip to content

Commit 6cf068d

Browse files
committedAug 29, 2024
Auto merge of #129721 - workingjubilee:rollup-y2o1mnp, r=workingjubilee
Rollup of 14 pull requests Successful merges: - #128192 (rustc_target: Add various aarch64 features) - #129170 (Add an ability to convert between `Span` and `visit::Location`) - #129343 (Emit specific message for time<=0.3.35) - #129378 (Clean up cfg-gating of ProcessPrng extern) - #129401 (Partially stabilize `feature(new_uninit)`) - #129467 (derive(SmartPointer): assume pointee from the single generic and better error messages) - #129494 (format code in tests/ui/threads-sendsync) - #129617 (Update books) - #129673 (Add fmt::Debug to sync::Weak<T, A>) - #129683 (copysign with sign being a NaN can have non-portable results) - #129689 (Move `'tcx` lifetime off of impl and onto methods for `CrateMetadataRef`) - #129695 (Fix path to run clippy on rustdoc) - #129712 (Correct trusty targets to be tier 3) - #129715 (Update `compiler_builtins` to `0.1.123`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents acb4e8b + bd66fad commit 6cf068d

File tree

113 files changed

+805
-474
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+805
-474
lines changed
 

‎compiler/rustc_arena/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#![feature(decl_macro)]
2222
#![feature(dropck_eyepatch)]
2323
#![feature(maybe_uninit_slice)]
24-
#![feature(new_uninit)]
2524
#![feature(rustc_attrs)]
2625
#![feature(rustdoc_internals)]
2726
#![feature(strict_provenance)]

‎compiler/rustc_builtin_macros/src/deriving/smart_ptr.rs

+47-28
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
1111
use rustc_expand::base::{Annotatable, ExtCtxt};
1212
use rustc_span::symbol::{sym, Ident};
1313
use rustc_span::{Span, Symbol};
14-
use smallvec::{smallvec, SmallVec};
1514
use thin_vec::{thin_vec, ThinVec};
1615

1716
macro_rules! path {
@@ -68,43 +67,63 @@ pub(crate) fn expand_deriving_smart_ptr(
6867
};
6968

7069
// Convert generic parameters (from the struct) into generic args.
71-
let mut pointee_param = None;
72-
let mut multiple_pointee_diag: SmallVec<[_; 2]> = smallvec![];
73-
let self_params = generics
70+
let self_params: Vec<_> = generics
7471
.params
7572
.iter()
76-
.enumerate()
77-
.map(|(idx, p)| match p.kind {
73+
.map(|p| match p.kind {
7874
GenericParamKind::Lifetime => GenericArg::Lifetime(cx.lifetime(p.span(), p.ident)),
79-
GenericParamKind::Type { .. } => {
80-
if p.attrs().iter().any(|attr| attr.has_name(sym::pointee)) {
81-
if pointee_param.is_some() {
82-
multiple_pointee_diag.push(cx.dcx().struct_span_err(
83-
p.span(),
84-
"`SmartPointer` can only admit one type as pointee",
85-
));
86-
} else {
87-
pointee_param = Some(idx);
88-
}
89-
}
90-
GenericArg::Type(cx.ty_ident(p.span(), p.ident))
91-
}
75+
GenericParamKind::Type { .. } => GenericArg::Type(cx.ty_ident(p.span(), p.ident)),
9276
GenericParamKind::Const { .. } => GenericArg::Const(cx.const_ident(p.span(), p.ident)),
9377
})
94-
.collect::<Vec<_>>();
95-
let Some(pointee_param_idx) = pointee_param else {
78+
.collect();
79+
let type_params: Vec<_> = generics
80+
.params
81+
.iter()
82+
.enumerate()
83+
.filter_map(|(idx, p)| {
84+
if let GenericParamKind::Type { .. } = p.kind {
85+
Some((idx, p.span(), p.attrs().iter().any(|attr| attr.has_name(sym::pointee))))
86+
} else {
87+
None
88+
}
89+
})
90+
.collect();
91+
92+
let pointee_param_idx = if type_params.is_empty() {
93+
// `#[derive(SmartPointer)]` requires at least one generic type on the target `struct`
9694
cx.dcx().struct_span_err(
9795
span,
98-
"At least one generic type should be designated as `#[pointee]` in order to derive `SmartPointer` traits",
96+
"`SmartPointer` can only be derived on `struct`s that are generic over at least one type",
9997
).emit();
10098
return;
101-
};
102-
if !multiple_pointee_diag.is_empty() {
103-
for diag in multiple_pointee_diag {
104-
diag.emit();
99+
} else if type_params.len() == 1 {
100+
// Regardless of the only type param being designed as `#[pointee]` or not, we can just use it as such
101+
type_params[0].0
102+
} else {
103+
let mut pointees = type_params
104+
.iter()
105+
.filter_map(|&(idx, span, is_pointee)| is_pointee.then_some((idx, span)))
106+
.fuse();
107+
match (pointees.next(), pointees.next()) {
108+
(Some((idx, _span)), None) => idx,
109+
(None, _) => {
110+
cx.dcx().struct_span_err(
111+
span,
112+
"exactly one generic type parameter must be marked as #[pointee] to derive SmartPointer traits",
113+
).emit();
114+
return;
115+
}
116+
(Some((_, one)), Some((_, another))) => {
117+
cx.dcx()
118+
.struct_span_err(
119+
vec![one, another],
120+
"only one type parameter can be marked as `#[pointee]` when deriving SmartPointer traits",
121+
)
122+
.emit();
123+
return;
124+
}
105125
}
106-
return;
107-
}
126+
};
108127

109128
// Create the type of `self`.
110129
let path = cx.path_all(span, false, vec![name_ident], self_params.clone());

0 commit comments

Comments
 (0)
Please sign in to comment.