From a0c21e4e7ea3a2143af9e65a98a19e6b1942ff53 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 31 Oct 2022 20:55:03 -0400 Subject: [PATCH 01/13] Remove let_underscore_must_use from list of uplifted lints --- RELEASES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index a3df56f1d2afc..ad550260c8bcf 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -6,7 +6,7 @@ Language - [Error on `as` casts of enums with `#[non_exhaustive]` variants](https://github.com/rust-lang/rust/pull/92744/) - [Stabilize `let else`](https://github.com/rust-lang/rust/pull/93628/) - [Stabilize generic associated types (GATs)](https://github.com/rust-lang/rust/pull/96709/) -- [Add lints `let_underscore_drop`, `let_underscore_lock`, and `let_underscore_must_use` from Clippy](https://github.com/rust-lang/rust/pull/97739/) +- [Add lints `let_underscore_drop` and `let_underscore_lock` from Clippy](https://github.com/rust-lang/rust/pull/97739/) - [Stabilize `break`ing from arbitrary labeled blocks ("label-break-value")](https://github.com/rust-lang/rust/pull/99332/) - [Uninitialized integers, floats, and raw pointers are now considered immediate UB](https://github.com/rust-lang/rust/pull/98919/). Usage of `MaybeUninit` is the correct way to work with uninitialized memory. From 7df9d818ab07d1d014ac46a1f462d87a2d57ce21 Mon Sep 17 00:00:00 2001 From: yukang Date: Wed, 2 Nov 2022 23:15:49 +0800 Subject: [PATCH 02/13] deprecate DelaySpanBugEmitted and use ErrorGuaranteed directly --- .../rustc_const_eval/src/interpret/operand.rs | 4 ++-- compiler/rustc_middle/src/ty/abstract_const.rs | 4 ++-- compiler/rustc_middle/src/ty/consts/kind.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 15 +++------------ compiler/rustc_middle/src/ty/mod.rs | 2 +- compiler/rustc_middle/src/ty/structural_impls.rs | 1 - compiler/rustc_type_ir/src/lib.rs | 2 +- compiler/rustc_type_ir/src/sty.rs | 10 ++++------ 8 files changed, 14 insertions(+), 26 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index 0c212cf59e17f..dd00678aa0cea 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -4,7 +4,7 @@ use rustc_hir::def::Namespace; use rustc_middle::ty::layout::{LayoutOf, PrimitiveExt, TyAndLayout}; use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter}; -use rustc_middle::ty::{ConstInt, DelaySpanBugEmitted, Ty}; +use rustc_middle::ty::{ConstInt, Ty}; use rustc_middle::{mir, ty}; use rustc_target::abi::{self, Abi, Align, HasDataLayout, Size, TagEncoding}; use rustc_target::abi::{VariantIdx, Variants}; @@ -567,7 +567,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { ty::ConstKind::Param(_) | ty::ConstKind::Placeholder(..) => { throw_inval!(TooGeneric) } - ty::ConstKind::Error(DelaySpanBugEmitted { reported, .. }) => { + ty::ConstKind::Error(reported) => { throw_inval!(AlreadyReported(reported)) } ty::ConstKind::Unevaluated(uv) => { diff --git a/compiler/rustc_middle/src/ty/abstract_const.rs b/compiler/rustc_middle/src/ty/abstract_const.rs index 1aa4df7780084..e5bcd5fb27aa7 100644 --- a/compiler/rustc_middle/src/ty/abstract_const.rs +++ b/compiler/rustc_middle/src/ty/abstract_const.rs @@ -1,7 +1,7 @@ //! A subset of a mir body used for const evaluatability checking. use crate::mir; use crate::ty::visit::TypeVisitable; -use crate::ty::{self, DelaySpanBugEmitted, EarlyBinder, SubstsRef, Ty, TyCtxt}; +use crate::ty::{self, EarlyBinder, SubstsRef, Ty, TyCtxt}; use rustc_errors::ErrorGuaranteed; use rustc_hir::def_id::DefId; use std::cmp; @@ -43,7 +43,7 @@ impl<'tcx> AbstractConst<'tcx> { ) -> Result>, ErrorGuaranteed> { match ct.kind() { ty::ConstKind::Unevaluated(uv) => AbstractConst::new(tcx, uv), - ty::ConstKind::Error(DelaySpanBugEmitted { reported, .. }) => Err(reported), + ty::ConstKind::Error(reported) => Err(reported), _ => Ok(None), } } diff --git a/compiler/rustc_middle/src/ty/consts/kind.rs b/compiler/rustc_middle/src/ty/consts/kind.rs index 4ab761e0715cd..c1c613f6c602e 100644 --- a/compiler/rustc_middle/src/ty/consts/kind.rs +++ b/compiler/rustc_middle/src/ty/consts/kind.rs @@ -69,7 +69,7 @@ pub enum ConstKind<'tcx> { /// A placeholder for a const which could not be computed; this is /// propagated to avoid useless error messages. - Error(ty::DelaySpanBugEmitted), + Error(ErrorGuaranteed), } #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 94e3f3b63c813..eeb53f9714ce8 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -116,7 +116,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { type BoundTy = ty::BoundTy; type PlaceholderType = ty::PlaceholderType; type InferTy = InferTy; - type DelaySpanBugEmitted = DelaySpanBugEmitted; + type ErrorGuaranteed = ErrorGuaranteed; type PredicateKind = ty::PredicateKind<'tcx>; type AllocId = crate::mir::interpret::AllocId; @@ -127,15 +127,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> { type PlaceholderRegion = ty::PlaceholderRegion; } -/// A type that is not publicly constructable. This prevents people from making [`TyKind::Error`]s -/// except through the error-reporting functions on a [`tcx`][TyCtxt]. -#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] -#[derive(TyEncodable, TyDecodable, HashStable)] -pub struct DelaySpanBugEmitted { - pub reported: ErrorGuaranteed, - _priv: (), -} - type InternedSet<'tcx, T> = ShardedHashMap, ()>; pub struct CtxtInterners<'tcx> { @@ -1302,7 +1293,7 @@ impl<'tcx> TyCtxt<'tcx> { #[track_caller] pub fn ty_error_with_message>(self, span: S, msg: &str) -> Ty<'tcx> { let reported = self.sess.delay_span_bug(span, msg); - self.mk_ty(Error(DelaySpanBugEmitted { reported, _priv: () })) + self.mk_ty(Error(reported)) } /// Like [TyCtxt::ty_error] but for constants. @@ -1325,7 +1316,7 @@ impl<'tcx> TyCtxt<'tcx> { ) -> Const<'tcx> { let reported = self.sess.delay_span_bug(span, msg); self.mk_const(ty::ConstS { - kind: ty::ConstKind::Error(DelaySpanBugEmitted { reported, _priv: () }), + kind: ty::ConstKind::Error(reported), ty, }) } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 9671d3a32f945..9267a541a59cb 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -80,7 +80,7 @@ pub use self::consts::{ }; pub use self::context::{ tls, CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, - CtxtInterners, DeducedParamAttrs, DelaySpanBugEmitted, FreeRegionInfo, GeneratorDiagnosticData, + CtxtInterners, DeducedParamAttrs, FreeRegionInfo, GeneratorDiagnosticData, GeneratorInteriorTypeCause, GlobalCtxt, Lift, OnDiskCache, TyCtxt, TypeckResults, UserType, UserTypeAnnotationIndex, }; diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 2cad333e3f52a..23cd93d6af40c 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -240,7 +240,6 @@ TrivialTypeTraversalAndLiftImpls! { Field, interpret::Scalar, rustc_target::abi::Size, - ty::DelaySpanBugEmitted, rustc_type_ir::DebruijnIndex, ty::BoundVar, ty::Placeholder, diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index 7fbe78aa52353..7c3eb4efbc984 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -45,7 +45,7 @@ pub trait Interner { type BoundTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type PlaceholderType: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type InferTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; - type DelaySpanBugEmitted: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; + type ErrorGuaranteed: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type PredicateKind: Clone + Debug + Hash + PartialEq + Eq; type AllocId: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; diff --git a/compiler/rustc_type_ir/src/sty.rs b/compiler/rustc_type_ir/src/sty.rs index a4fb1480fa448..02cbb2e858f80 100644 --- a/compiler/rustc_type_ir/src/sty.rs +++ b/compiler/rustc_type_ir/src/sty.rs @@ -217,7 +217,7 @@ pub enum TyKind { /// A placeholder for a type which could not be computed; this is /// propagated to avoid useless error messages. - Error(I::DelaySpanBugEmitted), + Error(I::ErrorGuaranteed), } impl TyKind { @@ -626,7 +626,7 @@ impl fmt::Debug for TyKind { // This is manually implemented because a derive would require `I: Encodable` impl Encodable for TyKind where - I::DelaySpanBugEmitted: Encodable, + I::ErrorGuaranteed: Encodable, I::AdtDef: Encodable, I::SubstsRef: Encodable, I::DefId: Encodable, @@ -645,7 +645,6 @@ where I::BoundTy: Encodable, I::PlaceholderType: Encodable, I::InferTy: Encodable, - I::DelaySpanBugEmitted: Encodable, I::PredicateKind: Encodable, I::AllocId: Encodable, { @@ -744,7 +743,7 @@ where // This is manually implemented because a derive would require `I: Decodable` impl> Decodable for TyKind where - I::DelaySpanBugEmitted: Decodable, + I::ErrorGuaranteed: Decodable, I::AdtDef: Decodable, I::SubstsRef: Decodable, I::DefId: Decodable, @@ -763,7 +762,6 @@ where I::BoundTy: Decodable, I::PlaceholderType: Decodable, I::InferTy: Decodable, - I::DelaySpanBugEmitted: Decodable, I::PredicateKind: Decodable, I::AllocId: Decodable, { @@ -829,7 +827,7 @@ where I::ParamTy: HashStable, I::PlaceholderType: HashStable, I::InferTy: HashStable, - I::DelaySpanBugEmitted: HashStable, + I::ErrorGuaranteed: HashStable, { #[inline] fn hash_stable( From 59be5151287e29d5340d6189dea2f18206f51e02 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 2 Nov 2022 17:33:25 +0000 Subject: [PATCH 03/13] Properly render asyncness for traits without default body --- compiler/rustc_ty_utils/src/ty.rs | 2 +- src/librustdoc/clean/mod.rs | 32 +++++++++++++++++------------ src/librustdoc/clean/types.rs | 5 +---- src/test/rustdoc/async-trait-sig.rs | 14 +++++++++++++ 4 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 src/test/rustdoc/async-trait-sig.rs diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 3eebb4ace477f..99d3bda6ebfff 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -413,7 +413,7 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option> { /// Check if a function is async. fn asyncness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::IsAsync { let node = tcx.hir().get_by_def_id(def_id.expect_local()); - if let Some(fn_kind) = node.fn_kind() { fn_kind.asyncness() } else { hir::IsAsync::NotAsync } + node.fn_sig().map_or(hir::IsAsync::NotAsync, |sig| sig.header.asyncness) } /// Don't call this directly: use ``tcx.conservative_is_privately_uninhabited`` instead. diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 1ce0d1e4ffd02..84afdadfa002a 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -880,7 +880,7 @@ fn clean_fn_or_proc_macro<'tcx>( ProcMacroItem(ProcMacro { kind, helpers }) } None => { - let mut func = clean_function(cx, sig, generics, body_id); + let mut func = clean_function(cx, sig, generics, FunctionArgs::Body(body_id)); clean_fn_decl_legacy_const_generics(&mut func, attrs); FunctionItem(func) } @@ -917,16 +917,28 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[ast::Attrib } } +enum FunctionArgs<'tcx> { + Body(hir::BodyId), + Names(&'tcx [Ident]), +} + fn clean_function<'tcx>( cx: &mut DocContext<'tcx>, sig: &hir::FnSig<'tcx>, generics: &hir::Generics<'tcx>, - body_id: hir::BodyId, + args: FunctionArgs<'tcx>, ) -> Box { let (generics, decl) = enter_impl_trait(cx, |cx| { // NOTE: generics must be cleaned before args let generics = clean_generics(generics, cx); - let args = clean_args_from_types_and_body_id(cx, sig.decl.inputs, body_id); + let args = match args { + FunctionArgs::Body(body_id) => { + clean_args_from_types_and_body_id(cx, sig.decl.inputs, body_id) + } + FunctionArgs::Names(names) => { + clean_args_from_types_and_names(cx, sig.decl.inputs, names) + } + }; let mut decl = clean_fn_decl_with_args(cx, sig.decl, args); if sig.header.is_async() { decl.output = decl.sugared_async_return_type(); @@ -1051,18 +1063,12 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext ), hir::TraitItemKind::Const(ty, None) => TyAssocConstItem(clean_ty(ty, cx)), hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => { - let m = clean_function(cx, sig, trait_item.generics, body); + let m = clean_function(cx, sig, trait_item.generics, FunctionArgs::Body(body)); MethodItem(m, None) } hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(names)) => { - let (generics, decl) = enter_impl_trait(cx, |cx| { - // NOTE: generics must be cleaned before args - let generics = clean_generics(trait_item.generics, cx); - let args = clean_args_from_types_and_names(cx, sig.decl.inputs, names); - let decl = clean_fn_decl_with_args(cx, sig.decl, args); - (generics, decl) - }); - TyMethodItem(Box::new(Function { decl, generics })) + let m = clean_function(cx, sig, trait_item.generics, FunctionArgs::Names(names)); + TyMethodItem(m) } hir::TraitItemKind::Type(bounds, Some(default)) => { let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)); @@ -1099,7 +1105,7 @@ pub(crate) fn clean_impl_item<'tcx>( AssocConstItem(clean_ty(ty, cx), default) } hir::ImplItemKind::Fn(ref sig, body) => { - let m = clean_function(cx, sig, impl_.generics, body); + let m = clean_function(cx, sig, impl_.generics, FunctionArgs::Body(body)); let defaultness = cx.tcx.impl_defaultness(impl_.owner_id); MethodItem(m, Some(defaultness)) } diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 439311f064029..f1eb438b199ce 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -694,13 +694,10 @@ impl Item { asyncness: hir::IsAsync::NotAsync, } } - ItemKind::FunctionItem(_) | ItemKind::MethodItem(_, _) => { + ItemKind::FunctionItem(_) | ItemKind::MethodItem(_, _) | ItemKind::TyMethodItem(_) => { let def_id = self.item_id.as_def_id().unwrap(); build_fn_header(def_id, tcx, tcx.asyncness(def_id)) } - ItemKind::TyMethodItem(_) => { - build_fn_header(self.item_id.as_def_id().unwrap(), tcx, hir::IsAsync::NotAsync) - } _ => return None, }; Some(header) diff --git a/src/test/rustdoc/async-trait-sig.rs b/src/test/rustdoc/async-trait-sig.rs new file mode 100644 index 0000000000000..2578bc8f7a166 --- /dev/null +++ b/src/test/rustdoc/async-trait-sig.rs @@ -0,0 +1,14 @@ +// edition:2021 + +#![feature(async_fn_in_trait)] +#![allow(incomplete_features)] + +pub trait Foo { + // @has async_trait_sig/trait.Foo.html '//h4[@class="code-header"]' "async fn bar() -> i32" + async fn bar() -> i32; + + // @has async_trait_sig/trait.Foo.html '//h4[@class="code-header"]' "async fn baz() -> i32" + async fn baz() -> i32 { + 1 + } +} From ab22f5521bdb940d8beabd442298a56ecb236b38 Mon Sep 17 00:00:00 2001 From: yukang Date: Thu, 3 Nov 2022 04:57:44 +0800 Subject: [PATCH 04/13] change error_reported to use Result instead of an option --- compiler/rustc_hir_analysis/src/astconv/mod.rs | 2 +- .../rustc_hir_analysis/src/coherence/orphan.rs | 4 +--- compiler/rustc_hir_typeck/src/cast.rs | 16 +++++++--------- .../src/traits/specialization_graph.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 5 +---- compiler/rustc_middle/src/ty/visit.rs | 6 +++--- compiler/rustc_transmute/src/lib.rs | 2 +- 7 files changed, 15 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 6baf98449775d..3d3d3d2d94f05 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -1977,7 +1977,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } err.emit() - } else if let Some(reported) = qself_ty.error_reported() { + } else if let Err(reported) = qself_ty.error_reported() { reported } else { // Don't print `TyErr` to the user. diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 1307f74f21071..e9674c93f3e45 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -23,9 +23,7 @@ pub(crate) fn orphan_check_impl( impl_def_id: LocalDefId, ) -> Result<(), ErrorGuaranteed> { let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap(); - if let Some(err) = trait_ref.error_reported() { - return Err(err); - } + trait_ref.error_reported()?; let ret = do_orphan_check_impl(tcx, trait_ref, impl_def_id); if tcx.trait_is_auto(trait_ref.def_id) { diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 0e7576ecf8b0c..cf7587ffa0e82 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -92,10 +92,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { debug!("pointer_kind({:?}, {:?})", t, span); let t = self.resolve_vars_if_possible(t); - - if let Some(reported) = t.error_reported() { - return Err(reported); - } + t.error_reported()?; if self.type_is_sized_modulo_regions(self.param_env, t, span) { return Ok(Some(PointerKind::Thin)); @@ -220,7 +217,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { match cast_ty.kind() { ty::Dynamic(_, _, ty::Dyn) | ty::Slice(..) => { let reported = check.report_cast_to_unsized_type(fcx); - Err(reported) + return Err(reported); } _ => Ok(check), } @@ -611,10 +608,11 @@ impl<'a, 'tcx> CastCheck<'tcx> { } fn report_cast_to_unsized_type(&self, fcx: &FnCtxt<'a, 'tcx>) -> ErrorGuaranteed { - if let Some(reported) = - self.cast_ty.error_reported().or_else(|| self.expr_ty.error_reported()) - { - return reported; + if let Err(err) = self.cast_ty.error_reported() { + return err; + } + if let Err(err) = self.expr_ty.error_reported() { + return err; } let tstr = fcx.ty_to_string(self.cast_ty); diff --git a/compiler/rustc_middle/src/traits/specialization_graph.rs b/compiler/rustc_middle/src/traits/specialization_graph.rs index 0a2819feecf0b..82442c8430db5 100644 --- a/compiler/rustc_middle/src/traits/specialization_graph.rs +++ b/compiler/rustc_middle/src/traits/specialization_graph.rs @@ -249,7 +249,7 @@ pub fn ancestors<'tcx>( if let Some(reported) = specialization_graph.has_errored { Err(reported) - } else if let Some(reported) = tcx.type_of(start_from_impl).error_reported() { + } else if let Err(reported) = tcx.type_of(start_from_impl).error_reported() { Err(reported) } else { Ok(Ancestors { diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index eeb53f9714ce8..95004e5c5ca2c 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1315,10 +1315,7 @@ impl<'tcx> TyCtxt<'tcx> { msg: &str, ) -> Const<'tcx> { let reported = self.sess.delay_span_bug(span, msg); - self.mk_const(ty::ConstS { - kind: ty::ConstKind::Error(reported), - ty, - }) + self.mk_const(ty::ConstS { kind: ty::ConstKind::Error(reported), ty }) } pub fn consider_optimizing String>(self, msg: T) -> bool { diff --git a/compiler/rustc_middle/src/ty/visit.rs b/compiler/rustc_middle/src/ty/visit.rs index c09f71f9a6d09..f0e9f990a8115 100644 --- a/compiler/rustc_middle/src/ty/visit.rs +++ b/compiler/rustc_middle/src/ty/visit.rs @@ -95,11 +95,11 @@ pub trait TypeVisitable<'tcx>: fmt::Debug + Clone { fn references_error(&self) -> bool { self.has_type_flags(TypeFlags::HAS_ERROR) } - fn error_reported(&self) -> Option { + fn error_reported(&self) -> Result<(), ErrorGuaranteed> { if self.references_error() { - Some(ErrorGuaranteed::unchecked_claim_error_was_emitted()) + Err(ErrorGuaranteed::unchecked_claim_error_was_emitted()) } else { - None + Ok(()) } } fn has_non_region_param(&self) -> bool { diff --git a/compiler/rustc_transmute/src/lib.rs b/compiler/rustc_transmute/src/lib.rs index f7cc94e53146a..384d03106b1e8 100644 --- a/compiler/rustc_transmute/src/lib.rs +++ b/compiler/rustc_transmute/src/lib.rs @@ -122,7 +122,7 @@ mod rustc { let c = c.eval(tcx, param_env); - if let Some(err) = c.error_reported() { + if let Err(err) = c.error_reported() { return Some(Self { alignment: true, lifetimes: true, From 68e19aa4ac8812e83b80035988d915087a4183e5 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Wed, 2 Nov 2022 15:33:36 -0700 Subject: [PATCH 05/13] rustdoc: remove redundant mobile CSS `.sidebar-elems { background }` The exact same background is already set for its parent, the `nav.sidebar`. --- src/librustdoc/html/static/css/rustdoc.css | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 360b6b9832a55..d7526498b0d66 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1797,7 +1797,6 @@ in storage.js .sidebar-elems { margin-top: 1em; - background-color: var(--sidebar-background-color); } .content { From a21a055ca6f0d0244cfe79ffba908987e475c946 Mon Sep 17 00:00:00 2001 From: yukang Date: Thu, 3 Nov 2022 09:22:08 +0800 Subject: [PATCH 06/13] remove 'delay_span_bug' following 'references_error' --- compiler/rustc_const_eval/src/transform/promote_consts.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_const_eval/src/transform/promote_consts.rs b/compiler/rustc_const_eval/src/transform/promote_consts.rs index f3ae16da43bd1..f48bcd9080966 100644 --- a/compiler/rustc_const_eval/src/transform/promote_consts.rs +++ b/compiler/rustc_const_eval/src/transform/promote_consts.rs @@ -45,11 +45,10 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> { // There's not really any point in promoting errorful MIR. // // This does not include MIR that failed const-checking, which we still try to promote. - if body.return_ty().references_error() { - tcx.sess.delay_span_bug(body.span, "PromoteTemps: MIR had errors"); + if let Err(_) = body.return_ty().error_reported() { + debug!("PromoteTemps: MIR had errors"); return; } - if body.source.promoted.is_some() { return; } From c6d23bdd328decdb0a0e98980af4c3b7aa13d9d6 Mon Sep 17 00:00:00 2001 From: yukang Date: Thu, 3 Nov 2022 09:42:34 +0800 Subject: [PATCH 07/13] code cleanup --- compiler/rustc_hir_typeck/src/cast.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index cf7587ffa0e82..4ff8951193884 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -216,8 +216,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { // inference is more completely known. match cast_ty.kind() { ty::Dynamic(_, _, ty::Dyn) | ty::Slice(..) => { - let reported = check.report_cast_to_unsized_type(fcx); - return Err(reported); + Err(check.report_cast_to_unsized_type(fcx)) } _ => Ok(check), } From 87b2110f25bed1407a9aded9e263b64dc3315d45 Mon Sep 17 00:00:00 2001 From: Florian Bartels Date: Thu, 3 Nov 2022 09:19:47 +0100 Subject: [PATCH 08/13] Add howto for adding new targets --- src/doc/rustc/src/target-tier-policy.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/doc/rustc/src/target-tier-policy.md b/src/doc/rustc/src/target-tier-policy.md index 53d0470fa8135..df9131ce84afd 100644 --- a/src/doc/rustc/src/target-tier-policy.md +++ b/src/doc/rustc/src/target-tier-policy.md @@ -3,6 +3,7 @@ ## Table of Contents * [General](#general) +* [Adding a new target](#adding-a-new-target) * [Tier 3 target policy](#tier-3-target-policy) * [Tier 2 target policy](#tier-2-target-policy) * [Tier 2 with host tools](#tier-2-with-host-tools) @@ -104,6 +105,30 @@ indicates something entirely optional, and does not indicate guidance or recommendations. This language is based on [IETF RFC 2119](https://tools.ietf.org/html/rfc2119). +## Adding a new target + +New targets typically start as Tier 3 and then can be promoted later. +To propose addition of a new target, open a pull request on [`rust-lang/rust`]: + +- Copy the [Tier 3 target policy](#tier-3-target-policy) to the description + and fill it out, see [example][tier3example]. +- Add a new description for the target in `src/doc/rustc/src/platform-support` + using the [template][platform_template]. +- Add the target to the [SUMMARY.md][summary] (allows wildcards) and + [platform-support.md][platformsupport] (must name all targets verbatim). + Link to the created description page. +- Ensure the pull request is assigned to a member of the [Rust compiler team][rust_compiler_team] by commenting: + ```text + r? compiler-team + ``` + +[tier3example]: https://github.com/rust-lang/rust/pull/94872 +[platform_template]: https://github.com/rust-lang/rust/blob/master/src/doc/rustc/src/platform-support/TEMPLATE.md +[summary]: https://github.com/rust-lang/rust/blob/master/src/doc/rustc/src/SUMMARY.md +[platformsupport]: https://github.com/rust-lang/rust/blob/master/src/doc/rustc/src/platform-support.md +[rust_compiler_team]: https://www.rust-lang.org/governance/teams/compiler +[`rust-lang/rust`]: https://github.com/rust-lang/rust + ## Tier 3 target policy At this tier, the Rust project provides no official support for a target, so we From ba18f16e81e568a6dfbd437edf4c949a9538c984 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 26 Oct 2022 14:40:34 -0300 Subject: [PATCH 09/13] Add visit_fn_ret_ty to hir intravisit --- compiler/rustc_hir/src/intravisit.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index d852893ad5dc6..3ef58d7d70570 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -358,6 +358,9 @@ pub trait Visitor<'v>: Sized { fn visit_where_predicate(&mut self, predicate: &'v WherePredicate<'v>) { walk_where_predicate(self, predicate) } + fn visit_fn_ret_ty(&mut self, ret_ty: &'v FnRetTy<'v>) { + walk_fn_ret_ty(self, ret_ty) + } fn visit_fn_decl(&mut self, fd: &'v FnDecl<'v>) { walk_fn_decl(self, fd) } @@ -903,7 +906,7 @@ pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: & for ty in function_declaration.inputs { visitor.visit_ty(ty) } - walk_fn_ret_ty(visitor, &function_declaration.output) + visitor.visit_fn_ret_ty(&function_declaration.output) } pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FnRetTy<'v>) { From 9c79a27e23f87d60736207f06f9c030396a444b4 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Thu, 3 Nov 2022 11:44:50 -0400 Subject: [PATCH 10/13] Add note to RELEASES.md regarding issue 102754. --- RELEASES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index a3df56f1d2afc..c7437f9f7e755 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -87,6 +87,9 @@ Compatibility Notes This strengthens the forward compatibility lint deprecated_cfg_attr_crate_type_name to deny. - [`llvm-has-rust-patches` allows setting the build system to treat the LLVM as having Rust-specific patches](https://github.com/rust-lang/rust/pull/101072) This option may need to be set for distributions that are building Rust with a patched LLVM via `llvm-config`, not the built-in LLVM. +- Combining three or more languages (e.g. Objective C, C++ and Rust) into one binary may hit linker limitations when using `lld`. For more information, see [issue 102754][102754]. + +[102754]: https://github.com/rust-lang/rust/issues/102754 Internal Changes ---------------- From 35b16d01ce149716a8d1443fff6a4c6815f3e56d Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Thu, 3 Nov 2022 15:41:01 +0000 Subject: [PATCH 11/13] Move some tests from `src/test/ui` to more reasonable places --- src/test/ui/{ => macros}/attr-from-macro.rs | 0 src/test/ui/{ => macros}/auxiliary/attr-from-macro.rs | 0 src/test/ui/{ => repr}/align-with-extern-c-fn.rs | 0 src/test/ui/{ => repr}/aligned_enum_cast.rs | 0 src/test/ui/{ => repr}/repr_c_int_align.rs | 0 src/test/ui/{rfc1623.rs => rfcs/rfc1623-2.rs} | 0 src/test/ui/{rfc1623.stderr => rfcs/rfc1623-2.stderr} | 8 ++++---- src/test/ui/{rfc1623-2.rs => rfcs/rfc1623-3.rs} | 0 src/test/ui/{rfc1623-2.stderr => rfcs/rfc1623-3.stderr} | 6 +++--- src/tools/tidy/src/ui_tests.rs | 2 +- 10 files changed, 8 insertions(+), 8 deletions(-) rename src/test/ui/{ => macros}/attr-from-macro.rs (100%) rename src/test/ui/{ => macros}/auxiliary/attr-from-macro.rs (100%) rename src/test/ui/{ => repr}/align-with-extern-c-fn.rs (100%) rename src/test/ui/{ => repr}/aligned_enum_cast.rs (100%) rename src/test/ui/{ => repr}/repr_c_int_align.rs (100%) rename src/test/ui/{rfc1623.rs => rfcs/rfc1623-2.rs} (100%) rename src/test/ui/{rfc1623.stderr => rfcs/rfc1623-2.stderr} (91%) rename src/test/ui/{rfc1623-2.rs => rfcs/rfc1623-3.rs} (100%) rename src/test/ui/{rfc1623-2.stderr => rfcs/rfc1623-3.stderr} (94%) diff --git a/src/test/ui/attr-from-macro.rs b/src/test/ui/macros/attr-from-macro.rs similarity index 100% rename from src/test/ui/attr-from-macro.rs rename to src/test/ui/macros/attr-from-macro.rs diff --git a/src/test/ui/auxiliary/attr-from-macro.rs b/src/test/ui/macros/auxiliary/attr-from-macro.rs similarity index 100% rename from src/test/ui/auxiliary/attr-from-macro.rs rename to src/test/ui/macros/auxiliary/attr-from-macro.rs diff --git a/src/test/ui/align-with-extern-c-fn.rs b/src/test/ui/repr/align-with-extern-c-fn.rs similarity index 100% rename from src/test/ui/align-with-extern-c-fn.rs rename to src/test/ui/repr/align-with-extern-c-fn.rs diff --git a/src/test/ui/aligned_enum_cast.rs b/src/test/ui/repr/aligned_enum_cast.rs similarity index 100% rename from src/test/ui/aligned_enum_cast.rs rename to src/test/ui/repr/aligned_enum_cast.rs diff --git a/src/test/ui/repr_c_int_align.rs b/src/test/ui/repr/repr_c_int_align.rs similarity index 100% rename from src/test/ui/repr_c_int_align.rs rename to src/test/ui/repr/repr_c_int_align.rs diff --git a/src/test/ui/rfc1623.rs b/src/test/ui/rfcs/rfc1623-2.rs similarity index 100% rename from src/test/ui/rfc1623.rs rename to src/test/ui/rfcs/rfc1623-2.rs diff --git a/src/test/ui/rfc1623.stderr b/src/test/ui/rfcs/rfc1623-2.stderr similarity index 91% rename from src/test/ui/rfc1623.stderr rename to src/test/ui/rfcs/rfc1623-2.stderr index b15a4cb110b73..d183eaaa6236e 100644 --- a/src/test/ui/rfc1623.stderr +++ b/src/test/ui/rfcs/rfc1623-2.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/rfc1623.rs:28:8 + --> $DIR/rfc1623-2.rs:28:8 | LL | f: &id, | ^^^ one type is more general than the other @@ -8,7 +8,7 @@ LL | f: &id, found trait `Fn<(&Foo<'_>,)>` error[E0308]: mismatched types - --> $DIR/rfc1623.rs:28:8 + --> $DIR/rfc1623-2.rs:28:8 | LL | f: &id, | ^^^ one type is more general than the other @@ -17,7 +17,7 @@ LL | f: &id, found trait `Fn<(&Foo<'_>,)>` error: implementation of `FnOnce` is not general enough - --> $DIR/rfc1623.rs:28:8 + --> $DIR/rfc1623-2.rs:28:8 | LL | f: &id, | ^^^ implementation of `FnOnce` is not general enough @@ -26,7 +26,7 @@ LL | f: &id, = note: ...but it actually implements `FnOnce<(&'2 Foo<'_>,)>`, for some specific lifetime `'2` error: implementation of `FnOnce` is not general enough - --> $DIR/rfc1623.rs:28:8 + --> $DIR/rfc1623-2.rs:28:8 | LL | f: &id, | ^^^ implementation of `FnOnce` is not general enough diff --git a/src/test/ui/rfc1623-2.rs b/src/test/ui/rfcs/rfc1623-3.rs similarity index 100% rename from src/test/ui/rfc1623-2.rs rename to src/test/ui/rfcs/rfc1623-3.rs diff --git a/src/test/ui/rfc1623-2.stderr b/src/test/ui/rfcs/rfc1623-3.stderr similarity index 94% rename from src/test/ui/rfc1623-2.stderr rename to src/test/ui/rfcs/rfc1623-3.stderr index 945c6533c797b..77fc3f0412ebf 100644 --- a/src/test/ui/rfc1623-2.stderr +++ b/src/test/ui/rfcs/rfc1623-3.stderr @@ -1,5 +1,5 @@ error[E0106]: missing lifetime specifier - --> $DIR/rfc1623-2.rs:8:42 + --> $DIR/rfc1623-3.rs:8:42 | LL | static NON_ELIDABLE_FN: &fn(&u8, &u8) -> &u8 = | --- --- ^ expected named lifetime parameter @@ -12,7 +12,7 @@ LL | static NON_ELIDABLE_FN: &for<'a> fn(&'a u8, &'a u8) -> &'a u8 = | +++++++ ++ ++ ++ error[E0106]: missing lifetime specifier - --> $DIR/rfc1623-2.rs:10:39 + --> $DIR/rfc1623-3.rs:10:39 | LL | &(non_elidable as fn(&u8, &u8) -> &u8); | --- --- ^ expected named lifetime parameter @@ -24,7 +24,7 @@ LL | &(non_elidable as for<'a> fn(&'a u8, &'a u8) -> &'a u8); | +++++++ ++ ++ ++ error[E0605]: non-primitive cast: `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8 {non_elidable}` as `for<'a, 'b> fn(&'a u8, &'b u8) -> &u8` - --> $DIR/rfc1623-2.rs:10:6 + --> $DIR/rfc1623-3.rs:10:6 | LL | &(non_elidable as fn(&u8, &u8) -> &u8); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index c600f99c2c4bf..6bf7d8206a576 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -7,7 +7,7 @@ use std::path::Path; const ENTRY_LIMIT: usize = 1000; // FIXME: The following limits should be reduced eventually. -const ROOT_ENTRY_LIMIT: usize = 948; +const ROOT_ENTRY_LIMIT: usize = 941; const ISSUES_ENTRY_LIMIT: usize = 2117; fn check_entries(path: &Path, bad: &mut bool) { From f097940da8f282b6503c5f37fd449652de285578 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 3 Nov 2022 12:29:17 -0700 Subject: [PATCH 12/13] rustdoc: clean up hardcoded CSS border color on search results Hardcoded colors in rustdoc.css should usually be avoided. --- src/librustdoc/html/static/css/rustdoc.css | 3 +-- src/test/rustdoc-gui/search-result-color.goml | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index d6f2b02afd8f8..0a9814ee28b58 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -894,7 +894,7 @@ so that we can apply CSS-filters to change the arrow color in themes */ /* A little margin ensures the browser's outlining of focused links has room to display. */ margin-left: 2px; margin-right: 2px; - border-bottom: 1px solid #aaa3; + border-bottom: 1px solid var(--border-color); } .search-results > a > div { @@ -1875,7 +1875,6 @@ in storage.js /* Display an alternating layout on tablets and phones */ .search-results > a { - border-bottom: 1px solid #aaa9; padding: 5px 0px; } .search-results .result-name, .search-results div.desc { diff --git a/src/test/rustdoc-gui/search-result-color.goml b/src/test/rustdoc-gui/search-result-color.goml index 69bb30df954bd..37d7b03a09958 100644 --- a/src/test/rustdoc-gui/search-result-color.goml +++ b/src/test/rustdoc-gui/search-result-color.goml @@ -75,6 +75,12 @@ assert-css: ( {"color": "rgb(0, 150, 207)"}, ) +// Checking the color of the bottom border. +assert-css: ( + ".search-results > a", + {"border-bottom-color": "rgb(92, 103, 115)"} +) + // Checking the color of "keyword" text. assert-css: ( "//*[@class='result-name']//*[text()='(keyword)']", @@ -181,6 +187,12 @@ assert-css: ( {"color": "rgb(221, 221, 221)"}, ) +// Checking the color of the bottom border. +assert-css: ( + ".search-results > a", + {"border-bottom-color": "rgb(224, 224, 224)"} +) + // Checking the color for "keyword" text. assert-css: ( "//*[@class='result-name']//*[text()='(keyword)']", @@ -272,6 +284,12 @@ assert-css: ( {"color": "rgb(0, 0, 0)"}, ) +// Checking the color of the bottom border. +assert-css: ( + ".search-results > a", + {"border-bottom-color": "rgb(224, 224, 224)"} +) + // Checking the color for "keyword" text. assert-css: ( "//*[@class='result-name']//*[text()='(keyword)']", From c51c07d30fbaa813775168bb01a678c0813a0b93 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 3 Nov 2022 13:22:54 -0700 Subject: [PATCH 13/13] rustdoc: remove no-op CSS `#main-content > .item-info { margin-top: 0 }` When this line was added in 04b4c40682c01cad8f9bc8d5b3907be91d6f81d4, it overrode a negative `margin-top` that was set on it by default. https://github.com/rust-lang/rust/blob/04b4c40682c01cad8f9bc8d5b3907be91d6f81d4/src/librustdoc/html/static/rustdoc.css#L500-L516 That negative top margin was removed in 593d6d1cb15c55c88319470dabb40126c7b7f1e2. --- src/librustdoc/html/static/css/rustdoc.css | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index d6f2b02afd8f8..ce9f0f4ae1961 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -677,7 +677,6 @@ pre, .rustdoc.source .example-wrap { } #main-content > .item-info { - margin-top: 0; margin-left: 0; }