Skip to content

Commit 2d873b1

Browse files
committed
Auto merge of rust-lang#136378 - jhpratt:rollup-l4w55bm, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - rust-lang#133266 (ci: fix explanation why LLVM download is disabled for windows-gnu) - rust-lang#134740 (Add amdgpu target) - rust-lang#135836 (bootstrap: only build `crt{begin,end}.o` when compiling to MUSL) - rust-lang#136154 (Use +secure-plt for powerpc-unknown-linux-gnu{,spe}) - rust-lang#136279 (Rename `tcx.ensure()` to `tcx.ensure_ok()`, and improve the associated docs) - rust-lang#136283 (Update encode_utf16 to mention it is native endian) - rust-lang#136309 (set rustc dylib on manually constructed rustc command) - rust-lang#136328 (Rework "long type names" printing logic) - rust-lang#136339 (CompileTest: Add Directives to Ignore `arm-unknown-*` Targets) - rust-lang#136358 (`#[optimize(none)]` implies `#[inline(never)]`) - rust-lang#136368 (Make comma separated lists of anything easier to make for errors) r? `@ghost` `@rustbot` modify labels: rollup try-job: dist-powerpc64-linux
2 parents e08cd3c + d34b025 commit 2d873b1

File tree

115 files changed

+967
-1133
lines changed

Some content is hidden

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

115 files changed

+967
-1133
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,10 @@ fn compute_hir_hash(
418418
pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
419419
let sess = tcx.sess;
420420
// Queries that borrow `resolver_for_lowering`.
421-
tcx.ensure_with_value().output_filenames(());
422-
tcx.ensure_with_value().early_lint_checks(());
423-
tcx.ensure_with_value().debugger_visualizers(LOCAL_CRATE);
424-
tcx.ensure_with_value().get_lang_items(());
421+
tcx.ensure_done().output_filenames(());
422+
tcx.ensure_done().early_lint_checks(());
423+
tcx.ensure_done().debugger_visualizers(LOCAL_CRATE);
424+
tcx.ensure_done().get_lang_items(());
425425
let (mut resolver, krate) = tcx.resolver_for_lowering().steal();
426426

427427
let ast_index = index_crate(&resolver.node_id_to_def_id, &krate);

compiler/rustc_borrowck/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ borrowck_lifetime_constraints_error =
9292
borrowck_limitations_implies_static =
9393
due to current limitations in the borrow checker, this implies a `'static` lifetime
9494
95-
borrowck_long_type_consider_verbose = consider using `--verbose` to print the full type name to the console
96-
borrowck_long_type_full_path = the full type name has been written to '{$path}'
97-
9895
borrowck_move_closure_suggestion =
9996
consider adding 'move' keyword before the nested closure
10097

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
289289
None => "value".to_owned(),
290290
};
291291
if needs_note {
292-
let mut path = None;
293-
let ty = self.infcx.tcx.short_ty_string(ty, &mut path);
292+
let ty = self.infcx.tcx.short_string(ty, err.long_ty_path());
294293
if let Some(local) = place.as_local() {
295294
let span = self.body.local_decls[local].source_info.span;
296295
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
@@ -306,11 +305,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
306305
place: &note_msg,
307306
});
308307
};
309-
if let Some(path) = path {
310-
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
311-
path: path.display().to_string(),
312-
});
313-
}
314308
}
315309

316310
if let UseSpans::FnSelfUse {

compiler/rustc_borrowck/src/diagnostics/mod.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::collections::BTreeMap;
44

55
use rustc_abi::{FieldIdx, VariantIdx};
66
use rustc_data_structures::fx::FxIndexMap;
7-
use rustc_errors::{Applicability, Diag, EmissionGuarantee, MultiSpan};
7+
use rustc_errors::{Applicability, Diag, EmissionGuarantee, MultiSpan, listify};
88
use rustc_hir::def::{CtorKind, Namespace};
99
use rustc_hir::{self as hir, CoroutineKind, LangItem};
1010
use rustc_index::IndexSlice;
@@ -29,7 +29,7 @@ use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2929
use rustc_trait_selection::error_reporting::traits::call_kind::{CallDesugaringKind, call_kind};
3030
use rustc_trait_selection::infer::InferCtxtExt;
3131
use rustc_trait_selection::traits::{
32-
FulfillmentErrorCode, type_known_to_meet_bound_modulo_regions,
32+
FulfillmentError, FulfillmentErrorCode, type_known_to_meet_bound_modulo_regions,
3333
};
3434
use tracing::debug;
3535

@@ -1433,17 +1433,15 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
14331433
error.obligation.predicate,
14341434
)
14351435
}
1436-
[errors @ .., last] => {
1436+
_ => {
14371437
format!(
14381438
"you could `clone` the value and consume it, if the \
1439-
following trait bounds could be satisfied: \
1440-
{} and `{}`",
1441-
errors
1442-
.iter()
1443-
.map(|e| format!("`{}`", e.obligation.predicate))
1444-
.collect::<Vec<_>>()
1445-
.join(", "),
1446-
last.obligation.predicate,
1439+
following trait bounds could be satisfied: {}",
1440+
listify(&errors, |e: &FulfillmentError<'tcx>| format!(
1441+
"`{}`",
1442+
e.obligation.predicate
1443+
))
1444+
.unwrap(),
14471445
)
14481446
}
14491447
};

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

+3-21
Original file line numberDiff line numberDiff line change
@@ -596,19 +596,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
596596
self.suggest_cloning(err, place_ty, expr, None);
597597
}
598598

599-
let mut path = None;
600-
let ty = self.infcx.tcx.short_ty_string(place_ty, &mut path);
599+
let ty = self.infcx.tcx.short_string(place_ty, err.long_ty_path());
601600
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
602601
is_partial_move: false,
603602
ty,
604603
place: &place_desc,
605604
span,
606605
});
607-
if let Some(path) = path {
608-
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
609-
path: path.display().to_string(),
610-
});
611-
}
612606
} else {
613607
binds_to.sort();
614608
binds_to.dedup();
@@ -635,19 +629,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
635629
self.suggest_cloning(err, place_ty, expr, Some(use_spans));
636630
}
637631

638-
let mut path = None;
639-
let ty = self.infcx.tcx.short_ty_string(place_ty, &mut path);
632+
let ty = self.infcx.tcx.short_string(place_ty, err.long_ty_path());
640633
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
641634
is_partial_move: false,
642635
ty,
643636
place: &place_desc,
644637
span: use_span,
645638
});
646-
if let Some(path) = path {
647-
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
648-
path: path.display().to_string(),
649-
});
650-
}
651639

652640
use_spans.args_subdiag(err, |args_span| {
653641
crate::session_diagnostics::CaptureArgLabel::MoveOutPlace {
@@ -845,19 +833,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
845833
self.suggest_cloning(err, bind_to.ty, expr, None);
846834
}
847835

848-
let mut path = None;
849-
let ty = self.infcx.tcx.short_ty_string(bind_to.ty, &mut path);
836+
let ty = self.infcx.tcx.short_string(bind_to.ty, err.long_ty_path());
850837
err.subdiagnostic(crate::session_diagnostics::TypeNoCopy::Label {
851838
is_partial_move: false,
852839
ty,
853840
place: place_desc,
854841
span: binding_span,
855842
});
856-
if let Some(path) = path {
857-
err.subdiagnostic(crate::session_diagnostics::LongTypePath {
858-
path: path.display().to_string(),
859-
});
860-
}
861843
}
862844
}
863845

compiler/rustc_borrowck/src/session_diagnostics.rs

-7
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,6 @@ pub(crate) enum OnClosureNote<'a> {
458458
},
459459
}
460460

461-
#[derive(Subdiagnostic)]
462-
#[note(borrowck_long_type_full_path)]
463-
#[note(borrowck_long_type_consider_verbose)]
464-
pub(crate) struct LongTypePath {
465-
pub(crate) path: String,
466-
}
467-
468461
#[derive(Subdiagnostic)]
469462
pub(crate) enum TypeNoCopy<'a> {
470463
#[label(borrowck_ty_no_impl_copy)]

compiler/rustc_builtin_macros/src/format.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use rustc_ast::{
88
token,
99
};
1010
use rustc_data_structures::fx::FxHashSet;
11-
use rustc_errors::{Applicability, Diag, MultiSpan, PResult, SingleLabelManySpans};
11+
use rustc_errors::{
12+
Applicability, Diag, MultiSpan, PResult, SingleLabelManySpans, listify, pluralize,
13+
};
1214
use rustc_expand::base::*;
1315
use rustc_lint_defs::builtin::NAMED_ARGUMENTS_USED_POSITIONALLY;
1416
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiag, LintId};
@@ -975,15 +977,11 @@ fn report_invalid_references(
975977
} else {
976978
MultiSpan::from_spans(invalid_refs.iter().filter_map(|&(_, span, _, _)| span).collect())
977979
};
978-
let arg_list = if let &[index] = &indexes[..] {
979-
format!("argument {index}")
980-
} else {
981-
let tail = indexes.pop().unwrap();
982-
format!(
983-
"arguments {head} and {tail}",
984-
head = indexes.into_iter().map(|i| i.to_string()).collect::<Vec<_>>().join(", ")
985-
)
986-
};
980+
let arg_list = format!(
981+
"argument{} {}",
982+
pluralize!(indexes.len()),
983+
listify(&indexes, |i: &usize| i.to_string()).unwrap_or_default()
984+
);
987985
e = ecx.dcx().struct_span_err(
988986
span,
989987
format!("invalid reference to positional {arg_list} ({num_args_desc})"),

compiler/rustc_codegen_cranelift/src/driver/aot.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ pub(crate) fn run_aot(
692692

693693
if tcx.dep_graph.is_fully_enabled() {
694694
for cgu in cgus {
695-
tcx.ensure().codegen_unit(cgu.name());
695+
tcx.ensure_ok().codegen_unit(cgu.name());
696696
}
697697
}
698698

compiler/rustc_codegen_ssa/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
634634
// unnecessarily.
635635
if tcx.dep_graph.is_fully_enabled() {
636636
for cgu in codegen_units {
637-
tcx.ensure().codegen_unit(cgu.name());
637+
tcx.ensure_ok().codegen_unit(cgu.name());
638638
}
639639
}
640640

compiler/rustc_driver_impl/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
317317
if let Some(pp_mode) = sess.opts.pretty {
318318
if pp_mode.needs_ast_map() {
319319
create_and_enter_global_ctxt(compiler, krate, |tcx| {
320-
tcx.ensure().early_lint_checks(());
320+
tcx.ensure_ok().early_lint_checks(());
321321
pretty::print(sess, pp_mode, pretty::PrintExtra::NeedsAstMap { tcx });
322322
passes::write_dep_info(tcx);
323323
});
@@ -365,7 +365,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
365365
return early_exit();
366366
}
367367

368-
tcx.ensure().analysis(());
368+
tcx.ensure_ok().analysis(());
369369

370370
if callbacks.after_analysis(compiler, tcx) == Compilation::Stop {
371371
return early_exit();

compiler/rustc_driver_impl/src/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl<'tcx> PrintExtra<'tcx> {
222222

223223
pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
224224
if ppm.needs_analysis() {
225-
ex.tcx().ensure().analysis(());
225+
ex.tcx().ensure_ok().analysis(());
226226
}
227227

228228
let (src, src_name) = get_source(sess);

compiler/rustc_errors/src/diagnostic.rs

+31
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::hash::{Hash, Hasher};
44
use std::marker::PhantomData;
55
use std::ops::{Deref, DerefMut};
66
use std::panic;
7+
use std::path::PathBuf;
78
use std::thread::panicking;
89

910
use rustc_data_structures::fx::FxIndexMap;
@@ -301,6 +302,7 @@ pub struct DiagInner {
301302

302303
pub is_lint: Option<IsLint>,
303304

305+
pub long_ty_path: Option<PathBuf>,
304306
/// With `-Ztrack_diagnostics` enabled,
305307
/// we print where in rustc this error was emitted.
306308
pub(crate) emitted_at: DiagLocation,
@@ -324,6 +326,7 @@ impl DiagInner {
324326
args: Default::default(),
325327
sort_span: DUMMY_SP,
326328
is_lint: None,
329+
long_ty_path: None,
327330
emitted_at: DiagLocation::caller(),
328331
}
329332
}
@@ -1293,9 +1296,37 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
12931296
/// `cancel`, etc. Afterwards, `drop` is the only code that will be run on
12941297
/// `self`.
12951298
fn take_diag(&mut self) -> DiagInner {
1299+
if let Some(path) = &self.long_ty_path {
1300+
self.note(format!(
1301+
"the full name for the type has been written to '{}'",
1302+
path.display()
1303+
));
1304+
self.note("consider using `--verbose` to print the full type name to the console");
1305+
}
12961306
Box::into_inner(self.diag.take().unwrap())
12971307
}
12981308

1309+
/// This method allows us to access the path of the file where "long types" are written to.
1310+
///
1311+
/// When calling `Diag::emit`, as part of that we will check if a `long_ty_path` has been set,
1312+
/// and if it has been then we add a note mentioning the file where the "long types" were
1313+
/// written to.
1314+
///
1315+
/// When calling `tcx.short_string()` after a `Diag` is constructed, the preferred way of doing
1316+
/// so is `tcx.short_string(ty, diag.long_ty_path())`. The diagnostic itself is the one that
1317+
/// keeps the existence of a "long type" anywhere in the diagnostic, so the note telling the
1318+
/// user where we wrote the file to is only printed once at most, *and* it makes it much harder
1319+
/// to forget to set it.
1320+
///
1321+
/// If the diagnostic hasn't been created before a "short ty string" is created, then you should
1322+
/// ensure that this method is called to set it `*diag.long_ty_path() = path`.
1323+
///
1324+
/// As a rule of thumb, if you see or add at least one `tcx.short_string()` call anywhere, in a
1325+
/// scope, `diag.long_ty_path()` should be called once somewhere close by.
1326+
pub fn long_ty_path(&mut self) -> &mut Option<PathBuf> {
1327+
&mut self.long_ty_path
1328+
}
1329+
12991330
/// Most `emit_producing_guarantee` functions use this as a starting point.
13001331
fn emit_producing_nothing(mut self) {
13011332
let diag = self.take_diag();

compiler/rustc_errors/src/lib.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub use rustc_error_messages::{
6565
SubdiagMessage, fallback_fluent_bundle, fluent_bundle,
6666
};
6767
use rustc_lint_defs::LintExpectationId;
68-
pub use rustc_lint_defs::{Applicability, pluralize};
68+
pub use rustc_lint_defs::{Applicability, listify, pluralize};
6969
use rustc_macros::{Decodable, Encodable};
7070
pub use rustc_span::ErrorGuaranteed;
7171
pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker};
@@ -1999,18 +1999,6 @@ pub fn a_or_an(s: &str) -> &'static str {
19991999
}
20002000
}
20012001

2002-
/// Grammatical tool for displaying messages to end users in a nice form.
2003-
///
2004-
/// Take a list ["a", "b", "c"] and output a display friendly version "a, b and c"
2005-
pub fn display_list_with_comma_and<T: std::fmt::Display>(v: &[T]) -> String {
2006-
match v {
2007-
[] => "".to_string(),
2008-
[a] => a.to_string(),
2009-
[a, b] => format!("{a} and {b}"),
2010-
[a, v @ ..] => format!("{a}, {}", display_list_with_comma_and(v)),
2011-
}
2012-
}
2013-
20142002
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
20152003
pub enum TerminalUrl {
20162004
No,

compiler/rustc_hir_analysis/src/check/check.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -778,13 +778,13 @@ fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) {
778778
pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
779779
match tcx.def_kind(def_id) {
780780
DefKind::Static { .. } => {
781-
tcx.ensure().typeck(def_id);
781+
tcx.ensure_ok().typeck(def_id);
782782
maybe_check_static_with_link_section(tcx, def_id);
783783
check_static_inhabited(tcx, def_id);
784784
check_static_linkage(tcx, def_id);
785785
}
786786
DefKind::Const => {
787-
tcx.ensure().typeck(def_id);
787+
tcx.ensure_ok().typeck(def_id);
788788
}
789789
DefKind::Enum => {
790790
check_enum(tcx, def_id);
@@ -804,7 +804,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
804804
DefKind::Impl { of_trait } => {
805805
if of_trait && let Some(impl_trait_header) = tcx.impl_trait_header(def_id) {
806806
if tcx
807-
.ensure()
807+
.ensure_ok()
808808
.coherent_trait(impl_trait_header.trait_ref.instantiate_identity().def_id)
809809
.is_ok()
810810
{
@@ -1042,7 +1042,7 @@ fn check_impl_items_against_trait<'tcx>(
10421042
continue;
10431043
};
10441044

1045-
let res = tcx.ensure().compare_impl_item(impl_item.expect_local());
1045+
let res = tcx.ensure_ok().compare_impl_item(impl_item.expect_local());
10461046

10471047
if res.is_ok() {
10481048
match ty_impl_item.kind {
@@ -1488,7 +1488,7 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {
14881488

14891489
for v in def.variants() {
14901490
if let ty::VariantDiscr::Explicit(discr_def_id) = v.discr {
1491-
tcx.ensure().typeck(discr_def_id.expect_local());
1491+
tcx.ensure_ok().typeck(discr_def_id.expect_local());
14921492
}
14931493
}
14941494

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,7 @@ pub(super) fn check_type_bounds<'tcx>(
20342034
) -> Result<(), ErrorGuaranteed> {
20352035
// Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case
20362036
// other `Foo` impls are incoherent.
2037-
tcx.ensure().coherent_trait(impl_trait_ref.def_id)?;
2037+
tcx.ensure_ok().coherent_trait(impl_trait_ref.def_id)?;
20382038

20392039
let param_env = tcx.param_env(impl_ty.def_id);
20402040
debug!(?param_env);

0 commit comments

Comments
 (0)