Skip to content

Commit a673ad6

Browse files
committed
Auto merge of rust-lang#111639 - Nilstrieb:rollup-vg149lm, r=Nilstrieb
Rollup of 10 pull requests Successful merges: - rust-lang#111428 (refactor(resolve): clean up the early error return caused by non-call) - rust-lang#111449 (Recover `impl<T ?Sized>` correctly) - rust-lang#111572 (Document that `missing_copy_implementations` and `missing_debug_implementations` only apply to public items.) - rust-lang#111602 (Suppress "erroneous constant used" for constants tainted by errors) - rust-lang#111605 (fixup version placeholder for `cfi_encoding` feature) - rust-lang#111607 (Add clubby789 to the bootstrap review rotation) - rust-lang#111614 (Add more interesting nonsense to weird-exprs.rs) - rust-lang#111617 (Fixed typo) - rust-lang#111620 (Add eholk back to compiler-contributors reviewers) - rust-lang#111621 (Fix release date of 1.58.1 in release notes.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 72b2716 + 5c0b8f1 commit a673ad6

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

+197
-282
lines changed

RELEASES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ and related tools.
14811481
[is_power_of_two_usize]: https://doc.rust-lang.org/stable/core/num/struct.NonZeroUsize.html#method.is_power_of_two
14821482
[stdarch/1266]: https://github.com./rust-lang/stdarch/pull/1266
14831483

1484-
Version 1.58.1 (2022-01-19)
1484+
Version 1.58.1 (2022-01-20)
14851485
===========================
14861486

14871487
* Fix race condition in `std::fs::remove_dir_all` ([CVE-2022-21658])

compiler/rustc_const_eval/src/const_eval/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ impl<'tcx> ConstEvalErr<'tcx> {
169169
// See <https://github.com./rust-lang/rust/pull/63152>.
170170
let mut err = struct_error(tcx, &self.error.to_string());
171171
self.decorate(&mut err, decorate);
172-
ErrorHandled::Reported(err.emit())
172+
ErrorHandled::Reported(err.emit().into())
173173
}
174174
_ => {
175175
// Report as hard error.
176176
let mut err = struct_error(tcx, message);
177177
err.span_label(self.span, self.error.to_string());
178178
self.decorate(&mut err, decorate);
179-
ErrorHandled::Reported(err.emit())
179+
ErrorHandled::Reported(err.emit().into())
180180
}
181181
}
182182
}

compiler/rustc_const_eval/src/const_eval/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
382382
rustc_span::DUMMY_SP,
383383
"This is likely a const item that is missing from its impl",
384384
);
385-
throw_inval!(AlreadyReported(guar));
385+
throw_inval!(AlreadyReported(guar.into()));
386386
} else {
387387
// `find_mir_or_eval_fn` checks that this is a const fn before even calling us,
388388
// so this should be unreachable.

compiler/rustc_const_eval/src/interpret/eval_context.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use either::{Either, Left, Right};
77
use rustc_hir::{self as hir, def_id::DefId, definitions::DefPathData};
88
use rustc_index::IndexVec;
99
use rustc_middle::mir;
10-
use rustc_middle::mir::interpret::{ErrorHandled, InterpError};
10+
use rustc_middle::mir::interpret::{ErrorHandled, InterpError, ReportedErrorInfo};
1111
use rustc_middle::ty::layout::{
1212
self, FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOf, LayoutOfHelpers,
1313
TyAndLayout,
@@ -470,7 +470,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
470470
};
471471
// do not continue if typeck errors occurred (can only occur in local crate)
472472
if let Some(err) = body.tainted_by_errors {
473-
throw_inval!(AlreadyReported(err));
473+
throw_inval!(AlreadyReported(ReportedErrorInfo::tainted_by_errors(err)));
474474
}
475475
Ok(body)
476476
}
@@ -517,7 +517,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
517517
Ok(None) => throw_inval!(TooGeneric),
518518

519519
// FIXME(eddyb) this could be a bit more specific than `AlreadyReported`.
520-
Err(error_reported) => throw_inval!(AlreadyReported(error_reported)),
520+
Err(error_reported) => throw_inval!(AlreadyReported(error_reported.into())),
521521
}
522522
}
523523

@@ -905,7 +905,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
905905
query(self.tcx.at(span.unwrap_or_else(|| self.cur_span()))).map_err(|err| {
906906
match err {
907907
ErrorHandled::Reported(err) => {
908-
if let Some(span) = span {
908+
if !err.is_tainted_by_errors() && let Some(span) = span {
909909
// To make it easier to figure out where this error comes from, also add a note at the current location.
910910
self.tcx.sess.span_note_without_error(span, "erroneous constant used");
911911
}

compiler/rustc_const_eval/src/interpret/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
595595
// FIXME(generic_const_exprs): `ConstKind::Expr` should be able to be evaluated
596596
ty::ConstKind::Expr(_) => throw_inval!(TooGeneric),
597597
ty::ConstKind::Error(reported) => {
598-
throw_inval!(AlreadyReported(reported))
598+
throw_inval!(AlreadyReported(reported.into()))
599599
}
600600
ty::ConstKind::Unevaluated(uv) => {
601601
let instance = self.resolve(uv.def, uv.substs)?;

compiler/rustc_feature/src/active.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ declare_features! (
338338
/// Allow conditional compilation depending on rust version
339339
(active, cfg_version, "1.45.0", Some(64796), None),
340340
/// Allows to use the `#[cfi_encoding = ""]` attribute.
341-
(active, cfi_encoding, "1.69.0", Some(89653), None),
341+
(active, cfi_encoding, "CURRENT_RUSTC_VERSION", Some(89653), None),
342342
/// Allows `for<...>` on closures and generators.
343343
(active, closure_lifetime_binder, "1.64.0", Some(97362), None),
344344
/// Allows `#[track_caller]` on closures and generators.

compiler/rustc_infer/src/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ impl<'tcx> InferCtxt<'tcx> {
15341534
if let Some(ct) = tcx.thir_abstract_const(unevaluated.def)? {
15351535
let ct = tcx.expand_abstract_consts(ct.subst(tcx, substs));
15361536
if let Err(e) = ct.error_reported() {
1537-
return Err(ErrorHandled::Reported(e));
1537+
return Err(ErrorHandled::Reported(e.into()));
15381538
} else if ct.has_non_region_infer() || ct.has_non_region_param() {
15391539
return Err(ErrorHandled::TooGeneric);
15401540
} else {

compiler/rustc_lint/src/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
611611

612612
declare_lint! {
613613
/// The `missing_copy_implementations` lint detects potentially-forgotten
614-
/// implementations of [`Copy`].
614+
/// implementations of [`Copy`] for public types.
615615
///
616616
/// [`Copy`]: https://doc.rust-lang.org/std/marker/trait.Copy.html
617617
///
@@ -729,7 +729,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
729729

730730
declare_lint! {
731731
/// The `missing_debug_implementations` lint detects missing
732-
/// implementations of [`fmt::Debug`].
732+
/// implementations of [`fmt::Debug`] for public types.
733733
///
734734
/// [`fmt::Debug`]: https://doc.rust-lang.org/std/fmt/trait.Debug.html
735735
///

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

+40-6
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,49 @@ use std::{any::Any, backtrace::Backtrace, fmt};
1515
pub enum ErrorHandled {
1616
/// Already reported an error for this evaluation, and the compilation is
1717
/// *guaranteed* to fail. Warnings/lints *must not* produce `Reported`.
18-
Reported(ErrorGuaranteed),
18+
Reported(ReportedErrorInfo),
1919
/// Don't emit an error, the evaluation failed because the MIR was generic
2020
/// and the substs didn't fully monomorphize it.
2121
TooGeneric,
2222
}
2323

2424
impl From<ErrorGuaranteed> for ErrorHandled {
25-
fn from(err: ErrorGuaranteed) -> ErrorHandled {
26-
ErrorHandled::Reported(err)
25+
#[inline]
26+
fn from(error: ErrorGuaranteed) -> ErrorHandled {
27+
ErrorHandled::Reported(error.into())
28+
}
29+
}
30+
31+
#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
32+
pub struct ReportedErrorInfo {
33+
error: ErrorGuaranteed,
34+
is_tainted_by_errors: bool,
35+
}
36+
37+
impl ReportedErrorInfo {
38+
#[inline]
39+
pub fn tainted_by_errors(error: ErrorGuaranteed) -> ReportedErrorInfo {
40+
ReportedErrorInfo { is_tainted_by_errors: true, error }
41+
}
42+
43+
/// Returns true if evaluation failed because MIR was tainted by errors.
44+
#[inline]
45+
pub fn is_tainted_by_errors(self) -> bool {
46+
self.is_tainted_by_errors
47+
}
48+
}
49+
50+
impl From<ErrorGuaranteed> for ReportedErrorInfo {
51+
#[inline]
52+
fn from(error: ErrorGuaranteed) -> ReportedErrorInfo {
53+
ReportedErrorInfo { is_tainted_by_errors: false, error }
54+
}
55+
}
56+
57+
impl Into<ErrorGuaranteed> for ReportedErrorInfo {
58+
#[inline]
59+
fn into(self) -> ErrorGuaranteed {
60+
self.error
2761
}
2862
}
2963

@@ -89,7 +123,7 @@ fn print_backtrace(backtrace: &Backtrace) {
89123

90124
impl From<ErrorGuaranteed> for InterpErrorInfo<'_> {
91125
fn from(err: ErrorGuaranteed) -> Self {
92-
InterpError::InvalidProgram(InvalidProgramInfo::AlreadyReported(err)).into()
126+
InterpError::InvalidProgram(InvalidProgramInfo::AlreadyReported(err.into())).into()
93127
}
94128
}
95129

@@ -125,7 +159,7 @@ pub enum InvalidProgramInfo<'tcx> {
125159
/// Resolution can fail if we are in a too generic context.
126160
TooGeneric,
127161
/// Abort in case errors are already reported.
128-
AlreadyReported(ErrorGuaranteed),
162+
AlreadyReported(ReportedErrorInfo),
129163
/// An error occurred during layout computation.
130164
Layout(layout::LayoutError<'tcx>),
131165
/// An error occurred during FnAbi computation: the passed --target lacks FFI support
@@ -144,7 +178,7 @@ impl fmt::Display for InvalidProgramInfo<'_> {
144178
use InvalidProgramInfo::*;
145179
match self {
146180
TooGeneric => write!(f, "encountered overly generic constant"),
147-
AlreadyReported(ErrorGuaranteed { .. }) => {
181+
AlreadyReported(_) => {
148182
write!(
149183
f,
150184
"an error has already been reported elsewhere (this should not usually be printed)"

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ use crate::ty::{self, Instance, Ty, TyCtxt};
120120
pub use self::error::{
121121
struct_error, CheckInAllocMsg, ErrorHandled, EvalToAllocationRawResult, EvalToConstValueResult,
122122
EvalToValTreeResult, InterpError, InterpErrorInfo, InterpResult, InvalidProgramInfo,
123-
MachineStopType, ResourceExhaustionInfo, ScalarSizeMismatch, UndefinedBehaviorInfo,
124-
UninitBytesAccess, UnsupportedOpInfo,
123+
MachineStopType, ReportedErrorInfo, ResourceExhaustionInfo, ScalarSizeMismatch,
124+
UndefinedBehaviorInfo, UninitBytesAccess, UnsupportedOpInfo,
125125
};
126126

127127
pub use self::value::{get_slice_bytes, ConstAlloc, ConstValue, Scalar};

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'tcx> TyCtxt<'tcx> {
6161
self.const_eval_global_id(param_env, cid, span)
6262
}
6363
Ok(None) => Err(ErrorHandled::TooGeneric),
64-
Err(error_reported) => Err(ErrorHandled::Reported(error_reported)),
64+
Err(err) => Err(ErrorHandled::Reported(err.into())),
6565
}
6666
}
6767

@@ -110,7 +110,7 @@ impl<'tcx> TyCtxt<'tcx> {
110110
})
111111
}
112112
Ok(None) => Err(ErrorHandled::TooGeneric),
113-
Err(error_reported) => Err(ErrorHandled::Reported(error_reported)),
113+
Err(err) => Err(ErrorHandled::Reported(err.into())),
114114
}
115115
}
116116

compiler/rustc_middle/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2342,7 +2342,7 @@ impl<'tcx> ConstantKind<'tcx> {
23422342
match tcx.const_eval_resolve(param_env, uneval, None) {
23432343
Ok(val) => Self::Val(val, ty),
23442344
Err(ErrorHandled::TooGeneric) => self,
2345-
Err(ErrorHandled::Reported(guar)) => Self::Ty(tcx.const_error(ty, guar)),
2345+
Err(ErrorHandled::Reported(guar)) => Self::Ty(tcx.const_error(ty, guar.into())),
23462346
}
23472347
}
23482348
}

compiler/rustc_middle/src/ty/consts/kind.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl<'tcx> ConstKind<'tcx> {
245245
// can leak through `val` into the const we return.
246246
Ok(val) => Some(Ok(EvalResult::ValTree(val?))),
247247
Err(ErrorHandled::TooGeneric) => None,
248-
Err(ErrorHandled::Reported(e)) => Some(Err(e)),
248+
Err(ErrorHandled::Reported(e)) => Some(Err(e.into())),
249249
}
250250
}
251251
EvalMode::Mir => {
@@ -256,7 +256,7 @@ impl<'tcx> ConstKind<'tcx> {
256256
// can leak through `val` into the const we return.
257257
Ok(val) => Some(Ok(EvalResult::ConstVal(val))),
258258
Err(ErrorHandled::TooGeneric) => None,
259-
Err(ErrorHandled::Reported(e)) => Some(Err(e)),
259+
Err(ErrorHandled::Reported(e)) => Some(Err(e.into())),
260260
}
261261
}
262262
}

compiler/rustc_parse/src/parser/generics.rs

+5
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ impl<'a> Parser<'a> {
453453
// `<` (LIFETIME|IDENT) `:` - generic parameter with bounds
454454
// `<` (LIFETIME|IDENT) `=` - generic parameter with a default
455455
// `<` const - generic const parameter
456+
// `<` IDENT `?` - RECOVERY for `impl<T ?Bound` missing a `:`, meant to
457+
// avoid the `T?` to `Option<T>` recovery for types.
456458
// The only truly ambiguous case is
457459
// `<` IDENT `>` `::` IDENT ...
458460
// we disambiguate it in favor of generics (`impl<T> ::absolute::Path<T> { ... }`)
@@ -463,6 +465,9 @@ impl<'a> Parser<'a> {
463465
|| self.look_ahead(start + 1, |t| t.is_lifetime() || t.is_ident())
464466
&& self.look_ahead(start + 2, |t| {
465467
matches!(t.kind, token::Gt | token::Comma | token::Colon | token::Eq)
468+
// Recovery-only branch -- this could be removed,
469+
// since it only affects diagnostics currently.
470+
|| matches!(t.kind, token::Question)
466471
})
467472
|| self.is_keyword_ahead(start + 1, &[kw::Const]))
468473
}

compiler/rustc_resolve/src/late.rs

-4
Original file line numberDiff line numberDiff line change
@@ -3543,10 +3543,6 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
35433543
//
35443544
// Similar thing, for types, happens in `report_errors` above.
35453545
let report_errors_for_call = |this: &mut Self, parent_err: Spanned<ResolutionError<'a>>| {
3546-
if !source.is_call() {
3547-
return Some(parent_err);
3548-
}
3549-
35503546
// Before we start looking for candidates, we have to get our hands
35513547
// on the type user is trying to perform invocation on; basically:
35523548
// we're transforming `HashMap::new` into just `HashMap`.

compiler/rustc_trait_selection/src/traits/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
801801
span: tcx.def_span(unevaluated.def),
802802
unevaluated: unevaluated,
803803
});
804-
Err(ErrorHandled::Reported(reported))
804+
Err(ErrorHandled::Reported(reported.into()))
805805
}
806806
Err(err) => Err(err),
807807
}

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn is_const_evaluatable<'tcx>(
7979
"Missing value for constant, but no error reported?",
8080
)))
8181
}
82-
Err(ErrorHandled::Reported(e)) => Err(NotConstEvaluatable::Error(e)),
82+
Err(ErrorHandled::Reported(e)) => Err(NotConstEvaluatable::Error(e.into())),
8383
Ok(_) => Ok(()),
8484
}
8585
}
@@ -147,7 +147,7 @@ pub fn is_const_evaluatable<'tcx>(
147147

148148
Err(err)
149149
}
150-
Err(ErrorHandled::Reported(e)) => Err(NotConstEvaluatable::Error(e)),
150+
Err(ErrorHandled::Reported(e)) => Err(NotConstEvaluatable::Error(e.into())),
151151
Ok(_) => Ok(()),
152152
}
153153
}

compiler/rustc_trait_selection/src/traits/fulfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
615615
(Err(ErrorHandled::Reported(reported)), _)
616616
| (_, Err(ErrorHandled::Reported(reported))) => ProcessResult::Error(
617617
CodeSelectionError(SelectionError::NotConstEvaluatable(
618-
NotConstEvaluatable::Error(reported),
618+
NotConstEvaluatable::Error(reported.into()),
619619
)),
620620
),
621621
(Err(ErrorHandled::TooGeneric), _) | (_, Err(ErrorHandled::TooGeneric)) => {

library/alloc/src/collections/btree/map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3021,7 +3021,7 @@ impl<'a, K, V, A> CursorMut<'a, K, V, A> {
30213021
})
30223022
}
30233023

3024-
/// Returns a mutable reference to the of the element that the cursor is
3024+
/// Returns a mutable reference to the key of the element that the cursor is
30253025
/// currently pointing to.
30263026
///
30273027
/// This returns `None` if the cursor is currently pointing to the

src/tools/miri/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ pub fn report_error<'tcx, 'mir>(
289289
(None, format!("see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information")),
290290
],
291291
InvalidProgram(
292-
InvalidProgramInfo::AlreadyReported(rustc_errors::ErrorGuaranteed { .. })
292+
InvalidProgramInfo::AlreadyReported(_)
293293
) => {
294294
// This got already reported. No point in reporting it again.
295295
return None;

src/tools/miri/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ extern crate rustc_ast;
4747
extern crate rustc_middle;
4848
extern crate rustc_const_eval;
4949
extern crate rustc_data_structures;
50-
extern crate rustc_errors;
5150
extern crate rustc_hir;
5251
extern crate rustc_index;
5352
extern crate rustc_session;

0 commit comments

Comments
 (0)