diff --git a/compiler/rustc_const_eval/src/const_eval/error.rs b/compiler/rustc_const_eval/src/const_eval/error.rs index ffeff8d079a..d39a7e8a192 100644 --- a/compiler/rustc_const_eval/src/const_eval/error.rs +++ b/compiler/rustc_const_eval/src/const_eval/error.rs @@ -138,7 +138,10 @@ pub(super) fn report<'tcx, C, F, E>( err_inval!(Layout(LayoutError::Unknown(_))) | err_inval!(TooGeneric) => { ErrorHandled::TooGeneric } - err_inval!(AlreadyReported(error_reported)) => ErrorHandled::Reported(error_reported), + err_inval!(AlreadyReported(guar)) => ErrorHandled::Reported(guar), + err_inval!(Layout(LayoutError::ReferencesError(guar))) => { + ErrorHandled::Reported(guar.into()) + } err_inval!(Layout(layout_error @ LayoutError::SizeOverflow(_))) => { // We must *always* hard error on these, even if the caller wants just a lint. // The `message` makes little sense here, this is a more serious error than the diff --git a/compiler/rustc_hir_typeck/src/intrinsicck.rs b/compiler/rustc_hir_typeck/src/intrinsicck.rs index 2cd18c4c3fc..4e65182f158 100644 --- a/compiler/rustc_hir_typeck/src/intrinsicck.rs +++ b/compiler/rustc_hir_typeck/src/intrinsicck.rs @@ -122,14 +122,9 @@ pub fn check_transmute(&self, from: Ty<'tcx>, to: Ty<'tcx>, hir_id: HirId) { } else { err.note(format!("source type: `{}` ({})", from, skeleton_string(from, sk_from))) .note(format!("target type: `{}` ({})", to, skeleton_string(to, sk_to))); - let mut should_delay_as_bug = false; - if let Err(LayoutError::Unknown(bad_from)) = sk_from && bad_from.references_error() { - should_delay_as_bug = true; - } - if let Err(LayoutError::Unknown(bad_to)) = sk_to && bad_to.references_error() { - should_delay_as_bug = true; - } - if should_delay_as_bug { + if let Err(LayoutError::ReferencesError(_)) = sk_from { + err.delay_as_bug(); + } else if let Err(LayoutError::ReferencesError(_)) = sk_to { err.delay_as_bug(); } } diff --git a/compiler/rustc_middle/messages.ftl b/compiler/rustc_middle/messages.ftl index bb7147ac80f..108a10b506b 100644 --- a/compiler/rustc_middle/messages.ftl +++ b/compiler/rustc_middle/messages.ftl @@ -52,6 +52,9 @@ middle_drop_check_overflow = overflow while adding drop-check rules for {$ty} .note = overflowed on {$overflow_ty} +middle_layout_references_error = + the type has an unknown layout + middle_limit_invalid = `limit` must be a non-negative integer .label = {$error_str} diff --git a/compiler/rustc_middle/src/error.rs b/compiler/rustc_middle/src/error.rs index 57b2de84b47..b346cd45391 100644 --- a/compiler/rustc_middle/src/error.rs +++ b/compiler/rustc_middle/src/error.rs @@ -132,6 +132,9 @@ pub enum LayoutError<'tcx> { #[diag(middle_cycle)] Cycle, + + #[diag(middle_layout_references_error)] + ReferencesError, } #[derive(Diagnostic)] diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 81e7dc3728a..93dabb973e3 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -10,7 +10,7 @@ use rustc_index::IndexVec; use rustc_session::config::OptLevel; use rustc_span::symbol::{sym, Symbol}; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP}; use rustc_target::abi::call::FnAbi; use rustc_target::abi::*; use rustc_target::spec::{abi::Abi as SpecAbi, HasTargetSpec, PanicStrategy, Target}; @@ -212,6 +212,7 @@ pub enum LayoutError<'tcx> { Unknown(Ty<'tcx>), SizeOverflow(Ty<'tcx>), NormalizationFailure(Ty<'tcx>, NormalizationError<'tcx>), + ReferencesError(ErrorGuaranteed), Cycle, } @@ -224,6 +225,7 @@ pub fn diagnostic_message(&self) -> DiagnosticMessage { SizeOverflow(_) => middle_values_too_big, NormalizationFailure(_, _) => middle_cannot_be_normalized, Cycle => middle_cycle, + ReferencesError(_) => middle_layout_references_error, } } @@ -237,6 +239,7 @@ pub fn into_diagnostic(self) -> crate::error::LayoutError<'tcx> { E::NormalizationFailure { ty, failure_ty: e.get_type_for_failure() } } Cycle => E::Cycle, + ReferencesError(_) => E::ReferencesError, } } } @@ -257,6 +260,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { e.get_type_for_failure() ), LayoutError::Cycle => write!(f, "a cycle occurred during layout computation"), + LayoutError::ReferencesError(_) => write!(f, "the type has an unknown layout"), } } } @@ -323,7 +327,8 @@ pub fn compute( Err( e @ LayoutError::Cycle | e @ LayoutError::SizeOverflow(_) - | e @ LayoutError::NormalizationFailure(..), + | e @ LayoutError::NormalizationFailure(..) + | e @ LayoutError::ReferencesError(_), ) => return Err(e), }; diff --git a/compiler/rustc_transmute/src/layout/tree.rs b/compiler/rustc_transmute/src/layout/tree.rs index 8bd26818256..e8ddb0a4396 100644 --- a/compiler/rustc_transmute/src/layout/tree.rs +++ b/compiler/rustc_transmute/src/layout/tree.rs @@ -195,7 +195,7 @@ pub(crate) enum Err { impl<'tcx> From<&LayoutError<'tcx>> for Err { fn from(err: &LayoutError<'tcx>) -> Self { match err { - LayoutError::Unknown(..) => Self::UnknownLayout, + LayoutError::Unknown(..) | LayoutError::ReferencesError(..) => Self::UnknownLayout, err => unimplemented!("{:?}", err), } } diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index b840ff184e0..3500c2cc370 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -96,6 +96,13 @@ fn layout_of_uncached<'tcx>( cx: &LayoutCx<'tcx, TyCtxt<'tcx>>, ty: Ty<'tcx>, ) -> Result, &'tcx LayoutError<'tcx>> { + // Types that reference `ty::Error` pessimistically don't have a meaningful layout. + // The only side-effect of this is possibly worse diagnostics in case the layout + // was actually computable (like if the `ty::Error` showed up only in a `PhantomData`). + if let Err(guar) = ty.error_reported() { + return Err(error(cx, LayoutError::ReferencesError(guar))); + } + let tcx = cx.tcx; let param_env = cx.param_env; let dl = cx.data_layout(); @@ -564,11 +571,15 @@ fn layout_of_uncached<'tcx>( return Err(error(cx, LayoutError::Unknown(ty))); } - ty::Bound(..) | ty::GeneratorWitness(..) | ty::GeneratorWitnessMIR(..) | ty::Infer(_) => { + ty::Bound(..) + | ty::GeneratorWitness(..) + | ty::GeneratorWitnessMIR(..) + | ty::Infer(_) + | ty::Error(_) => { bug!("Layout::compute: unexpected type `{}`", ty) } - ty::Placeholder(..) | ty::Param(_) | ty::Error(_) => { + ty::Placeholder(..) | ty::Param(_) => { return Err(error(cx, LayoutError::Unknown(ty))); } }) diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index ff908ec12ec..29e9423bb43 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -613,8 +613,6 @@ impl BTreeMap { /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -636,8 +634,6 @@ impl BTreeMap { /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -661,8 +657,6 @@ pub fn clear(&mut self) { /// /// # Examples /// - /// Basic usage: - /// /// ``` /// # #![feature(allocator_api)] /// # #![feature(btreemap_alloc)] @@ -688,8 +682,6 @@ impl BTreeMap { /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -744,8 +736,6 @@ pub fn get_key_value(&self, k: &Q) -> Option<(&K, &V)> /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -830,8 +820,6 @@ pub fn pop_first(&mut self) -> Option<(K, V)> /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -917,8 +905,6 @@ pub fn pop_last(&mut self) -> Option<(K, V)> /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -943,8 +929,6 @@ pub fn contains_key(&self, key: &Q) -> bool /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -982,8 +966,6 @@ pub fn get_mut(&mut self, key: &Q) -> Option<&mut V> /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -1017,8 +999,6 @@ pub fn insert(&mut self, key: K, value: V) -> Option /// /// # Examples /// - /// Basic usage: - /// /// ``` /// #![feature(map_try_insert)] /// @@ -1051,8 +1031,6 @@ pub fn try_insert(&mut self, key: K, value: V) -> Result<&mut V, OccupiedError<' /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -1078,8 +1056,6 @@ pub fn remove(&mut self, key: &Q) -> Option /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -1208,8 +1184,6 @@ pub fn append(&mut self, other: &mut Self) /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// use std::ops::Bound::Included; @@ -1251,8 +1225,6 @@ pub fn range(&self, range: R) -> Range<'_, K, V> /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -1283,8 +1255,6 @@ pub fn range_mut(&mut self, range: R) -> RangeMut<'_, K, V> /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -1336,8 +1306,6 @@ pub fn entry(&mut self, key: K) -> Entry<'_, K, V, A> /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -2388,8 +2356,6 @@ impl BTreeMap { /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -2420,8 +2386,6 @@ pub fn iter(&self) -> Iter<'_, K, V> { /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -2453,8 +2417,6 @@ pub fn iter_mut(&mut self) -> IterMut<'_, K, V> { /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -2474,8 +2436,6 @@ pub fn keys(&self) -> Keys<'_, K, V> { /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -2495,8 +2455,6 @@ pub fn values(&self) -> Values<'_, K, V> { /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -2521,8 +2479,6 @@ pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> { /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -2546,8 +2502,6 @@ pub const fn len(&self) -> usize { /// /// # Examples /// - /// Basic usage: - /// /// ``` /// use std::collections::BTreeMap; /// @@ -2578,8 +2532,6 @@ pub const fn is_empty(&self) -> bool { /// /// # Examples /// - /// Basic usage: - /// /// ``` /// #![feature(btree_cursors)] /// @@ -2619,8 +2571,6 @@ pub fn lower_bound(&self, bound: Bound<&Q>) -> Cursor<'_, K, V> /// /// # Examples /// - /// Basic usage: - /// /// ``` /// #![feature(btree_cursors)] /// @@ -2673,8 +2623,6 @@ pub fn lower_bound_mut(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V, A> /// /// # Examples /// - /// Basic usage: - /// /// ``` /// #![feature(btree_cursors)] /// @@ -2714,8 +2662,6 @@ pub fn upper_bound(&self, bound: Bound<&Q>) -> Cursor<'_, K, V> /// /// # Examples /// - /// Basic usage: - /// /// ``` /// #![feature(btree_cursors)] /// diff --git a/library/core/src/borrow.rs b/library/core/src/borrow.rs index efc9ada3891..bc026d0a446 100644 --- a/library/core/src/borrow.rs +++ b/library/core/src/borrow.rs @@ -22,7 +22,7 @@ /// Types express that they can be borrowed as some type `T` by implementing /// `Borrow`, providing a reference to a `T` in the trait’s /// [`borrow`] method. A type is free to borrow as several different types. -/// If it wishes to mutably borrow as the type – allowing the underlying data +/// If it wishes to mutably borrow as the type, allowing the underlying data /// to be modified, it can additionally implement [`BorrowMut`]. /// /// Further, when providing implementations for additional traits, it needs diff --git a/library/std/tests/process_spawning.rs b/library/std/tests/process_spawning.rs index 52e5b55fb9d..46dc9ff00bd 100644 --- a/library/std/tests/process_spawning.rs +++ b/library/std/tests/process_spawning.rs @@ -1,3 +1,5 @@ +#![cfg(not(target_env="sgx"))] + use std::env; use std::fs; use std::process; diff --git a/library/std/tests/switch-stdout.rs b/library/std/tests/switch-stdout.rs index 28ce6dfccd3..2605664d289 100644 --- a/library/std/tests/switch-stdout.rs +++ b/library/std/tests/switch-stdout.rs @@ -1,4 +1,4 @@ -#[cfg(any(target_family = "unix", target_family = "windows"))] +#![cfg(any(target_family = "unix", target_family = "windows"))] use std::fs::File; use std::io::{Read, Write}; diff --git a/src/librustdoc/html/templates/type_layout.html b/src/librustdoc/html/templates/type_layout.html index 20e09a54805..287cbab07d2 100644 --- a/src/librustdoc/html/templates/type_layout.html +++ b/src/librustdoc/html/templates/type_layout.html @@ -44,6 +44,11 @@ Note: Encountered an error during type layout; {#+ #} the type was too big. {# #}

{# #} + {% when Err(LayoutError::ReferencesError(_)) %} +

{# #} + Note: Encountered an error during type layout; {#+ #} + the type references errors. {# #} +

{# #} {% when Err(LayoutError::NormalizationFailure(_, _)) %}

{# #} Note: Encountered an error during type layout; {#+ #} diff --git a/tests/ui/layout/malformed-unsized-type-in-union.rs b/tests/ui/layout/malformed-unsized-type-in-union.rs new file mode 100644 index 00000000000..5d8ec576cf0 --- /dev/null +++ b/tests/ui/layout/malformed-unsized-type-in-union.rs @@ -0,0 +1,8 @@ +// issue: 113760 + +union W { s: dyn Iterator } +//~^ ERROR cannot find type `Missing` in this scope + +static ONCE: W = todo!(); + +fn main() {} diff --git a/tests/ui/layout/malformed-unsized-type-in-union.stderr b/tests/ui/layout/malformed-unsized-type-in-union.stderr new file mode 100644 index 00000000000..cbb8d6af38a --- /dev/null +++ b/tests/ui/layout/malformed-unsized-type-in-union.stderr @@ -0,0 +1,9 @@ +error[E0412]: cannot find type `Missing` in this scope + --> $DIR/malformed-unsized-type-in-union.rs:3:34 + | +LL | union W { s: dyn Iterator } + | ^^^^^^^ not found in this scope + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/proc-macro/derive-helper-shadowed.rs b/tests/ui/proc-macro/derive-helper-shadowed.rs index e299454e0fc..ac14ece6918 100644 --- a/tests/ui/proc-macro/derive-helper-shadowed.rs +++ b/tests/ui/proc-macro/derive-helper-shadowed.rs @@ -1,4 +1,4 @@ -// build-pass (FIXME(62277): could be check-pass?) +// check-pass // aux-build:test-macros.rs // aux-build:derive-helper-shadowed-2.rs diff --git a/tests/ui/proc-macro/derive-in-mod.rs b/tests/ui/proc-macro/derive-in-mod.rs index 8b5d4e9d09c..96e9d93fe12 100644 --- a/tests/ui/proc-macro/derive-in-mod.rs +++ b/tests/ui/proc-macro/derive-in-mod.rs @@ -1,4 +1,4 @@ -// build-pass (FIXME(62277): could be check-pass?) +// check-pass // aux-build:test-macros.rs extern crate test_macros; diff --git a/tests/ui/proc-macro/edition-imports-2018.rs b/tests/ui/proc-macro/edition-imports-2018.rs index 5a77cd4ef4f..76567353198 100644 --- a/tests/ui/proc-macro/edition-imports-2018.rs +++ b/tests/ui/proc-macro/edition-imports-2018.rs @@ -1,4 +1,4 @@ -// build-pass (FIXME(62277): could be check-pass?) +// check-pass // edition:2018 // aux-build:edition-imports-2015.rs diff --git a/tests/ui/proc-macro/extern-prelude-extern-crate-proc-macro.rs b/tests/ui/proc-macro/extern-prelude-extern-crate-proc-macro.rs index a6e64e1b1b1..38f61c36c8c 100644 --- a/tests/ui/proc-macro/extern-prelude-extern-crate-proc-macro.rs +++ b/tests/ui/proc-macro/extern-prelude-extern-crate-proc-macro.rs @@ -1,4 +1,4 @@ -// build-pass (FIXME(62277): could be check-pass?) +// check-pass // edition:2018 extern crate proc_macro; diff --git a/tests/ui/proc-macro/helper-attr-blocked-by-import.rs b/tests/ui/proc-macro/helper-attr-blocked-by-import.rs index 2e20a3de6bf..344323122dc 100644 --- a/tests/ui/proc-macro/helper-attr-blocked-by-import.rs +++ b/tests/ui/proc-macro/helper-attr-blocked-by-import.rs @@ -1,4 +1,4 @@ -// build-pass (FIXME(62277): could be check-pass?) +// check-pass // aux-build:test-macros.rs #[macro_use(Empty)] diff --git a/tests/ui/proc-macro/issue-53481.rs b/tests/ui/proc-macro/issue-53481.rs index ae10a3baa3e..922e60a4c4f 100644 --- a/tests/ui/proc-macro/issue-53481.rs +++ b/tests/ui/proc-macro/issue-53481.rs @@ -1,4 +1,4 @@ -// build-pass (FIXME(62277): could be check-pass?) +// check-pass // aux-build:test-macros.rs #[macro_use] diff --git a/tests/ui/proc-macro/macro-use-attr.rs b/tests/ui/proc-macro/macro-use-attr.rs index b101c09ed54..d275fb6a804 100644 --- a/tests/ui/proc-macro/macro-use-attr.rs +++ b/tests/ui/proc-macro/macro-use-attr.rs @@ -1,4 +1,4 @@ -// build-pass (FIXME(62277): could be check-pass?) +// check-pass // aux-build:test-macros.rs #[macro_use] diff --git a/tests/ui/proc-macro/macro-use-bang.rs b/tests/ui/proc-macro/macro-use-bang.rs index 4a0bf0b2f63..e3174fd446a 100644 --- a/tests/ui/proc-macro/macro-use-bang.rs +++ b/tests/ui/proc-macro/macro-use-bang.rs @@ -1,4 +1,4 @@ -// build-pass (FIXME(62277): could be check-pass?) +// check-pass // aux-build:test-macros.rs #[macro_use] diff --git a/triagebot.toml b/triagebot.toml index c947c3f1930..a180577a834 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -490,6 +490,7 @@ cc = ["@nnethercote"] [assign] warn_non_default_branch = true contributing_url = "https://rustc-dev-guide.rust-lang.org/getting-started.html" +users_on_vacation = ["jyn514"] [assign.adhoc_groups] compiler-team = [