Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #119987

Merged
merged 17 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
fb44c84
Keep error types around, even in obligations.
oli-obk Jan 10, 2024
f37a919
Remove redundant Code from FulfillmentErrorCode variants
compiler-errors Jan 12, 2024
fbdc116
OutputTypeParameterMismatch -> SignatureMismatch
compiler-errors Jan 12, 2024
0529ccf
Fix `allow_internal_unstable` for `(min_)specialization`
clubby789 Jan 14, 2024
a596159
std: Doc blocking behavior of LazyLock methods
behnam Jan 11, 2024
eb63d3a
`allow_internal_unstable(min_specialization)` on `newtype_index`
clubby789 Jan 14, 2024
c5cb87c
Closure body was being built incorrectly on error...
compiler-errors Jan 14, 2024
c811662
Use zip_eq to enforce that things being zipped have equal sizes
compiler-errors Jan 14, 2024
4efddb1
Add some helpful comments in `trimmed_def_paths`.
nnethercote Jan 9, 2024
086d17b
Refactor `try_print_trimmed_def_path`.
nnethercote Jan 10, 2024
32de78c
Replace `TrimmedDefPaths` with a bool.
nnethercote Jan 10, 2024
73256c6
Rollup merge of #119818 - oli-obk:even_more_follow_up_errors3, r=comp…
matthiaskrgr Jan 15, 2024
6f2670d
Rollup merge of #119870 - behnam-oneschema:lazylock-blocking-1, r=tgr…
matthiaskrgr Jan 15, 2024
1e46be6
Rollup merge of #119897 - compiler-errors:fulfillment-errors, r=lcnr
matthiaskrgr Jan 15, 2024
0891cb4
Rollup merge of #119963 - clubby789:spec-allow-internal-unstable, r=c…
matthiaskrgr Jan 15, 2024
b6f68a7
Rollup merge of #119971 - compiler-errors:zip-eq, r=nnethercote
matthiaskrgr Jan 15, 2024
82f38ab
Rollup merge of #119974 - nnethercote:trimmed_def_paths-improvements,…
matthiaskrgr Jan 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3879,6 +3879,7 @@ dependencies = [
name = "rustc_hir_analysis"
version = "0.0.0"
dependencies = [
"itertools",
"rustc_arena",
"rustc_ast",
"rustc_attr",
Expand Down Expand Up @@ -3917,6 +3918,7 @@ dependencies = [
name = "rustc_hir_typeck"
version = "0.0.0"
dependencies = [
"itertools",
"rustc_ast",
"rustc_attr",
"rustc_data_structures",
Expand Down Expand Up @@ -4200,6 +4202,7 @@ name = "rustc_mir_build"
version = "0.0.0"
dependencies = [
"either",
"itertools",
"rustc_apfloat",
"rustc_arena",
"rustc_ast",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Applicability::MaybeIncorrect,
);
for error in errors {
if let FulfillmentErrorCode::CodeSelectionError(
if let FulfillmentErrorCode::SelectionError(
SelectionError::Unimplemented,
) = error.code
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}
// The type doesn't implement Clone because of unmet obligations.
for error in errors {
if let traits::FulfillmentErrorCode::CodeSelectionError(
if let traits::FulfillmentErrorCode::SelectionError(
traits::SelectionError::Unimplemented,
) = error.code
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(
Expand Down
13 changes: 10 additions & 3 deletions compiler/rustc_borrowck/src/type_check/input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//! `RETURN_PLACE` the MIR arguments) are always fully normalized (and
//! contain revealed `impl Trait` values).

use itertools::Itertools;
use rustc_infer::infer::BoundRegionConversionTime;
use rustc_middle::mir::*;
use rustc_middle::ty::{self, Ty};
Expand Down Expand Up @@ -39,9 +40,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
user_provided_sig,
);

for (&user_ty, arg_decl) in user_provided_sig.inputs().iter().zip(
// In MIR, closure args begin with an implicit `self`. Skip it!
body.args_iter().skip(1).map(|local| &body.local_decls[local]),
let is_coroutine_with_implicit_resume_ty = self.tcx().is_coroutine(mir_def_id.to_def_id())
&& user_provided_sig.inputs().is_empty();

for (&user_ty, arg_decl) in user_provided_sig.inputs().iter().zip_eq(
// In MIR, closure args begin with an implicit `self`.
// Also, coroutines have a resume type which may be implicitly `()`.
body.args_iter()
.skip(1 + if is_coroutine_with_implicit_resume_ty { 1 } else { 0 })
.map(|local| &body.local_decls[local]),
) {
self.ascribe_user_type_skip_wf(
arg_decl.ty,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use rustc_lint::unerased_lint_store;
use rustc_metadata::creader::MetadataLoader;
use rustc_metadata::locator;
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType, TrimmedDefPaths};
use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType};
use rustc_session::getopts::{self, Matches};
use rustc_session::lint::{Lint, LintId};
use rustc_session::{config, EarlyDiagCtxt, Session};
Expand Down Expand Up @@ -204,7 +204,7 @@ impl Callbacks for TimePassesCallbacks {
//
self.time_passes = (config.opts.prints.is_empty() && config.opts.unstable_opts.time_passes)
.then(|| config.opts.unstable_opts.time_passes_format);
config.opts.trimmed_def_paths = TrimmedDefPaths::GoodPath;
config.opts.trimmed_def_paths = true;
}
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_analysis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ doctest = false

[dependencies]
# tidy-alphabetical-start
itertools = "0.11"
rustc_arena = { path = "../rustc_arena" }
rustc_ast = { path = "../rustc_ast" }
rustc_attr = { path = "../rustc_attr" }
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_hir_analysis/src/variance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//!
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/variance.html

use itertools::Itertools;
use rustc_arena::DroplessArena;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId};
Expand Down Expand Up @@ -91,7 +92,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
fn visit_opaque(&mut self, def_id: DefId, args: GenericArgsRef<'tcx>) -> ControlFlow<!> {
if def_id != self.root_def_id && self.tcx.is_descendant_of(def_id, self.root_def_id) {
let child_variances = self.tcx.variances_of(def_id);
for (a, v) in args.iter().zip(child_variances) {
for (a, v) in args.iter().zip_eq(child_variances) {
if *v != ty::Bivariant {
a.visit_with(self)?;
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[dependencies]
# tidy-alphabetical-start
itertools = "0.11"
rustc_ast = { path = "../rustc_ast" }
rustc_attr = { path = "../rustc_attr" }
rustc_data_structures = { path = "../rustc_data_structures" }
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_hir_typeck/src/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use super::method::MethodCallee;
use super::{FnCtxt, PlaceOp};

use itertools::Itertools;
use rustc_hir_analysis::autoderef::{Autoderef, AutoderefKind};
use rustc_infer::infer::InferOk;
use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref};
Expand Down Expand Up @@ -32,8 +33,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
autoderef: &Autoderef<'a, 'tcx>,
) -> InferOk<'tcx, Vec<Adjustment<'tcx>>> {
let mut obligations = vec![];
let steps = autoderef.steps();
if steps.is_empty() {
return InferOk { obligations: vec![], value: vec![] };
}

let mut obligations = vec![];
let targets =
steps.iter().skip(1).map(|&(ty, _)| ty).chain(iter::once(autoderef.final_ty(false)));
let steps: Vec<_> = steps
Expand All @@ -54,7 +59,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
None
}
})
.zip(targets)
.zip_eq(targets)
.map(|(autoderef, target)| Adjustment { kind: Adjust::Deref(autoderef), target })
.collect();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Finally, for ambiguity-related errors, we actually want to look
// for a parameter that is the source of the inference type left
// over in this predicate.
if let traits::FulfillmentErrorCode::CodeAmbiguity { .. } = error.code {
if let traits::FulfillmentErrorCode::Ambiguity { .. } = error.code {
fallback_param_to_point_at = None;
self_param_to_point_at = None;
param_to_point_at =
Expand Down Expand Up @@ -361,10 +361,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
error: &traits::FulfillmentError<'tcx>,
span: Span,
) -> bool {
if let traits::FulfillmentErrorCode::CodeSelectionError(
traits::SelectionError::OutputTypeParameterMismatch(
box traits::SelectionOutputTypeParameterMismatch { expected_trait_ref, .. },
),
if let traits::FulfillmentErrorCode::SelectionError(
traits::SelectionError::SignatureMismatch(box traits::SignatureMismatchData {
expected_trait_ref,
..
}),
) = error.code
&& let ty::Closure(def_id, _) | ty::Coroutine(def_id, ..) =
expected_trait_ref.skip_binder().self_ty().kind()
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
struct_span_code_err, BreakableCtxt, Diverges, Expectation, FnCtxt, Needs, RawTy,
TupleArgumentsFlag,
};
use itertools::Itertools;
use rustc_ast as ast;
use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::{
Expand Down Expand Up @@ -421,7 +422,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
formal_input_tys
.iter()
.copied()
.zip(expected_input_tys.iter().copied())
.zip_eq(expected_input_tys.iter().copied())
.map(|vars| self.resolve_vars_if_possible(vars)),
);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
for error in errors {
if let traits::FulfillmentErrorCode::CodeSelectionError(
if let traits::FulfillmentErrorCode::SelectionError(
traits::SelectionError::Unimplemented,
) = error.code
&& let ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) =
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_index_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ mod newtype;
feature = "nightly",
allow_internal_unstable(step_trait, rustc_attrs, trusted_step, spec_option_partial_eq)
)]
// FIXME: Remove the above comment about `min_specialization` once bootstrap is bumped,
// and the corresponding one on SpecOptionPartialEq
#[cfg_attr(all(feature = "nightly", not(bootstrap)), allow_internal_unstable(min_specialization))]
pub fn newtype_index(input: TokenStream) -> TokenStream {
newtype::newtype(input)
}
7 changes: 0 additions & 7 deletions compiler/rustc_infer/src/infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,13 +631,6 @@ impl<'tcx> InferCtxt<'tcx> {
ct_op: |ct| ct,
});

if let ty::ClauseKind::Projection(projection) = predicate.kind().skip_binder() {
if projection.term.references_error() {
// No point on adding any obligations since there's a type error involved.
obligations.clear();
return;
}
}
// Require that the predicate holds for the concrete type.
debug!(?predicate);
obligations.push(traits::Obligation::new(
Expand Down
13 changes: 6 additions & 7 deletions compiler/rustc_infer/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::{self, Const, ToPredicate, Ty, TyCtxt};
use rustc_span::Span;

pub use self::FulfillmentErrorCode::*;
pub use self::ImplSource::*;
pub use self::SelectionError::*;

Expand Down Expand Up @@ -129,12 +128,12 @@ pub struct FulfillmentError<'tcx> {
#[derive(Clone)]
pub enum FulfillmentErrorCode<'tcx> {
/// Inherently impossible to fulfill; this trait is implemented if and only if it is already implemented.
CodeCycle(Vec<PredicateObligation<'tcx>>),
CodeSelectionError(SelectionError<'tcx>),
CodeProjectionError(MismatchedProjectionTypes<'tcx>),
CodeSubtypeError(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
CodeConstEquateError(ExpectedFound<Const<'tcx>>, TypeError<'tcx>),
CodeAmbiguity {
Cycle(Vec<PredicateObligation<'tcx>>),
SelectionError(SelectionError<'tcx>),
ProjectionError(MismatchedProjectionTypes<'tcx>),
SubtypeError(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
ConstEquateError(ExpectedFound<Const<'tcx>>, TypeError<'tcx>),
Ambiguity {
/// Overflow reported from the new solver `-Znext-solver`, which will
/// be reported as an regular error as opposed to a fatal error.
overflow: bool,
Expand Down
15 changes: 8 additions & 7 deletions compiler/rustc_infer/src/traits/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ impl<'tcx> fmt::Debug for traits::FulfillmentError<'tcx> {

impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use traits::FulfillmentErrorCode::*;
match *self {
super::CodeSelectionError(ref e) => write!(f, "{e:?}"),
super::CodeProjectionError(ref e) => write!(f, "{e:?}"),
super::CodeSubtypeError(ref a, ref b) => {
SelectionError(ref e) => write!(f, "{e:?}"),
ProjectionError(ref e) => write!(f, "{e:?}"),
SubtypeError(ref a, ref b) => {
write!(f, "CodeSubtypeError({a:?}, {b:?})")
}
super::CodeConstEquateError(ref a, ref b) => {
ConstEquateError(ref a, ref b) => {
write!(f, "CodeConstEquateError({a:?}, {b:?})")
}
super::CodeAmbiguity { overflow: false } => write!(f, "Ambiguity"),
super::CodeAmbiguity { overflow: true } => write!(f, "Overflow"),
super::CodeCycle(ref cycle) => write!(f, "Cycle({cycle:?})"),
Ambiguity { overflow: false } => write!(f, "Ambiguity"),
Ambiguity { overflow: true } => write!(f, "Overflow"),
Cycle(ref cycle) => write!(f, "Cycle({cycle:?})"),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ pub enum SelectionError<'tcx> {
/// After a closure impl has selected, its "outputs" were evaluated
/// (which for closures includes the "input" type params) and they
/// didn't resolve. See `confirm_poly_trait_refs` for more.
OutputTypeParameterMismatch(Box<SelectionOutputTypeParameterMismatch<'tcx>>),
SignatureMismatch(Box<SignatureMismatchData<'tcx>>),
/// The trait pointed by `DefId` is not object safe.
TraitNotObjectSafe(DefId),
/// A given constant couldn't be evaluated.
Expand All @@ -618,7 +618,7 @@ pub enum SelectionError<'tcx> {
}

#[derive(Clone, Debug, TypeVisitable)]
pub struct SelectionOutputTypeParameterMismatch<'tcx> {
pub struct SignatureMismatchData<'tcx> {
pub found_trait_ref: ty::PolyTraitRef<'tcx>,
pub expected_trait_ref: ty::PolyTraitRef<'tcx>,
pub terr: ty::error::TypeError<'tcx>,
Expand Down
57 changes: 26 additions & 31 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use rustc_hir::def::{self, CtorKind, DefKind, Namespace};
use rustc_hir::def_id::{DefIdMap, DefIdSet, ModDefId, CRATE_DEF_ID, LOCAL_CRATE};
use rustc_hir::definitions::{DefKey, DefPathDataName};
use rustc_hir::LangItem;
use rustc_session::config::TrimmedDefPaths;
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
use rustc_session::Limit;
use rustc_span::symbol::{kw, Ident, Symbol};
Expand Down Expand Up @@ -365,26 +364,19 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {

/// Try to see if this path can be trimmed to a unique symbol name.
fn try_print_trimmed_def_path(&mut self, def_id: DefId) -> Result<bool, PrintError> {
if with_forced_trimmed_paths() {
let trimmed = self.force_print_trimmed_def_path(def_id)?;
if trimmed {
return Ok(true);
}
if with_forced_trimmed_paths() && self.force_print_trimmed_def_path(def_id)? {
return Ok(true);
}
if !self.tcx().sess.opts.unstable_opts.trim_diagnostic_paths
|| matches!(self.tcx().sess.opts.trimmed_def_paths, TrimmedDefPaths::Never)
|| with_no_trimmed_paths()
|| with_crate_prefix()
if self.tcx().sess.opts.unstable_opts.trim_diagnostic_paths
&& self.tcx().sess.opts.trimmed_def_paths
&& !with_no_trimmed_paths()
&& !with_crate_prefix()
&& let Some(symbol) = self.tcx().trimmed_def_paths(()).get(&def_id)
{
return Ok(false);
}

match self.tcx().trimmed_def_paths(()).get(&def_id) {
None => Ok(false),
Some(symbol) => {
write!(self, "{}", Ident::with_dummy_span(*symbol))?;
Ok(true)
}
write!(self, "{}", Ident::with_dummy_span(*symbol))?;
Ok(true)
} else {
Ok(false)
}
}

Expand Down Expand Up @@ -3080,18 +3072,19 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
/// See also [`DelayDm`](rustc_error_messages::DelayDm) and [`with_no_trimmed_paths!`].
// this is pub to be able to intra-doc-link it
pub fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<Symbol> {
let mut map: DefIdMap<Symbol> = Default::default();

if let TrimmedDefPaths::GoodPath = tcx.sess.opts.trimmed_def_paths {
// Trimming paths is expensive and not optimized, since we expect it to only be used for error reporting.
//
// For good paths causing this bug, the `rustc_middle::ty::print::with_no_trimmed_paths`
// wrapper can be used to suppress this query, in exchange for full paths being formatted.
tcx.sess.good_path_delayed_bug(
"trimmed_def_paths constructed but no error emitted; use `DelayDm` for lints or `with_no_trimmed_paths` for debugging",
);
}

assert!(tcx.sess.opts.trimmed_def_paths);

// Trimming paths is expensive and not optimized, since we expect it to only be used for error
// reporting.
//
// For good paths causing this bug, the `rustc_middle::ty::print::with_no_trimmed_paths`
// wrapper can be used to suppress this query, in exchange for full paths being formatted.
tcx.sess.good_path_delayed_bug(
"trimmed_def_paths constructed but no error emitted; use `DelayDm` for lints or `with_no_trimmed_paths` for debugging",
);

// Once constructed, unique namespace+symbol pairs will have a `Some(_)` entry, while
// non-unique pairs will have a `None` entry.
let unique_symbols_rev: &mut FxHashMap<(Namespace, Symbol), Option<DefId>> =
&mut FxHashMap::default();

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

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

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_mir_build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
# tidy-alphabetical-start
either = "1"
itertools = "0.11"
rustc_apfloat = "0.2.0"
rustc_arena = { path = "../rustc_arena" }
rustc_ast = { path = "../rustc_ast" }
Expand Down
Loading