From 98c7ed67fb00c3eac8f1baa3ea24bc903f83e550 Mon Sep 17 00:00:00 2001 From: Mark Mansi Date: Tue, 3 Mar 2020 12:29:07 -0600 Subject: [PATCH 01/30] DefKind::Method -> DefKind::AssocFn --- src/librustc/hir/map/mod.rs | 4 ++-- src/librustc/middle/stability.rs | 2 +- src/librustc/ty/context.rs | 2 +- src/librustc/ty/mod.rs | 6 +++--- src/librustc_ast_lowering/path.rs | 2 +- src/librustc_hir/def.rs | 7 ++++--- src/librustc_infer/infer/error_reporting/need_type_info.rs | 2 +- src/librustc_lint/unused.rs | 2 +- src/librustc_metadata/rmeta/decoder.rs | 2 +- src/librustc_mir/util/pretty.rs | 2 +- src/librustc_mir_build/hair/cx/expr.rs | 4 ++-- src/librustc_privacy/lib.rs | 4 ++-- src/librustc_resolve/build_reduced_graph.rs | 6 +++--- src/librustc_resolve/late.rs | 4 ++-- src/librustc_resolve/late/diagnostics.rs | 2 +- src/librustc_resolve/lib.rs | 2 +- src/librustc_save_analysis/lib.rs | 2 +- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/check/generator_interior.rs | 2 +- src/librustc_typeck/check/mod.rs | 4 ++-- src/librustc_typeck/check/pat.rs | 6 +++--- src/librustc_typeck/mem_categorization.rs | 2 +- src/librustdoc/passes/collect_intra_doc_links.rs | 4 ++-- 23 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 4f7c4153ea173..2374d47ae8ee7 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -326,12 +326,12 @@ impl<'hir> Map<'hir> { }, Node::TraitItem(item) => match item.kind { TraitItemKind::Const(..) => DefKind::AssocConst, - TraitItemKind::Method(..) => DefKind::Method, + TraitItemKind::Method(..) => DefKind::AssocFn, TraitItemKind::Type(..) => DefKind::AssocTy, }, Node::ImplItem(item) => match item.kind { ImplItemKind::Const(..) => DefKind::AssocConst, - ImplItemKind::Method(..) => DefKind::Method, + ImplItemKind::Method(..) => DefKind::AssocFn, ImplItemKind::TyAlias(..) => DefKind::AssocTy, ImplItemKind::OpaqueTy(..) => DefKind::AssocOpaqueTy, }, diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 9d3df9623bd62..1f6725fb3950f 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -250,7 +250,7 @@ pub enum EvalResult { fn skip_stability_check_due_to_privacy(tcx: TyCtxt<'_>, mut def_id: DefId) -> bool { // Check if `def_id` is a trait method. match tcx.def_kind(def_id) { - Some(DefKind::Method) | Some(DefKind::AssocTy) | Some(DefKind::AssocConst) => { + Some(DefKind::AssocFn) | Some(DefKind::AssocTy) | Some(DefKind::AssocConst) => { if let ty::TraitContainer(trait_def_id) = tcx.associated_item(def_id).container { // Trait methods do not declare visibility (even // for visibility info in cstore). Use containing diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 20736b50831bb..ec9ff55ffe431 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -611,7 +611,7 @@ impl<'tcx> TypeckTables<'tcx> { } match self.type_dependent_defs().get(expr.hir_id) { - Some(Ok((DefKind::Method, _))) => true, + Some(Ok((DefKind::AssocFn, _))) => true, _ => false, } } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index b25fd3c61fd5d..546686c20caa7 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -230,7 +230,7 @@ impl AssocItem { pub fn def_kind(&self) -> DefKind { match self.kind { AssocKind::Const => DefKind::AssocConst, - AssocKind::Method => DefKind::Method, + AssocKind::Method => DefKind::AssocFn, AssocKind::Type => DefKind::AssocTy, AssocKind::OpaqueTy => DefKind::AssocOpaqueTy, } @@ -2872,7 +2872,7 @@ impl<'tcx> TyCtxt<'tcx> { } } else { match self.def_kind(def_id).expect("no def for `DefId`") { - DefKind::AssocConst | DefKind::Method | DefKind::AssocTy => true, + DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy => true, _ => false, } }; @@ -3051,7 +3051,7 @@ impl<'tcx> TyCtxt<'tcx> { /// `DefId` of the impl that the method belongs to; otherwise, returns `None`. pub fn impl_of_method(self, def_id: DefId) -> Option { let item = if def_id.krate != LOCAL_CRATE { - if let Some(DefKind::Method) = self.def_kind(def_id) { + if let Some(DefKind::AssocFn) = self.def_kind(def_id) { Some(self.associated_item(def_id)) } else { None diff --git a/src/librustc_ast_lowering/path.rs b/src/librustc_ast_lowering/path.rs index 80d7e3d0d465a..db8517bfbf0c7 100644 --- a/src/librustc_ast_lowering/path.rs +++ b/src/librustc_ast_lowering/path.rs @@ -75,7 +75,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { ParenthesizedGenericArgs::Ok } // `a::b::Trait(Args)::TraitItem` - Res::Def(DefKind::Method, _) + Res::Def(DefKind::AssocFn, _) | Res::Def(DefKind::AssocConst, _) | Res::Def(DefKind::AssocTy, _) if i + 2 == proj_start => diff --git a/src/librustc_hir/def.rs b/src/librustc_hir/def.rs index 595543eaf535f..5b2c1453de642 100644 --- a/src/librustc_hir/def.rs +++ b/src/librustc_hir/def.rs @@ -72,7 +72,7 @@ pub enum DefKind { Static, /// Refers to the struct or enum variant's constructor. Ctor(CtorOf, CtorKind), - Method, + AssocFn, AssocConst, // Macro namespace @@ -107,7 +107,8 @@ impl DefKind { DefKind::Union => "union", DefKind::Trait => "trait", DefKind::ForeignTy => "foreign type", - DefKind::Method => "method", + // FIXME: Update the description to "assoc fn" + DefKind::AssocFn => "method", DefKind::Const => "constant", DefKind::AssocConst => "associated constant", DefKind::TyParam => "type parameter", @@ -150,7 +151,7 @@ impl DefKind { | DefKind::ConstParam | DefKind::Static | DefKind::Ctor(..) - | DefKind::Method + | DefKind::AssocFn | DefKind::AssocConst => ns == Namespace::ValueNS, DefKind::Macro(..) => ns == Namespace::MacroNS, diff --git a/src/librustc_infer/infer/error_reporting/need_type_info.rs b/src/librustc_infer/infer/error_reporting/need_type_info.rs index a1e6a0a325ada..56f8c8c2b9c76 100644 --- a/src/librustc_infer/infer/error_reporting/need_type_info.rs +++ b/src/librustc_infer/infer/error_reporting/need_type_info.rs @@ -468,7 +468,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { &segment.args, ) { let borrow = tables.borrow(); - if let Some((DefKind::Method, did)) = borrow.type_dependent_def(e.hir_id) { + if let Some((DefKind::AssocFn, did)) = borrow.type_dependent_def(e.hir_id) { let generics = self.tcx.generics_of(did); if !generics.params.is_empty() { err.span_suggestion( diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 02f04b2345932..49d05819c5ec9 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -54,7 +54,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { match callee.kind { hir::ExprKind::Path(ref qpath) => { match cx.tables.qpath_res(qpath, callee.hir_id) { - Res::Def(DefKind::Fn, def_id) | Res::Def(DefKind::Method, def_id) => { + Res::Def(DefKind::Fn, def_id) | Res::Def(DefKind::AssocFn, def_id) => { Some(def_id) } // `Res::Local` if it was a closure, for which we diff --git a/src/librustc_metadata/rmeta/decoder.rs b/src/librustc_metadata/rmeta/decoder.rs index a72ee0cbe4729..d0a35c6156436 100644 --- a/src/librustc_metadata/rmeta/decoder.rs +++ b/src/librustc_metadata/rmeta/decoder.rs @@ -504,7 +504,7 @@ impl EntryKind { EntryKind::Struct(_, _) => DefKind::Struct, EntryKind::Union(_, _) => DefKind::Union, EntryKind::Fn(_) | EntryKind::ForeignFn(_) => DefKind::Fn, - EntryKind::Method(_) => DefKind::Method, + EntryKind::Method(_) => DefKind::AssocFn, EntryKind::Type => DefKind::TyAlias, EntryKind::TypeParam => DefKind::TyParam, EntryKind::ConstParam => DefKind::ConstParam, diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index 6fd8f06fe8f25..ee8de0e6b9311 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -545,7 +545,7 @@ fn write_mir_sig( trace!("write_mir_sig: {:?}", src.instance); let kind = tcx.def_kind(src.def_id()); let is_function = match kind { - Some(DefKind::Fn) | Some(DefKind::Method) | Some(DefKind::Ctor(..)) => true, + Some(DefKind::Fn) | Some(DefKind::AssocFn) | Some(DefKind::Ctor(..)) => true, _ => tcx.is_closure(src.def_id()), }; match (kind, src.promoted) { diff --git a/src/librustc_mir_build/hair/cx/expr.rs b/src/librustc_mir_build/hair/cx/expr.rs index 46d49b6b4933f..9f04bc1dc7697 100644 --- a/src/librustc_mir_build/hair/cx/expr.rs +++ b/src/librustc_mir_build/hair/cx/expr.rs @@ -600,7 +600,7 @@ fn user_substs_applied_to_res<'tcx>( // a tuple-struct or tuple-variant. This has the type of a // `Fn` but with the user-given substitutions. Res::Def(DefKind::Fn, _) - | Res::Def(DefKind::Method, _) + | Res::Def(DefKind::AssocFn, _) | Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) | Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssocConst, _) => { @@ -703,7 +703,7 @@ fn convert_path_expr<'a, 'tcx>( match res { // A regular function, constructor function or a constant. Res::Def(DefKind::Fn, _) - | Res::Def(DefKind::Method, _) + | Res::Def(DefKind::AssocFn, _) | Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) | Res::SelfCtor(..) => { let user_ty = user_substs_applied_to_res(cx, expr.hir_id, res); diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 24696b203326f..175b2390d3083 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -620,7 +620,7 @@ impl EmbargoVisitor<'tcx> { | DefKind::ForeignTy | DefKind::Fn | DefKind::OpaqueTy - | DefKind::Method + | DefKind::AssocFn | DefKind::Trait | DefKind::TyParam | DefKind::Variant => (), @@ -1298,7 +1298,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> { _ => None, }; let def = def.filter(|(kind, _)| match kind { - DefKind::Method + DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy | DefKind::AssocOpaqueTy diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 86816fd9f3a2a..1fc99e40d8303 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -887,7 +887,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { | Res::PrimTy(..) | Res::ToolMod => self.r.define(parent, ident, TypeNS, (res, vis, span, expansion)), Res::Def(DefKind::Fn, _) - | Res::Def(DefKind::Method, _) + | Res::Def(DefKind::AssocFn, _) | Res::Def(DefKind::Static, _) | Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssocConst, _) @@ -911,7 +911,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { let field_names = cstore.struct_field_names_untracked(def_id, self.r.session); self.insert_field_names(def_id, field_names); } - Res::Def(DefKind::Method, def_id) => { + Res::Def(DefKind::AssocFn, def_id) => { if cstore.associated_item_cloned_untracked(def_id).method_has_self_argument { self.r.has_self.insert(def_id); } @@ -1257,7 +1257,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> { if sig.decl.has_self() { self.r.has_self.insert(item_def_id); } - (Res::Def(DefKind::Method, item_def_id), ValueNS) + (Res::Def(DefKind::AssocFn, item_def_id), ValueNS) } AssocItemKind::TyAlias(..) => (Res::Def(DefKind::AssocTy, item_def_id), TypeNS), AssocItemKind::Macro(_) => bug!(), // handled above diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index e5aa9c7d8962a..640b07d3d62be 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -266,7 +266,7 @@ impl<'a> PathSource<'a> { | Res::Def(DefKind::Static, _) | Res::Local(..) | Res::Def(DefKind::Fn, _) - | Res::Def(DefKind::Method, _) + | Res::Def(DefKind::AssocFn, _) | Res::Def(DefKind::AssocConst, _) | Res::SelfCtor(..) | Res::Def(DefKind::ConstParam, _) => true, @@ -293,7 +293,7 @@ impl<'a> PathSource<'a> { _ => false, }, PathSource::TraitItem(ns) => match res { - Res::Def(DefKind::AssocConst, _) | Res::Def(DefKind::Method, _) + Res::Def(DefKind::AssocConst, _) | Res::Def(DefKind::AssocFn, _) if ns == ValueNS => { true diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index 817a276ff3e73..a9463d970ce4b 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -124,7 +124,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> { .unwrap_or(false) } Res::Def(DefKind::Ctor(..), _) - | Res::Def(DefKind::Method, _) + | Res::Def(DefKind::AssocFn, _) | Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssocConst, _) | Res::SelfCtor(_) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 44eba0d533d3a..3a39331446344 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -742,7 +742,7 @@ impl<'a> NameBinding<'a> { fn is_importable(&self) -> bool { match self.res() { Res::Def(DefKind::AssocConst, _) - | Res::Def(DefKind::Method, _) + | Res::Def(DefKind::AssocFn, _) | Res::Def(DefKind::AssocTy, _) => false, _ => true, } diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index c68289adb1059..2bd335421e0f4 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -716,7 +716,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> { | Res::Def(HirDefKind::Ctor(..), _) => { Some(Ref { kind: RefKind::Variable, span, ref_id: id_from_def_id(res.def_id()) }) } - Res::Def(HirDefKind::Method, decl_id) => { + Res::Def(HirDefKind::AssocFn, decl_id) => { let def_id = if decl_id.is_local() { let ti = self.tcx.associated_item(decl_id); diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 199b476cb9a3e..d59923a0019f4 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -2588,7 +2588,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } // Case 4. Reference to a method or associated const. - DefKind::Method | DefKind::AssocConst => { + DefKind::AssocFn | DefKind::AssocConst => { if segments.len() >= 2 { let generics = tcx.generics_of(def_id); path_segs.push(PathSeg(generics.parent.unwrap(), last - 1)); diff --git a/src/librustc_typeck/check/generator_interior.rs b/src/librustc_typeck/check/generator_interior.rs index 50692e0f10487..7e52657377393 100644 --- a/src/librustc_typeck/check/generator_interior.rs +++ b/src/librustc_typeck/check/generator_interior.rs @@ -237,7 +237,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> { // ZST in a temporary, so skip its type, just in case it // can significantly complicate the generator type. Res::Def(DefKind::Fn, _) - | Res::Def(DefKind::Method, _) + | Res::Def(DefKind::AssocFn, _) | Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) => { // NOTE(eddyb) this assumes a path expression has // no nested expressions to keep track of. diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index b7353c6af267a..fd5cac5b24bf1 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2976,7 +2976,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn write_method_call(&self, hir_id: hir::HirId, method: MethodCallee<'tcx>) { debug!("write_method_call(hir_id={:?}, method={:?})", hir_id, method); - self.write_resolution(hir_id, Ok((DefKind::Method, method.def_id))); + self.write_resolution(hir_id, Ok((DefKind::AssocFn, method.def_id))); self.write_substs(hir_id, method.substs); // When the method is confirmed, the `method.substs` includes @@ -5364,7 +5364,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { is_alias_variant_ctor = true; } } - Res::Def(DefKind::Method, def_id) | Res::Def(DefKind::AssocConst, def_id) => { + Res::Def(DefKind::AssocFn, def_id) | Res::Def(DefKind::AssocConst, def_id) => { let container = tcx.associated_item(def_id).container; debug!("instantiate_value_path: def_id={:?} container={:?}", def_id, container); match container { diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index b7aac707a9838..c50274d19e3f6 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -682,7 +682,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.set_tainted_by_errors(); return tcx.types.err; } - Res::Def(DefKind::Method, _) + Res::Def(DefKind::AssocFn, _) | Res::Def(DefKind::Ctor(_, CtorKind::Fictive), _) | Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) => { report_unexpected_variant_res(tcx, res, pat.span, qpath); @@ -729,7 +729,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); let mut err = struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg); match (res, &pat.kind) { - (Res::Def(DefKind::Fn, _), _) | (Res::Def(DefKind::Method, _), _) => { + (Res::Def(DefKind::Fn, _), _) | (Res::Def(DefKind::AssocFn, _), _) => { err.span_label(pat.span, "`fn` calls are not allowed in patterns"); err.help( "for more information, visit \ @@ -766,7 +766,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { on_error(); return tcx.types.err; } - Res::Def(DefKind::AssocConst, _) | Res::Def(DefKind::Method, _) => { + Res::Def(DefKind::AssocConst, _) | Res::Def(DefKind::AssocFn, _) => { report_unexpected_res(res); return tcx.types.err; } diff --git a/src/librustc_typeck/mem_categorization.rs b/src/librustc_typeck/mem_categorization.rs index a4569a147567f..8e06948a10953 100644 --- a/src/librustc_typeck/mem_categorization.rs +++ b/src/librustc_typeck/mem_categorization.rs @@ -425,7 +425,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { | Res::Def(DefKind::ConstParam, _) | Res::Def(DefKind::AssocConst, _) | Res::Def(DefKind::Fn, _) - | Res::Def(DefKind::Method, _) + | Res::Def(DefKind::AssocFn, _) | Res::SelfCtor(..) => Ok(self.cat_rvalue(hir_id, span, expr_ty)), Res::Def(DefKind::Static, _) => Ok(Place { diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 7aa90d667813f..75355b84fee83 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -149,7 +149,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { // In case this is a trait item, skip the // early return and try looking for the trait. let value = match res { - Res::Def(DefKind::Method, _) | Res::Def(DefKind::AssocConst, _) => true, + Res::Def(DefKind::AssocFn, _) | Res::Def(DefKind::AssocConst, _) => true, Res::Def(DefKind::AssocTy, _) => false, Res::Def(DefKind::Variant, _) => { return handle_variant(cx, res, extra_fragment); @@ -813,7 +813,7 @@ fn ambiguity_error( for (res, ns) in candidates { let (action, mut suggestion) = match res { - Res::Def(DefKind::Method, _) | Res::Def(DefKind::Fn, _) => { + Res::Def(DefKind::AssocFn, _) | Res::Def(DefKind::Fn, _) => { ("add parentheses", format!("{}()", path_str)) } Res::Def(DefKind::Macro(..), _) => { From 3aeb9f0fafd33a425a67b7ee44f30f98dde64642 Mon Sep 17 00:00:00 2001 From: Mark Mansi Date: Tue, 3 Mar 2020 12:46:22 -0600 Subject: [PATCH 02/30] rename TraitItemKind::Method -> Fn --- src/librustc/hir/map/blocks.rs | 4 ++-- src/librustc/hir/map/mod.rs | 14 +++++++------- src/librustc_ast_lowering/item.rs | 4 ++-- src/librustc_hir/hir.rs | 6 +++--- src/librustc_hir/intravisit.rs | 4 ++-- src/librustc_hir/print.rs | 4 ++-- src/librustc_hir/target.rs | 4 ++-- src/librustc_incremental/persist/dirty_clean.rs | 2 +- src/librustc_infer/infer/error_reporting/mod.rs | 2 +- .../nice_region_error/find_anon_type.rs | 2 +- .../traits/error_reporting/on_unimplemented.rs | 2 +- .../traits/error_reporting/suggestions.rs | 6 +++--- src/librustc_lint/builtin.rs | 2 +- src/librustc_lint/nonstandard_style.rs | 2 +- src/librustc_metadata/rmeta/encoder.rs | 2 +- .../borrow_check/diagnostics/mutability_errors.rs | 4 ++-- src/librustc_mir_build/build/mod.rs | 2 +- src/librustc_passes/dead.rs | 6 +++--- src/librustc_passes/reachable.rs | 8 ++++---- src/librustc_resolve/late/lifetimes.rs | 9 +++------ src/librustc_traits/lowering/environment.rs | 2 +- src/librustc_typeck/check/compare_method.rs | 10 +++++----- src/librustc_typeck/check/method/suggest.rs | 2 +- src/librustc_typeck/check/mod.rs | 10 +++++----- src/librustc_typeck/check/wfcheck.rs | 4 ++-- src/librustc_typeck/collect.rs | 8 ++++---- src/librustc_typeck/collect/type_of.rs | 2 +- src/librustc_typeck/variance/constraints.rs | 2 +- src/librustc_typeck/variance/mod.rs | 2 +- src/librustc_typeck/variance/terms.rs | 2 +- src/librustdoc/clean/mod.rs | 4 ++-- 31 files changed, 67 insertions(+), 70 deletions(-) diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index 618f9a018d1e7..d9ffe4582e7d7 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -60,7 +60,7 @@ impl MaybeFnLike for hir::ImplItem<'_> { impl MaybeFnLike for hir::TraitItem<'_> { fn is_fn_like(&self) -> bool { match self.kind { - hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => true, + hir::TraitItemKind::Fn(_, hir::TraitMethod::Provided(_)) => true, _ => false, } } @@ -239,7 +239,7 @@ impl<'a> FnLikeNode<'a> { _ => bug!("item FnLikeNode that is not fn-like"), }, Node::TraitItem(ti) => match ti.kind { - hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => { + hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::Provided(body)) => { method(ti.hir_id, ti.ident, sig, None, body, ti.span, &ti.attrs) } _ => bug!("trait method FnLikeNode that is not fn-like"), diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 2374d47ae8ee7..9d2cc1877e407 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -51,7 +51,7 @@ impl<'hir> Entry<'hir> { }, Node::TraitItem(ref item) => match item.kind { - TraitItemKind::Method(ref sig, _) => Some(&sig.decl), + TraitItemKind::Fn(ref sig, _) => Some(&sig.decl), _ => None, }, @@ -77,7 +77,7 @@ impl<'hir> Entry<'hir> { }, Node::TraitItem(item) => match &item.kind { - TraitItemKind::Method(sig, _) => Some(sig), + TraitItemKind::Fn(sig, _) => Some(sig), _ => None, }, @@ -101,7 +101,7 @@ impl<'hir> Entry<'hir> { Node::TraitItem(item) => match item.kind { TraitItemKind::Const(_, Some(body)) - | TraitItemKind::Method(_, TraitMethod::Provided(body)) => Some(body), + | TraitItemKind::Fn(_, TraitMethod::Provided(body)) => Some(body), _ => None, }, @@ -326,7 +326,7 @@ impl<'hir> Map<'hir> { }, Node::TraitItem(item) => match item.kind { TraitItemKind::Const(..) => DefKind::AssocConst, - TraitItemKind::Method(..) => DefKind::AssocFn, + TraitItemKind::Fn(..) => DefKind::AssocFn, TraitItemKind::Type(..) => DefKind::AssocTy, }, Node::ImplItem(item) => match item.kind { @@ -473,7 +473,7 @@ impl<'hir> Map<'hir> { | Node::AnonConst(_) => BodyOwnerKind::Const, Node::Ctor(..) | Node::Item(&Item { kind: ItemKind::Fn(..), .. }) - | Node::TraitItem(&TraitItem { kind: TraitItemKind::Method(..), .. }) + | Node::TraitItem(&TraitItem { kind: TraitItemKind::Fn(..), .. }) | Node::ImplItem(&ImplItem { kind: ImplItemKind::Method(..), .. }) => BodyOwnerKind::Fn, Node::Item(&Item { kind: ItemKind::Static(_, m, _), .. }) => BodyOwnerKind::Static(m), Node::Expr(&Expr { kind: ExprKind::Closure(..), .. }) => BodyOwnerKind::Closure, @@ -801,7 +801,7 @@ impl<'hir> Map<'hir> { _ => false, }, Node::TraitItem(ti) => match ti.kind { - TraitItemKind::Method(..) => true, + TraitItemKind::Fn(..) => true, _ => false, }, Node::ImplItem(ii) => match ii.kind { @@ -1312,7 +1312,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String { Some(Node::TraitItem(ti)) => { let kind = match ti.kind { TraitItemKind::Const(..) => "assoc constant", - TraitItemKind::Method(..) => "trait method", + TraitItemKind::Fn(..) => "trait method", TraitItemKind::Type(..) => "assoc type", }; diff --git a/src/librustc_ast_lowering/item.rs b/src/librustc_ast_lowering/item.rs index 13148d97a67f3..f732f645dc07d 100644 --- a/src/librustc_ast_lowering/item.rs +++ b/src/librustc_ast_lowering/item.rs @@ -767,13 +767,13 @@ impl<'hir> LoweringContext<'_, 'hir> { let names = self.lower_fn_params_to_names(&sig.decl); let (generics, sig) = self.lower_method_sig(generics, sig, trait_item_def_id, false, None); - (generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Required(names))) + (generics, hir::TraitItemKind::Fn(sig, hir::TraitMethod::Required(names))) } AssocItemKind::Fn(_, ref sig, ref generics, Some(ref body)) => { let body_id = self.lower_fn_body_block(i.span, &sig.decl, Some(body)); let (generics, sig) = self.lower_method_sig(generics, sig, trait_item_def_id, false, None); - (generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Provided(body_id))) + (generics, hir::TraitItemKind::Fn(sig, hir::TraitMethod::Provided(body_id))) } AssocItemKind::TyAlias(_, ref generics, ref bounds, ref default) => { let ty = default.as_ref().map(|x| self.lower_ty(x, ImplTraitContext::disallowed())); diff --git a/src/librustc_hir/hir.rs b/src/librustc_hir/hir.rs index f948e22e84b10..5a83c65204cc4 100644 --- a/src/librustc_hir/hir.rs +++ b/src/librustc_hir/hir.rs @@ -1863,8 +1863,8 @@ pub enum TraitMethod<'hir> { pub enum TraitItemKind<'hir> { /// An associated constant with an optional value (otherwise `impl`s must contain a value). Const(&'hir Ty<'hir>, Option), - /// A method with an optional body. - Method(FnSig<'hir>, TraitMethod<'hir>), + /// An associated function with an optional body. + Fn(FnSig<'hir>, TraitMethod<'hir>), /// An associated type with (possibly empty) bounds and optional concrete /// type. Type(GenericBounds<'hir>, Option<&'hir Ty<'hir>>), @@ -2699,7 +2699,7 @@ impl Node<'_> { pub fn fn_decl(&self) -> Option<&FnDecl<'_>> { match self { - Node::TraitItem(TraitItem { kind: TraitItemKind::Method(fn_sig, _), .. }) + Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(fn_sig, _), .. }) | Node::ImplItem(ImplItem { kind: ImplItemKind::Method(fn_sig, _), .. }) | Node::Item(Item { kind: ItemKind::Fn(fn_sig, _, _), .. }) => Some(fn_sig.decl), Node::ForeignItem(ForeignItem { kind: ForeignItemKind::Fn(fn_decl, _, _), .. }) => { diff --git a/src/librustc_hir/intravisit.rs b/src/librustc_hir/intravisit.rs index 45257b04d7907..e92192c8b1f72 100644 --- a/src/librustc_hir/intravisit.rs +++ b/src/librustc_hir/intravisit.rs @@ -911,14 +911,14 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai visitor.visit_ty(ty); walk_list!(visitor, visit_nested_body, default); } - TraitItemKind::Method(ref sig, TraitMethod::Required(param_names)) => { + TraitItemKind::Fn(ref sig, TraitMethod::Required(param_names)) => { visitor.visit_id(trait_item.hir_id); visitor.visit_fn_decl(&sig.decl); for ¶m_name in param_names { visitor.visit_ident(param_name); } } - TraitItemKind::Method(ref sig, TraitMethod::Provided(body_id)) => { + TraitItemKind::Fn(ref sig, TraitMethod::Provided(body_id)) => { visitor.visit_fn( FnKind::Method(trait_item.ident, sig, None, &trait_item.attrs), &sig.decl, diff --git a/src/librustc_hir/print.rs b/src/librustc_hir/print.rs index 8cbbef959ce75..7738548dadef2 100644 --- a/src/librustc_hir/print.rs +++ b/src/librustc_hir/print.rs @@ -886,13 +886,13 @@ impl<'a> State<'a> { Spanned { span: rustc_span::DUMMY_SP, node: hir::VisibilityKind::Inherited }; self.print_associated_const(ti.ident, &ty, default, &vis); } - hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Required(ref arg_names)) => { + hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::Required(ref arg_names)) => { let vis = Spanned { span: rustc_span::DUMMY_SP, node: hir::VisibilityKind::Inherited }; self.print_method_sig(ti.ident, sig, &ti.generics, &vis, arg_names, None); self.s.word(";"); } - hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => { + hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::Provided(body)) => { let vis = Spanned { span: rustc_span::DUMMY_SP, node: hir::VisibilityKind::Inherited }; self.head(""); diff --git a/src/librustc_hir/target.rs b/src/librustc_hir/target.rs index 501976fc3cb39..b7bc555d7b410 100644 --- a/src/librustc_hir/target.rs +++ b/src/librustc_hir/target.rs @@ -105,10 +105,10 @@ impl Target { pub fn from_trait_item(trait_item: &TraitItem<'_>) -> Target { match trait_item.kind { TraitItemKind::Const(..) => Target::AssocConst, - TraitItemKind::Method(_, hir::TraitMethod::Required(_)) => { + TraitItemKind::Fn(_, hir::TraitMethod::Required(_)) => { Target::Method(MethodKind::Trait { body: false }) } - TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => { + TraitItemKind::Fn(_, hir::TraitMethod::Provided(_)) => { Target::Method(MethodKind::Trait { body: true }) } TraitItemKind::Type(..) => Target::AssocTy, diff --git a/src/librustc_incremental/persist/dirty_clean.rs b/src/librustc_incremental/persist/dirty_clean.rs index f304292d922e5..86c3fbcf8c7c1 100644 --- a/src/librustc_incremental/persist/dirty_clean.rs +++ b/src/librustc_incremental/persist/dirty_clean.rs @@ -328,7 +328,7 @@ impl DirtyCleanVisitor<'tcx> { } } HirNode::TraitItem(item) => match item.kind { - TraitItemKind::Method(..) => ("Node::TraitItem", LABELS_FN_IN_TRAIT), + TraitItemKind::Fn(..) => ("Node::TraitItem", LABELS_FN_IN_TRAIT), TraitItemKind::Const(..) => ("NodeTraitConst", LABELS_CONST_IN_TRAIT), TraitItemKind::Type(..) => ("NodeTraitType", LABELS_CONST_IN_TRAIT), }, diff --git a/src/librustc_infer/infer/error_reporting/mod.rs b/src/librustc_infer/infer/error_reporting/mod.rs index bd133738db7ab..9185c46702308 100644 --- a/src/librustc_infer/infer/error_reporting/mod.rs +++ b/src/librustc_infer/infer/error_reporting/mod.rs @@ -269,7 +269,7 @@ fn item_scope_tag(item: &hir::Item<'_>) -> &'static str { fn trait_item_scope_tag(item: &hir::TraitItem<'_>) -> &'static str { match item.kind { - hir::TraitItemKind::Method(..) => "method body", + hir::TraitItemKind::Fn(..) => "method body", hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => "associated item", } } diff --git a/src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs b/src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs index 2ae7f4cc04f98..7346cb0a03393 100644 --- a/src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -33,7 +33,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { let fndecl = match self.tcx().hir().get(hir_id) { Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. }) | Node::TraitItem(&hir::TraitItem { - kind: hir::TraitItemKind::Method(ref m, ..), + kind: hir::TraitItemKind::Fn(ref m, ..), .. }) | Node::ImplItem(&hir::ImplItem { diff --git a/src/librustc_infer/traits/error_reporting/on_unimplemented.rs b/src/librustc_infer/traits/error_reporting/on_unimplemented.rs index 87c1107bd427d..eb34a4875961c 100644 --- a/src/librustc_infer/traits/error_reporting/on_unimplemented.rs +++ b/src/librustc_infer/traits/error_reporting/on_unimplemented.rs @@ -70,7 +70,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { }) } hir::Node::TraitItem(hir::TraitItem { - kind: hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(body_id)), + kind: hir::TraitItemKind::Fn(_, hir::TraitMethod::Provided(body_id)), .. }) => self.describe_generator(*body_id).or_else(|| Some("a trait method")), hir::Node::ImplItem(hir::ImplItem { diff --git a/src/librustc_infer/traits/error_reporting/suggestions.rs b/src/librustc_infer/traits/error_reporting/suggestions.rs index ed6cfa51cdf18..e8575cd2c47e1 100644 --- a/src/librustc_infer/traits/error_reporting/suggestions.rs +++ b/src/librustc_infer/traits/error_reporting/suggestions.rs @@ -62,7 +62,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { match node { hir::Node::TraitItem(hir::TraitItem { generics, - kind: hir::TraitItemKind::Method(..), + kind: hir::TraitItemKind::Fn(..), .. }) if param_ty && self_ty == self.tcx.types.self_param => { // Restricting `Self` for a single method. @@ -73,7 +73,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, generics, _), .. }) | hir::Node::TraitItem(hir::TraitItem { generics, - kind: hir::TraitItemKind::Method(..), + kind: hir::TraitItemKind::Fn(..), .. }) | hir::Node::ImplItem(hir::ImplItem { @@ -807,7 +807,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { }) | Node::TraitItem(&hir::TraitItem { span, - kind: hir::TraitItemKind::Method(ref sig, _), + kind: hir::TraitItemKind::Fn(ref sig, _), .. }) => ( self.tcx.sess.source_map().def_span(span), diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 3eecd2a54e33e..c8bffc4d445a6 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -465,7 +465,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { let desc = match trait_item.kind { hir::TraitItemKind::Const(..) => "an associated constant", - hir::TraitItemKind::Method(..) => "a trait method", + hir::TraitItemKind::Fn(..) => "a trait method", hir::TraitItemKind::Type(..) => "an associated type", }; diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index b0560dc9fdf9c..37fefe680d7d2 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -343,7 +343,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase { } fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::TraitItem<'_>) { - if let hir::TraitItemKind::Method(_, hir::TraitMethod::Required(pnames)) = item.kind { + if let hir::TraitItemKind::Fn(_, hir::TraitMethod::Required(pnames)) = item.kind { self.check_snake_case(cx, "trait method", &item.ident); for param_name in pnames { self.check_snake_case(cx, "variable", param_name); diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index ea0cc2f0c8bf2..b89cd0792b893 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -805,7 +805,7 @@ impl EncodeContext<'tcx> { ) } ty::AssocKind::Method => { - let fn_data = if let hir::TraitItemKind::Method(m_sig, m) = &ast_item.kind { + let fn_data = if let hir::TraitItemKind::Fn(m_sig, m) = &ast_item.kind { let param_names = match *m { hir::TraitMethod::Required(ref names) => { self.encode_fn_param_names(names) diff --git a/src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs b/src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs index d91f6edc9800c..7ebc164e49c56 100644 --- a/src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs @@ -478,7 +478,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { })) | Some(hir::Node::TraitItem(hir::TraitItem { ident, - kind: hir::TraitItemKind::Method(sig, _), + kind: hir::TraitItemKind::Fn(sig, _), .. })) | Some(hir::Node::ImplItem(hir::ImplItem { @@ -520,7 +520,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { hir::Node::Item(hir::Item { ident, kind: hir::ItemKind::Fn(sig, ..), .. }) | hir::Node::TraitItem(hir::TraitItem { ident, - kind: hir::TraitItemKind::Method(sig, _), + kind: hir::TraitItemKind::Fn(sig, _), .. }) | hir::Node::ImplItem(hir::ImplItem { diff --git a/src/librustc_mir_build/build/mod.rs b/src/librustc_mir_build/build/mod.rs index 830877f713e4b..4cd1efe4ef912 100644 --- a/src/librustc_mir_build/build/mod.rs +++ b/src/librustc_mir_build/build/mod.rs @@ -44,7 +44,7 @@ fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> BodyAndCache<'_> { }) | Node::TraitItem(hir::TraitItem { kind: - hir::TraitItemKind::Method(hir::FnSig { decl, .. }, hir::TraitMethod::Provided(body_id)), + hir::TraitItemKind::Fn(hir::FnSig { decl, .. }, hir::TraitMethod::Provided(body_id)), .. }) => (*body_id, decl.output.span()), Node::Item(hir::Item { kind: hir::ItemKind::Static(ty, _, body_id), .. }) diff --git a/src/librustc_passes/dead.rs b/src/librustc_passes/dead.rs index bcf9fd5a5353f..4a0ffc23365da 100644 --- a/src/librustc_passes/dead.rs +++ b/src/librustc_passes/dead.rs @@ -391,7 +391,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> { let trait_item = self.krate.trait_item(trait_item_ref.id); match trait_item.kind { hir::TraitItemKind::Const(_, Some(_)) - | hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => { + | hir::TraitItemKind::Fn(_, hir::TraitMethod::Provided(_)) => { if has_allow_dead_code_or_lang_attr( self.tcx, trait_item.hir_id, @@ -682,11 +682,11 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> { fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { match trait_item.kind { hir::TraitItemKind::Const(_, Some(body_id)) - | hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(body_id)) => { + | hir::TraitItemKind::Fn(_, hir::TraitMethod::Provided(body_id)) => { self.visit_nested_body(body_id) } hir::TraitItemKind::Const(_, None) - | hir::TraitItemKind::Method(_, hir::TraitMethod::Required(_)) + | hir::TraitItemKind::Fn(_, hir::TraitMethod::Required(_)) | hir::TraitItemKind::Type(..) => {} } } diff --git a/src/librustc_passes/reachable.rs b/src/librustc_passes/reachable.rs index 888f4370dd5e8..79a9f22603042 100644 --- a/src/librustc_passes/reachable.rs +++ b/src/librustc_passes/reachable.rs @@ -162,8 +162,8 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { }, Some(Node::TraitItem(trait_method)) => match trait_method.kind { hir::TraitItemKind::Const(_, ref default) => default.is_some(), - hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(_)) => true, - hir::TraitItemKind::Method(_, hir::TraitMethod::Required(_)) + hir::TraitItemKind::Fn(_, hir::TraitMethod::Provided(_)) => true, + hir::TraitItemKind::Fn(_, hir::TraitMethod::Required(_)) | hir::TraitItemKind::Type(..) => false, }, Some(Node::ImplItem(impl_item)) => { @@ -278,11 +278,11 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { Node::TraitItem(trait_method) => { match trait_method.kind { hir::TraitItemKind::Const(_, None) - | hir::TraitItemKind::Method(_, hir::TraitMethod::Required(_)) => { + | hir::TraitItemKind::Fn(_, hir::TraitMethod::Required(_)) => { // Keep going, nothing to get exported } hir::TraitItemKind::Const(_, Some(body_id)) - | hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(body_id)) => { + | hir::TraitItemKind::Fn(_, hir::TraitMethod::Provided(body_id)) => { self.visit_nested_body(body_id); } hir::TraitItemKind::Type(..) => {} diff --git a/src/librustc_resolve/late/lifetimes.rs b/src/librustc_resolve/late/lifetimes.rs index 193b6d75935b2..280acfe8c4872 100644 --- a/src/librustc_resolve/late/lifetimes.rs +++ b/src/librustc_resolve/late/lifetimes.rs @@ -713,7 +713,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { use self::hir::TraitItemKind::*; self.missing_named_lifetime_spots.push((&trait_item.generics).into()); match trait_item.kind { - Method(ref sig, _) => { + Fn(ref sig, _) => { let tcx = self.tcx; self.visit_early_late( Some(tcx.hir().get_parent_item(trait_item.hir_id)), @@ -1816,8 +1816,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { match self.tcx.hir().get(fn_id) { Node::Item(&hir::Item { kind: hir::ItemKind::Fn(..), .. }) | Node::TraitItem(&hir::TraitItem { - kind: hir::TraitItemKind::Method(..), - .. + kind: hir::TraitItemKind::Fn(..), .. }) | Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Method(..), .. @@ -2093,9 +2092,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { // `fn` definitions and methods. Node::Item(&hir::Item { kind: hir::ItemKind::Fn(.., body), .. }) => Some(body), - Node::TraitItem(&hir::TraitItem { - kind: hir::TraitItemKind::Method(_, ref m), .. - }) => { + Node::TraitItem(&hir::TraitItem { kind: hir::TraitItemKind::Fn(_, ref m), .. }) => { if let hir::ItemKind::Trait(.., ref trait_items) = self.tcx.hir().expect_item(self.tcx.hir().get_parent_item(parent)).kind { diff --git a/src/librustc_traits/lowering/environment.rs b/src/librustc_traits/lowering/environment.rs index 0e26e9461f4c3..db392ede432e1 100644 --- a/src/librustc_traits/lowering/environment.rs +++ b/src/librustc_traits/lowering/environment.rs @@ -185,7 +185,7 @@ crate fn environment(tcx: TyCtxt<'_>, def_id: DefId) -> Environment<'_> { let node_kind = match node { Node::TraitItem(item) => match item.kind { - TraitItemKind::Method(..) => NodeKind::Fn, + TraitItemKind::Fn(..) => NodeKind::Fn, _ => NodeKind::Other, }, diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 8b54b5343756a..0c8dec8f8d4a9 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -412,8 +412,8 @@ fn extract_spans_for_error_reporting<'a, 'tcx>( TypeError::Mutability => { if let Some(trait_m_hir_id) = tcx.hir().as_local_hir_id(trait_m.def_id) { let trait_m_iter = match tcx.hir().expect_trait_item(trait_m_hir_id).kind { - TraitItemKind::Method(ref trait_m_sig, _) => trait_m_sig.decl.inputs.iter(), - _ => bug!("{:?} is not a TraitItemKind::Method", trait_m), + TraitItemKind::Fn(ref trait_m_sig, _) => trait_m_sig.decl.inputs.iter(), + _ => bug!("{:?} is not a TraitItemKind::Fn", trait_m), }; impl_m_iter @@ -440,10 +440,10 @@ fn extract_spans_for_error_reporting<'a, 'tcx>( if let Some(trait_m_hir_id) = tcx.hir().as_local_hir_id(trait_m.def_id) { let (trait_m_output, trait_m_iter) = match tcx.hir().expect_trait_item(trait_m_hir_id).kind { - TraitItemKind::Method(ref trait_m_sig, _) => { + TraitItemKind::Fn(ref trait_m_sig, _) => { (&trait_m_sig.decl.output, trait_m_sig.decl.inputs.iter()) } - _ => bug!("{:?} is not a TraitItemKind::Method", trait_m), + _ => bug!("{:?} is not a TraitItemKind::Fn", trait_m), }; let impl_iter = impl_sig.inputs().iter(); @@ -708,7 +708,7 @@ fn compare_number_of_method_arguments<'tcx>( let trait_m_hir_id = tcx.hir().as_local_hir_id(trait_m.def_id); let trait_span = if let Some(trait_id) = trait_m_hir_id { match tcx.hir().expect_trait_item(trait_id).kind { - TraitItemKind::Method(ref trait_m_sig, _) => { + TraitItemKind::Fn(ref trait_m_sig, _) => { let pos = if trait_number_args > 0 { trait_number_args - 1 } else { 0 }; if let Some(arg) = trait_m_sig.decl.inputs.get(pos) { Some(if pos == 0 { diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 95faa353e9b65..9e3b4a7be72bb 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -930,7 +930,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let ty::AssocKind::Method = item.kind { let id = self.tcx.hir().as_local_hir_id(item.def_id); if let Some(hir::Node::TraitItem(hir::TraitItem { - kind: hir::TraitItemKind::Method(fn_sig, method), + kind: hir::TraitItemKind::Fn(fn_sig, method), .. })) = id.map(|id| self.tcx.hir().get(id)) { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index fd5cac5b24bf1..3388a70b4cfd0 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -811,7 +811,7 @@ fn primary_body_of( }, Node::TraitItem(item) => match item.kind { hir::TraitItemKind::Const(ref ty, Some(body)) => Some((body, Some(ty), None, None)), - hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => { + hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::Provided(body)) => { Some((body, None, Some(&sig.header), Some(&sig.decl))) } _ => None, @@ -1733,7 +1733,7 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) { for item in items.iter() { let item = tcx.hir().trait_item(item.id); - if let hir::TraitItemKind::Method(sig, _) = &item.kind { + if let hir::TraitItemKind::Fn(sig, _) = &item.kind { let abi = sig.header.abi; fn_maybe_err(tcx, item.ident.span, abi); } @@ -4769,7 +4769,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } Node::TraitItem(&hir::TraitItem { ident, - kind: hir::TraitItemKind::Method(ref sig, ..), + kind: hir::TraitItemKind::Fn(ref sig, ..), .. }) => Some((&sig.decl, ident, true)), Node::ImplItem(&hir::ImplItem { @@ -4863,7 +4863,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .. })) | Some(Node::TraitItem(hir::TraitItem { - kind: hir::TraitItemKind::Method(.., hir::TraitMethod::Provided(body_id)), + kind: hir::TraitItemKind::Fn(.., hir::TraitMethod::Provided(body_id)), .. })) => { let body = hir.body(*body_id); @@ -4934,7 +4934,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .join(", ") } Some(Node::TraitItem(hir::TraitItem { - kind: hir::TraitItemKind::Method(.., hir::TraitMethod::Required(idents)), + kind: hir::TraitItemKind::Fn(.., hir::TraitMethod::Required(idents)), .. })) => { sugg_call = idents diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index e8e34a4e8f079..335b4a2850116 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -173,7 +173,7 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: DefId) { let trait_item = tcx.hir().expect_trait_item(hir_id); let method_sig = match trait_item.kind { - hir::TraitItemKind::Method(ref sig, _) => Some(sig), + hir::TraitItemKind::Fn(ref sig, _) => Some(sig), _ => None, }; check_object_unsafe_self_trait_by_name(tcx, &trait_item); @@ -207,7 +207,7 @@ fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem { trait_should_be_self.push(ty.span) } - hir::TraitItemKind::Method(sig, _) => { + hir::TraitItemKind::Fn(sig, _) => { for ty in sig.decl.inputs { if could_be_self(trait_def_id, ty) { trait_should_be_self.push(ty.span); diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 2dad3d1d6d708..d6262b352480d 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -715,7 +715,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) { tcx.generics_of(def_id); match trait_item.kind { - hir::TraitItemKind::Method(..) => { + hir::TraitItemKind::Fn(..) => { tcx.type_of(def_id); tcx.fn_sig(def_id); } @@ -1121,7 +1121,7 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option match item.kind { - hir::TraitItemKind::Method(ref sig, _) => { + hir::TraitItemKind::Fn(ref sig, _) => { has_late_bound_regions(tcx, &item.generics, &sig.decl) } _ => None, @@ -1437,7 +1437,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> { match tcx.hir().get(hir_id) { TraitItem(hir::TraitItem { - kind: TraitItemKind::Method(sig, TraitMethod::Provided(_)), + kind: TraitItemKind::Fn(sig, TraitMethod::Provided(_)), ident, generics, .. @@ -1474,7 +1474,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> { } TraitItem(hir::TraitItem { - kind: TraitItemKind::Method(FnSig { header, decl }, _), + kind: TraitItemKind::Fn(FnSig { header, decl }, _), ident, generics, .. diff --git a/src/librustc_typeck/collect/type_of.rs b/src/librustc_typeck/collect/type_of.rs index ec87112b7a8e0..815235adc7175 100644 --- a/src/librustc_typeck/collect/type_of.rs +++ b/src/librustc_typeck/collect/type_of.rs @@ -27,7 +27,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { match tcx.hir().get(hir_id) { Node::TraitItem(item) => match item.kind { - TraitItemKind::Method(..) => { + TraitItemKind::Fn(..) => { let substs = InternalSubsts::identity_for_item(tcx, def_id); tcx.mk_fn_def(def_id, substs) } diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index 6f5caea250b07..fc3b7201a1e63 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -105,7 +105,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> { } fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) { - if let hir::TraitItemKind::Method(..) = trait_item.kind { + if let hir::TraitItemKind::Fn(..) = trait_item.kind { self.visit_node_helper(trait_item.hir_id); } } diff --git a/src/librustc_typeck/variance/mod.rs b/src/librustc_typeck/variance/mod.rs index ddde11b38448b..412b90a9acffa 100644 --- a/src/librustc_typeck/variance/mod.rs +++ b/src/librustc_typeck/variance/mod.rs @@ -54,7 +54,7 @@ fn variances_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[ty::Variance] { }, Node::TraitItem(item) => match item.kind { - hir::TraitItemKind::Method(..) => {} + hir::TraitItemKind::Fn(..) => {} _ => unsupported(), }, diff --git a/src/librustc_typeck/variance/terms.rs b/src/librustc_typeck/variance/terms.rs index dd593a6abb4fe..f79f8c4bb9510 100644 --- a/src/librustc_typeck/variance/terms.rs +++ b/src/librustc_typeck/variance/terms.rs @@ -164,7 +164,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> { } fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) { - if let hir::TraitItemKind::Method(..) = trait_item.kind { + if let hir::TraitItemKind::Fn(..) = trait_item.kind { self.add_inferreds_for_item(trait_item.hir_id); } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 7c845a9b66bbd..569faf73a2114 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1084,10 +1084,10 @@ impl Clean for hir::TraitItem<'_> { hir::TraitItemKind::Const(ref ty, default) => { AssocConstItem(ty.clean(cx), default.map(|e| print_const_expr(cx, e))) } - hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => { + hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::Provided(body)) => { MethodItem((sig, &self.generics, body, None).clean(cx)) } - hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Required(ref names)) => { + hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::Required(ref names)) => { let (generics, decl) = enter_impl_trait(cx, || { (self.generics.clean(cx), (&*sig.decl, &names[..]).clean(cx)) }); From 0e1cd5935faf9240850c07afb2b7fd8d582c5e25 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 4 Mar 2020 08:23:12 -0800 Subject: [PATCH 03/30] Toolstate: remove redundant beta-week check. --- src/bootstrap/toolstate.rs | 39 +++++++++----------------------------- 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/src/bootstrap/toolstate.rs b/src/bootstrap/toolstate.rs index 7cffc47293070..7b41ba371a83a 100644 --- a/src/bootstrap/toolstate.rs +++ b/src/bootstrap/toolstate.rs @@ -215,6 +215,9 @@ impl Step for ToolStateCheck { tool, old_state, state ); } else { + // This warning only appears in the logs, which most + // people won't read. It's mostly here for testing and + // debugging. eprintln!( "warning: Tool `{}` is not test-pass (is `{}`), \ this should be fixed before beta is branched.", @@ -222,6 +225,8 @@ impl Step for ToolStateCheck { ); } } + // publish_toolstate.py will be responsible for creating + // comments/issues warning people if there is a regression. } } @@ -230,7 +235,7 @@ impl Step for ToolStateCheck { } if builder.config.channel == "nightly" && env::var_os("TOOLSTATE_PUBLISH").is_some() { - commit_toolstate_change(&toolstates, in_beta_week); + commit_toolstate_change(&toolstates); } } @@ -373,14 +378,12 @@ fn read_old_toolstate() -> Vec { /// /// * See /// if a private email by GitHub is wanted. -fn commit_toolstate_change(current_toolstate: &ToolstateData, in_beta_week: bool) { - let old_toolstate = read_old_toolstate(); - +fn commit_toolstate_change(current_toolstate: &ToolstateData) { let message = format!("({} CI update)", OS.expect("linux/windows only")); let mut success = false; for _ in 1..=5 { // Update the toolstate results (the new commit-to-toolstate mapping) in the toolstate repo. - change_toolstate(¤t_toolstate, &old_toolstate, in_beta_week); + change_toolstate(¤t_toolstate); // `git commit` failing means nothing to commit. let status = t!(Command::new("git") @@ -429,31 +432,7 @@ fn commit_toolstate_change(current_toolstate: &ToolstateData, in_beta_week: bool } } -fn change_toolstate( - current_toolstate: &ToolstateData, - old_toolstate: &[RepoState], - in_beta_week: bool, -) { - let mut regressed = false; - for repo_state in old_toolstate { - let tool = &repo_state.tool; - let state = repo_state.state(); - let new_state = current_toolstate[tool.as_str()]; - - if new_state != state { - eprintln!("The state of `{}` has changed from `{}` to `{}`", tool, state, new_state); - if new_state < state { - if !NIGHTLY_TOOLS.iter().any(|(name, _path)| name == tool) { - regressed = true; - } - } - } - } - - if regressed && in_beta_week { - std::process::exit(1); - } - +fn change_toolstate(current_toolstate: &ToolstateData) { let commit = t!(std::process::Command::new("git").arg("rev-parse").arg("HEAD").output()); let commit = t!(String::from_utf8(commit.stdout)); From a6d8c9c5ebea585304df74bdf56cff186ad8ef1a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 4 Mar 2020 10:17:15 +0100 Subject: [PATCH 04/30] more toolstate comments --- src/bootstrap/toolstate.rs | 8 +++++--- src/ci/publish_toolstate.sh | 4 +++- src/tools/publish_toolstate.py | 9 ++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/bootstrap/toolstate.rs b/src/bootstrap/toolstate.rs index 7b41ba371a83a..c8d8a29ac4e16 100644 --- a/src/bootstrap/toolstate.rs +++ b/src/bootstrap/toolstate.rs @@ -330,11 +330,11 @@ fn prepare_toolstate_config(token: &str) { Err(_) => false, }; if !success { - panic!("git config key={} value={} successful (status: {:?})", key, value, status); + panic!("git config key={} value={} failed (status: {:?})", key, value, status); } } - // If changing anything here, then please check that src/ci/publish_toolstate.sh is up to date + // If changing anything here, then please check that `src/ci/publish_toolstate.sh` is up to date // as well. git_config("user.email", "7378925+rust-toolstate-update@users.noreply.github.com"); git_config("user.name", "Rust Toolstate Update"); @@ -382,7 +382,9 @@ fn commit_toolstate_change(current_toolstate: &ToolstateData) { let message = format!("({} CI update)", OS.expect("linux/windows only")); let mut success = false; for _ in 1..=5 { - // Update the toolstate results (the new commit-to-toolstate mapping) in the toolstate repo. + // Upload the test results (the new commit-to-toolstate mapping) to the toolstate repo. + // This does *not* change the "current toolstate"; that only happens post-landing + // via `src/ci/docker/publish_toolstate.sh`. change_toolstate(¤t_toolstate); // `git commit` failing means nothing to commit. diff --git a/src/ci/publish_toolstate.sh b/src/ci/publish_toolstate.sh index 7c43d034d8b7f..691df04e754a6 100755 --- a/src/ci/publish_toolstate.sh +++ b/src/ci/publish_toolstate.sh @@ -23,7 +23,9 @@ GIT_COMMIT_MSG="$(git log --format=%s -n1 HEAD)" cd rust-toolstate FAILURE=1 for RETRY_COUNT in 1 2 3 4 5; do - # The purpose is to publish the new "current" toolstate in the toolstate repo. + # The purpose of this is to publish the new "current" toolstate in the toolstate repo. + # This happens post-landing, on master. + # (Publishing the per-commit test results happens pre-landing in src/bootstrap/toolstate.rs). "$(ciCheckoutPath)/src/tools/publish_toolstate.py" "$GIT_COMMIT" \ "$GIT_COMMIT_MSG" \ "$MESSAGE_FILE" \ diff --git a/src/tools/publish_toolstate.py b/src/tools/publish_toolstate.py index 5fbb986286ade..b389cd0373cc4 100755 --- a/src/tools/publish_toolstate.py +++ b/src/tools/publish_toolstate.py @@ -1,11 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# This script publishes the new "current" toolstate in the toolstate repo (not to be -# confused with publishing the test results, which happens in -# `src/ci/docker/x86_64-gnu-tools/checktools.sh`). -# It is set as callback for `src/ci/docker/x86_64-gnu-tools/repo.sh` by the CI scripts -# when a new commit lands on `master` (i.e., after it passed all checks on `auto`). +# This script computes the new "current" toolstate for the toolstate repo (not to be +# confused with publishing the test results, which happens in `src/bootstrap/toolstate.rs`). +# It gets called from `src/ci/publish_toolstate.sh` when a new commit lands on `master` +# (i.e., after it passed all checks on `auto`). from __future__ import print_function From a41f1f128ee9fbe595a588b9b91d545a895f5c39 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 4 Mar 2020 09:49:55 -0800 Subject: [PATCH 05/30] Further clarifications and comments on toolstate operation. --- src/bootstrap/toolstate.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/bootstrap/toolstate.rs b/src/bootstrap/toolstate.rs index c8d8a29ac4e16..f0e0f92af55fc 100644 --- a/src/bootstrap/toolstate.rs +++ b/src/bootstrap/toolstate.rs @@ -225,8 +225,11 @@ impl Step for ToolStateCheck { ); } } - // publish_toolstate.py will be responsible for creating - // comments/issues warning people if there is a regression. + // `publish_toolstate.py` is responsible for updating + // `latest.json` and creating comments/issues warning people + // if there is a regression. That all happens in a separate CI + // job on the master branch once the PR has passed all tests + // on the `auto` branch. } } @@ -385,7 +388,7 @@ fn commit_toolstate_change(current_toolstate: &ToolstateData) { // Upload the test results (the new commit-to-toolstate mapping) to the toolstate repo. // This does *not* change the "current toolstate"; that only happens post-landing // via `src/ci/docker/publish_toolstate.sh`. - change_toolstate(¤t_toolstate); + publish_test_results(¤t_toolstate); // `git commit` failing means nothing to commit. let status = t!(Command::new("git") @@ -434,7 +437,12 @@ fn commit_toolstate_change(current_toolstate: &ToolstateData) { } } -fn change_toolstate(current_toolstate: &ToolstateData) { +/// Updates the "history" files with the latest results. +/// +/// These results will later be promoted to `latest.json` by the +/// `publish_toolstate.py` script if the PR passes all tests and is merged to +/// master. +fn publish_test_results(current_toolstate: &ToolstateData) { let commit = t!(std::process::Command::new("git").arg("rev-parse").arg("HEAD").output()); let commit = t!(String::from_utf8(commit.stdout)); From 91525fd078bb6f3ec833aa42141ea027b37b26a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 4 Mar 2020 16:15:23 -0800 Subject: [PATCH 06/30] Tweak output for invalid negative impl AST errors --- src/librustc_ast/ast.rs | 4 +-- src/librustc_ast_passes/ast_validation.rs | 28 ++++++++++++------- src/librustc_ast_passes/feature_gate.rs | 8 +++--- src/librustc_ast_pretty/pprust.rs | 2 +- src/librustc_hir/print.rs | 2 +- src/librustc_parse/parser/item.rs | 2 +- src/librustc_save_analysis/sig.rs | 2 +- src/librustc_typeck/coherence/unsafety.rs | 4 +-- src/librustc_typeck/collect.rs | 2 +- .../coherence-negative-impls-safe.stderr | 4 +-- src/test/ui/error-codes/E0197.stderr | 2 +- src/test/ui/error-codes/E0198.stderr | 4 +-- .../feature-gate-optin-builtin-traits.stderr | 4 +-- .../inherent-impl.stderr | 8 +++--- .../defaultimpl/validation.stderr | 2 +- .../syntax-trait-polarity-feature-gate.stderr | 4 +-- src/test/ui/syntax-trait-polarity.stderr | 16 +++++------ .../traits/trait-safety-inherent-impl.stderr | 10 ++----- 18 files changed, 56 insertions(+), 52 deletions(-) diff --git a/src/librustc_ast/ast.rs b/src/librustc_ast/ast.rs index 88564647d61f9..e86ec2ebfa499 100644 --- a/src/librustc_ast/ast.rs +++ b/src/librustc_ast/ast.rs @@ -2117,14 +2117,14 @@ pub enum ImplPolarity { /// `impl Trait for Type` Positive, /// `impl !Trait for Type` - Negative, + Negative(Span), } impl fmt::Debug for ImplPolarity { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { ImplPolarity::Positive => "positive".fmt(f), - ImplPolarity::Negative => "negative".fmt(f), + ImplPolarity::Negative(_) => "negative".fmt(f), } } } diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs index 9f04c01bfa8f4..1070043458a5a 100644 --- a/src/librustc_ast_passes/ast_validation.rs +++ b/src/librustc_ast_passes/ast_validation.rs @@ -779,7 +779,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { defaultness: _, constness: _, generics: _, - of_trait: Some(_), + of_trait: Some(ref t), ref self_ty, items: _, } => { @@ -794,10 +794,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> { .help("use `auto trait Trait {}` instead") .emit(); } - if let (Unsafe::Yes(span), ImplPolarity::Negative) = (unsafety, polarity) { + if let (Unsafe::Yes(span), ImplPolarity::Negative(sp)) = (unsafety, polarity) { struct_span_err!( this.session, - item.span, + sp.to(t.path.span), E0198, "negative impls cannot be unsafe" ) @@ -816,7 +816,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { constness, generics: _, of_trait: None, - self_ty: _, + ref self_ty, items: _, } => { self.invalid_visibility( @@ -826,28 +826,36 @@ impl<'a> Visitor<'a> for AstValidator<'a> { if let Unsafe::Yes(span) = unsafety { struct_span_err!( self.session, - item.span, + vec![span, self_ty.span], E0197, "inherent impls cannot be unsafe" ) .span_label(span, "unsafe because of this") + .span_label(self_ty.span, "inherent impl for this type") .emit(); } - if polarity == ImplPolarity::Negative { - self.err_handler().span_err(item.span, "inherent impls cannot be negative"); + if let ImplPolarity::Negative(span) = polarity { + self.err_handler().span_err(span, "inherent impls cannot be negative"); } if let Defaultness::Default(def_span) = defaultness { - let span = self.session.source_map().def_span(item.span); self.err_handler() - .struct_span_err(span, "inherent impls cannot be `default`") + .struct_span_err( + vec![def_span, self_ty.span], + "inherent impls cannot be `default`", + ) .span_label(def_span, "`default` because of this") + .span_label(self_ty.span, "inherent impl for this type") .note("only trait implementations may be annotated with `default`") .emit(); } if let Const::Yes(span) = constness { self.err_handler() - .struct_span_err(item.span, "inherent impls cannot be `const`") + .struct_span_err( + vec![span, self_ty.span], + "inherent impls cannot be `const`", + ) .span_label(span, "`const` because of this") + .span_label(self_ty.span, "inherent impl for this type") .note("only trait implementations may be annotated with `const`") .emit(); } diff --git a/src/librustc_ast_passes/feature_gate.rs b/src/librustc_ast_passes/feature_gate.rs index 05e69d0cfd74e..3d9001d5d58bb 100644 --- a/src/librustc_ast_passes/feature_gate.rs +++ b/src/librustc_ast_passes/feature_gate.rs @@ -338,14 +338,14 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } } - ast::ItemKind::Impl { polarity, defaultness, .. } => { - if polarity == ast::ImplPolarity::Negative { + ast::ItemKind::Impl { polarity, defaultness, ref of_trait, .. } => { + if let ast::ImplPolarity::Negative(span) = polarity { gate_feature_post!( &self, optin_builtin_traits, - i.span, + span.to(of_trait.as_ref().map(|t| t.path.span).unwrap_or(span)), "negative trait bounds are not yet fully implemented; \ - use marker types for now" + use marker types for now" ); } diff --git a/src/librustc_ast_pretty/pprust.rs b/src/librustc_ast_pretty/pprust.rs index f95c154bb3b5a..dbfe5d34bc0cb 100644 --- a/src/librustc_ast_pretty/pprust.rs +++ b/src/librustc_ast_pretty/pprust.rs @@ -1175,7 +1175,7 @@ impl<'a> State<'a> { self.s.space(); } - if polarity == ast::ImplPolarity::Negative { + if let ast::ImplPolarity::Negative(_) = polarity { self.s.word("!"); } diff --git a/src/librustc_hir/print.rs b/src/librustc_hir/print.rs index 8cbbef959ce75..f03ab41f12d0a 100644 --- a/src/librustc_hir/print.rs +++ b/src/librustc_hir/print.rs @@ -652,7 +652,7 @@ impl<'a> State<'a> { self.word_nbsp("const"); } - if let hir::ImplPolarity::Negative = polarity { + if let hir::ImplPolarity::Negative(_) = polarity { self.s.word("!"); } diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 9bca1d0990159..09c512f32546b 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -414,7 +414,7 @@ impl<'a> Parser<'a> { // Disambiguate `impl !Trait for Type { ... }` and `impl ! { ... }` for the never type. let polarity = if self.check(&token::Not) && self.look_ahead(1, |t| t.can_begin_type()) { self.bump(); // `!` - ast::ImplPolarity::Negative + ast::ImplPolarity::Negative(self.prev_token.span) } else { ast::ImplPolarity::Positive }; diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index 32da62adc3c02..4fa226712b78e 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -519,7 +519,7 @@ impl Sig for ast::Item { text.push(' '); let trait_sig = if let Some(ref t) = *of_trait { - if polarity == ast::ImplPolarity::Negative { + if let ast::ImplPolarity::Negative(_) = polarity { text.push('!'); } let trait_sig = t.path.make(offset + text.len(), id, scx)?; diff --git a/src/librustc_typeck/coherence/unsafety.rs b/src/librustc_typeck/coherence/unsafety.rs index a604421740363..3b25f67aacc63 100644 --- a/src/librustc_typeck/coherence/unsafety.rs +++ b/src/librustc_typeck/coherence/unsafety.rs @@ -69,11 +69,11 @@ impl UnsafetyChecker<'tcx> { .emit(); } - (_, _, Unsafety::Unsafe, hir::ImplPolarity::Negative) => { + (_, _, Unsafety::Unsafe, hir::ImplPolarity::Negative(_)) => { // Reported in AST validation self.tcx.sess.delay_span_bug(item.span, "unsafe negative impl"); } - (_, _, Unsafety::Normal, hir::ImplPolarity::Negative) + (_, _, Unsafety::Normal, hir::ImplPolarity::Negative(_)) | (Unsafety::Unsafe, _, Unsafety::Unsafe, hir::ImplPolarity::Positive) | (Unsafety::Normal, Some(_), Unsafety::Unsafe, hir::ImplPolarity::Positive) | (Unsafety::Normal, None, Unsafety::Normal, _) => { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 2dad3d1d6d708..e6c3d5b8b9e9e 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1548,7 +1548,7 @@ fn impl_polarity(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ImplPolarity { let is_rustc_reservation = tcx.has_attr(def_id, sym::rustc_reservation_impl); let item = tcx.hir().expect_item(hir_id); match &item.kind { - hir::ItemKind::Impl { polarity: hir::ImplPolarity::Negative, .. } => { + hir::ItemKind::Impl { polarity: hir::ImplPolarity::Negative(_), .. } => { if is_rustc_reservation { tcx.sess.span_err(item.span, "reservation impls can't be negative"); } diff --git a/src/test/ui/coherence/coherence-negative-impls-safe.stderr b/src/test/ui/coherence/coherence-negative-impls-safe.stderr index 4db66af6783ca..eebd1de277ecf 100644 --- a/src/test/ui/coherence/coherence-negative-impls-safe.stderr +++ b/src/test/ui/coherence/coherence-negative-impls-safe.stderr @@ -1,8 +1,8 @@ error[E0198]: negative impls cannot be unsafe - --> $DIR/coherence-negative-impls-safe.rs:7:1 + --> $DIR/coherence-negative-impls-safe.rs:7:13 | LL | unsafe impl !Send for TestType {} - | ------^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ------ ^^^^^ | | | unsafe because of this diff --git a/src/test/ui/error-codes/E0197.stderr b/src/test/ui/error-codes/E0197.stderr index 51ed9c83bc999..bc3c2857958f9 100644 --- a/src/test/ui/error-codes/E0197.stderr +++ b/src/test/ui/error-codes/E0197.stderr @@ -2,7 +2,7 @@ error[E0197]: inherent impls cannot be unsafe --> $DIR/E0197.rs:3:1 | LL | unsafe impl Foo { } - | ------^^^^^^^^^^^^^ + | ^^^^^^ ^^^ inherent impl for this type | | | unsafe because of this diff --git a/src/test/ui/error-codes/E0198.stderr b/src/test/ui/error-codes/E0198.stderr index 90e8b4abd1296..4330476870037 100644 --- a/src/test/ui/error-codes/E0198.stderr +++ b/src/test/ui/error-codes/E0198.stderr @@ -1,8 +1,8 @@ error[E0198]: negative impls cannot be unsafe - --> $DIR/E0198.rs:5:1 + --> $DIR/E0198.rs:5:13 | LL | unsafe impl !Send for Foo { } - | ------^^^^^^^^^^^^^^^^^^^^^^^ + | ------ ^^^^^ | | | unsafe because of this diff --git a/src/test/ui/feature-gates/feature-gate-optin-builtin-traits.stderr b/src/test/ui/feature-gates/feature-gate-optin-builtin-traits.stderr index d29c373a33c95..490d29ad8a35f 100644 --- a/src/test/ui/feature-gates/feature-gate-optin-builtin-traits.stderr +++ b/src/test/ui/feature-gates/feature-gate-optin-builtin-traits.stderr @@ -8,10 +8,10 @@ LL | auto trait AutoDummyTrait {} = help: add `#![feature(optin_builtin_traits)]` to the crate attributes to enable error[E0658]: negative trait bounds are not yet fully implemented; use marker types for now - --> $DIR/feature-gate-optin-builtin-traits.rs:9:1 + --> $DIR/feature-gate-optin-builtin-traits.rs:9:6 | LL | impl !AutoDummyTrait for DummyStruct {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ | = note: see issue #13231 for more information = help: add `#![feature(optin_builtin_traits)]` to the crate attributes to enable diff --git a/src/test/ui/rfc-2632-const-trait-impl/inherent-impl.stderr b/src/test/ui/rfc-2632-const-trait-impl/inherent-impl.stderr index 3ea58a3728a5d..0a76c70b97d1e 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/inherent-impl.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/inherent-impl.stderr @@ -1,18 +1,18 @@ error: inherent impls cannot be `const` - --> $DIR/inherent-impl.rs:9:1 + --> $DIR/inherent-impl.rs:9:6 | LL | impl const S {} - | ^^^^^-----^^^^^ + | ^^^^^ ^ inherent impl for this type | | | `const` because of this | = note: only trait implementations may be annotated with `const` error: inherent impls cannot be `const` - --> $DIR/inherent-impl.rs:12:1 + --> $DIR/inherent-impl.rs:12:6 | LL | impl const T {} - | ^^^^^-----^^^^^ + | ^^^^^ ^ inherent impl for this type | | | `const` because of this | diff --git a/src/test/ui/specialization/defaultimpl/validation.stderr b/src/test/ui/specialization/defaultimpl/validation.stderr index 03b1ef69ca072..2a96f41a249fa 100644 --- a/src/test/ui/specialization/defaultimpl/validation.stderr +++ b/src/test/ui/specialization/defaultimpl/validation.stderr @@ -2,7 +2,7 @@ error: inherent impls cannot be `default` --> $DIR/validation.rs:7:1 | LL | default impl S {} - | -------^^^^^^^ + | ^^^^^^^ ^ inherent impl for this type | | | `default` because of this | diff --git a/src/test/ui/syntax-trait-polarity-feature-gate.stderr b/src/test/ui/syntax-trait-polarity-feature-gate.stderr index ed76377278b82..5d4c1b354f700 100644 --- a/src/test/ui/syntax-trait-polarity-feature-gate.stderr +++ b/src/test/ui/syntax-trait-polarity-feature-gate.stderr @@ -1,8 +1,8 @@ error[E0658]: negative trait bounds are not yet fully implemented; use marker types for now - --> $DIR/syntax-trait-polarity-feature-gate.rs:7:1 + --> $DIR/syntax-trait-polarity-feature-gate.rs:7:6 | LL | impl !Send for TestType {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^ | = note: see issue #13231 for more information = help: add `#![feature(optin_builtin_traits)]` to the crate attributes to enable diff --git a/src/test/ui/syntax-trait-polarity.stderr b/src/test/ui/syntax-trait-polarity.stderr index fef3a65088855..b7d5b4570aacc 100644 --- a/src/test/ui/syntax-trait-polarity.stderr +++ b/src/test/ui/syntax-trait-polarity.stderr @@ -1,28 +1,28 @@ error: inherent impls cannot be negative - --> $DIR/syntax-trait-polarity.rs:7:1 + --> $DIR/syntax-trait-polarity.rs:7:6 | LL | impl !TestType {} - | ^^^^^^^^^^^^^^^^^ + | ^ error[E0198]: negative impls cannot be unsafe - --> $DIR/syntax-trait-polarity.rs:12:1 + --> $DIR/syntax-trait-polarity.rs:12:13 | LL | unsafe impl !Send for TestType {} - | ------^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ------ ^^^^^ | | | unsafe because of this error: inherent impls cannot be negative - --> $DIR/syntax-trait-polarity.rs:19:1 + --> $DIR/syntax-trait-polarity.rs:19:9 | LL | impl !TestType2 {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ error[E0198]: negative impls cannot be unsafe - --> $DIR/syntax-trait-polarity.rs:22:1 + --> $DIR/syntax-trait-polarity.rs:22:16 | LL | unsafe impl !Send for TestType2 {} - | ------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ------ ^^^^^ | | | unsafe because of this diff --git a/src/test/ui/traits/trait-safety-inherent-impl.stderr b/src/test/ui/traits/trait-safety-inherent-impl.stderr index c398785d3949e..09ad4585ab156 100644 --- a/src/test/ui/traits/trait-safety-inherent-impl.stderr +++ b/src/test/ui/traits/trait-safety-inherent-impl.stderr @@ -1,14 +1,10 @@ error[E0197]: inherent impls cannot be unsafe --> $DIR/trait-safety-inherent-impl.rs:5:1 | -LL | unsafe impl SomeStruct { - | ^----- - | | - | _unsafe because of this +LL | unsafe impl SomeStruct { + | ^^^^^^ ^^^^^^^^^^ inherent impl for this type | | -LL | | fn foo(self) { } -LL | | } - | |_^ + | unsafe because of this error: aborting due to previous error From 713a291441d2c71e74141ddc9387166bd6755d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 5 Mar 2020 15:39:35 -0800 Subject: [PATCH 07/30] review comments --- src/librustc_ast_passes/ast_validation.rs | 52 +++++++++---------- src/librustc_parse/parser/item.rs | 18 ++++--- .../coherence-negative-impls-safe.stderr | 5 +- src/test/ui/error-codes/E0197.stderr | 4 +- src/test/ui/error-codes/E0198.stderr | 5 +- .../inherent-impl.stderr | 8 +-- .../defaultimpl/validation.stderr | 4 +- src/test/ui/syntax-trait-polarity.stderr | 22 +++++--- .../traits/trait-safety-inherent-impl.stderr | 4 +- 9 files changed, 65 insertions(+), 57 deletions(-) diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs index 1070043458a5a..d90e9c4df269c 100644 --- a/src/librustc_ast_passes/ast_validation.rs +++ b/src/librustc_ast_passes/ast_validation.rs @@ -801,6 +801,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { E0198, "negative impls cannot be unsafe" ) + .span_label(sp, "negative because of this") .span_label(span, "unsafe because of this") .emit(); } @@ -819,45 +820,40 @@ impl<'a> Visitor<'a> for AstValidator<'a> { ref self_ty, items: _, } => { + let error = |annotation_span, annotation, note, code| { + let mut err = self.err_handler().struct_span_err( + self_ty.span, + &format!("inherent impls cannot be {}", annotation), + ); + err.span_label(annotation_span, &format!("{} because of this", annotation)); + err.span_label(self_ty.span, "inherent impl for this type"); + if note { + err.note(&format!( + "only trait implementations may be annotated with {}", + annotation + )); + } + if code { + err.code(error_code!(E0197)); + } + err.emit(); + }; + self.invalid_visibility( &item.vis, Some("place qualifiers on individual impl items instead"), ); if let Unsafe::Yes(span) = unsafety { - struct_span_err!( - self.session, - vec![span, self_ty.span], - E0197, - "inherent impls cannot be unsafe" - ) - .span_label(span, "unsafe because of this") - .span_label(self_ty.span, "inherent impl for this type") - .emit(); + error(span, "unsafe", false, true) } if let ImplPolarity::Negative(span) = polarity { - self.err_handler().span_err(span, "inherent impls cannot be negative"); + error(span, "negative", false, false); } if let Defaultness::Default(def_span) = defaultness { - self.err_handler() - .struct_span_err( - vec![def_span, self_ty.span], - "inherent impls cannot be `default`", - ) - .span_label(def_span, "`default` because of this") - .span_label(self_ty.span, "inherent impl for this type") - .note("only trait implementations may be annotated with `default`") - .emit(); + error(def_span, "`default`", true, false); } if let Const::Yes(span) = constness { - self.err_handler() - .struct_span_err( - vec![span, self_ty.span], - "inherent impls cannot be `const`", - ) - .span_label(span, "`const` because of this") - .span_label(self_ty.span, "inherent impl for this type") - .note("only trait implementations may be annotated with `const`") - .emit(); + error(span, "`const`", true, false); } } ItemKind::Fn(def, ref sig, ref generics, ref body) => { diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 09c512f32546b..85bb546b74806 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -373,6 +373,16 @@ impl<'a> Parser<'a> { self.token.is_keyword(kw::Async) && self.is_keyword_ahead(1, &[kw::Fn]) } + fn parse_polarity(&mut self) -> ast::ImplPolarity { + // Disambiguate `impl !Trait for Type { ... }` and `impl ! { ... }` for the never type. + if self.check(&token::Not) && self.look_ahead(1, |t| t.can_begin_type()) { + self.bump(); // `!` + ast::ImplPolarity::Negative(self.prev_token.span) + } else { + ast::ImplPolarity::Positive + } + } + /// Parses an implementation item. /// /// ``` @@ -411,13 +421,7 @@ impl<'a> Parser<'a> { self.sess.gated_spans.gate(sym::const_trait_impl, span); } - // Disambiguate `impl !Trait for Type { ... }` and `impl ! { ... }` for the never type. - let polarity = if self.check(&token::Not) && self.look_ahead(1, |t| t.can_begin_type()) { - self.bump(); // `!` - ast::ImplPolarity::Negative(self.prev_token.span) - } else { - ast::ImplPolarity::Positive - }; + let polarity = self.parse_polarity(); // Parse both types and traits as a type, then reinterpret if necessary. let err_path = |span| ast::Path::from_ident(Ident::new(kw::Invalid, span)); diff --git a/src/test/ui/coherence/coherence-negative-impls-safe.stderr b/src/test/ui/coherence/coherence-negative-impls-safe.stderr index eebd1de277ecf..1bd37f395902a 100644 --- a/src/test/ui/coherence/coherence-negative-impls-safe.stderr +++ b/src/test/ui/coherence/coherence-negative-impls-safe.stderr @@ -2,8 +2,9 @@ error[E0198]: negative impls cannot be unsafe --> $DIR/coherence-negative-impls-safe.rs:7:13 | LL | unsafe impl !Send for TestType {} - | ------ ^^^^^ - | | + | ------ -^^^^ + | | | + | | negative because of this | unsafe because of this error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0197.stderr b/src/test/ui/error-codes/E0197.stderr index bc3c2857958f9..35e1042649ef9 100644 --- a/src/test/ui/error-codes/E0197.stderr +++ b/src/test/ui/error-codes/E0197.stderr @@ -1,8 +1,8 @@ error[E0197]: inherent impls cannot be unsafe - --> $DIR/E0197.rs:3:1 + --> $DIR/E0197.rs:3:13 | LL | unsafe impl Foo { } - | ^^^^^^ ^^^ inherent impl for this type + | ------ ^^^ inherent impl for this type | | | unsafe because of this diff --git a/src/test/ui/error-codes/E0198.stderr b/src/test/ui/error-codes/E0198.stderr index 4330476870037..bb2efefb427ba 100644 --- a/src/test/ui/error-codes/E0198.stderr +++ b/src/test/ui/error-codes/E0198.stderr @@ -2,8 +2,9 @@ error[E0198]: negative impls cannot be unsafe --> $DIR/E0198.rs:5:13 | LL | unsafe impl !Send for Foo { } - | ------ ^^^^^ - | | + | ------ -^^^^ + | | | + | | negative because of this | unsafe because of this error: aborting due to previous error diff --git a/src/test/ui/rfc-2632-const-trait-impl/inherent-impl.stderr b/src/test/ui/rfc-2632-const-trait-impl/inherent-impl.stderr index 0a76c70b97d1e..834f6a409f5b6 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/inherent-impl.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/inherent-impl.stderr @@ -1,18 +1,18 @@ error: inherent impls cannot be `const` - --> $DIR/inherent-impl.rs:9:6 + --> $DIR/inherent-impl.rs:9:12 | LL | impl const S {} - | ^^^^^ ^ inherent impl for this type + | ----- ^ inherent impl for this type | | | `const` because of this | = note: only trait implementations may be annotated with `const` error: inherent impls cannot be `const` - --> $DIR/inherent-impl.rs:12:6 + --> $DIR/inherent-impl.rs:12:12 | LL | impl const T {} - | ^^^^^ ^ inherent impl for this type + | ----- ^ inherent impl for this type | | | `const` because of this | diff --git a/src/test/ui/specialization/defaultimpl/validation.stderr b/src/test/ui/specialization/defaultimpl/validation.stderr index 2a96f41a249fa..6e19d79e48f6b 100644 --- a/src/test/ui/specialization/defaultimpl/validation.stderr +++ b/src/test/ui/specialization/defaultimpl/validation.stderr @@ -1,8 +1,8 @@ error: inherent impls cannot be `default` - --> $DIR/validation.rs:7:1 + --> $DIR/validation.rs:7:14 | LL | default impl S {} - | ^^^^^^^ ^ inherent impl for this type + | ------- ^ inherent impl for this type | | | `default` because of this | diff --git a/src/test/ui/syntax-trait-polarity.stderr b/src/test/ui/syntax-trait-polarity.stderr index b7d5b4570aacc..5777e0ade908e 100644 --- a/src/test/ui/syntax-trait-polarity.stderr +++ b/src/test/ui/syntax-trait-polarity.stderr @@ -1,29 +1,35 @@ error: inherent impls cannot be negative - --> $DIR/syntax-trait-polarity.rs:7:6 + --> $DIR/syntax-trait-polarity.rs:7:7 | LL | impl !TestType {} - | ^ + | -^^^^^^^^ inherent impl for this type + | | + | negative because of this error[E0198]: negative impls cannot be unsafe --> $DIR/syntax-trait-polarity.rs:12:13 | LL | unsafe impl !Send for TestType {} - | ------ ^^^^^ - | | + | ------ -^^^^ + | | | + | | negative because of this | unsafe because of this error: inherent impls cannot be negative - --> $DIR/syntax-trait-polarity.rs:19:9 + --> $DIR/syntax-trait-polarity.rs:19:10 | LL | impl !TestType2 {} - | ^ + | -^^^^^^^^^^^^ inherent impl for this type + | | + | negative because of this error[E0198]: negative impls cannot be unsafe --> $DIR/syntax-trait-polarity.rs:22:16 | LL | unsafe impl !Send for TestType2 {} - | ------ ^^^^^ - | | + | ------ -^^^^ + | | | + | | negative because of this | unsafe because of this error[E0192]: negative impls are only allowed for auto traits (e.g., `Send` and `Sync`) diff --git a/src/test/ui/traits/trait-safety-inherent-impl.stderr b/src/test/ui/traits/trait-safety-inherent-impl.stderr index 09ad4585ab156..0738d2973e2d7 100644 --- a/src/test/ui/traits/trait-safety-inherent-impl.stderr +++ b/src/test/ui/traits/trait-safety-inherent-impl.stderr @@ -1,8 +1,8 @@ error[E0197]: inherent impls cannot be unsafe - --> $DIR/trait-safety-inherent-impl.rs:5:1 + --> $DIR/trait-safety-inherent-impl.rs:5:13 | LL | unsafe impl SomeStruct { - | ^^^^^^ ^^^^^^^^^^ inherent impl for this type + | ------ ^^^^^^^^^^ inherent impl for this type | | | unsafe because of this From 3d146a3d1a58d35fb9198472ab2ccfb5eef9d1c9 Mon Sep 17 00:00:00 2001 From: Phoebe Bell Date: Sun, 9 Feb 2020 16:45:29 -0800 Subject: [PATCH 08/30] Document unsafe blocks in core::fmt --- src/libcore/fmt/float.rs | 6 ++++-- src/libcore/fmt/mod.rs | 18 ++++++++++++++++-- src/libcore/fmt/num.rs | 27 +++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/libcore/fmt/float.rs b/src/libcore/fmt/float.rs index 5ef673009bb6d..52d8349bc9a87 100644 --- a/src/libcore/fmt/float.rs +++ b/src/libcore/fmt/float.rs @@ -2,8 +2,6 @@ use crate::fmt::{Debug, Display, Formatter, LowerExp, Result, UpperExp}; use crate::mem::MaybeUninit; use crate::num::flt2dec; -// ignore-tidy-undocumented-unsafe - // Don't inline this so callers don't use the stack space this function // requires unless they have to. #[inline(never)] @@ -16,6 +14,7 @@ fn float_to_decimal_common_exact( where T: flt2dec::DecodableFloat, { + // SAFETY: Possible undefined behavior, see FIXME(#53491) unsafe { let mut buf = MaybeUninit::<[u8; 1024]>::uninit(); // enough for f32 and f64 let mut parts = MaybeUninit::<[flt2dec::Part<'_>; 4]>::uninit(); @@ -48,6 +47,7 @@ fn float_to_decimal_common_shortest( where T: flt2dec::DecodableFloat, { + // SAFETY: Possible undefined behavior, see FIXME(#53491) unsafe { // enough for f32 and f64 let mut buf = MaybeUninit::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninit(); @@ -103,6 +103,7 @@ fn float_to_exponential_common_exact( where T: flt2dec::DecodableFloat, { + // SAFETY: Possible undefined behavior, see FIXME(#53491) unsafe { let mut buf = MaybeUninit::<[u8; 1024]>::uninit(); // enough for f32 and f64 let mut parts = MaybeUninit::<[flt2dec::Part<'_>; 6]>::uninit(); @@ -132,6 +133,7 @@ fn float_to_exponential_common_shortest( where T: flt2dec::DecodableFloat, { + // SAFETY: Possible undefined behavior, see FIXME(#53491) unsafe { // enough for f32 and f64 let mut buf = MaybeUninit::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninit(); diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 993b1073493e9..a7b34e5f2f1c5 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -1,7 +1,5 @@ //! Utilities for formatting and printing strings. -// ignore-tidy-undocumented-unsafe - #![stable(feature = "rust1", since = "1.0.0")] use crate::cell::{Cell, Ref, RefCell, RefMut, UnsafeCell}; @@ -271,6 +269,14 @@ impl<'a> ArgumentV1<'a> { #[doc(hidden)] #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")] pub fn new<'b, T>(x: &'b T, f: fn(&T, &mut Formatter<'_>) -> Result) -> ArgumentV1<'b> { + // SAFETY: `mem::transmute(x)` is safe because + // 1. `&'b T` keeps the lifetime it originated with `'b` + // (so as to not have an unbounded lifetime) + // 2. `&'b T` and `&'b Void` have the same memory layout + // (when `T` is `Sized`, as it is here) + // `mem::transmute(f)` is safe since `fn(&T, &mut Formatter<'_>) -> Result` + // and `fn(&Void, &mut Formatter<'_>) -> Result` have the same ABI + // (as long as `T` is `Sized`) unsafe { ArgumentV1 { formatter: mem::transmute(f), value: mem::transmute(x) } } } @@ -1389,6 +1395,14 @@ impl<'a> Formatter<'a> { fn write_formatted_parts(&mut self, formatted: &flt2dec::Formatted<'_>) -> Result { fn write_bytes(buf: &mut dyn Write, s: &[u8]) -> Result { + // SAFETY: This is used for `flt2dec::Part::Num` and `flt2dec::Part::Copy`. + // It's safe to use for `flt2dec::Part::Num` since every char `c` is between + // `b'0'` and `b'9'`, which means `s` is valid UTF-8. + // It's also probably safe in practice to use for `flt2dec::Part::Copy(buf)` + // since `buf` should be plain ASCII, but it's possible for someone to pass + // in a bad value for `buf` into `flt2dec::to_shortest_str` since it is a + // public function. + // FIXME: Determine whether this could result in UB. buf.write_str(unsafe { str::from_utf8_unchecked(s) }) } diff --git a/src/libcore/fmt/num.rs b/src/libcore/fmt/num.rs index 5dfd3a8ecdbd6..7d77e33d74378 100644 --- a/src/libcore/fmt/num.rs +++ b/src/libcore/fmt/num.rs @@ -1,7 +1,5 @@ //! Integer and floating-point number formatting -// ignore-tidy-undocumented-unsafe - use crate::fmt; use crate::mem::MaybeUninit; use crate::num::flt2dec; @@ -84,6 +82,8 @@ trait GenericRadix { } } let buf = &buf[curr..]; + // SAFETY: The only chars in `buf` are created by `Self::digit` which are assumed to be + // valid UTF-8 let buf = unsafe { str::from_utf8_unchecked(slice::from_raw_parts(MaybeUninit::first_ptr(buf), buf.len())) }; @@ -189,11 +189,19 @@ static DEC_DIGITS_LUT: &[u8; 200] = b"0001020304050607080910111213141516171819\ macro_rules! impl_Display { ($($t:ident),* as $u:ident via $conv_fn:ident named $name:ident) => { fn $name(mut n: $u, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // 2^128 is about 3*10^38, so 39 gives an extra byte of space let mut buf = [MaybeUninit::::uninit(); 39]; let mut curr = buf.len() as isize; let buf_ptr = MaybeUninit::first_ptr_mut(&mut buf); let lut_ptr = DEC_DIGITS_LUT.as_ptr(); + // SAFETY: Since `d1` and `d2` are always less than or equal to `198`, we + // can copy from `lut_ptr[d1..d1 + 1]` and `lut_ptr[d2..d2 + 1]`. To show + // that it's OK to copy into `buf_ptr`, notice that at the beginning + // `curr == buf.len() == 39 > log(n)` since `n < 2^128 < 10^39`, and at + // each step this is kept the same as `n` is divided. Since `n` is always + // non-negative, this means that `curr > 0` so `buf_ptr[curr..curr + 1]` + // is safe to access. unsafe { // need at least 16 bits for the 4-characters-at-a-time to work. assert!(crate::mem::size_of::<$u>() >= 2); @@ -206,6 +214,10 @@ macro_rules! impl_Display { let d1 = (rem / 100) << 1; let d2 = (rem % 100) << 1; curr -= 4; + + // We are allowed to copy to `buf_ptr[curr..curr + 3]` here since + // otherwise `curr < 0`. But then `n` was originally at least `10000^10` + // which is `10^40 > 2^128 > n`. ptr::copy_nonoverlapping(lut_ptr.offset(d1), buf_ptr.offset(curr), 2); ptr::copy_nonoverlapping(lut_ptr.offset(d2), buf_ptr.offset(curr + 2), 2); } @@ -232,6 +244,8 @@ macro_rules! impl_Display { } } + // SAFETY: `curr` > 0 (since we made `buf` large enough), and all the chars are valid + // UTF-8 since `DEC_DIGITS_LUT` is let buf_slice = unsafe { str::from_utf8_unchecked( slice::from_raw_parts(buf_ptr.offset(curr), buf.len() - curr as usize)) @@ -304,6 +318,8 @@ macro_rules! impl_Exp { }; // 39 digits (worst case u128) + . = 40 + // Since `curr` always decreases by the number of digits copied, this means + // that `curr >= 0`. let mut buf = [MaybeUninit::::uninit(); 40]; let mut curr = buf.len() as isize; //index for buf let buf_ptr = MaybeUninit::first_ptr_mut(&mut buf); @@ -313,6 +329,8 @@ macro_rules! impl_Exp { while n >= 100 { let d1 = ((n % 100) as isize) << 1; curr -= 2; + // SAFETY: `d1 <= 198`, so we can copy from `lut_ptr[d1..d1 + 2]` since + // `DEC_DIGITS_LUT` has a length of 200. unsafe { ptr::copy_nonoverlapping(lut_ptr.offset(d1), buf_ptr.offset(curr), 2); } @@ -324,6 +342,7 @@ macro_rules! impl_Exp { // decode second-to-last character if n >= 10 { curr -= 1; + // SAFETY: Safe since `40 > curr >= 0` (see comment) unsafe { *buf_ptr.offset(curr) = (n as u8 % 10_u8) + b'0'; } @@ -333,11 +352,13 @@ macro_rules! impl_Exp { // add decimal point iff >1 mantissa digit will be printed if exponent != trailing_zeros || added_precision != 0 { curr -= 1; + // SAFETY: Safe since `40 > curr >= 0` unsafe { *buf_ptr.offset(curr) = b'.'; } } + // SAFETY: Safe since `40 > curr >= 0` let buf_slice = unsafe { // decode last character curr -= 1; @@ -350,6 +371,8 @@ macro_rules! impl_Exp { // stores 'e' (or 'E') and the up to 2-digit exponent let mut exp_buf = [MaybeUninit::::uninit(); 3]; let exp_ptr = MaybeUninit::first_ptr_mut(&mut exp_buf); + // SAFETY: In either case, `exp_buf` is written within bounds and `exp_ptr[..len]` + // is contained within `exp_buf` since `len <= 3`. let exp_slice = unsafe { *exp_ptr.offset(0) = if upper {b'E'} else {b'e'}; let len = if exponent < 10 { From 6fba412499e854d6c4cd8e6b22073d5684d549ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 6 Mar 2020 10:55:21 -0800 Subject: [PATCH 09/30] Further tweak spans in ast validation errors --- src/librustc_ast_passes/ast_validation.rs | 59 +++++++++++++++---- src/test/ui/async-await/no-const-async.stderr | 4 +- src/test/ui/auto-trait-validation.stderr | 18 ++++-- src/test/ui/issues/issue-23080-2.rs | 3 +- src/test/ui/issues/issue-23080-2.stderr | 11 ++-- src/test/ui/issues/issue-23080.rs | 3 +- src/test/ui/issues/issue-23080.stderr | 13 ++-- .../ui/parser/fn-header-semantic-fail.stderr | 10 ++-- ...inductive-overflow-supertrait-oibit.stderr | 6 +- .../typeck-auto-trait-no-supertraits-2.stderr | 6 +- .../typeck-auto-trait-no-supertraits.stderr | 6 +- 11 files changed, 91 insertions(+), 48 deletions(-) diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs index d90e9c4df269c..eff58ad4d9aab 100644 --- a/src/librustc_ast_passes/ast_validation.rs +++ b/src/librustc_ast_passes/ast_validation.rs @@ -13,7 +13,7 @@ use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor}; use rustc_ast::walk_list; use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::{error_code, struct_span_err, Applicability}; +use rustc_errors::{error_code, pluralize, struct_span_err, Applicability}; use rustc_parse::validate_attr; use rustc_session::lint::builtin::PATTERNS_IN_FNS_WITHOUT_BODY; use rustc_session::lint::LintBuffer; @@ -887,30 +887,63 @@ impl<'a> Visitor<'a> for AstValidator<'a> { if is_auto == IsAuto::Yes { // Auto traits cannot have generics, super traits nor contain items. if !generics.params.is_empty() { - struct_span_err!( + let spans: Vec<_> = generics.params.iter().map(|i| i.ident.span).collect(); + let last = spans.iter().last().map(|s| *s); + let len = spans.len(); + let mut err = struct_span_err!( self.session, - item.span, + spans, E0567, "auto traits cannot have generic parameters" - ) - .emit(); + ); + if let Some(span) = last { + err.span_label( + span, + &format!( + "cannot have {these} generic parameter{s}", + these = if len == 1 { "this" } else { "these" }, + s = pluralize!(len) + ), + ); + } + err.span_label( + item.ident.span, + "auto trait cannot have generic parameters", + ); + err.emit(); } if !bounds.is_empty() { - struct_span_err!( + let spans: Vec<_> = bounds.iter().map(|b| b.span()).collect(); + let last = spans.iter().last().map(|s| *s); + let len = spans.len(); + let mut err = struct_span_err!( self.session, - item.span, + spans, E0568, "auto traits cannot have super traits" - ) - .emit(); + ); + if let Some(span) = last { + err.span_label( + span, + &format!( + "cannot have {these} super trait{s}", + these = if len == 1 { "this" } else { "these" }, + s = pluralize!(len) + ), + ); + } + err.span_label(item.ident.span, "auto trait cannot have super traits"); + err.emit(); } if !trait_items.is_empty() { + let spans: Vec<_> = trait_items.iter().map(|i| i.ident.span).collect(); struct_span_err!( self.session, - item.span, + spans, E0380, "auto traits cannot have methods or associated items" ) + .span_label(item.ident.span, "auto trait cannot have items") .emit(); } } @@ -1157,9 +1190,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> { }) = fk.header() { self.err_handler() - .struct_span_err(span, "functions cannot be both `const` and `async`") + .struct_span_err( + vec![*cspan, *aspan], + "functions cannot be both `const` and `async`", + ) .span_label(*cspan, "`const` because of this") .span_label(*aspan, "`async` because of this") + .span_label(span, "") // Point at the fn header. .emit(); } diff --git a/src/test/ui/async-await/no-const-async.stderr b/src/test/ui/async-await/no-const-async.stderr index 07559cd240bb6..4e59bb507676f 100644 --- a/src/test/ui/async-await/no-const-async.stderr +++ b/src/test/ui/async-await/no-const-async.stderr @@ -1,8 +1,8 @@ error: functions cannot be both `const` and `async` - --> $DIR/no-const-async.rs:4:1 + --> $DIR/no-const-async.rs:4:5 | LL | pub const async fn x() {} - | ^^^^-----^-----^^^^^^^^^^ + | ----^^^^^-^^^^^---------- | | | | | `async` because of this | `const` because of this diff --git a/src/test/ui/auto-trait-validation.stderr b/src/test/ui/auto-trait-validation.stderr index 51422fab81fda..75919a1f9913f 100644 --- a/src/test/ui/auto-trait-validation.stderr +++ b/src/test/ui/auto-trait-validation.stderr @@ -1,20 +1,26 @@ error[E0567]: auto traits cannot have generic parameters - --> $DIR/auto-trait-validation.rs:3:1 + --> $DIR/auto-trait-validation.rs:3:20 | LL | auto trait Generic {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ------- ^ cannot have this generic parameter + | | + | auto trait cannot have generic parameters error[E0568]: auto traits cannot have super traits - --> $DIR/auto-trait-validation.rs:5:1 + --> $DIR/auto-trait-validation.rs:5:20 | LL | auto trait Bound : Copy {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ----- ^^^^ cannot have this super trait + | | + | auto trait cannot have super traits error[E0380]: auto traits cannot have methods or associated items - --> $DIR/auto-trait-validation.rs:7:1 + --> $DIR/auto-trait-validation.rs:7:25 | LL | auto trait MyTrait { fn foo() {} } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ------- ^^^ + | | + | auto trait cannot have items error: aborting due to 3 previous errors diff --git a/src/test/ui/issues/issue-23080-2.rs b/src/test/ui/issues/issue-23080-2.rs index 319aa2a5cce9e..d20bb4bd90726 100644 --- a/src/test/ui/issues/issue-23080-2.rs +++ b/src/test/ui/issues/issue-23080-2.rs @@ -3,8 +3,7 @@ #![feature(optin_builtin_traits)] unsafe auto trait Trait { -//~^ ERROR E0380 - type Output; + type Output; //~ ERROR E0380 } fn call_method(x: T) {} diff --git a/src/test/ui/issues/issue-23080-2.stderr b/src/test/ui/issues/issue-23080-2.stderr index 1103de0d91043..fcd1ecfa98288 100644 --- a/src/test/ui/issues/issue-23080-2.stderr +++ b/src/test/ui/issues/issue-23080-2.stderr @@ -1,11 +1,10 @@ error[E0380]: auto traits cannot have methods or associated items - --> $DIR/issue-23080-2.rs:5:1 + --> $DIR/issue-23080-2.rs:6:10 | -LL | / unsafe auto trait Trait { -LL | | -LL | | type Output; -LL | | } - | |_^ +LL | unsafe auto trait Trait { + | ----- auto trait cannot have items +LL | type Output; + | ^^^^^^ error[E0275]: overflow evaluating the requirement `<() as Trait>::Output` | diff --git a/src/test/ui/issues/issue-23080.rs b/src/test/ui/issues/issue-23080.rs index fdfee6981447d..fa5c35316bc28 100644 --- a/src/test/ui/issues/issue-23080.rs +++ b/src/test/ui/issues/issue-23080.rs @@ -1,8 +1,7 @@ #![feature(optin_builtin_traits)] unsafe auto trait Trait { -//~^ ERROR E0380 - fn method(&self) { + fn method(&self) { //~ ERROR E0380 println!("Hello"); } } diff --git a/src/test/ui/issues/issue-23080.stderr b/src/test/ui/issues/issue-23080.stderr index 91c2721732426..dbb9861b5784a 100644 --- a/src/test/ui/issues/issue-23080.stderr +++ b/src/test/ui/issues/issue-23080.stderr @@ -1,13 +1,10 @@ error[E0380]: auto traits cannot have methods or associated items - --> $DIR/issue-23080.rs:3:1 + --> $DIR/issue-23080.rs:4:8 | -LL | / unsafe auto trait Trait { -LL | | -LL | | fn method(&self) { -LL | | println!("Hello"); -LL | | } -LL | | } - | |_^ +LL | unsafe auto trait Trait { + | ----- auto trait cannot have items +LL | fn method(&self) { + | ^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/parser/fn-header-semantic-fail.stderr b/src/test/ui/parser/fn-header-semantic-fail.stderr index 1142cee9851b0..d6b36fbb71450 100644 --- a/src/test/ui/parser/fn-header-semantic-fail.stderr +++ b/src/test/ui/parser/fn-header-semantic-fail.stderr @@ -2,7 +2,7 @@ error: functions cannot be both `const` and `async` --> $DIR/fn-header-semantic-fail.rs:13:5 | LL | const async unsafe extern "C" fn ff5() {} // OK. - | -----^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^-^^^^^------------------------------ | | | | | `async` because of this | `const` because of this @@ -45,7 +45,7 @@ error: functions cannot be both `const` and `async` --> $DIR/fn-header-semantic-fail.rs:21:9 | LL | const async unsafe extern "C" fn ft5(); - | -----^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^-^^^^^---------------------------- | | | | | `async` because of this | `const` because of this @@ -88,7 +88,7 @@ error: functions cannot be both `const` and `async` --> $DIR/fn-header-semantic-fail.rs:34:9 | LL | const async unsafe extern "C" fn ft5() {} - | -----^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^-^^^^^------------------------------ | | | | | `async` because of this | `const` because of this @@ -97,7 +97,7 @@ error: functions cannot be both `const` and `async` --> $DIR/fn-header-semantic-fail.rs:46:9 | LL | const async unsafe extern "C" fn fi5() {} - | -----^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^-^^^^^------------------------------ | | | | | `async` because of this | `const` because of this @@ -160,7 +160,7 @@ error: functions cannot be both `const` and `async` --> $DIR/fn-header-semantic-fail.rs:55:9 | LL | const async unsafe extern "C" fn fe5(); - | -----^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^-^^^^^---------------------------- | | | | | `async` because of this | `const` because of this diff --git a/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr b/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr index 63182a6bd9581..03d05f4c928a6 100644 --- a/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr +++ b/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr @@ -1,8 +1,10 @@ error[E0568]: auto traits cannot have super traits - --> $DIR/traits-inductive-overflow-supertrait-oibit.rs:7:1 + --> $DIR/traits-inductive-overflow-supertrait-oibit.rs:7:19 | LL | auto trait Magic: Copy {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ----- ^^^^ cannot have this super trait + | | + | auto trait cannot have super traits error[E0277]: the trait bound `NoClone: std::marker::Copy` is not satisfied --> $DIR/traits-inductive-overflow-supertrait-oibit.rs:15:23 diff --git a/src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr b/src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr index 8755bcded9d2f..45c95b191bd59 100644 --- a/src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr +++ b/src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr @@ -1,8 +1,10 @@ error[E0568]: auto traits cannot have super traits - --> $DIR/typeck-auto-trait-no-supertraits-2.rs:3:1 + --> $DIR/typeck-auto-trait-no-supertraits-2.rs:3:20 | LL | auto trait Magic : Sized where Option : Magic {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ----- ^^^^^ cannot have this super trait + | | + | auto trait cannot have super traits error: aborting due to previous error diff --git a/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr b/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr index 5a38883490959..094f5d7dd24f2 100644 --- a/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr +++ b/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr @@ -1,8 +1,10 @@ error[E0568]: auto traits cannot have super traits - --> $DIR/typeck-auto-trait-no-supertraits.rs:27:1 + --> $DIR/typeck-auto-trait-no-supertraits.rs:27:19 | LL | auto trait Magic: Copy {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ----- ^^^^ cannot have this super trait + | | + | auto trait cannot have super traits error: aborting due to previous error From 005fc6eaccacd129e96e049a3342d1d539316433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 6 Mar 2020 11:45:00 -0800 Subject: [PATCH 10/30] Suggest removal of auto trait super traits and type params --- src/librustc_ast_passes/ast_validation.rs | 14 +++++++++++++- src/test/ui/auto-trait-validation.stderr | 10 ++++++++++ ...aits-inductive-overflow-supertrait-oibit.stderr | 5 +++++ .../typeck-auto-trait-no-supertraits-2.stderr | 5 +++++ .../typeck/typeck-auto-trait-no-supertraits.stderr | 5 +++++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs index eff58ad4d9aab..df229e57cf0b7 100644 --- a/src/librustc_ast_passes/ast_validation.rs +++ b/src/librustc_ast_passes/ast_validation.rs @@ -910,6 +910,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> { item.ident.span, "auto trait cannot have generic parameters", ); + err.span_suggestion_verbose( + generics.span, + "remove the parameters for the auto trait to be valid", + String::new(), + Applicability::MachineApplicable, + ); err.emit(); } if !bounds.is_empty() { @@ -922,6 +928,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { E0568, "auto traits cannot have super traits" ); + err.span_label(item.ident.span, "auto trait cannot have super traits"); if let Some(span) = last { err.span_label( span, @@ -931,8 +938,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> { s = pluralize!(len) ), ); + err.span_suggestion_verbose( + generics.span.shrink_to_hi().to(span), + "remove the super traits for the auto trait to be valid", + String::new(), + Applicability::MachineApplicable, + ); } - err.span_label(item.ident.span, "auto trait cannot have super traits"); err.emit(); } if !trait_items.is_empty() { diff --git a/src/test/ui/auto-trait-validation.stderr b/src/test/ui/auto-trait-validation.stderr index 75919a1f9913f..17d9ca71d149a 100644 --- a/src/test/ui/auto-trait-validation.stderr +++ b/src/test/ui/auto-trait-validation.stderr @@ -5,6 +5,11 @@ LL | auto trait Generic {} | ------- ^ cannot have this generic parameter | | | auto trait cannot have generic parameters + | +help: remove the parameters for the auto trait to be valid + | +LL | auto trait Generic {} + | -- error[E0568]: auto traits cannot have super traits --> $DIR/auto-trait-validation.rs:5:20 @@ -13,6 +18,11 @@ LL | auto trait Bound : Copy {} | ----- ^^^^ cannot have this super trait | | | auto trait cannot have super traits + | +help: remove the super traits for the auto trait to be valid + | +LL | auto trait Bound {} + | -- error[E0380]: auto traits cannot have methods or associated items --> $DIR/auto-trait-validation.rs:7:25 diff --git a/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr b/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr index 03d05f4c928a6..8714cfbedbbc1 100644 --- a/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr +++ b/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr @@ -5,6 +5,11 @@ LL | auto trait Magic: Copy {} | ----- ^^^^ cannot have this super trait | | | auto trait cannot have super traits + | +help: remove the super traits for the auto trait to be valid + | +LL | auto trait Magic {} + | -- error[E0277]: the trait bound `NoClone: std::marker::Copy` is not satisfied --> $DIR/traits-inductive-overflow-supertrait-oibit.rs:15:23 diff --git a/src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr b/src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr index 45c95b191bd59..c652a0c6df03d 100644 --- a/src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr +++ b/src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr @@ -5,6 +5,11 @@ LL | auto trait Magic : Sized where Option : Magic {} | ----- ^^^^^ cannot have this super trait | | | auto trait cannot have super traits + | +help: remove the super traits for the auto trait to be valid + | +LL | auto trait Magic where Option : Magic {} + | -- error: aborting due to previous error diff --git a/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr b/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr index 094f5d7dd24f2..fe6468bc71621 100644 --- a/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr +++ b/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr @@ -5,6 +5,11 @@ LL | auto trait Magic: Copy {} | ----- ^^^^ cannot have this super trait | | | auto trait cannot have super traits + | +help: remove the super traits for the auto trait to be valid + | +LL | auto trait Magic {} + | -- error: aborting due to previous error From f483032e97ba7c89f803fc6f8078f0acdd9d9b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 6 Mar 2020 11:58:52 -0800 Subject: [PATCH 11/30] review comment --- src/librustc_ast_passes/ast_validation.rs | 25 +++++++++-------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs index df229e57cf0b7..24cf4556dad2f 100644 --- a/src/librustc_ast_passes/ast_validation.rs +++ b/src/librustc_ast_passes/ast_validation.rs @@ -820,23 +820,14 @@ impl<'a> Visitor<'a> for AstValidator<'a> { ref self_ty, items: _, } => { - let error = |annotation_span, annotation, note, code| { + let error = |annotation_span, annotation| { let mut err = self.err_handler().struct_span_err( self_ty.span, &format!("inherent impls cannot be {}", annotation), ); err.span_label(annotation_span, &format!("{} because of this", annotation)); err.span_label(self_ty.span, "inherent impl for this type"); - if note { - err.note(&format!( - "only trait implementations may be annotated with {}", - annotation - )); - } - if code { - err.code(error_code!(E0197)); - } - err.emit(); + err }; self.invalid_visibility( @@ -844,16 +835,20 @@ impl<'a> Visitor<'a> for AstValidator<'a> { Some("place qualifiers on individual impl items instead"), ); if let Unsafe::Yes(span) = unsafety { - error(span, "unsafe", false, true) + error(span, "unsafe").code(error_code!(E0197)).emit(); } if let ImplPolarity::Negative(span) = polarity { - error(span, "negative", false, false); + error(span, "negative").emit(); } if let Defaultness::Default(def_span) = defaultness { - error(def_span, "`default`", true, false); + error(def_span, "`default`") + .note("only trait implementations may be annotated with `default`") + .emit(); } if let Const::Yes(span) = constness { - error(span, "`const`", true, false); + error(span, "`const`") + .note("only trait implementations may be annotated with `const`") + .emit(); } } ItemKind::Fn(def, ref sig, ref generics, ref body) => { From b900de0f778c4b66921a71824ed7745724405f45 Mon Sep 17 00:00:00 2001 From: Lena Wildervanck Date: Fri, 6 Mar 2020 10:29:11 +0100 Subject: [PATCH 12/30] Implement Error for TryReserveError --- src/liballoc/collections/mod.rs | 17 +++++++++++++++++ src/libstd/error.rs | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/src/liballoc/collections/mod.rs b/src/liballoc/collections/mod.rs index 0bb62373fab1e..9e7e66e657a93 100644 --- a/src/liballoc/collections/mod.rs +++ b/src/liballoc/collections/mod.rs @@ -42,6 +42,7 @@ pub use linked_list::LinkedList; pub use vec_deque::VecDeque; use crate::alloc::{Layout, LayoutErr}; +use core::fmt::Display; /// The error type for `try_reserve` methods. #[derive(Clone, PartialEq, Eq, Debug)] @@ -77,6 +78,22 @@ impl From for TryReserveError { } } +#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")] +impl Display for TryReserveError { + fn fmt( + &self, + fmt: &mut core::fmt::Formatter<'_>, + ) -> core::result::Result<(), core::fmt::Error> { + fmt.write_str("memory allocation failed")?; + fmt.write_str(match &self { + TryReserveError::CapacityOverflow => { + " because the computed capacity exceeded the collection's maximum" + } + TryReserveError::AllocError { .. } => " because the memory allocator returned a error", + }) + } +} + /// An intermediate trait for specialization of `Extend`. #[doc(hidden)] trait SpecExtend { diff --git a/src/libstd/error.rs b/src/libstd/error.rs index b480581e21ba9..61944edf1422b 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -552,6 +552,13 @@ impl Error for char::ParseCharError { } } +#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")] +impl Error for alloc::collections::TryReserveError { + fn description(&self) -> &str { + "memory allocation failed" + } +} + // Copied from `any.rs`. impl dyn Error + 'static { /// Returns `true` if the boxed type is the same as `T` From 48975946565e9a0adedb39a308db2fd2eeaa2839 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 8 Mar 2020 19:05:18 +0100 Subject: [PATCH 13/30] miri: ICE on invalid terminators --- src/librustc_mir/interpret/terminator.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index ea8378574a3e0..85fd502c69c31 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -114,15 +114,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { Unreachable => throw_ub!(Unreachable), // These should never occur for MIR we actually run. - DropAndReplace { .. } | FalseEdges { .. } | FalseUnwind { .. } => { - bug!("{:#?} should have been eliminated by MIR pass", terminator.kind) - } - - // These are not (yet) supported. It is unclear if they even can occur in - // MIR that we actually run. - Yield { .. } | GeneratorDrop | Abort => { - throw_unsup_format!("Unsupported terminator kind: {:#?}", terminator.kind) - } + DropAndReplace { .. } + | FalseEdges { .. } + | FalseUnwind { .. } + | Yield { .. } + | GeneratorDrop + | Abort => bug!("{:#?} should have been eliminated by MIR pass", terminator.kind), } Ok(()) From 8a8870fbae1bf601ac4d29d6c0c407a352caea57 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 9 Mar 2020 10:45:20 +0100 Subject: [PATCH 14/30] miri: add machine hook for Abort terminator --- src/librustc_mir/interpret/machine.rs | 5 +++++ src/librustc_mir/interpret/terminator.rs | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 6615cc608fb54..64a34fc7dd9ec 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -170,6 +170,11 @@ pub trait Machine<'mir, 'tcx>: Sized { unwind: Option, ) -> InterpResult<'tcx>; + /// Called to evaluate `Abort` MIR terminator. + fn abort(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> { + throw_unsup_format!("aborting execution is not supported"); + } + /// Called for all binary operations where the LHS has pointer type. /// /// Returns a (value, overflowed) pair if the operation succeeded diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index 85fd502c69c31..95d5276565f17 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -99,6 +99,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } } + Abort => { + M::abort(self)?; + } + // When we encounter Resume, we've finished unwinding // cleanup for the current stack frame. We pop it in order // to continue unwinding the next frame @@ -118,8 +122,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | FalseEdges { .. } | FalseUnwind { .. } | Yield { .. } - | GeneratorDrop - | Abort => bug!("{:#?} should have been eliminated by MIR pass", terminator.kind), + | GeneratorDrop => { + bug!("{:#?} should have been eliminated by MIR pass", terminator.kind) + } } Ok(()) From 911c75ff5f11c28c9f355857a47c5cd2d73767e7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 9 Mar 2020 20:18:48 +0100 Subject: [PATCH 15/30] also handle abort intrinsic with new machine hook --- src/librustc_mir/interpret/intrinsics.rs | 4 ++++ src/librustc_mir/interpret/machine.rs | 2 +- src/librustc_span/symbol.rs | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index 891afbf437f2b..88c6c26c5ba9a 100644 --- a/src/librustc_mir/interpret/intrinsics.rs +++ b/src/librustc_mir/interpret/intrinsics.rs @@ -103,6 +103,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { self.write_scalar(location.ptr, dest)?; } + sym::abort => { + M::abort(self)?; + } + sym::min_align_of | sym::pref_align_of | sym::needs_drop diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 64a34fc7dd9ec..a3c43d7d5d16a 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -171,7 +171,7 @@ pub trait Machine<'mir, 'tcx>: Sized { ) -> InterpResult<'tcx>; /// Called to evaluate `Abort` MIR terminator. - fn abort(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> { + fn abort(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx, !> { throw_unsup_format!("aborting execution is not supported"); } diff --git a/src/librustc_span/symbol.rs b/src/librustc_span/symbol.rs index c39f9f360c027..4f5c4de8569f6 100644 --- a/src/librustc_span/symbol.rs +++ b/src/librustc_span/symbol.rs @@ -120,6 +120,7 @@ symbols! { abi_unadjusted, abi_vectorcall, abi_x86_interrupt, + abort, aborts, address, add_with_overflow, From 88f8b881606aa22fdaabcefbf88ddc163e41d8e6 Mon Sep 17 00:00:00 2001 From: Lena Wildervanck Date: Tue, 10 Mar 2020 11:19:40 +0100 Subject: [PATCH 16/30] Remove deprecated description function of TryReserveError --- src/libstd/error.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 61944edf1422b..ba13a8a06df10 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -553,11 +553,7 @@ impl Error for char::ParseCharError { } #[unstable(feature = "try_reserve", reason = "new API", issue = "48043")] -impl Error for alloc::collections::TryReserveError { - fn description(&self) -> &str { - "memory allocation failed" - } -} +impl Error for alloc::collections::TryReserveError {} // Copied from `any.rs`. impl dyn Error + 'static { From 0037f4e37cb32f6195ab57fe4e5d34eb0adcd2d5 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 6 Mar 2020 11:13:26 -0300 Subject: [PATCH 17/30] Rename rustc-guide to rustc-dev-guide --- .github/ISSUE_TEMPLATE/tracking_issue.md | 8 ++++---- CONTRIBUTING.md | 18 +++++++++--------- README.md | 6 +++--- src/README.md | 2 +- src/doc/index.md | 2 +- src/doc/rustc/src/contributing.md | 2 +- src/librustc/README.md | 2 +- src/librustc/dep_graph/README.md | 2 +- src/librustc/dep_graph/graph.rs | 2 +- src/librustc/hir/mod.rs | 2 +- src/librustc/infer/canonical.rs | 2 +- src/librustc/lib.rs | 2 +- src/librustc/middle/region.rs | 2 +- src/librustc/mir/mod.rs | 2 +- src/librustc/traits/mod.rs | 2 +- src/librustc/traits/select.rs | 2 +- src/librustc/ty/context.rs | 2 +- src/librustc/ty/query/README.md | 2 +- src/librustc/ty/sty.rs | 2 +- src/librustc_ast/README.md | 4 ++-- src/librustc_codegen_llvm/README.md | 2 +- src/librustc_codegen_ssa/README.md | 4 ++-- src/librustc_driver/README.md | 2 +- src/librustc_hir/hir.rs | 2 +- src/librustc_hir/lib.rs | 2 +- src/librustc_incremental/persist/README.md | 2 +- .../infer/canonical/canonicalizer.rs | 6 +++--- src/librustc_infer/infer/canonical/mod.rs | 2 +- .../infer/canonical/query_response.rs | 4 ++-- .../infer/canonical/substitute.rs | 2 +- .../infer/higher_ranked/README.md | 6 +++--- src/librustc_infer/infer/higher_ranked/mod.rs | 2 +- .../infer/lexical_region_resolve/README.md | 4 ++-- .../infer/region_constraints/README.md | 2 +- src/librustc_infer/lib.rs | 2 +- src/librustc_infer/traits/coherence.rs | 4 ++-- src/librustc_infer/traits/mod.rs | 2 +- src/librustc_infer/traits/query/type_op/mod.rs | 2 +- src/librustc_infer/traits/select.rs | 6 +++--- src/librustc_infer/traits/specialize/mod.rs | 2 +- src/librustc_passes/region.rs | 2 +- src/librustc_target/README.md | 2 +- src/librustc_typeck/README.md | 4 ++-- src/librustc_typeck/check/method/mod.rs | 2 +- src/librustc_typeck/variance/mod.rs | 2 +- src/librustc_typeck/variance/terms.rs | 4 ++-- src/librustdoc/README.md | 2 +- src/test/COMPILER_TESTS.md | 2 +- triagebot.toml | 4 ++-- 49 files changed, 76 insertions(+), 76 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/tracking_issue.md b/.github/ISSUE_TEMPLATE/tracking_issue.md index f93591204cd98..faf84bf8aca5c 100644 --- a/.github/ISSUE_TEMPLATE/tracking_issue.md +++ b/.github/ISSUE_TEMPLATE/tracking_issue.md @@ -36,11 +36,11 @@ for larger features an implementation could be broken up into multiple PRs. - [ ] Implement the RFC (cc @rust-lang/XXX -- can anyone write up mentoring instructions?) -- [ ] Adjust documentation ([see instructions on rustc-guide][doc-guide]) -- [ ] Stabilization PR ([see instructions on rustc-guide][stabilization-guide]) +- [ ] Adjust documentation ([see instructions on rustc-dev-guide][doc-guide]) +- [ ] Stabilization PR ([see instructions on rustc-dev-guide][stabilization-guide]) -[stabilization-guide]: https://rust-lang.github.io/rustc-guide/stabilization_guide.html#stabilization-pr -[doc-guide]: https://rust-lang.github.io/rustc-guide/stabilization_guide.html#documentation-prs +[stabilization-guide]: https://rust-lang.github.io/rustc-dev-guide/stabilization_guide.html#stabilization-pr +[doc-guide]: https://rust-lang.github.io/rustc-dev-guide/stabilization_guide.html#documentation-prs ### Unresolved Questions $DIR/auto-trait-validation.rs:3:20 + --> $DIR/auto-trait-validation.rs:3:19 | LL | auto trait Generic {} - | ------- ^ cannot have this generic parameter + | -------^^^ help: remove the parameters | | | auto trait cannot have generic parameters - | -help: remove the parameters for the auto trait to be valid - | -LL | auto trait Generic {} - | -- error[E0568]: auto traits cannot have super traits --> $DIR/auto-trait-validation.rs:5:20 | LL | auto trait Bound : Copy {} - | ----- ^^^^ cannot have this super trait + | ----- ^^^^ help: remove the super traits | | | auto trait cannot have super traits - | -help: remove the super traits for the auto trait to be valid - | -LL | auto trait Bound {} - | -- error[E0380]: auto traits cannot have methods or associated items --> $DIR/auto-trait-validation.rs:7:25 diff --git a/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr b/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr index 8714cfbedbbc1..a83ff3701511d 100644 --- a/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr +++ b/src/test/ui/traits/traits-inductive-overflow-supertrait-oibit.stderr @@ -2,14 +2,9 @@ error[E0568]: auto traits cannot have super traits --> $DIR/traits-inductive-overflow-supertrait-oibit.rs:7:19 | LL | auto trait Magic: Copy {} - | ----- ^^^^ cannot have this super trait + | ----- ^^^^ help: remove the super traits | | | auto trait cannot have super traits - | -help: remove the super traits for the auto trait to be valid - | -LL | auto trait Magic {} - | -- error[E0277]: the trait bound `NoClone: std::marker::Copy` is not satisfied --> $DIR/traits-inductive-overflow-supertrait-oibit.rs:15:23 diff --git a/src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr b/src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr index c652a0c6df03d..e397629327754 100644 --- a/src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr +++ b/src/test/ui/typeck/typeck-auto-trait-no-supertraits-2.stderr @@ -2,14 +2,9 @@ error[E0568]: auto traits cannot have super traits --> $DIR/typeck-auto-trait-no-supertraits-2.rs:3:20 | LL | auto trait Magic : Sized where Option : Magic {} - | ----- ^^^^^ cannot have this super trait + | ----- ^^^^^ help: remove the super traits | | | auto trait cannot have super traits - | -help: remove the super traits for the auto trait to be valid - | -LL | auto trait Magic where Option : Magic {} - | -- error: aborting due to previous error diff --git a/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr b/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr index fe6468bc71621..b1602e3642ecb 100644 --- a/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr +++ b/src/test/ui/typeck/typeck-auto-trait-no-supertraits.stderr @@ -2,14 +2,9 @@ error[E0568]: auto traits cannot have super traits --> $DIR/typeck-auto-trait-no-supertraits.rs:27:19 | LL | auto trait Magic: Copy {} - | ----- ^^^^ cannot have this super trait + | ----- ^^^^ help: remove the super traits | | | auto trait cannot have super traits - | -help: remove the super traits for the auto trait to be valid - | -LL | auto trait Magic {} - | -- error: aborting due to previous error From 3244c84363e337ae07cf8dda07876d3c044e759e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Wed, 11 Mar 2020 14:24:07 +0100 Subject: [PATCH 23/30] rustdoc: remove unused import --- src/librustdoc/clean/inline.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 7cb870ae702fb..f600b3308e882 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -12,7 +12,6 @@ use rustc_hir::Mutability; use rustc_metadata::creader::LoadedMacro; use rustc_mir::const_eval::is_min_const_fn; use rustc_span::hygiene::MacroKind; -use rustc_span::symbol::sym; use rustc_span::Span; use crate::clean::{self, GetDefId, ToSource, TypeKind}; From 7ee1b470920d2ff4d6ffb100a5bbcf594b9031a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 11 Mar 2020 09:17:55 -0700 Subject: [PATCH 24/30] review comments --- src/librustc_ast_passes/ast_validation.rs | 103 +++++++++++----------- src/librustc_ast_passes/lib.rs | 1 + 2 files changed, 53 insertions(+), 51 deletions(-) diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs index 668ac8047d17b..2a39dc6b011e7 100644 --- a/src/librustc_ast_passes/ast_validation.rs +++ b/src/librustc_ast_passes/ast_validation.rs @@ -9,6 +9,7 @@ use rustc_ast::ast::*; use rustc_ast::attr; use rustc_ast::expand::is_proc_macro_attr; +use rustc_ast::ptr::P; use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor}; use rustc_ast::walk_list; use rustc_ast_pretty::pprust; @@ -594,6 +595,54 @@ impl<'a> AstValidator<'a> { .span_label(ident.span, format!("`_` is not a valid name for this `{}` item", kind)) .emit(); } + + fn deny_generic_params(&self, generics: &Generics, ident_span: Span) { + if !generics.params.is_empty() { + struct_span_err!( + self.session, + generics.span, + E0567, + "auto traits cannot have generic parameters" + ) + .span_label(ident_span, "auto trait cannot have generic parameters") + .span_suggestion( + generics.span, + "remove the parameters", + String::new(), + Applicability::MachineApplicable, + ) + .emit(); + } + } + + fn deny_super_traits(&self, bounds: &GenericBounds, ident_span: Span) { + if let [first @ last] | [first, .., last] = &bounds[..] { + let span = first.span().to(last.span()); + struct_span_err!(self.session, span, E0568, "auto traits cannot have super traits") + .span_label(ident_span, "auto trait cannot have super traits") + .span_suggestion( + span, + "remove the super traits", + String::new(), + Applicability::MachineApplicable, + ) + .emit(); + } + } + + fn deny_items(&self, trait_items: &[P], ident_span: Span) { + if !trait_items.is_empty() { + let spans: Vec<_> = trait_items.iter().map(|i| i.ident.span).collect(); + struct_span_err!( + self.session, + spans, + E0380, + "auto traits cannot have methods or associated items" + ) + .span_label(ident_span, "auto trait cannot have items") + .emit(); + } + } } fn validate_generic_param_order<'a>( @@ -881,57 +930,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> { ItemKind::Trait(is_auto, _, ref generics, ref bounds, ref trait_items) => { if is_auto == IsAuto::Yes { // Auto traits cannot have generics, super traits nor contain items. - if !generics.params.is_empty() { - let mut err = struct_span_err!( - self.session, - generics.span, - E0567, - "auto traits cannot have generic parameters" - ); - err.span_label( - item.ident.span, - "auto trait cannot have generic parameters", - ); - err.span_suggestion( - generics.span, - "remove the parameters", - String::new(), - Applicability::MachineApplicable, - ); - err.emit(); - } - if !bounds.is_empty() { - let span = match &bounds[..] { - [] => unreachable!(), - [single] => single.span(), - [first, .., last] => first.span().to(last.span()), - }; - let mut err = struct_span_err!( - self.session, - span, - E0568, - "auto traits cannot have super traits" - ); - err.span_label(item.ident.span, "auto trait cannot have super traits"); - err.span_suggestion( - span, - "remove the super traits", - String::new(), - Applicability::MachineApplicable, - ); - err.emit(); - } - if !trait_items.is_empty() { - let spans: Vec<_> = trait_items.iter().map(|i| i.ident.span).collect(); - struct_span_err!( - self.session, - spans, - E0380, - "auto traits cannot have methods or associated items" - ) - .span_label(item.ident.span, "auto trait cannot have items") - .emit(); - } + self.deny_generic_params(generics, item.ident.span); + self.deny_super_traits(bounds, item.ident.span); + self.deny_items(trait_items, item.ident.span); } self.no_questions_in_bounds(bounds, "supertraits", true); diff --git a/src/librustc_ast_passes/lib.rs b/src/librustc_ast_passes/lib.rs index 520a7ac3e5665..10081d36754ba 100644 --- a/src/librustc_ast_passes/lib.rs +++ b/src/librustc_ast_passes/lib.rs @@ -1,3 +1,4 @@ +#![feature(bindings_after_at)] //! The `rustc_ast_passes` crate contains passes which validate the AST in `syntax` //! parsed by `rustc_parse` and then lowered, after the passes in this crate, //! by `rustc_ast_lowering`. From c0c526951c87c79e0db5e6e32b95bbe0a01347d3 Mon Sep 17 00:00:00 2001 From: Kinsey Favre Date: Thu, 6 Feb 2020 12:25:18 -0600 Subject: [PATCH 25/30] Add Display and Error impls for proc_macro::LexError This should allow LexError to play much nicer with the `?` operator. --- src/libproc_macro/lib.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index c51db695a5b15..5ae7640d4b873 100644 --- a/src/libproc_macro/lib.rs +++ b/src/libproc_macro/lib.rs @@ -41,7 +41,7 @@ pub use diagnostic::{Diagnostic, Level, MultiSpan}; use std::ops::{Bound, RangeBounds}; use std::path::PathBuf; use std::str::FromStr; -use std::{fmt, iter, mem}; +use std::{error, fmt, iter, mem}; /// The main type provided by this crate, representing an abstract stream of /// tokens, or, more specifically, a sequence of token trees. @@ -66,6 +66,16 @@ pub struct LexError { _inner: (), } +#[stable(feature = "proc_macro_lib", since = "1.15.0")] +impl fmt::Display for LexError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("lex error") + } +} + +#[stable(feature = "proc_macro_lib", since = "1.15.0")] +impl error::Error for LexError {} + #[stable(feature = "proc_macro_lib", since = "1.15.0")] impl !Send for LexError {} #[stable(feature = "proc_macro_lib", since = "1.15.0")] From 599cd683eac7fdb076fe86f2928062e087214a22 Mon Sep 17 00:00:00 2001 From: Lena Wildervanck Date: Wed, 11 Mar 2020 17:30:04 +0100 Subject: [PATCH 26/30] Format the match statement --- src/liballoc/collections/mod.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/liballoc/collections/mod.rs b/src/liballoc/collections/mod.rs index 9e7e66e657a93..b2e9b89cbda5b 100644 --- a/src/liballoc/collections/mod.rs +++ b/src/liballoc/collections/mod.rs @@ -85,12 +85,15 @@ impl Display for TryReserveError { fmt: &mut core::fmt::Formatter<'_>, ) -> core::result::Result<(), core::fmt::Error> { fmt.write_str("memory allocation failed")?; - fmt.write_str(match &self { + let reason = match &self { TryReserveError::CapacityOverflow => { " because the computed capacity exceeded the collection's maximum" } - TryReserveError::AllocError { .. } => " because the memory allocator returned a error", - }) + TryReserveError::AllocError { .. } => { + " because the memory allocator returned a error" + } + }; + fmt.write_str(reason) } } From 2c90a37969644866d0503c20a94196de3f6bea99 Mon Sep 17 00:00:00 2001 From: Lena Wildervanck Date: Wed, 11 Mar 2020 17:55:14 +0100 Subject: [PATCH 27/30] Reformat match statement to make the check pass --- src/liballoc/collections/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/liballoc/collections/mod.rs b/src/liballoc/collections/mod.rs index b2e9b89cbda5b..6b21e54f66aa0 100644 --- a/src/liballoc/collections/mod.rs +++ b/src/liballoc/collections/mod.rs @@ -89,9 +89,7 @@ impl Display for TryReserveError { TryReserveError::CapacityOverflow => { " because the computed capacity exceeded the collection's maximum" } - TryReserveError::AllocError { .. } => { - " because the memory allocator returned a error" - } + TryReserveError::AllocError { .. } => " because the memory allocator returned a error", }; fmt.write_str(reason) } From f2b22a136c9129a2f74cd897d8f1ea8ff5386e99 Mon Sep 17 00:00:00 2001 From: Kinsey Favre Date: Sat, 8 Feb 2020 09:55:49 -0600 Subject: [PATCH 28/30] Correct stability attribute for new LexError impls --- src/libproc_macro/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index 5ae7640d4b873..13bce45243fe1 100644 --- a/src/libproc_macro/lib.rs +++ b/src/libproc_macro/lib.rs @@ -66,14 +66,14 @@ pub struct LexError { _inner: (), } -#[stable(feature = "proc_macro_lib", since = "1.15.0")] +#[stable(feature = "proc_macro_lexerror_impls", since = "1.44.0")] impl fmt::Display for LexError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("lex error") } } -#[stable(feature = "proc_macro_lib", since = "1.15.0")] +#[stable(feature = "proc_macro_lexerror_impls", since = "1.44.0")] impl error::Error for LexError {} #[stable(feature = "proc_macro_lib", since = "1.15.0")] From 5099ab6e6b80c02f2b16e99c169d318cfd9252c1 Mon Sep 17 00:00:00 2001 From: Kinsey Favre Date: Sat, 8 Feb 2020 10:51:54 -0600 Subject: [PATCH 29/30] Give LexError more descriptive Display impl --- src/libproc_macro/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index 13bce45243fe1..59ce14c97c0e6 100644 --- a/src/libproc_macro/lib.rs +++ b/src/libproc_macro/lib.rs @@ -69,7 +69,7 @@ pub struct LexError { #[stable(feature = "proc_macro_lexerror_impls", since = "1.44.0")] impl fmt::Display for LexError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str("lex error") + f.write_str("cannot parse string into token stream") } } From d7100d60999c1e339ec536c3321b98e0f2b9e8b3 Mon Sep 17 00:00:00 2001 From: YI Date: Thu, 12 Mar 2020 18:43:51 +0800 Subject: [PATCH 30/30] update outdated comment --- src/librustc_typeck/constrained_generic_params.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_typeck/constrained_generic_params.rs b/src/librustc_typeck/constrained_generic_params.rs index 9b187d461cdeb..aff3768e35c55 100644 --- a/src/librustc_typeck/constrained_generic_params.rs +++ b/src/librustc_typeck/constrained_generic_params.rs @@ -36,7 +36,7 @@ pub fn parameters_for_impl<'tcx>( vec.into_iter().collect() } -/// If `include_projections` is false, returns the list of parameters that are +/// If `include_nonconstraining` is false, returns the list of parameters that are /// constrained by `t` - i.e., the value of each parameter in the list is /// uniquely determined by `t` (see RFC 447). If it is true, return the list /// of parameters whose values are needed in order to constrain `ty` - these