Skip to content

Commit 7508c3e

Browse files
committed
Auto merge of #121055 - matthiaskrgr:rollup-bzn5sda, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #118882 (Check normalized call signature for WF in mir typeck) - #120999 (rustdoc: replace `clean::InstantiationParam` with `clean::GenericArg`) - #121002 (remove unnecessary calls to `commit_if_ok`) - #121005 (Remove jsha from the rustdoc review rotation) - #121014 (Remove `force_print_diagnostic`) - #121043 (add lcnr to the compiler-team assignment group) - #121046 (Fix incorrect use of `compile_fail`) - #121047 (Do not assemble candidates for default impls) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 37b6533 + ab1fa19 commit 7508c3e

File tree

23 files changed

+328
-236
lines changed

23 files changed

+328
-236
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14321432
return;
14331433
}
14341434
};
1435-
let (sig, map) = tcx.instantiate_bound_regions(sig, |br| {
1435+
let (unnormalized_sig, map) = tcx.instantiate_bound_regions(sig, |br| {
14361436
use crate::renumber::RegionCtxt;
14371437

14381438
let region_ctxt_fn = || {
@@ -1454,7 +1454,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14541454
region_ctxt_fn,
14551455
)
14561456
});
1457-
debug!(?sig);
1457+
debug!(?unnormalized_sig);
14581458
// IMPORTANT: We have to prove well formed for the function signature before
14591459
// we normalize it, as otherwise types like `<&'a &'b () as Trait>::Assoc`
14601460
// get normalized away, causing us to ignore the `'b: 'a` bound used by the function.
@@ -1464,15 +1464,31 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14641464
//
14651465
// See #91068 for an example.
14661466
self.prove_predicates(
1467-
sig.inputs_and_output.iter().map(|ty| {
1467+
unnormalized_sig.inputs_and_output.iter().map(|ty| {
14681468
ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(
14691469
ty.into(),
14701470
)))
14711471
}),
14721472
term_location.to_locations(),
14731473
ConstraintCategory::Boring,
14741474
);
1475-
let sig = self.normalize(sig, term_location);
1475+
1476+
let sig = self.normalize(unnormalized_sig, term_location);
1477+
// HACK(#114936): `WF(sig)` does not imply `WF(normalized(sig))`
1478+
// with built-in `Fn` implementations, since the impl may not be
1479+
// well-formed itself.
1480+
if sig != unnormalized_sig {
1481+
self.prove_predicates(
1482+
sig.inputs_and_output.iter().map(|ty| {
1483+
ty::Binder::dummy(ty::PredicateKind::Clause(
1484+
ty::ClauseKind::WellFormed(ty.into()),
1485+
))
1486+
}),
1487+
term_location.to_locations(),
1488+
ConstraintCategory::Boring,
1489+
);
1490+
}
1491+
14761492
self.check_call_dest(body, term, &sig, *destination, *target, term_location);
14771493

14781494
// The ordinary liveness rules will ensure that all

compiler/rustc_errors/src/lib.rs

+70-35
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ use std::fmt;
7878
use std::hash::Hash;
7979
use std::io::Write;
8080
use std::num::NonZeroUsize;
81+
use std::ops::DerefMut;
8182
use std::panic;
8283
use std::path::{Path, PathBuf};
8384

@@ -666,22 +667,51 @@ impl DiagCtxt {
666667
/// tools that want to reuse a `Parser` cleaning the previously emitted diagnostics as well as
667668
/// the overall count of emitted error diagnostics.
668669
pub fn reset_err_count(&self) {
670+
// Use destructuring so that if a field gets added to `DiagCtxtInner`, it's impossible to
671+
// fail to update this method as well.
669672
let mut inner = self.inner.borrow_mut();
670-
inner.stashed_err_count = 0;
671-
inner.deduplicated_err_count = 0;
672-
inner.deduplicated_warn_count = 0;
673-
inner.must_produce_diag = false;
674-
inner.has_printed = false;
675-
inner.suppressed_expected_diag = false;
676-
677-
// actually free the underlying memory (which `clear` would not do)
678-
inner.err_guars = Default::default();
679-
inner.lint_err_guars = Default::default();
680-
inner.delayed_bugs = Default::default();
681-
inner.taught_diagnostics = Default::default();
682-
inner.emitted_diagnostic_codes = Default::default();
683-
inner.emitted_diagnostics = Default::default();
684-
inner.stashed_diagnostics = Default::default();
673+
let DiagCtxtInner {
674+
flags: _,
675+
err_guars,
676+
lint_err_guars,
677+
delayed_bugs,
678+
stashed_err_count,
679+
deduplicated_err_count,
680+
deduplicated_warn_count,
681+
emitter: _,
682+
must_produce_diag,
683+
has_printed,
684+
suppressed_expected_diag,
685+
taught_diagnostics,
686+
emitted_diagnostic_codes,
687+
emitted_diagnostics,
688+
stashed_diagnostics,
689+
future_breakage_diagnostics,
690+
check_unstable_expect_diagnostics,
691+
unstable_expect_diagnostics,
692+
fulfilled_expectations,
693+
ice_file: _,
694+
} = inner.deref_mut();
695+
696+
// For the `Vec`s and `HashMap`s, we overwrite with an empty container to free the
697+
// underlying memory (which `clear` would not do).
698+
*err_guars = Default::default();
699+
*lint_err_guars = Default::default();
700+
*delayed_bugs = Default::default();
701+
*stashed_err_count = 0;
702+
*deduplicated_err_count = 0;
703+
*deduplicated_warn_count = 0;
704+
*must_produce_diag = false;
705+
*has_printed = false;
706+
*suppressed_expected_diag = false;
707+
*taught_diagnostics = Default::default();
708+
*emitted_diagnostic_codes = Default::default();
709+
*emitted_diagnostics = Default::default();
710+
*stashed_diagnostics = Default::default();
711+
*future_breakage_diagnostics = Default::default();
712+
*check_unstable_expect_diagnostics = false;
713+
*unstable_expect_diagnostics = Default::default();
714+
*fulfilled_expectations = Default::default();
685715
}
686716

687717
/// Stash a given diagnostic with the given `Span` and [`StashKey`] as the key.
@@ -780,11 +810,12 @@ impl DiagCtxt {
780810
match (errors.len(), warnings.len()) {
781811
(0, 0) => return,
782812
(0, _) => {
783-
// Use `inner.emitter` directly, otherwise the warning might not be emitted, e.g.
784-
// with a configuration like `--cap-lints allow --force-warn bare_trait_objects`.
785-
inner
786-
.emitter
787-
.emit_diagnostic(Diagnostic::new(Warning, DiagnosticMessage::Str(warnings)));
813+
// Use `ForceWarning` rather than `Warning` to guarantee emission, e.g. with a
814+
// configuration like `--cap-lints allow --force-warn bare_trait_objects`.
815+
inner.emit_diagnostic(Diagnostic::new(
816+
ForceWarning(None),
817+
DiagnosticMessage::Str(warnings),
818+
));
788819
}
789820
(_, 0) => {
790821
inner.emit_diagnostic(Diagnostic::new(Error, errors));
@@ -812,20 +843,23 @@ impl DiagCtxt {
812843
error_codes.sort();
813844
if error_codes.len() > 1 {
814845
let limit = if error_codes.len() > 9 { 9 } else { error_codes.len() };
815-
inner.failure_note(format!(
846+
let msg1 = format!(
816847
"Some errors have detailed explanations: {}{}",
817848
error_codes[..limit].join(", "),
818849
if error_codes.len() > 9 { "..." } else { "." }
819-
));
820-
inner.failure_note(format!(
850+
);
851+
let msg2 = format!(
821852
"For more information about an error, try `rustc --explain {}`.",
822853
&error_codes[0]
823-
));
854+
);
855+
inner.emit_diagnostic(Diagnostic::new(FailureNote, msg1));
856+
inner.emit_diagnostic(Diagnostic::new(FailureNote, msg2));
824857
} else {
825-
inner.failure_note(format!(
858+
let msg = format!(
826859
"For more information about this error, try `rustc --explain {}`.",
827860
&error_codes[0]
828-
));
861+
);
862+
inner.emit_diagnostic(Diagnostic::new(FailureNote, msg));
829863
}
830864
}
831865
}
@@ -848,10 +882,6 @@ impl DiagCtxt {
848882
self.inner.borrow_mut().taught_diagnostics.insert(code)
849883
}
850884

851-
pub fn force_print_diagnostic(&self, db: Diagnostic) {
852-
self.inner.borrow_mut().emitter.emit_diagnostic(db);
853-
}
854-
855885
pub fn emit_diagnostic(&self, diagnostic: Diagnostic) -> Option<ErrorGuaranteed> {
856886
self.inner.borrow_mut().emit_diagnostic(diagnostic)
857887
}
@@ -1179,7 +1209,7 @@ impl DiagCtxt {
11791209
span: impl Into<MultiSpan>,
11801210
msg: impl Into<DiagnosticMessage>,
11811211
) -> DiagnosticBuilder<'_, ()> {
1182-
DiagnosticBuilder::new(self, Note, msg).with_span(span)
1212+
self.struct_note(msg).with_span(span)
11831213
}
11841214

11851215
#[rustc_lint_diagnostics]
@@ -1207,6 +1237,15 @@ impl DiagCtxt {
12071237
DiagnosticBuilder::new(self, Help, msg)
12081238
}
12091239

1240+
#[rustc_lint_diagnostics]
1241+
#[track_caller]
1242+
pub fn struct_failure_note(
1243+
&self,
1244+
msg: impl Into<DiagnosticMessage>,
1245+
) -> DiagnosticBuilder<'_, ()> {
1246+
DiagnosticBuilder::new(self, FailureNote, msg)
1247+
}
1248+
12101249
#[rustc_lint_diagnostics]
12111250
#[track_caller]
12121251
pub fn struct_allow(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
@@ -1406,10 +1445,6 @@ impl DiagCtxtInner {
14061445
.or_else(|| self.delayed_bugs.get(0).map(|(_, guar)| guar).copied())
14071446
}
14081447

1409-
fn failure_note(&mut self, msg: impl Into<DiagnosticMessage>) {
1410-
self.emit_diagnostic(Diagnostic::new(FailureNote, msg));
1411-
}
1412-
14131448
fn flush_delayed(&mut self) {
14141449
if self.delayed_bugs.is_empty() {
14151450
return;

compiler/rustc_infer/src/infer/at.rs

+20-28
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,11 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
285285
T: Relate<'tcx>,
286286
{
287287
let Trace { at, trace, a_is_expected } = self;
288-
at.infcx.commit_if_ok(|_| {
289-
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
290-
fields
291-
.sub(a_is_expected)
292-
.relate(a, b)
293-
.map(move |_| InferOk { value: (), obligations: fields.obligations })
294-
})
288+
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
289+
fields
290+
.sub(a_is_expected)
291+
.relate(a, b)
292+
.map(move |_| InferOk { value: (), obligations: fields.obligations })
295293
}
296294

297295
/// Makes `a == b`; the expectation is set by the call to
@@ -302,13 +300,11 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
302300
T: Relate<'tcx>,
303301
{
304302
let Trace { at, trace, a_is_expected } = self;
305-
at.infcx.commit_if_ok(|_| {
306-
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
307-
fields
308-
.equate(a_is_expected)
309-
.relate(a, b)
310-
.map(move |_| InferOk { value: (), obligations: fields.obligations })
311-
})
303+
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
304+
fields
305+
.equate(a_is_expected)
306+
.relate(a, b)
307+
.map(move |_| InferOk { value: (), obligations: fields.obligations })
312308
}
313309

314310
#[instrument(skip(self), level = "debug")]
@@ -317,13 +313,11 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
317313
T: Relate<'tcx>,
318314
{
319315
let Trace { at, trace, a_is_expected } = self;
320-
at.infcx.commit_if_ok(|_| {
321-
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
322-
fields
323-
.lub(a_is_expected)
324-
.relate(a, b)
325-
.map(move |t| InferOk { value: t, obligations: fields.obligations })
326-
})
316+
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
317+
fields
318+
.lub(a_is_expected)
319+
.relate(a, b)
320+
.map(move |t| InferOk { value: t, obligations: fields.obligations })
327321
}
328322

329323
#[instrument(skip(self), level = "debug")]
@@ -332,13 +326,11 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
332326
T: Relate<'tcx>,
333327
{
334328
let Trace { at, trace, a_is_expected } = self;
335-
at.infcx.commit_if_ok(|_| {
336-
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
337-
fields
338-
.glb(a_is_expected)
339-
.relate(a, b)
340-
.map(move |t| InferOk { value: t, obligations: fields.obligations })
341-
})
329+
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
330+
fields
331+
.glb(a_is_expected)
332+
.relate(a, b)
333+
.map(move |t| InferOk { value: t, obligations: fields.obligations })
342334
}
343335
}
344336

compiler/rustc_infer/src/infer/canonical/query_response.rs

+32-34
Original file line numberDiff line numberDiff line change
@@ -620,42 +620,40 @@ impl<'tcx> InferCtxt<'tcx> {
620620
variables1: &OriginalQueryValues<'tcx>,
621621
variables2: impl Fn(BoundVar) -> GenericArg<'tcx>,
622622
) -> InferResult<'tcx, ()> {
623-
self.commit_if_ok(|_| {
624-
let mut obligations = vec![];
625-
for (index, value1) in variables1.var_values.iter().enumerate() {
626-
let value2 = variables2(BoundVar::new(index));
627-
628-
match (value1.unpack(), value2.unpack()) {
629-
(GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => {
630-
obligations.extend(
631-
self.at(cause, param_env)
632-
.eq(DefineOpaqueTypes::Yes, v1, v2)?
633-
.into_obligations(),
634-
);
635-
}
636-
(GenericArgKind::Lifetime(re1), GenericArgKind::Lifetime(re2))
637-
if re1.is_erased() && re2.is_erased() =>
638-
{
639-
// no action needed
640-
}
641-
(GenericArgKind::Lifetime(v1), GenericArgKind::Lifetime(v2)) => {
642-
obligations.extend(
643-
self.at(cause, param_env)
644-
.eq(DefineOpaqueTypes::Yes, v1, v2)?
645-
.into_obligations(),
646-
);
647-
}
648-
(GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
649-
let ok = self.at(cause, param_env).eq(DefineOpaqueTypes::Yes, v1, v2)?;
650-
obligations.extend(ok.into_obligations());
651-
}
652-
_ => {
653-
bug!("kind mismatch, cannot unify {:?} and {:?}", value1, value2,);
654-
}
623+
let mut obligations = vec![];
624+
for (index, value1) in variables1.var_values.iter().enumerate() {
625+
let value2 = variables2(BoundVar::new(index));
626+
627+
match (value1.unpack(), value2.unpack()) {
628+
(GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => {
629+
obligations.extend(
630+
self.at(cause, param_env)
631+
.eq(DefineOpaqueTypes::Yes, v1, v2)?
632+
.into_obligations(),
633+
);
634+
}
635+
(GenericArgKind::Lifetime(re1), GenericArgKind::Lifetime(re2))
636+
if re1.is_erased() && re2.is_erased() =>
637+
{
638+
// no action needed
639+
}
640+
(GenericArgKind::Lifetime(v1), GenericArgKind::Lifetime(v2)) => {
641+
obligations.extend(
642+
self.at(cause, param_env)
643+
.eq(DefineOpaqueTypes::Yes, v1, v2)?
644+
.into_obligations(),
645+
);
646+
}
647+
(GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
648+
let ok = self.at(cause, param_env).eq(DefineOpaqueTypes::Yes, v1, v2)?;
649+
obligations.extend(ok.into_obligations());
650+
}
651+
_ => {
652+
bug!("kind mismatch, cannot unify {:?} and {:?}", value1, value2,);
655653
}
656654
}
657-
Ok(InferOk { value: (), obligations })
658-
})
655+
}
656+
Ok(InferOk { value: (), obligations })
659657
}
660658
}
661659

0 commit comments

Comments
 (0)