Skip to content

Commit cd11905

Browse files
committed
Auto merge of #95056 - Dylan-DPC:rollup-swtuw2n, r=Dylan-DPC
Rollup of 10 pull requests Successful merges: - #91133 (Improve `unsafe` diagnostic) - #93222 (Make ErrorReported impossible to construct outside `rustc_errors`) - #93745 (Stabilize ADX target feature) - #94309 ([generator_interior] Be more precise with scopes of borrowed places) - #94698 (Remove redundant code from copy-suggestions) - #94731 (Suggest adding `{ .. }` around a const function call with arguments) - #94960 (Fix many spelling mistakes) - #94982 (Add deprecated_safe feature gate and attribute, cc #94978) - #94997 (debuginfo: Fix ICE when generating name for type that produces a layout error.) - #95000 (Fixed wrong type name in comment) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4ca56d2 + 4493826 commit cd11905

File tree

181 files changed

+1290
-773
lines changed

Some content is hidden

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

181 files changed

+1290
-773
lines changed

compiler/rustc_ast_lowering/src/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(super) struct ItemLowerer<'a, 'lowering, 'hir> {
2626
}
2727

2828
/// When we have a ty alias we *may* have two where clauses. To give the best diagnostics, we set the span
29-
/// to the where clause that is prefered, if it exists. Otherwise, it sets the span to the other where
29+
/// to the where clause that is preferred, if it exists. Otherwise, it sets the span to the other where
3030
/// clause if it exists.
3131
fn add_ty_alias_where_clause(
3232
generics: &mut ast::Generics,

compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
952952
sess.diagnostic().delay_span_bug(
953953
span,
954954
"unexpected delimiter in key-value attribute's value",
955-
)
955+
);
956956
}
957957
unwrap_single_token(sess, tokens, span)
958958
}

compiler/rustc_ast_passes/src/ast_validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ impl<'a> AstValidator<'a> {
440440
attr.span,
441441
"allow, cfg, cfg_attr, deny, \
442442
forbid, and warn are the only allowed built-in attributes in function parameters",
443-
)
443+
);
444444
}
445445
});
446446
}

compiler/rustc_ast_passes/src/feature_gate.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,12 @@ impl<'a> PostExpansionVisitor<'a> {
252252
"wasm ABI is experimental and subject to change"
253253
);
254254
}
255-
abi => self
256-
.sess
257-
.parse_sess
258-
.span_diagnostic
259-
.delay_span_bug(span, &format!("unrecognized ABI not caught in lowering: {}", abi)),
255+
abi => {
256+
self.sess.parse_sess.span_diagnostic.delay_span_bug(
257+
span,
258+
&format!("unrecognized ABI not caught in lowering: {}", abi),
259+
);
260+
}
260261
}
261262
}
262263

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+55-80
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use rustc_middle::mir::{
1212
FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef,
1313
ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm,
1414
};
15-
use rustc_middle::ty::{
16-
self, suggest_constraining_type_param, suggest_constraining_type_params, PredicateKind, Ty,
17-
};
15+
use rustc_middle::ty::{self, suggest_constraining_type_params, PredicateKind, Ty};
1816
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
1917
use rustc_span::symbol::sym;
2018
use rustc_span::{BytePos, MultiSpan, Span};
@@ -285,86 +283,63 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
285283
Some(ref name) => format!("`{}`", name),
286284
None => "value".to_owned(),
287285
};
288-
if let ty::Param(param_ty) = ty.kind() {
289-
let tcx = self.infcx.tcx;
290-
let generics = tcx.generics_of(self.mir_def_id());
291-
let param = generics.type_param(&param_ty, tcx);
292-
if let Some(generics) = tcx
293-
.typeck_root_def_id(self.mir_def_id().to_def_id())
294-
.as_local()
295-
.and_then(|def_id| tcx.hir().get_generics(def_id))
296-
{
297-
suggest_constraining_type_param(
298-
tcx,
299-
generics,
300-
&mut err,
301-
param.name.as_str(),
302-
"Copy",
303-
None,
286+
287+
// Try to find predicates on *generic params* that would allow copying `ty`
288+
let tcx = self.infcx.tcx;
289+
let generics = tcx.generics_of(self.mir_def_id());
290+
if let Some(hir_generics) = tcx
291+
.typeck_root_def_id(self.mir_def_id().to_def_id())
292+
.as_local()
293+
.and_then(|def_id| tcx.hir().get_generics(def_id))
294+
{
295+
let predicates: Result<Vec<_>, _> = tcx.infer_ctxt().enter(|infcx| {
296+
let mut fulfill_cx =
297+
<dyn rustc_infer::traits::TraitEngine<'_>>::new(infcx.tcx);
298+
299+
let copy_did = infcx.tcx.lang_items().copy_trait().unwrap();
300+
let cause = ObligationCause::new(
301+
span,
302+
self.mir_hir_id(),
303+
rustc_infer::traits::ObligationCauseCode::MiscObligation,
304304
);
305-
}
306-
} else {
307-
// Try to find predicates on *generic params* that would allow copying `ty`
308-
309-
let tcx = self.infcx.tcx;
310-
let generics = tcx.generics_of(self.mir_def_id());
311-
if let Some(hir_generics) = tcx
312-
.typeck_root_def_id(self.mir_def_id().to_def_id())
313-
.as_local()
314-
.and_then(|def_id| tcx.hir().get_generics(def_id))
315-
{
316-
let predicates: Result<Vec<_>, _> = tcx.infer_ctxt().enter(|infcx| {
317-
let mut fulfill_cx =
318-
<dyn rustc_infer::traits::TraitEngine<'_>>::new(infcx.tcx);
319-
320-
let copy_did = infcx.tcx.lang_items().copy_trait().unwrap();
321-
let cause = ObligationCause::new(
322-
span,
323-
self.mir_hir_id(),
324-
rustc_infer::traits::ObligationCauseCode::MiscObligation,
325-
);
326-
fulfill_cx.register_bound(
327-
&infcx,
328-
self.param_env,
329-
// Erase any region vids from the type, which may not be resolved
330-
infcx.tcx.erase_regions(ty),
331-
copy_did,
332-
cause,
333-
);
334-
// Select all, including ambiguous predicates
335-
let errors = fulfill_cx.select_all_or_error(&infcx);
336-
337-
// Only emit suggestion if all required predicates are on generic
338-
errors
339-
.into_iter()
340-
.map(|err| match err.obligation.predicate.kind().skip_binder() {
341-
PredicateKind::Trait(predicate) => {
342-
match predicate.self_ty().kind() {
343-
ty::Param(param_ty) => Ok((
344-
generics.type_param(param_ty, tcx),
345-
predicate
346-
.trait_ref
347-
.print_only_trait_path()
348-
.to_string(),
349-
)),
350-
_ => Err(()),
351-
}
305+
fulfill_cx.register_bound(
306+
&infcx,
307+
self.param_env,
308+
// Erase any region vids from the type, which may not be resolved
309+
infcx.tcx.erase_regions(ty),
310+
copy_did,
311+
cause,
312+
);
313+
// Select all, including ambiguous predicates
314+
let errors = fulfill_cx.select_all_or_error(&infcx);
315+
316+
// Only emit suggestion if all required predicates are on generic
317+
errors
318+
.into_iter()
319+
.map(|err| match err.obligation.predicate.kind().skip_binder() {
320+
PredicateKind::Trait(predicate) => {
321+
match predicate.self_ty().kind() {
322+
ty::Param(param_ty) => Ok((
323+
generics.type_param(param_ty, tcx),
324+
predicate.trait_ref.print_only_trait_path().to_string(),
325+
)),
326+
_ => Err(()),
352327
}
353-
_ => Err(()),
354-
})
355-
.collect()
356-
});
328+
}
329+
_ => Err(()),
330+
})
331+
.collect()
332+
});
357333

358-
if let Ok(predicates) = predicates {
359-
suggest_constraining_type_params(
360-
tcx,
361-
hir_generics,
362-
&mut err,
363-
predicates.iter().map(|(param, constraint)| {
364-
(param.name.as_str(), &**constraint, None)
365-
}),
366-
);
367-
}
334+
if let Ok(predicates) = predicates {
335+
suggest_constraining_type_params(
336+
tcx,
337+
hir_generics,
338+
&mut err,
339+
predicates.iter().map(|(param, constraint)| {
340+
(param.name.as_str(), &**constraint, None)
341+
}),
342+
);
368343
}
369344
}
370345

compiler/rustc_borrowck/src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn do_mir_borrowck<'a, 'tcx>(
178178

179179
// Gather the upvars of a closure, if any.
180180
let tables = tcx.typeck_opt_const_arg(def);
181-
if let Some(ErrorGuaranteed) = tables.tainted_by_errors {
181+
if let Some(ErrorGuaranteed { .. }) = tables.tainted_by_errors {
182182
infcx.set_tainted_by_errors();
183183
errors.set_tainted_by_errors();
184184
}
@@ -2274,6 +2274,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22742274
}
22752275

22762276
mod error {
2277+
use rustc_errors::ErrorGuaranteed;
2278+
22772279
use super::*;
22782280

22792281
pub struct BorrowckErrors<'tcx> {
@@ -2311,7 +2313,7 @@ mod error {
23112313
// FIXME(eddyb) this is a suboptimal API because `tainted_by_errors` is
23122314
// set before any emission actually happens (weakening the guarantee).
23132315
pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_, ErrorGuaranteed>) {
2314-
self.tainted_by_errors = Some(ErrorGuaranteed {});
2316+
self.tainted_by_errors = Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
23152317
t.buffer(&mut self.buffered);
23162318
}
23172319

@@ -2320,7 +2322,7 @@ mod error {
23202322
}
23212323

23222324
pub fn set_tainted_by_errors(&mut self) {
2323-
self.tainted_by_errors = Some(ErrorGuaranteed {});
2325+
self.tainted_by_errors = Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
23242326
}
23252327
}
23262328

compiler/rustc_codegen_cranelift/src/constant.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Handling of `static`s, `const`s and promoted allocations
22
33
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
4-
use rustc_errors::ErrorGuaranteed;
54
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
65
use rustc_middle::mir::interpret::{
76
read_target_uint, AllocId, ConstAllocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar,
@@ -54,7 +53,7 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool {
5453
{
5554
all_constants_ok = false;
5655
match err {
57-
ErrorHandled::Reported(ErrorGuaranteed) | ErrorHandled::Linted => {
56+
ErrorHandled::Reported(_) | ErrorHandled::Linted => {
5857
fx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
5958
}
6059
ErrorHandled::TooGeneric => {

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,30 @@ fn push_debuginfo_type_name<'tcx>(
7474
ty::Float(float_ty) => output.push_str(float_ty.name_str()),
7575
ty::Foreign(def_id) => push_item_name(tcx, def_id, qualified, output),
7676
ty::Adt(def, substs) => {
77-
let ty_and_layout = tcx.layout_of(ParamEnv::reveal_all().and(t)).expect("layout error");
77+
// `layout_for_cpp_like_fallback` will be `Some` if we want to use the fallback encoding.
78+
let layout_for_cpp_like_fallback = if cpp_like_debuginfo && def.is_enum() {
79+
match tcx.layout_of(ParamEnv::reveal_all().and(t)) {
80+
Ok(layout) => {
81+
if !wants_c_like_enum_debuginfo(layout) {
82+
Some(layout)
83+
} else {
84+
// This is a C-like enum so we don't want to use the fallback encoding
85+
// for the name.
86+
None
87+
}
88+
}
89+
Err(e) => {
90+
// Computing the layout can still fail here, e.g. if the target architecture
91+
// cannot represent the type. See https://github.com/rust-lang/rust/issues/94961.
92+
tcx.sess.fatal(&format!("{}", e));
93+
}
94+
}
95+
} else {
96+
// We are not emitting cpp-like debuginfo or this isn't even an enum.
97+
None
98+
};
7899

79-
if def.is_enum() && cpp_like_debuginfo && !wants_c_like_enum_debuginfo(ty_and_layout) {
100+
if let Some(ty_and_layout) = layout_for_cpp_like_fallback {
80101
msvc_enum_fallback(
81102
tcx,
82103
ty_and_layout,

compiler/rustc_codegen_ssa/src/mir/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::traits::*;
2-
use rustc_errors::ErrorGuaranteed;
32
use rustc_middle::mir;
43
use rustc_middle::mir::interpret::ErrorHandled;
54
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, TyAndLayout};
@@ -191,7 +190,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
191190
all_consts_ok = false;
192191
match err {
193192
// errored or at least linted
194-
ErrorHandled::Reported(ErrorGuaranteed) | ErrorHandled::Linted => {}
193+
ErrorHandled::Reported(_) | ErrorHandled::Linted => {}
195194
ErrorHandled::TooGeneric => {
196195
span_bug!(const_.span, "codgen encountered polymorphic constant: {:?}", err)
197196
}

compiler/rustc_codegen_ssa/src/target_features.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const AARCH64_TIED_FEATURES: &[&[&str]] = &[
148148
];
149149

150150
const X86_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
151-
("adx", Some(sym::adx_target_feature)),
151+
("adx", None),
152152
("aes", None),
153153
("avx", None),
154154
("avx2", None),

compiler/rustc_const_eval/src/const_eval/machine.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_errors::ErrorGuaranteed;
21
use rustc_hir::def::DefKind;
32
use rustc_middle::mir;
43
use rustc_middle::ty::{self, Ty};
@@ -247,11 +246,11 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
247246
if ecx.tcx.is_ctfe_mir_available(def.did) {
248247
Ok(ecx.tcx.mir_for_ctfe_opt_const_arg(def))
249248
} else if ecx.tcx.def_kind(def.did) == DefKind::AssocConst {
250-
ecx.tcx.sess.delay_span_bug(
249+
let guar = ecx.tcx.sess.delay_span_bug(
251250
rustc_span::DUMMY_SP,
252251
"This is likely a const item that is missing from its impl",
253252
);
254-
throw_inval!(AlreadyReported(ErrorGuaranteed {}));
253+
throw_inval!(AlreadyReported(guar));
255254
} else {
256255
let path = ecx.tcx.def_path_str(def.did);
257256
Err(ConstEvalErrKind::NeedsRfc(format!("calling extern function `{}`", path))

compiler/rustc_const_eval/src/interpret/intern.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,11 @@ pub fn intern_const_alloc_recursive<
406406
} else if ecx.memory.dead_alloc_map.contains_key(&alloc_id) {
407407
// Codegen does not like dangling pointers, and generally `tcx` assumes that
408408
// all allocations referenced anywhere actually exist. So, make sure we error here.
409-
ecx.tcx.sess.span_err(ecx.tcx.span, "encountered dangling pointer in final constant");
410-
return Err(ErrorGuaranteed);
409+
let reported = ecx
410+
.tcx
411+
.sess
412+
.span_err(ecx.tcx.span, "encountered dangling pointer in final constant");
413+
return Err(reported);
411414
} else if ecx.tcx.get_global_alloc(alloc_id).is_none() {
412415
// We have hit an `AllocId` that is neither in local or global memory and isn't
413416
// marked as dangling by local memory. That should be impossible.

compiler/rustc_const_eval/src/interpret/operand.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
use std::convert::TryFrom;
55
use std::fmt::Write;
66

7-
use rustc_errors::ErrorGuaranteed;
87
use rustc_hir::def::Namespace;
98
use rustc_macros::HashStable;
109
use rustc_middle::ty::layout::{LayoutOf, PrimitiveExt, TyAndLayout};
1110
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Printer};
12-
use rustc_middle::ty::{ConstInt, Ty};
11+
use rustc_middle::ty::{ConstInt, DelaySpanBugEmitted, Ty};
1312
use rustc_middle::{mir, ty};
1413
use rustc_target::abi::{Abi, HasDataLayout, Size, TagEncoding};
1514
use rustc_target::abi::{VariantIdx, Variants};
@@ -565,7 +564,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
565564
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
566565
match val.val() {
567566
ty::ConstKind::Param(_) | ty::ConstKind::Bound(..) => throw_inval!(TooGeneric),
568-
ty::ConstKind::Error(_) => throw_inval!(AlreadyReported(ErrorGuaranteed)),
567+
ty::ConstKind::Error(DelaySpanBugEmitted { reported, .. }) => {
568+
throw_inval!(AlreadyReported(reported))
569+
}
569570
ty::ConstKind::Unevaluated(uv) => {
570571
let instance = self.resolve(uv.def, uv.substs)?;
571572
Ok(self.eval_to_allocation(GlobalId { instance, promoted: uv.promoted })?.into())

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
259259
self.tcx.sess.diagnostic().emit_diagnostic(&error);
260260
}
261261
} else {
262-
assert!(self.tcx.sess.has_errors());
262+
assert!(self.tcx.sess.has_errors().is_some());
263263
}
264264
}
265265

@@ -327,8 +327,8 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
327327

328328
match op.importance() {
329329
ops::DiagnosticImportance::Primary => {
330-
self.error_emitted = Some(ErrorGuaranteed);
331-
err.emit();
330+
let reported = err.emit();
331+
self.error_emitted = Some(reported);
332332
}
333333

334334
ops::DiagnosticImportance::Secondary => err.buffer(&mut self.secondary_errors),

0 commit comments

Comments
 (0)