Skip to content

Commit e526d12

Browse files
committed
Auto merge of #105187 - matthiaskrgr:rollup-nxyxpko, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #105026 (v8a as default aarch64 target) - #105033 (sparc-struct-abi: work around new tail-call optimization) - #105144 (Document normalization methods `At::{normalize,query_normalize}`) - #105155 (rustdoc: clean up help and settings button CSS) - #105162 (Properly synthesize `FnSig` value during cycle) - #105163 (Check lifetime param count in `collect_trait_impl_trait_tys`) - #105185 (Move `normalize_fn_sig` to `TypeErrCtxt`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 32e613b + 8e0d83a commit e526d12

File tree

19 files changed

+198
-151
lines changed

19 files changed

+198
-151
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+5
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,11 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
494494
.flatten();
495495
features.extend(feats);
496496

497+
// FIXME: Move v8a to target definition list when earliest supported LLVM is 14.
498+
if get_version() >= (14, 0, 0) && sess.target.arch == "aarch64" {
499+
features.push("+v8a".into());
500+
}
501+
497502
if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) {
498503
sess.emit_err(TargetFeatureDisableOrEnable {
499504
features: f,

compiler/rustc_hir_analysis/src/check/compare_method.rs

+18-21
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,11 @@ fn compare_predicate_entailment<'tcx>(
173173
impl_to_placeholder_substs.rebase_onto(tcx, impl_m.container_id(tcx), trait_to_impl_substs);
174174
debug!("compare_impl_method: trait_to_placeholder_substs={:?}", trait_to_placeholder_substs);
175175

176-
let impl_m_generics = tcx.generics_of(impl_m.def_id);
177-
let trait_m_generics = tcx.generics_of(trait_m.def_id);
178176
let impl_m_predicates = tcx.predicates_of(impl_m.def_id);
179177
let trait_m_predicates = tcx.predicates_of(trait_m.def_id);
180178

181179
// Check region bounds.
182-
check_region_bounds_on_impl_item(tcx, impl_m, trait_m, &trait_m_generics, &impl_m_generics)?;
180+
check_region_bounds_on_impl_item(tcx, impl_m, trait_m, false)?;
183181

184182
// Create obligations for each predicate declared by the impl
185183
// definition in the context of the trait's parameter
@@ -338,6 +336,7 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
338336
// First, check a few of the same thing as `compare_impl_method`, just so we don't ICE during substitutions later.
339337
compare_number_of_generics(tcx, impl_m, trait_m, tcx.hir().span_if_local(impl_m.def_id), true)?;
340338
compare_generic_param_kinds(tcx, impl_m, trait_m, true)?;
339+
check_region_bounds_on_impl_item(tcx, impl_m, trait_m, true)?;
341340

342341
let trait_to_impl_substs = impl_trait_ref.substs;
343342

@@ -722,12 +721,14 @@ fn check_region_bounds_on_impl_item<'tcx>(
722721
tcx: TyCtxt<'tcx>,
723722
impl_m: &ty::AssocItem,
724723
trait_m: &ty::AssocItem,
725-
trait_generics: &ty::Generics,
726-
impl_generics: &ty::Generics,
724+
delay: bool,
727725
) -> Result<(), ErrorGuaranteed> {
728-
let trait_params = trait_generics.own_counts().lifetimes;
726+
let impl_generics = tcx.generics_of(impl_m.def_id);
729727
let impl_params = impl_generics.own_counts().lifetimes;
730728

729+
let trait_generics = tcx.generics_of(trait_m.def_id);
730+
let trait_params = trait_generics.own_counts().lifetimes;
731+
731732
debug!(
732733
"check_region_bounds_on_impl_item: \
733734
trait_generics={:?} \
@@ -761,12 +762,16 @@ fn check_region_bounds_on_impl_item<'tcx>(
761762
None
762763
};
763764

764-
let reported = tcx.sess.emit_err(LifetimesOrBoundsMismatchOnTrait {
765-
span,
766-
item_kind: assoc_item_kind_str(impl_m),
767-
ident: impl_m.ident(tcx),
768-
generics_span,
769-
});
765+
let reported = tcx
766+
.sess
767+
.create_err(LifetimesOrBoundsMismatchOnTrait {
768+
span,
769+
item_kind: assoc_item_kind_str(impl_m),
770+
ident: impl_m.ident(tcx),
771+
generics_span,
772+
})
773+
.emit_unless(delay);
774+
770775
return Err(reported);
771776
}
772777

@@ -1504,18 +1509,10 @@ fn compare_type_predicate_entailment<'tcx>(
15041509
let trait_to_impl_substs =
15051510
impl_substs.rebase_onto(tcx, impl_ty.container_id(tcx), impl_trait_ref.substs);
15061511

1507-
let impl_ty_generics = tcx.generics_of(impl_ty.def_id);
1508-
let trait_ty_generics = tcx.generics_of(trait_ty.def_id);
15091512
let impl_ty_predicates = tcx.predicates_of(impl_ty.def_id);
15101513
let trait_ty_predicates = tcx.predicates_of(trait_ty.def_id);
15111514

1512-
check_region_bounds_on_impl_item(
1513-
tcx,
1514-
impl_ty,
1515-
trait_ty,
1516-
&trait_ty_generics,
1517-
&impl_ty_generics,
1518-
)?;
1515+
check_region_bounds_on_impl_item(tcx, impl_ty, trait_ty, false)?;
15191516

15201517
let impl_ty_own_bounds = impl_ty_predicates.instantiate_own(tcx, impl_substs);
15211518

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_middle::ty::{self, Const, Ty, TyCtxt};
2222
use rustc_session::Session;
2323
use rustc_span::symbol::Ident;
2424
use rustc_span::{self, Span};
25-
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode};
25+
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode, ObligationCtxt};
2626

2727
use std::cell::{Cell, RefCell};
2828
use std::ops::Deref;
@@ -162,6 +162,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
162162
infcx: &self.infcx,
163163
typeck_results: Some(self.typeck_results.borrow()),
164164
fallback_has_occurred: self.fallback_has_occurred.get(),
165+
normalize_fn_sig: Box::new(|fn_sig| {
166+
if fn_sig.has_escaping_bound_vars() {
167+
return fn_sig;
168+
}
169+
self.probe(|_| {
170+
let ocx = ObligationCtxt::new_in_snapshot(self);
171+
let normalized_fn_sig =
172+
ocx.normalize(&ObligationCause::dummy(), self.param_env, fn_sig);
173+
if ocx.select_all_or_error().is_empty() {
174+
let normalized_fn_sig = self.resolve_vars_if_possible(normalized_fn_sig);
175+
if !normalized_fn_sig.needs_infer() {
176+
return normalized_fn_sig;
177+
}
178+
}
179+
fn_sig
180+
})
181+
}),
165182
}
166183
}
167184

compiler/rustc_hir_typeck/src/inherited.rs

+2-27
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::callee::DeferredCallResolution;
22

33
use rustc_data_structures::fx::FxHashSet;
4-
use rustc_data_structures::sync::Lrc;
54
use rustc_hir as hir;
65
use rustc_hir::def_id::LocalDefId;
76
use rustc_hir::HirIdMap;
@@ -11,9 +10,7 @@ use rustc_middle::ty::visit::TypeVisitable;
1110
use rustc_middle::ty::{self, Ty, TyCtxt};
1211
use rustc_span::def_id::LocalDefIdMap;
1312
use rustc_span::{self, Span};
14-
use rustc_trait_selection::traits::{
15-
self, ObligationCause, ObligationCtxt, TraitEngine, TraitEngineExt as _,
16-
};
13+
use rustc_trait_selection::traits::{self, TraitEngine, TraitEngineExt as _};
1714

1815
use std::cell::RefCell;
1916
use std::ops::Deref;
@@ -92,29 +89,7 @@ impl<'tcx> Inherited<'tcx> {
9289
infcx: tcx
9390
.infer_ctxt()
9491
.ignoring_regions()
95-
.with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id))
96-
.with_normalize_fn_sig_for_diagnostic(Lrc::new(move |infcx, fn_sig| {
97-
if fn_sig.has_escaping_bound_vars() {
98-
return fn_sig;
99-
}
100-
infcx.probe(|_| {
101-
let ocx = ObligationCtxt::new_in_snapshot(infcx);
102-
let normalized_fn_sig = ocx.normalize(
103-
&ObligationCause::dummy(),
104-
// FIXME(compiler-errors): This is probably not the right param-env...
105-
infcx.tcx.param_env(def_id),
106-
fn_sig,
107-
);
108-
if ocx.select_all_or_error().is_empty() {
109-
let normalized_fn_sig =
110-
infcx.resolve_vars_if_possible(normalized_fn_sig);
111-
if !normalized_fn_sig.needs_infer() {
112-
return normalized_fn_sig;
113-
}
114-
}
115-
fn_sig
116-
})
117-
})),
92+
.with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id)),
11893
def_id,
11994
typeck_results: RefCell::new(ty::TypeckResults::new(hir_owner)),
12095
}

compiler/rustc_infer/src/infer/at.rs

-4
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ impl<'tcx> InferCtxt<'tcx> {
7777
err_count_on_creation: self.err_count_on_creation,
7878
in_snapshot: self.in_snapshot.clone(),
7979
universe: self.universe.clone(),
80-
normalize_fn_sig_for_diagnostic: self
81-
.normalize_fn_sig_for_diagnostic
82-
.as_ref()
83-
.map(|f| f.clone()),
8480
intercrate: self.intercrate,
8581
}
8682
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pub mod nice_region_error;
9595
pub struct TypeErrCtxt<'a, 'tcx> {
9696
pub infcx: &'a InferCtxt<'tcx>,
9797
pub typeck_results: Option<std::cell::Ref<'a, ty::TypeckResults<'tcx>>>,
98+
pub normalize_fn_sig: Box<dyn Fn(ty::PolyFnSig<'tcx>) -> ty::PolyFnSig<'tcx> + 'a>,
9899
pub fallback_has_occurred: bool,
99100
}
100101

@@ -1007,22 +1008,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
10071008
}
10081009
}
10091010

1010-
fn normalize_fn_sig_for_diagnostic(&self, sig: ty::PolyFnSig<'tcx>) -> ty::PolyFnSig<'tcx> {
1011-
if let Some(normalize) = &self.normalize_fn_sig_for_diagnostic {
1012-
normalize(self, sig)
1013-
} else {
1014-
sig
1015-
}
1016-
}
1017-
10181011
/// Given two `fn` signatures highlight only sub-parts that are different.
10191012
fn cmp_fn_sig(
10201013
&self,
10211014
sig1: &ty::PolyFnSig<'tcx>,
10221015
sig2: &ty::PolyFnSig<'tcx>,
10231016
) -> (DiagnosticStyledString, DiagnosticStyledString) {
1024-
let sig1 = &self.normalize_fn_sig_for_diagnostic(*sig1);
1025-
let sig2 = &self.normalize_fn_sig_for_diagnostic(*sig2);
1017+
let sig1 = &(self.normalize_fn_sig)(*sig1);
1018+
let sig2 = &(self.normalize_fn_sig)(*sig2);
10261019

10271020
let get_lifetimes = |sig| {
10281021
use rustc_hir::def::Namespace;

compiler/rustc_infer/src/infer/mod.rs

+7-26
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ pub struct InferOk<'tcx, T> {
8080
}
8181
pub type InferResult<'tcx, T> = Result<InferOk<'tcx, T>, TypeError<'tcx>>;
8282

83-
pub type Bound<T> = Option<T>;
8483
pub type UnitResult<'tcx> = RelateResult<'tcx, ()>; // "unify result"
8584
pub type FixupResult<'tcx, T> = Result<T, FixupError<'tcx>>; // "fixup result"
8685

@@ -334,9 +333,6 @@ pub struct InferCtxt<'tcx> {
334333
/// bound.
335334
universe: Cell<ty::UniverseIndex>,
336335

337-
normalize_fn_sig_for_diagnostic:
338-
Option<Lrc<dyn Fn(&InferCtxt<'tcx>, ty::PolyFnSig<'tcx>) -> ty::PolyFnSig<'tcx>>>,
339-
340336
/// During coherence we have to assume that other crates may add
341337
/// additional impls which we currently don't know about.
342338
///
@@ -573,8 +569,6 @@ pub struct InferCtxtBuilder<'tcx> {
573569
considering_regions: bool,
574570
/// Whether we are in coherence mode.
575571
intercrate: bool,
576-
normalize_fn_sig_for_diagnostic:
577-
Option<Lrc<dyn Fn(&InferCtxt<'tcx>, ty::PolyFnSig<'tcx>) -> ty::PolyFnSig<'tcx>>>,
578572
}
579573

580574
pub trait TyCtxtInferExt<'tcx> {
@@ -587,7 +581,6 @@ impl<'tcx> TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
587581
tcx: self,
588582
defining_use_anchor: DefiningAnchor::Error,
589583
considering_regions: true,
590-
normalize_fn_sig_for_diagnostic: None,
591584
intercrate: false,
592585
}
593586
}
@@ -615,14 +608,6 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
615608
self
616609
}
617610

618-
pub fn with_normalize_fn_sig_for_diagnostic(
619-
mut self,
620-
fun: Lrc<dyn Fn(&InferCtxt<'tcx>, ty::PolyFnSig<'tcx>) -> ty::PolyFnSig<'tcx>>,
621-
) -> Self {
622-
self.normalize_fn_sig_for_diagnostic = Some(fun);
623-
self
624-
}
625-
626611
/// Given a canonical value `C` as a starting point, create an
627612
/// inference context that contains each of the bound values
628613
/// within instantiated as a fresh variable. The `f` closure is
@@ -644,13 +629,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
644629
}
645630

646631
pub fn build(&mut self) -> InferCtxt<'tcx> {
647-
let InferCtxtBuilder {
648-
tcx,
649-
defining_use_anchor,
650-
considering_regions,
651-
ref normalize_fn_sig_for_diagnostic,
652-
intercrate,
653-
} = *self;
632+
let InferCtxtBuilder { tcx, defining_use_anchor, considering_regions, intercrate } = *self;
654633
InferCtxt {
655634
tcx,
656635
defining_use_anchor,
@@ -666,9 +645,6 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
666645
in_snapshot: Cell::new(false),
667646
skip_leak_check: Cell::new(false),
668647
universe: Cell::new(ty::UniverseIndex::ROOT),
669-
normalize_fn_sig_for_diagnostic: normalize_fn_sig_for_diagnostic
670-
.as_ref()
671-
.map(|f| f.clone()),
672648
intercrate,
673649
}
674650
}
@@ -709,7 +685,12 @@ impl<'tcx> InferCtxt<'tcx> {
709685
/// Creates a `TypeErrCtxt` for emitting various inference errors.
710686
/// During typeck, use `FnCtxt::err_ctxt` instead.
711687
pub fn err_ctxt(&self) -> TypeErrCtxt<'_, 'tcx> {
712-
TypeErrCtxt { infcx: self, typeck_results: None, fallback_has_occurred: false }
688+
TypeErrCtxt {
689+
infcx: self,
690+
typeck_results: None,
691+
fallback_has_occurred: false,
692+
normalize_fn_sig: Box::new(|fn_sig| fn_sig),
693+
}
713694
}
714695

715696
pub fn is_in_snapshot(&self) -> bool {

compiler/rustc_middle/src/values.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,23 @@ impl<'tcx> Value<TyCtxt<'tcx>> for ty::SymbolName<'_> {
3232
}
3333

3434
impl<'tcx> Value<TyCtxt<'tcx>> for ty::Binder<'_, ty::FnSig<'_>> {
35-
fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &[QueryInfo]) -> Self {
35+
fn from_cycle_error(tcx: TyCtxt<'tcx>, stack: &[QueryInfo]) -> Self {
3636
let err = tcx.ty_error();
37-
// FIXME(compiler-errors): It would be nice if we could get the
38-
// query key, so we could at least generate a fn signature that
39-
// has the right arity.
37+
38+
let arity = if let Some(frame) = stack.get(0)
39+
&& frame.query.name == "fn_sig"
40+
&& let Some(def_id) = frame.query.def_id
41+
&& let Some(node) = tcx.hir().get_if_local(def_id)
42+
&& let Some(sig) = node.fn_sig()
43+
{
44+
sig.decl.inputs.len() + sig.decl.implicit_self.has_implicit_self() as usize
45+
} else {
46+
tcx.sess.abort_if_errors();
47+
unreachable!()
48+
};
49+
4050
let fn_sig = ty::Binder::dummy(tcx.mk_fn_sig(
41-
[].into_iter(),
51+
std::iter::repeat(err).take(arity),
4252
err,
4353
false,
4454
rustc_hir::Unsafety::Normal,

compiler/rustc_trait_selection/src/traits/coherence.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use crate::traits::select::IntercrateAmbiguityCause;
1111
use crate::traits::util::impl_subject_and_oblig;
1212
use crate::traits::SkipLeakCheck;
1313
use crate::traits::{
14-
self, Normalized, Obligation, ObligationCause, ObligationCtxt, PredicateObligation,
15-
PredicateObligations, SelectionContext,
14+
self, Obligation, ObligationCause, ObligationCtxt, PredicateObligation, PredicateObligations,
15+
SelectionContext,
1616
};
1717
use rustc_data_structures::fx::FxIndexSet;
1818
use rustc_errors::Diagnostic;
@@ -30,6 +30,8 @@ use std::fmt::Debug;
3030
use std::iter;
3131
use std::ops::ControlFlow;
3232

33+
use super::NormalizeExt;
34+
3335
/// Whether we do the orphan check relative to this crate or
3436
/// to some remote crate.
3537
#[derive(Copy, Clone, Debug)]
@@ -128,8 +130,8 @@ fn with_fresh_ty_vars<'cx, 'tcx>(
128130
predicates: tcx.predicates_of(impl_def_id).instantiate(tcx, impl_substs).predicates,
129131
};
130132

131-
let Normalized { value: mut header, obligations } =
132-
traits::normalize(selcx, param_env, ObligationCause::dummy(), header);
133+
let InferOk { value: mut header, obligations } =
134+
selcx.infcx.at(&ObligationCause::dummy(), param_env).normalize(header);
133135

134136
header.predicates.extend(obligations.into_iter().map(|o| o.predicate));
135137
header

compiler/rustc_trait_selection/src/traits/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub use self::object_safety::astconv_object_safety_violations;
5656
pub use self::object_safety::is_vtable_safe_method;
5757
pub use self::object_safety::MethodViolationCode;
5858
pub use self::object_safety::ObjectSafetyViolation;
59-
pub(crate) use self::project::{normalize, normalize_to};
6059
pub use self::project::{normalize_projection_type, NormalizeExt};
6160
pub use self::select::{EvaluationCache, SelectionCache, SelectionContext};
6261
pub use self::select::{EvaluationResult, IntercrateAmbiguityCause, OverflowError};

0 commit comments

Comments
 (0)