Skip to content

Commit 9bf3bbe

Browse files
committed
Auto merge of rust-lang#120662 - matthiaskrgr:rollup-dbrpeqj, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#120396 (Account for unbounded type param receiver in suggestions) - rust-lang#120423 (update indirect structural match lints to match RFC and to show up for dependencies) - rust-lang#120435 (Suggest name value cfg when only value is used for check-cfg) - rust-lang#120507 (Account for non-overlapping unmet trait bounds in suggestion) - rust-lang#120520 (Some cleanups around diagnostic levels.) - rust-lang#120521 (Make `NonZero` constructors generic.) - rust-lang#120527 (Switch OwnedStore handle count to AtomicU32) - rust-lang#120550 (Continue to borrowck even if there were previous errors) - rust-lang#120575 (Simplify codegen diagnostic handling) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8c0b4f6 + c28b4a0 commit 9bf3bbe

File tree

277 files changed

+4452
-1424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

277 files changed

+4452
-1424
lines changed

compiler/rustc_borrowck/src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,16 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
110110
let (input_body, promoted) = tcx.mir_promoted(def);
111111
debug!("run query mir_borrowck: {}", tcx.def_path_str(def));
112112

113-
if input_body.borrow().should_skip() {
114-
debug!("Skipping borrowck because of injected body");
113+
let input_body: &Body<'_> = &input_body.borrow();
114+
115+
if input_body.should_skip() || input_body.tainted_by_errors.is_some() {
116+
debug!("Skipping borrowck because of injected body or tainted body");
115117
// Let's make up a borrowck result! Fun times!
116118
let result = BorrowCheckResult {
117119
concrete_opaque_types: FxIndexMap::default(),
118120
closure_requirements: None,
119121
used_mut_upvars: SmallVec::new(),
120-
tainted_by_errors: None,
122+
tainted_by_errors: input_body.tainted_by_errors,
121123
};
122124
return tcx.arena.alloc(result);
123125
}
@@ -126,7 +128,6 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
126128

127129
let infcx =
128130
tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id)).build();
129-
let input_body: &Body<'_> = &input_body.borrow();
130131
let promoted: &IndexSlice<_, _> = &promoted.borrow();
131132
let opt_closure_req = do_mir_borrowck(&infcx, input_body, promoted, None).0;
132133
debug!("mir_borrowck done");

compiler/rustc_codegen_ssa/src/back/write.rs

+5-40
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ use rustc_data_structures::profiling::{SelfProfilerRef, VerboseTimingGuard};
1515
use rustc_data_structures::sync::Lrc;
1616
use rustc_errors::emitter::Emitter;
1717
use rustc_errors::translation::Translate;
18-
use rustc_errors::{
19-
DiagCtxt, DiagnosticArgName, DiagnosticArgValue, DiagnosticBuilder, DiagnosticMessage, ErrCode,
20-
FatalError, FluentBundle, Level, Style,
21-
};
18+
use rustc_errors::{DiagCtxt, Diagnostic, DiagnosticBuilder, FatalError, FluentBundle, Level};
2219
use rustc_fs_util::link_or_copy;
2320
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
2421
use rustc_incremental::{
@@ -997,13 +994,6 @@ pub(crate) enum Message<B: WriteBackendMethods> {
997994
/// process another codegen unit.
998995
pub struct CguMessage;
999996

1000-
struct Diagnostic {
1001-
msgs: Vec<(DiagnosticMessage, Style)>,
1002-
args: FxHashMap<DiagnosticArgName, DiagnosticArgValue>,
1003-
code: Option<ErrCode>,
1004-
lvl: Level,
1005-
}
1006-
1007997
#[derive(PartialEq, Clone, Copy, Debug)]
1008998
enum MainThreadState {
1009999
/// Doing nothing.
@@ -1764,7 +1754,6 @@ fn spawn_work<'a, B: ExtraBackendMethods>(
17641754
enum SharedEmitterMessage {
17651755
Diagnostic(Diagnostic),
17661756
InlineAsmError(u32, String, Level, Option<(String, Vec<InnerSpan>)>),
1767-
AbortIfErrors,
17681757
Fatal(String),
17691758
}
17701759

@@ -1810,24 +1799,8 @@ impl Translate for SharedEmitter {
18101799
}
18111800

18121801
impl Emitter for SharedEmitter {
1813-
fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) {
1814-
let args: FxHashMap<DiagnosticArgName, DiagnosticArgValue> =
1815-
diag.args().map(|(name, arg)| (name.clone(), arg.clone())).collect();
1816-
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
1817-
msgs: diag.messages.clone(),
1818-
args: args.clone(),
1819-
code: diag.code,
1820-
lvl: diag.level(),
1821-
})));
1822-
for child in &diag.children {
1823-
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
1824-
msgs: child.messages.clone(),
1825-
args: args.clone(),
1826-
code: None,
1827-
lvl: child.level,
1828-
})));
1829-
}
1830-
drop(self.sender.send(SharedEmitterMessage::AbortIfErrors));
1802+
fn emit_diagnostic(&mut self, diag: rustc_errors::Diagnostic) {
1803+
drop(self.sender.send(SharedEmitterMessage::Diagnostic(diag)));
18311804
}
18321805

18331806
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
@@ -1852,13 +1825,8 @@ impl SharedEmitterMain {
18521825

18531826
match message {
18541827
Ok(SharedEmitterMessage::Diagnostic(diag)) => {
1855-
let dcx = sess.dcx();
1856-
let mut d = rustc_errors::Diagnostic::new_with_messages(diag.lvl, diag.msgs);
1857-
if let Some(code) = diag.code {
1858-
d.code(code);
1859-
}
1860-
d.replace_args(diag.args);
1861-
dcx.emit_diagnostic(d);
1828+
sess.dcx().emit_diagnostic(diag);
1829+
sess.dcx().abort_if_errors();
18621830
}
18631831
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg, level, source)) => {
18641832
assert!(matches!(level, Level::Error | Level::Warning | Level::Note));
@@ -1891,9 +1859,6 @@ impl SharedEmitterMain {
18911859

18921860
err.emit();
18931861
}
1894-
Ok(SharedEmitterMessage::AbortIfErrors) => {
1895-
sess.dcx().abort_if_errors();
1896-
}
18971862
Ok(SharedEmitterMessage::Fatal(msg)) => {
18981863
sess.dcx().fatal(msg);
18991864
}

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-28
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::mem;
2020
use std::ops::{ControlFlow, Deref};
2121

2222
use super::ops::{self, NonConstOp, Status};
23-
use super::qualifs::{self, CustomEq, HasMutInterior, NeedsDrop, NeedsNonConstDrop};
23+
use super::qualifs::{self, HasMutInterior, NeedsDrop, NeedsNonConstDrop};
2424
use super::resolver::FlowSensitiveAnalysis;
2525
use super::{ConstCx, Qualif};
2626
use crate::const_eval::is_unstable_const_fn;
@@ -149,37 +149,10 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
149149

150150
let return_loc = ccx.body.terminator_loc(return_block);
151151

152-
let custom_eq = match ccx.const_kind() {
153-
// We don't care whether a `const fn` returns a value that is not structurally
154-
// matchable. Functions calls are opaque and always use type-based qualification, so
155-
// this value should never be used.
156-
hir::ConstContext::ConstFn => true,
157-
158-
// If we know that all values of the return type are structurally matchable, there's no
159-
// need to run dataflow.
160-
// Opaque types do not participate in const generics or pattern matching, so we can safely count them out.
161-
_ if ccx.body.return_ty().has_opaque_types()
162-
|| !CustomEq::in_any_value_of_ty(ccx, ccx.body.return_ty()) =>
163-
{
164-
false
165-
}
166-
167-
hir::ConstContext::Const { .. } | hir::ConstContext::Static(_) => {
168-
let mut cursor = FlowSensitiveAnalysis::new(CustomEq, ccx)
169-
.into_engine(ccx.tcx, ccx.body)
170-
.iterate_to_fixpoint()
171-
.into_results_cursor(ccx.body);
172-
173-
cursor.seek_after_primary_effect(return_loc);
174-
cursor.get().contains(RETURN_PLACE)
175-
}
176-
};
177-
178152
ConstQualifs {
179153
needs_drop: self.needs_drop(ccx, RETURN_PLACE, return_loc),
180154
needs_non_const_drop: self.needs_non_const_drop(ccx, RETURN_PLACE, return_loc),
181155
has_mut_interior: self.has_mut_interior(ccx, RETURN_PLACE, return_loc),
182-
custom_eq,
183156
tainted_by_errors,
184157
}
185158
}

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+1-31
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::mir::*;
1010
use rustc_middle::traits::BuiltinImplSource;
1111
use rustc_middle::ty::{self, AdtDef, GenericArgsRef, Ty};
1212
use rustc_trait_selection::traits::{
13-
self, ImplSource, Obligation, ObligationCause, ObligationCtxt, SelectionContext,
13+
ImplSource, Obligation, ObligationCause, ObligationCtxt, SelectionContext,
1414
};
1515

1616
use super::ConstCx;
@@ -24,7 +24,6 @@ pub fn in_any_value_of_ty<'tcx>(
2424
has_mut_interior: HasMutInterior::in_any_value_of_ty(cx, ty),
2525
needs_drop: NeedsDrop::in_any_value_of_ty(cx, ty),
2626
needs_non_const_drop: NeedsNonConstDrop::in_any_value_of_ty(cx, ty),
27-
custom_eq: CustomEq::in_any_value_of_ty(cx, ty),
2827
tainted_by_errors,
2928
}
3029
}
@@ -213,35 +212,6 @@ impl Qualif for NeedsNonConstDrop {
213212
}
214213
}
215214

216-
/// A constant that cannot be used as part of a pattern in a `match` expression.
217-
pub struct CustomEq;
218-
219-
impl Qualif for CustomEq {
220-
const ANALYSIS_NAME: &'static str = "flow_custom_eq";
221-
222-
fn in_qualifs(qualifs: &ConstQualifs) -> bool {
223-
qualifs.custom_eq
224-
}
225-
226-
fn in_any_value_of_ty<'tcx>(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
227-
// If *any* component of a composite data type does not implement `Structural{Partial,}Eq`,
228-
// we know that at least some values of that type are not structural-match. I say "some"
229-
// because that component may be part of an enum variant (e.g.,
230-
// `Option::<NonStructuralMatchTy>::Some`), in which case some values of this type may be
231-
// structural-match (`Option::None`).
232-
traits::search_for_structural_match_violation(cx.body.span, cx.tcx, ty).is_some()
233-
}
234-
235-
fn in_adt_inherently<'tcx>(
236-
cx: &ConstCx<'_, 'tcx>,
237-
def: AdtDef<'tcx>,
238-
args: GenericArgsRef<'tcx>,
239-
) -> bool {
240-
let ty = Ty::new_adt(cx.tcx, def, args);
241-
!ty.is_structural_eq_shallow(cx.tcx)
242-
}
243-
}
244-
245215
// FIXME: Use `mir::visit::Visitor` for the `in_*` functions if/when it supports early return.
246216

247217
/// Returns `true` if this `Rvalue` contains qualif `Q`.

compiler/rustc_error_messages/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl From<Cow<'static, str>> for DiagnosticMessage {
378378
}
379379
}
380380

381-
/// A workaround for "good path" ICEs when formatting types in disabled lints.
381+
/// A workaround for good_path_delayed_bug ICEs when formatting types in disabled lints.
382382
///
383383
/// Delays formatting until `.into(): DiagnosticMessage` is used.
384384
pub struct DelayDm<F>(pub F);

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ impl Translate for AnnotateSnippetEmitter {
4444

4545
impl Emitter for AnnotateSnippetEmitter {
4646
/// The entry point for the diagnostics generation
47-
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
47+
fn emit_diagnostic(&mut self, mut diag: Diagnostic) {
4848
let fluent_args = to_fluent_args(diag.args());
4949

50-
let mut children = diag.children.clone();
51-
let (mut primary_span, suggestions) = self.primary_span_formatted(diag, &fluent_args);
50+
let mut suggestions = diag.suggestions.unwrap_or(vec![]);
51+
self.primary_span_formatted(&mut diag.span, &mut suggestions, &fluent_args);
5252

5353
self.fix_multispans_in_extern_macros_and_render_macro_backtrace(
54-
&mut primary_span,
55-
&mut children,
54+
&mut diag.span,
55+
&mut diag.children,
5656
&diag.level,
5757
self.macro_backtrace,
5858
);
@@ -62,9 +62,9 @@ impl Emitter for AnnotateSnippetEmitter {
6262
&diag.messages,
6363
&fluent_args,
6464
&diag.code,
65-
&primary_span,
66-
&children,
67-
suggestions,
65+
&diag.span,
66+
&diag.children,
67+
&suggestions,
6868
);
6969
}
7070

@@ -85,7 +85,11 @@ fn source_string(file: Lrc<SourceFile>, line: &Line) -> String {
8585
/// Maps `Diagnostic::Level` to `snippet::AnnotationType`
8686
fn annotation_type_for_level(level: Level) -> AnnotationType {
8787
match level {
88-
Level::Bug | Level::DelayedBug(_) | Level::Fatal | Level::Error => AnnotationType::Error,
88+
Level::Bug
89+
| Level::Fatal
90+
| Level::Error
91+
| Level::DelayedBug
92+
| Level::GoodPathDelayedBug => AnnotationType::Error,
8993
Level::ForceWarning(_) | Level::Warning => AnnotationType::Warning,
9094
Level::Note | Level::OnceNote => AnnotationType::Note,
9195
Level::Help | Level::OnceHelp => AnnotationType::Help,

compiler/rustc_errors/src/diagnostic.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::snippet::Style;
22
use crate::{
3-
CodeSuggestion, DelayedBugKind, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee,
4-
ErrCode, Level, MultiSpan, SubdiagnosticMessage, Substitution, SubstitutionPart,
5-
SuggestionStyle,
3+
CodeSuggestion, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, ErrCode, Level,
4+
MultiSpan, SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle,
65
};
76
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
87
use rustc_error_messages::fluent_value_from_str_list_sep_by_and;
@@ -235,19 +234,16 @@ impl Diagnostic {
235234

236235
pub fn is_error(&self) -> bool {
237236
match self.level {
238-
Level::Bug
239-
| Level::DelayedBug(DelayedBugKind::Normal)
240-
| Level::Fatal
241-
| Level::Error
242-
| Level::FailureNote => true,
237+
Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug => true,
243238

244-
Level::ForceWarning(_)
239+
Level::GoodPathDelayedBug
240+
| Level::ForceWarning(_)
245241
| Level::Warning
246-
| Level::DelayedBug(DelayedBugKind::GoodPath)
247242
| Level::Note
248243
| Level::OnceNote
249244
| Level::Help
250245
| Level::OnceHelp
246+
| Level::FailureNote
251247
| Level::Allow
252248
| Level::Expect(_) => false,
253249
}
@@ -306,11 +302,11 @@ impl Diagnostic {
306302
#[track_caller]
307303
pub fn downgrade_to_delayed_bug(&mut self) {
308304
assert!(
309-
self.is_error(),
305+
matches!(self.level, Level::Error | Level::DelayedBug),
310306
"downgrade_to_delayed_bug: cannot downgrade {:?} to DelayedBug: not an error",
311307
self.level
312308
);
313-
self.level = Level::DelayedBug(DelayedBugKind::Normal);
309+
self.level = Level::DelayedBug;
314310
}
315311

316312
/// Appends a labeled span to the diagnostic.

0 commit comments

Comments
 (0)