Skip to content

Commit 7942405

Browse files
committed
Auto merge of #123869 - matthiaskrgr:rollup-9kif9c9, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #123654 (typeck: fix `?` suggestion span) - #123807 (Remove `sys_common::thread`) - #123834 (Don't do coroutine-closure-specific upvar analysis if tainted by errors) - #123847 (Suppress `let else` suggestion for uninitialized refutable `let`s) - #123857 (std::net: TcpListener shrinks the backlog argument to 32 for Haiku.) - #123858 (zkvm: fix path to cmath in zkvm module) - #123867 (Add `unsafe` to two functions with safety invariants) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 22a2425 + 3026204 commit 7942405

23 files changed

+230
-145
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,12 +1287,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12871287
ty::TraitRef::new(self.tcx, into_def_id, [expr_ty, expected_ty]),
12881288
))
12891289
{
1290-
let mut span = expr.span;
1291-
while expr.span.eq_ctxt(span)
1292-
&& let Some(parent_callsite) = span.parent_callsite()
1293-
{
1294-
span = parent_callsite;
1295-
}
1290+
let span = expr.span.find_oldest_ancestor_in_same_ctxt();
12961291

12971292
let mut sugg = if expr.precedence().order() >= PREC_POSTFIX {
12981293
vec![(span.shrink_to_hi(), ".into()".to_owned())]
@@ -1897,12 +1892,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18971892
None => sugg.to_string(),
18981893
};
18991894

1900-
err.span_suggestion_verbose(
1901-
expr.span.shrink_to_hi(),
1902-
msg,
1903-
sugg,
1904-
Applicability::HasPlaceholders,
1905-
);
1895+
let span = expr.span.find_oldest_ancestor_in_same_ctxt();
1896+
err.span_suggestion_verbose(span.shrink_to_hi(), msg, sugg, Applicability::HasPlaceholders);
19061897
return true;
19071898
}
19081899

compiler/rustc_hir_typeck/src/upvar.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection, Pro
4343
use rustc_middle::mir::FakeReadCause;
4444
use rustc_middle::traits::ObligationCauseCode;
4545
use rustc_middle::ty::{
46-
self, ClosureSizeProfileData, Ty, TyCtxt, TypeckResults, UpvarArgs, UpvarCapture,
46+
self, ClosureSizeProfileData, Ty, TyCtxt, TypeVisitableExt as _, TypeckResults, UpvarArgs,
47+
UpvarCapture,
4748
};
4849
use rustc_session::lint;
4950
use rustc_span::sym;
@@ -191,6 +192,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
191192
);
192193
}
193194
};
195+
let args = self.resolve_vars_if_possible(args);
194196
let closure_def_id = closure_def_id.expect_local();
195197

196198
assert_eq!(self.tcx.hir().body_owner_def_id(body.id()), closure_def_id);
@@ -361,7 +363,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
361363
// For coroutine-closures, we additionally must compute the
362364
// `coroutine_captures_by_ref_ty` type, which is used to generate the by-ref
363365
// version of the coroutine-closure's output coroutine.
364-
if let UpvarArgs::CoroutineClosure(args) = args {
366+
if let UpvarArgs::CoroutineClosure(args) = args
367+
&& !args.references_error()
368+
{
365369
let closure_env_region: ty::Region<'_> = ty::Region::new_bound(
366370
self.tcx,
367371
ty::INNERMOST,

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ impl<'tcx> CoroutineArgs<'tcx> {
771771
}
772772
}
773773

774-
#[derive(Debug, Copy, Clone, HashStable)]
774+
#[derive(Debug, Copy, Clone, HashStable, TypeFoldable, TypeVisitable)]
775775
pub enum UpvarArgs<'tcx> {
776776
Closure(GenericArgsRef<'tcx>),
777777
Coroutine(GenericArgsRef<'tcx>),

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
674674
if let Some(span) = sp
675675
&& self.tcx.sess.source_map().is_span_accessible(span)
676676
&& interpreted_as_const.is_none()
677+
&& scrut.is_some()
677678
{
678679
let mut bindings = vec![];
679680
pat.each_binding(|name, _, _, _| bindings.push(name));

compiler/rustc_span/src/lib.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,45 @@ impl Span {
743743
Some(self)
744744
}
745745

746+
/// Recursively walk down the expansion ancestors to find the oldest ancestor span with the same
747+
/// [`SyntaxContext`] the initial span.
748+
///
749+
/// This method is suitable for peeling through *local* macro expansions to find the "innermost"
750+
/// span that is still local and shares the same [`SyntaxContext`]. For example, given
751+
///
752+
/// ```ignore (illustrative example, contains type error)
753+
/// macro_rules! outer {
754+
/// ($x: expr) => {
755+
/// inner!($x)
756+
/// }
757+
/// }
758+
///
759+
/// macro_rules! inner {
760+
/// ($x: expr) => {
761+
/// format!("error: {}", $x)
762+
/// //~^ ERROR mismatched types
763+
/// }
764+
/// }
765+
///
766+
/// fn bar(x: &str) -> Result<(), Box<dyn std::error::Error>> {
767+
/// Err(outer!(x))
768+
/// }
769+
/// ```
770+
///
771+
/// if provided the initial span of `outer!(x)` inside `bar`, this method will recurse
772+
/// the parent callsites until we reach `format!("error: {}", $x)`, at which point it is the
773+
/// oldest ancestor span that is both still local and shares the same [`SyntaxContext`] as the
774+
/// initial span.
775+
pub fn find_oldest_ancestor_in_same_ctxt(self) -> Span {
776+
let mut cur = self;
777+
while cur.eq_ctxt(self)
778+
&& let Some(parent_callsite) = cur.parent_callsite()
779+
{
780+
cur = parent_callsite;
781+
}
782+
cur
783+
}
784+
746785
/// Edition of the crate from which this span came.
747786
pub fn edition(self) -> edition::Edition {
748787
self.ctxt().edition()

library/std/src/sys/pal/windows/thread.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,31 @@ impl Thread {
4545
Err(io::Error::last_os_error())
4646
};
4747

48-
extern "system" fn thread_start(main: *mut c_void) -> c::DWORD {
49-
unsafe {
50-
// Next, reserve some stack space for if we otherwise run out of stack.
51-
stack_overflow::reserve_stack();
52-
// Finally, let's run some code.
53-
Box::from_raw(main as *mut Box<dyn FnOnce()>)();
54-
}
48+
unsafe extern "system" fn thread_start(main: *mut c_void) -> c::DWORD {
49+
// Next, reserve some stack space for if we otherwise run out of stack.
50+
stack_overflow::reserve_stack();
51+
// Finally, let's run some code.
52+
Box::from_raw(main as *mut Box<dyn FnOnce()>)();
5553
0
5654
}
5755
}
5856

5957
pub fn set_name(name: &CStr) {
6058
if let Ok(utf8) = name.to_str() {
6159
if let Ok(utf16) = to_u16s(utf8) {
62-
Self::set_name_wide(&utf16)
60+
unsafe {
61+
// SAFETY: the vec returned by `to_u16s` ends with a zero value
62+
Self::set_name_wide(&utf16)
63+
}
6364
};
6465
};
6566
}
6667

67-
pub fn set_name_wide(name: &[u16]) {
68-
unsafe {
69-
c::SetThreadDescription(c::GetCurrentThread(), name.as_ptr());
70-
};
68+
/// # Safety
69+
///
70+
/// `name` must end with a zero value
71+
pub unsafe fn set_name_wide(name: &[u16]) {
72+
c::SetThreadDescription(c::GetCurrentThread(), name.as_ptr());
7173
}
7274

7375
pub fn join(self) {

library/std/src/sys/pal/zkvm/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ const WORD_SIZE: usize = core::mem::size_of::<u32>();
1212
pub mod alloc;
1313
#[path = "../zkvm/args.rs"]
1414
pub mod args;
15-
#[path = "../unix/cmath.rs"]
16-
pub mod cmath;
1715
pub mod env;
1816
#[path = "../unsupported/fs.rs"]
1917
pub mod fs;

library/std/src/sys_common/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub mod fs;
2525
pub mod io;
2626
pub mod lazy_box;
2727
pub mod process;
28-
pub mod thread;
2928
pub mod thread_local_dtor;
3029
pub mod thread_parking;
3130
pub mod wstr;

library/std/src/sys_common/net.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,10 @@ impl TcpListener {
417417
// it allows up to about 37, but other times it doesn't even
418418
// accept 32. There may be a global limitation causing this.
419419
let backlog = 20;
420+
} else if #[cfg(target_os = "haiku")] {
421+
// Haiku does not support a queue length > 32
422+
// https://github.com/haiku/haiku/blob/979a0bc487864675517fb2fab28f87dc8bf43041/headers/posix/sys/socket.h#L81
423+
let backlog = 32;
420424
} else {
421425
// The default for all other platforms
422426
let backlog = 128;

library/std/src/sys_common/thread.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)