Skip to content

Commit 1d0a389

Browse files
committed
Auto merge of rust-lang#119987 - matthiaskrgr:rollup-f7lkx4w, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#119818 (Silence some follow-up errors [3/x]) - rust-lang#119870 (std: Doc blocking behavior of LazyLock) - rust-lang#119897 (`OutputTypeParameterMismatch` -> `SignatureMismatch`) - rust-lang#119963 (Fix `allow_internal_unstable` for `(min_)specialization`) - rust-lang#119971 (Use `zip_eq` to enforce that things being zipped have equal sizes) - rust-lang#119974 (Minor `trimmed_def_paths` improvements) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1ead476 + 82f38ab commit 1d0a389

File tree

41 files changed

+230
-213
lines changed

Some content is hidden

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

41 files changed

+230
-213
lines changed

Cargo.lock

+3
Original file line numberDiff line numberDiff line change
@@ -3879,6 +3879,7 @@ dependencies = [
38793879
name = "rustc_hir_analysis"
38803880
version = "0.0.0"
38813881
dependencies = [
3882+
"itertools",
38823883
"rustc_arena",
38833884
"rustc_ast",
38843885
"rustc_attr",
@@ -3917,6 +3918,7 @@ dependencies = [
39173918
name = "rustc_hir_typeck"
39183919
version = "0.0.0"
39193920
dependencies = [
3921+
"itertools",
39203922
"rustc_ast",
39213923
"rustc_attr",
39223924
"rustc_data_structures",
@@ -4200,6 +4202,7 @@ name = "rustc_mir_build"
42004202
version = "0.0.0"
42014203
dependencies = [
42024204
"either",
4205+
"itertools",
42034206
"rustc_apfloat",
42044207
"rustc_arena",
42054208
"rustc_ast",

compiler/rustc_borrowck/src/diagnostics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12151215
Applicability::MaybeIncorrect,
12161216
);
12171217
for error in errors {
1218-
if let FulfillmentErrorCode::CodeSelectionError(
1218+
if let FulfillmentErrorCode::SelectionError(
12191219
SelectionError::Unimplemented,
12201220
) = error.code
12211221
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
12911291
}
12921292
// The type doesn't implement Clone because of unmet obligations.
12931293
for error in errors {
1294-
if let traits::FulfillmentErrorCode::CodeSelectionError(
1294+
if let traits::FulfillmentErrorCode::SelectionError(
12951295
traits::SelectionError::Unimplemented,
12961296
) = error.code
12971297
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(

compiler/rustc_borrowck/src/type_check/input_output.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! `RETURN_PLACE` the MIR arguments) are always fully normalized (and
88
//! contain revealed `impl Trait` values).
99
10+
use itertools::Itertools;
1011
use rustc_infer::infer::BoundRegionConversionTime;
1112
use rustc_middle::mir::*;
1213
use rustc_middle::ty::{self, Ty};
@@ -39,9 +40,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
3940
user_provided_sig,
4041
);
4142

42-
for (&user_ty, arg_decl) in user_provided_sig.inputs().iter().zip(
43-
// In MIR, closure args begin with an implicit `self`. Skip it!
44-
body.args_iter().skip(1).map(|local| &body.local_decls[local]),
43+
let is_coroutine_with_implicit_resume_ty = self.tcx().is_coroutine(mir_def_id.to_def_id())
44+
&& user_provided_sig.inputs().is_empty();
45+
46+
for (&user_ty, arg_decl) in user_provided_sig.inputs().iter().zip_eq(
47+
// In MIR, closure args begin with an implicit `self`.
48+
// Also, coroutines have a resume type which may be implicitly `()`.
49+
body.args_iter()
50+
.skip(1 + if is_coroutine_with_implicit_resume_ty { 1 } else { 0 })
51+
.map(|local| &body.local_decls[local]),
4552
) {
4653
self.ascribe_user_type_skip_wf(
4754
arg_decl.ty,

compiler/rustc_driver_impl/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_lint::unerased_lint_store;
3535
use rustc_metadata::creader::MetadataLoader;
3636
use rustc_metadata::locator;
3737
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
38-
use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType, TrimmedDefPaths};
38+
use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType};
3939
use rustc_session::getopts::{self, Matches};
4040
use rustc_session::lint::{Lint, LintId};
4141
use rustc_session::{config, EarlyDiagCtxt, Session};
@@ -204,7 +204,7 @@ impl Callbacks for TimePassesCallbacks {
204204
//
205205
self.time_passes = (config.opts.prints.is_empty() && config.opts.unstable_opts.time_passes)
206206
.then(|| config.opts.unstable_opts.time_passes_format);
207-
config.opts.trimmed_def_paths = TrimmedDefPaths::GoodPath;
207+
config.opts.trimmed_def_paths = true;
208208
}
209209
}
210210

compiler/rustc_hir_analysis/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ doctest = false
99

1010
[dependencies]
1111
# tidy-alphabetical-start
12+
itertools = "0.11"
1213
rustc_arena = { path = "../rustc_arena" }
1314
rustc_ast = { path = "../rustc_ast" }
1415
rustc_attr = { path = "../rustc_attr" }

compiler/rustc_hir_analysis/src/variance/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//!
44
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/variance.html
55
6+
use itertools::Itertools;
67
use rustc_arena::DroplessArena;
78
use rustc_hir::def::DefKind;
89
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -91,7 +92,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
9192
fn visit_opaque(&mut self, def_id: DefId, args: GenericArgsRef<'tcx>) -> ControlFlow<!> {
9293
if def_id != self.root_def_id && self.tcx.is_descendant_of(def_id, self.root_def_id) {
9394
let child_variances = self.tcx.variances_of(def_id);
94-
for (a, v) in args.iter().zip(child_variances) {
95+
for (a, v) in args.iter().zip_eq(child_variances) {
9596
if *v != ty::Bivariant {
9697
a.visit_with(self)?;
9798
}

compiler/rustc_hir_typeck/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8+
itertools = "0.11"
89
rustc_ast = { path = "../rustc_ast" }
910
rustc_attr = { path = "../rustc_attr" }
1011
rustc_data_structures = { path = "../rustc_data_structures" }

compiler/rustc_hir_typeck/src/autoderef.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use super::method::MethodCallee;
33
use super::{FnCtxt, PlaceOp};
44

5+
use itertools::Itertools;
56
use rustc_hir_analysis::autoderef::{Autoderef, AutoderefKind};
67
use rustc_infer::infer::InferOk;
78
use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref};
@@ -32,8 +33,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3233
&self,
3334
autoderef: &Autoderef<'a, 'tcx>,
3435
) -> InferOk<'tcx, Vec<Adjustment<'tcx>>> {
35-
let mut obligations = vec![];
3636
let steps = autoderef.steps();
37+
if steps.is_empty() {
38+
return InferOk { obligations: vec![], value: vec![] };
39+
}
40+
41+
let mut obligations = vec![];
3742
let targets =
3843
steps.iter().skip(1).map(|&(ty, _)| ty).chain(iter::once(autoderef.final_ty(false)));
3944
let steps: Vec<_> = steps
@@ -54,7 +59,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5459
None
5560
}
5661
})
57-
.zip(targets)
62+
.zip_eq(targets)
5863
.map(|(autoderef, target)| Adjustment { kind: Adjust::Deref(autoderef), target })
5964
.collect();
6065

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8686
// Finally, for ambiguity-related errors, we actually want to look
8787
// for a parameter that is the source of the inference type left
8888
// over in this predicate.
89-
if let traits::FulfillmentErrorCode::CodeAmbiguity { .. } = error.code {
89+
if let traits::FulfillmentErrorCode::Ambiguity { .. } = error.code {
9090
fallback_param_to_point_at = None;
9191
self_param_to_point_at = None;
9292
param_to_point_at =
@@ -361,10 +361,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
361361
error: &traits::FulfillmentError<'tcx>,
362362
span: Span,
363363
) -> bool {
364-
if let traits::FulfillmentErrorCode::CodeSelectionError(
365-
traits::SelectionError::OutputTypeParameterMismatch(
366-
box traits::SelectionOutputTypeParameterMismatch { expected_trait_ref, .. },
367-
),
364+
if let traits::FulfillmentErrorCode::SelectionError(
365+
traits::SelectionError::SignatureMismatch(box traits::SignatureMismatchData {
366+
expected_trait_ref,
367+
..
368+
}),
368369
) = error.code
369370
&& let ty::Closure(def_id, _) | ty::Coroutine(def_id, ..) =
370371
expected_trait_ref.skip_binder().self_ty().kind()

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::{
99
struct_span_code_err, BreakableCtxt, Diverges, Expectation, FnCtxt, Needs, RawTy,
1010
TupleArgumentsFlag,
1111
};
12+
use itertools::Itertools;
1213
use rustc_ast as ast;
1314
use rustc_data_structures::fx::FxIndexSet;
1415
use rustc_errors::{
@@ -421,7 +422,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
421422
formal_input_tys
422423
.iter()
423424
.copied()
424-
.zip(expected_input_tys.iter().copied())
425+
.zip_eq(expected_input_tys.iter().copied())
425426
.map(|vars| self.resolve_vars_if_possible(vars)),
426427
);
427428

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16481648
}
16491649
}
16501650
for error in errors {
1651-
if let traits::FulfillmentErrorCode::CodeSelectionError(
1651+
if let traits::FulfillmentErrorCode::SelectionError(
16521652
traits::SelectionError::Unimplemented,
16531653
) = error.code
16541654
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) =

compiler/rustc_index_macros/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ mod newtype;
3939
feature = "nightly",
4040
allow_internal_unstable(step_trait, rustc_attrs, trusted_step, spec_option_partial_eq)
4141
)]
42+
// FIXME: Remove the above comment about `min_specialization` once bootstrap is bumped,
43+
// and the corresponding one on SpecOptionPartialEq
44+
#[cfg_attr(all(feature = "nightly", not(bootstrap)), allow_internal_unstable(min_specialization))]
4245
pub fn newtype_index(input: TokenStream) -> TokenStream {
4346
newtype::newtype(input)
4447
}

compiler/rustc_infer/src/infer/opaque_types.rs

-7
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,6 @@ impl<'tcx> InferCtxt<'tcx> {
631631
ct_op: |ct| ct,
632632
});
633633

634-
if let ty::ClauseKind::Projection(projection) = predicate.kind().skip_binder() {
635-
if projection.term.references_error() {
636-
// No point on adding any obligations since there's a type error involved.
637-
obligations.clear();
638-
return;
639-
}
640-
}
641634
// Require that the predicate holds for the concrete type.
642635
debug!(?predicate);
643636
obligations.push(traits::Obligation::new(

compiler/rustc_infer/src/traits/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use rustc_middle::ty::error::{ExpectedFound, TypeError};
1717
use rustc_middle::ty::{self, Const, ToPredicate, Ty, TyCtxt};
1818
use rustc_span::Span;
1919

20-
pub use self::FulfillmentErrorCode::*;
2120
pub use self::ImplSource::*;
2221
pub use self::SelectionError::*;
2322

@@ -129,12 +128,12 @@ pub struct FulfillmentError<'tcx> {
129128
#[derive(Clone)]
130129
pub enum FulfillmentErrorCode<'tcx> {
131130
/// Inherently impossible to fulfill; this trait is implemented if and only if it is already implemented.
132-
CodeCycle(Vec<PredicateObligation<'tcx>>),
133-
CodeSelectionError(SelectionError<'tcx>),
134-
CodeProjectionError(MismatchedProjectionTypes<'tcx>),
135-
CodeSubtypeError(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
136-
CodeConstEquateError(ExpectedFound<Const<'tcx>>, TypeError<'tcx>),
137-
CodeAmbiguity {
131+
Cycle(Vec<PredicateObligation<'tcx>>),
132+
SelectionError(SelectionError<'tcx>),
133+
ProjectionError(MismatchedProjectionTypes<'tcx>),
134+
SubtypeError(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
135+
ConstEquateError(ExpectedFound<Const<'tcx>>, TypeError<'tcx>),
136+
Ambiguity {
138137
/// Overflow reported from the new solver `-Znext-solver`, which will
139138
/// be reported as an regular error as opposed to a fatal error.
140139
overflow: bool,

compiler/rustc_infer/src/traits/structural_impls.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,19 @@ impl<'tcx> fmt::Debug for traits::FulfillmentError<'tcx> {
3737

3838
impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
3939
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40+
use traits::FulfillmentErrorCode::*;
4041
match *self {
41-
super::CodeSelectionError(ref e) => write!(f, "{e:?}"),
42-
super::CodeProjectionError(ref e) => write!(f, "{e:?}"),
43-
super::CodeSubtypeError(ref a, ref b) => {
42+
SelectionError(ref e) => write!(f, "{e:?}"),
43+
ProjectionError(ref e) => write!(f, "{e:?}"),
44+
SubtypeError(ref a, ref b) => {
4445
write!(f, "CodeSubtypeError({a:?}, {b:?})")
4546
}
46-
super::CodeConstEquateError(ref a, ref b) => {
47+
ConstEquateError(ref a, ref b) => {
4748
write!(f, "CodeConstEquateError({a:?}, {b:?})")
4849
}
49-
super::CodeAmbiguity { overflow: false } => write!(f, "Ambiguity"),
50-
super::CodeAmbiguity { overflow: true } => write!(f, "Overflow"),
51-
super::CodeCycle(ref cycle) => write!(f, "Cycle({cycle:?})"),
50+
Ambiguity { overflow: false } => write!(f, "Ambiguity"),
51+
Ambiguity { overflow: true } => write!(f, "Overflow"),
52+
Cycle(ref cycle) => write!(f, "Cycle({cycle:?})"),
5253
}
5354
}
5455
}

compiler/rustc_middle/src/traits/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ pub enum SelectionError<'tcx> {
604604
/// After a closure impl has selected, its "outputs" were evaluated
605605
/// (which for closures includes the "input" type params) and they
606606
/// didn't resolve. See `confirm_poly_trait_refs` for more.
607-
OutputTypeParameterMismatch(Box<SelectionOutputTypeParameterMismatch<'tcx>>),
607+
SignatureMismatch(Box<SignatureMismatchData<'tcx>>),
608608
/// The trait pointed by `DefId` is not object safe.
609609
TraitNotObjectSafe(DefId),
610610
/// A given constant couldn't be evaluated.
@@ -618,7 +618,7 @@ pub enum SelectionError<'tcx> {
618618
}
619619

620620
#[derive(Clone, Debug, TypeVisitable)]
621-
pub struct SelectionOutputTypeParameterMismatch<'tcx> {
621+
pub struct SignatureMismatchData<'tcx> {
622622
pub found_trait_ref: ty::PolyTraitRef<'tcx>,
623623
pub expected_trait_ref: ty::PolyTraitRef<'tcx>,
624624
pub terr: ty::error::TypeError<'tcx>,

compiler/rustc_middle/src/ty/print/pretty.rs

+26-31
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc_hir::def::{self, CtorKind, DefKind, Namespace};
1515
use rustc_hir::def_id::{DefIdMap, DefIdSet, ModDefId, CRATE_DEF_ID, LOCAL_CRATE};
1616
use rustc_hir::definitions::{DefKey, DefPathDataName};
1717
use rustc_hir::LangItem;
18-
use rustc_session::config::TrimmedDefPaths;
1918
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
2019
use rustc_session::Limit;
2120
use rustc_span::symbol::{kw, Ident, Symbol};
@@ -365,26 +364,19 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
365364

366365
/// Try to see if this path can be trimmed to a unique symbol name.
367366
fn try_print_trimmed_def_path(&mut self, def_id: DefId) -> Result<bool, PrintError> {
368-
if with_forced_trimmed_paths() {
369-
let trimmed = self.force_print_trimmed_def_path(def_id)?;
370-
if trimmed {
371-
return Ok(true);
372-
}
367+
if with_forced_trimmed_paths() && self.force_print_trimmed_def_path(def_id)? {
368+
return Ok(true);
373369
}
374-
if !self.tcx().sess.opts.unstable_opts.trim_diagnostic_paths
375-
|| matches!(self.tcx().sess.opts.trimmed_def_paths, TrimmedDefPaths::Never)
376-
|| with_no_trimmed_paths()
377-
|| with_crate_prefix()
370+
if self.tcx().sess.opts.unstable_opts.trim_diagnostic_paths
371+
&& self.tcx().sess.opts.trimmed_def_paths
372+
&& !with_no_trimmed_paths()
373+
&& !with_crate_prefix()
374+
&& let Some(symbol) = self.tcx().trimmed_def_paths(()).get(&def_id)
378375
{
379-
return Ok(false);
380-
}
381-
382-
match self.tcx().trimmed_def_paths(()).get(&def_id) {
383-
None => Ok(false),
384-
Some(symbol) => {
385-
write!(self, "{}", Ident::with_dummy_span(*symbol))?;
386-
Ok(true)
387-
}
376+
write!(self, "{}", Ident::with_dummy_span(*symbol))?;
377+
Ok(true)
378+
} else {
379+
Ok(false)
388380
}
389381
}
390382

@@ -3080,18 +3072,19 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
30803072
/// See also [`DelayDm`](rustc_error_messages::DelayDm) and [`with_no_trimmed_paths!`].
30813073
// this is pub to be able to intra-doc-link it
30823074
pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
3083-
let mut map: DefIdMap<Symbol> = Default::default();
3084-
3085-
if let TrimmedDefPaths::GoodPath = tcx.sess.opts.trimmed_def_paths {
3086-
// Trimming paths is expensive and not optimized, since we expect it to only be used for error reporting.
3087-
//
3088-
// For good paths causing this bug, the `rustc_middle::ty::print::with_no_trimmed_paths`
3089-
// wrapper can be used to suppress this query, in exchange for full paths being formatted.
3090-
tcx.sess.good_path_delayed_bug(
3091-
"trimmed_def_paths constructed but no error emitted; use `DelayDm` for lints or `with_no_trimmed_paths` for debugging",
3092-
);
3093-
}
3094-
3075+
assert!(tcx.sess.opts.trimmed_def_paths);
3076+
3077+
// Trimming paths is expensive and not optimized, since we expect it to only be used for error
3078+
// reporting.
3079+
//
3080+
// For good paths causing this bug, the `rustc_middle::ty::print::with_no_trimmed_paths`
3081+
// wrapper can be used to suppress this query, in exchange for full paths being formatted.
3082+
tcx.sess.good_path_delayed_bug(
3083+
"trimmed_def_paths constructed but no error emitted; use `DelayDm` for lints or `with_no_trimmed_paths` for debugging",
3084+
);
3085+
3086+
// Once constructed, unique namespace+symbol pairs will have a `Some(_)` entry, while
3087+
// non-unique pairs will have a `None` entry.
30953088
let unique_symbols_rev: &mut FxHashMap<(Namespace, Symbol), Option<DefId>> =
30963089
&mut FxHashMap::default();
30973090

@@ -3121,6 +3114,8 @@ pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
31213114
}
31223115
});
31233116

3117+
// Put the symbol from all the unique namespace+symbol pairs into `map`.
3118+
let mut map: DefIdMap<Symbol> = Default::default();
31243119
for ((_, symbol), opt_def_id) in unique_symbols_rev.drain() {
31253120
use std::collections::hash_map::Entry::{Occupied, Vacant};
31263121

compiler/rustc_mir_build/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66
[dependencies]
77
# tidy-alphabetical-start
88
either = "1"
9+
itertools = "0.11"
910
rustc_apfloat = "0.2.0"
1011
rustc_arena = { path = "../rustc_arena" }
1112
rustc_ast = { path = "../rustc_ast" }

0 commit comments

Comments
 (0)