diff --git a/src/libcore/iter/adapters/mod.rs b/src/libcore/iter/adapters/mod.rs index af46e6df2942b..b270290295693 100644 --- a/src/libcore/iter/adapters/mod.rs +++ b/src/libcore/iter/adapters/mod.rs @@ -2180,137 +2180,65 @@ impl ExactSizeIterator for Inspect impl FusedIterator for Inspect where F: FnMut(&I::Item) {} -/// An iterator adapter that produces output as long as the underlying -/// iterator produces `Option::Some` values. -pub(crate) struct OptionShunt { - iter: I, - exited_early: bool, -} - -impl OptionShunt -where - I: Iterator>, -{ - /// Process the given iterator as if it yielded a `T` instead of a - /// `Option`. Any `None` value will stop the inner iterator and - /// the overall result will be a `None`. - pub fn process(iter: I, mut f: F) -> Option - where - F: FnMut(&mut Self) -> U, - { - let mut shunt = OptionShunt::new(iter); - let value = f(shunt.by_ref()); - shunt.reconstruct(value) - } - - fn new(iter: I) -> Self { - OptionShunt { - iter, - exited_early: false, - } - } - - /// Consume the adapter and rebuild a `Option` value. - fn reconstruct(self, val: U) -> Option { - if self.exited_early { - None - } else { - Some(val) - } - } -} - -impl Iterator for OptionShunt -where - I: Iterator>, -{ - type Item = T; - - fn next(&mut self) -> Option { - match self.iter.next() { - Some(Some(v)) => Some(v), - Some(None) => { - self.exited_early = true; - None - } - None => None, - } - } - - fn size_hint(&self) -> (usize, Option) { - if self.exited_early { - (0, Some(0)) - } else { - let (_, upper) = self.iter.size_hint(); - (0, upper) - } - } -} - /// An iterator adapter that produces output as long as the underlying /// iterator produces `Result::Ok` values. /// /// If an error is encountered, the iterator stops and the error is -/// stored. The error may be recovered later via `reconstruct`. -pub(crate) struct ResultShunt { +/// stored. +pub(crate) struct ResultShunt<'a, I, E> { iter: I, - error: Option, + error: &'a mut Result<(), E>, } -impl ResultShunt - where I: Iterator> +/// Process the given iterator as if it yielded a `T` instead of a +/// `Result`. Any errors will stop the inner iterator and +/// the overall result will be an error. +pub(crate) fn process_results(iter: I, mut f: F) -> Result +where + I: Iterator>, + for<'a> F: FnMut(ResultShunt<'a, I, E>) -> U, { - /// Process the given iterator as if it yielded a `T` instead of a - /// `Result`. Any errors will stop the inner iterator and - /// the overall result will be an error. - pub fn process(iter: I, mut f: F) -> Result - where F: FnMut(&mut Self) -> U - { - let mut shunt = ResultShunt::new(iter); - let value = f(shunt.by_ref()); - shunt.reconstruct(value) - } - - fn new(iter: I) -> Self { - ResultShunt { - iter, - error: None, - } - } - - /// Consume the adapter and rebuild a `Result` value. This should - /// *always* be called, otherwise any potential error would be - /// lost. - fn reconstruct(self, val: U) -> Result { - match self.error { - None => Ok(val), - Some(e) => Err(e), - } - } + let mut error = Ok(()); + let shunt = ResultShunt { + iter, + error: &mut error, + }; + let value = f(shunt); + error.map(|()| value) } -impl Iterator for ResultShunt +impl Iterator for ResultShunt<'_, I, E> where I: Iterator> { type Item = T; fn next(&mut self) -> Option { - match self.iter.next() { - Some(Ok(v)) => Some(v), - Some(Err(e)) => { - self.error = Some(e); - None - } - None => None, - } + self.find(|_| true) } fn size_hint(&self) -> (usize, Option) { - if self.error.is_some() { + if self.error.is_err() { (0, Some(0)) } else { let (_, upper) = self.iter.size_hint(); (0, upper) } } + + fn try_fold(&mut self, init: B, mut f: F) -> R + where + F: FnMut(B, Self::Item) -> R, + R: Try, + { + let error = &mut *self.error; + self.iter + .try_fold(init, |acc, x| match x { + Ok(x) => LoopState::from_try(f(acc, x)), + Err(e) => { + *error = Err(e); + LoopState::Break(Try::from_ok(acc)) + } + }) + .into_try() + } } diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index 4a7d7f96b9b04..aba8e84d58be5 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -360,7 +360,7 @@ pub use self::adapters::Flatten; #[stable(feature = "iter_copied", since = "1.36.0")] pub use self::adapters::Copied; -pub(crate) use self::adapters::{TrustedRandomAccess, OptionShunt, ResultShunt}; +pub(crate) use self::adapters::{TrustedRandomAccess, process_results}; mod range; mod sources; diff --git a/src/libcore/iter/traits/accum.rs b/src/libcore/iter/traits/accum.rs index 01b64fb08acf7..812463e77f976 100644 --- a/src/libcore/iter/traits/accum.rs +++ b/src/libcore/iter/traits/accum.rs @@ -1,6 +1,6 @@ use crate::ops::{Mul, Add}; use crate::num::Wrapping; -use crate::iter::adapters::{OptionShunt, ResultShunt}; +use crate::iter; /// Trait to represent types that can be created by summing up an iterator. /// @@ -139,7 +139,7 @@ impl Sum> for Result fn sum(iter: I) -> Result where I: Iterator>, { - ResultShunt::process(iter, |i| i.sum()) + iter::process_results(iter, |i| i.sum()) } } @@ -153,7 +153,7 @@ impl Product> for Result fn product(iter: I) -> Result where I: Iterator>, { - ResultShunt::process(iter, |i| i.product()) + iter::process_results(iter, |i| i.product()) } } @@ -180,7 +180,7 @@ where where I: Iterator>, { - OptionShunt::process(iter, |i| i.sum()) + iter.map(|x| x.ok_or(())).sum::>().ok() } } @@ -196,6 +196,6 @@ where where I: Iterator>, { - OptionShunt::process(iter, |i| i.product()) + iter.map(|x| x.ok_or(())).product::>().ok() } } diff --git a/src/libcore/mem/maybe_uninit.rs b/src/libcore/mem/maybe_uninit.rs index 64fdf504369f2..ff063759cba62 100644 --- a/src/libcore/mem/maybe_uninit.rs +++ b/src/libcore/mem/maybe_uninit.rs @@ -51,7 +51,8 @@ use crate::mem::ManuallyDrop; /// /// On top of that, remember that most types have additional invariants beyond merely /// being considered initialized at the type level. For example, a `1`-initialized [`Vec`] -/// is considered initialized because the only requirement the compiler knows about it +/// is considered initialized (under the current implementation; this does not constitute +/// a stable guarantee) because the only requirement the compiler knows about it /// is that the data pointer must be non-null. Creating such a `Vec` does not cause /// *immediate* undefined behavior, but will cause undefined behavior with most /// safe operations (including dropping it). @@ -402,6 +403,14 @@ impl MaybeUninit { /// /// [inv]: #initialization-invariant /// + /// On top of that, remember that most types have additional invariants beyond merely + /// being considered initialized at the type level. For example, a `1`-initialized [`Vec`] + /// is considered initialized (under the current implementation; this does not constitute + /// a stable guarantee) because the only requirement the compiler knows about it + /// is that the data pointer must be non-null. Creating such a `Vec` does not cause + /// *immediate* undefined behavior, but will cause undefined behavior with most + /// safe operations (including dropping it). + /// /// # Examples /// /// Correct usage of this method: diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 7713e5761d4bd..259ed36c57885 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -135,7 +135,7 @@ #![stable(feature = "rust1", since = "1.0.0")] -use crate::iter::{FromIterator, FusedIterator, TrustedLen, OptionShunt}; +use crate::iter::{FromIterator, FusedIterator, TrustedLen}; use crate::{convert, fmt, hint, mem, ops::{self, Deref, DerefMut}}; use crate::pin::Pin; @@ -1499,7 +1499,10 @@ impl> FromIterator> for Option { // FIXME(#11084): This could be replaced with Iterator::scan when this // performance bug is closed. - OptionShunt::process(iter.into_iter(), |i| i.collect()) + iter.into_iter() + .map(|x| x.ok_or(())) + .collect::>() + .ok() } } diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 559877ddd5a1c..8c60a9c1b501d 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -231,7 +231,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use crate::fmt; -use crate::iter::{FromIterator, FusedIterator, TrustedLen, ResultShunt}; +use crate::iter::{self, FromIterator, FusedIterator, TrustedLen}; use crate::ops::{self, Deref, DerefMut}; /// `Result` is a type that represents either success ([`Ok`]) or failure ([`Err`]). @@ -1343,7 +1343,7 @@ impl> FromIterator> for Result { // FIXME(#11084): This could be replaced with Iterator::scan when this // performance bug is closed. - ResultShunt::process(iter.into_iter(), |i| i.collect()) + iter::process_results(iter.into_iter(), |i| i.collect()) } } diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index e27e160560714..3615fab791505 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -1203,6 +1203,23 @@ fn test_iterator_sum_result() { assert_eq!(v.iter().cloned().sum::>(), Ok(10)); let v: &[Result] = &[Ok(1), Err(()), Ok(3), Ok(4)]; assert_eq!(v.iter().cloned().sum::>(), Err(())); + + #[derive(PartialEq, Debug)] + struct S(Result); + + impl Sum> for S { + fn sum>>(mut iter: I) -> Self { + // takes the sum by repeatedly calling `next` on `iter`, + // thus testing that repeated calls to `ResultShunt::try_fold` + // produce the expected results + Self(iter.by_ref().sum()) + } + } + + let v: &[Result] = &[Ok(1), Ok(2), Ok(3), Ok(4)]; + assert_eq!(v.iter().cloned().sum::(), S(Ok(10))); + let v: &[Result] = &[Ok(1), Err(()), Ok(3), Ok(4)]; + assert_eq!(v.iter().cloned().sum::(), S(Err(()))); } #[test] diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index aa36b55ae376e..f53d2ffb6df54 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -137,17 +137,17 @@ impl<'tcx> ConstEvalErr<'tcx> { message: &str, lint_root: Option, ) -> Result, ErrorHandled> { - match self.error { + let must_error = match self.error { err_inval!(Layout(LayoutError::Unknown(_))) | err_inval!(TooGeneric) => return Err(ErrorHandled::TooGeneric), - err_inval!(Layout(LayoutError::SizeOverflow(_))) | err_inval!(TypeckError) => return Err(ErrorHandled::Reported), - _ => {}, - } + err_inval!(Layout(LayoutError::SizeOverflow(_))) => true, + _ => false, + }; trace!("reporting const eval failure at {:?}", self.span); - let mut err = if let Some(lint_root) = lint_root { + let mut err = if let (Some(lint_root), false) = (lint_root, must_error) { let hir_id = self.stacktrace .iter() .rev() @@ -160,10 +160,14 @@ impl<'tcx> ConstEvalErr<'tcx> { tcx.span, message, ) + } else if must_error { + struct_error(tcx, &self.error.to_string()) } else { struct_error(tcx, message) }; - err.span_label(self.span, self.error.to_string()); + if !must_error { + err.span_label(self.span, self.error.to_string()); + } // Skip the last, which is just the environment of the constant. The stacktrace // is sometimes empty because we create "fake" eval contexts in CTFE to do work // on constant values. @@ -335,7 +339,7 @@ impl fmt::Debug for InvalidProgramInfo<'tcx> { TypeckError => write!(f, "encountered constants with type errors, stopping evaluation"), Layout(ref err) => - write!(f, "rustc layout computation failed: {:?}", err), + write!(f, "{}", err), } } } diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index 2b68eb53a4ab9..a2aaaddf0931c 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -30,6 +30,7 @@ use std::iter; use std::str; use std::sync::Arc; use syntax::symbol::LocalInternedString; +use syntax::source_map::{DUMMY_SP, Span}; use crate::abi::Abi; /// There is one `CodegenCx` per compilation unit. Each one has its own LLVM @@ -860,9 +861,13 @@ impl LayoutOf for CodegenCx<'ll, 'tcx> { type TyLayout = TyLayout<'tcx>; fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { + self.spanned_layout_of(ty, DUMMY_SP) + } + + fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Span) -> Self::TyLayout { self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)) .unwrap_or_else(|e| if let LayoutError::SizeOverflow(_) = e { - self.sess().fatal(&e.to_string()) + self.sess().span_fatal(span, &e.to_string()) } else { bug!("failed to get layout for `{}`: {}", ty, e) }) diff --git a/src/librustc_codegen_ssa/mir/analyze.rs b/src/librustc_codegen_ssa/mir/analyze.rs index 907689541f978..cc0c733c22410 100644 --- a/src/librustc_codegen_ssa/mir/analyze.rs +++ b/src/librustc_codegen_ssa/mir/analyze.rs @@ -9,6 +9,7 @@ use rustc::mir::visit::{Visitor, PlaceContext, MutatingUseContext, NonMutatingUs use rustc::mir::traversal; use rustc::ty; use rustc::ty::layout::{LayoutOf, HasTyCtxt}; +use syntax_pos::DUMMY_SP; use super::FunctionCx; use crate::traits::*; @@ -20,10 +21,13 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( analyzer.visit_body(mir); - for (index, ty) in mir.local_decls.iter().map(|l| l.ty).enumerate() { + for (index, (ty, span)) in mir.local_decls.iter() + .map(|l| (l.ty, l.source_info.span)) + .enumerate() + { let ty = fx.monomorphize(&ty); debug!("local {} has type {:?}", index, ty); - let layout = fx.cx.layout_of(ty); + let layout = fx.cx.spanned_layout_of(ty, span); if fx.cx.is_backend_immediate(layout) { // These sorts of types are immediates that we can store // in an Value without an alloca. @@ -93,10 +97,12 @@ impl> LocalAnalyzer<'mir, 'a, 'tcx, Bx> { } } - fn process_place(&mut self, - place_ref: &mir::PlaceRef<'_, 'tcx>, - context: PlaceContext, - location: Location) { + fn process_place( + &mut self, + place_ref: &mir::PlaceRef<'_, 'tcx>, + context: PlaceContext, + location: Location, + ) { let cx = self.fx.cx; if let Some(proj) = place_ref.projection { @@ -116,12 +122,17 @@ impl> LocalAnalyzer<'mir, 'a, 'tcx, Bx> { .projection_ty(cx.tcx(), &proj.elem) .ty; let elem_ty = self.fx.monomorphize(&elem_ty); - if cx.layout_of(elem_ty).is_zst() { + let span = if let mir::PlaceBase::Local(index) = place_ref.base { + self.fx.mir.local_decls[*index].source_info.span + } else { + DUMMY_SP + }; + if cx.spanned_layout_of(elem_ty, span).is_zst() { return; } if let mir::ProjectionElem::Field(..) = proj.elem { - let layout = cx.layout_of(base_ty.ty); + let layout = cx.spanned_layout_of(base_ty.ty, span); if cx.is_backend_immediate(layout) || cx.is_backend_scalar_pair(layout) { // Recurse with the same context, instead of `Projection`, // potentially stopping at non-operand projections, @@ -188,7 +199,8 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx> projection: None, } = *place { self.assign(index, location); - if !self.fx.rvalue_creates_operand(rvalue) { + let decl_span = self.fx.mir.local_decls[index].source_info.span; + if !self.fx.rvalue_creates_operand(rvalue, decl_span) { self.not_ssa(index); } } else { diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs index 21cedb7a9b394..9da1e5024ba3a 100644 --- a/src/librustc_codegen_ssa/mir/rvalue.rs +++ b/src/librustc_codegen_ssa/mir/rvalue.rs @@ -6,6 +6,7 @@ use rustc::middle::lang_items::ExchangeMallocFnLangItem; use rustc_apfloat::{ieee, Float, Status, Round}; use std::{u128, i128}; use syntax::symbol::sym; +use syntax::source_map::{DUMMY_SP, Span}; use crate::base; use crate::MemFlags; @@ -136,7 +137,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } _ => { - assert!(self.rvalue_creates_operand(rvalue)); + assert!(self.rvalue_creates_operand(rvalue, DUMMY_SP)); let (mut bx, temp) = self.codegen_rvalue_operand(bx, rvalue); temp.val.store(&mut bx, dest); bx @@ -169,7 +170,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mut bx: Bx, rvalue: &mir::Rvalue<'tcx> ) -> (Bx, OperandRef<'tcx, Bx::Value>) { - assert!(self.rvalue_creates_operand(rvalue), "cannot codegen {:?} to operand", rvalue); + assert!( + self.rvalue_creates_operand(rvalue, DUMMY_SP), + "cannot codegen {:?} to operand", + rvalue, + ); match *rvalue { mir::Rvalue::Cast(ref kind, ref source, mir_cast_ty) => { @@ -691,7 +696,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { - pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>) -> bool { + pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>, span: Span) -> bool { match *rvalue { mir::Rvalue::Ref(..) | mir::Rvalue::Len(..) | @@ -707,7 +712,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mir::Rvalue::Aggregate(..) => { let ty = rvalue.ty(self.mir, self.cx.tcx()); let ty = self.monomorphize(&ty); - self.cx.layout_of(ty).is_zst() + self.cx.spanned_layout_of(ty, span).is_zst() } } diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index f10d7fb965116..1f23d8c017ccd 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -506,7 +506,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { pub fn push_stack_frame( &mut self, instance: ty::Instance<'tcx>, - span: source_map::Span, + span: Span, body: &'mir mir::Body<'tcx>, return_place: Option>, return_to_block: StackPopCleanup, diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 1908d85e4ff2a..2c56f5fb4523a 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1771,8 +1771,13 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> { path: &ast::Path, is_value: bool, ) -> Res { - self.resolve_ast_path_cb(path, is_value, - |resolver, span, error| resolve_error(resolver, span, error)) + match self.resolve_ast_path_inner(path, is_value) { + Ok(r) => r, + Err((span, error)) => { + resolve_error(self, span, error); + Res::Err + } + } } fn resolve_str_path( @@ -1833,8 +1838,6 @@ impl<'a> Resolver<'a> { /// just that an error occurred. pub fn resolve_str_path_error(&mut self, span: Span, path_str: &str, is_value: bool) -> Result<(ast::Path, Res), ()> { - let mut errored = false; - let path = if path_str.starts_with("::") { ast::Path { span, @@ -1855,24 +1858,16 @@ impl<'a> Resolver<'a> { .collect(), } }; - let res = self.resolve_ast_path_cb(&path, is_value, |_, _, _| errored = true); - if errored || res == def::Res::Err { - Err(()) - } else { - Ok((path, res)) - } + let res = self.resolve_ast_path_inner(&path, is_value).map_err(|_| ())?; + Ok((path, res)) } /// Like `resolve_ast_path`, but takes a callback in case there was an error. - // FIXME(eddyb) use `Result` or something instead of callbacks. - fn resolve_ast_path_cb( + fn resolve_ast_path_inner( &mut self, path: &ast::Path, is_value: bool, - error_callback: F, - ) -> Res - where F: for<'c, 'b> FnOnce(&'c mut Resolver<'_>, Span, ResolutionError<'b>) - { + ) -> Result)> { let namespace = if is_value { ValueNS } else { TypeNS }; let span = path.span; let path = Segment::from_path(&path); @@ -1880,23 +1875,21 @@ impl<'a> Resolver<'a> { match self.resolve_path_without_parent_scope(&path, Some(namespace), true, span, CrateLint::No) { PathResult::Module(ModuleOrUniformRoot::Module(module)) => - module.res().unwrap(), + Ok(module.res().unwrap()), PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => - path_res.base_res(), + Ok(path_res.base_res()), PathResult::NonModule(..) => { - error_callback(self, span, ResolutionError::FailedToResolve { + Err((span, ResolutionError::FailedToResolve { label: String::from("type-relative paths are not supported in this context"), suggestion: None, - }); - Res::Err + })) } PathResult::Module(..) | PathResult::Indeterminate => unreachable!(), PathResult::Failed { span, label, suggestion, .. } => { - error_callback(self, span, ResolutionError::FailedToResolve { + Err((span, ResolutionError::FailedToResolve { label, suggestion, - }); - Res::Err + })) } } } diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs index 80fcb45d0b9bc..dd7ae742a63c6 100644 --- a/src/librustc_target/abi/mod.rs +++ b/src/librustc_target/abi/mod.rs @@ -9,6 +9,7 @@ use std::ops::{Add, Deref, Sub, Mul, AddAssign, Range, RangeInclusive}; use rustc_data_structures::newtype_index; use rustc_data_structures::indexed_vec::{Idx, IndexVec}; use syntax_pos::symbol::{sym, Symbol}; +use syntax_pos::Span; pub mod call; @@ -1012,6 +1013,9 @@ pub trait LayoutOf { type TyLayout; fn layout_of(&self, ty: Self::Ty) -> Self::TyLayout; + fn spanned_layout_of(&self, ty: Self::Ty, _span: Span) -> Self::TyLayout { + self.layout_of(ty) + } } #[derive(Copy, Clone, PartialEq, Eq)] diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 2774f2b4751ba..8d264caf1c453 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -877,15 +877,23 @@ fn write_shared( r#"var themes = document.getElementById("theme-choices"); var themePicker = document.getElementById("theme-picker"); +function showThemeButtonState() {{ + themes.style.display = "none"; + themePicker.style.borderBottomRightRadius = "3px"; + themePicker.style.borderBottomLeftRadius = "3px"; +}} + +function hideThemeButtonState() {{ + themes.style.display = "block"; + themePicker.style.borderBottomRightRadius = "0"; + themePicker.style.borderBottomLeftRadius = "0"; +}} + function switchThemeButtonState() {{ if (themes.style.display === "block") {{ - themes.style.display = "none"; - themePicker.style.borderBottomRightRadius = "3px"; - themePicker.style.borderBottomLeftRadius = "3px"; + showThemeButtonState(); }} else {{ - themes.style.display = "block"; - themePicker.style.borderBottomRightRadius = "0"; - themePicker.style.borderBottomLeftRadius = "0"; + hideThemeButtonState(); }} }}; @@ -898,7 +906,7 @@ function handleThemeButtonsBlur(e) {{ (!related || (related.id !== "themePicker" && (!related.parentNode || related.parentNode.id !== "theme-choices")))) {{ - switchThemeButtonState(); + hideThemeButtonState(); }} }} diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 04de3374d0587..84cfdd790b733 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -71,6 +71,10 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { resolver.resolve_str_path_error(DUMMY_SP, &path_str, ns == ValueNS) }) }); + let result = match result { + Ok((_, Res::Err)) => Err(()), + _ => result, + }; if let Ok((_, res)) = result { let res = res.map_id(|_| panic!("unexpected node_id")); @@ -134,6 +138,9 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { let (_, ty_res) = cx.enter_resolver(|resolver| resolver.with_scope(node_id, |resolver| { resolver.resolve_str_path_error(DUMMY_SP, &path, false) }))?; + if let Res::Err = ty_res { + return Err(()); + } let ty_res = ty_res.map_id(|_| panic!("unexpected node_id")); match ty_res { Res::Def(DefKind::Struct, did) diff --git a/src/test/ui/consts/issue-55878.rs b/src/test/ui/consts/issue-55878.rs new file mode 100644 index 0000000000000..aa1dd58d2463d --- /dev/null +++ b/src/test/ui/consts/issue-55878.rs @@ -0,0 +1,7 @@ +// normalize-stderr-64bit "18446744073709551615" -> "SIZE" +// normalize-stderr-32bit "4294967295" -> "SIZE" + +// error-pattern: is too big for the current architecture +fn main() { + println!("Size: {}", std::mem::size_of::<[u8; std::u64::MAX as usize]>()); +} diff --git a/src/test/ui/consts/issue-55878.stderr b/src/test/ui/consts/issue-55878.stderr new file mode 100644 index 0000000000000..4332c7f19dc11 --- /dev/null +++ b/src/test/ui/consts/issue-55878.stderr @@ -0,0 +1,14 @@ +error[E0080]: the type `[u8; SIZE]` is too big for the current architecture + --> $SRC_DIR/libcore/mem/mod.rs:LL:COL + | +LL | intrinsics::size_of::() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + ::: $DIR/issue-55878.rs:6:26 + | +LL | println!("Size: {}", std::mem::size_of::<[u8; std::u64::MAX as usize]>()); + | --------------------------------------------------- + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/huge-array-simple-32.rs b/src/test/ui/huge-array-simple-32.rs new file mode 100644 index 0000000000000..f72d69ee747b8 --- /dev/null +++ b/src/test/ui/huge-array-simple-32.rs @@ -0,0 +1,11 @@ +// ignore-32bit + +// FIXME https://github.com/rust-lang/rust/issues/59774 +// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" +// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" +#![allow(exceeding_bitshifts)] + +fn main() { + let _fat: [u8; (1<<61)+(1<<31)] = //~ ERROR too big for the current architecture + [0; (1u64<<61) as usize +(1u64<<31) as usize]; +} diff --git a/src/test/ui/huge-array-simple-32.stderr b/src/test/ui/huge-array-simple-32.stderr new file mode 100644 index 0000000000000..70d9194ea55c5 --- /dev/null +++ b/src/test/ui/huge-array-simple-32.stderr @@ -0,0 +1,8 @@ +error: the type `[u8; 2305843011361177600]` is too big for the current architecture + --> $DIR/huge-array-simple-32.rs:9:9 + | +LL | let _fat: [u8; (1<<61)+(1<<31)] = + | ^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/huge-array-simple-64.rs b/src/test/ui/huge-array-simple-64.rs new file mode 100644 index 0000000000000..9f98f4d753190 --- /dev/null +++ b/src/test/ui/huge-array-simple-64.rs @@ -0,0 +1,11 @@ +// ignore-64bit + +// FIXME https://github.com/rust-lang/rust/issues/59774 +// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" +// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" +#![allow(exceeding_bitshifts)] + +fn main() { + let _fat: [u8; (1<<31)+(1<<15)] = //~ ERROR too big for the current architecture + [0; (1u32<<31) as usize +(1u32<<15) as usize]; +} diff --git a/src/test/ui/huge-array-simple-64.stderr b/src/test/ui/huge-array-simple-64.stderr new file mode 100644 index 0000000000000..3f8e79e5b0b6e --- /dev/null +++ b/src/test/ui/huge-array-simple-64.stderr @@ -0,0 +1,8 @@ +error: the type `[u8; 2147516416]` is too big for the current architecture + --> $DIR/huge-array-simple-64.rs:9:9 + | +LL | let _fat: [u8; (1<<31)+(1<<15)] = + | ^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/huge-array-simple.rs b/src/test/ui/huge-array-simple.rs deleted file mode 100644 index 0ff27168a7d86..0000000000000 --- a/src/test/ui/huge-array-simple.rs +++ /dev/null @@ -1,20 +0,0 @@ -// error-pattern: too big for the current architecture - -// normalize-stderr-test "; \d+]" -> "; N]" - -// FIXME https://github.com/rust-lang/rust/issues/59774 -// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" -// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" -#![allow(exceeding_bitshifts)] - -#[cfg(target_pointer_width = "64")] -fn main() { - let _fat : [u8; (1<<61)+(1<<31)] = - [0; (1u64<<61) as usize +(1u64<<31) as usize]; -} - -#[cfg(target_pointer_width = "32")] -fn main() { - let _fat : [u8; (1<<31)+(1<<15)] = - [0; (1u32<<31) as usize +(1u32<<15) as usize]; -} diff --git a/src/test/ui/huge-array-simple.stderr b/src/test/ui/huge-array-simple.stderr deleted file mode 100644 index 3e9c86296cec2..0000000000000 --- a/src/test/ui/huge-array-simple.stderr +++ /dev/null @@ -1,4 +0,0 @@ -error: the type `[u8; N]` is too big for the current architecture - -error: aborting due to previous error - diff --git a/src/test/ui/huge-array.rs b/src/test/ui/huge-array.rs index f58dcd5806761..1ecf012e04be4 100644 --- a/src/test/ui/huge-array.rs +++ b/src/test/ui/huge-array.rs @@ -1,11 +1,10 @@ -// error-pattern:; 1518600000 - // FIXME https://github.com/rust-lang/rust/issues/59774 // normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" // normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" fn generic(t: T) { let s: [T; 1518600000] = [t; 1518600000]; + //~^ ERROR the type `[[u8; 1518599999]; 1518600000]` is too big for the current architecture } fn main() { diff --git a/src/test/ui/huge-array.stderr b/src/test/ui/huge-array.stderr index 38d9effcfb527..823d974f4290e 100644 --- a/src/test/ui/huge-array.stderr +++ b/src/test/ui/huge-array.stderr @@ -1,4 +1,8 @@ error: the type `[[u8; 1518599999]; 1518600000]` is too big for the current architecture + --> $DIR/huge-array.rs:6:9 + | +LL | let s: [T; 1518600000] = [t; 1518600000]; + | ^ error: aborting due to previous error diff --git a/src/test/ui/huge-enum.rs b/src/test/ui/huge-enum.rs index 2492afbdc8f81..98d0ba6e15c09 100644 --- a/src/test/ui/huge-enum.rs +++ b/src/test/ui/huge-enum.rs @@ -6,11 +6,12 @@ // normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" #[cfg(target_pointer_width = "32")] -fn main() { - let big: Option<[u32; (1<<29)-1]> = None; -} +type BIG = Option<[u32; (1<<29)-1]>; #[cfg(target_pointer_width = "64")] +type BIG = Option<[u32; (1<<45)-1]>; + fn main() { - let big: Option<[u32; (1<<45)-1]> = None; + let big: BIG = None; + //~^ ERROR is too big for the current architecture } diff --git a/src/test/ui/huge-enum.stderr b/src/test/ui/huge-enum.stderr index 67cae3d52ed2d..1f16c81a8f45e 100644 --- a/src/test/ui/huge-enum.stderr +++ b/src/test/ui/huge-enum.stderr @@ -1,4 +1,8 @@ error: the type `TYPE` is too big for the current architecture + --> $DIR/huge-enum.rs:15:9 + | +LL | let big: BIG = None; + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/huge-struct.rs b/src/test/ui/huge-struct.rs index dc7d75a6f028e..e120cae7fdd14 100644 --- a/src/test/ui/huge-struct.rs +++ b/src/test/ui/huge-struct.rs @@ -47,4 +47,6 @@ struct S1M { val: S1k> } fn main() { let fat: Option>>> = None; + //~^ ERROR the type `S32>>` is too big for the current architecture + } diff --git a/src/test/ui/huge-struct.stderr b/src/test/ui/huge-struct.stderr index 06b084bdc3a39..5c2140df48126 100644 --- a/src/test/ui/huge-struct.stderr +++ b/src/test/ui/huge-struct.stderr @@ -1,4 +1,8 @@ error: the type `SXX>>` is too big for the current architecture + --> $DIR/huge-struct.rs:49:9 + | +LL | let fat: Option>>> = None; + | ^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-15919-32.rs b/src/test/ui/issues/issue-15919-32.rs new file mode 100644 index 0000000000000..92394a4e54e9e --- /dev/null +++ b/src/test/ui/issues/issue-15919-32.rs @@ -0,0 +1,9 @@ +// ignore-64bit + +// FIXME https://github.com/rust-lang/rust/issues/59774 +// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" +// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" + +fn main() { + let x = [0usize; 0xffff_ffff]; //~ ERROR too big +} diff --git a/src/test/ui/issues/issue-15919-32.stderr b/src/test/ui/issues/issue-15919-32.stderr new file mode 100644 index 0000000000000..7f5d9262d39a7 --- /dev/null +++ b/src/test/ui/issues/issue-15919-32.stderr @@ -0,0 +1,8 @@ +error: the type `[usize; 4294967295]` is too big for the current architecture + --> $DIR/issue-15919-32.rs:8:9 + | +LL | let x = [0usize; 0xffff_ffff]; + | ^ + +error: aborting due to previous error + diff --git a/src/test/ui/issues/issue-15919-64.rs b/src/test/ui/issues/issue-15919-64.rs new file mode 100644 index 0000000000000..938ee92e2f256 --- /dev/null +++ b/src/test/ui/issues/issue-15919-64.rs @@ -0,0 +1,9 @@ +// ignore-32bit + +// FIXME https://github.com/rust-lang/rust/issues/59774 +// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" +// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" + +fn main() { + let x = [0usize; 0xffff_ffff_ffff_ffff]; //~ ERROR too big +} diff --git a/src/test/ui/issues/issue-15919-64.stderr b/src/test/ui/issues/issue-15919-64.stderr new file mode 100644 index 0000000000000..571b87d9961c0 --- /dev/null +++ b/src/test/ui/issues/issue-15919-64.stderr @@ -0,0 +1,8 @@ +error: the type `[usize; 18446744073709551615]` is too big for the current architecture + --> $DIR/issue-15919-64.rs:8:9 + | +LL | let x = [0usize; 0xffff_ffff_ffff_ffff]; + | ^ + +error: aborting due to previous error + diff --git a/src/test/ui/issues/issue-15919.rs b/src/test/ui/issues/issue-15919.rs deleted file mode 100644 index a7ac4802a12d5..0000000000000 --- a/src/test/ui/issues/issue-15919.rs +++ /dev/null @@ -1,16 +0,0 @@ -// error-pattern: too big for the current architecture -// normalize-stderr-test "\[usize; \d+\]" -> "[usize; N]" - -// FIXME https://github.com/rust-lang/rust/issues/59774 -// normalize-stderr-test "thread.*panicked.*Metadata module not compiled.*\n" -> "" -// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" - -#[cfg(target_pointer_width = "32")] -fn main() { - let x = [0usize; 0xffff_ffff]; -} - -#[cfg(target_pointer_width = "64")] -fn main() { - let x = [0usize; 0xffff_ffff_ffff_ffff]; -} diff --git a/src/test/ui/issues/issue-15919.stderr b/src/test/ui/issues/issue-15919.stderr deleted file mode 100644 index e4e88cc47cfe7..0000000000000 --- a/src/test/ui/issues/issue-15919.stderr +++ /dev/null @@ -1,4 +0,0 @@ -error: the type `[usize; N]` is too big for the current architecture - -error: aborting due to previous error - diff --git a/src/test/ui/issues/issue-56762.rs b/src/test/ui/issues/issue-56762.rs index 8bb81b907c9a4..5ba5b9847d085 100644 --- a/src/test/ui/issues/issue-56762.rs +++ b/src/test/ui/issues/issue-56762.rs @@ -17,6 +17,8 @@ impl TooBigArray { } static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new(); +//~^ ERROR the type `[u8; 2305843009213693951]` is too big for the current architecture static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE]; +//~^ ERROR the type `[u8; 2305843009213693951]` is too big for the current architecture fn main() { } diff --git a/src/test/ui/issues/issue-56762.stderr b/src/test/ui/issues/issue-56762.stderr index 83d5dc62e6161..69626d4bc7a9e 100644 --- a/src/test/ui/issues/issue-56762.stderr +++ b/src/test/ui/issues/issue-56762.stderr @@ -1,4 +1,15 @@ -error: the type `[u8; 2305843009213693951]` is too big for the current architecture +error[E0080]: the type `[u8; 2305843009213693951]` is too big for the current architecture + --> $DIR/issue-56762.rs:19:1 + | +LL | static MY_TOO_BIG_ARRAY_1: TooBigArray = TooBigArray::new(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to previous error +error[E0080]: the type `[u8; 2305843009213693951]` is too big for the current architecture + --> $DIR/issue-56762.rs:21:1 + | +LL | static MY_TOO_BIG_ARRAY_2: [u8; HUGE_SIZE] = [0x00; HUGE_SIZE]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0080`.