Skip to content

Rollup of 8 pull requests #132940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
15a71b6
cleanup: Remove outdated comment and logic of `thir_body`
adwinwhite Nov 5, 2024
1d6e847
Check for both `StmtKind::MacCall` and `ExprKind::MacCall`
BoxyUwU Nov 5, 2024
544b9f9
Update mdbook to 0.4.42
ehuss Nov 8, 2024
b2d1874
elem_offset / subslice_range: use addr() instead of 'as usize'
RalfJung Nov 10, 2024
ae3c68d
split up the first paragraph of doc comments for better summaries
lolbinarycat Nov 10, 2024
02add7d
Provide placeholder generic arguments for traits in "no method found …
dianne Nov 2, 2024
2ddb91a
Check for null in the `alloc_zeroed` example
cuviper Nov 12, 2024
8473e3f
Make sure that we suggest turbofishing the right type arg
compiler-errors Nov 12, 2024
9098e03
Rollup merge of #132487 - dianne:include-trait-args-in-suggestion, r=…
matthiaskrgr Nov 12, 2024
2ad4a35
Rollup merge of #132627 - adwinwhite:thir_body_cleanup, r=compiler-er…
matthiaskrgr Nov 12, 2024
b7dc481
Rollup merge of #132653 - BoxyUwU:const_arg_stmt_mac_call, r=compiler…
matthiaskrgr Nov 12, 2024
52bb9fa
Rollup merge of #132793 - ehuss:update-mdbook, r=Mark-Simulacrum
matthiaskrgr Nov 12, 2024
953064f
Rollup merge of #132847 - RalfJung:addr-dont-expose, r=Mark-Simulacrum
matthiaskrgr Nov 12, 2024
0555bb2
Rollup merge of #132869 - lolbinarycat:library-fix-too_long_first_doc…
matthiaskrgr Nov 12, 2024
119b939
Rollup merge of #132929 - cuviper:check-alloc_zeroed, r=tgross35
matthiaskrgr Nov 12, 2024
506f52c
Rollup merge of #132933 - compiler-errors:never-lint-arg-bug, r=Waffl…
matthiaskrgr Nov 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ impl Expr {
///
/// Does not ensure that the path resolves to a const param, the caller should check this.
pub fn is_potential_trivial_const_arg(&self, strip_identity_block: bool) -> bool {
let this = if strip_identity_block { self.maybe_unwrap_block().1 } else { self };
let this = if strip_identity_block { self.maybe_unwrap_block() } else { self };

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

/// Returns an expression with (when possible) *one* outter brace removed
pub fn maybe_unwrap_block(&self) -> (bool, &Expr) {
pub fn maybe_unwrap_block(&self) -> &Expr {
if let ExprKind::Block(block, None) = &self.kind
&& let [stmt] = block.stmts.as_slice()
&& let StmtKind::Expr(expr) = &stmt.kind
{
(true, expr)
expr
} else {
(false, self)
self
}
}

/// Determines whether this expression is a macro call optionally wrapped in braces . If
/// `already_stripped_block` is set then we do not attempt to peel off a layer of braces.
///
/// Returns the [`NodeId`] of the macro call and whether a layer of braces has been peeled
/// either before, or part of, this function.
pub fn optionally_braced_mac_call(
&self,
already_stripped_block: bool,
) -> Option<(bool, NodeId)> {
match &self.kind {
ExprKind::Block(block, None)
if let [stmt] = &*block.stmts
&& !already_stripped_block =>
{
match &stmt.kind {
StmtKind::MacCall(_) => Some((true, stmt.id)),
StmtKind::Expr(expr) if let ExprKind::MacCall(_) = &expr.kind => {
Some((true, expr.id))
}
_ => None,
}
}
ExprKind::MacCall(_) => Some((already_stripped_block, self.id)),
_ => None,
}
}

Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_hir_typeck/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,11 @@ impl<'tcx> AnnotateUnitFallbackVisitor<'_, 'tcx> {
.iter()
.filter(|arg| matches!(arg.unpack(), ty::GenericArgKind::Type(_)))
.count();
for (idx, arg) in args.iter().enumerate() {
for (idx, arg) in args
.iter()
.filter(|arg| matches!(arg.unpack(), ty::GenericArgKind::Type(_)))
.enumerate()
{
if let Some(ty) = arg.as_type()
&& let Some(vid) = self.fcx.root_vid(ty)
&& self.reachable_vids.contains(&vid)
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#![feature(array_windows)]
#![feature(box_patterns)]
#![feature(if_let_guard)]
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(never_type)]
#![feature(try_blocks)]
Expand Down
64 changes: 43 additions & 21 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3874,22 +3874,52 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
param.name.ident(),
));
let bounds_span = hir_generics.bounds_span_for_suggestions(def_id);
let mut applicability = Applicability::MaybeIncorrect;
// Format the path of each suggested candidate, providing placeholders
// for any generic arguments without defaults.
let candidate_strs: Vec<_> = candidates
.iter()
.map(|cand| {
let cand_path = self.tcx.def_path_str(cand.def_id);
let cand_params = &self.tcx.generics_of(cand.def_id).own_params;
let cand_args: String = cand_params
.iter()
.skip(1)
.filter_map(|param| match param.kind {
ty::GenericParamDefKind::Type {
has_default: true,
..
}
| ty::GenericParamDefKind::Const {
has_default: true,
..
} => None,
_ => Some(param.name.as_str()),
})
.intersperse(", ")
.collect();
if cand_args.is_empty() {
cand_path
} else {
applicability = Applicability::HasPlaceholders;
format!("{cand_path}</* {cand_args} */>")
}
})
.collect();

if rcvr_ty.is_ref()
&& param.is_impl_trait()
&& let Some((bounds_span, _)) = bounds_span
{
err.multipart_suggestions(
msg,
candidates.iter().map(|t| {
candidate_strs.iter().map(|cand| {
vec![
(param.span.shrink_to_lo(), "(".to_string()),
(
bounds_span,
format!(" + {})", self.tcx.def_path_str(t.def_id)),
),
(bounds_span, format!(" + {cand})")),
]
}),
Applicability::MaybeIncorrect,
applicability,
);
return;
}
Expand All @@ -3905,16 +3935,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(param.span.shrink_to_hi(), Introducer::Colon, None)
};

let all_suggs = candidates.iter().map(|cand| {
let suggestion = format!(
"{} {}",
match introducer {
Introducer::Plus => " +",
Introducer::Colon => ":",
Introducer::Nothing => "",
},
self.tcx.def_path_str(cand.def_id)
);
let all_suggs = candidate_strs.iter().map(|cand| {
let suggestion = format!("{} {cand}", match introducer {
Introducer::Plus => " +",
Introducer::Colon => ":",
Introducer::Nothing => "",
},);

let mut suggs = vec![];

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

err.multipart_suggestions(
msg,
all_suggs,
Applicability::MaybeIncorrect,
);
err.multipart_suggestions(msg, all_suggs, applicability);

return;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ rustc_queries! {
separate_provide_extern
}

/// Fetch the THIR for a given body. If typeck for that body failed, returns an empty `Thir`.
/// Fetch the THIR for a given body.
query thir_body(key: LocalDefId) -> Result<(&'tcx Steal<thir::Thir<'tcx>>, thir::ExprId), ErrorGuaranteed> {
// Perf tests revealed that hashing THIR is inefficient (see #85729).
no_hash
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_mir_build/src/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,10 +1005,6 @@ pub(crate) fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
// Runs all other queries that depend on THIR.
tcx.ensure_with_value().mir_built(def);
let thir = &thir.steal();
// If `thir` is empty, a type error occurred, skip this body.
if thir.exprs.is_empty() {
return;
}

let hir_id = tcx.local_def_id_to_hir_id(def);
let safety_context = tcx.hir().fn_sig_by_hir_id(hir_id).map_or(SafetyContext::Safe, |fn_sig| {
Expand Down
29 changes: 10 additions & 19 deletions compiler/rustc_resolve/src/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,16 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
&self,
anon_const: &'a AnonConst,
) -> Option<(PendingAnonConstInfo, NodeId)> {
let (block_was_stripped, expr) = anon_const.value.maybe_unwrap_block();
match expr {
Expr { kind: ExprKind::MacCall(..), id, .. } => Some((
anon_const.value.optionally_braced_mac_call(false).map(|(block_was_stripped, id)| {
(
PendingAnonConstInfo {
id: anon_const.id,
span: anon_const.value.span,
block_was_stripped,
},
*id,
)),
_ => None,
}
id,
)
})
}

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

let (block_was_stripped, expr) = if pending_anon.block_was_stripped {
(true, const_arg_sub_expr)
} else {
const_arg_sub_expr.maybe_unwrap_block()
};

match expr {
Expr { kind: ExprKind::MacCall(..), id, .. } => {
Some((PendingAnonConstInfo { block_was_stripped, ..pending_anon }, *id))
}
_ => None,
}
const_arg_sub_expr.optionally_braced_mac_call(pending_anon.block_was_stripped).map(
|(block_was_stripped, id)| {
(PendingAnonConstInfo { block_was_stripped, ..pending_anon }, id)
},
)
}
}

Expand Down
5 changes: 4 additions & 1 deletion library/alloc/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,14 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
/// # Examples
///
/// ```
/// use std::alloc::{alloc_zeroed, dealloc, Layout};
/// use std::alloc::{alloc_zeroed, dealloc, handle_alloc_error, Layout};
///
/// unsafe {
/// let layout = Layout::new::<u16>();
/// let ptr = alloc_zeroed(layout);
/// if ptr.is_null() {
/// handle_alloc_error(layout);
/// }
///
/// assert_eq!(*(ptr as *mut u16), 0);
///
Expand Down
4 changes: 3 additions & 1 deletion library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2932,7 +2932,9 @@ impl<T, I: iter::TrustedLen<Item = T>> ToRcSlice<T> for I {
}

/// `Weak` is a version of [`Rc`] that holds a non-owning reference to the
/// managed allocation. The allocation is accessed by calling [`upgrade`] on the `Weak`
/// managed allocation.
///
/// The allocation is accessed by calling [`upgrade`] on the `Weak`
/// pointer, which returns an <code>[Option]<[Rc]\<T>></code>.
///
/// Since a `Weak` reference does not count towards ownership, it will not
Expand Down
4 changes: 3 additions & 1 deletion library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
}

/// `Weak` is a version of [`Arc`] that holds a non-owning reference to the
/// managed allocation. The allocation is accessed by calling [`upgrade`] on the `Weak`
/// managed allocation.
///
/// The allocation is accessed by calling [`upgrade`] on the `Weak`
/// pointer, which returns an <code>[Option]<[Arc]\<T>></code>.
///
/// Since a `Weak` reference does not count towards ownership, it will not
Expand Down
8 changes: 5 additions & 3 deletions library/alloc/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
)
}

/// An analogous trait to `Wake` but used to construct a `LocalWaker`. This API
/// works in exactly the same way as `Wake`, except that it uses an `Rc` instead
/// of an `Arc`, and the result is a `LocalWaker` instead of a `Waker`.
/// An analogous trait to `Wake` but used to construct a `LocalWaker`.
///
/// This API works in exactly the same way as `Wake`,
/// except that it uses an `Rc` instead of an `Arc`,
/// and the result is a `LocalWaker` instead of a `Waker`.
///
/// The benefits of using `LocalWaker` over `Waker` are that it allows the local waker
/// to hold data that does not implement `Send` and `Sync`. Additionally, it saves calls
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4578,8 +4578,8 @@ impl<T> [T] {
panic!("elements are zero-sized");
}

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

let byte_offset = elem_start.wrapping_sub(self_start);

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

let self_start = self.as_ptr() as usize;
let subslice_start = subslice.as_ptr() as usize;
let self_start = self.as_ptr().addr();
let subslice_start = subslice.as_ptr().addr();

let byte_start = subslice_start.wrapping_sub(self_start);

Expand Down
2 changes: 2 additions & 0 deletions library/std/src/sync/mpmc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ use crate::panic::{RefUnwindSafe, UnwindSafe};
use crate::time::{Duration, Instant};

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

/// Creates a new synchronous, bounded channel.
///
/// All data sent on the [`Sender`] will become available on the [`Receiver`]
/// in the same order as it was sent. Like asynchronous [`channel`]s, the
/// [`Receiver`] will block until a message becomes available. `sync_channel`
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/sync/mpsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ pub enum TrySendError<T> {
}

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

/// Creates a new synchronous, bounded channel.
///
/// All data sent on the [`SyncSender`] will become available on the [`Receiver`]
/// in the same order as it was sent. Like asynchronous [`channel`]s, the
/// [`Receiver`] will block until a message becomes available. `sync_channel`
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rust-by-example
1 change: 1 addition & 0 deletions src/tools/rustbook/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
24 changes: 20 additions & 4 deletions src/tools/rustbook/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,12 @@ dependencies = [

[[package]]
name = "handlebars"
version = "5.1.2"
version = "6.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d08485b96a0e6393e9e4d1b8d48cf74ad6c063cd905eb33f42c1ce3f0377539b"
checksum = "fd4ccde012831f9a071a637b0d4e31df31c0f6c525784b35ae76a9ac6bc1e315"
dependencies = [
"log",
"num-order",
"pest",
"pest_derive",
"serde",
Expand Down Expand Up @@ -645,9 +646,9 @@ dependencies = [

[[package]]
name = "mdbook"
version = "0.4.40"
version = "0.4.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b45a38e19bd200220ef07c892b0157ad3d2365e5b5a267ca01ad12182491eea5"
checksum = "7624879735513024d323e7267a0b3a7176aceb0db537939beb4ee31d9e8945e3"
dependencies = [
"ammonia",
"anyhow",
Expand Down Expand Up @@ -762,6 +763,21 @@ dependencies = [
"windows-sys 0.59.0",
]

[[package]]
name = "num-modular"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17bb261bf36fa7d83f4c294f834e91256769097b3cb505d44831e0a179ac647f"

[[package]]
name = "num-order"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "537b596b97c40fcf8056d153049eb22f481c17ebce72a513ec9286e4986d1bb6"
dependencies = [
"num-modular",
]

[[package]]
name = "num-traits"
version = "0.2.19"
Expand Down
Loading
Loading