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 8 pull requests #121055

Merged
merged 18 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
36d7f76
Replace clean::InstantiationParam with clean::GenericArg
fmease Feb 13, 2024
ae92334
remove questionable calls to `commit_if_ok`
lcnr Feb 13, 2024
622b5a5
Remove jsha from the rustdoc review rotation
fmease Feb 13, 2024
2b4a2b9
Check normalized call signature for WF in mir typeck
compiler-errors Jan 30, 2024
57746a3
add lcnr to the compiler-team assignment group
lcnr Feb 13, 2024
cd3ba4a
Fix incorrect use of `compile_fail`
camelid Feb 13, 2024
b4eee2e
Do not assemble candidates for default impls
compiler-errors Feb 13, 2024
bdc6d82
Make `struct_span_note` call `struct_note`.
nnethercote Feb 12, 2024
c1ffb0b
Remove `force_print_diagnostic`.
nnethercote Feb 12, 2024
56b451a
Fix `DiagCtxtInner::reset_err_count`.
nnethercote Feb 13, 2024
db9591c
Rollup merge of #118882 - compiler-errors:normalized-sig-wf, r=lcnr
matthiaskrgr Feb 13, 2024
2e98b27
Rollup merge of #120999 - fmease:rustdoc-rm-instantiation-param, r=no…
matthiaskrgr Feb 13, 2024
147fd3f
Rollup merge of #121002 - lcnr:cleanup-commit_if_ok, r=oli-obk
matthiaskrgr Feb 13, 2024
8f9779f
Rollup merge of #121005 - fmease:update-rustdoc-review-rotation, r=jsha
matthiaskrgr Feb 13, 2024
8c0d54f
Rollup merge of #121014 - nnethercote:rm-force_print_diagnostic, r=ol…
matthiaskrgr Feb 13, 2024
8775df3
Rollup merge of #121043 - lcnr:lcnr-compiler-assign, r=fmease
matthiaskrgr Feb 13, 2024
e499e99
Rollup merge of #121046 - camelid:rm-incorrect-compile_fail, r=Nilstrieb
matthiaskrgr Feb 13, 2024
ab1fa19
Rollup merge of #121047 - compiler-errors:default-impls, r=lcnr
matthiaskrgr Feb 13, 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
24 changes: 20 additions & 4 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
return;
}
};
let (sig, map) = tcx.instantiate_bound_regions(sig, |br| {
let (unnormalized_sig, map) = tcx.instantiate_bound_regions(sig, |br| {
use crate::renumber::RegionCtxt;

let region_ctxt_fn = || {
Expand All @@ -1454,7 +1454,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
region_ctxt_fn,
)
});
debug!(?sig);
debug!(?unnormalized_sig);
// IMPORTANT: We have to prove well formed for the function signature before
// we normalize it, as otherwise types like `<&'a &'b () as Trait>::Assoc`
// get normalized away, causing us to ignore the `'b: 'a` bound used by the function.
Expand All @@ -1464,15 +1464,31 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
//
// See #91068 for an example.
self.prove_predicates(
sig.inputs_and_output.iter().map(|ty| {
unnormalized_sig.inputs_and_output.iter().map(|ty| {
ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(
ty.into(),
)))
}),
term_location.to_locations(),
ConstraintCategory::Boring,
);
let sig = self.normalize(sig, term_location);

let sig = self.normalize(unnormalized_sig, term_location);
// HACK(#114936): `WF(sig)` does not imply `WF(normalized(sig))`
// with built-in `Fn` implementations, since the impl may not be
// well-formed itself.
if sig != unnormalized_sig {
self.prove_predicates(
sig.inputs_and_output.iter().map(|ty| {
ty::Binder::dummy(ty::PredicateKind::Clause(
ty::ClauseKind::WellFormed(ty.into()),
))
}),
term_location.to_locations(),
ConstraintCategory::Boring,
);
}

self.check_call_dest(body, term, &sig, *destination, *target, term_location);

// The ordinary liveness rules will ensure that all
Expand Down
105 changes: 70 additions & 35 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ use std::fmt;
use std::hash::Hash;
use std::io::Write;
use std::num::NonZeroUsize;
use std::ops::DerefMut;
use std::panic;
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -666,22 +667,51 @@ impl DiagCtxt {
/// tools that want to reuse a `Parser` cleaning the previously emitted diagnostics as well as
/// the overall count of emitted error diagnostics.
pub fn reset_err_count(&self) {
// Use destructuring so that if a field gets added to `DiagCtxtInner`, it's impossible to
// fail to update this method as well.
let mut inner = self.inner.borrow_mut();
inner.stashed_err_count = 0;
inner.deduplicated_err_count = 0;
inner.deduplicated_warn_count = 0;
inner.must_produce_diag = false;
inner.has_printed = false;
inner.suppressed_expected_diag = false;

// actually free the underlying memory (which `clear` would not do)
inner.err_guars = Default::default();
inner.lint_err_guars = Default::default();
inner.delayed_bugs = Default::default();
inner.taught_diagnostics = Default::default();
inner.emitted_diagnostic_codes = Default::default();
inner.emitted_diagnostics = Default::default();
inner.stashed_diagnostics = Default::default();
let DiagCtxtInner {
flags: _,
err_guars,
lint_err_guars,
delayed_bugs,
stashed_err_count,
deduplicated_err_count,
deduplicated_warn_count,
emitter: _,
must_produce_diag,
has_printed,
suppressed_expected_diag,
taught_diagnostics,
emitted_diagnostic_codes,
emitted_diagnostics,
stashed_diagnostics,
future_breakage_diagnostics,
check_unstable_expect_diagnostics,
unstable_expect_diagnostics,
fulfilled_expectations,
ice_file: _,
} = inner.deref_mut();

// For the `Vec`s and `HashMap`s, we overwrite with an empty container to free the
// underlying memory (which `clear` would not do).
*err_guars = Default::default();
*lint_err_guars = Default::default();
*delayed_bugs = Default::default();
*stashed_err_count = 0;
*deduplicated_err_count = 0;
*deduplicated_warn_count = 0;
*must_produce_diag = false;
*has_printed = false;
*suppressed_expected_diag = false;
*taught_diagnostics = Default::default();
*emitted_diagnostic_codes = Default::default();
*emitted_diagnostics = Default::default();
*stashed_diagnostics = Default::default();
*future_breakage_diagnostics = Default::default();
*check_unstable_expect_diagnostics = false;
*unstable_expect_diagnostics = Default::default();
*fulfilled_expectations = Default::default();
}

/// Stash a given diagnostic with the given `Span` and [`StashKey`] as the key.
Expand Down Expand Up @@ -780,11 +810,12 @@ impl DiagCtxt {
match (errors.len(), warnings.len()) {
(0, 0) => return,
(0, _) => {
// Use `inner.emitter` directly, otherwise the warning might not be emitted, e.g.
// with a configuration like `--cap-lints allow --force-warn bare_trait_objects`.
inner
.emitter
.emit_diagnostic(Diagnostic::new(Warning, DiagnosticMessage::Str(warnings)));
// Use `ForceWarning` rather than `Warning` to guarantee emission, e.g. with a
// configuration like `--cap-lints allow --force-warn bare_trait_objects`.
inner.emit_diagnostic(Diagnostic::new(
ForceWarning(None),
DiagnosticMessage::Str(warnings),
));
}
(_, 0) => {
inner.emit_diagnostic(Diagnostic::new(Error, errors));
Expand Down Expand Up @@ -812,20 +843,23 @@ impl DiagCtxt {
error_codes.sort();
if error_codes.len() > 1 {
let limit = if error_codes.len() > 9 { 9 } else { error_codes.len() };
inner.failure_note(format!(
let msg1 = format!(
"Some errors have detailed explanations: {}{}",
error_codes[..limit].join(", "),
if error_codes.len() > 9 { "..." } else { "." }
));
inner.failure_note(format!(
);
let msg2 = format!(
"For more information about an error, try `rustc --explain {}`.",
&error_codes[0]
));
);
inner.emit_diagnostic(Diagnostic::new(FailureNote, msg1));
inner.emit_diagnostic(Diagnostic::new(FailureNote, msg2));
} else {
inner.failure_note(format!(
let msg = format!(
"For more information about this error, try `rustc --explain {}`.",
&error_codes[0]
));
);
inner.emit_diagnostic(Diagnostic::new(FailureNote, msg));
}
}
}
Expand All @@ -848,10 +882,6 @@ impl DiagCtxt {
self.inner.borrow_mut().taught_diagnostics.insert(code)
}

pub fn force_print_diagnostic(&self, db: Diagnostic) {
self.inner.borrow_mut().emitter.emit_diagnostic(db);
}

pub fn emit_diagnostic(&self, diagnostic: Diagnostic) -> Option<ErrorGuaranteed> {
self.inner.borrow_mut().emit_diagnostic(diagnostic)
}
Expand Down Expand Up @@ -1179,7 +1209,7 @@ impl DiagCtxt {
span: impl Into<MultiSpan>,
msg: impl Into<DiagnosticMessage>,
) -> DiagnosticBuilder<'_, ()> {
DiagnosticBuilder::new(self, Note, msg).with_span(span)
self.struct_note(msg).with_span(span)
}

#[rustc_lint_diagnostics]
Expand Down Expand Up @@ -1207,6 +1237,15 @@ impl DiagCtxt {
DiagnosticBuilder::new(self, Help, msg)
}

#[rustc_lint_diagnostics]
#[track_caller]
pub fn struct_failure_note(
&self,
msg: impl Into<DiagnosticMessage>,
) -> DiagnosticBuilder<'_, ()> {
DiagnosticBuilder::new(self, FailureNote, msg)
}

#[rustc_lint_diagnostics]
#[track_caller]
pub fn struct_allow(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
Expand Down Expand Up @@ -1406,10 +1445,6 @@ impl DiagCtxtInner {
.or_else(|| self.delayed_bugs.get(0).map(|(_, guar)| guar).copied())
}

fn failure_note(&mut self, msg: impl Into<DiagnosticMessage>) {
self.emit_diagnostic(Diagnostic::new(FailureNote, msg));
}

fn flush_delayed(&mut self) {
if self.delayed_bugs.is_empty() {
return;
Expand Down
48 changes: 20 additions & 28 deletions compiler/rustc_infer/src/infer/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,11 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
T: Relate<'tcx>,
{
let Trace { at, trace, a_is_expected } = self;
at.infcx.commit_if_ok(|_| {
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
fields
.sub(a_is_expected)
.relate(a, b)
.map(move |_| InferOk { value: (), obligations: fields.obligations })
})
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
fields
.sub(a_is_expected)
.relate(a, b)
.map(move |_| InferOk { value: (), obligations: fields.obligations })
}

/// Makes `a == b`; the expectation is set by the call to
Expand All @@ -302,13 +300,11 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
T: Relate<'tcx>,
{
let Trace { at, trace, a_is_expected } = self;
at.infcx.commit_if_ok(|_| {
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
fields
.equate(a_is_expected)
.relate(a, b)
.map(move |_| InferOk { value: (), obligations: fields.obligations })
})
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
fields
.equate(a_is_expected)
.relate(a, b)
.map(move |_| InferOk { value: (), obligations: fields.obligations })
}

#[instrument(skip(self), level = "debug")]
Expand All @@ -317,13 +313,11 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
T: Relate<'tcx>,
{
let Trace { at, trace, a_is_expected } = self;
at.infcx.commit_if_ok(|_| {
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
fields
.lub(a_is_expected)
.relate(a, b)
.map(move |t| InferOk { value: t, obligations: fields.obligations })
})
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
fields
.lub(a_is_expected)
.relate(a, b)
.map(move |t| InferOk { value: t, obligations: fields.obligations })
}

#[instrument(skip(self), level = "debug")]
Expand All @@ -332,13 +326,11 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
T: Relate<'tcx>,
{
let Trace { at, trace, a_is_expected } = self;
at.infcx.commit_if_ok(|_| {
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
fields
.glb(a_is_expected)
.relate(a, b)
.map(move |t| InferOk { value: t, obligations: fields.obligations })
})
let mut fields = at.infcx.combine_fields(trace, at.param_env, define_opaque_types);
fields
.glb(a_is_expected)
.relate(a, b)
.map(move |t| InferOk { value: t, obligations: fields.obligations })
}
}

Expand Down
66 changes: 32 additions & 34 deletions compiler/rustc_infer/src/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,42 +620,40 @@ impl<'tcx> InferCtxt<'tcx> {
variables1: &OriginalQueryValues<'tcx>,
variables2: impl Fn(BoundVar) -> GenericArg<'tcx>,
) -> InferResult<'tcx, ()> {
self.commit_if_ok(|_| {
let mut obligations = vec![];
for (index, value1) in variables1.var_values.iter().enumerate() {
let value2 = variables2(BoundVar::new(index));

match (value1.unpack(), value2.unpack()) {
(GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => {
obligations.extend(
self.at(cause, param_env)
.eq(DefineOpaqueTypes::Yes, v1, v2)?
.into_obligations(),
);
}
(GenericArgKind::Lifetime(re1), GenericArgKind::Lifetime(re2))
if re1.is_erased() && re2.is_erased() =>
{
// no action needed
}
(GenericArgKind::Lifetime(v1), GenericArgKind::Lifetime(v2)) => {
obligations.extend(
self.at(cause, param_env)
.eq(DefineOpaqueTypes::Yes, v1, v2)?
.into_obligations(),
);
}
(GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
let ok = self.at(cause, param_env).eq(DefineOpaqueTypes::Yes, v1, v2)?;
obligations.extend(ok.into_obligations());
}
_ => {
bug!("kind mismatch, cannot unify {:?} and {:?}", value1, value2,);
}
let mut obligations = vec![];
for (index, value1) in variables1.var_values.iter().enumerate() {
let value2 = variables2(BoundVar::new(index));

match (value1.unpack(), value2.unpack()) {
(GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => {
obligations.extend(
self.at(cause, param_env)
.eq(DefineOpaqueTypes::Yes, v1, v2)?
.into_obligations(),
);
}
(GenericArgKind::Lifetime(re1), GenericArgKind::Lifetime(re2))
if re1.is_erased() && re2.is_erased() =>
{
// no action needed
}
(GenericArgKind::Lifetime(v1), GenericArgKind::Lifetime(v2)) => {
obligations.extend(
self.at(cause, param_env)
.eq(DefineOpaqueTypes::Yes, v1, v2)?
.into_obligations(),
);
}
(GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
let ok = self.at(cause, param_env).eq(DefineOpaqueTypes::Yes, v1, v2)?;
obligations.extend(ok.into_obligations());
}
_ => {
bug!("kind mismatch, cannot unify {:?} and {:?}", value1, value2,);
}
}
Ok(InferOk { value: (), obligations })
})
}
Ok(InferOk { value: (), obligations })
}
}

Expand Down
Loading
Loading