Skip to content

Commit 493c960

Browse files
committed
Auto merge of rust-lang#98656 - Dylan-DPC:rollup-hhytn0c, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - rust-lang#97423 (Simplify memory ordering intrinsics) - rust-lang#97542 (Use typed indices in argument mismatch algorithm) - rust-lang#97786 (Account for `-Z simulate-remapped-rust-src-base` when resolving remapped paths) - rust-lang#98277 (Fix trait object reborrow suggestion) - rust-lang#98525 (Add regression test for rust-lang#79224) - rust-lang#98549 (interpret: do not prune requires_caller_location stack frames quite so early) - rust-lang#98603 (Some borrowck diagnostic fixes) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 116edb6 + 25fb2b4 commit 493c960

File tree

85 files changed

+1785
-1246
lines changed

Some content is hidden

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

85 files changed

+1785
-1246
lines changed

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

+7-46
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_middle::ty;
44
use rustc_mir_dataflow::move_paths::{
55
IllegalMoveOrigin, IllegalMoveOriginKind, LookupResult, MoveError, MovePathIndex,
66
};
7-
use rustc_span::{sym, Span};
7+
use rustc_span::Span;
88

99
use crate::diagnostics::UseSpans;
1010
use crate::prefixes::PrefixSet;
@@ -218,29 +218,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
218218

219219
fn report(&mut self, error: GroupedMoveError<'tcx>) {
220220
let (mut err, err_span) = {
221-
let (span, use_spans, original_path, kind, has_complex_bindings): (
222-
Span,
223-
Option<UseSpans<'tcx>>,
224-
Place<'tcx>,
225-
&IllegalMoveOriginKind<'_>,
226-
bool,
227-
) = match error {
228-
GroupedMoveError::MovesFromPlace {
229-
span,
230-
original_path,
231-
ref kind,
232-
ref binds_to,
233-
..
221+
let (span, use_spans, original_path, kind) = match error {
222+
GroupedMoveError::MovesFromPlace { span, original_path, ref kind, .. }
223+
| GroupedMoveError::MovesFromValue { span, original_path, ref kind, .. } => {
224+
(span, None, original_path, kind)
234225
}
235-
| GroupedMoveError::MovesFromValue {
236-
span,
237-
original_path,
238-
ref kind,
239-
ref binds_to,
240-
..
241-
} => (span, None, original_path, kind, !binds_to.is_empty()),
242226
GroupedMoveError::OtherIllegalMove { use_spans, original_path, ref kind } => {
243-
(use_spans.args_or_use(), Some(use_spans), original_path, kind, false)
227+
(use_spans.args_or_use(), Some(use_spans), original_path, kind)
244228
}
245229
};
246230
debug!(
@@ -259,7 +243,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
259243
target_place,
260244
span,
261245
use_spans,
262-
has_complex_bindings,
263246
),
264247
&IllegalMoveOriginKind::InteriorOfTypeWithDestructor { container_ty: ty } => {
265248
self.cannot_move_out_of_interior_of_drop(span, ty)
@@ -302,7 +285,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
302285
deref_target_place: Place<'tcx>,
303286
span: Span,
304287
use_spans: Option<UseSpans<'tcx>>,
305-
has_complex_bindings: bool,
306288
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
307289
// Inspect the type of the content behind the
308290
// borrow to provide feedback about why this
@@ -399,28 +381,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
399381
}
400382
}
401383
};
402-
let ty = move_place.ty(self.body, self.infcx.tcx).ty;
403-
let def_id = match *ty.kind() {
404-
ty::Adt(self_def, _) => self_def.did(),
405-
ty::Foreign(def_id)
406-
| ty::FnDef(def_id, _)
407-
| ty::Closure(def_id, _)
408-
| ty::Generator(def_id, ..)
409-
| ty::Opaque(def_id, _) => def_id,
410-
_ => return err,
411-
};
412-
let diag_name = self.infcx.tcx.get_diagnostic_name(def_id);
413-
if matches!(diag_name, Some(sym::Option | sym::Result))
414-
&& use_spans.map_or(true, |v| !v.for_closure())
415-
&& !has_complex_bindings
416-
{
417-
err.span_suggestion_verbose(
418-
span.shrink_to_hi(),
419-
&format!("consider borrowing the `{}`'s content", diag_name.unwrap()),
420-
".as_ref()",
421-
Applicability::MaybeIncorrect,
422-
);
423-
} else if let Some(use_spans) = use_spans {
384+
if let Some(use_spans) = use_spans {
424385
self.explain_captures(
425386
&mut err, span, span, use_spans, move_place, None, "", "", "", false, true,
426387
);

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+30-25
Original file line numberDiff line numberDiff line change
@@ -434,16 +434,16 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
434434

435435
match self.local_names[local] {
436436
Some(name) if !local_decl.from_compiler_desugaring() => {
437-
let label = match local_decl.local_info.as_ref().unwrap() {
438-
box LocalInfo::User(ClearCrossCrate::Set(
437+
let label = match local_decl.local_info.as_deref().unwrap() {
438+
LocalInfo::User(ClearCrossCrate::Set(
439439
mir::BindingForm::ImplicitSelf(_),
440440
)) => {
441441
let (span, suggestion) =
442442
suggest_ampmut_self(self.infcx.tcx, local_decl);
443443
Some((true, span, suggestion))
444444
}
445445

446-
box LocalInfo::User(ClearCrossCrate::Set(mir::BindingForm::Var(
446+
LocalInfo::User(ClearCrossCrate::Set(mir::BindingForm::Var(
447447
mir::VarBindingForm {
448448
binding_mode: ty::BindingMode::BindByValue(_),
449449
opt_ty_info,
@@ -473,20 +473,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
473473
// on for loops, RHS points to the iterator part
474474
Some(DesugaringKind::ForLoop) => {
475475
self.suggest_similar_mut_method_for_for_loop(&mut err);
476-
Some((
477-
false,
478-
opt_assignment_rhs_span.unwrap(),
479-
format!(
480-
"this iterator yields `{SIGIL}` {DESC}s",
481-
SIGIL = pointer_sigil,
482-
DESC = pointer_desc
483-
),
484-
))
476+
err.span_label(opt_assignment_rhs_span.unwrap(), format!(
477+
"this iterator yields `{pointer_sigil}` {pointer_desc}s",
478+
));
479+
None
485480
}
486481
// don't create labels for compiler-generated spans
487482
Some(_) => None,
488483
None => {
489-
let (span, suggestion) = if name != kw::SelfLower {
484+
let label = if name != kw::SelfLower {
490485
suggest_ampmut(
491486
self.infcx.tcx,
492487
local_decl,
@@ -501,7 +496,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
501496
..
502497
}),
503498
))) => {
504-
suggest_ampmut_self(self.infcx.tcx, local_decl)
499+
let (span, sugg) = suggest_ampmut_self(
500+
self.infcx.tcx,
501+
local_decl,
502+
);
503+
(true, span, sugg)
505504
}
506505
// explicit self (eg `self: &'a Self`)
507506
_ => suggest_ampmut(
@@ -512,12 +511,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
512511
),
513512
}
514513
};
515-
Some((true, span, suggestion))
514+
Some(label)
516515
}
517516
}
518517
}
519518

520-
box LocalInfo::User(ClearCrossCrate::Set(mir::BindingForm::Var(
519+
LocalInfo::User(ClearCrossCrate::Set(mir::BindingForm::Var(
521520
mir::VarBindingForm {
522521
binding_mode: ty::BindingMode::BindByReference(_),
523522
..
@@ -528,7 +527,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
528527
.map(|replacement| (true, pattern_span, replacement))
529528
}
530529

531-
box LocalInfo::User(ClearCrossCrate::Clear) => {
530+
LocalInfo::User(ClearCrossCrate::Clear) => {
532531
bug!("saw cleared local state")
533532
}
534533

@@ -559,7 +558,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
559558
}
560559
}
561560
Some((false, err_label_span, message)) => {
562-
err.span_label(err_label_span, &message);
561+
err.span_label(
562+
err_label_span,
563+
&format!(
564+
"consider changing this binding's type to be: `{message}`"
565+
),
566+
);
563567
}
564568
None => {}
565569
}
@@ -1004,7 +1008,7 @@ fn suggest_ampmut<'tcx>(
10041008
local_decl: &mir::LocalDecl<'tcx>,
10051009
opt_assignment_rhs_span: Option<Span>,
10061010
opt_ty_info: Option<Span>,
1007-
) -> (Span, String) {
1011+
) -> (bool, Span, String) {
10081012
if let Some(assignment_rhs_span) = opt_assignment_rhs_span
10091013
&& let Ok(src) = tcx.sess.source_map().span_to_snippet(assignment_rhs_span)
10101014
{
@@ -1028,37 +1032,38 @@ fn suggest_ampmut<'tcx>(
10281032
let lt_name = &src[1..ws_pos];
10291033
let ty = src[ws_pos..].trim_start();
10301034
if !is_mutbl(ty) {
1031-
return (assignment_rhs_span, format!("&{lt_name} mut {ty}"));
1035+
return (true, assignment_rhs_span, format!("&{lt_name} mut {ty}"));
10321036
}
10331037
} else if let Some(stripped) = src.strip_prefix('&') {
10341038
let stripped = stripped.trim_start();
10351039
if !is_mutbl(stripped) {
1036-
return (assignment_rhs_span, format!("&mut {stripped}"));
1040+
return (true, assignment_rhs_span, format!("&mut {stripped}"));
10371041
}
10381042
}
10391043
}
10401044

1041-
let highlight_span = match opt_ty_info {
1045+
let (suggestability, highlight_span) = match opt_ty_info {
10421046
// if this is a variable binding with an explicit type,
10431047
// try to highlight that for the suggestion.
1044-
Some(ty_span) => ty_span,
1048+
Some(ty_span) => (true, ty_span),
10451049

10461050
// otherwise, just highlight the span associated with
10471051
// the (MIR) LocalDecl.
1048-
None => local_decl.source_info.span,
1052+
None => (false, local_decl.source_info.span),
10491053
};
10501054

10511055
if let Ok(src) = tcx.sess.source_map().span_to_snippet(highlight_span)
10521056
&& let (true, Some(ws_pos)) = (src.starts_with("&'"), src.find(char::is_whitespace))
10531057
{
10541058
let lt_name = &src[1..ws_pos];
10551059
let ty = &src[ws_pos..];
1056-
return (highlight_span, format!("&{} mut{}", lt_name, ty));
1060+
return (true, highlight_span, format!("&{} mut{}", lt_name, ty));
10571061
}
10581062

10591063
let ty_mut = local_decl.ty.builtin_deref(true).unwrap();
10601064
assert_eq!(ty_mut.mutbl, hir::Mutability::Not);
10611065
(
1066+
suggestability,
10621067
highlight_span,
10631068
if local_decl.ty.is_region_ptr() {
10641069
format!("&mut {}", ty_mut.ty)

compiler/rustc_codegen_ssa/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(associated_type_bounds)]
77
#![feature(strict_provenance)]
88
#![feature(int_roundings)]
9+
#![feature(if_let_guard)]
910
#![recursion_limit = "256"]
1011
#![allow(rustc::potential_query_instability)]
1112

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

+26-32
Original file line numberDiff line numberDiff line change
@@ -376,32 +376,23 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
376376
}
377377

378378
// This requires that atomic intrinsics follow a specific naming pattern:
379-
// "atomic_<operation>[_<ordering>]", and no ordering means SeqCst
380-
name if name_str.starts_with("atomic_") => {
379+
// "atomic_<operation>[_<ordering>]"
380+
name if let Some(atomic) = name_str.strip_prefix("atomic_") => {
381381
use crate::common::AtomicOrdering::*;
382382
use crate::common::{AtomicRmwBinOp, SynchronizationScope};
383383

384-
let split: Vec<_> = name_str.split('_').collect();
385-
386-
let is_cxchg = split[1] == "cxchg" || split[1] == "cxchgweak";
387-
let (order, failorder) = match split.len() {
388-
2 => (SequentiallyConsistent, SequentiallyConsistent),
389-
3 => match split[2] {
390-
"unordered" => (Unordered, Unordered),
391-
"relaxed" => (Relaxed, Relaxed),
392-
"acq" => (Acquire, Acquire),
393-
"rel" => (Release, Relaxed),
394-
"acqrel" => (AcquireRelease, Acquire),
395-
"failrelaxed" if is_cxchg => (SequentiallyConsistent, Relaxed),
396-
"failacq" if is_cxchg => (SequentiallyConsistent, Acquire),
397-
_ => bx.sess().fatal("unknown ordering in atomic intrinsic"),
398-
},
399-
4 => match (split[2], split[3]) {
400-
("acq", "failrelaxed") if is_cxchg => (Acquire, Relaxed),
401-
("acqrel", "failrelaxed") if is_cxchg => (AcquireRelease, Relaxed),
402-
_ => bx.sess().fatal("unknown ordering in atomic intrinsic"),
403-
},
404-
_ => bx.sess().fatal("Atomic intrinsic not in correct format"),
384+
let Some((instruction, ordering)) = atomic.split_once('_') else {
385+
bx.sess().fatal("Atomic intrinsic missing memory ordering");
386+
};
387+
388+
let parse_ordering = |bx: &Bx, s| match s {
389+
"unordered" => Unordered,
390+
"relaxed" => Relaxed,
391+
"acquire" => Acquire,
392+
"release" => Release,
393+
"acqrel" => AcquireRelease,
394+
"seqcst" => SequentiallyConsistent,
395+
_ => bx.sess().fatal("unknown ordering in atomic intrinsic"),
405396
};
406397

407398
let invalid_monomorphization = |ty| {
@@ -416,11 +407,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
416407
);
417408
};
418409

419-
match split[1] {
410+
match instruction {
420411
"cxchg" | "cxchgweak" => {
412+
let Some((success, failure)) = ordering.split_once('_') else {
413+
bx.sess().fatal("Atomic compare-exchange intrinsic missing failure memory ordering");
414+
};
421415
let ty = substs.type_at(0);
422416
if int_type_width_signed(ty, bx.tcx()).is_some() || ty.is_unsafe_ptr() {
423-
let weak = split[1] == "cxchgweak";
417+
let weak = instruction == "cxchgweak";
424418
let mut dst = args[0].immediate();
425419
let mut cmp = args[1].immediate();
426420
let mut src = args[2].immediate();
@@ -432,7 +426,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
432426
cmp = bx.ptrtoint(cmp, bx.type_isize());
433427
src = bx.ptrtoint(src, bx.type_isize());
434428
}
435-
let pair = bx.atomic_cmpxchg(dst, cmp, src, order, failorder, weak);
429+
let pair = bx.atomic_cmpxchg(dst, cmp, src, parse_ordering(bx, success), parse_ordering(bx, failure), weak);
436430
let val = bx.extract_value(pair, 0);
437431
let success = bx.extract_value(pair, 1);
438432
let val = bx.from_immediate(val);
@@ -460,11 +454,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
460454
let llty = bx.type_isize();
461455
let ptr_llty = bx.type_ptr_to(llty);
462456
source = bx.pointercast(source, ptr_llty);
463-
let result = bx.atomic_load(llty, source, order, size);
457+
let result = bx.atomic_load(llty, source, parse_ordering(bx, ordering), size);
464458
// ... and then cast the result back to a pointer
465459
bx.inttoptr(result, bx.backend_type(layout))
466460
} else {
467-
bx.atomic_load(bx.backend_type(layout), source, order, size)
461+
bx.atomic_load(bx.backend_type(layout), source, parse_ordering(bx, ordering), size)
468462
}
469463
} else {
470464
return invalid_monomorphization(ty);
@@ -484,20 +478,20 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
484478
ptr = bx.pointercast(ptr, ptr_llty);
485479
val = bx.ptrtoint(val, bx.type_isize());
486480
}
487-
bx.atomic_store(val, ptr, order, size);
481+
bx.atomic_store(val, ptr, parse_ordering(bx, ordering), size);
488482
return;
489483
} else {
490484
return invalid_monomorphization(ty);
491485
}
492486
}
493487

494488
"fence" => {
495-
bx.atomic_fence(order, SynchronizationScope::CrossThread);
489+
bx.atomic_fence(parse_ordering(bx, ordering), SynchronizationScope::CrossThread);
496490
return;
497491
}
498492

499493
"singlethreadfence" => {
500-
bx.atomic_fence(order, SynchronizationScope::SingleThread);
494+
bx.atomic_fence(parse_ordering(bx, ordering), SynchronizationScope::SingleThread);
501495
return;
502496
}
503497

@@ -531,7 +525,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
531525
ptr = bx.pointercast(ptr, ptr_llty);
532526
val = bx.ptrtoint(val, bx.type_isize());
533527
}
534-
bx.atomic_rmw(atom_op, ptr, val, order)
528+
bx.atomic_rmw(atom_op, ptr, val, parse_ordering(bx, ordering))
535529
} else {
536530
return invalid_monomorphization(ty);
537531
}

compiler/rustc_const_eval/src/const_eval/error.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ impl<'tcx> ConstEvalErr<'tcx> {
8282
'tcx: 'mir,
8383
{
8484
error.print_backtrace();
85-
let stacktrace = ecx.generate_stacktrace();
86-
ConstEvalErr {
87-
error: error.into_kind(),
88-
stacktrace,
89-
span: span.unwrap_or_else(|| ecx.cur_span()),
90-
}
85+
let mut stacktrace = ecx.generate_stacktrace();
86+
// Filter out `requires_caller_location` frames.
87+
stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*ecx.tcx));
88+
// If `span` is missing, use topmost remaining frame, or else the "root" span from `ecx.tcx`.
89+
let span = span.or_else(|| stacktrace.first().map(|f| f.span)).unwrap_or(ecx.tcx.span);
90+
ConstEvalErr { error: error.into_kind(), stacktrace, span }
9191
}
9292

9393
pub fn struct_error(

0 commit comments

Comments
 (0)