Skip to content

Rollup of 3 pull requests #144723

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

Merged
merged 16 commits into from
Jul 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ where
// `QueryNormalizeExt::query_normalize` used in the query and `normalize` called below:
// the former fails to normalize the `nll/relate_tys/impl-fn-ignore-binder-via-bottom.rs`
// test. Check after #85499 lands to see if its fixes have erased this difference.
let (param_env, value) = key.into_parts();
let ty::ParamEnvAnd { param_env, value } = key;
let _ = ocx.normalize(&cause, param_env, value.value);

let diag = try_extract_error_from_fulfill_cx(
Expand Down Expand Up @@ -324,7 +324,7 @@ where
mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
let ocx = ObligationCtxt::new(&infcx);

let (param_env, value) = key.into_parts();
let ty::ParamEnvAnd { param_env, value } = key;
let _ = ocx.deeply_normalize(&cause, param_env, value.value);

let diag = try_extract_error_from_fulfill_cx(
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1597,8 +1597,9 @@ impl HumanEmitter {
annotated_files.swap(0, pos);
}

let annotated_files_len = annotated_files.len();
// Print out the annotate source lines that correspond with the error
for annotated_file in annotated_files {
for (file_idx, annotated_file) in annotated_files.into_iter().enumerate() {
// we can't annotate anything if the source is unavailable.
if !should_show_source_code(
&self.ignored_directories_in_source_blocks,
Expand Down Expand Up @@ -1855,7 +1856,9 @@ impl HumanEmitter {
width_offset,
code_offset,
margin,
!is_cont && line_idx + 1 == annotated_file.lines.len(),
!is_cont
&& file_idx + 1 == annotated_files_len
&& line_idx + 1 == annotated_file.lines.len(),
);

let mut to_add = FxHashMap::default();
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_hir_typeck/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use rustc_span::{DUMMY_SP, Span};
use rustc_trait_selection::traits::{ObligationCause, ObligationCtxt};
use tracing::debug;

use crate::typeck_root_ctxt::InferVarInfo;
use crate::{FnCtxt, errors};

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -345,7 +346,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
.map(|(_, info)| *info)
.collect();

let found_infer_var_info = ty::InferVarInfo {
let found_infer_var_info = InferVarInfo {
self_in_trait: infer_var_infos.items().any(|info| info.self_in_trait),
output: infer_var_infos.items().any(|info| info.output),
};
Expand Down
25 changes: 20 additions & 5 deletions compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ enum ClauseFlavor {
Const,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
enum ParamTerm {
Ty(ty::ParamTy),
Const(ty::ParamConst),
}

impl ParamTerm {
fn index(self) -> usize {
match self {
ParamTerm::Ty(ty) => ty.index as usize,
ParamTerm::Const(ct) => ct.index as usize,
}
}
}

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub(crate) fn adjust_fulfillment_error_for_expr_obligation(
&self,
Expand Down Expand Up @@ -77,17 +92,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => return false,
};

let find_param_matching = |matches: &dyn Fn(ty::ParamTerm) -> bool| {
let find_param_matching = |matches: &dyn Fn(ParamTerm) -> bool| {
predicate_args.iter().find_map(|arg| {
arg.walk().find_map(|arg| {
if let ty::GenericArgKind::Type(ty) = arg.kind()
&& let ty::Param(param_ty) = *ty.kind()
&& matches(ty::ParamTerm::Ty(param_ty))
&& matches(ParamTerm::Ty(param_ty))
{
Some(arg)
} else if let ty::GenericArgKind::Const(ct) = arg.kind()
&& let ty::ConstKind::Param(param_ct) = ct.kind()
&& matches(ty::ParamTerm::Const(param_ct))
&& matches(ParamTerm::Const(param_ct))
{
Some(arg)
} else {
Expand All @@ -106,14 +121,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// from a trait or impl, for example.
let mut fallback_param_to_point_at = find_param_matching(&|param_term| {
self.tcx.parent(generics.param_at(param_term.index(), self.tcx).def_id) != def_id
&& !matches!(param_term, ty::ParamTerm::Ty(ty) if ty.name == kw::SelfUpper)
&& !matches!(param_term, ParamTerm::Ty(ty) if ty.name == kw::SelfUpper)
});
// Finally, the `Self` parameter is possibly the reason that the predicate
// is unsatisfied. This is less likely to be true for methods, because
// method probe means that we already kinda check that the predicates due
// to the `Self` type are true.
let mut self_param_to_point_at = find_param_matching(
&|param_term| matches!(param_term, ty::ParamTerm::Ty(ty) if ty.name == kw::SelfUpper),
&|param_term| matches!(param_term, ParamTerm::Ty(ty) if ty.name == kw::SelfUpper),
);

// Finally, for ambiguity-related errors, we actually want to look
Expand Down
15 changes: 14 additions & 1 deletion compiler/rustc_hir_typeck/src/typeck_root_ctxt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ use tracing::{debug, instrument};

use super::callee::DeferredCallResolution;

#[derive(Debug, Default, Copy, Clone)]
pub(crate) struct InferVarInfo {
/// This is true if we identified that this Ty (`?T`) is found in a `?T: Foo`
/// obligation, where:
///
/// * `Foo` is not `Sized`
/// * `(): Foo` may be satisfied
pub self_in_trait: bool,
/// This is true if we identified that this Ty (`?T`) is found in a `<_ as
/// _>::AssocType = ?T`
pub output: bool,
}

/// Data shared between a "typeck root" and its nested bodies,
/// e.g. closures defined within the function. For example:
/// ```ignore (illustrative)
Expand Down Expand Up @@ -71,7 +84,7 @@ pub(crate) struct TypeckRootCtxt<'tcx> {
/// fallback. See the `fallback` module for details.
pub(super) diverging_type_vars: RefCell<UnordSet<Ty<'tcx>>>,

pub(super) infer_var_info: RefCell<UnordMap<ty::TyVid, ty::InferVarInfo>>,
pub(super) infer_var_info: RefCell<UnordMap<ty::TyVid, InferVarInfo>>,
}

impl<'tcx> Deref for TypeckRootCtxt<'tcx> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<'tcx> InferCtxt<'tcx> {
where
V: TypeFoldable<TyCtxt<'tcx>>,
{
let (param_env, value) = value.into_parts();
let ty::ParamEnvAnd { param_env, value } = value;
let canonical_param_env = self.tcx.canonical_param_env_cache.get_or_insert(
self.tcx,
param_env,
Expand Down
36 changes: 26 additions & 10 deletions compiler/rustc_infer/src/infer/relate/generalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ use crate::infer::type_variable::TypeVariableValue;
use crate::infer::unify_key::ConstVariableValue;
use crate::infer::{InferCtxt, RegionVariableOrigin, relate};

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
enum TermVid {
Ty(ty::TyVid),
Const(ty::ConstVid),
}

impl From<ty::TyVid> for TermVid {
fn from(value: ty::TyVid) -> Self {
TermVid::Ty(value)
}
}

impl From<ty::ConstVid> for TermVid {
fn from(value: ty::ConstVid) -> Self {
TermVid::Const(value)
}
}

impl<'tcx> InferCtxt<'tcx> {
/// The idea is that we should ensure that the type variable `target_vid`
/// is equal to, a subtype of, or a supertype of `source_ty`.
Expand Down Expand Up @@ -238,20 +256,18 @@ impl<'tcx> InferCtxt<'tcx> {
&self,
span: Span,
structurally_relate_aliases: StructurallyRelateAliases,
target_vid: impl Into<ty::TermVid>,
target_vid: impl Into<TermVid>,
ambient_variance: ty::Variance,
source_term: T,
) -> RelateResult<'tcx, Generalization<T>> {
assert!(!source_term.has_escaping_bound_vars());
let (for_universe, root_vid) = match target_vid.into() {
ty::TermVid::Ty(ty_vid) => {
(self.probe_ty_var(ty_vid).unwrap_err(), ty::TermVid::Ty(self.root_var(ty_vid)))
TermVid::Ty(ty_vid) => {
(self.probe_ty_var(ty_vid).unwrap_err(), TermVid::Ty(self.root_var(ty_vid)))
}
ty::TermVid::Const(ct_vid) => (
TermVid::Const(ct_vid) => (
self.probe_const_var(ct_vid).unwrap_err(),
ty::TermVid::Const(
self.inner.borrow_mut().const_unification_table().find(ct_vid).vid,
),
TermVid::Const(self.inner.borrow_mut().const_unification_table().find(ct_vid).vid),
),
};

Expand Down Expand Up @@ -299,7 +315,7 @@ struct Generalizer<'me, 'tcx> {
/// The vid of the type variable that is in the process of being
/// instantiated. If we find this within the value we are folding,
/// that means we would have created a cyclic value.
root_vid: ty::TermVid,
root_vid: TermVid,

/// The universe of the type variable that is in the process of being
/// instantiated. If we find anything that this universe cannot name,
Expand Down Expand Up @@ -469,7 +485,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
ty::Infer(ty::TyVar(vid)) => {
let mut inner = self.infcx.inner.borrow_mut();
let vid = inner.type_variables().root_var(vid);
if ty::TermVid::Ty(vid) == self.root_vid {
if TermVid::Ty(vid) == self.root_vid {
// If sub-roots are equal, then `root_vid` and
// `vid` are related via subtyping.
Err(self.cyclic_term_error())
Expand Down Expand Up @@ -621,7 +637,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
// If root const vids are equal, then `root_vid` and
// `vid` are related and we'd be inferring an infinitely
// deep const.
if ty::TermVid::Const(
if TermVid::Const(
self.infcx.inner.borrow_mut().const_unification_table().find(vid).vid,
) == self.root_vid
{
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use rustc_parse::{
new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal, validate_attr,
};
use rustc_passes::{abi_test, input_stats, layout_test};
use rustc_resolve::Resolver;
use rustc_resolve::{Resolver, ResolverOutputs};
use rustc_session::config::{CrateType, Input, OutFileName, OutputFilenames, OutputType};
use rustc_session::cstore::Untracked;
use rustc_session::output::{collect_crate_types, filename_for_input};
Expand Down Expand Up @@ -793,7 +793,7 @@ fn resolver_for_lowering_raw<'tcx>(
// Make sure we don't mutate the cstore from here on.
tcx.untracked().cstore.freeze();

let ty::ResolverOutputs {
let ResolverOutputs {
global_ctxt: untracked_resolutions,
ast_lowering: untracked_resolver_for_lowering,
} = resolver.into_outputs();
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_middle/src/ty/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,9 @@ impl_decodable_via_ref! {
&'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
&'tcx traits::ImplSource<'tcx, ()>,
&'tcx mir::Body<'tcx>,
&'tcx mir::ConcreteOpaqueTypes<'tcx>,
&'tcx ty::List<ty::BoundVariableKind>,
&'tcx ty::List<ty::Pattern<'tcx>>,
&'tcx ty::ListWithCachedTypeInfo<ty::Clause<'tcx>>,
&'tcx ty::List<FieldIdx>,
&'tcx ty::List<(VariantIdx, FieldIdx)>,
}

#[macro_export]
Expand Down
Loading
Loading