Skip to content

Commit

Permalink
Auto merge of rust-lang#112383 - Dylan-DPC:rollup-et2z6nt, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

Successful merges:

 - rust-lang#112076 (Fall back to bidirectional normalizes-to if no subst-relate candidate in alias-relate goal)
 - rust-lang#112122 (Add `-Ztrait-solver=next-coherence`)
 - rust-lang#112251 (rustdoc: convert `if let Some()` that always matches to variable)
 - rust-lang#112345 (fix(expand): prevent infinity loop in macro containing only "///")
 - rust-lang#112359 (Respect `RUST_BACKTRACE` for delayed bugs)
 - rust-lang#112382 (download-rustc: Fix `x test core` on MacOS)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jun 7, 2023
2 parents e94bda3 + 90c361c commit b2807b2
Show file tree
Hide file tree
Showing 49 changed files with 671 additions and 232 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
let infcx = self
.tcx
.infer_ctxt()
.with_opaque_type_inference(if self.tcx.trait_solver_next() {
.with_opaque_type_inference(if self.next_trait_solver() {
DefiningAnchor::Bind(def_id)
} else {
DefiningAnchor::Bubble
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub(crate) fn type_check<'mir, 'tcx>(

// FIXME(-Ztrait-solver=next): A bit dubious that we're only registering
// predefined opaques in the typeck root.
if infcx.tcx.trait_solver_next() && !infcx.tcx.is_typeck_child(body.source.def_id()) {
if infcx.next_trait_solver() && !infcx.tcx.is_typeck_child(body.source.def_id()) {
checker.register_predefined_opaques_in_new_solver();
}

Expand Down
18 changes: 14 additions & 4 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, Noted};
pub use diagnostic_impls::{
DiagnosticArgFromDisplay, DiagnosticSymbolList, LabelKind, SingleLabelManySpans,
};
use std::backtrace::Backtrace;
use std::backtrace::{Backtrace, BacktraceStatus};

/// A handler deals with errors and other compiler output.
/// Certain errors (fatal, bug, unimpl) may cause immediate exit,
Expand Down Expand Up @@ -1331,7 +1331,7 @@ impl HandlerInner {
// once *any* errors were emitted (and truncate `delayed_span_bugs`
// when an error is first emitted, also), but maybe there's a case
// in which that's not sound? otherwise this is really inefficient.
let backtrace = std::backtrace::Backtrace::force_capture();
let backtrace = std::backtrace::Backtrace::capture();
self.delayed_span_bugs
.push(DelayedDiagnostic::with_backtrace(diagnostic.clone(), backtrace));

Expand Down Expand Up @@ -1620,7 +1620,7 @@ impl HandlerInner {
if self.flags.report_delayed_bugs {
self.emit_diagnostic(&mut diagnostic);
}
let backtrace = std::backtrace::Backtrace::force_capture();
let backtrace = std::backtrace::Backtrace::capture();
self.delayed_good_path_bugs.push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace));
}

Expand Down Expand Up @@ -1739,7 +1739,17 @@ impl DelayedDiagnostic {
}

fn decorate(mut self) -> Diagnostic {
self.inner.note(format!("delayed at {}\n{}", self.inner.emitted_at, self.note));
match self.note.status() {
BacktraceStatus::Captured => {
self.inner.note(format!("delayed at {}\n{}", self.inner.emitted_at, self.note));
}
// Avoid the needless newline when no backtrace has been captured,
// the display impl should just be a single line.
_ => {
self.inner.note(format!("delayed at {} - {}", self.inner.emitted_at, self.note));
}
}

self.inner
}
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_expand/src/mbe/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ pub(super) fn compute_locs(matcher: &[TokenTree]) -> Vec<MatcherLoc> {
}

/// A single matcher position, representing the state of matching.
#[derive(Debug)]
struct MatcherPos {
/// The index into `TtParser::locs`, which represents the "dot".
idx: usize,
Expand Down
45 changes: 35 additions & 10 deletions compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,40 @@ fn check_lhs_nt_follows(sess: &ParseSess, def: &ast::Item, lhs: &mbe::TokenTree)
// after parsing/expansion. we can report every error in every macro this way.
}

fn is_empty_token_tree(sess: &ParseSess, seq: &mbe::SequenceRepetition) -> bool {
if seq.separator.is_some() {
false
} else {
let mut is_empty = true;
let mut iter = seq.tts.iter().peekable();
while let Some(tt) = iter.next() {
match tt {
mbe::TokenTree::MetaVarDecl(_, _, Some(NonterminalKind::Vis)) => {}
mbe::TokenTree::Token(t @ Token { kind: DocComment(..), .. }) => {
let mut now = t;
while let Some(&mbe::TokenTree::Token(
next @ Token { kind: DocComment(..), .. },
)) = iter.peek()
{
now = next;
iter.next();
}
let span = t.span.to(now.span);
sess.span_diagnostic.span_note_without_error(
span,
"doc comments are ignored in matcher position",
);
}
mbe::TokenTree::Sequence(_, sub_seq)
if (sub_seq.kleene.op == mbe::KleeneOp::ZeroOrMore
|| sub_seq.kleene.op == mbe::KleeneOp::ZeroOrOne) => {}
_ => is_empty = false,
}
}
is_empty
}
}

/// Checks that the lhs contains no repetition which could match an empty token
/// tree, because then the matcher would hang indefinitely.
fn check_lhs_no_empty_seq(sess: &ParseSess, tts: &[mbe::TokenTree]) -> bool {
Expand All @@ -644,16 +678,7 @@ fn check_lhs_no_empty_seq(sess: &ParseSess, tts: &[mbe::TokenTree]) -> bool {
}
}
TokenTree::Sequence(span, seq) => {
if seq.separator.is_none()
&& seq.tts.iter().all(|seq_tt| match seq_tt {
TokenTree::MetaVarDecl(_, _, Some(NonterminalKind::Vis)) => true,
TokenTree::Sequence(_, sub_seq) => {
sub_seq.kleene.op == mbe::KleeneOp::ZeroOrMore
|| sub_seq.kleene.op == mbe::KleeneOp::ZeroOrOne
}
_ => false,
})
{
if is_empty_token_tree(sess, seq) {
let sp = span.entire();
sess.span_diagnostic.span_err(sp, "repetition matches empty token tree");
return false;
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_hir_analysis/src/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<'a, 'tcx> Iterator for Autoderef<'a, 'tcx> {
// NOTE: we may still need to normalize the built-in deref in case
// we have some type like `&<Ty as Trait>::Assoc`, since users of
// autoderef expect this type to have been structurally normalized.
if self.infcx.tcx.trait_solver_next()
if self.infcx.next_trait_solver()
&& let ty::Alias(ty::Projection, _) = ty.kind()
{
let (normalized_ty, obligations) = self.structurally_normalize(ty)?;
Expand Down Expand Up @@ -161,8 +161,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
&self,
ty: Ty<'tcx>,
) -> Option<(Ty<'tcx>, Vec<traits::PredicateObligation<'tcx>>)> {
let tcx = self.infcx.tcx;
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new_in_snapshot(tcx);
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new_in_snapshot(self.infcx);

let cause = traits::ObligationCause::misc(self.span, self.body_id);
let normalized_ty = match self
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ pub(super) fn check_generator_obligations(tcx: TyCtxt<'_>, def_id: LocalDefId) {
.with_opaque_type_inference(DefiningAnchor::Bind(def_id))
.build();

let mut fulfillment_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
let mut fulfillment_cx = <dyn TraitEngine<'_>>::new(&infcx);
for (predicate, cause) in generator_interior_predicates {
let obligation = Obligation::new(tcx, cause.clone(), param_env, *predicate);
fulfillment_cx.register_predicate_obligation(&infcx, obligation);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
// In the new solver, lazy norm may allow us to shallowly equate
// more types, but we emit possibly impossible-to-satisfy obligations.
// Filter these cases out to make sure our coercion is more accurate.
if self.tcx.trait_solver_next() {
if self.next_trait_solver() {
if let Ok(res) = &res {
for obligation in &res.obligations {
if !self.predicate_may_hold(&obligation) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn structurally_resolved_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
let mut ty = self.resolve_vars_with_obligations(ty);

if self.tcx.trait_solver_next()
if self.next_trait_solver()
&& let ty::Alias(ty::Projection, _) = ty.kind()
{
match self
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/inherited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ impl<'tcx> Inherited<'tcx> {

Inherited {
typeck_results,
fulfillment_cx: RefCell::new(<dyn TraitEngine<'_>>::new(&infcx)),
infcx,
fulfillment_cx: RefCell::new(<dyn TraitEngine<'_>>::new(tcx)),
locals: RefCell::new(Default::default()),
deferred_sized_obligations: RefCell::new(Vec::new()),
deferred_call_resolutions: RefCell::new(Default::default()),
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
.insert(opaque_type_key, hidden_type)
&& last_opaque_ty.ty != hidden_type.ty
{
assert!(!self.tcx().trait_solver_next());
assert!(!self.fcx.next_trait_solver());
hidden_type
.report_mismatch(&last_opaque_ty, opaque_type_key.def_id, self.tcx())
.stash(
Expand Down Expand Up @@ -812,7 +812,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {

fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
match self.fcx.fully_resolve(t) {
Ok(t) if self.fcx.tcx.trait_solver_next() => {
Ok(t) if self.fcx.next_trait_solver() => {
// We must normalize erasing regions here, since later lints
// expect that types that show up in the typeck are fully
// normalized.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_infer/src/infer/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl<'tcx> InferCtxt<'tcx> {
in_snapshot: self.in_snapshot.clone(),
universe: self.universe.clone(),
intercrate: self.intercrate,
next_trait_solver: self.next_trait_solver,
}
}
}
Expand Down
32 changes: 15 additions & 17 deletions compiler/rustc_infer/src/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ impl<'tcx> InferCtxt<'tcx> {
| (
ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)),
ty::Alias(AliasKind::Projection, _),
) if self.tcx.trait_solver_next() => {
) if self.next_trait_solver() => {
bug!()
}

(_, ty::Alias(..)) | (ty::Alias(..), _) if self.tcx.trait_solver_next() => {
(_, ty::Alias(..)) | (ty::Alias(..), _) if self.next_trait_solver() => {
relation.register_type_relate_obligation(a, b);
Ok(a)
}
Expand Down Expand Up @@ -227,9 +227,20 @@ impl<'tcx> InferCtxt<'tcx> {
return self.unify_const_variable(vid, a, relation.param_env());
}
(ty::ConstKind::Unevaluated(..), _) | (_, ty::ConstKind::Unevaluated(..))
if self.tcx.features().generic_const_exprs || self.tcx.trait_solver_next() =>
if self.tcx.features().generic_const_exprs || self.next_trait_solver() =>
{
relation.register_const_equate_obligation(a, b);
let (a, b) = if relation.a_is_expected() { (a, b) } else { (b, a) };

relation.register_predicates([ty::Binder::dummy(if self.next_trait_solver() {
ty::PredicateKind::AliasRelate(
a.into(),
b.into(),
ty::AliasRelationDirection::Equate,
)
} else {
ty::PredicateKind::ConstEquate(a, b)
})]);

return Ok(b);
}
_ => {}
Expand Down Expand Up @@ -453,19 +464,6 @@ pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> {
/// be used if control over the obligation causes is required.
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ToPredicate<'tcx>>);

/// Register an obligation that both constants must be equal to each other.
///
/// If they aren't equal then the relation doesn't hold.
fn register_const_equate_obligation(&mut self, a: ty::Const<'tcx>, b: ty::Const<'tcx>) {
let (a, b) = if self.a_is_expected() { (a, b) } else { (b, a) };

self.register_predicates([ty::Binder::dummy(if self.tcx().trait_solver_next() {
ty::PredicateKind::AliasRelate(a.into(), b.into(), ty::AliasRelationDirection::Equate)
} else {
ty::PredicateKind::ConstEquate(a, b)
})]);
}

/// Register an obligation that both types must be related to each other according to
/// the [`ty::AliasRelationDirection`] given by [`ObligationEmittingRelation::alias_relate_direction`]
fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/equate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
if self.fields.define_opaque_types == DefineOpaqueTypes::Yes
&& def_id.is_local()
&& !self.tcx().trait_solver_next() =>
&& !self.fields.infcx.next_trait_solver() =>
{
self.fields.obligations.extend(
infcx
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/lattice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ where
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
if this.define_opaque_types() == DefineOpaqueTypes::Yes
&& def_id.is_local()
&& !this.tcx().trait_solver_next() =>
&& !this.infcx().next_trait_solver() =>
{
this.register_obligations(
infcx
Expand Down
17 changes: 17 additions & 0 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ pub struct InferCtxt<'tcx> {
/// there is no type that the user could *actually name* that
/// would satisfy it. This avoids crippling inference, basically.
pub intercrate: bool,

next_trait_solver: bool,
}

/// See the `error_reporting` module for more details.
Expand Down Expand Up @@ -545,6 +547,9 @@ pub struct InferCtxtBuilder<'tcx> {
skip_leak_check: bool,
/// Whether we are in coherence mode.
intercrate: bool,
/// Whether we should use the new trait solver in the local inference context,
/// which affects things like which solver is used in `predicate_may_hold`.
next_trait_solver: bool,
}

pub trait TyCtxtInferExt<'tcx> {
Expand All @@ -559,6 +564,7 @@ impl<'tcx> TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
considering_regions: true,
skip_leak_check: false,
intercrate: false,
next_trait_solver: self.next_trait_solver_globally(),
}
}
}
Expand All @@ -575,6 +581,11 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
self
}

pub fn with_next_trait_solver(mut self, next_trait_solver: bool) -> Self {
self.next_trait_solver = next_trait_solver;
self
}

pub fn intercrate(mut self, intercrate: bool) -> Self {
self.intercrate = intercrate;
self
Expand Down Expand Up @@ -617,6 +628,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
considering_regions,
skip_leak_check,
intercrate,
next_trait_solver,
} = *self;
InferCtxt {
tcx,
Expand All @@ -634,6 +646,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
in_snapshot: Cell::new(false),
universe: Cell::new(ty::UniverseIndex::ROOT),
intercrate,
next_trait_solver,
}
}
}
Expand Down Expand Up @@ -670,6 +683,10 @@ pub struct CombinedSnapshot<'tcx> {
}

impl<'tcx> InferCtxt<'tcx> {
pub fn next_trait_solver(&self) -> bool {
self.next_trait_solver
}

/// Creates a `TypeErrCtxt` for emitting various inference errors.
/// During typeck, use `FnCtxt::err_ctxt` instead.
pub fn err_ctxt(&self) -> TypeErrCtxt<'_, 'tcx> {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/nll_relate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,12 @@ where
(
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }),
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }),
) if a_def_id == b_def_id || infcx.tcx.trait_solver_next() => {
) if a_def_id == b_def_id || infcx.next_trait_solver() => {
infcx.super_combine_tys(self, a, b).or_else(|err| {
// This behavior is only there for the old solver, the new solver
// shouldn't ever fail. Instead, it unconditionally emits an
// alias-relate goal.
assert!(!self.tcx().trait_solver_next());
assert!(!self.infcx.next_trait_solver());
self.tcx().sess.delay_span_bug(
self.delegate.span(),
"failure to relate an opaque to itself should result in an error later on",
Expand All @@ -506,7 +506,7 @@ where
}
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _)
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
if def_id.is_local() && !self.tcx().trait_solver_next() =>
if def_id.is_local() && !self.infcx.next_trait_solver() =>
{
self.relate_opaques(a, b)
}
Expand Down

0 comments on commit b2807b2

Please sign in to comment.