Skip to content

Commit f7801d6

Browse files
committed
Auto merge of #78767 - m-ou-se:rollup-eu5wgxl, r=m-ou-se
Rollup of 15 pull requests Successful merges: - #76718 (Move Vec UI tests to unit tests when possible) - #78093 (Clean up docs for 'as' keyword) - #78425 (Move f64::NAN ui tests into `library`) - #78465 (Change as_str → to_string in proc_macro::Ident::span() docs) - #78584 (Add keyboard handling to the theme picker menu) - #78716 (Array trait impl comment/doc fixes) - #78727 ((rustdoc) fix test for trait impl display) - #78733 (fix a couple of clippy warnings:) - #78735 (Simplify the implementation of `get_mut` (no unsafe)) - #78738 (Move range in ui test to ops test in library/core) - #78739 (Fix ICE on type error in async function) - #78742 (make intern_const_alloc_recursive return error) - #78756 (Update cargo) - #78757 (Improve and clean up some intra-doc links) - #78758 (Fixed typo in comment) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8c20701 + 8416e13 commit f7801d6

File tree

51 files changed

+503
-367
lines changed

Some content is hidden

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

51 files changed

+503
-367
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ dependencies = [
9191

9292
[[package]]
9393
name = "anyhow"
94-
version = "1.0.32"
94+
version = "1.0.34"
9595
source = "registry+https://github.com/rust-lang/crates.io-index"
96-
checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b"
96+
checksum = "bf8dcb5b4bbaa28653b647d8c77bd4ed40183b48882e130c1f1ffb73de069fd7"
9797

9898
[[package]]
9999
name = "arc-swap"

compiler/rustc_ast/src/attr/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ pub fn list_contains_name(items: &[NestedMetaItem], name: Symbol) -> bool {
360360
impl MetaItem {
361361
fn token_trees_and_spacings(&self) -> Vec<TreeAndSpacing> {
362362
let mut idents = vec![];
363-
let mut last_pos = BytePos(0 as u32);
363+
let mut last_pos = BytePos(0_u32);
364364
for (i, segment) in self.path.segments.iter().enumerate() {
365365
let is_first = i == 0;
366366
if !is_first {

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
739739
"cannot infer {} {} {} `{}`{}",
740740
kind_str, preposition, descr, type_name, parent_desc
741741
)
742-
.into()
743742
}
744743
}
745744
}

compiler/rustc_interface/src/util.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ pub fn get_codegen_backend(sopts: &config::Options) -> Box<dyn CodegenBackend> {
246246

247247
INIT.call_once(|| {
248248
#[cfg(feature = "llvm")]
249-
const DEFAULT_CODEGEN_BACKEND: &'static str = "llvm";
249+
const DEFAULT_CODEGEN_BACKEND: &str = "llvm";
250250

251251
#[cfg(not(feature = "llvm"))]
252-
const DEFAULT_CODEGEN_BACKEND: &'static str = "cranelift";
252+
const DEFAULT_CODEGEN_BACKEND: &str = "cranelift";
253253

254254
let codegen_name = sopts
255255
.debugging_opts
@@ -414,11 +414,10 @@ pub fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend
414414
let libdir = filesearch::relative_target_lib_path(&sysroot, &target);
415415
sysroot.join(libdir).with_file_name("codegen-backends")
416416
})
417-
.filter(|f| {
417+
.find(|f| {
418418
info!("codegen backend candidate: {}", f.display());
419419
f.exists()
420-
})
421-
.next();
420+
});
422421
let sysroot = sysroot.unwrap_or_else(|| {
423422
let candidates = sysroot_candidates
424423
.iter()

compiler/rustc_middle/src/middle/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ impl<'tcx> TyCtxt<'tcx> {
399399
def_id: DefId,
400400
id: Option<HirId>,
401401
span: Span,
402-
unmarked: impl FnOnce(Span, DefId) -> (),
402+
unmarked: impl FnOnce(Span, DefId),
403403
) {
404404
let soft_handler = |lint, span, msg: &_| {
405405
self.struct_span_lint_hir(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, |lint| {

compiler/rustc_middle/src/mir/interpret/error.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ impl From<ErrorHandled> for InterpErrorInfo<'_> {
8181
}
8282
}
8383

84+
impl From<ErrorReported> for InterpErrorInfo<'_> {
85+
fn from(err: ErrorReported) -> Self {
86+
InterpError::InvalidProgram(InvalidProgramInfo::AlreadyReported(err)).into()
87+
}
88+
}
89+
8490
impl<'tcx> From<InterpError<'tcx>> for InterpErrorInfo<'tcx> {
8591
fn from(kind: InterpError<'tcx>) -> Self {
8692
let capture_backtrace = tls::with_opt(|tcx| {
@@ -115,8 +121,8 @@ pub enum InvalidProgramInfo<'tcx> {
115121
/// Cannot compute this constant because it depends on another one
116122
/// which already produced an error.
117123
ReferencedConstant,
118-
/// Abort in case type errors are reached.
119-
TypeckError(ErrorReported),
124+
/// Abort in case errors are already reported.
125+
AlreadyReported(ErrorReported),
120126
/// An error occurred during layout computation.
121127
Layout(layout::LayoutError<'tcx>),
122128
/// An invalid transmute happened.
@@ -129,7 +135,7 @@ impl fmt::Display for InvalidProgramInfo<'_> {
129135
match self {
130136
TooGeneric => write!(f, "encountered overly generic constant"),
131137
ReferencedConstant => write!(f, "referenced constant has errors"),
132-
TypeckError(ErrorReported) => {
138+
AlreadyReported(ErrorReported) => {
133139
write!(f, "encountered constants with type errors, stopping evaluation")
134140
}
135141
Layout(ref err) => write!(f, "{}", err),

compiler/rustc_middle/src/mir/terminator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl SwitchTargets {
4646
pub fn new(targets: impl Iterator<Item = (u128, BasicBlock)>, otherwise: BasicBlock) -> Self {
4747
let (values, mut targets): (SmallVec<_>, SmallVec<_>) = targets.unzip();
4848
targets.push(otherwise);
49-
Self { values: values.into(), targets }
49+
Self { values, targets }
5050
}
5151

5252
/// Builds a switch targets definition that jumps to `then` if the tested value equals `value`,

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ pub type PlaceholderConst = Placeholder<BoundVar>;
16411641
#[derive(Hash, HashStable)]
16421642
pub struct WithOptConstParam<T> {
16431643
pub did: T,
1644-
/// The `DefId` of the corresponding generic paramter in case `did` is
1644+
/// The `DefId` of the corresponding generic parameter in case `did` is
16451645
/// a const argument.
16461646
///
16471647
/// Note that even if `did` is a const argument, this may still be `None`.

compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
120120
let move_out = self.move_data.moves[(*move_site).moi];
121121
let moved_place = &self.move_data.move_paths[move_out.path].place;
122122
// `*(_1)` where `_1` is a `Box` is actually a move out.
123-
let is_box_move = moved_place.as_ref().projection == &[ProjectionElem::Deref]
123+
let is_box_move = moved_place.as_ref().projection == [ProjectionElem::Deref]
124124
&& self.body.local_decls[moved_place.local].ty.is_box();
125125

126126
!is_box_move

compiler/rustc_mir/src/const_eval/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<'tcx> ConstEvalErr<'tcx> {
141141
err_inval!(Layout(LayoutError::Unknown(_))) | err_inval!(TooGeneric) => {
142142
return ErrorHandled::TooGeneric;
143143
}
144-
err_inval!(TypeckError(error_reported)) => {
144+
err_inval!(AlreadyReported(error_reported)) => {
145145
return ErrorHandled::Reported(error_reported);
146146
}
147147
// We must *always* hard error on these, even if the caller wants just a lint.

compiler/rustc_mir/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
6767
None => InternKind::Constant,
6868
}
6969
};
70-
intern_const_alloc_recursive(ecx, intern_kind, ret);
70+
intern_const_alloc_recursive(ecx, intern_kind, ret)?;
7171

7272
debug!("eval_body_using_ecx done: {:?}", *ret);
7373
Ok(ret)

compiler/rustc_mir/src/const_eval/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ pub(crate) fn const_caller_location(
2929
let mut ecx = mk_eval_cx(tcx, DUMMY_SP, ty::ParamEnv::reveal_all(), false);
3030

3131
let loc_place = ecx.alloc_caller_location(file, line, col);
32-
intern_const_alloc_recursive(&mut ecx, InternKind::Constant, loc_place);
32+
if intern_const_alloc_recursive(&mut ecx, InternKind::Constant, loc_place).is_err() {
33+
bug!("intern_const_alloc_recursive should not error in this case")
34+
}
3335
ConstValue::Scalar(loc_place.ptr)
3436
}
3537

compiler/rustc_mir/src/interpret/eval_context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
469469
if let Some(def) = def.as_local() {
470470
if self.tcx.has_typeck_results(def.did) {
471471
if let Some(error_reported) = self.tcx.typeck_opt_const_arg(def).tainted_by_errors {
472-
throw_inval!(TypeckError(error_reported))
472+
throw_inval!(AlreadyReported(error_reported))
473473
}
474474
}
475475
}
@@ -525,8 +525,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
525525
Ok(Some(instance)) => Ok(instance),
526526
Ok(None) => throw_inval!(TooGeneric),
527527

528-
// FIXME(eddyb) this could be a bit more specific than `TypeckError`.
529-
Err(error_reported) => throw_inval!(TypeckError(error_reported)),
528+
// FIXME(eddyb) this could be a bit more specific than `AlreadyReported`.
529+
Err(error_reported) => throw_inval!(AlreadyReported(error_reported)),
530530
}
531531
}
532532

compiler/rustc_mir/src/interpret/intern.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
1717
use super::validity::RefTracking;
1818
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
19+
use rustc_errors::ErrorReported;
1920
use rustc_hir as hir;
2021
use rustc_middle::mir::interpret::InterpResult;
2122
use rustc_middle::ty::{self, layout::TyAndLayout, Ty};
@@ -285,11 +286,13 @@ pub enum InternKind {
285286
/// tracks where in the value we are and thus can show much better error messages.
286287
/// Any errors here would anyway be turned into `const_err` lints, whereas validation failures
287288
/// are hard errors.
289+
#[tracing::instrument(skip(ecx))]
288290
pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
289291
ecx: &mut InterpCx<'mir, 'tcx, M>,
290292
intern_kind: InternKind,
291293
ret: MPlaceTy<'tcx>,
292-
) where
294+
) -> Result<(), ErrorReported>
295+
where
293296
'tcx: 'mir,
294297
{
295298
let tcx = ecx.tcx;
@@ -405,12 +408,14 @@ pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
405408
// Codegen does not like dangling pointers, and generally `tcx` assumes that
406409
// all allocations referenced anywhere actually exist. So, make sure we error here.
407410
ecx.tcx.sess.span_err(ecx.tcx.span, "encountered dangling pointer in final constant");
411+
return Err(ErrorReported);
408412
} else if ecx.tcx.get_global_alloc(alloc_id).is_none() {
409413
// We have hit an `AllocId` that is neither in local or global memory and isn't
410414
// marked as dangling by local memory. That should be impossible.
411415
span_bug!(ecx.tcx.span, "encountered unknown alloc id {:?}", alloc_id);
412416
}
413417
}
418+
Ok(())
414419
}
415420

416421
impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {

compiler/rustc_mir/src/interpret/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
544544
// Early-return cases.
545545
let val_val = match val.val {
546546
ty::ConstKind::Param(_) | ty::ConstKind::Bound(..) => throw_inval!(TooGeneric),
547-
ty::ConstKind::Error(_) => throw_inval!(TypeckError(ErrorReported)),
547+
ty::ConstKind::Error(_) => throw_inval!(AlreadyReported(ErrorReported)),
548548
ty::ConstKind::Unevaluated(def, substs, promoted) => {
549549
let instance = self.resolve(def, substs)?;
550550
return Ok(self.eval_to_allocation(GlobalId { instance, promoted })?.into());

compiler/rustc_mir/src/transform/match_branches.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
6363
};
6464

6565
// Check that destinations are identical, and if not, then don't optimize this block
66-
if &bbs[first].terminator().kind != &bbs[second].terminator().kind {
66+
if bbs[first].terminator().kind != bbs[second].terminator().kind {
6767
continue;
6868
}
6969

compiler/rustc_resolve/src/late/diagnostics.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1886,9 +1886,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
18861886
if snippet.starts_with('&') && !snippet.starts_with("&'") {
18871887
introduce_suggestion
18881888
.push((param.span, format!("&'a {}", &snippet[1..])));
1889-
} else if snippet.starts_with("&'_ ") {
1890-
introduce_suggestion
1891-
.push((param.span, format!("&'a {}", &snippet[4..])));
1889+
} else if let Some(stripped) = snippet.strip_prefix("&'_ ") {
1890+
introduce_suggestion.push((param.span, format!("&'a {}", &stripped)));
18921891
}
18931892
}
18941893
}

compiler/rustc_span/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,7 @@ fn normalize_src(src: &mut String, start_pos: BytePos) -> Vec<NormalizedPos> {
15741574

15751575
/// Removes UTF-8 BOM, if any.
15761576
fn remove_bom(src: &mut String, normalized_pos: &mut Vec<NormalizedPos>) {
1577-
if src.starts_with("\u{feff}") {
1577+
if src.starts_with('\u{feff}') {
15781578
src.drain(..3);
15791579
normalized_pos.push(NormalizedPos { pos: BytePos(0), diff: 3 });
15801580
}

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1388,11 +1388,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
13881388
trait_ref: &ty::PolyTraitRef<'tcx>,
13891389
) {
13901390
let get_trait_impl = |trait_def_id| {
1391-
self.tcx.find_map_relevant_impl(
1392-
trait_def_id,
1393-
trait_ref.skip_binder().self_ty(),
1394-
|impl_def_id| Some(impl_def_id),
1395-
)
1391+
self.tcx.find_map_relevant_impl(trait_def_id, trait_ref.skip_binder().self_ty(), Some)
13961392
};
13971393
let required_trait_path = self.tcx.def_path_str(trait_ref.def_id());
13981394
let all_traits = self.tcx.all_traits(LOCAL_CRATE);

compiler/rustc_trait_selection/src/traits/fulfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
499499
Err(ErrorHandled::TooGeneric) => {
500500
pending_obligation.stalled_on = substs
501501
.iter()
502-
.filter_map(|ty| TyOrConstInferVar::maybe_from_generic_arg(ty))
502+
.filter_map(TyOrConstInferVar::maybe_from_generic_arg)
503503
.collect();
504504
ProcessResult::Unchanged
505505
}

compiler/rustc_typeck/src/check/closure.rs

+1
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
605605
let ret_ty = self.inh.infcx.shallow_resolve(ret_ty);
606606
let ret_vid = match *ret_ty.kind() {
607607
ty::Infer(ty::TyVar(ret_vid)) => ret_vid,
608+
ty::Error(_) => return None,
608609
_ => span_bug!(
609610
self.tcx.def_span(expr_def_id),
610611
"async fn generator return type not an inference variable"

0 commit comments

Comments
 (0)