authorbors <bors@rust-lang.org> 2025-06-22 09:49:14 UTC
committerbors <bors@rust-lang.org> 2025-06-22 09:49:14 UTC
loga30f1783fe136d92545423dd30b12eb619973cdb
tree61f87ea56fcedeae69b194a37dd41b06e1f5f866
parent9972ebfcc2b1ab322dc6611c1c997344078e05cd
parent34dd5362be9fc460208d7b465d0911f25ab4035b

Auto merge of #142864 - jhpratt:rollup-mf0yq8o, r=jhpratt

Rollup of 10 pull requests Successful merges: - rust-lang/rust#140254 (Pass -Cpanic=abort for the panic_abort crate) - rust-lang/rust#142600 (Port `#[rustc_pub_transparent]` to the new attribute system) - rust-lang/rust#142617 (improve search graph docs, reset `encountered_overflow` between reruns) - rust-lang/rust#142747 (rustdoc_json: conversion cleanups) - rust-lang/rust#142776 (All HIR attributes are outer) - rust-lang/rust#142800 (integer docs: remove extraneous text) - rust-lang/rust#142841 (Enable fmt-write-bloat for Windows) - rust-lang/rust#142845 (Enable textrel-on-minimal-lib for Windows) - rust-lang/rust#142850 (remove asm_goto feature annotation, for it is now stabilized) - rust-lang/rust#142860 (Notify me on tidy changes) r? `@ghost` `@rustbot` modify labels: rollup

36 files changed, 536 insertions(+), 913 deletions(-)

compiler/rustc_ast/src/attr/mod.rs+22-7
......@@ -206,12 +206,24 @@ impl AttributeExt for Attribute {
206206 }
207207 }
208208
209 fn style(&self) -> AttrStyle {
210 self.style
209 fn doc_resolution_scope(&self) -> Option<AttrStyle> {
210 match &self.kind {
211 AttrKind::DocComment(..) => Some(self.style),
212 AttrKind::Normal(normal)
213 if normal.item.path == sym::doc && normal.item.value_str().is_some() =>
214 {
215 Some(self.style)
216 }
217 _ => None,
218 }
211219 }
212220}
213221
214222impl Attribute {
223 pub fn style(&self) -> AttrStyle {
224 self.style
225 }
226
215227 pub fn may_have_doc_links(&self) -> bool {
216228 self.doc_str().is_some_and(|s| comments::may_have_doc_links(s.as_str()))
217229 }
......@@ -806,7 +818,14 @@ pub trait AttributeExt: Debug {
806818 /// * `#[doc(...)]` returns `None`.
807819 fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)>;
808820
809 fn style(&self) -> AttrStyle;
821 /// Returns outer or inner if this is a doc attribute or a sugared doc
822 /// comment, otherwise None.
823 ///
824 /// This is used in the case of doc comments on modules, to decide whether
825 /// to resolve intra-doc links against the symbols in scope within the
826 /// commented module (for inner doc) vs within its parent module (for outer
827 /// doc).
828 fn doc_resolution_scope(&self) -> Option<AttrStyle>;
810829}
811830
812831// FIXME(fn_delegation): use function delegation instead of manually forwarding
......@@ -881,8 +900,4 @@ impl Attribute {
881900 pub fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)> {
882901 AttributeExt::doc_str_and_comment_kind(self)
883902 }
884
885 pub fn style(&self) -> AttrStyle {
886 AttributeExt::style(self)
887 }
888903}
compiler/rustc_attr_data_structures/src/attributes.rs+3
......@@ -240,6 +240,9 @@ pub enum AttributeKind {
240240 /// Represents `#[optimize(size|speed)]`
241241 Optimize(OptimizeAttr, Span),
242242
243 /// Represents `#[rustc_pub_transparent]` (used by the `repr_transparent_external_private_fields` lint).
244 PubTransparent(Span),
245
243246 /// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations).
244247 Repr(ThinVec<(ReprAttr, Span)>),
245248
compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs+13
......@@ -19,3 +19,16 @@ impl<S: Stage> SingleAttributeParser<S> for AsPtrParser {
1919 Some(AttributeKind::AsPtr(cx.attr_span))
2020 }
2121}
22
23pub(crate) struct PubTransparentParser;
24impl<S: Stage> SingleAttributeParser<S> for PubTransparentParser {
25 const PATH: &[Symbol] = &[sym::rustc_pub_transparent];
26 const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
27 const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
28 const TEMPLATE: AttributeTemplate = template!(Word);
29
30 fn convert(cx: &mut AcceptContext<'_, '_, S>, _args: &ArgParser<'_>) -> Option<AttributeKind> {
31 // FIXME: check that there's no args (this is currently checked elsewhere)
32 Some(AttributeKind::PubTransparent(cx.attr_span))
33 }
34}
compiler/rustc_attr_parsing/src/context.rs+2-1
......@@ -19,7 +19,7 @@ use crate::attributes::codegen_attrs::{ColdParser, OptimizeParser};
1919use crate::attributes::confusables::ConfusablesParser;
2020use crate::attributes::deprecation::DeprecationParser;
2121use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
22use crate::attributes::lint_helpers::AsPtrParser;
22use crate::attributes::lint_helpers::{AsPtrParser, PubTransparentParser};
2323use crate::attributes::repr::{AlignParser, ReprParser};
2424use crate::attributes::semantics::MayDangleParser;
2525use crate::attributes::stability::{
......@@ -113,6 +113,7 @@ attribute_parsers!(
113113 Single<InlineParser>,
114114 Single<MayDangleParser>,
115115 Single<OptimizeParser>,
116 Single<PubTransparentParser>,
116117 Single<RustcForceInlineParser>,
117118 Single<TransparencyParser>,
118119 // tidy-alphabetical-end
compiler/rustc_feature/src/builtin_attrs.rs+1-1
......@@ -710,7 +710,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
710710 ),
711711 rustc_attr!(
712712 rustc_pub_transparent, Normal, template!(Word),
713 WarnFollowing, EncodeCrossCrate::Yes,
713 ErrorFollowing, EncodeCrossCrate::Yes,
714714 "used internally to mark types with a `transparent` representation when it is guaranteed by the documentation",
715715 ),
716716
compiler/rustc_hir/src/hir.rs+10-21
......@@ -1346,12 +1346,13 @@ impl AttributeExt for Attribute {
13461346 }
13471347 }
13481348
1349 #[inline]
1350 fn style(&self) -> AttrStyle {
1351 match &self {
1352 Attribute::Unparsed(u) => u.style,
1353 Attribute::Parsed(AttributeKind::DocComment { style, .. }) => *style,
1354 _ => panic!(),
1349 fn doc_resolution_scope(&self) -> Option<AttrStyle> {
1350 match self {
1351 Attribute::Parsed(AttributeKind::DocComment { style, .. }) => Some(*style),
1352 Attribute::Unparsed(attr) if self.has_name(sym::doc) && self.value_str().is_some() => {
1353 Some(attr.style)
1354 }
1355 _ => None,
13551356 }
13561357 }
13571358}
......@@ -1442,11 +1443,6 @@ impl Attribute {
14421443 pub fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)> {
14431444 AttributeExt::doc_str_and_comment_kind(self)
14441445 }
1445
1446 #[inline]
1447 pub fn style(&self) -> AttrStyle {
1448 AttributeExt::style(self)
1449 }
14501446}
14511447
14521448/// Attributes owned by a HIR owner.
......@@ -2286,16 +2282,9 @@ pub struct Expr<'hir> {
22862282}
22872283
22882284impl Expr<'_> {
2289 pub fn precedence(
2290 &self,
2291 for_each_attr: &dyn Fn(HirId, &mut dyn FnMut(&Attribute)),
2292 ) -> ExprPrecedence {
2285 pub fn precedence(&self, has_attr: &dyn Fn(HirId) -> bool) -> ExprPrecedence {
22932286 let prefix_attrs_precedence = || -> ExprPrecedence {
2294 let mut has_outer_attr = false;
2295 for_each_attr(self.hir_id, &mut |attr: &Attribute| {
2296 has_outer_attr |= matches!(attr.style(), AttrStyle::Outer)
2297 });
2298 if has_outer_attr { ExprPrecedence::Prefix } else { ExprPrecedence::Unambiguous }
2287 if has_attr(self.hir_id) { ExprPrecedence::Prefix } else { ExprPrecedence::Unambiguous }
22992288 };
23002289
23012290 match &self.kind {
......@@ -2351,7 +2340,7 @@ impl Expr<'_> {
23512340 | ExprKind::Use(..)
23522341 | ExprKind::Err(_) => prefix_attrs_precedence(),
23532342
2354 ExprKind::DropTemps(expr, ..) => expr.precedence(for_each_attr),
2343 ExprKind::DropTemps(expr, ..) => expr.precedence(has_attr),
23552344 }
23562345 }
23572346
compiler/rustc_hir_analysis/src/check/check.rs+6-1
......@@ -2,6 +2,7 @@ use std::cell::LazyCell;
22use std::ops::ControlFlow;
33
44use rustc_abi::FieldIdx;
5use rustc_attr_data_structures::AttributeKind;
56use rustc_attr_data_structures::ReprAttr::ReprPacked;
67use rustc_data_structures::unord::{UnordMap, UnordSet};
78use rustc_errors::codes::*;
......@@ -1384,7 +1385,11 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
13841385 ty::Tuple(list) => list.iter().try_for_each(|t| check_non_exhaustive(tcx, t)),
13851386 ty::Array(ty, _) => check_non_exhaustive(tcx, *ty),
13861387 ty::Adt(def, args) => {
1387 if !def.did().is_local() && !tcx.has_attr(def.did(), sym::rustc_pub_transparent)
1388 if !def.did().is_local()
1389 && !attrs::find_attr!(
1390 tcx.get_all_attrs(def.did()),
1391 AttributeKind::PubTransparent(_)
1392 )
13881393 {
13891394 let non_exhaustive = def.is_variant_list_non_exhaustive()
13901395 || def
compiler/rustc_hir_pretty/src/lib.rs+40-54
......@@ -10,7 +10,7 @@ use std::vec;
1010
1111use rustc_abi::ExternAbi;
1212use rustc_ast::util::parser::{self, ExprPrecedence, Fixity};
13use rustc_ast::{AttrStyle, DUMMY_NODE_ID, DelimArgs};
13use rustc_ast::{DUMMY_NODE_ID, DelimArgs};
1414use rustc_ast_pretty::pp::Breaks::{Consistent, Inconsistent};
1515use rustc_ast_pretty::pp::{self, BoxMarker, Breaks};
1616use rustc_ast_pretty::pprust::state::MacHeader;
......@@ -81,32 +81,24 @@ impl<'a> State<'a> {
8181 }
8282
8383 fn precedence(&self, expr: &hir::Expr<'_>) -> ExprPrecedence {
84 let for_each_attr = |id: HirId, callback: &mut dyn FnMut(&hir::Attribute)| {
85 self.attrs(id).iter().for_each(callback);
86 };
87 expr.precedence(&for_each_attr)
88 }
89
90 fn print_attrs_as_inner(&mut self, attrs: &[hir::Attribute]) {
91 self.print_either_attributes(attrs, ast::AttrStyle::Inner)
92 }
93
94 fn print_attrs_as_outer(&mut self, attrs: &[hir::Attribute]) {
95 self.print_either_attributes(attrs, ast::AttrStyle::Outer)
84 let has_attr = |id: HirId| !self.attrs(id).is_empty();
85 expr.precedence(&has_attr)
9686 }
9787
98 fn print_either_attributes(&mut self, attrs: &[hir::Attribute], style: ast::AttrStyle) {
88 fn print_attrs(&mut self, attrs: &[hir::Attribute]) {
9989 if attrs.is_empty() {
10090 return;
10191 }
10292
10393 for attr in attrs {
104 self.print_attribute_inline(attr, style);
94 self.print_attribute_as_style(attr, ast::AttrStyle::Outer);
10595 }
10696 self.hardbreak_if_not_bol();
10797 }
10898
109 fn print_attribute_inline(&mut self, attr: &hir::Attribute, style: AttrStyle) {
99 /// Print a single attribute as if it has style `style`, disregarding the
100 /// actual style of the attribute.
101 fn print_attribute_as_style(&mut self, attr: &hir::Attribute, style: ast::AttrStyle) {
110102 match &attr {
111103 hir::Attribute::Unparsed(unparsed) => {
112104 self.maybe_print_comment(unparsed.span.lo());
......@@ -118,14 +110,17 @@ impl<'a> State<'a> {
118110 self.word("]");
119111 self.hardbreak()
120112 }
121 hir::Attribute::Parsed(AttributeKind::DocComment { style, kind, comment, .. }) => {
113 hir::Attribute::Parsed(AttributeKind::DocComment { kind, comment, .. }) => {
122114 self.word(rustc_ast_pretty::pprust::state::doc_comment_to_string(
123 *kind, *style, *comment,
115 *kind, style, *comment,
124116 ));
125117 self.hardbreak()
126118 }
127119 hir::Attribute::Parsed(pa) => {
128 self.word("#[attr = ");
120 match style {
121 ast::AttrStyle::Inner => self.word("#![attr = "),
122 ast::AttrStyle::Outer => self.word("#[attr = "),
123 }
129124 pa.print_attribute(self);
130125 self.word("]");
131126 self.hardbreak()
......@@ -281,10 +276,17 @@ pub fn print_crate<'a>(
281276 ann,
282277 };
283278
279 // Print all attributes, regardless of actual style, as inner attributes
280 // since this is the crate root with nothing above it to print outer
281 // attributes.
282 for attr in s.attrs(hir::CRATE_HIR_ID) {
283 s.print_attribute_as_style(attr, ast::AttrStyle::Inner);
284 }
285
284286 // When printing the AST, we sometimes need to inject `#[no_std]` here.
285287 // Since you can't compile the HIR, it's not necessary.
286288
287 s.print_mod(krate, (*attrs)(hir::CRATE_HIR_ID));
289 s.print_mod(krate);
288290 s.print_remaining_comments();
289291 s.s.eof()
290292}
......@@ -299,7 +301,7 @@ where
299301}
300302
301303pub fn attribute_to_string(ann: &dyn PpAnn, attr: &hir::Attribute) -> String {
302 to_string(ann, |s| s.print_attribute_inline(attr, AttrStyle::Outer))
304 to_string(ann, |s| s.print_attribute_as_style(attr, ast::AttrStyle::Outer))
303305}
304306
305307pub fn ty_to_string(ann: &dyn PpAnn, ty: &hir::Ty<'_>) -> String {
......@@ -361,8 +363,7 @@ impl<'a> State<'a> {
361363 self.commasep_cmnt(b, exprs, |s, e| s.print_expr(e), |e| e.span);
362364 }
363365
364 fn print_mod(&mut self, _mod: &hir::Mod<'_>, attrs: &[hir::Attribute]) {
365 self.print_attrs_as_inner(attrs);
366 fn print_mod(&mut self, _mod: &hir::Mod<'_>) {
366367 for &item_id in _mod.item_ids {
367368 self.ann.nested(self, Nested::Item(item_id));
368369 }
......@@ -479,7 +480,7 @@ impl<'a> State<'a> {
479480 fn print_foreign_item(&mut self, item: &hir::ForeignItem<'_>) {
480481 self.hardbreak_if_not_bol();
481482 self.maybe_print_comment(item.span.lo());
482 self.print_attrs_as_outer(self.attrs(item.hir_id()));
483 self.print_attrs(self.attrs(item.hir_id()));
483484 match item.kind {
484485 hir::ForeignItemKind::Fn(sig, arg_idents, generics) => {
485486 let (cb, ib) = self.head("");
......@@ -565,7 +566,7 @@ impl<'a> State<'a> {
565566 self.hardbreak_if_not_bol();
566567 self.maybe_print_comment(item.span.lo());
567568 let attrs = self.attrs(item.hir_id());
568 self.print_attrs_as_outer(attrs);
569 self.print_attrs(attrs);
569570 self.ann.pre(self, AnnNode::Item(item));
570571 match item.kind {
571572 hir::ItemKind::ExternCrate(orig_name, ident) => {
......@@ -647,14 +648,13 @@ impl<'a> State<'a> {
647648 self.print_ident(ident);
648649 self.nbsp();
649650 self.bopen(ib);
650 self.print_mod(mod_, attrs);
651 self.print_mod(mod_);
651652 self.bclose(item.span, cb);
652653 }
653654 hir::ItemKind::ForeignMod { abi, items } => {
654655 let (cb, ib) = self.head("extern");
655656 self.word_nbsp(abi.to_string());
656657 self.bopen(ib);
657 self.print_attrs_as_inner(self.attrs(item.hir_id()));
658658 for item in items {
659659 self.ann.nested(self, Nested::ForeignItem(item.id));
660660 }
......@@ -731,7 +731,6 @@ impl<'a> State<'a> {
731731
732732 self.space();
733733 self.bopen(ib);
734 self.print_attrs_as_inner(attrs);
735734 for impl_item in items {
736735 self.ann.nested(self, Nested::ImplItem(impl_item.id));
737736 }
......@@ -822,7 +821,7 @@ impl<'a> State<'a> {
822821 for v in variants {
823822 self.space_if_not_bol();
824823 self.maybe_print_comment(v.span.lo());
825 self.print_attrs_as_outer(self.attrs(v.hir_id));
824 self.print_attrs(self.attrs(v.hir_id));
826825 let ib = self.ibox(INDENT_UNIT);
827826 self.print_variant(v);
828827 self.word(",");
......@@ -857,7 +856,7 @@ impl<'a> State<'a> {
857856 self.popen();
858857 self.commasep(Inconsistent, struct_def.fields(), |s, field| {
859858 s.maybe_print_comment(field.span.lo());
860 s.print_attrs_as_outer(s.attrs(field.hir_id));
859 s.print_attrs(s.attrs(field.hir_id));
861860 s.print_type(field.ty);
862861 });
863862 self.pclose();
......@@ -878,7 +877,7 @@ impl<'a> State<'a> {
878877 for field in struct_def.fields() {
879878 self.hardbreak_if_not_bol();
880879 self.maybe_print_comment(field.span.lo());
881 self.print_attrs_as_outer(self.attrs(field.hir_id));
880 self.print_attrs(self.attrs(field.hir_id));
882881 self.print_ident(field.ident);
883882 self.word_nbsp(":");
884883 self.print_type(field.ty);
......@@ -916,7 +915,7 @@ impl<'a> State<'a> {
916915 self.ann.pre(self, AnnNode::SubItem(ti.hir_id()));
917916 self.hardbreak_if_not_bol();
918917 self.maybe_print_comment(ti.span.lo());
919 self.print_attrs_as_outer(self.attrs(ti.hir_id()));
918 self.print_attrs(self.attrs(ti.hir_id()));
920919 match ti.kind {
921920 hir::TraitItemKind::Const(ty, default) => {
922921 self.print_associated_const(ti.ident, ti.generics, ty, default);
......@@ -944,7 +943,7 @@ impl<'a> State<'a> {
944943 self.ann.pre(self, AnnNode::SubItem(ii.hir_id()));
945944 self.hardbreak_if_not_bol();
946945 self.maybe_print_comment(ii.span.lo());
947 self.print_attrs_as_outer(self.attrs(ii.hir_id()));
946 self.print_attrs(self.attrs(ii.hir_id()));
948947
949948 match ii.kind {
950949 hir::ImplItemKind::Const(ty, expr) => {
......@@ -1028,27 +1027,16 @@ impl<'a> State<'a> {
10281027 }
10291028
10301029 fn print_block(&mut self, blk: &hir::Block<'_>, cb: BoxMarker, ib: BoxMarker) {
1031 self.print_block_with_attrs(blk, &[], cb, ib)
1030 self.print_block_maybe_unclosed(blk, Some(cb), ib)
10321031 }
10331032
10341033 fn print_block_unclosed(&mut self, blk: &hir::Block<'_>, ib: BoxMarker) {
1035 self.print_block_maybe_unclosed(blk, &[], None, ib)
1036 }
1037
1038 fn print_block_with_attrs(
1039 &mut self,
1040 blk: &hir::Block<'_>,
1041 attrs: &[hir::Attribute],
1042 cb: BoxMarker,
1043 ib: BoxMarker,
1044 ) {
1045 self.print_block_maybe_unclosed(blk, attrs, Some(cb), ib)
1034 self.print_block_maybe_unclosed(blk, None, ib)
10461035 }
10471036
10481037 fn print_block_maybe_unclosed(
10491038 &mut self,
10501039 blk: &hir::Block<'_>,
1051 attrs: &[hir::Attribute],
10521040 cb: Option<BoxMarker>,
10531041 ib: BoxMarker,
10541042 ) {
......@@ -1060,8 +1048,6 @@ impl<'a> State<'a> {
10601048 self.ann.pre(self, AnnNode::Block(blk));
10611049 self.bopen(ib);
10621050
1063 self.print_attrs_as_inner(attrs);
1064
10651051 for st in blk.stmts {
10661052 self.print_stmt(st);
10671053 }
......@@ -1251,7 +1237,7 @@ impl<'a> State<'a> {
12511237
12521238 fn print_expr_field(&mut self, field: &hir::ExprField<'_>) {
12531239 let cb = self.cbox(INDENT_UNIT);
1254 self.print_attrs_as_outer(self.attrs(field.hir_id));
1240 self.print_attrs(self.attrs(field.hir_id));
12551241 if !field.is_shorthand {
12561242 self.print_ident(field.ident);
12571243 self.word_space(":");
......@@ -1451,7 +1437,7 @@ impl<'a> State<'a> {
14511437
14521438 fn print_expr(&mut self, expr: &hir::Expr<'_>) {
14531439 self.maybe_print_comment(expr.span.lo());
1454 self.print_attrs_as_outer(self.attrs(expr.hir_id));
1440 self.print_attrs(self.attrs(expr.hir_id));
14551441 let ib = self.ibox(INDENT_UNIT);
14561442 self.ann.pre(self, AnnNode::Expr(expr));
14571443 match expr.kind {
......@@ -2076,7 +2062,7 @@ impl<'a> State<'a> {
20762062 self.space();
20772063 }
20782064 let cb = self.cbox(INDENT_UNIT);
2079 self.print_attrs_as_outer(self.attrs(field.hir_id));
2065 self.print_attrs(self.attrs(field.hir_id));
20802066 if !field.is_shorthand {
20812067 self.print_ident(field.ident);
20822068 self.word_nbsp(":");
......@@ -2086,7 +2072,7 @@ impl<'a> State<'a> {
20862072 }
20872073
20882074 fn print_param(&mut self, arg: &hir::Param<'_>) {
2089 self.print_attrs_as_outer(self.attrs(arg.hir_id));
2075 self.print_attrs(self.attrs(arg.hir_id));
20902076 self.print_pat(arg.pat);
20912077 }
20922078
......@@ -2121,7 +2107,7 @@ impl<'a> State<'a> {
21212107 let cb = self.cbox(INDENT_UNIT);
21222108 self.ann.pre(self, AnnNode::Arm(arm));
21232109 let ib = self.ibox(0);
2124 self.print_attrs_as_outer(self.attrs(arm.hir_id));
2110 self.print_attrs(self.attrs(arm.hir_id));
21252111 self.print_pat(arm.pat);
21262112 self.space();
21272113 if let Some(ref g) = arm.guard {
......@@ -2409,7 +2395,7 @@ impl<'a> State<'a> {
24092395 }
24102396
24112397 fn print_where_predicate(&mut self, predicate: &hir::WherePredicate<'_>) {
2412 self.print_attrs_as_outer(self.attrs(predicate.hir_id));
2398 self.print_attrs(self.attrs(predicate.hir_id));
24132399 match *predicate.kind {
24142400 hir::WherePredicateKind::BoundPredicate(hir::WhereBoundPredicate {
24152401 bound_generic_params,
compiler/rustc_hir_typeck/src/expr.rs+5-4
......@@ -18,7 +18,7 @@ use rustc_errors::{
1818use rustc_hir::def::{CtorKind, DefKind, Res};
1919use rustc_hir::def_id::DefId;
2020use rustc_hir::lang_items::LangItem;
21use rustc_hir::{Attribute, ExprKind, HirId, QPath};
21use rustc_hir::{ExprKind, HirId, QPath};
2222use rustc_hir_analysis::NoVariantNamed;
2323use rustc_hir_analysis::hir_ty_lowering::{FeedConstTy, HirTyLowerer as _};
2424use rustc_infer::infer;
......@@ -55,7 +55,7 @@ use crate::{
5555
5656impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5757 pub(crate) fn precedence(&self, expr: &hir::Expr<'_>) -> ExprPrecedence {
58 let for_each_attr = |id: HirId, callback: &mut dyn FnMut(&Attribute)| {
58 let has_attr = |id: HirId| -> bool {
5959 for attr in self.tcx.hir_attrs(id) {
6060 // For the purpose of rendering suggestions, disregard attributes
6161 // that originate from desugaring of any kind. For example, `x?`
......@@ -71,11 +71,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7171 // let y: u32 = (x?).try_into().unwrap();
7272 // + +++++++++++++++++++++
7373 if attr.span().desugaring_kind().is_none() {
74 callback(attr);
74 return true;
7575 }
7676 }
77 false
7778 };
78 expr.precedence(&for_each_attr)
79 expr.precedence(&has_attr)
7980 }
8081
8182 /// Check an expr with an expectation type, and also demand that the expr's
compiler/rustc_lint/src/context.rs+4-3
......@@ -855,14 +855,15 @@ impl<'tcx> LateContext<'tcx> {
855855 /// rendering diagnostic. This is not the same as the precedence that would
856856 /// be used for pretty-printing HIR by rustc_hir_pretty.
857857 pub fn precedence(&self, expr: &hir::Expr<'_>) -> ExprPrecedence {
858 let for_each_attr = |id: hir::HirId, callback: &mut dyn FnMut(&hir::Attribute)| {
858 let has_attr = |id: hir::HirId| -> bool {
859859 for attr in self.tcx.hir_attrs(id) {
860860 if attr.span().desugaring_kind().is_none() {
861 callback(attr);
861 return true;
862862 }
863863 }
864 false
864865 };
865 expr.precedence(&for_each_attr)
866 expr.precedence(&has_attr)
866867 }
867868
868869 /// If the given expression is a local binding, find the initializer expression.
compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs+1-1
......@@ -430,7 +430,7 @@ where
430430 canonical_input,
431431 step_kind_from_parent,
432432 &mut canonical_goal_evaluation,
433 |search_graph, canonical_goal_evaluation| {
433 |search_graph, cx, canonical_input, canonical_goal_evaluation| {
434434 EvalCtxt::enter_canonical(
435435 cx,
436436 search_graph,
compiler/rustc_passes/src/check_attr.rs+41-30
......@@ -116,6 +116,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
116116 let mut seen = FxHashMap::default();
117117 let attrs = self.tcx.hir_attrs(hir_id);
118118 for attr in attrs {
119 let mut style = None;
119120 match attr {
120121 Attribute::Parsed(AttributeKind::Confusables { first_span, .. }) => {
121122 self.check_confusables(*first_span, target);
......@@ -149,6 +150,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
149150 }
150151 Attribute::Parsed(AttributeKind::Repr(_)) => { /* handled below this loop and elsewhere */
151152 }
153
154 &Attribute::Parsed(AttributeKind::PubTransparent(attr_span)) => {
155 self.check_rustc_pub_transparent(attr_span, span, attrs)
156 }
152157 Attribute::Parsed(AttributeKind::Cold(attr_span)) => {
153158 self.check_cold(hir_id, *attr_span, span, target)
154159 }
......@@ -163,10 +168,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
163168 Attribute::Parsed(AttributeKind::AsPtr(attr_span)) => {
164169 self.check_applied_to_fn_or_method(hir_id, *attr_span, span, target)
165170 }
166 &Attribute::Parsed(AttributeKind::MayDangle(attr_span)) => {
167 self.check_may_dangle(hir_id, attr_span)
171 Attribute::Parsed(AttributeKind::MayDangle(attr_span)) => {
172 self.check_may_dangle(hir_id, *attr_span)
168173 }
169 Attribute::Unparsed(_) => {
174 Attribute::Unparsed(attr_item) => {
175 style = Some(attr_item.style);
170176 match attr.path().as_slice() {
171177 [sym::diagnostic, sym::do_not_recommend, ..] => {
172178 self.check_do_not_recommend(attr.span(), hir_id, target, attr, item)
......@@ -189,6 +195,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
189195 }
190196 [sym::doc, ..] => self.check_doc_attrs(
191197 attr,
198 attr_item.style,
192199 hir_id,
193200 target,
194201 &mut specified_inline,
......@@ -288,7 +295,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
288295 self.check_type_const(hir_id,attr, target);
289296 }
290297 [sym::linkage, ..] => self.check_linkage(attr, span, target),
291 [sym::rustc_pub_transparent, ..] => self.check_rustc_pub_transparent(attr.span(), span, attrs),
292298 [
293299 // ok
294300 sym::allow
......@@ -350,14 +356,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
350356 if let Some(BuiltinAttribute { type_: AttributeType::CrateLevel, .. }) =
351357 attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name))
352358 {
353 match attr.style() {
354 ast::AttrStyle::Outer => self.tcx.emit_node_span_lint(
359 match style {
360 Some(ast::AttrStyle::Outer) => self.tcx.emit_node_span_lint(
355361 UNUSED_ATTRIBUTES,
356362 hir_id,
357363 attr.span(),
358364 errors::OuterCrateLevelAttr,
359365 ),
360 ast::AttrStyle::Inner => self.tcx.emit_node_span_lint(
366 Some(ast::AttrStyle::Inner) | None => self.tcx.emit_node_span_lint(
361367 UNUSED_ATTRIBUTES,
362368 hir_id,
363369 attr.span(),
......@@ -371,7 +377,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
371377 check_duplicates(self.tcx, attr, hir_id, *duplicates, &mut seen);
372378 }
373379
374 self.check_unused_attribute(hir_id, attr)
380 self.check_unused_attribute(hir_id, attr, style)
375381 }
376382
377383 self.check_repr(attrs, span, target, item, hir_id);
......@@ -1194,7 +1200,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
11941200 /// the first `inline`/`no_inline` attribute.
11951201 fn check_doc_inline(
11961202 &self,
1197 attr: &Attribute,
1203 style: AttrStyle,
11981204 meta: &MetaItemInner,
11991205 hir_id: HirId,
12001206 target: Target,
......@@ -1224,8 +1230,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
12241230 meta.span(),
12251231 errors::DocInlineOnlyUse {
12261232 attr_span: meta.span(),
1227 item_span: (attr.style() == AttrStyle::Outer)
1228 .then(|| self.tcx.hir_span(hir_id)),
1233 item_span: (style == AttrStyle::Outer).then(|| self.tcx.hir_span(hir_id)),
12291234 },
12301235 );
12311236 }
......@@ -1234,7 +1239,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
12341239
12351240 fn check_doc_masked(
12361241 &self,
1237 attr: &Attribute,
1242 style: AttrStyle,
12381243 meta: &MetaItemInner,
12391244 hir_id: HirId,
12401245 target: Target,
......@@ -1246,8 +1251,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
12461251 meta.span(),
12471252 errors::DocMaskedOnlyExternCrate {
12481253 attr_span: meta.span(),
1249 item_span: (attr.style() == AttrStyle::Outer)
1250 .then(|| self.tcx.hir_span(hir_id)),
1254 item_span: (style == AttrStyle::Outer).then(|| self.tcx.hir_span(hir_id)),
12511255 },
12521256 );
12531257 return;
......@@ -1260,8 +1264,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
12601264 meta.span(),
12611265 errors::DocMaskedNotExternCrateSelf {
12621266 attr_span: meta.span(),
1263 item_span: (attr.style() == AttrStyle::Outer)
1264 .then(|| self.tcx.hir_span(hir_id)),
1267 item_span: (style == AttrStyle::Outer).then(|| self.tcx.hir_span(hir_id)),
12651268 },
12661269 );
12671270 }
......@@ -1285,13 +1288,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
12851288 fn check_attr_crate_level(
12861289 &self,
12871290 attr: &Attribute,
1291 style: AttrStyle,
12881292 meta: &MetaItemInner,
12891293 hir_id: HirId,
12901294 ) -> bool {
12911295 if hir_id != CRATE_HIR_ID {
12921296 // insert a bang between `#` and `[...`
12931297 let bang_span = attr.span().lo() + BytePos(1);
1294 let sugg = (attr.style() == AttrStyle::Outer
1298 let sugg = (style == AttrStyle::Outer
12951299 && self.tcx.hir_get_parent_item(hir_id) == CRATE_OWNER_ID)
12961300 .then_some(errors::AttrCrateLevelOnlySugg {
12971301 attr: attr.span().with_lo(bang_span).with_hi(bang_span),
......@@ -1308,7 +1312,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
13081312 }
13091313
13101314 /// Checks that `doc(test(...))` attribute contains only valid attributes and are at the right place.
1311 fn check_test_attr(&self, attr: &Attribute, meta: &MetaItemInner, hir_id: HirId) {
1315 fn check_test_attr(
1316 &self,
1317 attr: &Attribute,
1318 style: AttrStyle,
1319 meta: &MetaItemInner,
1320 hir_id: HirId,
1321 ) {
13121322 if let Some(metas) = meta.meta_item_list() {
13131323 for i_meta in metas {
13141324 match (i_meta.name(), i_meta.meta_item()) {
......@@ -1316,7 +1326,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
13161326 // Allowed everywhere like `#[doc]`
13171327 }
13181328 (Some(sym::no_crate_inject), _) => {
1319 self.check_attr_crate_level(attr, meta, hir_id);
1329 self.check_attr_crate_level(attr, style, meta, hir_id);
13201330 }
13211331 (_, Some(m)) => {
13221332 self.tcx.emit_node_span_lint(
......@@ -1370,6 +1380,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
13701380 fn check_doc_attrs(
13711381 &self,
13721382 attr: &Attribute,
1383 style: AttrStyle,
13731384 hir_id: HirId,
13741385 target: Target,
13751386 specified_inline: &mut Option<(bool, Span)>,
......@@ -1404,7 +1415,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
14041415 }
14051416
14061417 Some(sym::test) => {
1407 self.check_test_attr(attr, meta, hir_id);
1418 self.check_test_attr(attr, style, meta, hir_id);
14081419 }
14091420
14101421 Some(
......@@ -1415,25 +1426,25 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
14151426 | sym::html_root_url
14161427 | sym::html_no_source,
14171428 ) => {
1418 self.check_attr_crate_level(attr, meta, hir_id);
1429 self.check_attr_crate_level(attr, style, meta, hir_id);
14191430 }
14201431
14211432 Some(sym::cfg_hide) => {
1422 if self.check_attr_crate_level(attr, meta, hir_id) {
1433 if self.check_attr_crate_level(attr, style, meta, hir_id) {
14231434 self.check_doc_cfg_hide(meta, hir_id);
14241435 }
14251436 }
14261437
14271438 Some(sym::inline | sym::no_inline) => {
1428 self.check_doc_inline(attr, meta, hir_id, target, specified_inline)
1439 self.check_doc_inline(style, meta, hir_id, target, specified_inline)
14291440 }
14301441
1431 Some(sym::masked) => self.check_doc_masked(attr, meta, hir_id, target),
1442 Some(sym::masked) => self.check_doc_masked(style, meta, hir_id, target),
14321443
14331444 Some(sym::cfg | sym::hidden | sym::notable_trait) => {}
14341445
14351446 Some(sym::rust_logo) => {
1436 if self.check_attr_crate_level(attr, meta, hir_id)
1447 if self.check_attr_crate_level(attr, style, meta, hir_id)
14371448 && !self.tcx.features().rustdoc_internals()
14381449 {
14391450 feature_err(
......@@ -1472,7 +1483,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
14721483 errors::DocTestUnknownInclude {
14731484 path,
14741485 value: value.to_string(),
1475 inner: match attr.style() {
1486 inner: match style {
14761487 AttrStyle::Inner => "!",
14771488 AttrStyle::Outer => "",
14781489 },
......@@ -2426,7 +2437,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
24262437 }
24272438 }
24282439
2429 fn check_unused_attribute(&self, hir_id: HirId, attr: &Attribute) {
2440 fn check_unused_attribute(&self, hir_id: HirId, attr: &Attribute, style: Option<AttrStyle>) {
24302441 // FIXME(jdonszelmann): deduplicate these checks after more attrs are parsed. This is very
24312442 // ugly now but can 100% be removed later.
24322443 if let Attribute::Parsed(p) = attr {
......@@ -2479,14 +2490,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
24792490 })
24802491 {
24812492 if hir_id != CRATE_HIR_ID {
2482 match attr.style() {
2483 ast::AttrStyle::Outer => self.tcx.emit_node_span_lint(
2493 match style {
2494 Some(ast::AttrStyle::Outer) => self.tcx.emit_node_span_lint(
24842495 UNUSED_ATTRIBUTES,
24852496 hir_id,
24862497 attr.span(),
24872498 errors::OuterCrateLevelAttr,
24882499 ),
2489 ast::AttrStyle::Inner => self.tcx.emit_node_span_lint(
2500 Some(ast::AttrStyle::Inner) | None => self.tcx.emit_node_span_lint(
24902501 UNUSED_ATTRIBUTES,
24912502 hir_id,
24922503 attr.span(),
compiler/rustc_resolve/src/rustdoc.rs+6-1
......@@ -356,7 +356,12 @@ pub fn strip_generics_from_path(path_str: &str) -> Result<Box<str>, MalformedGen
356356/// If there are no doc-comments, return true.
357357/// FIXME(#78591): Support both inner and outer attributes on the same item.
358358pub fn inner_docs(attrs: &[impl AttributeExt]) -> bool {
359 attrs.iter().find(|a| a.doc_str().is_some()).is_none_or(|a| a.style() == ast::AttrStyle::Inner)
359 for attr in attrs {
360 if let Some(attr_style) = attr.doc_resolution_scope() {
361 return attr_style == ast::AttrStyle::Inner;
362 }
363 }
364 true
360365}
361366
362367/// Has `#[rustc_doc_primitive]` or `#[doc(keyword)]`.
compiler/rustc_type_ir/src/search_graph/global_cache.rs+8-9
......@@ -2,6 +2,7 @@ use derive_where::derive_where;
22
33use super::{AvailableDepth, Cx, NestedGoals};
44use crate::data_structures::HashMap;
5use crate::search_graph::EvaluationResult;
56
67struct Success<X: Cx> {
78 required_depth: usize,
......@@ -43,28 +44,26 @@ impl<X: Cx> GlobalCache<X> {
4344 &mut self,
4445 cx: X,
4546 input: X::Input,
46
47 origin_result: X::Result,
47 evaluation_result: EvaluationResult<X>,
4848 dep_node: X::DepNodeIndex,
49
50 required_depth: usize,
51 encountered_overflow: bool,
52 nested_goals: NestedGoals<X>,
5349 ) {
54 let result = cx.mk_tracked(origin_result, dep_node);
50 let EvaluationResult { encountered_overflow, required_depth, heads, nested_goals, result } =
51 evaluation_result;
52 debug_assert!(heads.is_empty());
53 let result = cx.mk_tracked(result, dep_node);
5554 let entry = self.map.entry(input).or_default();
5655 if encountered_overflow {
5756 let with_overflow = WithOverflow { nested_goals, result };
5857 let prev = entry.with_overflow.insert(required_depth, with_overflow);
5958 if let Some(prev) = &prev {
6059 assert!(cx.evaluation_is_concurrent());
61 assert_eq!(cx.get_tracked(&prev.result), origin_result);
60 assert_eq!(cx.get_tracked(&prev.result), evaluation_result.result);
6261 }
6362 } else {
6463 let prev = entry.success.replace(Success { required_depth, nested_goals, result });
6564 if let Some(prev) = &prev {
6665 assert!(cx.evaluation_is_concurrent());
67 assert_eq!(cx.get_tracked(&prev.result), origin_result);
66 assert_eq!(cx.get_tracked(&prev.result), evaluation_result.result);
6867 }
6968 }
7069 }
compiler/rustc_type_ir/src/search_graph/mod.rs+109-59
......@@ -1,16 +1,16 @@
1/// The search graph is responsible for caching and cycle detection in the trait
2/// solver. Making sure that caching doesn't result in soundness bugs or unstable
3/// query results is very challenging and makes this one of the most-involved
4/// self-contained components of the compiler.
5///
6/// We added fuzzing support to test its correctness. The fuzzers used to verify
7/// the current implementation can be found in https://github.com/lcnr/search_graph_fuzz.
8///
9/// This is just a quick overview of the general design, please check out the relevant
10/// [rustc-dev-guide chapter](https://rustc-dev-guide.rust-lang.org/solve/caching.html) for
11/// more details. Caching is split between a global cache and the per-cycle `provisional_cache`.
12/// The global cache has to be completely unobservable, while the per-cycle cache may impact
13/// behavior as long as the resulting behavior is still correct.
1//! The search graph is responsible for caching and cycle detection in the trait
2//! solver. Making sure that caching doesn't result in soundness bugs or unstable
3//! query results is very challenging and makes this one of the most-involved
4//! self-contained components of the compiler.
5//!
6//! We added fuzzing support to test its correctness. The fuzzers used to verify
7//! the current implementation can be found in <https://github.com/lcnr/search_graph_fuzz>.
8//!
9//! This is just a quick overview of the general design, please check out the relevant
10//! [rustc-dev-guide chapter](https://rustc-dev-guide.rust-lang.org/solve/caching.html) for
11//! more details. Caching is split between a global cache and the per-cycle `provisional_cache`.
12//! The global cache has to be completely unobservable, while the per-cycle cache may impact
13//! behavior as long as the resulting behavior is still correct.
1414use std::cmp::Ordering;
1515use std::collections::BTreeMap;
1616use std::collections::hash_map::Entry;
......@@ -381,18 +381,16 @@ impl PathsToNested {
381381/// The nested goals of each stack entry and the path from the
382382/// stack entry to that nested goal.
383383///
384/// They are used when checking whether reevaluating a global cache
385/// would encounter a cycle or use a provisional cache entry given the
386/// currentl search graph state. We need to disable the global cache
387/// in this case as it could otherwise result in behaviorial differences.
388/// Cycles can impact behavior. The cycle ABA may have different final
389/// results from a the cycle BAB depending on the cycle root.
390///
384391/// We only start tracking nested goals once we've either encountered
385392/// overflow or a solver cycle. This is a performance optimization to
386393/// avoid tracking nested goals on the happy path.
387///
388/// We use nested goals for two reasons:
389/// - when rebasing provisional cache entries
390/// - when checking whether we have to ignore a global cache entry as reevaluating
391/// it would encounter a cycle or use a provisional cache entry.
392///
393/// We need to disable the global cache if using it would hide a cycle, as
394/// cycles can impact behavior. The cycle ABA may have different final
395/// results from a the cycle BAB depending on the cycle root.
396394#[derive_where(Debug, Default, Clone; X: Cx)]
397395struct NestedGoals<X: Cx> {
398396 nested_goals: HashMap<X::Input, PathsToNested>,
......@@ -450,6 +448,43 @@ struct ProvisionalCacheEntry<X: Cx> {
450448 result: X::Result,
451449}
452450
451/// The final result of evaluating a goal.
452///
453/// We reset `encountered_overflow` when reevaluating a goal,
454/// but need to track whether we've hit the recursion limit at
455/// all for correctness.
456///
457/// We've previously simply returned the final `StackEntry` but this
458/// made it easy to accidentally drop information from the previous
459/// evaluation.
460#[derive_where(Debug; X: Cx)]
461struct EvaluationResult<X: Cx> {
462 encountered_overflow: bool,
463 required_depth: usize,
464 heads: CycleHeads,
465 nested_goals: NestedGoals<X>,
466 result: X::Result,
467}
468
469impl<X: Cx> EvaluationResult<X> {
470 fn finalize(
471 final_entry: StackEntry<X>,
472 encountered_overflow: bool,
473 result: X::Result,
474 ) -> EvaluationResult<X> {
475 EvaluationResult {
476 encountered_overflow,
477 // Unlike `encountered_overflow`, we share `heads`, `required_depth`,
478 // and `nested_goals` between evaluations.
479 required_depth: final_entry.required_depth,
480 heads: final_entry.heads,
481 nested_goals: final_entry.nested_goals,
482 // We only care about the final result.
483 result,
484 }
485 }
486}
487
453488pub struct SearchGraph<D: Delegate<Cx = X>, X: Cx = <D as Delegate>::Cx> {
454489 root_depth: AvailableDepth,
455490 /// The stack of goals currently being computed.
......@@ -562,7 +597,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
562597 input: X::Input,
563598 step_kind_from_parent: PathKind,
564599 inspect: &mut D::ProofTreeBuilder,
565 mut evaluate_goal: impl FnMut(&mut Self, &mut D::ProofTreeBuilder) -> X::Result,
600 evaluate_goal: impl Fn(&mut Self, X, X::Input, &mut D::ProofTreeBuilder) -> X::Result + Copy,
566601 ) -> X::Result {
567602 let Some(available_depth) =
568603 AvailableDepth::allowed_depth_for_nested::<D>(self.root_depth, &self.stack)
......@@ -616,12 +651,12 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
616651 input,
617652 step_kind_from_parent,
618653 available_depth,
654 provisional_result: None,
619655 required_depth: 0,
620656 heads: Default::default(),
621657 encountered_overflow: false,
622658 has_been_used: None,
623659 nested_goals: Default::default(),
624 provisional_result: None,
625660 });
626661
627662 // This is for global caching, so we properly track query dependencies.
......@@ -630,35 +665,41 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
630665 // not tracked by the cache key and from outside of this anon task, it
631666 // must not be added to the global cache. Notably, this is the case for
632667 // trait solver cycles participants.
633 let ((final_entry, result), dep_node) = cx.with_cached_task(|| {
634 self.evaluate_goal_in_task(cx, input, inspect, &mut evaluate_goal)
635 });
668 let (evaluation_result, dep_node) =
669 cx.with_cached_task(|| self.evaluate_goal_in_task(cx, input, inspect, evaluate_goal));
636670
637671 // We've finished computing the goal and have popped it from the stack,
638672 // lazily update its parent goal.
639673 Self::update_parent_goal(
640674 &mut self.stack,
641 final_entry.step_kind_from_parent,
642 final_entry.required_depth,
643 &final_entry.heads,
644 final_entry.encountered_overflow,
645 UpdateParentGoalCtxt::Ordinary(&final_entry.nested_goals),
675 step_kind_from_parent,
676 evaluation_result.required_depth,
677 &evaluation_result.heads,
678 evaluation_result.encountered_overflow,
679 UpdateParentGoalCtxt::Ordinary(&evaluation_result.nested_goals),
646680 );
681 let result = evaluation_result.result;
647682
648683 // We're now done with this goal. We only add the root of cycles to the global cache.
649684 // In case this goal is involved in a larger cycle add it to the provisional cache.
650 if final_entry.heads.is_empty() {
685 if evaluation_result.heads.is_empty() {
651686 if let Some((_scope, expected)) = validate_cache {
652687 // Do not try to move a goal into the cache again if we're testing
653688 // the global cache.
654 assert_eq!(result, expected, "input={input:?}");
689 assert_eq!(evaluation_result.result, expected, "input={input:?}");
655690 } else if D::inspect_is_noop(inspect) {
656 self.insert_global_cache(cx, final_entry, result, dep_node)
691 self.insert_global_cache(cx, input, evaluation_result, dep_node)
657692 }
658693 } else if D::ENABLE_PROVISIONAL_CACHE {
659694 debug_assert!(validate_cache.is_none(), "unexpected non-root: {input:?}");
660695 let entry = self.provisional_cache.entry(input).or_default();
661 let StackEntry { heads, encountered_overflow, .. } = final_entry;
696 let EvaluationResult {
697 encountered_overflow,
698 required_depth: _,
699 heads,
700 nested_goals: _,
701 result,
702 } = evaluation_result;
662703 let path_from_head = Self::cycle_path_kind(
663704 &self.stack,
664705 step_kind_from_parent,
......@@ -1023,19 +1064,25 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
10231064 cx: X,
10241065 input: X::Input,
10251066 inspect: &mut D::ProofTreeBuilder,
1026 mut evaluate_goal: impl FnMut(&mut Self, &mut D::ProofTreeBuilder) -> X::Result,
1027 ) -> (StackEntry<X>, X::Result) {
1067 evaluate_goal: impl Fn(&mut Self, X, X::Input, &mut D::ProofTreeBuilder) -> X::Result + Copy,
1068 ) -> EvaluationResult<X> {
1069 // We reset `encountered_overflow` each time we rerun this goal
1070 // but need to make sure we currently propagate it to the global
1071 // cache even if only some of the evaluations actually reach the
1072 // recursion limit.
1073 let mut encountered_overflow = false;
10281074 let mut i = 0;
10291075 loop {
1030 let result = evaluate_goal(self, inspect);
1076 let result = evaluate_goal(self, cx, input, inspect);
10311077 let stack_entry = self.stack.pop();
1078 encountered_overflow |= stack_entry.encountered_overflow;
10321079 debug_assert_eq!(stack_entry.input, input);
10331080
10341081 // If the current goal is not the root of a cycle, we are done.
10351082 //
10361083 // There are no provisional cache entries which depend on this goal.
10371084 let Some(usage_kind) = stack_entry.has_been_used else {
1038 return (stack_entry, result);
1085 return EvaluationResult::finalize(stack_entry, encountered_overflow, result);
10391086 };
10401087
10411088 // If it is a cycle head, we have to keep trying to prove it until
......@@ -1051,7 +1098,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
10511098 // final result is equal to the initial response for that case.
10521099 if self.reached_fixpoint(cx, &stack_entry, usage_kind, result) {
10531100 self.rebase_provisional_cache_entries(&stack_entry, |_, result| result);
1054 return (stack_entry, result);
1101 return EvaluationResult::finalize(stack_entry, encountered_overflow, result);
10551102 }
10561103
10571104 // If computing this goal results in ambiguity with no constraints,
......@@ -1070,7 +1117,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
10701117 self.rebase_provisional_cache_entries(&stack_entry, |input, _| {
10711118 D::propagate_ambiguity(cx, input, result)
10721119 });
1073 return (stack_entry, result);
1120 return EvaluationResult::finalize(stack_entry, encountered_overflow, result);
10741121 };
10751122
10761123 // If we've reached the fixpoint step limit, we bail with overflow and taint all
......@@ -1082,7 +1129,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
10821129 self.rebase_provisional_cache_entries(&stack_entry, |input, _| {
10831130 D::on_fixpoint_overflow(cx, input)
10841131 });
1085 return (stack_entry, result);
1132 return EvaluationResult::finalize(stack_entry, encountered_overflow, result);
10861133 }
10871134
10881135 // Clear all provisional cache entries which depend on a previous provisional
......@@ -1091,9 +1138,22 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
10911138
10921139 debug!(?result, "fixpoint changed provisional results");
10931140 self.stack.push(StackEntry {
1094 has_been_used: None,
1141 input,
1142 step_kind_from_parent: stack_entry.step_kind_from_parent,
1143 available_depth: stack_entry.available_depth,
10951144 provisional_result: Some(result),
1096 ..stack_entry
1145 // We can keep these goals from previous iterations as they are only
1146 // ever read after finalizing this evaluation.
1147 required_depth: stack_entry.required_depth,
1148 heads: stack_entry.heads,
1149 nested_goals: stack_entry.nested_goals,
1150 // We reset these two fields when rerunning this goal. We could
1151 // keep `encountered_overflow` as it's only used as a performance
1152 // optimization. However, given that the proof tree will likely look
1153 // similar to the previous iterations when reevaluating, it's better
1154 // for caching if the reevaluation also starts out with `false`.
1155 encountered_overflow: false,
1156 has_been_used: None,
10971157 });
10981158 }
10991159 }
......@@ -1109,21 +1169,11 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
11091169 fn insert_global_cache(
11101170 &mut self,
11111171 cx: X,
1112 final_entry: StackEntry<X>,
1113 result: X::Result,
1172 input: X::Input,
1173 evaluation_result: EvaluationResult<X>,
11141174 dep_node: X::DepNodeIndex,
11151175 ) {
1116 debug!(?final_entry, ?result, "insert global cache");
1117 cx.with_global_cache(|cache| {
1118 cache.insert(
1119 cx,
1120 final_entry.input,
1121 result,
1122 dep_node,
1123 final_entry.required_depth,
1124 final_entry.encountered_overflow,
1125 final_entry.nested_goals,
1126 )
1127 })
1176 debug!(?evaluation_result, "insert global cache");
1177 cx.with_global_cache(|cache| cache.insert(cx, input, evaluation_result, dep_node))
11281178 }
11291179}
compiler/rustc_type_ir/src/search_graph/stack.rs+4-4
......@@ -26,6 +26,10 @@ pub(super) struct StackEntry<X: Cx> {
2626 /// The available depth of a given goal, immutable.
2727 pub available_depth: AvailableDepth,
2828
29 /// Starts out as `None` and gets set when rerunning this
30 /// goal in case we encounter a cycle.
31 pub provisional_result: Option<X::Result>,
32
2933 /// The maximum depth required while evaluating this goal.
3034 pub required_depth: usize,
3135
......@@ -42,10 +46,6 @@ pub(super) struct StackEntry<X: Cx> {
4246
4347 /// The nested goals of this goal, see the doc comment of the type.
4448 pub nested_goals: NestedGoals<X>,
45
46 /// Starts out as `None` and gets set when rerunning this
47 /// goal in case we encounter a cycle.
48 pub provisional_result: Option<X::Result>,
4949}
5050
5151#[derive_where(Default; X: Cx)]
library/Cargo.toml+10
......@@ -1,3 +1,5 @@
1cargo-features = ["profile-rustflags"]
2
13[workspace]
24resolver = "1"
35members = [
......@@ -44,6 +46,14 @@ object.debug = 0
4446rustc-demangle.debug = 0
4547rustc-demangle.opt-level = "s"
4648
49# panic_abort must always be compiled with panic=abort, even when the rest of the
50# sysroot is panic=unwind.
51[profile.dev.package.panic_abort]
52rustflags = ["-Cpanic=abort"]
53
54[profile.release.package.panic_abort]
55rustflags = ["-Cpanic=abort"]
56
4757[patch.crates-io]
4858# See comments in `library/rustc-std-workspace-core/README.md` for what's going on
4959# here
library/core/src/num/int_macros.rs-208
......@@ -29,8 +29,6 @@ macro_rules! int_impl {
2929 ///
3030 /// # Examples
3131 ///
32 /// Basic usage:
33 ///
3432 /// ```
3533 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN, ", stringify!($Min), ");")]
3634 /// ```
......@@ -42,8 +40,6 @@ macro_rules! int_impl {
4240 ///
4341 /// # Examples
4442 ///
45 /// Basic usage:
46 ///
4743 /// ```
4844 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX, ", stringify!($Max), ");")]
4945 /// ```
......@@ -64,8 +60,6 @@ macro_rules! int_impl {
6460 ///
6561 /// # Examples
6662 ///
67 /// Basic usage:
68 ///
6963 /// ```
7064 #[doc = concat!("let n = 0b100_0000", stringify!($SelfT), ";")]
7165 ///
......@@ -85,8 +79,6 @@ macro_rules! int_impl {
8579 ///
8680 /// # Examples
8781 ///
88 /// Basic usage:
89 ///
9082 /// ```
9183 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.count_zeros(), 1);")]
9284 /// ```
......@@ -106,8 +98,6 @@ macro_rules! int_impl {
10698 ///
10799 /// # Examples
108100 ///
109 /// Basic usage:
110 ///
111101 /// ```
112102 #[doc = concat!("let n = -1", stringify!($SelfT), ";")]
113103 ///
......@@ -127,8 +117,6 @@ macro_rules! int_impl {
127117 ///
128118 /// # Examples
129119 ///
130 /// Basic usage:
131 ///
132120 /// ```
133121 #[doc = concat!("let n = -4", stringify!($SelfT), ";")]
134122 ///
......@@ -147,8 +135,6 @@ macro_rules! int_impl {
147135 ///
148136 /// # Examples
149137 ///
150 /// Basic usage:
151 ///
152138 /// ```
153139 #[doc = concat!("let n = -1", stringify!($SelfT), ";")]
154140 ///
......@@ -167,8 +153,6 @@ macro_rules! int_impl {
167153 ///
168154 /// # Examples
169155 ///
170 /// Basic usage:
171 ///
172156 /// ```
173157 #[doc = concat!("let n = 3", stringify!($SelfT), ";")]
174158 ///
......@@ -188,8 +172,6 @@ macro_rules! int_impl {
188172 ///
189173 /// # Examples
190174 ///
191 /// Basic usage:
192 ///
193175 /// ```
194176 /// #![feature(isolate_most_least_significant_one)]
195177 ///
......@@ -211,8 +193,6 @@ macro_rules! int_impl {
211193 ///
212194 /// # Examples
213195 ///
214 /// Basic usage:
215 ///
216196 /// ```
217197 /// #![feature(isolate_most_least_significant_one)]
218198 ///
......@@ -236,8 +216,6 @@ macro_rules! int_impl {
236216 ///
237217 /// # Examples
238218 ///
239 /// Basic usage:
240 ///
241219 /// ```
242220 #[doc = concat!("let n = -1", stringify!($SelfT), ";")]
243221 ///
......@@ -259,8 +237,6 @@ macro_rules! int_impl {
259237 ///
260238 /// # Examples
261239 ///
262 /// Basic usage:
263 ///
264240 /// ```
265241 #[doc = concat!("let n = ", $rot_op, stringify!($SelfT), ";")]
266242 #[doc = concat!("let m = ", $rot_result, ";")]
......@@ -284,8 +260,6 @@ macro_rules! int_impl {
284260 ///
285261 /// # Examples
286262 ///
287 /// Basic usage:
288 ///
289263 /// ```
290264 #[doc = concat!("let n = ", $rot_result, stringify!($SelfT), ";")]
291265 #[doc = concat!("let m = ", $rot_op, ";")]
......@@ -305,8 +279,6 @@ macro_rules! int_impl {
305279 ///
306280 /// # Examples
307281 ///
308 /// Basic usage:
309 ///
310282 /// ```
311283 #[doc = concat!("let n = ", $swap_op, stringify!($SelfT), ";")]
312284 ///
......@@ -328,8 +300,6 @@ macro_rules! int_impl {
328300 ///
329301 /// # Examples
330302 ///
331 /// Basic usage:
332 ///
333303 /// ```
334304 #[doc = concat!("let n = ", $swap_op, stringify!($SelfT), ";")]
335305 /// let m = n.reverse_bits();
......@@ -352,8 +322,6 @@ macro_rules! int_impl {
352322 ///
353323 /// # Examples
354324 ///
355 /// Basic usage:
356 ///
357325 /// ```
358326 #[doc = concat!("let n = 0x1A", stringify!($SelfT), ";")]
359327 ///
......@@ -384,8 +352,6 @@ macro_rules! int_impl {
384352 ///
385353 /// # Examples
386354 ///
387 /// Basic usage:
388 ///
389355 /// ```
390356 #[doc = concat!("let n = 0x1A", stringify!($SelfT), ";")]
391357 ///
......@@ -416,8 +382,6 @@ macro_rules! int_impl {
416382 ///
417383 /// # Examples
418384 ///
419 /// Basic usage:
420 ///
421385 /// ```
422386 #[doc = concat!("let n = 0x1A", stringify!($SelfT), ";")]
423387 ///
......@@ -449,8 +413,6 @@ macro_rules! int_impl {
449413 ///
450414 /// # Examples
451415 ///
452 /// Basic usage:
453 ///
454416 /// ```
455417 #[doc = concat!("let n = 0x1A", stringify!($SelfT), ";")]
456418 ///
......@@ -481,8 +443,6 @@ macro_rules! int_impl {
481443 ///
482444 /// # Examples
483445 ///
484 /// Basic usage:
485 ///
486446 /// ```
487447 #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(1), Some(", stringify!($SelfT), "::MAX - 1));")]
488448 #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(3), None);")]
......@@ -508,8 +468,6 @@ macro_rules! int_impl {
508468 ///
509469 /// # Examples
510470 ///
511 /// Basic usage:
512 ///
513471 /// ```
514472 /// #![feature(strict_overflow_ops)]
515473 #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).strict_add(1), ", stringify!($SelfT), "::MAX - 1);")]
......@@ -576,8 +534,6 @@ macro_rules! int_impl {
576534 ///
577535 /// # Examples
578536 ///
579 /// Basic usage:
580 ///
581537 /// ```
582538 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_add_unsigned(2), Some(3));")]
583539 #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add_unsigned(3), None);")]
......@@ -603,8 +559,6 @@ macro_rules! int_impl {
603559 ///
604560 /// # Examples
605561 ///
606 /// Basic usage:
607 ///
608562 /// ```
609563 /// #![feature(strict_overflow_ops)]
610564 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".strict_add_unsigned(2), 3);")]
......@@ -631,8 +585,6 @@ macro_rules! int_impl {
631585 ///
632586 /// # Examples
633587 ///
634 /// Basic usage:
635 ///
636588 /// ```
637589 #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 2).checked_sub(1), Some(", stringify!($SelfT), "::MIN + 1));")]
638590 #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 2).checked_sub(3), None);")]
......@@ -658,8 +610,6 @@ macro_rules! int_impl {
658610 ///
659611 /// # Examples
660612 ///
661 /// Basic usage:
662 ///
663613 /// ```
664614 /// #![feature(strict_overflow_ops)]
665615 #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 2).strict_sub(1), ", stringify!($SelfT), "::MIN + 1);")]
......@@ -726,8 +676,6 @@ macro_rules! int_impl {
726676 ///
727677 /// # Examples
728678 ///
729 /// Basic usage:
730 ///
731679 /// ```
732680 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_sub_unsigned(2), Some(-1));")]
733681 #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 2).checked_sub_unsigned(3), None);")]
......@@ -753,8 +701,6 @@ macro_rules! int_impl {
753701 ///
754702 /// # Examples
755703 ///
756 /// Basic usage:
757 ///
758704 /// ```
759705 /// #![feature(strict_overflow_ops)]
760706 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".strict_sub_unsigned(2), -1);")]
......@@ -781,8 +727,6 @@ macro_rules! int_impl {
781727 ///
782728 /// # Examples
783729 ///
784 /// Basic usage:
785 ///
786730 /// ```
787731 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.checked_mul(1), Some(", stringify!($SelfT), "::MAX));")]
788732 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.checked_mul(2), None);")]
......@@ -808,8 +752,6 @@ macro_rules! int_impl {
808752 ///
809753 /// # Examples
810754 ///
811 /// Basic usage:
812 ///
813755 /// ```
814756 /// #![feature(strict_overflow_ops)]
815757 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.strict_mul(1), ", stringify!($SelfT), "::MAX);")]
......@@ -876,8 +818,6 @@ macro_rules! int_impl {
876818 ///
877819 /// # Examples
878820 ///
879 /// Basic usage:
880 ///
881821 /// ```
882822 #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).checked_div(-1), Some(", stringify!($Max), "));")]
883823 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_div(-1), None);")]
......@@ -914,8 +854,6 @@ macro_rules! int_impl {
914854 ///
915855 /// # Examples
916856 ///
917 /// Basic usage:
918 ///
919857 /// ```
920858 /// #![feature(strict_overflow_ops)]
921859 #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).strict_div(-1), ", stringify!($Max), ");")]
......@@ -949,8 +887,6 @@ macro_rules! int_impl {
949887 ///
950888 /// # Examples
951889 ///
952 /// Basic usage:
953 ///
954890 /// ```
955891 #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).checked_div_euclid(-1), Some(", stringify!($Max), "));")]
956892 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_div_euclid(-1), None);")]
......@@ -987,8 +923,6 @@ macro_rules! int_impl {
987923 ///
988924 /// # Examples
989925 ///
990 /// Basic usage:
991 ///
992926 /// ```
993927 /// #![feature(strict_overflow_ops)]
994928 #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).strict_div_euclid(-1), ", stringify!($Max), ");")]
......@@ -1023,8 +957,6 @@ macro_rules! int_impl {
1023957 ///
1024958 /// # Examples
1025959 ///
1026 /// Basic usage:
1027 ///
1028960 /// ```
1029961 /// #![feature(exact_div)]
1030962 #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).checked_exact_div(-1), Some(", stringify!($Max), "));")]
......@@ -1063,8 +995,6 @@ macro_rules! int_impl {
1063995 ///
1064996 /// # Examples
1065997 ///
1066 /// Basic usage:
1067 ///
1068998 /// ```
1069999 /// #![feature(exact_div)]
10701000 #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".exact_div(2), 32);")]
......@@ -1126,8 +1056,6 @@ macro_rules! int_impl {
11261056 ///
11271057 /// # Examples
11281058 ///
1129 /// Basic usage:
1130 ///
11311059 /// ```
11321060 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_rem(2), Some(1));")]
11331061 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_rem(0), None);")]
......@@ -1163,8 +1091,6 @@ macro_rules! int_impl {
11631091 ///
11641092 /// # Examples
11651093 ///
1166 /// Basic usage:
1167 ///
11681094 /// ```
11691095 /// #![feature(strict_overflow_ops)]
11701096 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".strict_rem(2), 1);")]
......@@ -1198,8 +1124,6 @@ macro_rules! int_impl {
11981124 ///
11991125 /// # Examples
12001126 ///
1201 /// Basic usage:
1202 ///
12031127 /// ```
12041128 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_rem_euclid(2), Some(1));")]
12051129 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_rem_euclid(0), None);")]
......@@ -1235,8 +1159,6 @@ macro_rules! int_impl {
12351159 ///
12361160 /// # Examples
12371161 ///
1238 /// Basic usage:
1239 ///
12401162 /// ```
12411163 /// #![feature(strict_overflow_ops)]
12421164 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".strict_rem_euclid(2), 1);")]
......@@ -1269,8 +1191,6 @@ macro_rules! int_impl {
12691191 ///
12701192 /// # Examples
12711193 ///
1272 /// Basic usage:
1273 ///
12741194 /// ```
12751195 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_neg(), Some(-5));")]
12761196 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_neg(), None);")]
......@@ -1328,8 +1248,6 @@ macro_rules! int_impl {
13281248 ///
13291249 /// # Examples
13301250 ///
1331 /// Basic usage:
1332 ///
13331251 /// ```
13341252 /// #![feature(strict_overflow_ops)]
13351253 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".strict_neg(), -5);")]
......@@ -1356,8 +1274,6 @@ macro_rules! int_impl {
13561274 ///
13571275 /// # Examples
13581276 ///
1359 /// Basic usage:
1360 ///
13611277 /// ```
13621278 #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".checked_shl(4), Some(0x10));")]
13631279 #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".checked_shl(129), None);")]
......@@ -1389,8 +1305,6 @@ macro_rules! int_impl {
13891305 ///
13901306 /// # Examples
13911307 ///
1392 /// Basic usage:
1393 ///
13941308 /// ```
13951309 /// #![feature(strict_overflow_ops)]
13961310 #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".strict_shl(4), 0x10);")]
......@@ -1453,7 +1367,6 @@ macro_rules! int_impl {
14531367 ///
14541368 /// # Examples
14551369 ///
1456 /// Basic usage:
14571370 /// ```
14581371 #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".unbounded_shl(4), 0x10);")]
14591372 #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".unbounded_shl(129), 0);")]
......@@ -1478,8 +1391,6 @@ macro_rules! int_impl {
14781391 ///
14791392 /// # Examples
14801393 ///
1481 /// Basic usage:
1482 ///
14831394 /// ```
14841395 #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".checked_shr(4), Some(0x1));")]
14851396 #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".checked_shr(128), None);")]
......@@ -1510,8 +1421,6 @@ macro_rules! int_impl {
15101421 ///
15111422 /// # Examples
15121423 ///
1513 /// Basic usage:
1514 ///
15151424 /// ```
15161425 /// #![feature(strict_overflow_ops)]
15171426 #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".strict_shr(4), 0x1);")]
......@@ -1575,7 +1484,6 @@ macro_rules! int_impl {
15751484 ///
15761485 /// # Examples
15771486 ///
1578 /// Basic usage:
15791487 /// ```
15801488 #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".unbounded_shr(4), 0x1);")]
15811489 #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".unbounded_shr(129), 0);")]
......@@ -1605,8 +1513,6 @@ macro_rules! int_impl {
16051513 ///
16061514 /// # Examples
16071515 ///
1608 /// Basic usage:
1609 ///
16101516 /// ```
16111517 #[doc = concat!("assert_eq!((-5", stringify!($SelfT), ").checked_abs(), Some(5));")]
16121518 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_abs(), None);")]
......@@ -1635,8 +1541,6 @@ macro_rules! int_impl {
16351541 ///
16361542 /// # Examples
16371543 ///
1638 /// Basic usage:
1639 ///
16401544 /// ```
16411545 /// #![feature(strict_overflow_ops)]
16421546 #[doc = concat!("assert_eq!((-5", stringify!($SelfT), ").strict_abs(), 5);")]
......@@ -1666,8 +1570,6 @@ macro_rules! int_impl {
16661570 ///
16671571 /// # Examples
16681572 ///
1669 /// Basic usage:
1670 ///
16711573 /// ```
16721574 #[doc = concat!("assert_eq!(8", stringify!($SelfT), ".checked_pow(2), Some(64));")]
16731575 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.checked_pow(2), None);")]
......@@ -1709,8 +1611,6 @@ macro_rules! int_impl {
17091611 ///
17101612 /// # Examples
17111613 ///
1712 /// Basic usage:
1713 ///
17141614 /// ```
17151615 /// #![feature(strict_overflow_ops)]
17161616 #[doc = concat!("assert_eq!(8", stringify!($SelfT), ".strict_pow(2), 64);")]
......@@ -1753,7 +1653,6 @@ macro_rules! int_impl {
17531653 ///
17541654 /// # Examples
17551655 ///
1756 /// Basic usage:
17571656 /// ```
17581657 #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".checked_isqrt(), Some(3));")]
17591658 /// ```
......@@ -1801,8 +1700,6 @@ macro_rules! int_impl {
18011700 ///
18021701 /// # Examples
18031702 ///
1804 /// Basic usage:
1805 ///
18061703 /// ```
18071704 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".saturating_add(1), 101);")]
18081705 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.saturating_add(100), ", stringify!($SelfT), "::MAX);")]
......@@ -1823,8 +1720,6 @@ macro_rules! int_impl {
18231720 ///
18241721 /// # Examples
18251722 ///
1826 /// Basic usage:
1827 ///
18281723 /// ```
18291724 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".saturating_add_unsigned(2), 3);")]
18301725 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.saturating_add_unsigned(100), ", stringify!($SelfT), "::MAX);")]
......@@ -1848,8 +1743,6 @@ macro_rules! int_impl {
18481743 ///
18491744 /// # Examples
18501745 ///
1851 /// Basic usage:
1852 ///
18531746 /// ```
18541747 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".saturating_sub(127), -27);")]
18551748 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_sub(100), ", stringify!($SelfT), "::MIN);")]
......@@ -1869,8 +1762,6 @@ macro_rules! int_impl {
18691762 ///
18701763 /// # Examples
18711764 ///
1872 /// Basic usage:
1873 ///
18741765 /// ```
18751766 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".saturating_sub_unsigned(127), -27);")]
18761767 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_sub_unsigned(100), ", stringify!($SelfT), "::MIN);")]
......@@ -1894,8 +1785,6 @@ macro_rules! int_impl {
18941785 ///
18951786 /// # Examples
18961787 ///
1897 /// Basic usage:
1898 ///
18991788 /// ```
19001789 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".saturating_neg(), -100);")]
19011790 #[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").saturating_neg(), 100);")]
......@@ -1917,8 +1806,6 @@ macro_rules! int_impl {
19171806 ///
19181807 /// # Examples
19191808 ///
1920 /// Basic usage:
1921 ///
19221809 /// ```
19231810 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".saturating_abs(), 100);")]
19241811 #[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").saturating_abs(), 100);")]
......@@ -1944,8 +1831,6 @@ macro_rules! int_impl {
19441831 ///
19451832 /// # Examples
19461833 ///
1947 /// Basic usage:
1948 ///
19491834 /// ```
19501835 #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".saturating_mul(12), 120);")]
19511836 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.saturating_mul(10), ", stringify!($SelfT), "::MAX);")]
......@@ -1976,8 +1861,6 @@ macro_rules! int_impl {
19761861 ///
19771862 /// # Examples
19781863 ///
1979 /// Basic usage:
1980 ///
19811864 /// ```
19821865 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".saturating_div(2), 2);")]
19831866 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.saturating_div(-1), ", stringify!($SelfT), "::MIN + 1);")]
......@@ -2001,8 +1884,6 @@ macro_rules! int_impl {
20011884 ///
20021885 /// # Examples
20031886 ///
2004 /// Basic usage:
2005 ///
20061887 /// ```
20071888 #[doc = concat!("assert_eq!((-4", stringify!($SelfT), ").saturating_pow(3), -64);")]
20081889 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_pow(2), ", stringify!($SelfT), "::MAX);")]
......@@ -2026,8 +1907,6 @@ macro_rules! int_impl {
20261907 ///
20271908 /// # Examples
20281909 ///
2029 /// Basic usage:
2030 ///
20311910 /// ```
20321911 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_add(27), 127);")]
20331912 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.wrapping_add(2), ", stringify!($SelfT), "::MIN + 1);")]
......@@ -2046,8 +1925,6 @@ macro_rules! int_impl {
20461925 ///
20471926 /// # Examples
20481927 ///
2049 /// Basic usage:
2050 ///
20511928 /// ```
20521929 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_add_unsigned(27), 127);")]
20531930 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.wrapping_add_unsigned(2), ", stringify!($SelfT), "::MIN + 1);")]
......@@ -2066,8 +1943,6 @@ macro_rules! int_impl {
20661943 ///
20671944 /// # Examples
20681945 ///
2069 /// Basic usage:
2070 ///
20711946 /// ```
20721947 #[doc = concat!("assert_eq!(0", stringify!($SelfT), ".wrapping_sub(127), -127);")]
20731948 #[doc = concat!("assert_eq!((-2", stringify!($SelfT), ").wrapping_sub(", stringify!($SelfT), "::MAX), ", stringify!($SelfT), "::MAX);")]
......@@ -2086,8 +1961,6 @@ macro_rules! int_impl {
20861961 ///
20871962 /// # Examples
20881963 ///
2089 /// Basic usage:
2090 ///
20911964 /// ```
20921965 #[doc = concat!("assert_eq!(0", stringify!($SelfT), ".wrapping_sub_unsigned(127), -127);")]
20931966 #[doc = concat!("assert_eq!((-2", stringify!($SelfT), ").wrapping_sub_unsigned(", stringify!($UnsignedT), "::MAX), -1);")]
......@@ -2106,8 +1979,6 @@ macro_rules! int_impl {
21061979 ///
21071980 /// # Examples
21081981 ///
2109 /// Basic usage:
2110 ///
21111982 /// ```
21121983 #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".wrapping_mul(12), 120);")]
21131984 /// assert_eq!(11i8.wrapping_mul(12), -124);
......@@ -2134,8 +2005,6 @@ macro_rules! int_impl {
21342005 ///
21352006 /// # Examples
21362007 ///
2137 /// Basic usage:
2138 ///
21392008 /// ```
21402009 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_div(10), 10);")]
21412010 /// assert_eq!((-128i8).wrapping_div(-1), -128);
......@@ -2162,8 +2031,6 @@ macro_rules! int_impl {
21622031 ///
21632032 /// # Examples
21642033 ///
2165 /// Basic usage:
2166 ///
21672034 /// ```
21682035 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_div_euclid(10), 10);")]
21692036 /// assert_eq!((-128i8).wrapping_div_euclid(-1), -128);
......@@ -2190,8 +2057,6 @@ macro_rules! int_impl {
21902057 ///
21912058 /// # Examples
21922059 ///
2193 /// Basic usage:
2194 ///
21952060 /// ```
21962061 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_rem(10), 0);")]
21972062 /// assert_eq!((-128i8).wrapping_rem(-1), 0);
......@@ -2217,8 +2082,6 @@ macro_rules! int_impl {
22172082 ///
22182083 /// # Examples
22192084 ///
2220 /// Basic usage:
2221 ///
22222085 /// ```
22232086 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_rem_euclid(10), 0);")]
22242087 /// assert_eq!((-128i8).wrapping_rem_euclid(-1), 0);
......@@ -2241,8 +2104,6 @@ macro_rules! int_impl {
22412104 ///
22422105 /// # Examples
22432106 ///
2244 /// Basic usage:
2245 ///
22462107 /// ```
22472108 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_neg(), -100);")]
22482109 #[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").wrapping_neg(), 100);")]
......@@ -2267,8 +2128,6 @@ macro_rules! int_impl {
22672128 ///
22682129 /// # Examples
22692130 ///
2270 /// Basic usage:
2271 ///
22722131 /// ```
22732132 #[doc = concat!("assert_eq!((-1", stringify!($SelfT), ").wrapping_shl(7), -128);")]
22742133 #[doc = concat!("assert_eq!((-1", stringify!($SelfT), ").wrapping_shl(128), -1);")]
......@@ -2296,8 +2155,6 @@ macro_rules! int_impl {
22962155 ///
22972156 /// # Examples
22982157 ///
2299 /// Basic usage:
2300 ///
23012158 /// ```
23022159 #[doc = concat!("assert_eq!((-128", stringify!($SelfT), ").wrapping_shr(7), -1);")]
23032160 /// assert_eq!((-128i16).wrapping_shr(64), -128);
......@@ -2324,8 +2181,6 @@ macro_rules! int_impl {
23242181 ///
23252182 /// # Examples
23262183 ///
2327 /// Basic usage:
2328 ///
23292184 /// ```
23302185 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_abs(), 100);")]
23312186 #[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").wrapping_abs(), 100);")]
......@@ -2352,8 +2207,6 @@ macro_rules! int_impl {
23522207 ///
23532208 /// # Examples
23542209 ///
2355 /// Basic usage:
2356 ///
23572210 /// ```
23582211 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".unsigned_abs(), 100", stringify!($UnsignedT), ");")]
23592212 #[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").unsigned_abs(), 100", stringify!($UnsignedT), ");")]
......@@ -2373,8 +2226,6 @@ macro_rules! int_impl {
23732226 ///
23742227 /// # Examples
23752228 ///
2376 /// Basic usage:
2377 ///
23782229 /// ```
23792230 #[doc = concat!("assert_eq!(3", stringify!($SelfT), ".wrapping_pow(4), 81);")]
23802231 /// assert_eq!(3i8.wrapping_pow(5), -13);
......@@ -2432,8 +2283,6 @@ macro_rules! int_impl {
24322283 ///
24332284 /// # Examples
24342285 ///
2435 /// Basic usage:
2436 ///
24372286 /// ```
24382287 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_add(2), (7, false));")]
24392288 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.overflowing_add(1), (", stringify!($SelfT), "::MIN, true));")]
......@@ -2513,8 +2362,6 @@ macro_rules! int_impl {
25132362 ///
25142363 /// # Examples
25152364 ///
2516 /// Basic usage:
2517 ///
25182365 /// ```
25192366 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".overflowing_add_unsigned(2), (3, false));")]
25202367 #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN).overflowing_add_unsigned(", stringify!($UnsignedT), "::MAX), (", stringify!($SelfT), "::MAX, false));")]
......@@ -2538,8 +2385,6 @@ macro_rules! int_impl {
25382385 ///
25392386 /// # Examples
25402387 ///
2541 /// Basic usage:
2542 ///
25432388 /// ```
25442389 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_sub(2), (3, false));")]
25452390 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.overflowing_sub(1), (", stringify!($SelfT), "::MAX, true));")]
......@@ -2620,8 +2465,6 @@ macro_rules! int_impl {
26202465 ///
26212466 /// # Examples
26222467 ///
2623 /// Basic usage:
2624 ///
26252468 /// ```
26262469 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".overflowing_sub_unsigned(2), (-1, false));")]
26272470 #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX).overflowing_sub_unsigned(", stringify!($UnsignedT), "::MAX), (", stringify!($SelfT), "::MIN, false));")]
......@@ -2645,8 +2488,6 @@ macro_rules! int_impl {
26452488 ///
26462489 /// # Examples
26472490 ///
2648 /// Basic usage:
2649 ///
26502491 /// ```
26512492 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_mul(2), (10, false));")]
26522493 /// assert_eq!(1_000_000_000i32.overflowing_mul(10), (1410065408, true));
......@@ -2671,8 +2512,6 @@ macro_rules! int_impl {
26712512 ///
26722513 /// # Examples
26732514 ///
2674 /// Basic usage:
2675 ///
26762515 /// Please note that this example is shared between integer types.
26772516 /// Which explains why `i32` is used here.
26782517 ///
......@@ -2704,8 +2543,6 @@ macro_rules! int_impl {
27042543 ///
27052544 /// # Examples
27062545 ///
2707 /// Basic usage:
2708 ///
27092546 /// Please note that this example is shared between integer types.
27102547 /// Which explains why `i32` is used here.
27112548 ///
......@@ -2744,8 +2581,6 @@ macro_rules! int_impl {
27442581 ///
27452582 /// # Examples
27462583 ///
2747 /// Basic usage:
2748 ///
27492584 /// Please note that this example is shared between integer types.
27502585 /// Which explains why `i32` is used here.
27512586 ///
......@@ -2780,8 +2615,6 @@ macro_rules! int_impl {
27802615 ///
27812616 /// # Examples
27822617 ///
2783 /// Basic usage:
2784 ///
27852618 /// ```
27862619 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_div(2), (2, false));")]
27872620 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.overflowing_div(-1), (", stringify!($SelfT), "::MIN, true));")]
......@@ -2811,8 +2644,6 @@ macro_rules! int_impl {
28112644 ///
28122645 /// # Examples
28132646 ///
2814 /// Basic usage:
2815 ///
28162647 /// ```
28172648 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_div_euclid(2), (2, false));")]
28182649 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.overflowing_div_euclid(-1), (", stringify!($SelfT), "::MIN, true));")]
......@@ -2842,8 +2673,6 @@ macro_rules! int_impl {
28422673 ///
28432674 /// # Examples
28442675 ///
2845 /// Basic usage:
2846 ///
28472676 /// ```
28482677 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_rem(2), (1, false));")]
28492678 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.overflowing_rem(-1), (0, true));")]
......@@ -2873,8 +2702,6 @@ macro_rules! int_impl {
28732702 ///
28742703 /// # Examples
28752704 ///
2876 /// Basic usage:
2877 ///
28782705 /// ```
28792706 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_rem_euclid(2), (1, false));")]
28802707 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.overflowing_rem_euclid(-1), (0, true));")]
......@@ -2902,8 +2729,6 @@ macro_rules! int_impl {
29022729 ///
29032730 /// # Examples
29042731 ///
2905 /// Basic usage:
2906 ///
29072732 /// ```
29082733 #[doc = concat!("assert_eq!(2", stringify!($SelfT), ".overflowing_neg(), (-2, false));")]
29092734 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.overflowing_neg(), (", stringify!($SelfT), "::MIN, true));")]
......@@ -2930,8 +2755,6 @@ macro_rules! int_impl {
29302755 ///
29312756 /// # Examples
29322757 ///
2933 /// Basic usage:
2934 ///
29352758 /// ```
29362759 #[doc = concat!("assert_eq!(0x1", stringify!($SelfT),".overflowing_shl(4), (0x10, false));")]
29372760 /// assert_eq!(0x1i32.overflowing_shl(36), (0x10, true));
......@@ -2954,8 +2777,6 @@ macro_rules! int_impl {
29542777 ///
29552778 /// # Examples
29562779 ///
2957 /// Basic usage:
2958 ///
29592780 /// ```
29602781 #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".overflowing_shr(4), (0x1, false));")]
29612782 /// assert_eq!(0x10i32.overflowing_shr(36), (0x1, true));
......@@ -2979,8 +2800,6 @@ macro_rules! int_impl {
29792800 ///
29802801 /// # Examples
29812802 ///
2982 /// Basic usage:
2983 ///
29842803 /// ```
29852804 #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".overflowing_abs(), (10, false));")]
29862805 #[doc = concat!("assert_eq!((-10", stringify!($SelfT), ").overflowing_abs(), (10, false));")]
......@@ -3002,8 +2821,6 @@ macro_rules! int_impl {
30022821 ///
30032822 /// # Examples
30042823 ///
3005 /// Basic usage:
3006 ///
30072824 /// ```
30082825 #[doc = concat!("assert_eq!(3", stringify!($SelfT), ".overflowing_pow(4), (81, false));")]
30092826 /// assert_eq!(3i8.overflowing_pow(5), (-13, true));
......@@ -3045,8 +2862,6 @@ macro_rules! int_impl {
30452862 ///
30462863 /// # Examples
30472864 ///
3048 /// Basic usage:
3049 ///
30502865 /// ```
30512866 #[doc = concat!("let x: ", stringify!($SelfT), " = 2; // or any other integer type")]
30522867 ///
......@@ -3106,7 +2921,6 @@ macro_rules! int_impl {
31062921 ///
31072922 /// # Examples
31082923 ///
3109 /// Basic usage:
31102924 /// ```
31112925 #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".isqrt(), 3);")]
31122926 /// ```
......@@ -3142,8 +2956,6 @@ macro_rules! int_impl {
31422956 ///
31432957 /// # Examples
31442958 ///
3145 /// Basic usage:
3146 ///
31472959 /// ```
31482960 #[doc = concat!("let a: ", stringify!($SelfT), " = 7; // or any other integer type")]
31492961 /// let b = 4;
......@@ -3181,8 +2993,6 @@ macro_rules! int_impl {
31812993 ///
31822994 /// # Examples
31832995 ///
3184 /// Basic usage:
3185 ///
31862996 /// ```
31872997 #[doc = concat!("let a: ", stringify!($SelfT), " = 7; // or any other integer type")]
31882998 /// let b = 4;
......@@ -3230,8 +3040,6 @@ macro_rules! int_impl {
32303040 ///
32313041 /// # Examples
32323042 ///
3233 /// Basic usage:
3234 ///
32353043 /// ```
32363044 /// #![feature(int_roundings)]
32373045 #[doc = concat!("let a: ", stringify!($SelfT)," = 8;")]
......@@ -3274,8 +3082,6 @@ macro_rules! int_impl {
32743082 ///
32753083 /// # Examples
32763084 ///
3277 /// Basic usage:
3278 ///
32793085 /// ```
32803086 /// #![feature(int_roundings)]
32813087 #[doc = concat!("let a: ", stringify!($SelfT)," = 8;")]
......@@ -3321,8 +3127,6 @@ macro_rules! int_impl {
33213127 ///
33223128 /// # Examples
33233129 ///
3324 /// Basic usage:
3325 ///
33263130 /// ```
33273131 /// #![feature(int_roundings)]
33283132 #[doc = concat!("assert_eq!(16_", stringify!($SelfT), ".next_multiple_of(8), 16);")]
......@@ -3367,8 +3171,6 @@ macro_rules! int_impl {
33673171 ///
33683172 /// # Examples
33693173 ///
3370 /// Basic usage:
3371 ///
33723174 /// ```
33733175 /// #![feature(int_roundings)]
33743176 #[doc = concat!("assert_eq!(16_", stringify!($SelfT), ".checked_next_multiple_of(8), Some(16));")]
......@@ -3582,8 +3384,6 @@ macro_rules! int_impl {
35823384 ///
35833385 /// # Examples
35843386 ///
3585 /// Basic usage:
3586 ///
35873387 /// ```
35883388 #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".abs(), 10);")]
35893389 #[doc = concat!("assert_eq!((-10", stringify!($SelfT), ").abs(), 10);")]
......@@ -3613,8 +3413,6 @@ macro_rules! int_impl {
36133413 ///
36143414 /// # Examples
36153415 ///
3616 /// Basic usage:
3617 ///
36183416 /// ```
36193417 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".abs_diff(80), 20", stringify!($UnsignedT), ");")]
36203418 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".abs_diff(110), 10", stringify!($UnsignedT), ");")]
......@@ -3656,8 +3454,6 @@ macro_rules! int_impl {
36563454 ///
36573455 /// # Examples
36583456 ///
3659 /// Basic usage:
3660 ///
36613457 /// ```
36623458 #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".signum(), 1);")]
36633459 #[doc = concat!("assert_eq!(0", stringify!($SelfT), ".signum(), 0);")]
......@@ -3682,8 +3478,6 @@ macro_rules! int_impl {
36823478 ///
36833479 /// # Examples
36843480 ///
3685 /// Basic usage:
3686 ///
36873481 /// ```
36883482 #[doc = concat!("assert!(10", stringify!($SelfT), ".is_positive());")]
36893483 #[doc = concat!("assert!(!(-10", stringify!($SelfT), ").is_positive());")]
......@@ -3699,8 +3493,6 @@ macro_rules! int_impl {
36993493 ///
37003494 /// # Examples
37013495 ///
3702 /// Basic usage:
3703 ///
37043496 /// ```
37053497 #[doc = concat!("assert!((-10", stringify!($SelfT), ").is_negative());")]
37063498 #[doc = concat!("assert!(!10", stringify!($SelfT), ".is_negative());")]
library/core/src/num/mod.rs-4
......@@ -1399,7 +1399,6 @@ macro_rules! from_str_int_impl {
13991399 ///
14001400 /// # Examples
14011401 ///
1402 /// Basic usage:
14031402 /// ```
14041403 /// use std::str::FromStr;
14051404 ///
......@@ -1445,7 +1444,6 @@ macro_rules! from_str_int_impl {
14451444 ///
14461445 /// # Examples
14471446 ///
1448 /// Basic usage:
14491447 /// ```
14501448 #[doc = concat!("assert_eq!(", stringify!($int_ty), "::from_str_radix(\"A\", 16), Ok(10));")]
14511449 /// ```
......@@ -1478,7 +1476,6 @@ macro_rules! from_str_int_impl {
14781476 ///
14791477 /// # Examples
14801478 ///
1481 /// Basic usage:
14821479 /// ```
14831480 /// #![feature(int_from_ascii)]
14841481 ///
......@@ -1523,7 +1520,6 @@ macro_rules! from_str_int_impl {
15231520 ///
15241521 /// # Examples
15251522 ///
1526 /// Basic usage:
15271523 /// ```
15281524 /// #![feature(int_from_ascii)]
15291525 ///
library/core/src/num/saturating.rs-46
......@@ -300,8 +300,6 @@ macro_rules! saturating_impl {
300300
301301 /// # Examples
302302 ///
303 /// Basic usage:
304 ///
305303 /// ```
306304 /// use std::num::Saturating;
307305 ///
......@@ -490,8 +488,6 @@ macro_rules! saturating_int_impl {
490488 ///
491489 /// # Examples
492490 ///
493 /// Basic usage:
494 ///
495491 /// ```
496492 /// use std::num::Saturating;
497493 ///
......@@ -504,8 +500,6 @@ macro_rules! saturating_int_impl {
504500 ///
505501 /// # Examples
506502 ///
507 /// Basic usage:
508 ///
509503 /// ```
510504 /// use std::num::Saturating;
511505 ///
......@@ -518,8 +512,6 @@ macro_rules! saturating_int_impl {
518512 ///
519513 /// # Examples
520514 ///
521 /// Basic usage:
522 ///
523515 /// ```
524516 /// use std::num::Saturating;
525517 ///
......@@ -532,8 +524,6 @@ macro_rules! saturating_int_impl {
532524 ///
533525 /// # Examples
534526 ///
535 /// Basic usage:
536 ///
537527 /// ```
538528 /// use std::num::Saturating;
539529 ///
......@@ -556,8 +546,6 @@ macro_rules! saturating_int_impl {
556546 ///
557547 /// # Examples
558548 ///
559 /// Basic usage:
560 ///
561549 /// ```
562550 /// use std::num::Saturating;
563551 ///
......@@ -576,8 +564,6 @@ macro_rules! saturating_int_impl {
576564 ///
577565 /// # Examples
578566 ///
579 /// Basic usage:
580 ///
581567 /// ```
582568 /// use std::num::Saturating;
583569 ///
......@@ -603,8 +589,6 @@ macro_rules! saturating_int_impl {
603589 ///
604590 /// # Examples
605591 ///
606 /// Basic usage:
607 ///
608592 /// ```
609593 /// use std::num::Saturating;
610594 ///
......@@ -631,8 +615,6 @@ macro_rules! saturating_int_impl {
631615 ///
632616 /// # Examples
633617 ///
634 /// Basic usage:
635 ///
636618 /// ```
637619 /// use std::num::Saturating;
638620 ///
......@@ -654,8 +636,6 @@ macro_rules! saturating_int_impl {
654636 ///
655637 /// # Examples
656638 ///
657 /// Basic usage:
658 ///
659639 /// ```
660640 /// use std::num::Saturating;
661641 ///
......@@ -683,8 +663,6 @@ macro_rules! saturating_int_impl {
683663 /// Please note that this example is shared between integer types.
684664 /// Which explains why `i16` is used here.
685665 ///
686 /// Basic usage:
687 ///
688666 /// ```
689667 /// use std::num::Saturating;
690668 ///
......@@ -712,8 +690,6 @@ macro_rules! saturating_int_impl {
712690 ///
713691 /// # Examples
714692 ///
715 /// Basic usage:
716 ///
717693 /// ```
718694 /// use std::num::Saturating;
719695 ///
......@@ -740,8 +716,6 @@ macro_rules! saturating_int_impl {
740716 ///
741717 /// # Examples
742718 ///
743 /// Basic usage:
744 ///
745719 /// ```
746720 /// use std::num::Saturating;
747721 ///
......@@ -768,8 +742,6 @@ macro_rules! saturating_int_impl {
768742 ///
769743 /// # Examples
770744 ///
771 /// Basic usage:
772 ///
773745 /// ```
774746 /// use std::num::Saturating;
775747 ///
......@@ -797,8 +769,6 @@ macro_rules! saturating_int_impl {
797769 ///
798770 /// # Examples
799771 ///
800 /// Basic usage:
801 ///
802772 /// ```
803773 /// use std::num::Saturating;
804774 ///
......@@ -823,8 +793,6 @@ macro_rules! saturating_int_impl {
823793 ///
824794 /// # Examples
825795 ///
826 /// Basic usage:
827 ///
828796 /// ```
829797 /// use std::num::Saturating;
830798 ///
......@@ -860,8 +828,6 @@ macro_rules! saturating_int_impl_signed {
860828 ///
861829 /// # Examples
862830 ///
863 /// Basic usage:
864 ///
865831 /// ```
866832 /// use std::num::Saturating;
867833 ///
......@@ -883,8 +849,6 @@ macro_rules! saturating_int_impl_signed {
883849 ///
884850 /// # Examples
885851 ///
886 /// Basic usage:
887 ///
888852 /// ```
889853 /// use std::num::Saturating;
890854 ///
......@@ -911,8 +875,6 @@ macro_rules! saturating_int_impl_signed {
911875 ///
912876 /// # Examples
913877 ///
914 /// Basic usage:
915 ///
916878 /// ```
917879 /// use std::num::Saturating;
918880 ///
......@@ -934,8 +896,6 @@ macro_rules! saturating_int_impl_signed {
934896 ///
935897 /// # Examples
936898 ///
937 /// Basic usage:
938 ///
939899 /// ```
940900 /// use std::num::Saturating;
941901 ///
......@@ -955,8 +915,6 @@ macro_rules! saturating_int_impl_signed {
955915 ///
956916 /// # Examples
957917 ///
958 /// Basic usage:
959 ///
960918 /// ```
961919 /// use std::num::Saturating;
962920 ///
......@@ -994,8 +952,6 @@ macro_rules! saturating_int_impl_unsigned {
994952 ///
995953 /// # Examples
996954 ///
997 /// Basic usage:
998 ///
999955 /// ```
1000956 /// use std::num::Saturating;
1001957 ///
......@@ -1016,8 +972,6 @@ macro_rules! saturating_int_impl_unsigned {
1016972 ///
1017973 /// # Examples
1018974 ///
1019 /// Basic usage:
1020 ///
1021975 /// ```
1022976 /// use std::num::Saturating;
1023977 ///
library/core/src/num/uint_macros.rs-197
......@@ -27,8 +27,6 @@ macro_rules! uint_impl {
2727 ///
2828 /// # Examples
2929 ///
30 /// Basic usage:
31 ///
3230 /// ```
3331 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN, 0);")]
3432 /// ```
......@@ -40,8 +38,6 @@ macro_rules! uint_impl {
4038 ///
4139 /// # Examples
4240 ///
43 /// Basic usage:
44 ///
4541 /// ```
4642 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX, ", stringify!($MaxV), ");")]
4743 /// ```
......@@ -62,8 +58,6 @@ macro_rules! uint_impl {
6258 ///
6359 /// # Examples
6460 ///
65 /// Basic usage:
66 ///
6761 /// ```
6862 #[doc = concat!("let n = 0b01001100", stringify!($SelfT), ";")]
6963 /// assert_eq!(n.count_ones(), 3);
......@@ -89,8 +83,6 @@ macro_rules! uint_impl {
8983 ///
9084 /// # Examples
9185 ///
92 /// Basic usage:
93 ///
9486 /// ```
9587 #[doc = concat!("let zero = 0", stringify!($SelfT), ";")]
9688 #[doc = concat!("assert_eq!(zero.count_zeros(), ", stringify!($BITS), ");")]
......@@ -114,8 +106,6 @@ macro_rules! uint_impl {
114106 ///
115107 /// # Examples
116108 ///
117 /// Basic usage:
118 ///
119109 /// ```
120110 #[doc = concat!("let n = ", stringify!($SelfT), "::MAX >> 2;")]
121111 /// assert_eq!(n.leading_zeros(), 2);
......@@ -141,8 +131,6 @@ macro_rules! uint_impl {
141131 ///
142132 /// # Examples
143133 ///
144 /// Basic usage:
145 ///
146134 /// ```
147135 #[doc = concat!("let n = 0b0101000", stringify!($SelfT), ";")]
148136 /// assert_eq!(n.trailing_zeros(), 3);
......@@ -166,8 +154,6 @@ macro_rules! uint_impl {
166154 ///
167155 /// # Examples
168156 ///
169 /// Basic usage:
170 ///
171157 /// ```
172158 #[doc = concat!("let n = !(", stringify!($SelfT), "::MAX >> 2);")]
173159 /// assert_eq!(n.leading_ones(), 2);
......@@ -192,8 +178,6 @@ macro_rules! uint_impl {
192178 ///
193179 /// # Examples
194180 ///
195 /// Basic usage:
196 ///
197181 /// ```
198182 #[doc = concat!("let n = 0b1010111", stringify!($SelfT), ";")]
199183 /// assert_eq!(n.trailing_ones(), 3);
......@@ -219,8 +203,6 @@ macro_rules! uint_impl {
219203 ///
220204 /// # Examples
221205 ///
222 /// Basic usage:
223 ///
224206 /// ```
225207 /// #![feature(uint_bit_width)]
226208 ///
......@@ -242,8 +224,6 @@ macro_rules! uint_impl {
242224 ///
243225 /// # Examples
244226 ///
245 /// Basic usage:
246 ///
247227 /// ```
248228 /// #![feature(isolate_most_least_significant_one)]
249229 ///
......@@ -265,8 +245,6 @@ macro_rules! uint_impl {
265245 ///
266246 /// # Examples
267247 ///
268 /// Basic usage:
269 ///
270248 /// ```
271249 /// #![feature(isolate_most_least_significant_one)]
272250 ///
......@@ -290,8 +268,6 @@ macro_rules! uint_impl {
290268 ///
291269 /// # Examples
292270 ///
293 /// Basic usage:
294 ///
295271 /// ```
296272 #[doc = concat!("let n = ", stringify!($SelfT), "::MAX;")]
297273 ///
......@@ -313,8 +289,6 @@ macro_rules! uint_impl {
313289 ///
314290 /// # Examples
315291 ///
316 /// Basic usage:
317 ///
318292 /// ```
319293 #[doc = concat!("let n = ", $rot_op, stringify!($SelfT), ";")]
320294 #[doc = concat!("let m = ", $rot_result, ";")]
......@@ -338,8 +312,6 @@ macro_rules! uint_impl {
338312 ///
339313 /// # Examples
340314 ///
341 /// Basic usage:
342 ///
343315 /// ```
344316 #[doc = concat!("let n = ", $rot_result, stringify!($SelfT), ";")]
345317 #[doc = concat!("let m = ", $rot_op, ";")]
......@@ -359,8 +331,6 @@ macro_rules! uint_impl {
359331 ///
360332 /// # Examples
361333 ///
362 /// Basic usage:
363 ///
364334 /// ```
365335 #[doc = concat!("let n = ", $swap_op, stringify!($SelfT), ";")]
366336 /// let m = n.swap_bytes();
......@@ -381,8 +351,6 @@ macro_rules! uint_impl {
381351 ///
382352 /// # Examples
383353 ///
384 /// Basic usage:
385 ///
386354 /// ```
387355 #[doc = concat!("let n = ", $swap_op, stringify!($SelfT), ";")]
388356 /// let m = n.reverse_bits();
......@@ -406,8 +374,6 @@ macro_rules! uint_impl {
406374 ///
407375 /// # Examples
408376 ///
409 /// Basic usage:
410 ///
411377 /// ```
412378 #[doc = concat!("let n = 0x1A", stringify!($SelfT), ";")]
413379 ///
......@@ -439,8 +405,6 @@ macro_rules! uint_impl {
439405 ///
440406 /// # Examples
441407 ///
442 /// Basic usage:
443 ///
444408 /// ```
445409 #[doc = concat!("let n = 0x1A", stringify!($SelfT), ";")]
446410 ///
......@@ -472,8 +436,6 @@ macro_rules! uint_impl {
472436 ///
473437 /// # Examples
474438 ///
475 /// Basic usage:
476 ///
477439 /// ```
478440 #[doc = concat!("let n = 0x1A", stringify!($SelfT), ";")]
479441 ///
......@@ -506,8 +468,6 @@ macro_rules! uint_impl {
506468 ///
507469 /// # Examples
508470 ///
509 /// Basic usage:
510 ///
511471 /// ```
512472 #[doc = concat!("let n = 0x1A", stringify!($SelfT), ";")]
513473 ///
......@@ -538,8 +498,6 @@ macro_rules! uint_impl {
538498 ///
539499 /// # Examples
540500 ///
541 /// Basic usage:
542 ///
543501 /// ```
544502 #[doc = concat!(
545503 "assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(1), ",
......@@ -579,8 +537,6 @@ macro_rules! uint_impl {
579537 ///
580538 /// # Examples
581539 ///
582 /// Basic usage:
583 ///
584540 /// ```
585541 /// #![feature(strict_overflow_ops)]
586542 #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).strict_add(1), ", stringify!($SelfT), "::MAX - 1);")]
......@@ -647,8 +603,6 @@ macro_rules! uint_impl {
647603 ///
648604 /// # Examples
649605 ///
650 /// Basic usage:
651 ///
652606 /// ```
653607 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_add_signed(2), Some(3));")]
654608 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_add_signed(-2), None);")]
......@@ -675,8 +629,6 @@ macro_rules! uint_impl {
675629 ///
676630 /// # Examples
677631 ///
678 /// Basic usage:
679 ///
680632 /// ```
681633 /// #![feature(strict_overflow_ops)]
682634 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".strict_add_signed(2), 3);")]
......@@ -708,8 +660,6 @@ macro_rules! uint_impl {
708660 ///
709661 /// # Examples
710662 ///
711 /// Basic usage:
712 ///
713663 /// ```
714664 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_sub(1), Some(0));")]
715665 #[doc = concat!("assert_eq!(0", stringify!($SelfT), ".checked_sub(1), None);")]
......@@ -744,8 +694,6 @@ macro_rules! uint_impl {
744694 ///
745695 /// # Examples
746696 ///
747 /// Basic usage:
748 ///
749697 /// ```
750698 /// #![feature(strict_overflow_ops)]
751699 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".strict_sub(1), 0);")]
......@@ -837,8 +785,6 @@ macro_rules! uint_impl {
837785 ///
838786 /// # Examples
839787 ///
840 /// Basic usage:
841 ///
842788 /// ```
843789 /// #![feature(mixed_integer_ops_unsigned_sub)]
844790 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_sub_signed(2), None);")]
......@@ -866,8 +812,6 @@ macro_rules! uint_impl {
866812 ///
867813 /// # Examples
868814 ///
869 /// Basic usage:
870 ///
871815 /// ```
872816 /// #![feature(unsigned_signed_diff)]
873817 #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".checked_signed_diff(2), Some(8));")]
......@@ -925,8 +869,6 @@ macro_rules! uint_impl {
925869 ///
926870 /// # Examples
927871 ///
928 /// Basic usage:
929 ///
930872 /// ```
931873 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_mul(1), Some(5));")]
932874 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.checked_mul(2), None);")]
......@@ -952,8 +894,6 @@ macro_rules! uint_impl {
952894 ///
953895 /// # Examples
954896 ///
955 /// Basic usage:
956 ///
957897 /// ```
958898 /// #![feature(strict_overflow_ops)]
959899 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".strict_mul(1), 5);")]
......@@ -1020,8 +960,6 @@ macro_rules! uint_impl {
1020960 ///
1021961 /// # Examples
1022962 ///
1023 /// Basic usage:
1024 ///
1025963 /// ```
1026964 #[doc = concat!("assert_eq!(128", stringify!($SelfT), ".checked_div(2), Some(64));")]
1027965 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_div(0), None);")]
......@@ -1053,8 +991,6 @@ macro_rules! uint_impl {
1053991 ///
1054992 /// # Examples
1055993 ///
1056 /// Basic usage:
1057 ///
1058994 /// ```
1059995 /// #![feature(strict_overflow_ops)]
1060996 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".strict_div(10), 10);")]
......@@ -1080,8 +1016,6 @@ macro_rules! uint_impl {
10801016 ///
10811017 /// # Examples
10821018 ///
1083 /// Basic usage:
1084 ///
10851019 /// ```
10861020 #[doc = concat!("assert_eq!(128", stringify!($SelfT), ".checked_div_euclid(2), Some(64));")]
10871021 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_div_euclid(0), None);")]
......@@ -1113,8 +1047,6 @@ macro_rules! uint_impl {
11131047 ///
11141048 /// # Examples
11151049 ///
1116 /// Basic usage:
1117 ///
11181050 /// ```
11191051 /// #![feature(strict_overflow_ops)]
11201052 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".strict_div_euclid(10), 10);")]
......@@ -1142,8 +1074,6 @@ macro_rules! uint_impl {
11421074 ///
11431075 /// # Examples
11441076 ///
1145 /// Basic usage:
1146 ///
11471077 /// ```
11481078 /// #![feature(exact_div)]
11491079 #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".exact_div(2), 32);")]
......@@ -1184,8 +1114,6 @@ macro_rules! uint_impl {
11841114 ///
11851115 /// # Examples
11861116 ///
1187 /// Basic usage:
1188 ///
11891117 /// ```
11901118 /// #![feature(exact_div)]
11911119 #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".exact_div(2), 32);")]
......@@ -1241,8 +1169,6 @@ macro_rules! uint_impl {
12411169 ///
12421170 /// # Examples
12431171 ///
1244 /// Basic usage:
1245 ///
12461172 /// ```
12471173 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_rem(2), Some(1));")]
12481174 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_rem(0), None);")]
......@@ -1275,8 +1201,6 @@ macro_rules! uint_impl {
12751201 ///
12761202 /// # Examples
12771203 ///
1278 /// Basic usage:
1279 ///
12801204 /// ```
12811205 /// #![feature(strict_overflow_ops)]
12821206 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".strict_rem(10), 0);")]
......@@ -1302,8 +1226,6 @@ macro_rules! uint_impl {
13021226 ///
13031227 /// # Examples
13041228 ///
1305 /// Basic usage:
1306 ///
13071229 /// ```
13081230 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_rem_euclid(2), Some(1));")]
13091231 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_rem_euclid(0), None);")]
......@@ -1336,8 +1258,6 @@ macro_rules! uint_impl {
13361258 ///
13371259 /// # Examples
13381260 ///
1339 /// Basic usage:
1340 ///
13411261 /// ```
13421262 /// #![feature(strict_overflow_ops)]
13431263 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".strict_rem_euclid(10), 0);")]
......@@ -1583,8 +1503,6 @@ macro_rules! uint_impl {
15831503 ///
15841504 /// # Examples
15851505 ///
1586 /// Basic usage:
1587 ///
15881506 /// ```
15891507 #[doc = concat!("assert_eq!(0", stringify!($SelfT), ".checked_neg(), Some(0));")]
15901508 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_neg(), None);")]
......@@ -1612,8 +1530,6 @@ macro_rules! uint_impl {
16121530 ///
16131531 /// # Examples
16141532 ///
1615 /// Basic usage:
1616 ///
16171533 /// ```
16181534 /// #![feature(strict_overflow_ops)]
16191535 #[doc = concat!("assert_eq!(0", stringify!($SelfT), ".strict_neg(), 0);")]
......@@ -1640,8 +1556,6 @@ macro_rules! uint_impl {
16401556 ///
16411557 /// # Examples
16421558 ///
1643 /// Basic usage:
1644 ///
16451559 /// ```
16461560 #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".checked_shl(4), Some(0x10));")]
16471561 #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".checked_shl(129), None);")]
......@@ -1673,8 +1587,6 @@ macro_rules! uint_impl {
16731587 ///
16741588 /// # Examples
16751589 ///
1676 /// Basic usage:
1677 ///
16781590 /// ```
16791591 /// #![feature(strict_overflow_ops)]
16801592 #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".strict_shl(4), 0x10);")]
......@@ -1737,7 +1649,6 @@ macro_rules! uint_impl {
17371649 ///
17381650 /// # Examples
17391651 ///
1740 /// Basic usage:
17411652 /// ```
17421653 #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".unbounded_shl(4), 0x10);")]
17431654 #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".unbounded_shl(129), 0);")]
......@@ -1762,8 +1673,6 @@ macro_rules! uint_impl {
17621673 ///
17631674 /// # Examples
17641675 ///
1765 /// Basic usage:
1766 ///
17671676 /// ```
17681677 #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".checked_shr(4), Some(0x1));")]
17691678 #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".checked_shr(129), None);")]
......@@ -1794,8 +1703,6 @@ macro_rules! uint_impl {
17941703 ///
17951704 /// # Examples
17961705 ///
1797 /// Basic usage:
1798 ///
17991706 /// ```
18001707 /// #![feature(strict_overflow_ops)]
18011708 #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".strict_shr(4), 0x1);")]
......@@ -1858,7 +1765,6 @@ macro_rules! uint_impl {
18581765 ///
18591766 /// # Examples
18601767 ///
1861 /// Basic usage:
18621768 /// ```
18631769 #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".unbounded_shr(4), 0x1);")]
18641770 #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".unbounded_shr(129), 0);")]
......@@ -1883,8 +1789,6 @@ macro_rules! uint_impl {
18831789 ///
18841790 /// # Examples
18851791 ///
1886 /// Basic usage:
1887 ///
18881792 /// ```
18891793 #[doc = concat!("assert_eq!(2", stringify!($SelfT), ".checked_pow(5), Some(32));")]
18901794 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.checked_pow(2), None);")]
......@@ -1925,8 +1829,6 @@ macro_rules! uint_impl {
19251829 ///
19261830 /// # Examples
19271831 ///
1928 /// Basic usage:
1929 ///
19301832 /// ```
19311833 /// #![feature(strict_overflow_ops)]
19321834 #[doc = concat!("assert_eq!(2", stringify!($SelfT), ".strict_pow(5), 32);")]
......@@ -1968,8 +1870,6 @@ macro_rules! uint_impl {
19681870 ///
19691871 /// # Examples
19701872 ///
1971 /// Basic usage:
1972 ///
19731873 /// ```
19741874 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".saturating_add(1), 101);")]
19751875 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.saturating_add(127), ", stringify!($SelfT), "::MAX);")]
......@@ -1988,8 +1888,6 @@ macro_rules! uint_impl {
19881888 ///
19891889 /// # Examples
19901890 ///
1991 /// Basic usage:
1992 ///
19931891 /// ```
19941892 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".saturating_add_signed(2), 3);")]
19951893 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".saturating_add_signed(-2), 0);")]
......@@ -2016,8 +1914,6 @@ macro_rules! uint_impl {
20161914 ///
20171915 /// # Examples
20181916 ///
2019 /// Basic usage:
2020 ///
20211917 /// ```
20221918 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".saturating_sub(27), 73);")]
20231919 #[doc = concat!("assert_eq!(13", stringify!($SelfT), ".saturating_sub(127), 0);")]
......@@ -2036,8 +1932,6 @@ macro_rules! uint_impl {
20361932 ///
20371933 /// # Examples
20381934 ///
2039 /// Basic usage:
2040 ///
20411935 /// ```
20421936 /// #![feature(mixed_integer_ops_unsigned_sub)]
20431937 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".saturating_sub_signed(2), 0);")]
......@@ -2065,8 +1959,6 @@ macro_rules! uint_impl {
20651959 ///
20661960 /// # Examples
20671961 ///
2068 /// Basic usage:
2069 ///
20701962 /// ```
20711963 #[doc = concat!("assert_eq!(2", stringify!($SelfT), ".saturating_mul(10), 20);")]
20721964 #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX).saturating_mul(10), ", stringify!($SelfT),"::MAX);")]
......@@ -2092,8 +1984,6 @@ macro_rules! uint_impl {
20921984 ///
20931985 /// # Examples
20941986 ///
2095 /// Basic usage:
2096 ///
20971987 /// ```
20981988 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".saturating_div(2), 2);")]
20991989 ///
......@@ -2114,8 +2004,6 @@ macro_rules! uint_impl {
21142004 ///
21152005 /// # Examples
21162006 ///
2117 /// Basic usage:
2118 ///
21192007 /// ```
21202008 #[doc = concat!("assert_eq!(4", stringify!($SelfT), ".saturating_pow(3), 64);")]
21212009 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.saturating_pow(2), ", stringify!($SelfT), "::MAX);")]
......@@ -2137,8 +2025,6 @@ macro_rules! uint_impl {
21372025 ///
21382026 /// # Examples
21392027 ///
2140 /// Basic usage:
2141 ///
21422028 /// ```
21432029 #[doc = concat!("assert_eq!(200", stringify!($SelfT), ".wrapping_add(55), 255);")]
21442030 #[doc = concat!("assert_eq!(200", stringify!($SelfT), ".wrapping_add(", stringify!($SelfT), "::MAX), 199);")]
......@@ -2157,8 +2043,6 @@ macro_rules! uint_impl {
21572043 ///
21582044 /// # Examples
21592045 ///
2160 /// Basic usage:
2161 ///
21622046 /// ```
21632047 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".wrapping_add_signed(2), 3);")]
21642048 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".wrapping_add_signed(-2), ", stringify!($SelfT), "::MAX);")]
......@@ -2178,8 +2062,6 @@ macro_rules! uint_impl {
21782062 ///
21792063 /// # Examples
21802064 ///
2181 /// Basic usage:
2182 ///
21832065 /// ```
21842066 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_sub(100), 0);")]
21852067 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_sub(", stringify!($SelfT), "::MAX), 101);")]
......@@ -2198,8 +2080,6 @@ macro_rules! uint_impl {
21982080 ///
21992081 /// # Examples
22002082 ///
2201 /// Basic usage:
2202 ///
22032083 /// ```
22042084 /// #![feature(mixed_integer_ops_unsigned_sub)]
22052085 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".wrapping_sub_signed(2), ", stringify!($SelfT), "::MAX);")]
......@@ -2219,8 +2099,6 @@ macro_rules! uint_impl {
22192099 ///
22202100 /// # Examples
22212101 ///
2222 /// Basic usage:
2223 ///
22242102 /// Please note that this example is shared between integer types.
22252103 /// Which explains why `u8` is used here.
22262104 ///
......@@ -2249,8 +2127,6 @@ macro_rules! uint_impl {
22492127 ///
22502128 /// # Examples
22512129 ///
2252 /// Basic usage:
2253 ///
22542130 /// ```
22552131 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_div(10), 10);")]
22562132 /// ```
......@@ -2278,8 +2154,6 @@ macro_rules! uint_impl {
22782154 ///
22792155 /// # Examples
22802156 ///
2281 /// Basic usage:
2282 ///
22832157 /// ```
22842158 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_div_euclid(10), 10);")]
22852159 /// ```
......@@ -2306,8 +2180,6 @@ macro_rules! uint_impl {
23062180 ///
23072181 /// # Examples
23082182 ///
2309 /// Basic usage:
2310 ///
23112183 /// ```
23122184 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_rem(10), 0);")]
23132185 /// ```
......@@ -2336,8 +2208,6 @@ macro_rules! uint_impl {
23362208 ///
23372209 /// # Examples
23382210 ///
2339 /// Basic usage:
2340 ///
23412211 /// ```
23422212 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_rem_euclid(10), 0);")]
23432213 /// ```
......@@ -2363,8 +2233,6 @@ macro_rules! uint_impl {
23632233 ///
23642234 /// # Examples
23652235 ///
2366 /// Basic usage:
2367 ///
23682236 /// ```
23692237 #[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".wrapping_neg(), 0);")]
23702238 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.wrapping_neg(), 1);")]
......@@ -2393,8 +2261,6 @@ macro_rules! uint_impl {
23932261 ///
23942262 /// # Examples
23952263 ///
2396 /// Basic usage:
2397 ///
23982264 /// ```
23992265 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".wrapping_shl(7), 128);")]
24002266 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".wrapping_shl(128), 1);")]
......@@ -2425,8 +2291,6 @@ macro_rules! uint_impl {
24252291 ///
24262292 /// # Examples
24272293 ///
2428 /// Basic usage:
2429 ///
24302294 /// ```
24312295 #[doc = concat!("assert_eq!(128", stringify!($SelfT), ".wrapping_shr(7), 1);")]
24322296 #[doc = concat!("assert_eq!(128", stringify!($SelfT), ".wrapping_shr(128), 128);")]
......@@ -2449,8 +2313,6 @@ macro_rules! uint_impl {
24492313 ///
24502314 /// # Examples
24512315 ///
2452 /// Basic usage:
2453 ///
24542316 /// ```
24552317 #[doc = concat!("assert_eq!(3", stringify!($SelfT), ".wrapping_pow(5), 243);")]
24562318 /// assert_eq!(3u8.wrapping_pow(6), 217);
......@@ -2507,8 +2369,6 @@ macro_rules! uint_impl {
25072369 ///
25082370 /// # Examples
25092371 ///
2510 /// Basic usage:
2511 ///
25122372 /// ```
25132373 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_add(2), (7, false));")]
25142374 #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.overflowing_add(1), (0, true));")]
......@@ -2587,8 +2447,6 @@ macro_rules! uint_impl {
25872447 ///
25882448 /// # Examples
25892449 ///
2590 /// Basic usage:
2591 ///
25922450 /// ```
25932451 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".overflowing_add_signed(2), (3, false));")]
25942452 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".overflowing_add_signed(-2), (", stringify!($SelfT), "::MAX, true));")]
......@@ -2612,8 +2470,6 @@ macro_rules! uint_impl {
26122470 ///
26132471 /// # Examples
26142472 ///
2615 /// Basic usage:
2616 ///
26172473 /// ```
26182474 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_sub(2), (3, false));")]
26192475 #[doc = concat!("assert_eq!(0", stringify!($SelfT), ".overflowing_sub(1), (", stringify!($SelfT), "::MAX, true));")]
......@@ -2683,8 +2539,6 @@ macro_rules! uint_impl {
26832539 ///
26842540 /// # Examples
26852541 ///
2686 /// Basic usage:
2687 ///
26882542 /// ```
26892543 /// #![feature(mixed_integer_ops_unsigned_sub)]
26902544 #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".overflowing_sub_signed(2), (", stringify!($SelfT), "::MAX, true));")]
......@@ -2705,8 +2559,6 @@ macro_rules! uint_impl {
27052559 ///
27062560 /// # Examples
27072561 ///
2708 /// Basic usage:
2709 ///
27102562 /// ```
27112563 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".abs_diff(80), 20", stringify!($SelfT), ");")]
27122564 #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".abs_diff(110), 10", stringify!($SelfT), ");")]
......@@ -2738,8 +2590,6 @@ macro_rules! uint_impl {
27382590 ///
27392591 /// # Examples
27402592 ///
2741 /// Basic usage:
2742 ///
27432593 /// Please note that this example is shared between integer types.
27442594 /// Which explains why `u32` is used here.
27452595 ///
......@@ -2767,8 +2617,6 @@ macro_rules! uint_impl {
27672617 ///
27682618 /// # Examples
27692619 ///
2770 /// Basic usage:
2771 ///
27722620 /// Please note that this example is shared between integer types.
27732621 /// Which explains why `u32` is used here.
27742622 ///
......@@ -2800,8 +2648,6 @@ macro_rules! uint_impl {
28002648 ///
28012649 /// # Examples
28022650 ///
2803 /// Basic usage:
2804 ///
28052651 /// Please note that this example is shared between integer types.
28062652 /// Which explains why `u32` is used here.
28072653 ///
......@@ -2888,8 +2734,6 @@ macro_rules! uint_impl {
28882734 ///
28892735 /// # Examples
28902736 ///
2891 /// Basic usage:
2892 ///
28932737 /// Please note that this example is shared between integer types,
28942738 /// which explains why `u32` is used here.
28952739 ///
......@@ -2955,8 +2799,6 @@ macro_rules! uint_impl {
29552799 ///
29562800 /// # Examples
29572801 ///
2958 /// Basic usage:
2959 ///
29602802 /// ```
29612803 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_div(2), (2, false));")]
29622804 /// ```
......@@ -2986,8 +2828,6 @@ macro_rules! uint_impl {
29862828 ///
29872829 /// # Examples
29882830 ///
2989 /// Basic usage:
2990 ///
29912831 /// ```
29922832 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_div_euclid(2), (2, false));")]
29932833 /// ```
......@@ -3014,8 +2854,6 @@ macro_rules! uint_impl {
30142854 ///
30152855 /// # Examples
30162856 ///
3017 /// Basic usage:
3018 ///
30192857 /// ```
30202858 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_rem(2), (1, false));")]
30212859 /// ```
......@@ -3045,8 +2883,6 @@ macro_rules! uint_impl {
30452883 ///
30462884 /// # Examples
30472885 ///
3048 /// Basic usage:
3049 ///
30502886 /// ```
30512887 #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_rem_euclid(2), (1, false));")]
30522888 /// ```
......@@ -3069,8 +2905,6 @@ macro_rules! uint_impl {
30692905 ///
30702906 /// # Examples
30712907 ///
3072 /// Basic usage:
3073 ///
30742908 /// ```
30752909 #[doc = concat!("assert_eq!(0", stringify!($SelfT), ".overflowing_neg(), (0, false));")]
30762910 #[doc = concat!("assert_eq!(2", stringify!($SelfT), ".overflowing_neg(), (-2i32 as ", stringify!($SelfT), ", true));")]
......@@ -3094,8 +2928,6 @@ macro_rules! uint_impl {
30942928 ///
30952929 /// # Examples
30962930 ///
3097 /// Basic usage:
3098 ///
30992931 /// ```
31002932 #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".overflowing_shl(4), (0x10, false));")]
31012933 #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".overflowing_shl(132), (0x10, true));")]
......@@ -3120,8 +2952,6 @@ macro_rules! uint_impl {
31202952 ///
31212953 /// # Examples
31222954 ///
3123 /// Basic usage:
3124 ///
31252955 /// ```
31262956 #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".overflowing_shr(4), (0x1, false));")]
31272957 #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".overflowing_shr(132), (0x1, true));")]
......@@ -3142,8 +2972,6 @@ macro_rules! uint_impl {
31422972 ///
31432973 /// # Examples
31442974 ///
3145 /// Basic usage:
3146 ///
31472975 /// ```
31482976 #[doc = concat!("assert_eq!(3", stringify!($SelfT), ".overflowing_pow(5), (243, false));")]
31492977 /// assert_eq!(3u8.overflowing_pow(6), (217, true));
......@@ -3185,8 +3013,6 @@ macro_rules! uint_impl {
31853013 ///
31863014 /// # Examples
31873015 ///
3188 /// Basic usage:
3189 ///
31903016 /// ```
31913017 #[doc = concat!("assert_eq!(2", stringify!($SelfT), ".pow(5), 32);")]
31923018 /// ```
......@@ -3240,7 +3066,6 @@ macro_rules! uint_impl {
32403066 ///
32413067 /// # Examples
32423068 ///
3243 /// Basic usage:
32443069 /// ```
32453070 #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".isqrt(), 3);")]
32463071 /// ```
......@@ -3282,8 +3107,6 @@ macro_rules! uint_impl {
32823107 ///
32833108 /// # Examples
32843109 ///
3285 /// Basic usage:
3286 ///
32873110 /// ```
32883111 #[doc = concat!("assert_eq!(7", stringify!($SelfT), ".div_euclid(4), 1); // or any other integer type")]
32893112 /// ```
......@@ -3310,8 +3133,6 @@ macro_rules! uint_impl {
33103133 ///
33113134 /// # Examples
33123135 ///
3313 /// Basic usage:
3314 ///
33153136 /// ```
33163137 #[doc = concat!("assert_eq!(7", stringify!($SelfT), ".rem_euclid(4), 3); // or any other integer type")]
33173138 /// ```
......@@ -3336,8 +3157,6 @@ macro_rules! uint_impl {
33363157 ///
33373158 /// # Examples
33383159 ///
3339 /// Basic usage:
3340 ///
33413160 /// ```
33423161 /// #![feature(int_roundings)]
33433162 #[doc = concat!("assert_eq!(7_", stringify!($SelfT), ".div_floor(4), 1);")]
......@@ -3359,8 +3178,6 @@ macro_rules! uint_impl {
33593178 ///
33603179 /// # Examples
33613180 ///
3362 /// Basic usage:
3363 ///
33643181 /// ```
33653182 #[doc = concat!("assert_eq!(7_", stringify!($SelfT), ".div_ceil(4), 2);")]
33663183 /// ```
......@@ -3394,8 +3211,6 @@ macro_rules! uint_impl {
33943211 ///
33953212 /// # Examples
33963213 ///
3397 /// Basic usage:
3398 ///
33993214 /// ```
34003215 #[doc = concat!("assert_eq!(16_", stringify!($SelfT), ".next_multiple_of(8), 16);")]
34013216 #[doc = concat!("assert_eq!(23_", stringify!($SelfT), ".next_multiple_of(8), 24);")]
......@@ -3419,8 +3234,6 @@ macro_rules! uint_impl {
34193234 ///
34203235 /// # Examples
34213236 ///
3422 /// Basic usage:
3423 ///
34243237 /// ```
34253238 #[doc = concat!("assert_eq!(16_", stringify!($SelfT), ".checked_next_multiple_of(8), Some(16));")]
34263239 #[doc = concat!("assert_eq!(23_", stringify!($SelfT), ".checked_next_multiple_of(8), Some(24));")]
......@@ -3448,8 +3261,6 @@ macro_rules! uint_impl {
34483261 ///
34493262 /// # Examples
34503263 ///
3451 /// Basic usage:
3452 ///
34533264 /// ```
34543265 #[doc = concat!("assert!(6_", stringify!($SelfT), ".is_multiple_of(2));")]
34553266 #[doc = concat!("assert!(!5_", stringify!($SelfT), ".is_multiple_of(2));")]
......@@ -3473,8 +3284,6 @@ macro_rules! uint_impl {
34733284 ///
34743285 /// # Examples
34753286 ///
3476 /// Basic usage:
3477 ///
34783287 /// ```
34793288 #[doc = concat!("assert!(16", stringify!($SelfT), ".is_power_of_two());")]
34803289 #[doc = concat!("assert!(!10", stringify!($SelfT), ".is_power_of_two());")]
......@@ -3517,8 +3326,6 @@ macro_rules! uint_impl {
35173326 ///
35183327 /// # Examples
35193328 ///
3520 /// Basic usage:
3521 ///
35223329 /// ```
35233330 #[doc = concat!("assert_eq!(2", stringify!($SelfT), ".next_power_of_two(), 2);")]
35243331 #[doc = concat!("assert_eq!(3", stringify!($SelfT), ".next_power_of_two(), 4);")]
......@@ -3540,8 +3347,6 @@ macro_rules! uint_impl {
35403347 ///
35413348 /// # Examples
35423349 ///
3543 /// Basic usage:
3544 ///
35453350 /// ```
35463351 #[doc = concat!("assert_eq!(2", stringify!($SelfT), ".checked_next_power_of_two(), Some(2));")]
35473352 #[doc = concat!("assert_eq!(3", stringify!($SelfT), ".checked_next_power_of_two(), Some(4));")]
......@@ -3562,8 +3367,6 @@ macro_rules! uint_impl {
35623367 ///
35633368 /// # Examples
35643369 ///
3565 /// Basic usage:
3566 ///
35673370 /// ```
35683371 /// #![feature(wrapping_next_power_of_two)]
35693372 ///
src/bootstrap/src/bin/rustc.rs-12
......@@ -151,18 +151,6 @@ fn main() {
151151 cmd.arg("--sysroot").arg(&sysroot);
152152 }
153153
154 // If we're compiling specifically the `panic_abort` crate then we pass
155 // the `-C panic=abort` option. Note that we do not do this for any
156 // other crate intentionally as this is the only crate for now that we
157 // ship with panic=abort.
158 //
159 // This... is a bit of a hack how we detect this. Ideally this
160 // information should be encoded in the crate I guess? Would likely
161 // require an RFC amendment to RFC 1513, however.
162 if crate_name == Some("panic_abort") {
163 cmd.arg("-C").arg("panic=abort");
164 }
165
166154 let crate_type = parse_value_from_args(&orig_args, "--crate-type");
167155 // `-Ztls-model=initial-exec` must not be applied to proc-macros, see
168156 // issue https://github.com/rust-lang/rust/issues/100530
src/librustdoc/clean/types.rs-14
......@@ -2432,20 +2432,6 @@ pub(crate) enum ConstantKind {
24322432 Infer,
24332433}
24342434
2435impl Constant {
2436 pub(crate) fn expr(&self, tcx: TyCtxt<'_>) -> String {
2437 self.kind.expr(tcx)
2438 }
2439
2440 pub(crate) fn value(&self, tcx: TyCtxt<'_>) -> Option<String> {
2441 self.kind.value(tcx)
2442 }
2443
2444 pub(crate) fn is_literal(&self, tcx: TyCtxt<'_>) -> bool {
2445 self.kind.is_literal(tcx)
2446 }
2447}
2448
24492435impl ConstantKind {
24502436 pub(crate) fn expr(&self, tcx: TyCtxt<'_>) -> String {
24512437 match *self {
src/librustdoc/json/conversions.rs+169-175
......@@ -11,7 +11,7 @@ use rustc_hir::def::CtorKind;
1111use rustc_hir::def_id::DefId;
1212use rustc_metadata::rendered_const;
1313use rustc_middle::{bug, ty};
14use rustc_span::{Pos, Symbol, kw};
14use rustc_span::{Pos, kw, sym};
1515use rustdoc_json_types::*;
1616use thin_vec::ThinVec;
1717
......@@ -66,47 +66,16 @@ impl JsonRenderer<'_> {
6666 id,
6767 crate_id: item_id.krate().as_u32(),
6868 name: name.map(|sym| sym.to_string()),
69 span: span.and_then(|span| self.convert_span(span)),
70 visibility: self.convert_visibility(visibility),
69 span: span.and_then(|span| span.into_json(self)),
70 visibility: visibility.into_json(self),
7171 docs,
7272 attrs,
73 deprecation: deprecation.map(from_deprecation),
73 deprecation: deprecation.into_json(self),
7474 inner,
7575 links,
7676 })
7777 }
7878
79 fn convert_span(&self, span: clean::Span) -> Option<Span> {
80 match span.filename(self.sess()) {
81 rustc_span::FileName::Real(name) => {
82 if let Some(local_path) = name.into_local_path() {
83 let hi = span.hi(self.sess());
84 let lo = span.lo(self.sess());
85 Some(Span {
86 filename: local_path,
87 begin: (lo.line, lo.col.to_usize() + 1),
88 end: (hi.line, hi.col.to_usize() + 1),
89 })
90 } else {
91 None
92 }
93 }
94 _ => None,
95 }
96 }
97
98 fn convert_visibility(&self, v: Option<ty::Visibility<DefId>>) -> Visibility {
99 match v {
100 None => Visibility::Default,
101 Some(ty::Visibility::Public) => Visibility::Public,
102 Some(ty::Visibility::Restricted(did)) if did.is_crate_root() => Visibility::Crate,
103 Some(ty::Visibility::Restricted(did)) => Visibility::Restricted {
104 parent: self.id_from_item_default(did.into()),
105 path: self.tcx.def_path(did).to_string_no_crate_verbose(),
106 },
107 }
108 }
109
11079 fn ids(&self, items: &[clean::Item]) -> Vec<Id> {
11180 items
11281 .iter()
......@@ -140,11 +109,29 @@ where
140109 }
141110}
142111
112impl<T, U> FromClean<Box<T>> for U
113where
114 U: FromClean<T>,
115{
116 fn from_clean(opt: &Box<T>, renderer: &JsonRenderer<'_>) -> Self {
117 opt.as_ref().into_json(renderer)
118 }
119}
120
121impl<T, U> FromClean<Option<T>> for Option<U>
122where
123 U: FromClean<T>,
124{
125 fn from_clean(opt: &Option<T>, renderer: &JsonRenderer<'_>) -> Self {
126 opt.as_ref().map(|x| x.into_json(renderer))
127 }
128}
129
143130impl<T, U> FromClean<Vec<T>> for Vec<U>
144131where
145132 U: FromClean<T>,
146133{
147 fn from_clean(items: &Vec<T>, renderer: &JsonRenderer<'_>) -> Vec<U> {
134 fn from_clean(items: &Vec<T>, renderer: &JsonRenderer<'_>) -> Self {
148135 items.iter().map(|i| i.into_json(renderer)).collect()
149136 }
150137}
......@@ -153,20 +140,57 @@ impl<T, U> FromClean<ThinVec<T>> for Vec<U>
153140where
154141 U: FromClean<T>,
155142{
156 fn from_clean(items: &ThinVec<T>, renderer: &JsonRenderer<'_>) -> Vec<U> {
143 fn from_clean(items: &ThinVec<T>, renderer: &JsonRenderer<'_>) -> Self {
157144 items.iter().map(|i| i.into_json(renderer)).collect()
158145 }
159146}
160147
161pub(crate) fn from_deprecation(deprecation: attrs::Deprecation) -> Deprecation {
162 let attrs::Deprecation { since, note, suggestion: _ } = deprecation;
163 let since = match since {
164 DeprecatedSince::RustcVersion(version) => Some(version.to_string()),
165 DeprecatedSince::Future => Some("TBD".to_owned()),
166 DeprecatedSince::NonStandard(since) => Some(since.to_string()),
167 DeprecatedSince::Unspecified | DeprecatedSince::Err => None,
168 };
169 Deprecation { since, note: note.map(|s| s.to_string()) }
148impl FromClean<clean::Span> for Option<Span> {
149 fn from_clean(span: &clean::Span, renderer: &JsonRenderer<'_>) -> Self {
150 match span.filename(renderer.sess()) {
151 rustc_span::FileName::Real(name) => {
152 if let Some(local_path) = name.into_local_path() {
153 let hi = span.hi(renderer.sess());
154 let lo = span.lo(renderer.sess());
155 Some(Span {
156 filename: local_path,
157 begin: (lo.line, lo.col.to_usize() + 1),
158 end: (hi.line, hi.col.to_usize() + 1),
159 })
160 } else {
161 None
162 }
163 }
164 _ => None,
165 }
166 }
167}
168
169impl FromClean<Option<ty::Visibility<DefId>>> for Visibility {
170 fn from_clean(v: &Option<ty::Visibility<DefId>>, renderer: &JsonRenderer<'_>) -> Self {
171 match v {
172 None => Visibility::Default,
173 Some(ty::Visibility::Public) => Visibility::Public,
174 Some(ty::Visibility::Restricted(did)) if did.is_crate_root() => Visibility::Crate,
175 Some(ty::Visibility::Restricted(did)) => Visibility::Restricted {
176 parent: renderer.id_from_item_default((*did).into()),
177 path: renderer.tcx.def_path(*did).to_string_no_crate_verbose(),
178 },
179 }
180 }
181}
182
183impl FromClean<attrs::Deprecation> for Deprecation {
184 fn from_clean(deprecation: &attrs::Deprecation, _renderer: &JsonRenderer<'_>) -> Self {
185 let attrs::Deprecation { since, note, suggestion: _ } = deprecation;
186 let since = match since {
187 DeprecatedSince::RustcVersion(version) => Some(version.to_string()),
188 DeprecatedSince::Future => Some("TBD".to_string()),
189 DeprecatedSince::NonStandard(since) => Some(since.to_string()),
190 DeprecatedSince::Unspecified | DeprecatedSince::Err => None,
191 };
192 Deprecation { since, note: note.map(|sym| sym.to_string()) }
193 }
170194}
171195
172196impl FromClean<clean::GenericArgs> for Option<Box<GenericArgs>> {
......@@ -182,7 +206,7 @@ impl FromClean<clean::GenericArgs> for Option<Box<GenericArgs>> {
182206 },
183207 Parenthesized { inputs, output } => GenericArgs::Parenthesized {
184208 inputs: inputs.into_json(renderer),
185 output: output.as_ref().map(|a| a.as_ref().into_json(renderer)),
209 output: output.into_json(renderer),
186210 },
187211 ReturnTypeNotation => GenericArgs::ReturnTypeNotation,
188212 }))
......@@ -193,7 +217,7 @@ impl FromClean<clean::GenericArg> for GenericArg {
193217 fn from_clean(arg: &clean::GenericArg, renderer: &JsonRenderer<'_>) -> Self {
194218 use clean::GenericArg::*;
195219 match arg {
196 Lifetime(l) => GenericArg::Lifetime(convert_lifetime(l)),
220 Lifetime(l) => GenericArg::Lifetime(l.into_json(renderer)),
197221 Type(t) => GenericArg::Type(t.into_json(renderer)),
198222 Const(box c) => GenericArg::Const(c.into_json(renderer)),
199223 Infer => GenericArg::Infer,
......@@ -201,17 +225,6 @@ impl FromClean<clean::GenericArg> for GenericArg {
201225 }
202226}
203227
204impl FromClean<clean::Constant> for Constant {
205 // FIXME(generic_const_items): Add support for generic const items.
206 fn from_clean(constant: &clean::Constant, renderer: &JsonRenderer<'_>) -> Self {
207 let tcx = renderer.tcx;
208 let expr = constant.expr(tcx);
209 let value = constant.value(tcx);
210 let is_literal = constant.is_literal(tcx);
211 Constant { expr, value, is_literal }
212 }
213}
214
215228impl FromClean<clean::ConstantKind> for Constant {
216229 // FIXME(generic_const_items): Add support for generic const items.
217230 fn from_clean(constant: &clean::ConstantKind, renderer: &JsonRenderer<'_>) -> Self {
......@@ -259,21 +272,25 @@ fn from_clean_item(item: &clean::Item, renderer: &JsonRenderer<'_>) -> ItemEnum
259272 StructFieldItem(f) => ItemEnum::StructField(f.into_json(renderer)),
260273 EnumItem(e) => ItemEnum::Enum(e.into_json(renderer)),
261274 VariantItem(v) => ItemEnum::Variant(v.into_json(renderer)),
262 FunctionItem(f) => ItemEnum::Function(from_function(f, true, header.unwrap(), renderer)),
275 FunctionItem(f) => {
276 ItemEnum::Function(from_clean_function(f, true, header.unwrap(), renderer))
277 }
263278 ForeignFunctionItem(f, _) => {
264 ItemEnum::Function(from_function(f, false, header.unwrap(), renderer))
279 ItemEnum::Function(from_clean_function(f, false, header.unwrap(), renderer))
265280 }
266 TraitItem(t) => ItemEnum::Trait(t.as_ref().into_json(renderer)),
281 TraitItem(t) => ItemEnum::Trait(t.into_json(renderer)),
267282 TraitAliasItem(t) => ItemEnum::TraitAlias(t.into_json(renderer)),
268 MethodItem(m, _) => ItemEnum::Function(from_function(m, true, header.unwrap(), renderer)),
283 MethodItem(m, _) => {
284 ItemEnum::Function(from_clean_function(m, true, header.unwrap(), renderer))
285 }
269286 RequiredMethodItem(m) => {
270 ItemEnum::Function(from_function(m, false, header.unwrap(), renderer))
287 ItemEnum::Function(from_clean_function(m, false, header.unwrap(), renderer))
271288 }
272 ImplItem(i) => ItemEnum::Impl(i.as_ref().into_json(renderer)),
273 StaticItem(s) => ItemEnum::Static(convert_static(s, &rustc_hir::Safety::Safe, renderer)),
274 ForeignStaticItem(s, safety) => ItemEnum::Static(convert_static(s, safety, renderer)),
289 ImplItem(i) => ItemEnum::Impl(i.into_json(renderer)),
290 StaticItem(s) => ItemEnum::Static(from_clean_static(s, rustc_hir::Safety::Safe, renderer)),
291 ForeignStaticItem(s, safety) => ItemEnum::Static(from_clean_static(s, *safety, renderer)),
275292 ForeignTypeItem => ItemEnum::ExternType,
276 TypeAliasItem(t) => ItemEnum::TypeAlias(t.as_ref().into_json(renderer)),
293 TypeAliasItem(t) => ItemEnum::TypeAlias(t.into_json(renderer)),
277294 // FIXME(generic_const_items): Add support for generic free consts
278295 ConstantItem(ci) => ItemEnum::Constant {
279296 type_: ci.type_.into_json(renderer),
......@@ -289,7 +306,7 @@ fn from_clean_item(item: &clean::Item, renderer: &JsonRenderer<'_>) -> ItemEnum
289306 }
290307 // FIXME(generic_const_items): Add support for generic associated consts.
291308 RequiredAssocConstItem(_generics, ty) => {
292 ItemEnum::AssocConst { type_: ty.as_ref().into_json(renderer), value: None }
309 ItemEnum::AssocConst { type_: ty.into_json(renderer), value: None }
293310 }
294311 // FIXME(generic_const_items): Add support for generic associated consts.
295312 ProvidedAssocConstItem(ci) | ImplAssocConstItem(ci) => ItemEnum::AssocConst {
......@@ -361,32 +378,38 @@ impl FromClean<clean::Union> for Union {
361378 }
362379}
363380
364pub(crate) fn from_fn_header(header: &rustc_hir::FnHeader) -> FunctionHeader {
365 FunctionHeader {
366 is_async: header.is_async(),
367 is_const: header.is_const(),
368 is_unsafe: header.is_unsafe(),
369 abi: convert_abi(header.abi),
381impl FromClean<rustc_hir::FnHeader> for FunctionHeader {
382 fn from_clean(header: &rustc_hir::FnHeader, renderer: &JsonRenderer<'_>) -> Self {
383 FunctionHeader {
384 is_async: header.is_async(),
385 is_const: header.is_const(),
386 is_unsafe: header.is_unsafe(),
387 abi: header.abi.into_json(renderer),
388 }
370389 }
371390}
372391
373fn convert_abi(a: ExternAbi) -> Abi {
374 match a {
375 ExternAbi::Rust => Abi::Rust,
376 ExternAbi::C { unwind } => Abi::C { unwind },
377 ExternAbi::Cdecl { unwind } => Abi::Cdecl { unwind },
378 ExternAbi::Stdcall { unwind } => Abi::Stdcall { unwind },
379 ExternAbi::Fastcall { unwind } => Abi::Fastcall { unwind },
380 ExternAbi::Aapcs { unwind } => Abi::Aapcs { unwind },
381 ExternAbi::Win64 { unwind } => Abi::Win64 { unwind },
382 ExternAbi::SysV64 { unwind } => Abi::SysV64 { unwind },
383 ExternAbi::System { unwind } => Abi::System { unwind },
384 _ => Abi::Other(a.to_string()),
392impl FromClean<ExternAbi> for Abi {
393 fn from_clean(a: &ExternAbi, _renderer: &JsonRenderer<'_>) -> Self {
394 match *a {
395 ExternAbi::Rust => Abi::Rust,
396 ExternAbi::C { unwind } => Abi::C { unwind },
397 ExternAbi::Cdecl { unwind } => Abi::Cdecl { unwind },
398 ExternAbi::Stdcall { unwind } => Abi::Stdcall { unwind },
399 ExternAbi::Fastcall { unwind } => Abi::Fastcall { unwind },
400 ExternAbi::Aapcs { unwind } => Abi::Aapcs { unwind },
401 ExternAbi::Win64 { unwind } => Abi::Win64 { unwind },
402 ExternAbi::SysV64 { unwind } => Abi::SysV64 { unwind },
403 ExternAbi::System { unwind } => Abi::System { unwind },
404 _ => Abi::Other(a.to_string()),
405 }
385406 }
386407}
387408
388fn convert_lifetime(l: &clean::Lifetime) -> String {
389 l.0.to_string()
409impl FromClean<clean::Lifetime> for String {
410 fn from_clean(l: &clean::Lifetime, _renderer: &JsonRenderer<'_>) -> String {
411 l.0.to_string()
412 }
390413}
391414
392415impl FromClean<clean::Generics> for Generics {
......@@ -411,16 +434,16 @@ impl FromClean<clean::GenericParamDefKind> for GenericParamDefKind {
411434 fn from_clean(kind: &clean::GenericParamDefKind, renderer: &JsonRenderer<'_>) -> Self {
412435 use clean::GenericParamDefKind::*;
413436 match kind {
414 Lifetime { outlives } => GenericParamDefKind::Lifetime {
415 outlives: outlives.into_iter().map(convert_lifetime).collect(),
416 },
437 Lifetime { outlives } => {
438 GenericParamDefKind::Lifetime { outlives: outlives.into_json(renderer) }
439 }
417440 Type { bounds, default, synthetic } => GenericParamDefKind::Type {
418441 bounds: bounds.into_json(renderer),
419 default: default.as_ref().map(|x| x.as_ref().into_json(renderer)),
442 default: default.into_json(renderer),
420443 is_synthetic: *synthetic,
421444 },
422445 Const { ty, default, synthetic: _ } => GenericParamDefKind::Const {
423 type_: ty.as_ref().into_json(renderer),
446 type_: ty.into_json(renderer),
424447 default: default.as_ref().map(|x| x.as_ref().clone()),
425448 },
426449 }
......@@ -434,45 +457,14 @@ impl FromClean<clean::WherePredicate> for WherePredicate {
434457 BoundPredicate { ty, bounds, bound_params } => WherePredicate::BoundPredicate {
435458 type_: ty.into_json(renderer),
436459 bounds: bounds.into_json(renderer),
437 generic_params: bound_params
438 .iter()
439 .map(|x| {
440 let name = x.name.to_string();
441 let kind = match &x.kind {
442 clean::GenericParamDefKind::Lifetime { outlives } => {
443 GenericParamDefKind::Lifetime {
444 outlives: outlives.iter().map(|lt| lt.0.to_string()).collect(),
445 }
446 }
447 clean::GenericParamDefKind::Type { bounds, default, synthetic } => {
448 GenericParamDefKind::Type {
449 bounds: bounds
450 .into_iter()
451 .map(|bound| bound.into_json(renderer))
452 .collect(),
453 default: default
454 .as_ref()
455 .map(|ty| ty.as_ref().into_json(renderer)),
456 is_synthetic: *synthetic,
457 }
458 }
459 clean::GenericParamDefKind::Const { ty, default, synthetic: _ } => {
460 GenericParamDefKind::Const {
461 type_: ty.as_ref().into_json(renderer),
462 default: default.as_ref().map(|d| d.as_ref().clone()),
463 }
464 }
465 };
466 GenericParamDef { name, kind }
467 })
468 .collect(),
460 generic_params: bound_params.into_json(renderer),
469461 },
470462 RegionPredicate { lifetime, bounds } => WherePredicate::LifetimePredicate {
471 lifetime: convert_lifetime(lifetime),
463 lifetime: lifetime.into_json(renderer),
472464 outlives: bounds
473465 .iter()
474466 .map(|bound| match bound {
475 clean::GenericBound::Outlives(lt) => convert_lifetime(lt),
467 clean::GenericBound::Outlives(lt) => lt.into_json(renderer),
476468 _ => bug!("found non-outlives-bound on lifetime predicate"),
477469 })
478470 .collect(),
......@@ -496,15 +488,15 @@ impl FromClean<clean::GenericBound> for GenericBound {
496488 GenericBound::TraitBound {
497489 trait_: trait_.into_json(renderer),
498490 generic_params: generic_params.into_json(renderer),
499 modifier: from_trait_bound_modifier(modifier),
491 modifier: modifier.into_json(renderer),
500492 }
501493 }
502 Outlives(lifetime) => GenericBound::Outlives(convert_lifetime(lifetime)),
494 Outlives(lifetime) => GenericBound::Outlives(lifetime.into_json(renderer)),
503495 Use(args) => GenericBound::Use(
504496 args.iter()
505497 .map(|arg| match arg {
506498 clean::PreciseCapturingArg::Lifetime(lt) => {
507 PreciseCapturingArg::Lifetime(convert_lifetime(lt))
499 PreciseCapturingArg::Lifetime(lt.into_json(renderer))
508500 }
509501 clean::PreciseCapturingArg::Param(param) => {
510502 PreciseCapturingArg::Param(param.to_string())
......@@ -516,19 +508,22 @@ impl FromClean<clean::GenericBound> for GenericBound {
516508 }
517509}
518510
519pub(crate) fn from_trait_bound_modifier(
520 modifiers: &rustc_hir::TraitBoundModifiers,
521) -> TraitBoundModifier {
522 use rustc_hir as hir;
523 let hir::TraitBoundModifiers { constness, polarity } = modifiers;
524 match (constness, polarity) {
525 (hir::BoundConstness::Never, hir::BoundPolarity::Positive) => TraitBoundModifier::None,
526 (hir::BoundConstness::Never, hir::BoundPolarity::Maybe(_)) => TraitBoundModifier::Maybe,
527 (hir::BoundConstness::Maybe(_), hir::BoundPolarity::Positive) => {
528 TraitBoundModifier::MaybeConst
511impl FromClean<rustc_hir::TraitBoundModifiers> for TraitBoundModifier {
512 fn from_clean(
513 modifiers: &rustc_hir::TraitBoundModifiers,
514 _renderer: &JsonRenderer<'_>,
515 ) -> Self {
516 use rustc_hir as hir;
517 let hir::TraitBoundModifiers { constness, polarity } = modifiers;
518 match (constness, polarity) {
519 (hir::BoundConstness::Never, hir::BoundPolarity::Positive) => TraitBoundModifier::None,
520 (hir::BoundConstness::Never, hir::BoundPolarity::Maybe(_)) => TraitBoundModifier::Maybe,
521 (hir::BoundConstness::Maybe(_), hir::BoundPolarity::Positive) => {
522 TraitBoundModifier::MaybeConst
523 }
524 // FIXME: Fill out the rest of this matrix.
525 _ => TraitBoundModifier::None,
529526 }
530 // FIXME: Fill out the rest of this matrix.
531 _ => TraitBoundModifier::None,
532527 }
533528}
534529
......@@ -542,35 +537,35 @@ impl FromClean<clean::Type> for Type {
542537 match ty {
543538 clean::Type::Path { path } => Type::ResolvedPath(path.into_json(renderer)),
544539 clean::Type::DynTrait(bounds, lt) => Type::DynTrait(DynTrait {
545 lifetime: lt.as_ref().map(convert_lifetime),
540 lifetime: lt.into_json(renderer),
546541 traits: bounds.into_json(renderer),
547542 }),
548543 Generic(s) => Type::Generic(s.to_string()),
549544 // FIXME: add dedicated variant to json Type?
550545 SelfTy => Type::Generic("Self".to_owned()),
551546 Primitive(p) => Type::Primitive(p.as_sym().to_string()),
552 BareFunction(f) => Type::FunctionPointer(Box::new(f.as_ref().into_json(renderer))),
547 BareFunction(f) => Type::FunctionPointer(Box::new(f.into_json(renderer))),
553548 Tuple(t) => Type::Tuple(t.into_json(renderer)),
554 Slice(t) => Type::Slice(Box::new(t.as_ref().into_json(renderer))),
549 Slice(t) => Type::Slice(Box::new(t.into_json(renderer))),
555550 Array(t, s) => {
556 Type::Array { type_: Box::new(t.as_ref().into_json(renderer)), len: s.to_string() }
551 Type::Array { type_: Box::new(t.into_json(renderer)), len: s.to_string() }
557552 }
558553 clean::Type::Pat(t, p) => Type::Pat {
559 type_: Box::new(t.as_ref().into_json(renderer)),
554 type_: Box::new(t.into_json(renderer)),
560555 __pat_unstable_do_not_use: p.to_string(),
561556 },
562557 ImplTrait(g) => Type::ImplTrait(g.into_json(renderer)),
563558 Infer => Type::Infer,
564559 RawPointer(mutability, type_) => Type::RawPointer {
565560 is_mutable: *mutability == ast::Mutability::Mut,
566 type_: Box::new(type_.as_ref().into_json(renderer)),
561 type_: Box::new(type_.into_json(renderer)),
567562 },
568563 BorrowedRef { lifetime, mutability, type_ } => Type::BorrowedRef {
569 lifetime: lifetime.as_ref().map(convert_lifetime),
564 lifetime: lifetime.into_json(renderer),
570565 is_mutable: *mutability == ast::Mutability::Mut,
571 type_: Box::new(type_.as_ref().into_json(renderer)),
566 type_: Box::new(type_.into_json(renderer)),
572567 },
573 QPath(qpath) => qpath.as_ref().into_json(renderer),
568 QPath(qpath) => qpath.into_json(renderer),
574569 // FIXME(unsafe_binder): Implement rustdoc-json.
575570 UnsafeBinder(_) => todo!(),
576571 }
......@@ -578,7 +573,7 @@ impl FromClean<clean::Type> for Type {
578573}
579574
580575impl FromClean<clean::Path> for Path {
581 fn from_clean(path: &clean::Path, renderer: &JsonRenderer<'_>) -> Path {
576 fn from_clean(path: &clean::Path, renderer: &JsonRenderer<'_>) -> Self {
582577 Path {
583578 path: path.whole_name(),
584579 id: renderer.id_from_item_default(path.def_id().into()),
......@@ -608,13 +603,13 @@ impl FromClean<clean::QPathData> for Type {
608603 name: assoc.name.to_string(),
609604 args: assoc.args.into_json(renderer),
610605 self_type: Box::new(self_type.into_json(renderer)),
611 trait_: trait_.as_ref().map(|trait_| trait_.into_json(renderer)),
606 trait_: trait_.into_json(renderer),
612607 }
613608 }
614609}
615610
616611impl FromClean<clean::Term> for Term {
617 fn from_clean(term: &clean::Term, renderer: &JsonRenderer<'_>) -> Term {
612 fn from_clean(term: &clean::Term, renderer: &JsonRenderer<'_>) -> Self {
618613 match term {
619614 clean::Term::Type(ty) => Term::Type(ty.into_json(renderer)),
620615 clean::Term::Constant(c) => Term::Constant(c.into_json(renderer)),
......@@ -630,7 +625,7 @@ impl FromClean<clean::BareFunctionDecl> for FunctionPointer {
630625 is_unsafe: safety.is_unsafe(),
631626 is_const: false,
632627 is_async: false,
633 abi: convert_abi(*abi),
628 abi: abi.into_json(renderer),
634629 },
635630 generic_params: generic_params.into_json(renderer),
636631 sig: decl.into_json(renderer),
......@@ -709,17 +704,17 @@ impl FromClean<clean::Impl> for Impl {
709704 .into_iter()
710705 .map(|x| x.to_string())
711706 .collect(),
712 trait_: trait_.as_ref().map(|path| path.into_json(renderer)),
707 trait_: trait_.into_json(renderer),
713708 for_: for_.into_json(renderer),
714709 items: renderer.ids(&items),
715710 is_negative,
716711 is_synthetic,
717 blanket_impl: blanket_impl.map(|x| x.as_ref().into_json(renderer)),
712 blanket_impl: blanket_impl.map(|x| x.into_json(renderer)),
718713 }
719714 }
720715}
721716
722pub(crate) fn from_function(
717pub(crate) fn from_clean_function(
723718 clean::Function { decl, generics }: &clean::Function,
724719 has_body: bool,
725720 header: rustc_hir::FnHeader,
......@@ -728,7 +723,7 @@ pub(crate) fn from_function(
728723 Function {
729724 sig: decl.into_json(renderer),
730725 generics: generics.into_json(renderer),
731 header: from_fn_header(&header),
726 header: header.into_json(renderer),
732727 has_body,
733728 }
734729}
......@@ -750,7 +745,7 @@ impl FromClean<clean::Variant> for Variant {
750745 fn from_clean(variant: &clean::Variant, renderer: &JsonRenderer<'_>) -> Self {
751746 use clean::VariantKind::*;
752747
753 let discriminant = variant.discriminant.as_ref().map(|d| d.into_json(renderer));
748 let discriminant = variant.discriminant.into_json(renderer);
754749
755750 let kind = match &variant.kind {
756751 CLike => VariantKind::Plain,
......@@ -783,10 +778,7 @@ impl FromClean<clean::Import> for Use {
783778 use clean::ImportKind::*;
784779 let (name, is_glob) = match import.kind {
785780 Simple(s) => (s.to_string(), false),
786 Glob => (
787 import.source.path.last_opt().unwrap_or_else(|| Symbol::intern("*")).to_string(),
788 true,
789 ),
781 Glob => (import.source.path.last_opt().unwrap_or(sym::asterisk).to_string(), true),
790782 };
791783 Use {
792784 source: import.source.path.whole_name(),
......@@ -798,20 +790,22 @@ impl FromClean<clean::Import> for Use {
798790}
799791
800792impl FromClean<clean::ProcMacro> for ProcMacro {
801 fn from_clean(mac: &clean::ProcMacro, _renderer: &JsonRenderer<'_>) -> Self {
793 fn from_clean(mac: &clean::ProcMacro, renderer: &JsonRenderer<'_>) -> Self {
802794 ProcMacro {
803 kind: from_macro_kind(mac.kind),
795 kind: mac.kind.into_json(renderer),
804796 helpers: mac.helpers.iter().map(|x| x.to_string()).collect(),
805797 }
806798 }
807799}
808800
809pub(crate) fn from_macro_kind(kind: rustc_span::hygiene::MacroKind) -> MacroKind {
810 use rustc_span::hygiene::MacroKind::*;
811 match kind {
812 Bang => MacroKind::Bang,
813 Attr => MacroKind::Attr,
814 Derive => MacroKind::Derive,
801impl FromClean<rustc_span::hygiene::MacroKind> for MacroKind {
802 fn from_clean(kind: &rustc_span::hygiene::MacroKind, _renderer: &JsonRenderer<'_>) -> Self {
803 use rustc_span::hygiene::MacroKind::*;
804 match kind {
805 Bang => MacroKind::Bang,
806 Attr => MacroKind::Attr,
807 Derive => MacroKind::Derive,
808 }
815809 }
816810}
817811
......@@ -822,9 +816,9 @@ impl FromClean<clean::TypeAlias> for TypeAlias {
822816 }
823817}
824818
825fn convert_static(
819fn from_clean_static(
826820 stat: &clean::Static,
827 safety: &rustc_hir::Safety,
821 safety: rustc_hir::Safety,
828822 renderer: &JsonRenderer<'_>,
829823) -> Static {
830824 let tcx = renderer.tcx;
src/tools/clippy/clippy_lints/src/doc/doc_suspicious_footnotes.rs+10-3
......@@ -1,4 +1,5 @@
11use clippy_utils::diagnostics::span_lint_and_then;
2use rustc_ast::attr::AttributeExt as _;
23use rustc_ast::token::CommentKind;
34use rustc_errors::Applicability;
45use rustc_hir::{AttrStyle, Attribute};
......@@ -43,13 +44,19 @@ pub fn check(cx: &LateContext<'_>, doc: &str, range: Range<usize>, fragments: &F
4344 "looks like a footnote ref, but has no matching footnote",
4445 |diag| {
4546 if this_fragment.kind == DocFragmentKind::SugaredDoc {
46 let (doc_attr, (_, doc_attr_comment_kind)) = attrs
47 let (doc_attr, (_, doc_attr_comment_kind), attr_style) = attrs
4748 .iter()
4849 .filter(|attr| attr.span().overlaps(this_fragment.span))
4950 .rev()
50 .find_map(|attr| Some((attr, attr.doc_str_and_comment_kind()?)))
51 .find_map(|attr| {
52 Some((
53 attr,
54 attr.doc_str_and_comment_kind()?,
55 attr.doc_resolution_scope()?,
56 ))
57 })
5158 .unwrap();
52 let (to_add, terminator) = match (doc_attr_comment_kind, doc_attr.style()) {
59 let (to_add, terminator) = match (doc_attr_comment_kind, attr_style) {
5360 (CommentKind::Line, AttrStyle::Outer) => ("\n///\n/// ", ""),
5461 (CommentKind::Line, AttrStyle::Inner) => ("\n//!\n//! ", ""),
5562 (CommentKind::Block, AttrStyle::Outer) => ("\n/** ", " */"),
tests/codegen/asm/critical.rs-1
......@@ -1,6 +1,5 @@
11//@ only-x86_64
22//@ compile-flags: -C no-prepopulate-passes
3#![feature(asm_goto)]
43#![feature(asm_goto_with_outputs)]
54#![crate_type = "lib"]
65use std::arch::asm;
tests/run-make/fmt-write-bloat/rmake.rs+2-7
......@@ -15,14 +15,9 @@
1515//! `NO_DEBUG_ASSERTIONS=1`). If debug assertions are disabled, then we can check for the absence of
1616//! additional `usize` formatting and padding related symbols.
1717
18//@ ignore-windows
19// Reason:
20// - MSVC targets really need to parse the .pdb file (aka the debug information).
21// On Windows there's an API for that (dbghelp) which maybe we can use
22// - MinGW targets have a lot of symbols included in their runtime which we can't avoid.
23// We would need to make the symbols we're looking for more specific for this test to work.
2418//@ ignore-cross-compile
2519
20use run_make_support::artifact_names::bin_name;
2621use run_make_support::env::no_debug_assertions;
2722use run_make_support::rustc;
2823use run_make_support::symbols::any_symbol_contains;
......@@ -36,5 +31,5 @@ fn main() {
3631 // otherwise, add them to the list of symbols to deny.
3732 panic_syms.extend_from_slice(&["panicking", "panic_fmt", "pad_integral", "Display"]);
3833 }
39 assert!(!any_symbol_contains("main", &panic_syms));
34 assert!(!any_symbol_contains(bin_name("main"), &panic_syms));
4035}
tests/run-make/textrel-on-minimal-lib/rmake.rs+3-5
......@@ -6,25 +6,23 @@
66// See https://github.com/rust-lang/rust/issues/68794
77
88//@ ignore-cross-compile
9//@ ignore-windows
10// Reason: There is no `bar.dll` produced by CC to run readobj on
119
1210use run_make_support::{
13 cc, dynamic_lib_name, extra_c_flags, extra_cxx_flags, llvm_readobj, rustc, static_lib_name,
11 bin_name, cc, extra_c_flags, extra_cxx_flags, llvm_readobj, rustc, static_lib_name,
1412};
1513
1614fn main() {
1715 rustc().input("foo.rs").run();
1816 cc().input("bar.c")
1917 .input(static_lib_name("foo"))
20 .out_exe(&dynamic_lib_name("bar"))
18 .out_exe(&bin_name("bar"))
2119 .arg("-fPIC")
2220 .arg("-shared")
2321 .args(extra_c_flags())
2422 .args(extra_cxx_flags())
2523 .run();
2624 llvm_readobj()
27 .input(dynamic_lib_name("bar"))
25 .input(bin_name("bar"))
2826 .arg("--dynamic")
2927 .run()
3028 .assert_stdout_not_contains("TEXTREL");
tests/ui/deprecation/deprecated-expr-precedence.rs created+8
......@@ -0,0 +1,8 @@
1//@ check-fail
2//@ compile-flags: --crate-type=lib
3
4// Regression test for issue 142649
5pub fn public() {
6 #[deprecated] 0
7 //~^ ERROR mismatched types
8}
tests/ui/deprecation/deprecated-expr-precedence.stderr created+11
......@@ -0,0 +1,11 @@
1error[E0308]: mismatched types
2 --> $DIR/deprecated-expr-precedence.rs:6:19
3 |
4LL | pub fn public() {
5 | - help: try adding a return type: `-> i32`
6LL | #[deprecated] 0
7 | ^ expected `()`, found integer
8
9error: aborting due to 1 previous error
10
11For more information about this error, try `rustc --explain E0308`.
tests/ui/unpretty/deprecated-attr.rs+5
......@@ -16,3 +16,8 @@ pub struct SinceAndNote;
1616
1717#[deprecated(note = "here's why this is deprecated", since = "1.2.3")]
1818pub struct FlippedOrder;
19
20pub fn f() {
21 // Attribute is ignored here (with a warning), but still preserved in HIR
22 #[deprecated] 0
23}
tests/ui/unpretty/deprecated-attr.stdout+9
......@@ -24,3 +24,12 @@ struct SinceAndNote;
2424#[attr = Deprecation {deprecation: Deprecation {since: NonStandard("1.2.3"),
2525note: "here's why this is deprecated"}}]
2626struct FlippedOrder;
27
28fn f() {
29
30 // Attribute is ignored here (with a warning), but still preserved in HIR
31 #[attr = Deprecation {deprecation:
32 Deprecation {since:
33 Unspecified}}]
34 0
35}
tests/ui/unpretty/diagnostic-attr.stdout+1-3
......@@ -12,6 +12,4 @@ extern crate std;
1212trait ImportantTrait<A> { }
1313
1414#[diagnostic::do_not_recommend]
15impl <T> ImportantTrait<T> for T where T: Clone
16 {#![diagnostic::do_not_recommend]
17}
15impl <T> ImportantTrait<T> for T where T: Clone { }
tests/ui/unpretty/exhaustive-asm.hir.stdout+1-1
......@@ -26,7 +26,7 @@ mod expressions {
2626
2727mod items {
2828 /// ItemKind::GlobalAsm
29 mod item_global_asm {/// ItemKind::GlobalAsm
29 mod item_global_asm {
3030 global_asm! (".globl my_asm_func");
3131 }
3232}
tests/ui/unpretty/exhaustive.hir.stdout+28-41
......@@ -50,20 +50,14 @@ mod prelude {
5050 }
5151}
5252
53//! inner single-line doc comment
54/*!
53/// inner single-line doc comment
54/**
5555 * inner multi-line doc comment
5656 */
5757#[doc = "inner doc attribute"]
5858#[allow(dead_code, unused_variables)]
5959#[no_std]
60mod attributes {//! inner single-line doc comment
61 /*!
62 * inner multi-line doc comment
63 */
64 #![doc = "inner doc attribute"]
65 #![allow(dead_code, unused_variables)]
66 #![no_std]
60mod attributes {
6761
6862 /// outer single-line doc comment
6963 /**
......@@ -413,25 +407,25 @@ mod expressions {
413407}
414408mod items {
415409 /// ItemKind::ExternCrate
416 mod item_extern_crate {/// ItemKind::ExternCrate
410 mod item_extern_crate {
417411 extern crate core;
418412 extern crate self as unpretty;
419413 extern crate core as _;
420414 }
421415 /// ItemKind::Use
422 mod item_use {/// ItemKind::Use
416 mod item_use {
423417 use ::{};
424418 use crate::expressions;
425419 use crate::items::item_use;
426420 use core::*;
427421 }
428422 /// ItemKind::Static
429 mod item_static {/// ItemKind::Static
423 mod item_static {
430424 static A: () = { };
431425 static mut B: () = { };
432426 }
433427 /// ItemKind::Const
434 mod item_const {/// ItemKind::Const
428 mod item_const {
435429 const A: () = { };
436430 trait TraitItems {
437431 const
......@@ -445,7 +439,7 @@ mod items {
445439 }
446440 }
447441 /// ItemKind::Fn
448 mod item_fn {/// ItemKind::Fn
442 mod item_fn {
449443 const unsafe extern "C" fn f() { }
450444 async unsafe extern "C" fn g()
451445 ->
......@@ -460,21 +454,19 @@ mod items {
460454 }
461455 }
462456 /// ItemKind::Mod
463 mod item_mod {/// ItemKind::Mod
464 }
457 mod item_mod { }
465458 /// ItemKind::ForeignMod
466 mod item_foreign_mod {/// ItemKind::ForeignMod
459 mod item_foreign_mod {
467460 extern "Rust" { }
468461 extern "C" { }
469462 }
470463 /// ItemKind::GlobalAsm: see exhaustive-asm.rs
471464 /// ItemKind::TyAlias
472 mod item_ty_alias {/// ItemKind::GlobalAsm: see exhaustive-asm.rs
473 /// ItemKind::TyAlias
465 mod item_ty_alias {
474466 type Type<'a> where T: 'a = T;
475467 }
476468 /// ItemKind::Enum
477 mod item_enum {/// ItemKind::Enum
469 mod item_enum {
478470 enum Void { }
479471 enum Empty {
480472 Unit,
......@@ -490,7 +482,7 @@ mod items {
490482 }
491483 }
492484 /// ItemKind::Struct
493 mod item_struct {/// ItemKind::Struct
485 mod item_struct {
494486 struct Unit;
495487 struct Tuple();
496488 struct Newtype(Unit);
......@@ -501,45 +493,40 @@ mod items {
501493 }
502494 }
503495 /// ItemKind::Union
504 mod item_union {/// ItemKind::Union
496 mod item_union {
505497 union Generic<'a, T> where T: 'a {
506498 t: T,
507499 }
508500 }
509501 /// ItemKind::Trait
510 mod item_trait {/// ItemKind::Trait
502 mod item_trait {
511503 auto unsafe trait Send { }
512504 trait Trait<'a>: Sized where Self: 'a { }
513505 }
514506 /// ItemKind::TraitAlias
515 mod item_trait_alias {/// ItemKind::TraitAlias
507 mod item_trait_alias {
516508 trait Trait<T> = Sized where for<'a> T: 'a;
517509 }
518510 /// ItemKind::Impl
519 mod item_impl {/// ItemKind::Impl
511 mod item_impl {
520512 impl () { }
521513 impl <T> () { }
522514 impl Default for () { }
523515 impl const <T> Default for () { }
524516 }
525517 /// ItemKind::MacCall
526 mod item_mac_call {/// ItemKind::MacCall
527 }
518 mod item_mac_call { }
528519 /// ItemKind::MacroDef
529 mod item_macro_def {/// ItemKind::MacroDef
520 mod item_macro_def {
530521 macro_rules! mac { () => {...}; }
531522 macro stringify { () => {} }
532523 }
533524 /// ItemKind::Delegation
534 /*! FIXME: todo */
535 mod item_delegation {/// ItemKind::Delegation
536 /*! FIXME: todo */
537 }
525 /** FIXME: todo */
526 mod item_delegation { }
538527 /// ItemKind::DelegationMac
539 /*! FIXME: todo */
540 mod item_delegation_mac {/// ItemKind::DelegationMac
541 /*! FIXME: todo */
542 }
528 /** FIXME: todo */
529 mod item_delegation_mac { }
543530}
544531mod patterns {
545532 /// PatKind::Missing
......@@ -690,29 +677,29 @@ mod types {
690677 /// TyKind::Paren
691678 fn ty_paren() { let _: T; }
692679 /// TyKind::Typeof
693 /*! unused for now */
680 /** unused for now */
694681 fn ty_typeof() { }
695682 /// TyKind::Infer
696683 fn ty_infer() { let _: _; }
697684 /// TyKind::ImplicitSelf
698 /*! there is no syntax for this */
685 /** there is no syntax for this */
699686 fn ty_implicit_self() { }
700687 /// TyKind::MacCall
701688 #[expect(deprecated)]
702689 fn ty_mac_call() { let _: T; let _: T; let _: T; }
703690 /// TyKind::CVarArgs
704 /*! FIXME: todo */
691 /** FIXME: todo */
705692 fn ty_c_var_args() { }
706693 /// TyKind::Pat
707694 fn ty_pat() { let _: u32 is 1..=RangeMax; }
708695}
709696mod visibilities {
710697 /// VisibilityKind::Public
711 mod visibility_public {/// VisibilityKind::Public
698 mod visibility_public {
712699 struct Pub;
713700 }
714701 /// VisibilityKind::Restricted
715 mod visibility_restricted {/// VisibilityKind::Restricted
702 mod visibility_restricted {
716703 struct PubCrate;
717704 struct PubSelf;
718705 struct PubSuper;
triagebot.toml+4
......@@ -1023,6 +1023,10 @@ Otherwise, you can ignore this comment.
10231023[mentions."src/tools/x"]
10241024message = "`src/tools/x` was changed. Bump version of Cargo.toml in `src/tools/x` so tidy will suggest installing the new version."
10251025
1026[mentions."src/tools/tidy"]
1027message = "There are changes to the `tidy` tool."
1028cc = ["@jieyouxu"]
1029
10261030[mentions."src/tools/tidy/src/deps.rs"]
10271031message = "The list of allowed third-party dependencies may have been modified! You must ensure that any new dependencies have compatible licenses before merging."
10281032cc = ["@davidtwco", "@wesleywiser"]