Skip to content

Commit c2ec908

Browse files
committed
Auto merge of rust-lang#118395 - compiler-errors:rollup-c8yqlmw, r=compiler-errors
Rollup of 9 pull requests Successful merges: - rust-lang#111133 (Detect Python-like slicing and suggest how to fix) - rust-lang#114708 (Allow setting `rla` labels via `rustbot`) - rust-lang#117526 (Account for `!` arm in tail `match` expr) - rust-lang#118172 (Add `pretty_terminator` to pretty stable-mir) - rust-lang#118202 (Added linker_arg(s) Linker trait methods for link-arg to be prefixed "-Wl," for cc-like linker args and not verbatim) - rust-lang#118374 (QueryContext: rename try_collect_active_jobs -> collect_active_jobs, change return type from Option<QueryMap> to QueryMap) - rust-lang#118381 (rustc_span: Use correct edit distance start length for suggestions) - rust-lang#118382 (Address unused tuple struct fields in the compiler) - rust-lang#118384 (Address unused tuple struct fields in rustdoc) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 49b3924 + 2aca724 commit c2ec908

File tree

33 files changed

+510
-103
lines changed

33 files changed

+510
-103
lines changed

compiler/rustc_ast/src/token.rs

+5
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,11 @@ impl Token {
756756
)
757757
}
758758

759+
/// Returns `true` if the token is the integer literal.
760+
pub fn is_integer_lit(&self) -> bool {
761+
matches!(self.kind, Literal(Lit { kind: LitKind::Integer, .. }))
762+
}
763+
759764
/// Returns `true` if the token is a non-raw identifier for which `pred` holds.
760765
pub fn is_non_raw_ident_where(&self, pred: impl FnOnce(Ident) -> bool) -> bool {
761766
match self.ident() {

compiler/rustc_borrowck/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use rustc_target::abi::FieldIdx;
4242
use smallvec::SmallVec;
4343
use std::cell::RefCell;
4444
use std::collections::BTreeMap;
45+
use std::marker::PhantomData;
4546
use std::ops::Deref;
4647
use std::rc::Rc;
4748

@@ -100,7 +101,7 @@ use renumber::RegionCtxt;
100101
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
101102

102103
/// Associate some local constants with the `'tcx` lifetime
103-
struct TyCtxtConsts<'tcx>(TyCtxt<'tcx>);
104+
struct TyCtxtConsts<'tcx>(PhantomData<&'tcx ()>);
104105
impl<'tcx> TyCtxtConsts<'tcx> {
105106
const DEREF_PROJECTION: &'tcx [PlaceElem<'tcx>; 1] = &[ProjectionElem::Deref];
106107
}

compiler/rustc_codegen_ssa/src/back/link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use tempfile::Builder as TempFileBuilder;
4444
use itertools::Itertools;
4545
use std::cell::OnceCell;
4646
use std::collections::BTreeSet;
47-
use std::ffi::OsString;
47+
use std::ffi::{OsStr, OsString};
4848
use std::fs::{read, File, OpenOptions};
4949
use std::io::{BufWriter, Write};
5050
use std::ops::Deref;
@@ -2527,7 +2527,7 @@ fn add_native_libs_from_crate(
25272527
NativeLibKind::WasmImportModule => {}
25282528
NativeLibKind::LinkArg => {
25292529
if link_static {
2530-
cmd.arg(name);
2530+
cmd.linker_arg(OsStr::new(name), verbatim);
25312531
}
25322532
}
25332533
}

compiler/rustc_codegen_ssa/src/back/linker.rs

+38-32
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ pub trait Linker {
196196
fn add_no_exec(&mut self) {}
197197
fn add_as_needed(&mut self) {}
198198
fn reset_per_library_state(&mut self) {}
199+
fn linker_arg(&mut self, arg: &OsStr, verbatim: bool) {
200+
self.linker_args(&[arg], verbatim);
201+
}
202+
fn linker_args(&mut self, args: &[&OsStr], _verbatim: bool) {
203+
args.into_iter().for_each(|a| {
204+
self.cmd().arg(a);
205+
});
206+
}
199207
}
200208

201209
impl dyn Linker + '_ {
@@ -223,38 +231,12 @@ pub struct GccLinker<'a> {
223231
}
224232

225233
impl<'a> GccLinker<'a> {
226-
/// Passes an argument directly to the linker.
227-
///
228-
/// When the linker is not ld-like such as when using a compiler as a linker, the argument is
229-
/// prepended by `-Wl,`.
230-
fn linker_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
231-
self.linker_args(&[arg]);
232-
self
234+
fn linker_arg(&mut self, arg: impl AsRef<OsStr>) {
235+
Linker::linker_arg(self, arg.as_ref(), false);
233236
}
234-
235-
/// Passes a series of arguments directly to the linker.
236-
///
237-
/// When the linker is ld-like, the arguments are simply appended to the command. When the
238-
/// linker is not ld-like such as when using a compiler as a linker, the arguments are joined by
239-
/// commas to form an argument that is then prepended with `-Wl`. In this situation, only a
240-
/// single argument is appended to the command to ensure that the order of the arguments is
241-
/// preserved by the compiler.
242-
fn linker_args(&mut self, args: &[impl AsRef<OsStr>]) -> &mut Self {
243-
if self.is_ld {
244-
args.into_iter().for_each(|a| {
245-
self.cmd.arg(a);
246-
});
247-
} else {
248-
if !args.is_empty() {
249-
let mut s = OsString::from("-Wl");
250-
for a in args {
251-
s.push(",");
252-
s.push(a);
253-
}
254-
self.cmd.arg(s);
255-
}
256-
}
257-
self
237+
fn linker_args(&mut self, args: &[impl AsRef<OsStr>]) {
238+
let args_vec: Vec<&OsStr> = args.iter().map(|x| x.as_ref()).collect();
239+
Linker::linker_args(self, &args_vec, false);
258240
}
259241

260242
fn takes_hints(&self) -> bool {
@@ -361,6 +343,30 @@ impl<'a> GccLinker<'a> {
361343
}
362344

363345
impl<'a> Linker for GccLinker<'a> {
346+
/// Passes a series of arguments directly to the linker.
347+
///
348+
/// When the linker is ld-like, the arguments are simply appended to the command. When the
349+
/// linker is not ld-like such as when using a compiler as a linker, the arguments are joined by
350+
/// commas to form an argument that is then prepended with `-Wl`. In this situation, only a
351+
/// single argument is appended to the command to ensure that the order of the arguments is
352+
/// preserved by the compiler.
353+
fn linker_args(&mut self, args: &[&OsStr], verbatim: bool) {
354+
if self.is_ld || verbatim {
355+
args.into_iter().for_each(|a| {
356+
self.cmd.arg(a);
357+
});
358+
} else {
359+
if !args.is_empty() {
360+
let mut s = OsString::from("-Wl");
361+
for a in args {
362+
s.push(",");
363+
s.push(a);
364+
}
365+
self.cmd.arg(s);
366+
}
367+
}
368+
}
369+
364370
fn cmd(&mut self) -> &mut Command {
365371
&mut self.cmd
366372
}
@@ -531,7 +537,7 @@ impl<'a> Linker for GccLinker<'a> {
531537
self.linker_arg("-force_load");
532538
self.linker_arg(&lib);
533539
} else {
534-
self.linker_arg("--whole-archive").cmd.arg(lib);
540+
self.linker_args(&[OsString::from("--whole-archive"), lib.into()]);
535541
self.linker_arg("--no-whole-archive");
536542
}
537543
}

compiler/rustc_hir_typeck/src/_match.rs

+35-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
139139
&cause,
140140
Some(arm.body),
141141
arm_ty,
142-
|err| self.suggest_removing_semicolon_for_coerce(err, expr, arm_ty, prior_arm),
142+
|err| {
143+
self.explain_never_type_coerced_to_unit(err, arm, arm_ty, prior_arm, expr);
144+
},
143145
false,
144146
);
145147

@@ -177,6 +179,38 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
177179
coercion.complete(self)
178180
}
179181

182+
fn explain_never_type_coerced_to_unit(
183+
&self,
184+
err: &mut Diagnostic,
185+
arm: &hir::Arm<'tcx>,
186+
arm_ty: Ty<'tcx>,
187+
prior_arm: Option<(Option<hir::HirId>, Ty<'tcx>, Span)>,
188+
expr: &hir::Expr<'tcx>,
189+
) {
190+
if let hir::ExprKind::Block(block, _) = arm.body.kind
191+
&& let Some(expr) = block.expr
192+
&& let arm_tail_ty = self.node_ty(expr.hir_id)
193+
&& arm_tail_ty.is_never()
194+
&& !arm_ty.is_never()
195+
{
196+
err.span_label(
197+
expr.span,
198+
format!(
199+
"this expression is of type `!`, but it is coerced to `{arm_ty}` due to its \
200+
surrounding expression",
201+
),
202+
);
203+
self.suggest_mismatched_types_on_tail(
204+
err,
205+
expr,
206+
arm_ty,
207+
prior_arm.map_or(arm_tail_ty, |(_, ty, _)| ty),
208+
expr.hir_id,
209+
);
210+
}
211+
self.suggest_removing_semicolon_for_coerce(err, expr, arm_ty, prior_arm)
212+
}
213+
180214
fn suggest_removing_semicolon_for_coerce(
181215
&self,
182216
diag: &mut Diagnostic,

compiler/rustc_hir_typeck/src/coercion.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
17151715
// label pointing out the cause for the type coercion will be wrong
17161716
// as prior return coercions would not be relevant (#57664).
17171717
let fn_decl = if let (Some(expr), Some(blk_id)) = (expression, blk_id) {
1718+
fcx.suggest_missing_semicolon(&mut err, expr, expected, false);
17181719
let pointing_at_return_type =
17191720
fcx.suggest_mismatched_types_on_tail(&mut err, expr, expected, found, blk_id);
17201721
if let (Some(cond_expr), true, false) = (

compiler/rustc_hir_typeck/src/expr.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
663663
coerce.coerce_forced_unit(
664664
self,
665665
&cause,
666-
|err| {
667-
self.suggest_mismatched_types_on_tail(err, expr, ty, e_ty, target_id);
666+
|mut err| {
667+
self.suggest_missing_semicolon(&mut err, expr, e_ty, false);
668+
self.suggest_mismatched_types_on_tail(
669+
&mut err, expr, ty, e_ty, target_id,
670+
);
668671
let error = Some(Sorts(ExpectedFound { expected: ty, found: e_ty }));
669672
self.annotate_loop_expected_due_to_inference(err, expr, error);
670673
if let Some(val) = ty_kind_suggestion(ty) {

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7272
blk_id: hir::HirId,
7373
) -> bool {
7474
let expr = expr.peel_drop_temps();
75-
self.suggest_missing_semicolon(err, expr, expected, false);
7675
let mut pointing_at_return_type = false;
7776
if let hir::ExprKind::Break(..) = expr.kind {
7877
// `break` type mismatches provide better context for tail `loop` expressions.

compiler/rustc_interface/src/util.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,8 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
126126
.deadlock_handler(|| {
127127
// On deadlock, creates a new thread and forwards information in thread
128128
// locals to it. The new thread runs the deadlock handler.
129-
let query_map = FromDyn::from(tls::with(|tcx| {
130-
QueryCtxt::new(tcx)
131-
.try_collect_active_jobs()
132-
.expect("active jobs shouldn't be locked in deadlock handler")
133-
}));
129+
let query_map =
130+
FromDyn::from(tls::with(|tcx| QueryCtxt::new(tcx).collect_active_jobs()));
134131
let registry = rayon_core::Registry::current();
135132
thread::spawn(move || deadlock(query_map.into_inner(), &registry));
136133
});

compiler/rustc_mir_transform/src/check_unsafety.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ pub(crate) fn provide(providers: &mut Providers) {
385385
enum Context {
386386
Safe,
387387
/// in an `unsafe fn`
388-
UnsafeFn(HirId),
388+
UnsafeFn,
389389
/// in a *used* `unsafe` block
390390
/// (i.e. a block without unused-unsafe warning)
391391
UnsafeBlock(HirId),
@@ -407,7 +407,7 @@ impl<'tcx> intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'_, 'tcx> {
407407
};
408408
let unused_unsafe = match (self.context, used) {
409409
(_, false) => UnusedUnsafe::Unused,
410-
(Context::Safe, true) | (Context::UnsafeFn(_), true) => {
410+
(Context::Safe, true) | (Context::UnsafeFn, true) => {
411411
let previous_context = self.context;
412412
self.context = Context::UnsafeBlock(block.hir_id);
413413
intravisit::walk_block(self, block);
@@ -454,7 +454,7 @@ fn check_unused_unsafe(
454454
let body = tcx.hir().body(body_id);
455455
let hir_id = tcx.local_def_id_to_hir_id(def_id);
456456
let context = match tcx.hir().fn_sig_by_hir_id(hir_id) {
457-
Some(sig) if sig.header.unsafety == hir::Unsafety::Unsafe => Context::UnsafeFn(hir_id),
457+
Some(sig) if sig.header.unsafety == hir::Unsafety::Unsafe => Context::UnsafeFn,
458458
_ => Context::Safe,
459459
};
460460

compiler/rustc_parse/src/parser/stmt.rs

+28-11
Original file line numberDiff line numberDiff line change
@@ -567,20 +567,37 @@ impl<'a> Parser<'a> {
567567
snapshot.recover_diff_marker();
568568
}
569569
if self.token == token::Colon {
570-
// if next token is following a colon, it's likely a path
571-
// and we can suggest a path separator
572-
self.bump();
573-
if self.token.span.lo() == self.prev_token.span.hi() {
570+
// if a previous and next token of the current one is
571+
// integer literal (e.g. `1:42`), it's likely a range
572+
// expression for Pythonistas and we can suggest so.
573+
if self.prev_token.is_integer_lit()
574+
&& self.may_recover()
575+
&& self.look_ahead(1, |token| token.is_integer_lit())
576+
{
577+
// FIXME(hkmatsumoto): Might be better to trigger
578+
// this only when parsing an index expression.
574579
err.span_suggestion_verbose(
575-
self.prev_token.span,
576-
"maybe write a path separator here",
577-
"::",
580+
self.token.span,
581+
"you might have meant a range expression",
582+
"..",
578583
Applicability::MaybeIncorrect,
579584
);
580-
}
581-
if self.sess.unstable_features.is_nightly_build() {
582-
// FIXME(Nilstrieb): Remove this again after a few months.
583-
err.note("type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>");
585+
} else {
586+
// if next token is following a colon, it's likely a path
587+
// and we can suggest a path separator
588+
self.bump();
589+
if self.token.span.lo() == self.prev_token.span.hi() {
590+
err.span_suggestion_verbose(
591+
self.prev_token.span,
592+
"maybe write a path separator here",
593+
"::",
594+
Applicability::MaybeIncorrect,
595+
);
596+
}
597+
if self.sess.unstable_features.is_nightly_build() {
598+
// FIXME(Nilstrieb): Remove this again after a few months.
599+
err.note("type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>");
600+
}
584601
}
585602
}
586603

compiler/rustc_query_impl/src/plumbing.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ impl QueryContext for QueryCtxt<'_> {
8080
tls::with_related_context(self.tcx, |icx| icx.query)
8181
}
8282

83-
fn try_collect_active_jobs(self) -> Option<QueryMap> {
83+
fn collect_active_jobs(self) -> QueryMap {
8484
let mut jobs = QueryMap::default();
8585

8686
for collect in super::TRY_COLLECT_ACTIVE_JOBS.iter() {
8787
collect(self.tcx, &mut jobs);
8888
}
8989

90-
Some(jobs)
90+
jobs
9191
}
9292

9393
// Interactions with on_disk_cache
@@ -155,11 +155,11 @@ impl QueryContext for QueryCtxt<'_> {
155155
fn depth_limit_error(self, job: QueryJobId) {
156156
let mut span = None;
157157
let mut layout_of_depth = None;
158-
if let Some(map) = self.try_collect_active_jobs() {
159-
if let Some((info, depth)) = job.try_find_layout_root(map, dep_kinds::layout_of) {
160-
span = Some(info.job.span);
161-
layout_of_depth = Some(LayoutOfDepth { desc: info.query.description, depth });
162-
}
158+
if let Some((info, depth)) =
159+
job.try_find_layout_root(self.collect_active_jobs(), dep_kinds::layout_of)
160+
{
161+
span = Some(info.job.span);
162+
layout_of_depth = Some(LayoutOfDepth { desc: info.query.description, depth });
163163
}
164164

165165
let suggested_limit = match self.recursion_limit() {

compiler/rustc_query_system/src/query/job.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -620,13 +620,13 @@ pub fn print_query_stack<Qcx: QueryContext>(
620620
// state if it was responsible for triggering the panic.
621621
let mut count_printed = 0;
622622
let mut count_total = 0;
623-
let query_map = qcx.try_collect_active_jobs();
623+
let query_map = qcx.collect_active_jobs();
624624

625625
if let Some(ref mut file) = file {
626626
let _ = writeln!(file, "\n\nquery stack during panic:");
627627
}
628628
while let Some(query) = current_query {
629-
let Some(query_info) = query_map.as_ref().and_then(|map| map.get(&query)) else {
629+
let Some(query_info) = query_map.get(&query) else {
630630
break;
631631
};
632632
if Some(count_printed) < num_frames || num_frames.is_none() {

compiler/rustc_query_system/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub trait QueryContext: HasDepContext {
106106
/// Get the query information from the TLS context.
107107
fn current_query_job(self) -> Option<QueryJobId>;
108108

109-
fn try_collect_active_jobs(self) -> Option<QueryMap>;
109+
fn collect_active_jobs(self) -> QueryMap;
110110

111111
/// Load side effects associated to the node in the previous session.
112112
fn load_side_effects(self, prev_dep_node_index: SerializedDepNodeIndex) -> QuerySideEffects;

compiler/rustc_query_system/src/query/plumbing.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,8 @@ where
242242
Q: QueryConfig<Qcx>,
243243
Qcx: QueryContext,
244244
{
245-
let error = try_execute.find_cycle_in_stack(
246-
qcx.try_collect_active_jobs().unwrap(),
247-
&qcx.current_query_job(),
248-
span,
249-
);
245+
let error =
246+
try_execute.find_cycle_in_stack(qcx.collect_active_jobs(), &qcx.current_query_job(), span);
250247
(mk_cycle(query, qcx, error), None)
251248
}
252249

0 commit comments

Comments
 (0)