Skip to content

Commit 1c42857

Browse files
committed
Auto merge of #3113 - rust-lang:rustup-2023-10-07, r=saethlin
Automatic sync from rustc
2 parents 3b08930 + 722736a commit 1c42857

File tree

255 files changed

+7078
-4889
lines changed

Some content is hidden

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

255 files changed

+7078
-4889
lines changed

Cargo.lock

+29-6
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,12 @@ checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
508508

509509
[[package]]
510510
name = "clippy"
511-
version = "0.1.74"
511+
version = "0.1.75"
512512
dependencies = [
513+
"anstream",
513514
"clippy_lints",
514515
"clippy_utils",
516+
"color-print",
515517
"filetime",
516518
"futures",
517519
"if_chain",
@@ -546,7 +548,7 @@ dependencies = [
546548

547549
[[package]]
548550
name = "clippy_lints"
549-
version = "0.1.74"
551+
version = "0.1.75"
550552
dependencies = [
551553
"arrayvec",
552554
"cargo_metadata",
@@ -566,11 +568,12 @@ dependencies = [
566568
"unicode-normalization",
567569
"unicode-script",
568570
"url",
571+
"walkdir",
569572
]
570573

571574
[[package]]
572575
name = "clippy_utils"
573-
version = "0.1.74"
576+
version = "0.1.75"
574577
dependencies = [
575578
"arrayvec",
576579
"if_chain",
@@ -603,6 +606,27 @@ dependencies = [
603606
"tracing-error",
604607
]
605608

609+
[[package]]
610+
name = "color-print"
611+
version = "0.3.5"
612+
source = "registry+https://github.com/rust-lang/crates.io-index"
613+
checksum = "7a858372ff14bab9b1b30ea504f2a4bc534582aee3e42ba2d41d2a7baba63d5d"
614+
dependencies = [
615+
"color-print-proc-macro",
616+
]
617+
618+
[[package]]
619+
name = "color-print-proc-macro"
620+
version = "0.3.5"
621+
source = "registry+https://github.com/rust-lang/crates.io-index"
622+
checksum = "57e37866456a721d0a404439a1adae37a31be4e0055590d053dfe6981e05003f"
623+
dependencies = [
624+
"nom",
625+
"proc-macro2",
626+
"quote",
627+
"syn 1.0.109",
628+
]
629+
606630
[[package]]
607631
name = "color-spantrace"
608632
version = "0.2.0"
@@ -933,7 +957,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"
933957

934958
[[package]]
935959
name = "declare_clippy_lint"
936-
version = "0.1.74"
960+
version = "0.1.75"
937961
dependencies = [
938962
"itertools",
939963
"quote",
@@ -4311,7 +4335,6 @@ dependencies = [
43114335
"rustc_errors",
43124336
"rustc_hir",
43134337
"rustc_index",
4314-
"rustc_macros",
43154338
"rustc_middle",
43164339
"rustc_query_system",
43174340
"rustc_serialize",
@@ -4417,7 +4440,6 @@ dependencies = [
44174440
"rustc_hir",
44184441
"rustc_interface",
44194442
"rustc_middle",
4420-
"rustc_session",
44214443
"rustc_span",
44224444
"rustc_target",
44234445
"stable_mir",
@@ -4991,6 +5013,7 @@ version = "0.0.0"
49915013
dependencies = [
49925014
"addr2line",
49935015
"alloc",
5016+
"cc",
49945017
"cfg-if",
49955018
"compiler_builtins",
49965019
"core",

compiler/rustc_attr/src/builtin.rs

+23-62
Original file line numberDiff line numberDiff line change
@@ -353,28 +353,28 @@ pub fn find_body_stability(
353353
body_stab
354354
}
355355

356+
fn insert_or_error(sess: &Session, meta: &MetaItem, item: &mut Option<Symbol>) -> Option<()> {
357+
if item.is_some() {
358+
handle_errors(
359+
&sess.parse_sess,
360+
meta.span,
361+
AttrError::MultipleItem(pprust::path_to_string(&meta.path)),
362+
);
363+
None
364+
} else if let Some(v) = meta.value_str() {
365+
*item = Some(v);
366+
Some(())
367+
} else {
368+
sess.emit_err(session_diagnostics::IncorrectMetaItem { span: meta.span });
369+
None
370+
}
371+
}
372+
356373
/// Read the content of a `stable`/`rustc_const_stable` attribute, and return the feature name and
357374
/// its stability information.
358375
fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, StabilityLevel)> {
359376
let meta = attr.meta()?;
360377
let MetaItem { kind: MetaItemKind::List(ref metas), .. } = meta else { return None };
361-
let insert_or_error = |meta: &MetaItem, item: &mut Option<Symbol>| {
362-
if item.is_some() {
363-
handle_errors(
364-
&sess.parse_sess,
365-
meta.span,
366-
AttrError::MultipleItem(pprust::path_to_string(&meta.path)),
367-
);
368-
return false;
369-
}
370-
if let Some(v) = meta.value_str() {
371-
*item = Some(v);
372-
true
373-
} else {
374-
sess.emit_err(session_diagnostics::IncorrectMetaItem { span: meta.span });
375-
false
376-
}
377-
};
378378

379379
let mut feature = None;
380380
let mut since = None;
@@ -389,16 +389,8 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit
389389
};
390390

391391
match mi.name_or_empty() {
392-
sym::feature => {
393-
if !insert_or_error(mi, &mut feature) {
394-
return None;
395-
}
396-
}
397-
sym::since => {
398-
if !insert_or_error(mi, &mut since) {
399-
return None;
400-
}
401-
}
392+
sym::feature => insert_or_error(sess, mi, &mut feature)?,
393+
sym::since => insert_or_error(sess, mi, &mut since)?,
402394
_ => {
403395
handle_errors(
404396
&sess.parse_sess,
@@ -438,23 +430,6 @@ fn parse_stability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabilit
438430
fn parse_unstability(sess: &Session, attr: &Attribute) -> Option<(Symbol, StabilityLevel)> {
439431
let meta = attr.meta()?;
440432
let MetaItem { kind: MetaItemKind::List(ref metas), .. } = meta else { return None };
441-
let insert_or_error = |meta: &MetaItem, item: &mut Option<Symbol>| {
442-
if item.is_some() {
443-
handle_errors(
444-
&sess.parse_sess,
445-
meta.span,
446-
AttrError::MultipleItem(pprust::path_to_string(&meta.path)),
447-
);
448-
return false;
449-
}
450-
if let Some(v) = meta.value_str() {
451-
*item = Some(v);
452-
true
453-
} else {
454-
sess.emit_err(session_diagnostics::IncorrectMetaItem { span: meta.span });
455-
false
456-
}
457-
};
458433

459434
let mut feature = None;
460435
let mut reason = None;
@@ -473,20 +448,10 @@ fn parse_unstability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabil
473448
};
474449

475450
match mi.name_or_empty() {
476-
sym::feature => {
477-
if !insert_or_error(mi, &mut feature) {
478-
return None;
479-
}
480-
}
481-
sym::reason => {
482-
if !insert_or_error(mi, &mut reason) {
483-
return None;
484-
}
485-
}
451+
sym::feature => insert_or_error(sess, mi, &mut feature)?,
452+
sym::reason => insert_or_error(sess, mi, &mut reason)?,
486453
sym::issue => {
487-
if !insert_or_error(mi, &mut issue) {
488-
return None;
489-
}
454+
insert_or_error(sess, mi, &mut issue)?;
490455

491456
// These unwraps are safe because `insert_or_error` ensures the meta item
492457
// is a name/value pair string literal.
@@ -515,11 +480,7 @@ fn parse_unstability(sess: &Session, attr: &Attribute) -> Option<(Symbol, Stabil
515480
}
516481
is_soft = true;
517482
}
518-
sym::implied_by => {
519-
if !insert_or_error(mi, &mut implied_by) {
520-
return None;
521-
}
522-
}
483+
sym::implied_by => insert_or_error(sess, mi, &mut implied_by)?,
523484
_ => {
524485
handle_errors(
525486
&sess.parse_sess,

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ fn check_opaque_type_well_formed<'tcx>(
368368
if errors.is_empty() {
369369
Ok(definition_ty)
370370
} else {
371-
Err(infcx.err_ctxt().report_fulfillment_errors(&errors))
371+
Err(infcx.err_ctxt().report_fulfillment_errors(errors))
372372
}
373373
}
374374

compiler/rustc_codegen_cranelift/src/base.rs

-11
Original file line numberDiff line numberDiff line change
@@ -250,17 +250,6 @@ pub(crate) fn verify_func(
250250
}
251251

252252
fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
253-
if let Err(err) =
254-
fx.mir.post_mono_checks(fx.tcx, ty::ParamEnv::reveal_all(), |c| Ok(fx.monomorphize(c)))
255-
{
256-
err.emit_err(fx.tcx);
257-
fx.bcx.append_block_params_for_function_params(fx.block_map[START_BLOCK]);
258-
fx.bcx.switch_to_block(fx.block_map[START_BLOCK]);
259-
// compilation should have been aborted
260-
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
261-
return;
262-
}
263-
264253
let arg_uninhabited = fx
265254
.mir
266255
.args_iter()

compiler/rustc_codegen_ssa/src/mir/constant.rs

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
2121
}
2222

2323
pub fn eval_mir_constant(&self, constant: &mir::ConstOperand<'tcx>) -> mir::ConstValue<'tcx> {
24+
// `MirUsedCollector` visited all constants before codegen began, so if we got here there
25+
// can be no more constants that fail to evaluate.
2426
self.monomorphize(constant.const_)
2527
.eval(self.cx.tcx(), ty::ParamEnv::reveal_all(), Some(constant.span))
2628
.expect("erroneous constant not captured by required_consts")

compiler/rustc_codegen_ssa/src/mir/mod.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,11 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
209209
caller_location: None,
210210
};
211211

212-
fx.per_local_var_debug_info = fx.compute_per_local_var_debug_info(&mut start_bx);
212+
// It may seem like we should iterate over `required_consts` to ensure they all successfully
213+
// evaluate; however, the `MirUsedCollector` already did that during the collection phase of
214+
// monomorphization so we don't have to do it again.
213215

214-
// Rust post-monomorphization checks; we later rely on them.
215-
if let Err(err) =
216-
mir.post_mono_checks(cx.tcx(), ty::ParamEnv::reveal_all(), |c| Ok(fx.monomorphize(c)))
217-
{
218-
err.emit_err(cx.tcx());
219-
// This IR shouldn't ever be emitted, but let's try to guard against any of this code
220-
// ever running.
221-
start_bx.abort();
222-
return;
223-
}
216+
fx.per_local_var_debug_info = fx.compute_per_local_var_debug_info(&mut start_bx);
224217

225218
let memory_locals = analyze::non_ssa_locals(&fx);
226219

compiler/rustc_const_eval/src/interpret/eval_context.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -750,12 +750,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
750750

751751
// Make sure all the constants required by this frame evaluate successfully (post-monomorphization check).
752752
if M::POST_MONO_CHECKS {
753-
// `ctfe_query` does some error message decoration that we want to be in effect here.
754-
self.ctfe_query(None, |tcx| {
755-
body.post_mono_checks(*tcx, self.param_env, |c| {
756-
self.subst_from_current_frame_and_normalize_erasing_regions(c)
757-
})
758-
})?;
753+
for &const_ in &body.required_consts {
754+
let c =
755+
self.subst_from_current_frame_and_normalize_erasing_regions(const_.const_)?;
756+
c.eval(*self.tcx, self.param_env, Some(const_.span)).map_err(|err| {
757+
err.emit_note(*self.tcx);
758+
err
759+
})?;
760+
}
759761
}
760762

761763
// done
@@ -1054,14 +1056,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10541056
Ok(())
10551057
}
10561058

1057-
/// Call a query that can return `ErrorHandled`. If `span` is `Some`, point to that span when an error occurs.
1059+
/// Call a query that can return `ErrorHandled`. Should be used for statics and other globals.
1060+
/// (`mir::Const`/`ty::Const` have `eval` methods that can be used directly instead.)
10581061
pub fn ctfe_query<T>(
10591062
&self,
1060-
span: Option<Span>,
10611063
query: impl FnOnce(TyCtxtAt<'tcx>) -> Result<T, ErrorHandled>,
10621064
) -> Result<T, ErrorHandled> {
10631065
// Use a precise span for better cycle errors.
1064-
query(self.tcx.at(span.unwrap_or_else(|| self.cur_span()))).map_err(|err| {
1066+
query(self.tcx.at(self.cur_span())).map_err(|err| {
10651067
err.emit_note(*self.tcx);
10661068
err
10671069
})
@@ -1082,7 +1084,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10821084
} else {
10831085
self.param_env
10841086
};
1085-
let val = self.ctfe_query(None, |tcx| tcx.eval_to_allocation_raw(param_env.and(gid)))?;
1087+
let val = self.ctfe_query(|tcx| tcx.eval_to_allocation_raw(param_env.and(gid)))?;
10861088
self.raw_const_to_mplace(val)
10871089
}
10881090

@@ -1092,7 +1094,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10921094
span: Option<Span>,
10931095
layout: Option<TyAndLayout<'tcx>>,
10941096
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
1095-
let const_val = self.ctfe_query(span, |tcx| val.eval(*tcx, self.param_env, span))?;
1097+
let const_val = val.eval(*self.tcx, self.param_env, span).map_err(|err| {
1098+
// FIXME: somehow this is reachable even when POST_MONO_CHECKS is on.
1099+
// Are we not always populating `required_consts`?
1100+
err.emit_note(*self.tcx);
1101+
err
1102+
})?;
10961103
self.const_val_to_op(const_val, val.ty(), layout)
10971104
}
10981105

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
164164
sym::type_name => Ty::new_static_str(self.tcx.tcx),
165165
_ => bug!(),
166166
};
167-
let val = self.ctfe_query(None, |tcx| {
167+
let val = self.ctfe_query(|tcx| {
168168
tcx.const_eval_global_id(self.param_env, gid, Some(tcx.span))
169169
})?;
170170
let val = self.const_val_to_op(val, ty, Some(dest.layout))?;

compiler/rustc_const_eval/src/interpret/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
536536
}
537537

538538
// We don't give a span -- statics don't need that, they cannot be generic or associated.
539-
let val = self.ctfe_query(None, |tcx| tcx.eval_static_initializer(def_id))?;
539+
let val = self.ctfe_query(|tcx| tcx.eval_static_initializer(def_id))?;
540540
(val, Some(def_id))
541541
}
542542
};

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
743743

744744
let errors = ocx.select_all_or_error();
745745
if !errors.is_empty() {
746-
infcx.err_ctxt().report_fulfillment_errors(&errors);
746+
infcx.err_ctxt().report_fulfillment_errors(errors);
747747
}
748748

749749
// Attempting to call a trait method?

0 commit comments

Comments
 (0)