Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9a9dadd

Browse files
committedNov 12, 2024
Auto merge of rust-lang#132940 - matthiaskrgr:rollup-f0czmkq, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#132487 (Provide placeholder generics for traits in "no method found for type parameter" suggestions) - rust-lang#132627 (cleanup: Remove outdated comment of `thir_body`) - rust-lang#132653 (Don't use `maybe_unwrap_block` when checking for macro calls in a block expr) - rust-lang#132793 (Update mdbook to 0.4.42) - rust-lang#132847 (elem_offset / subslice_range: use addr() instead of 'as usize') - rust-lang#132869 (split up the first paragraph of doc comments for better summaries) - rust-lang#132929 (Check for null in the `alloc_zeroed` example) - rust-lang#132933 (Make sure that we suggest turbofishing the right type arg for never suggestion) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 67f2127 + 506f52c commit 9a9dadd

27 files changed

+771
-87
lines changed
 

‎compiler/rustc_ast/src/ast.rs

+31-4
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ impl Expr {
11941194
///
11951195
/// Does not ensure that the path resolves to a const param, the caller should check this.
11961196
pub fn is_potential_trivial_const_arg(&self, strip_identity_block: bool) -> bool {
1197-
let this = if strip_identity_block { self.maybe_unwrap_block().1 } else { self };
1197+
let this = if strip_identity_block { self.maybe_unwrap_block() } else { self };
11981198

11991199
if let ExprKind::Path(None, path) = &this.kind
12001200
&& path.is_potential_trivial_const_arg()
@@ -1206,14 +1206,41 @@ impl Expr {
12061206
}
12071207

12081208
/// Returns an expression with (when possible) *one* outter brace removed
1209-
pub fn maybe_unwrap_block(&self) -> (bool, &Expr) {
1209+
pub fn maybe_unwrap_block(&self) -> &Expr {
12101210
if let ExprKind::Block(block, None) = &self.kind
12111211
&& let [stmt] = block.stmts.as_slice()
12121212
&& let StmtKind::Expr(expr) = &stmt.kind
12131213
{
1214-
(true, expr)
1214+
expr
12151215
} else {
1216-
(false, self)
1216+
self
1217+
}
1218+
}
1219+
1220+
/// Determines whether this expression is a macro call optionally wrapped in braces . If
1221+
/// `already_stripped_block` is set then we do not attempt to peel off a layer of braces.
1222+
///
1223+
/// Returns the [`NodeId`] of the macro call and whether a layer of braces has been peeled
1224+
/// either before, or part of, this function.
1225+
pub fn optionally_braced_mac_call(
1226+
&self,
1227+
already_stripped_block: bool,
1228+
) -> Option<(bool, NodeId)> {
1229+
match &self.kind {
1230+
ExprKind::Block(block, None)
1231+
if let [stmt] = &*block.stmts
1232+
&& !already_stripped_block =>
1233+
{
1234+
match &stmt.kind {
1235+
StmtKind::MacCall(_) => Some((true, stmt.id)),
1236+
StmtKind::Expr(expr) if let ExprKind::MacCall(_) = &expr.kind => {
1237+
Some((true, expr.id))
1238+
}
1239+
_ => None,
1240+
}
1241+
}
1242+
ExprKind::MacCall(_) => Some((already_stripped_block, self.id)),
1243+
_ => None,
12171244
}
12181245
}
12191246

‎compiler/rustc_hir_typeck/src/fallback.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,11 @@ impl<'tcx> AnnotateUnitFallbackVisitor<'_, 'tcx> {
621621
.iter()
622622
.filter(|arg| matches!(arg.unpack(), ty::GenericArgKind::Type(_)))
623623
.count();
624-
for (idx, arg) in args.iter().enumerate() {
624+
for (idx, arg) in args
625+
.iter()
626+
.filter(|arg| matches!(arg.unpack(), ty::GenericArgKind::Type(_)))
627+
.enumerate()
628+
{
625629
if let Some(ty) = arg.as_type()
626630
&& let Some(vid) = self.fcx.root_vid(ty)
627631
&& self.reachable_vids.contains(&vid)

‎compiler/rustc_hir_typeck/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![feature(array_windows)]
55
#![feature(box_patterns)]
66
#![feature(if_let_guard)]
7+
#![feature(iter_intersperse)]
78
#![feature(let_chains)]
89
#![feature(never_type)]
910
#![feature(try_blocks)]

‎compiler/rustc_hir_typeck/src/method/suggest.rs

+43-21
Original file line numberDiff line numberDiff line change
@@ -3874,22 +3874,52 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
38743874
param.name.ident(),
38753875
));
38763876
let bounds_span = hir_generics.bounds_span_for_suggestions(def_id);
3877+
let mut applicability = Applicability::MaybeIncorrect;
3878+
// Format the path of each suggested candidate, providing placeholders
3879+
// for any generic arguments without defaults.
3880+
let candidate_strs: Vec<_> = candidates
3881+
.iter()
3882+
.map(|cand| {
3883+
let cand_path = self.tcx.def_path_str(cand.def_id);
3884+
let cand_params = &self.tcx.generics_of(cand.def_id).own_params;
3885+
let cand_args: String = cand_params
3886+
.iter()
3887+
.skip(1)
3888+
.filter_map(|param| match param.kind {
3889+
ty::GenericParamDefKind::Type {
3890+
has_default: true,
3891+
..
3892+
}
3893+
| ty::GenericParamDefKind::Const {
3894+
has_default: true,
3895+
..
3896+
} => None,
3897+
_ => Some(param.name.as_str()),
3898+
})
3899+
.intersperse(", ")
3900+
.collect();
3901+
if cand_args.is_empty() {
3902+
cand_path
3903+
} else {
3904+
applicability = Applicability::HasPlaceholders;
3905+
format!("{cand_path}</* {cand_args} */>")
3906+
}
3907+
})
3908+
.collect();
3909+
38773910
if rcvr_ty.is_ref()
38783911
&& param.is_impl_trait()
38793912
&& let Some((bounds_span, _)) = bounds_span
38803913
{
38813914
err.multipart_suggestions(
38823915
msg,
3883-
candidates.iter().map(|t| {
3916+
candidate_strs.iter().map(|cand| {
38843917
vec![
38853918
(param.span.shrink_to_lo(), "(".to_string()),
3886-
(
3887-
bounds_span,
3888-
format!(" + {})", self.tcx.def_path_str(t.def_id)),
3889-
),
3919+
(bounds_span, format!(" + {cand})")),
38903920
]
38913921
}),
3892-
Applicability::MaybeIncorrect,
3922+
applicability,
38933923
);
38943924
return;
38953925
}
@@ -3905,16 +3935,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
39053935
(param.span.shrink_to_hi(), Introducer::Colon, None)
39063936
};
39073937

3908-
let all_suggs = candidates.iter().map(|cand| {
3909-
let suggestion = format!(
3910-
"{} {}",
3911-
match introducer {
3912-
Introducer::Plus => " +",
3913-
Introducer::Colon => ":",
3914-
Introducer::Nothing => "",
3915-
},
3916-
self.tcx.def_path_str(cand.def_id)
3917-
);
3938+
let all_suggs = candidate_strs.iter().map(|cand| {
3939+
let suggestion = format!("{} {cand}", match introducer {
3940+
Introducer::Plus => " +",
3941+
Introducer::Colon => ":",
3942+
Introducer::Nothing => "",
3943+
},);
39183944

39193945
let mut suggs = vec![];
39203946

@@ -3928,11 +3954,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
39283954
suggs
39293955
});
39303956

3931-
err.multipart_suggestions(
3932-
msg,
3933-
all_suggs,
3934-
Applicability::MaybeIncorrect,
3935-
);
3957+
err.multipart_suggestions(msg, all_suggs, applicability);
39363958

39373959
return;
39383960
}

‎compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ rustc_queries! {
463463
separate_provide_extern
464464
}
465465

466-
/// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
466+
/// Fetch the THIR for a given body.
467467
query thir_body(key: LocalDefId) -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed> {
468468
// Perf tests revealed that hashing THIR is inefficient (see #85729).
469469
no_hash

‎compiler/rustc_mir_build/src/check_unsafety.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1005,10 +1005,6 @@ pub(crate) fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
10051005
// Runs all other queries that depend on THIR.
10061006
tcx.ensure_with_value().mir_built(def);
10071007
let thir = &thir.steal();
1008-
// If `thir` is empty, a type error occurred, skip this body.
1009-
if thir.exprs.is_empty() {
1010-
return;
1011-
}
10121008

10131009
let hir_id = tcx.local_def_id_to_hir_id(def);
10141010
let safety_context = tcx.hir().fn_sig_by_hir_id(hir_id).map_or(SafetyContext::Safe, |fn_sig| {

‎compiler/rustc_resolve/src/def_collector.rs

+10-19
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,16 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
130130
&self,
131131
anon_const: &'a AnonConst,
132132
) -> Option<(PendingAnonConstInfo, NodeId)> {
133-
let (block_was_stripped, expr) = anon_const.value.maybe_unwrap_block();
134-
match expr {
135-
Expr { kind: ExprKind::MacCall(..), id, .. } => Some((
133+
anon_const.value.optionally_braced_mac_call(false).map(|(block_was_stripped, id)| {
134+
(
136135
PendingAnonConstInfo {
137136
id: anon_const.id,
138137
span: anon_const.value.span,
139138
block_was_stripped,
140139
},
141-
*id,
142-
)),
143-
_ => None,
144-
}
140+
id,
141+
)
142+
})
145143
}
146144

147145
/// Determines whether the expression `const_arg_sub_expr` is a simple macro call, sometimes
@@ -161,18 +159,11 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
161159
panic!("Checking expr is trivial macro call without having entered anon const: `{const_arg_sub_expr:?}`"),
162160
);
163161

164-
let (block_was_stripped, expr) = if pending_anon.block_was_stripped {
165-
(true, const_arg_sub_expr)
166-
} else {
167-
const_arg_sub_expr.maybe_unwrap_block()
168-
};
169-
170-
match expr {
171-
Expr { kind: ExprKind::MacCall(..), id, .. } => {
172-
Some((PendingAnonConstInfo { block_was_stripped, ..pending_anon }, *id))
173-
}
174-
_ => None,
175-
}
162+
const_arg_sub_expr.optionally_braced_mac_call(pending_anon.block_was_stripped).map(
163+
|(block_was_stripped, id)| {
164+
(PendingAnonConstInfo { block_was_stripped, ..pending_anon }, id)
165+
},
166+
)
176167
}
177168
}
178169

‎library/alloc/src/alloc.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,14 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
155155
/// # Examples
156156
///
157157
/// ```
158-
/// use std::alloc::{alloc_zeroed, dealloc, Layout};
158+
/// use std::alloc::{alloc_zeroed, dealloc, handle_alloc_error, Layout};
159159
///
160160
/// unsafe {
161161
/// let layout = Layout::new::<u16>();
162162
/// let ptr = alloc_zeroed(layout);
163+
/// if ptr.is_null() {
164+
/// handle_alloc_error(layout);
165+
/// }
163166
///
164167
/// assert_eq!(*(ptr as *mut u16), 0);
165168
///

‎library/alloc/src/rc.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2932,7 +2932,9 @@ impl<T, I: iter::TrustedLen<Item = T>> ToRcSlice<T> for I {
29322932
}
29332933

29342934
/// `Weak` is a version of [`Rc`] that holds a non-owning reference to the
2935-
/// managed allocation. The allocation is accessed by calling [`upgrade`] on the `Weak`
2935+
/// managed allocation.
2936+
///
2937+
/// The allocation is accessed by calling [`upgrade`] on the `Weak`
29362938
/// pointer, which returns an <code>[Option]<[Rc]\<T>></code>.
29372939
///
29382940
/// Since a `Weak` reference does not count towards ownership, it will not

‎library/alloc/src/sync.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
291291
}
292292

293293
/// `Weak` is a version of [`Arc`] that holds a non-owning reference to the
294-
/// managed allocation. The allocation is accessed by calling [`upgrade`] on the `Weak`
294+
/// managed allocation.
295+
///
296+
/// The allocation is accessed by calling [`upgrade`] on the `Weak`
295297
/// pointer, which returns an <code>[Option]<[Arc]\<T>></code>.
296298
///
297299
/// Since a `Weak` reference does not count towards ownership, it will not

‎library/alloc/src/task.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,11 @@ fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
176176
)
177177
}
178178

179-
/// An analogous trait to `Wake` but used to construct a `LocalWaker`. This API
180-
/// works in exactly the same way as `Wake`, except that it uses an `Rc` instead
181-
/// of an `Arc`, and the result is a `LocalWaker` instead of a `Waker`.
179+
/// An analogous trait to `Wake` but used to construct a `LocalWaker`.
180+
///
181+
/// This API works in exactly the same way as `Wake`,
182+
/// except that it uses an `Rc` instead of an `Arc`,
183+
/// and the result is a `LocalWaker` instead of a `Waker`.
182184
///
183185
/// The benefits of using `LocalWaker` over `Waker` are that it allows the local waker
184186
/// to hold data that does not implement `Send` and `Sync`. Additionally, it saves calls

‎library/core/src/slice/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4578,8 +4578,8 @@ impl<T> [T] {
45784578
panic!("elements are zero-sized");
45794579
}
45804580

4581-
let self_start = self.as_ptr() as usize;
4582-
let elem_start = element as *const T as usize;
4581+
let self_start = self.as_ptr().addr();
4582+
let elem_start = ptr::from_ref(element).addr();
45834583

45844584
let byte_offset = elem_start.wrapping_sub(self_start);
45854585

@@ -4631,8 +4631,8 @@ impl<T> [T] {
46314631
panic!("elements are zero-sized");
46324632
}
46334633

4634-
let self_start = self.as_ptr() as usize;
4635-
let subslice_start = subslice.as_ptr() as usize;
4634+
let self_start = self.as_ptr().addr();
4635+
let subslice_start = subslice.as_ptr().addr();
46364636

46374637
let byte_start = subslice_start.wrapping_sub(self_start);
46384638

‎library/std/src/sync/mpmc/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ use crate::panic::{RefUnwindSafe, UnwindSafe};
153153
use crate::time::{Duration, Instant};
154154

155155
/// Creates a new asynchronous channel, returning the sender/receiver halves.
156+
///
156157
/// All data sent on the [`Sender`] will become available on the [`Receiver`] in
157158
/// the same order as it was sent, and no [`send`] will block the calling thread
158159
/// (this channel has an "infinite buffer", unlike [`sync_channel`], which will
@@ -201,6 +202,7 @@ pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
201202
}
202203

203204
/// Creates a new synchronous, bounded channel.
205+
///
204206
/// All data sent on the [`Sender`] will become available on the [`Receiver`]
205207
/// in the same order as it was sent. Like asynchronous [`channel`]s, the
206208
/// [`Receiver`] will block until a message becomes available. `sync_channel`

‎library/std/src/sync/mpsc/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ pub enum TrySendError<T> {
483483
}
484484

485485
/// Creates a new asynchronous channel, returning the sender/receiver halves.
486+
///
486487
/// All data sent on the [`Sender`] will become available on the [`Receiver`] in
487488
/// the same order as it was sent, and no [`send`] will block the calling thread
488489
/// (this channel has an "infinite buffer", unlike [`sync_channel`], which will
@@ -527,6 +528,7 @@ pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
527528
}
528529

529530
/// Creates a new synchronous, bounded channel.
531+
///
530532
/// All data sent on the [`SyncSender`] will become available on the [`Receiver`]
531533
/// in the same order as it was sent. Like asynchronous [`channel`]s, the
532534
/// [`Receiver`] will block until a message becomes available. `sync_channel`

‎src/tools/rustbook/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

‎src/tools/rustbook/Cargo.lock

+20-4
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,12 @@ dependencies = [
441441

442442
[[package]]
443443
name = "handlebars"
444-
version = "5.1.2"
444+
version = "6.2.0"
445445
source = "registry+https://github.com/rust-lang/crates.io-index"
446-
checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b"
446+
checksum = "fd4ccde012831f9a071a637b0d4e31df31c0f6c525784b35ae76a9ac6bc1e315"
447447
dependencies = [
448448
"log",
449+
"num-order",
449450
"pest",
450451
"pest_derive",
451452
"serde",
@@ -645,9 +646,9 @@ dependencies = [
645646

646647
[[package]]
647648
name = "mdbook"
648-
version = "0.4.40"
649+
version = "0.4.42"
649650
source = "registry+https://github.com/rust-lang/crates.io-index"
650-
checksum = "b45a38e19bd200220ef07c892b0157ad3d2365e5b5a267ca01ad12182491eea5"
651+
checksum = "7624879735513024d323e7267a0b3a7176aceb0db537939beb4ee31d9e8945e3"
651652
dependencies = [
652653
"ammonia",
653654
"anyhow",
@@ -762,6 +763,21 @@ dependencies = [
762763
"windows-sys 0.59.0",
763764
]
764765

766+
[[package]]
767+
name = "num-modular"
768+
version = "0.6.1"
769+
source = "registry+https://github.com/rust-lang/crates.io-index"
770+
checksum = "17bb261bf36fa7d83f4c294f834e91256769097b3cb505d44831e0a179ac647f"
771+
772+
[[package]]
773+
name = "num-order"
774+
version = "1.2.0"
775+
source = "registry+https://github.com/rust-lang/crates.io-index"
776+
checksum = "537b596b97c40fcf8056d153049eb22f481c17ebce72a513ec9286e4986d1bb6"
777+
dependencies = [
778+
"num-modular",
779+
]
780+
765781
[[package]]
766782
name = "num-traits"
767783
version = "0.2.19"
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.