authorbors <bors@rust-lang.org> 2026-04-07 19:43:18 UTC
committerbors <bors@rust-lang.org> 2026-04-07 19:43:18 UTC
logc756124775121dea0e640652c5ee3c89e3dd0eb4
treee47fe8ad8ed0c21c2ede138b8ed9389ad0af2102
parentad4b9354009cb6bd5a9ff1b5f5a63a13ec98ebc9
parent2895451ff3f1adc536b4905a0dcd4b02fc936f1f

Auto merge of #154958 - JonathanBrouwer:rollup-PEahluH, r=JonathanBrouwer

Rollup of 22 pull requests Successful merges: - rust-lang/rust#150965 (Fix no results when searching for == in doc) - rust-lang/rust#153999 (Remove `TaggedQueryKey::def_kind`) - rust-lang/rust#154146 (Split out the creation of `Cycle` to a new `process_cycle` function) - rust-lang/rust#154147 (Do not attempt generating DllImport for extern types) - rust-lang/rust#154812 (Update Fira Mono License Information) - rust-lang/rust#154880 (bootstrap: minor improvements to download-rustc) - rust-lang/rust#154886 (Stabilize check-cfg suggestions for symbol) - rust-lang/rust#154889 (Update wasm-component-ld to 0.5.22) - rust-lang/rust#154928 (Fix pin docs) - rust-lang/rust#154942 (delegation: generate more verbose error delegation) - rust-lang/rust#153269 (GCI: During reachability analysis don't try to evaluate the initializer of overly generic free const items) - rust-lang/rust#154506 (Migrate some tests from `tests/ui/issues` to appropriate directories) - rust-lang/rust#154673 (Use a different name for fast try builds) - rust-lang/rust#154761 (coretests: add argument order regression tests for min_by/max_by/minmax_by) - rust-lang/rust#154795 (Add more info about where autodiff can be applied) - rust-lang/rust#154808 (Post-attribute ports cleanup pt. 1) - rust-lang/rust#154825 (constify `Step for NonZero<u*>`) - rust-lang/rust#154837 (library: std: motor: use OS' process::exit in abort_internal) - rust-lang/rust#154866 (add regression test for rust-lang/rust#146514) - rust-lang/rust#154922 (c-b: Export inverse hyperbolic trigonometric functions) - rust-lang/rust#154931 (delegation(small cleanup): remove not needed PhantomData) - rust-lang/rust#154950 (library: no `cfg(target_arch)` on scalable intrinsics)

79 files changed, 1435 insertions(+), 1766 deletions(-)

Cargo.lock+26-26
......@@ -6221,9 +6221,9 @@ dependencies = [
62216221
62226222[[package]]
62236223name = "wasi-preview1-component-adapter-provider"
6224version = "40.0.0"
6224version = "43.0.0"
62256225source = "registry+https://github.com/rust-lang/crates.io-index"
6226checksum = "bb5e2b9858989c3a257de4ca169977f4f79897b64e4f482f188f4fcf8ac557d1"
6226checksum = "93759d6fd0db242718bdcc6e4626eff8b0f3124ee7e58e47177a59f561baf164"
62276227
62286228[[package]]
62296229name = "wasm-bindgen"
......@@ -6272,9 +6272,9 @@ dependencies = [
62726272
62736273[[package]]
62746274name = "wasm-component-ld"
6275version = "0.5.21"
6275version = "0.5.22"
62766276source = "registry+https://github.com/rust-lang/crates.io-index"
6277checksum = "59dcd765f510df84d1677a502c49057761486597a95950b4c92153e5707af091"
6277checksum = "216ca7b603f362831b31db4e2cdea1fa3609edd7177792fa64f62a80e10aa917"
62786278dependencies = [
62796279 "anyhow",
62806280 "clap",
......@@ -6283,7 +6283,7 @@ dependencies = [
62836283 "libc",
62846284 "tempfile",
62856285 "wasi-preview1-component-adapter-provider",
6286 "wasmparser 0.245.1",
6286 "wasmparser 0.246.2",
62876287 "wat",
62886288 "windows-sys 0.61.2",
62896289 "winsplit",
......@@ -6310,24 +6310,24 @@ dependencies = [
63106310
63116311[[package]]
63126312name = "wasm-encoder"
6313version = "0.245.1"
6313version = "0.246.2"
63146314source = "registry+https://github.com/rust-lang/crates.io-index"
6315checksum = "3f9dca005e69bf015e45577e415b9af8c67e8ee3c0e38b5b0add5aa92581ed5c"
6315checksum = "61fb705ce81adde29d2a8e99d87995e39a6e927358c91398f374474746070ef7"
63166316dependencies = [
63176317 "leb128fmt",
6318 "wasmparser 0.245.1",
6318 "wasmparser 0.246.2",
63196319]
63206320
63216321[[package]]
63226322name = "wasm-metadata"
6323version = "0.245.1"
6323version = "0.246.2"
63246324source = "registry+https://github.com/rust-lang/crates.io-index"
6325checksum = "da55e60097e8b37b475a0fa35c3420dd71d9eb7bd66109978ab55faf56a57efb"
6325checksum = "e3e4c2aa916c425dcca61a6887d3e135acdee2c6d0ed51fd61c08d41ddaf62b1"
63266326dependencies = [
63276327 "anyhow",
63286328 "indexmap",
6329 "wasm-encoder 0.245.1",
6330 "wasmparser 0.245.1",
6329 "wasm-encoder 0.246.2",
6330 "wasmparser 0.246.2",
63316331]
63326332
63336333[[package]]
......@@ -6352,9 +6352,9 @@ dependencies = [
63526352
63536353[[package]]
63546354name = "wasmparser"
6355version = "0.245.1"
6355version = "0.246.2"
63566356source = "registry+https://github.com/rust-lang/crates.io-index"
6357checksum = "4f08c9adee0428b7bddf3890fc27e015ac4b761cc608c822667102b8bfd6995e"
6357checksum = "71cde4757396defafd25417cfb36aa3161027d06d865b0c24baaae229aac005d"
63586358dependencies = [
63596359 "bitflags",
63606360 "hashbrown 0.16.1",
......@@ -6365,22 +6365,22 @@ dependencies = [
63656365
63666366[[package]]
63676367name = "wast"
6368version = "245.0.1"
6368version = "246.0.2"
63696369source = "registry+https://github.com/rust-lang/crates.io-index"
6370checksum = "28cf1149285569120b8ce39db8b465e8a2b55c34cbb586bd977e43e2bc7300bf"
6370checksum = "fe3fe8e3bf88ad96d031b4181ddbd64634b17cb0d06dfc3de589ef43591a9a62"
63716371dependencies = [
63726372 "bumpalo",
63736373 "leb128fmt",
63746374 "memchr",
63756375 "unicode-width 0.2.2",
6376 "wasm-encoder 0.245.1",
6376 "wasm-encoder 0.246.2",
63776377]
63786378
63796379[[package]]
63806380name = "wat"
6381version = "1.245.1"
6381version = "1.246.2"
63826382source = "registry+https://github.com/rust-lang/crates.io-index"
6383checksum = "cd48d1679b6858988cb96b154dda0ec5bbb09275b71db46057be37332d5477be"
6383checksum = "4bd7fda1199b94fff395c2d19a153f05dbe7807630316fa9673367666fd2ad8c"
63846384dependencies = [
63856385 "wast",
63866386]
......@@ -6811,9 +6811,9 @@ dependencies = [
68116811
68126812[[package]]
68136813name = "wit-component"
6814version = "0.245.1"
6814version = "0.246.2"
68156815source = "registry+https://github.com/rust-lang/crates.io-index"
6816checksum = "4894f10d2d5cbc17c77e91f86a1e48e191a788da4425293b55c98b44ba3fcac9"
6816checksum = "1936c26cb24b93dc36bf78fb5dc35c55cd37f66ecdc2d2663a717d9fb3ee951e"
68176817dependencies = [
68186818 "anyhow",
68196819 "bitflags",
......@@ -6822,17 +6822,17 @@ dependencies = [
68226822 "serde",
68236823 "serde_derive",
68246824 "serde_json",
6825 "wasm-encoder 0.245.1",
6825 "wasm-encoder 0.246.2",
68266826 "wasm-metadata",
6827 "wasmparser 0.245.1",
6827 "wasmparser 0.246.2",
68286828 "wit-parser",
68296829]
68306830
68316831[[package]]
68326832name = "wit-parser"
6833version = "0.245.1"
6833version = "0.246.2"
68346834source = "registry+https://github.com/rust-lang/crates.io-index"
6835checksum = "330698718e82983499419494dd1e3d7811a457a9bf9f69734e8c5f07a2547929"
6835checksum = "fd979042b5ff288607ccf3b314145435453f20fc67173195f91062d2289b204d"
68366836dependencies = [
68376837 "anyhow",
68386838 "hashbrown 0.16.1",
......@@ -6844,7 +6844,7 @@ dependencies = [
68446844 "serde_derive",
68456845 "serde_json",
68466846 "unicode-xid",
6847 "wasmparser 0.245.1",
6847 "wasmparser 0.246.2",
68486848]
68496849
68506850[[package]]
compiler/rustc_ast_lowering/src/delegation.rs+34-41
......@@ -37,7 +37,6 @@
3737//! also be emitted during HIR ty lowering.
3838
3939use std::iter;
40use std::marker::PhantomData;
4140
4241use ast::visit::Visitor;
4342use hir::def::{DefKind, PartialRes, Res};
......@@ -128,14 +127,12 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
128127 {
129128 self.get_sig_id(delegation_info.resolution_node, span)
130129 } else {
131 return self.generate_delegation_error(
132 self.dcx().span_delayed_bug(
133 span,
134 format!("LoweringContext: the delegation {:?} is unresolved", item_id),
135 ),
130 self.dcx().span_delayed_bug(
136131 span,
137 delegation,
132 format!("LoweringContext: the delegation {:?} is unresolved", item_id),
138133 );
134
135 return self.generate_delegation_error(span, delegation);
139136 };
140137
141138 match sig_id {
......@@ -172,7 +169,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
172169
173170 DelegationResults { body_id, sig, ident, generics }
174171 }
175 Err(err) => self.generate_delegation_error(err, span, delegation),
172 Err(_) => self.generate_delegation_error(span, delegation),
176173 }
177174 }
178175
......@@ -420,7 +417,6 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
420417 resolver: this.resolver,
421418 path_id: delegation.id,
422419 self_param_id: pat_node_id,
423 phantom: PhantomData,
424420 };
425421 self_resolver.visit_block(block);
426422 // Target expr needs to lower `self` path.
......@@ -604,7 +600,6 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
604600
605601 fn generate_delegation_error(
606602 &mut self,
607 err: ErrorGuaranteed,
608603 span: Span,
609604 delegation: &Delegation,
610605 ) -> DelegationResults<'hir> {
......@@ -622,36 +617,35 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
622617 let ident = self.lower_ident(delegation.ident);
623618
624619 let body_id = self.lower_body(|this| {
625 let body_expr = match delegation.body.as_ref() {
626 Some(box block) => {
627 // Generates a block when we failed to resolve delegation, where a target expression is its only statement,
628 // thus there will be no ICEs on further stages of analysis (see #144594)
629
630 // As we generate a void function we want to convert target expression to statement to avoid additional
631 // errors, such as mismatched return type
632 let stmts = this.arena.alloc_from_iter([hir::Stmt {
633 hir_id: this.next_id(),
634 kind: rustc_hir::StmtKind::Semi(
635 this.arena.alloc(this.lower_target_expr(block)),
636 ),
637 span,
638 }]);
639
640 let block = this.arena.alloc(hir::Block {
641 stmts,
642 expr: None,
643 hir_id: this.next_id(),
644 rules: hir::BlockCheckMode::DefaultBlock,
645 span,
646 targeted_by_break: false,
647 });
620 let path = this.lower_qpath(
621 delegation.id,
622 &delegation.qself,
623 &delegation.path,
624 ParamMode::Optional,
625 AllowReturnTypeNotation::No,
626 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
627 None,
628 );
648629
649 hir::ExprKind::Block(block, None)
650 }
651 None => hir::ExprKind::Err(err),
630 let callee_path = this.arena.alloc(this.mk_expr(hir::ExprKind::Path(path), span));
631 let args = if let Some(box block) = delegation.body.as_ref() {
632 this.arena.alloc_slice(&[this.lower_target_expr(block)])
633 } else {
634 &mut []
652635 };
653636
654 (&[], this.mk_expr(body_expr, span))
637 let call = this.arena.alloc(this.mk_expr(hir::ExprKind::Call(callee_path, args), span));
638
639 let block = this.arena.alloc(hir::Block {
640 stmts: &[],
641 expr: Some(call),
642 hir_id: this.next_id(),
643 rules: hir::BlockCheckMode::DefaultBlock,
644 span,
645 targeted_by_break: false,
646 });
647
648 (&[], this.mk_expr(hir::ExprKind::Block(block, None), span))
655649 });
656650
657651 let generics = hir::Generics::empty();
......@@ -673,14 +667,13 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
673667 }
674668}
675669
676struct SelfResolver<'a, 'tcx, R> {
670struct SelfResolver<'a, R> {
677671 resolver: &'a mut R,
678672 path_id: NodeId,
679673 self_param_id: NodeId,
680 phantom: PhantomData<&'tcx ()>,
681674}
682675
683impl<'tcx, R: ResolverAstLoweringExt<'tcx>> SelfResolver<'_, 'tcx, R> {
676impl<'tcx, R: ResolverAstLoweringExt<'tcx>> SelfResolver<'_, R> {
684677 fn try_replace_id(&mut self, id: NodeId) {
685678 if let Some(res) = self.resolver.get_partial_res(id)
686679 && let Some(Res::Local(sig_id)) = res.full_res()
......@@ -692,7 +685,7 @@ impl<'tcx, R: ResolverAstLoweringExt<'tcx>> SelfResolver<'_, 'tcx, R> {
692685 }
693686}
694687
695impl<'ast, 'a, 'tcx, R: ResolverAstLoweringExt<'tcx>> Visitor<'ast> for SelfResolver<'a, 'tcx, R> {
688impl<'ast, 'tcx, R: ResolverAstLoweringExt<'tcx>> Visitor<'ast> for SelfResolver<'_, R> {
696689 fn visit_id(&mut self, id: NodeId) {
697690 self.try_replace_id(id);
698691 }
compiler/rustc_attr_parsing/src/validate_attr.rs+14-47
......@@ -1,15 +1,14 @@
11//! Meta-syntax validation logic of attributes for post-expansion.
22
33use std::convert::identity;
4use std::slice;
54
65use rustc_ast::token::Delimiter;
76use rustc_ast::tokenstream::DelimSpan;
87use rustc_ast::{
98 self as ast, AttrArgs, Attribute, DelimArgs, MetaItem, MetaItemInner, MetaItemKind, Safety,
109};
11use rustc_errors::{Applicability, FatalError, PResult};
12use rustc_feature::{AttributeTemplate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute};
10use rustc_errors::{Applicability, PResult};
11use rustc_feature::{AttributeTemplate, BUILTIN_ATTRIBUTE_MAP};
1312use rustc_hir::AttrPath;
1413use rustc_hir::lints::AttributeLintKind;
1514use rustc_parse::parse_in;
......@@ -19,43 +18,23 @@ use rustc_session::lint::builtin::ILL_FORMED_ATTRIBUTE_INPUT;
1918use rustc_session::parse::ParseSess;
2019use rustc_span::{Span, Symbol, sym};
2120
22use crate::{AttributeParser, Late, session_diagnostics as errors};
21use crate::session_diagnostics as errors;
2322
2423pub fn check_attr(psess: &ParseSess, attr: &Attribute) {
25 if attr.is_doc_comment() || attr.has_name(sym::cfg_trace) || attr.has_name(sym::cfg_attr_trace)
24 // Built-in attributes are parsed in their respective attribute parsers, so can be ignored here
25 if attr.is_doc_comment()
26 || attr.name().is_some_and(|name| BUILTIN_ATTRIBUTE_MAP.contains_key(&name))
2627 {
2728 return;
2829 }
2930
30 let builtin_attr_info = attr.name().and_then(|name| BUILTIN_ATTRIBUTE_MAP.get(&name));
31
32 // Check input tokens for built-in and key-value attributes.
33 match builtin_attr_info {
34 // `rustc_dummy` doesn't have any restrictions specific to built-in attributes.
35 Some(BuiltinAttribute { name, template, .. }) => {
36 if AttributeParser::<Late>::is_parsed_attribute(slice::from_ref(&name)) {
37 return;
38 }
39 match parse_meta(psess, attr) {
40 // Don't check safety again, we just did that
41 Ok(meta) => {
42 check_builtin_meta_item(psess, &meta, attr.style, *name, *template, false)
43 }
44 Err(err) => {
45 err.emit();
46 }
47 }
48 }
49 _ => {
50 let attr_item = attr.get_normal_item();
51 if let AttrArgs::Eq { .. } = attr_item.args.unparsed_ref().unwrap() {
52 // All key-value attributes are restricted to meta-item syntax.
53 match parse_meta(psess, attr) {
54 Ok(_) => {}
55 Err(err) => {
56 err.emit();
57 }
58 }
31 let attr_item = attr.get_normal_item();
32 if let AttrArgs::Eq { .. } = attr_item.args.unparsed_ref().unwrap() {
33 // All key-value attributes are restricted to meta-item syntax.
34 match parse_meta(psess, attr) {
35 Ok(_) => {}
36 Err(err) => {
37 err.emit();
5938 }
6039 }
6140 }
......@@ -170,7 +149,7 @@ pub fn check_builtin_meta_item(
170149 }
171150}
172151
173fn emit_malformed_attribute(
152pub fn emit_malformed_attribute(
174153 psess: &ParseSess,
175154 style: ast::AttrStyle,
176155 span: Span,
......@@ -232,15 +211,3 @@ fn emit_malformed_attribute(
232211 err.emit();
233212 }
234213}
235
236pub fn emit_fatal_malformed_builtin_attribute(
237 psess: &ParseSess,
238 attr: &Attribute,
239 name: Symbol,
240) -> ! {
241 let template = BUILTIN_ATTRIBUTE_MAP.get(&name).expect("builtin attr defined").template;
242 emit_malformed_attribute(psess, attr.style, attr.span, name, template);
243 // This is fatal, otherwise it will likely cause a cascade of other errors
244 // (and an error here is expected to be very rare).
245 FatalError.raise()
246}
compiler/rustc_expand/src/errors.rs-18
......@@ -603,21 +603,3 @@ pub(crate) struct TrailingMacro {
603603 pub is_trailing: bool,
604604 pub name: Ident,
605605}
606
607#[derive(Diagnostic)]
608#[diag("unused attribute `{$attr_name}`")]
609pub(crate) struct UnusedBuiltinAttribute {
610 #[note(
611 "the built-in attribute `{$attr_name}` will be ignored, since it's applied to the macro invocation `{$macro_name}`"
612 )]
613 pub invoc_span: Span,
614 pub attr_name: Symbol,
615 pub macro_name: String,
616 #[suggestion(
617 "remove the attribute",
618 code = "",
619 applicability = "machine-applicable",
620 style = "tool-only"
621 )]
622 pub attr_span: Span,
623}
compiler/rustc_expand/src/expand.rs+3-18
......@@ -15,8 +15,8 @@ use rustc_ast::{
1515use rustc_ast_pretty::pprust;
1616use rustc_attr_parsing::parser::AllowExprMetavar;
1717use rustc_attr_parsing::{
18 AttributeParser, CFG_TEMPLATE, Early, EvalConfigResult, ShouldEmit, eval_config_entry,
19 parse_cfg, validate_attr,
18 AttributeParser, CFG_TEMPLATE, EvalConfigResult, ShouldEmit, eval_config_entry, parse_cfg,
19 validate_attr,
2020};
2121use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
2222use rustc_data_structures::stack::ensure_sufficient_stack;
......@@ -30,7 +30,7 @@ use rustc_parse::parser::{
3030 RecoverColon, RecoverComma, Recovery, token_descr,
3131};
3232use rustc_session::Session;
33use rustc_session::lint::builtin::{UNUSED_ATTRIBUTES, UNUSED_DOC_COMMENTS};
33use rustc_session::lint::builtin::UNUSED_DOC_COMMENTS;
3434use rustc_session::parse::feature_err;
3535use rustc_span::hygiene::SyntaxContext;
3636use rustc_span::{ErrorGuaranteed, FileName, Ident, LocalExpnId, Span, Symbol, sym};
......@@ -2274,21 +2274,6 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
22742274 self.cx.current_expansion.lint_node_id,
22752275 crate::errors::MacroCallUnusedDocComment { span: attr.span },
22762276 );
2277 } else if rustc_attr_parsing::is_builtin_attr(attr)
2278 && !AttributeParser::<Early>::is_parsed_attribute(&attr.path())
2279 {
2280 let attr_name = attr.name().unwrap();
2281 self.cx.sess.psess.buffer_lint(
2282 UNUSED_ATTRIBUTES,
2283 attr.span,
2284 self.cx.current_expansion.lint_node_id,
2285 crate::errors::UnusedBuiltinAttribute {
2286 attr_name,
2287 macro_name: pprust::path_to_string(&call.path),
2288 invoc_span: call.path.span,
2289 attr_span: attr.span,
2290 },
2291 );
22922277 }
22932278 }
22942279 }
compiler/rustc_expand/src/module.rs+15-2
......@@ -2,12 +2,14 @@ use std::iter::once;
22use std::path::{self, Path, PathBuf};
33
44use rustc_ast::{AttrVec, Attribute, Inline, Item, ModSpans};
5use rustc_attr_parsing::validate_attr;
5use rustc_attr_parsing::validate_attr::emit_malformed_attribute;
66use rustc_errors::{Diag, ErrorGuaranteed};
7use rustc_feature::template;
78use rustc_parse::lexer::StripTokens;
89use rustc_parse::{exp, new_parser_from_file, unwrap_or_emit_fatal};
910use rustc_session::Session;
1011use rustc_session::parse::ParseSess;
12use rustc_span::fatal_error::FatalError;
1113use rustc_span::{Ident, Span, sym};
1214use thin_vec::ThinVec;
1315
......@@ -184,6 +186,7 @@ pub(crate) fn mod_file_path_from_attr(
184186 attrs: &[Attribute],
185187 dir_path: &Path,
186188) -> Option<PathBuf> {
189 // FIXME(154781) use a parsed attribute here
187190 // Extract path string from first `#[path = "path_string"]` attribute.
188191 let first_path = attrs.iter().find(|at| at.has_name(sym::path))?;
189192 let Some(path_sym) = first_path.value_str() else {
......@@ -195,7 +198,17 @@ pub(crate) fn mod_file_path_from_attr(
195198 // Usually bad forms are checked during semantic analysis via
196199 // `TyCtxt::check_mod_attrs`), but by the time that runs the macro
197200 // is expanded, and it doesn't give an error.
198 validate_attr::emit_fatal_malformed_builtin_attribute(&sess.psess, first_path, sym::path);
201 emit_malformed_attribute(
202 &sess.psess,
203 first_path.style,
204 first_path.span,
205 sym::path,
206 template!(
207 NameValueStr: "file",
208 "https://doc.rust-lang.org/reference/items/modules.html#the-path-attribute"
209 ),
210 );
211 FatalError.raise()
199212 };
200213
201214 let path_str = path_sym.as_str();
compiler/rustc_feature/src/builtin_attrs.rs+231-1005
......@@ -2,12 +2,9 @@
22
33use std::sync::LazyLock;
44
5use AttributeDuplicates::*;
65use AttributeGate::*;
7use AttributeType::*;
86use rustc_data_structures::fx::FxHashMap;
97use rustc_hir::AttrStyle;
10use rustc_hir::attrs::EncodeCrossCrate;
118use rustc_span::edition::Edition;
129use rustc_span::{Symbol, sym};
1310
......@@ -73,21 +70,10 @@ pub fn find_gated_cfg(pred: impl Fn(Symbol) -> bool) -> Option<&'static GatedCfg
7370// move that documentation into the relevant place in the other docs, and
7471// remove the chapter on the flag.
7572
76#[derive(Copy, Clone, PartialEq, Debug)]
77pub enum AttributeType {
78 /// Normal, builtin attribute that is consumed
79 /// by the compiler before the unused_attribute check
80 Normal,
81
82 /// Builtin attribute that is only allowed at the crate level
83 CrateLevel,
84}
85
8673#[derive(Copy, Clone, PartialEq, Debug)]
8774pub enum AttributeSafety {
8875 /// Normal attribute that does not need `#[unsafe(...)]`
8976 Normal,
90
9177 /// Unsafe attribute that requires safety obligations to be discharged.
9278 ///
9379 /// An error is emitted when `#[unsafe(...)]` is omitted, except when the attribute's edition
......@@ -181,57 +167,6 @@ impl AttributeTemplate {
181167 }
182168}
183169
184/// How to handle multiple duplicate attributes on the same item.
185#[derive(Clone, Copy, Default)]
186pub enum AttributeDuplicates {
187 /// Duplicates of this attribute are allowed.
188 ///
189 /// This should only be used with attributes where duplicates have semantic
190 /// meaning, or some kind of "additive" behavior. For example, `#[warn(..)]`
191 /// can be specified multiple times, and it combines all the entries. Or use
192 /// this if there is validation done elsewhere.
193 #[default]
194 DuplicatesOk,
195 /// Duplicates after the first attribute will be an unused_attribute warning.
196 ///
197 /// This is usually used for "word" attributes, where they are used as a
198 /// boolean marker, like `#[used]`. It is not necessarily wrong that there
199 /// are duplicates, but the others should probably be removed.
200 WarnFollowing,
201 /// Same as `WarnFollowing`, but only issues warnings for word-style attributes.
202 ///
203 /// This is only for special cases, for example multiple `#[macro_use]` can
204 /// be warned, but multiple `#[macro_use(...)]` should not because the list
205 /// form has different meaning from the word form.
206 WarnFollowingWordOnly,
207 /// Duplicates after the first attribute will be an error.
208 ///
209 /// This should be used where duplicates would be ignored, but carry extra
210 /// meaning that could cause confusion. For example, `#[stable(since="1.0")]
211 /// #[stable(since="2.0")]`, which version should be used for `stable`?
212 ErrorFollowing,
213 /// Duplicates preceding the last instance of the attribute will be an error.
214 ///
215 /// This is the same as `ErrorFollowing`, except the last attribute is the
216 /// one that is "used". This is typically used in cases like codegen
217 /// attributes which usually only honor the last attribute.
218 ErrorPreceding,
219 /// Duplicates after the first attribute will be an unused_attribute warning
220 /// with a note that this will be an error in the future.
221 ///
222 /// This should be used for attributes that should be `ErrorFollowing`, but
223 /// because older versions of rustc silently accepted (and ignored) the
224 /// attributes, this is used to transition.
225 FutureWarnFollowing,
226 /// Duplicates preceding the last instance of the attribute will be a
227 /// warning, with a note that this will be an error in the future.
228 ///
229 /// This is the same as `FutureWarnFollowing`, except the last attribute is
230 /// the one that is "used". Ideally these can eventually migrate to
231 /// `ErrorPreceding`.
232 FutureWarnPreceding,
233}
234
235170/// A convenience macro for constructing attribute templates.
236171/// E.g., `template!(Word, List: "description")` means that the attribute
237172/// supports forms `#[attr]` and `#[attr(description)]`.
......@@ -268,50 +203,31 @@ macro_rules! template {
268203}
269204
270205macro_rules! ungated {
271 (unsafe($edition:ident) $attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr $(,)?) => {
206 (unsafe($edition:ident) $attr:ident $(,)?) => {
272207 BuiltinAttribute {
273208 name: sym::$attr,
274 encode_cross_crate: $encode_cross_crate,
275 type_: $typ,
276209 safety: AttributeSafety::Unsafe { unsafe_since: Some(Edition::$edition) },
277 template: $tpl,
278210 gate: Ungated,
279 duplicates: $duplicates,
280211 }
281212 };
282 (unsafe $attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr $(,)?) => {
213 (unsafe $attr:ident $(,)?) => {
283214 BuiltinAttribute {
284215 name: sym::$attr,
285 encode_cross_crate: $encode_cross_crate,
286 type_: $typ,
287216 safety: AttributeSafety::Unsafe { unsafe_since: None },
288 template: $tpl,
289217 gate: Ungated,
290 duplicates: $duplicates,
291218 }
292219 };
293 ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr $(,)?) => {
294 BuiltinAttribute {
295 name: sym::$attr,
296 encode_cross_crate: $encode_cross_crate,
297 type_: $typ,
298 safety: AttributeSafety::Normal,
299 template: $tpl,
300 gate: Ungated,
301 duplicates: $duplicates,
302 }
220 ($attr:ident $(,)?) => {
221 BuiltinAttribute { name: sym::$attr, safety: AttributeSafety::Normal, gate: Ungated }
303222 };
304223}
305224
306225macro_rules! gated {
307 (unsafe $attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr, $gate:ident, $message:expr $(,)?) => {
226 (unsafe $attr:ident, $gate:ident, $message:expr $(,)?) => {
308227 BuiltinAttribute {
309228 name: sym::$attr,
310 encode_cross_crate: $encode_cross_crate,
311 type_: $typ,
312229 safety: AttributeSafety::Unsafe { unsafe_since: None },
313 template: $tpl,
314 duplicates: $duplicates,
230
315231 gate: Gated {
316232 feature: sym::$gate,
317233 message: $message,
......@@ -320,14 +236,11 @@ macro_rules! gated {
320236 },
321237 }
322238 };
323 (unsafe $attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr, $message:expr $(,)?) => {
239 (unsafe $attr:ident, $message:expr $(,)?) => {
324240 BuiltinAttribute {
325241 name: sym::$attr,
326 encode_cross_crate: $encode_cross_crate,
327 type_: $typ,
328242 safety: AttributeSafety::Unsafe { unsafe_since: None },
329 template: $tpl,
330 duplicates: $duplicates,
243
331244 gate: Gated {
332245 feature: sym::$attr,
333246 message: $message,
......@@ -336,14 +249,11 @@ macro_rules! gated {
336249 },
337250 }
338251 };
339 ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr, $gate:ident, $message:expr $(,)?) => {
252 ($attr:ident, $gate:ident, $message:expr $(,)?) => {
340253 BuiltinAttribute {
341254 name: sym::$attr,
342 encode_cross_crate: $encode_cross_crate,
343 type_: $typ,
344255 safety: AttributeSafety::Normal,
345 template: $tpl,
346 duplicates: $duplicates,
256
347257 gate: Gated {
348258 feature: sym::$gate,
349259 message: $message,
......@@ -352,14 +262,11 @@ macro_rules! gated {
352262 },
353263 }
354264 };
355 ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr, $message:expr $(,)?) => {
265 ($attr:ident, $message:expr $(,)?) => {
356266 BuiltinAttribute {
357267 name: sym::$attr,
358 encode_cross_crate: $encode_cross_crate,
359 type_: $typ,
360268 safety: AttributeSafety::Normal,
361 template: $tpl,
362 duplicates: $duplicates,
269
363270 gate: Gated {
364271 feature: sym::$attr,
365272 message: $message,
......@@ -371,13 +278,8 @@ macro_rules! gated {
371278}
372279
373280macro_rules! rustc_attr {
374 (TEST, $attr:ident, $typ:expr, $tpl:expr, $duplicate:expr, $encode_cross_crate:expr $(,)?) => {
375 rustc_attr!(
376 $attr,
377 $typ,
378 $tpl,
379 $duplicate,
380 $encode_cross_crate,
281 (TEST, $attr:ident $(,)?) => {
282 rustc_attr!( $attr,
381283 concat!(
382284 "the `#[",
383285 stringify!($attr),
......@@ -385,14 +287,10 @@ macro_rules! rustc_attr {
385287 ),
386288 )
387289 };
388 ($attr:ident, $typ:expr, $tpl:expr, $duplicates:expr, $encode_cross_crate:expr, $($notes:expr),* $(,)?) => {
290 ($attr:ident $(, $notes:expr)* $(,)?) => {
389291 BuiltinAttribute {
390292 name: sym::$attr,
391 encode_cross_crate: $encode_cross_crate,
392 type_: $typ,
393293 safety: AttributeSafety::Normal,
394 template: $tpl,
395 duplicates: $duplicates,
396294 gate: Gated {
397295 feature: sym::rustc_attrs,
398296 message: "use of an internal attribute",
......@@ -416,15 +314,7 @@ macro_rules! experimental {
416314
417315pub struct BuiltinAttribute {
418316 pub name: Symbol,
419 /// Whether this attribute is encode cross crate.
420 ///
421 /// If so, it is encoded in the crate metadata.
422 /// Otherwise, it can only be used in the local crate.
423 pub encode_cross_crate: EncodeCrossCrate,
424 pub type_: AttributeType,
425317 pub safety: AttributeSafety,
426 pub template: AttributeTemplate,
427 pub duplicates: AttributeDuplicates,
428318 pub gate: AttributeGate,
429319}
430320
......@@ -436,379 +326,100 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
436326 // ==========================================================================
437327
438328 // Conditional compilation:
439 ungated!(
440 cfg, Normal,
441 template!(
442 List: &["predicate"],
443 "https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute"
444 ),
445 DuplicatesOk, EncodeCrossCrate::No
446 ),
447 ungated!(
448 cfg_attr, Normal,
449 template!(
450 List: &["predicate, attr1, attr2, ..."],
451 "https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute"
452 ),
453 DuplicatesOk, EncodeCrossCrate::No
454 ),
329 ungated!(cfg),
330 ungated!(cfg_attr),
455331
456332 // Testing:
457 ungated!(
458 ignore, Normal,
459 template!(
460 Word,
461 NameValueStr: "reason",
462 "https://doc.rust-lang.org/reference/attributes/testing.html#the-ignore-attribute"
463 ),
464 WarnFollowing, EncodeCrossCrate::No,
465 ),
466 ungated!(
467 should_panic, Normal,
468 template!(
469 Word,
470 List: &[r#"expected = "reason""#],
471 NameValueStr: "reason",
472 "https://doc.rust-lang.org/reference/attributes/testing.html#the-should_panic-attribute"
473 ),
474 FutureWarnFollowing, EncodeCrossCrate::No,
475 ),
333 ungated!(ignore),
334 ungated!(should_panic),
476335
477336 // Macros:
478 ungated!(
479 automatically_derived, Normal,
480 template!(
481 Word,
482 "https://doc.rust-lang.org/reference/attributes/derive.html#the-automatically_derived-attribute"
483 ),
484 WarnFollowing, EncodeCrossCrate::Yes
485 ),
486 ungated!(
487 macro_use, Normal,
488 template!(
489 Word,
490 List: &["name1, name2, ..."],
491 "https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute"
492 ),
493 WarnFollowingWordOnly, EncodeCrossCrate::No,
494 ),
495 ungated!(macro_escape, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No), // Deprecated synonym for `macro_use`.
496 ungated!(
497 macro_export, Normal,
498 template!(
499 Word,
500 List: &["local_inner_macros"],
501 "https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope"
502 ),
503 WarnFollowing, EncodeCrossCrate::Yes
504 ),
505 ungated!(
506 proc_macro, Normal,
507 template!(
508 Word,
509 "https://doc.rust-lang.org/reference/procedural-macros.html#function-like-procedural-macros"),
510 ErrorFollowing, EncodeCrossCrate::No
511 ),
512 ungated!(
513 proc_macro_derive, Normal,
514 template!(
515 List: &["TraitName", "TraitName, attributes(name1, name2, ...)"],
516 "https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros"
517 ),
518 ErrorFollowing, EncodeCrossCrate::No,
519 ),
520 ungated!(
521 proc_macro_attribute, Normal,
522 template!(Word, "https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros"),
523 ErrorFollowing, EncodeCrossCrate::No
524 ),
337 ungated!(automatically_derived),
338 ungated!(macro_use),
339 ungated!(macro_escape), // Deprecated synonym for `macro_use`.
340 ungated!(macro_export),
341 ungated!(proc_macro),
342 ungated!(proc_macro_derive),
343 ungated!(proc_macro_attribute),
525344
526345 // Lints:
527 ungated!(
528 warn, Normal,
529 template!(
530 List: &["lint1", "lint1, lint2, ...", r#"lint1, lint2, lint3, reason = "...""#],
531 "https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes"
532 ),
533 DuplicatesOk, EncodeCrossCrate::No,
534 ),
535 ungated!(
536 allow, Normal,
537 template!(
538 List: &["lint1", "lint1, lint2, ...", r#"lint1, lint2, lint3, reason = "...""#],
539 "https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes"
540 ),
541 DuplicatesOk, EncodeCrossCrate::No,
542 ),
543 ungated!(
544 expect, Normal,
545 template!(
546 List: &["lint1", "lint1, lint2, ...", r#"lint1, lint2, lint3, reason = "...""#],
547 "https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes"
548 ),
549 DuplicatesOk, EncodeCrossCrate::No,
550 ),
551 ungated!(
552 forbid, Normal,
553 template!(
554 List: &["lint1", "lint1, lint2, ...", r#"lint1, lint2, lint3, reason = "...""#],
555 "https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes"
556 ),
557 DuplicatesOk, EncodeCrossCrate::No
558 ),
559 ungated!(
560 deny, Normal,
561 template!(
562 List: &["lint1", "lint1, lint2, ...", r#"lint1, lint2, lint3, reason = "...""#],
563 "https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes"
564 ),
565 DuplicatesOk, EncodeCrossCrate::No
566 ),
567 ungated!(
568 must_use, Normal,
569 template!(
570 Word,
571 NameValueStr: "reason",
572 "https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute"
573 ),
574 FutureWarnFollowing, EncodeCrossCrate::Yes
575 ),
576 gated!(
577 must_not_suspend, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing,
578 EncodeCrossCrate::Yes, experimental!(must_not_suspend)
579 ),
580 ungated!(
581 deprecated, Normal,
582 template!(
583 Word,
584 List: &[r#"/*opt*/ since = "version", /*opt*/ note = "reason""#],
585 NameValueStr: "reason",
586 "https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute"
587 ),
588 ErrorFollowing, EncodeCrossCrate::Yes
589 ),
346 ungated!(warn),
347 ungated!(allow),
348 ungated!(expect),
349 ungated!(forbid),
350 ungated!(deny),
351 ungated!(must_use),
352 gated!(must_not_suspend, experimental!(must_not_suspend)),
353 ungated!(deprecated),
590354
591355 // Crate properties:
592 ungated!(
593 crate_name, CrateLevel,
594 template!(
595 NameValueStr: "name",
596 "https://doc.rust-lang.org/reference/crates-and-source-files.html#the-crate_name-attribute"
597 ),
598 FutureWarnFollowing, EncodeCrossCrate::No,
599 ),
600 ungated!(
601 crate_type, CrateLevel,
602 template!(
603 NameValueStr: ["bin", "lib", "dylib", "cdylib", "rlib", "staticlib", "sdylib", "proc-macro"],
604 "https://doc.rust-lang.org/reference/linkage.html"
605 ),
606 DuplicatesOk, EncodeCrossCrate::No,
607 ),
356 ungated!(crate_name),
357 ungated!(crate_type),
608358
609359 // ABI, linking, symbols, and FFI
610 ungated!(
611 link, Normal,
612 template!(List: &[
613 r#"name = "...""#,
614 r#"name = "...", kind = "dylib|static|...""#,
615 r#"name = "...", wasm_import_module = "...""#,
616 r#"name = "...", import_name_type = "decorated|noprefix|undecorated""#,
617 r#"name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated""#,
618 ], "https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute"),
619 DuplicatesOk, EncodeCrossCrate::No,
620 ),
621 ungated!(
622 link_name, Normal,
623 template!(NameValueStr: "name", "https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_name-attribute"),
624 FutureWarnPreceding, EncodeCrossCrate::Yes
625 ),
626 ungated!(
627 no_link, Normal,
628 template!(Word, "https://doc.rust-lang.org/reference/items/extern-crates.html#the-no_link-attribute"),
629 WarnFollowing, EncodeCrossCrate::No
630 ),
631 ungated!(
632 repr, Normal,
633 template!(
634 List: &["C", "Rust", "transparent", "align(...)", "packed(...)", "<integer type>"],
635 "https://doc.rust-lang.org/reference/type-layout.html#representations"
636 ),
637 DuplicatesOk, EncodeCrossCrate::No
638 ),
360 ungated!(link),
361 ungated!(link_name),
362 ungated!(no_link),
363 ungated!(repr),
639364 // FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
640 gated!(rustc_align, Normal, template!(List: &["alignment"]), DuplicatesOk, EncodeCrossCrate::No, fn_align, experimental!(rustc_align)),
641 gated!(rustc_align_static, Normal, template!(List: &["alignment"]), DuplicatesOk, EncodeCrossCrate::No, static_align, experimental!(rustc_align_static)),
642 ungated!(
643 unsafe(Edition2024) export_name, Normal,
644 template!(NameValueStr: "name", "https://doc.rust-lang.org/reference/abi.html#the-export_name-attribute"),
645 FutureWarnPreceding, EncodeCrossCrate::No
646 ),
647 ungated!(
648 unsafe(Edition2024) link_section, Normal,
649 template!(NameValueStr: "name", "https://doc.rust-lang.org/reference/abi.html#the-link_section-attribute"),
650 FutureWarnPreceding, EncodeCrossCrate::No
651 ),
652 ungated!(
653 unsafe(Edition2024) no_mangle, Normal,
654 template!(Word, "https://doc.rust-lang.org/reference/abi.html#the-no_mangle-attribute"),
655 WarnFollowing, EncodeCrossCrate::No
656 ),
657 ungated!(
658 used, Normal,
659 template!(Word, List: &["compiler", "linker"], "https://doc.rust-lang.org/reference/abi.html#the-used-attribute"),
660 WarnFollowing, EncodeCrossCrate::No
661 ),
662 ungated!(
663 link_ordinal, Normal,
664 template!(List: &["ordinal"], "https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_ordinal-attribute"),
665 ErrorPreceding, EncodeCrossCrate::Yes
666 ),
667 ungated!(
668 unsafe naked, Normal,
669 template!(Word, "https://doc.rust-lang.org/reference/attributes/codegen.html#the-naked-attribute"),
670 WarnFollowing, EncodeCrossCrate::No
671 ),
365 gated!(rustc_align,fn_align, experimental!(rustc_align)),
366 gated!(rustc_align_static,static_align, experimental!(rustc_align_static)),
367 ungated!(unsafe(Edition2024) export_name),
368 ungated!(unsafe(Edition2024) link_section),
369 ungated!(unsafe(Edition2024) no_mangle),
370 ungated!(used),
371 ungated!(link_ordinal),
372 ungated!(unsafe naked),
672373 // See `TyAndLayout::pass_indirectly_in_non_rustic_abis` for details.
673 rustc_attr!(
674 rustc_pass_indirectly_in_non_rustic_abis, Normal, template!(Word), ErrorFollowing,
675 EncodeCrossCrate::No,
676 "types marked with `#[rustc_pass_indirectly_in_non_rustic_abis]` are always passed indirectly by non-Rustic ABIs"
677 ),
374 rustc_attr!(rustc_pass_indirectly_in_non_rustic_abis, "types marked with `#[rustc_pass_indirectly_in_non_rustic_abis]` are always passed indirectly by non-Rustic ABIs"),
678375
679376 // Limits:
680 ungated!(
681 recursion_limit, CrateLevel,
682 template!(NameValueStr: "N", "https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute"),
683 FutureWarnFollowing, EncodeCrossCrate::No
684 ),
685 ungated!(
686 type_length_limit, CrateLevel,
687 template!(NameValueStr: "N", "https://doc.rust-lang.org/reference/attributes/limits.html#the-type_length_limit-attribute"),
688 FutureWarnFollowing, EncodeCrossCrate::No
689 ),
377 ungated!(recursion_limit),
378 ungated!(type_length_limit),
690379 gated!(
691 move_size_limit, CrateLevel, template!(NameValueStr: "N"), ErrorFollowing,
692 EncodeCrossCrate::No, large_assignments, experimental!(move_size_limit)
380 move_size_limit, large_assignments, experimental!(move_size_limit)
693381 ),
694382
695383 // Entry point:
696 ungated!(
697 no_main, CrateLevel,
698 template!(Word, "https://doc.rust-lang.org/reference/crates-and-source-files.html#the-no_main-attribute"),
699 WarnFollowing, EncodeCrossCrate::No
700 ),
384 ungated!(no_main),
701385
702386 // Modules, prelude, and resolution:
703 ungated!(
704 path, Normal,
705 template!(NameValueStr: "file", "https://doc.rust-lang.org/reference/items/modules.html#the-path-attribute"),
706 FutureWarnFollowing, EncodeCrossCrate::No
707 ),
708 ungated!(
709 no_std, CrateLevel,
710 template!(Word, "https://doc.rust-lang.org/reference/names/preludes.html#the-no_std-attribute"),
711 WarnFollowing, EncodeCrossCrate::No
712 ),
713 ungated!(
714 no_implicit_prelude, Normal,
715 template!(Word, "https://doc.rust-lang.org/reference/names/preludes.html#the-no_implicit_prelude-attribute"),
716 WarnFollowing, EncodeCrossCrate::No
717 ),
718 ungated!(
719 non_exhaustive, Normal,
720 template!(Word, "https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute"),
721 WarnFollowing, EncodeCrossCrate::Yes
722 ),
387 ungated!(path),
388 ungated!(no_std),
389 ungated!(no_implicit_prelude),
390 ungated!(non_exhaustive),
723391
724392 // Runtime
725 ungated!(
726 windows_subsystem, CrateLevel,
727 template!(NameValueStr: ["windows", "console"], "https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute"),
728 FutureWarnFollowing, EncodeCrossCrate::No
729 ),
730 ungated!( // RFC 2070
731 panic_handler, Normal,
732 template!(Word, "https://doc.rust-lang.org/reference/panic.html#the-panic_handler-attribute"),
733 WarnFollowing, EncodeCrossCrate::Yes
393 ungated!(windows_subsystem),
394 ungated!(// RFC 2070
395 panic_handler
734396 ),
735397
736398 // Code generation:
737 ungated!(
738 inline, Normal,
739 template!(
740 Word,
741 List: &["always", "never"],
742 "https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute"
743 ),
744 FutureWarnFollowing, EncodeCrossCrate::No
745 ),
746 ungated!(
747 cold, Normal,
748 template!(Word, "https://doc.rust-lang.org/reference/attributes/codegen.html#the-cold-attribute"),
749 WarnFollowing, EncodeCrossCrate::No
750 ),
751 ungated!(
752 no_builtins, CrateLevel,
753 template!(Word, "https://doc.rust-lang.org/reference/attributes/codegen.html#the-no_builtins-attribute"),
754 WarnFollowing, EncodeCrossCrate::Yes
755 ),
756 ungated!(
757 target_feature, Normal,
758 template!(List: &[r#"enable = "name""#], "https://doc.rust-lang.org/reference/attributes/codegen.html#the-target_feature-attribute"),
759 DuplicatesOk, EncodeCrossCrate::No,
760 ),
761 ungated!(
762 track_caller, Normal,
763 template!(Word, "https://doc.rust-lang.org/reference/attributes/codegen.html#the-track_caller-attribute"),
764 WarnFollowing, EncodeCrossCrate::Yes
765 ),
766 ungated!(
767 instruction_set, Normal,
768 template!(List: &["set"], "https://doc.rust-lang.org/reference/attributes/codegen.html#the-instruction_set-attribute"),
769 ErrorPreceding, EncodeCrossCrate::No
770 ),
399 ungated!(inline),
400 ungated!(cold),
401 ungated!(no_builtins),
402 ungated!(target_feature),
403 ungated!(track_caller),
404 ungated!(instruction_set),
771405 gated!(
772 unsafe force_target_feature, Normal, template!(List: &[r#"enable = "name""#]),
773 DuplicatesOk, EncodeCrossCrate::No, effective_target_features, experimental!(force_target_feature)
406 unsafe force_target_feature,
407 effective_target_features, experimental!(force_target_feature)
774408 ),
775409 gated!(
776 sanitize, Normal, template!(List: &[r#"address = "on|off""#, r#"kernel_address = "on|off""#, r#"cfi = "on|off""#, r#"hwaddress = "on|off""#, r#"kernel_hwaddress = "on|off""#, r#"kcfi = "on|off""#, r#"memory = "on|off""#, r#"memtag = "on|off""#, r#"shadow_call_stack = "on|off""#, r#"thread = "on|off""#]), ErrorPreceding,
777 EncodeCrossCrate::No, sanitize, experimental!(sanitize),
410 sanitize,
411 sanitize, experimental!(sanitize)
778412 ),
779413 gated!(
780 coverage, Normal, template!(OneOf: &[sym::off, sym::on]),
781 ErrorPreceding, EncodeCrossCrate::No,
414 coverage,
782415 coverage_attribute, experimental!(coverage)
783416 ),
784417
785 ungated!(
786 doc, Normal,
787 template!(
788 List: &["hidden", "inline"],
789 NameValueStr: "string",
790 "https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html"
791 ),
792 DuplicatesOk, EncodeCrossCrate::Yes
793 ),
418 ungated!(doc),
794419
795420 // Debugging
796 ungated!(
797 debugger_visualizer, Normal,
798 template!(
799 List: &[r#"natvis_file = "...", gdb_script_file = "...""#],
800 "https://doc.rust-lang.org/reference/attributes/debugger.html#the-debugger_visualizer-attribute"
801 ),
802 DuplicatesOk, EncodeCrossCrate::No
803 ),
804 ungated!(
805 collapse_debuginfo, Normal,
806 template!(
807 List: &["no", "external", "yes"],
808 "https://doc.rust-lang.org/reference/attributes/debugger.html#the-collapse_debuginfo-attribute"
809 ),
810 ErrorFollowing, EncodeCrossCrate::Yes
811 ),
421 ungated!(debugger_visualizer),
422 ungated!(collapse_debuginfo),
812423
813424 // ==========================================================================
814425 // Unstable attributes:
......@@ -816,71 +427,61 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
816427
817428 // Linking:
818429 gated!(
819 export_stable, Normal, template!(Word), WarnFollowing,
820 EncodeCrossCrate::No, experimental!(export_stable)
430 export_stable, experimental!(export_stable)
821431 ),
822432
823433 // Testing:
824434 gated!(
825 test_runner, CrateLevel, template!(List: &["path"]), ErrorFollowing,
826 EncodeCrossCrate::Yes, custom_test_frameworks,
827 "custom test frameworks are an unstable feature",
435 test_runner, custom_test_frameworks,
436 "custom test frameworks are an unstable feature"
828437 ),
829438
830439 gated!(
831 reexport_test_harness_main, CrateLevel, template!(NameValueStr: "name"), ErrorFollowing,
832 EncodeCrossCrate::No, custom_test_frameworks,
833 "custom test frameworks are an unstable feature",
440 reexport_test_harness_main, custom_test_frameworks,
441 "custom test frameworks are an unstable feature"
834442 ),
835443
836444 // RFC #1268
837445 gated!(
838 marker, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
839 marker_trait_attr, experimental!(marker)
446 marker,marker_trait_attr, experimental!(marker)
840447 ),
841448 gated!(
842 thread_local, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
843 "`#[thread_local]` is an experimental feature, and does not currently handle destructors",
449 thread_local,"`#[thread_local]` is an experimental feature, and does not currently handle destructors"
844450 ),
845451 gated!(
846 no_core, CrateLevel, template!(Word), WarnFollowing,
847 EncodeCrossCrate::No, experimental!(no_core)
452 no_core, experimental!(no_core)
848453 ),
849454 // RFC 2412
850455 gated!(
851 optimize, Normal, template!(List: &["none", "size", "speed"]), ErrorPreceding,
852 EncodeCrossCrate::No, optimize_attribute, experimental!(optimize)
456 optimize,
457 optimize_attribute, experimental!(optimize)
853458 ),
854459
855460 gated!(
856 unsafe ffi_pure, Normal, template!(Word), WarnFollowing,
857 EncodeCrossCrate::No, experimental!(ffi_pure)
461 unsafe ffi_pure, experimental!(ffi_pure)
858462 ),
859463 gated!(
860 unsafe ffi_const, Normal, template!(Word), WarnFollowing,
861 EncodeCrossCrate::No, experimental!(ffi_const)
464 unsafe ffi_const, experimental!(ffi_const)
862465 ),
863466 gated!(
864 register_tool, CrateLevel, template!(List: &["tool1, tool2, ..."]), DuplicatesOk,
865 EncodeCrossCrate::No, experimental!(register_tool),
467 register_tool, experimental!(register_tool)
866468 ),
867469 // `#[cfi_encoding = ""]`
868470 gated!(
869 cfi_encoding, Normal, template!(NameValueStr: "encoding"), ErrorPreceding,
870 EncodeCrossCrate::Yes, experimental!(cfi_encoding)
471 cfi_encoding,
472 experimental!(cfi_encoding)
871473 ),
872474
873475 // `#[coroutine]` attribute to be applied to closures to make them coroutines instead
874476 gated!(
875 coroutine, Normal, template!(Word), ErrorFollowing,
876 EncodeCrossCrate::No, coroutines, experimental!(coroutine)
477 coroutine,coroutines, experimental!(coroutine)
877478 ),
878479
879480 // RFC 3543
880481 // `#[patchable_function_entry(prefix_nops = m, entry_nops = n)]`
881482 gated!(
882 patchable_function_entry, Normal, template!(List: &["prefix_nops = m, entry_nops = n"]), ErrorPreceding,
883 EncodeCrossCrate::Yes, experimental!(patchable_function_entry)
483 patchable_function_entry,
484 experimental!(patchable_function_entry)
884485 ),
885486
886487 // The `#[loop_match]` and `#[const_continue]` attributes are part of the
......@@ -888,12 +489,10 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
888489 //
889490 // - https://github.com/rust-lang/rust/issues/132306
890491 gated!(
891 const_continue, Normal, template!(Word), ErrorFollowing,
892 EncodeCrossCrate::No, loop_match, experimental!(const_continue)
492 const_continue,loop_match, experimental!(const_continue)
893493 ),
894494 gated!(
895 loop_match, Normal, template!(Word), ErrorFollowing,
896 EncodeCrossCrate::No, loop_match, experimental!(loop_match)
495 loop_match,loop_match, experimental!(loop_match)
897496 ),
898497
899498 // The `#[pin_v2]` attribute is part of the `pin_ergonomics` experiment
......@@ -901,74 +500,40 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
901500 //
902501 // - https://github.com/rust-lang/rust/issues/130494
903502 gated!(
904 pin_v2, Normal, template!(Word), ErrorFollowing,
905 EncodeCrossCrate::Yes, pin_ergonomics, experimental!(pin_v2),
503 pin_v2,pin_ergonomics, experimental!(pin_v2),
906504 ),
907505
908506 // ==========================================================================
909507 // Internal attributes: Stability, deprecation, and unsafe:
910508 // ==========================================================================
911509
912 ungated!(
913 feature, CrateLevel,
914 template!(List: &["name1, name2, ..."]), DuplicatesOk, EncodeCrossCrate::No,
915 ),
510 ungated!(feature),
916511 // DuplicatesOk since it has its own validation
917 ungated!(
918 stable, Normal,
919 template!(List: &[r#"feature = "name", since = "version""#]), DuplicatesOk, EncodeCrossCrate::No,
920 ),
921 ungated!(
922 unstable, Normal,
923 template!(List: &[r#"feature = "name", reason = "...", issue = "N""#]), DuplicatesOk,
924 EncodeCrossCrate::Yes
925 ),
926 ungated!(
927 unstable_feature_bound, Normal, template!(Word, List: &["feat1, feat2, ..."]),
928 DuplicatesOk, EncodeCrossCrate::No,
929 ),
930 ungated!(
931 rustc_const_unstable, Normal, template!(List: &[r#"feature = "name""#]),
932 DuplicatesOk, EncodeCrossCrate::Yes
933 ),
934 ungated!(
935 rustc_const_stable, Normal,
936 template!(List: &[r#"feature = "name""#]), DuplicatesOk, EncodeCrossCrate::No,
937 ),
938 ungated!(
939 rustc_default_body_unstable, Normal,
940 template!(List: &[r#"feature = "name", reason = "...", issue = "N""#]),
941 DuplicatesOk, EncodeCrossCrate::No
942 ),
943 gated!(
944 allow_internal_unstable, Normal, template!(Word, List: &["feat1, feat2, ..."]),
945 DuplicatesOk, EncodeCrossCrate::Yes,
512 ungated!(stable),
513 ungated!(unstable),
514 ungated!(unstable_feature_bound),
515 ungated!(rustc_const_unstable),
516 ungated!(rustc_const_stable),
517 ungated!(rustc_default_body_unstable),
518 gated!(
519 allow_internal_unstable,
946520 "allow_internal_unstable side-steps feature gating and stability checks",
947521 ),
948522 gated!(
949 allow_internal_unsafe, Normal, template!(Word), WarnFollowing,
950 EncodeCrossCrate::No, "allow_internal_unsafe side-steps the unsafe_code lint",
523 allow_internal_unsafe, "allow_internal_unsafe side-steps the unsafe_code lint",
951524 ),
952525 gated!(
953 rustc_eii_foreign_item, Normal, template!(Word),
954 ErrorFollowing, EncodeCrossCrate::Yes, eii_internals,
526 rustc_eii_foreign_item,
527 eii_internals,
955528 "used internally to mark types with a `transparent` representation when it is guaranteed by the documentation",
956529 ),
957 rustc_attr!(
958 rustc_allowed_through_unstable_modules, Normal, template!(NameValueStr: "deprecation message"),
959 WarnFollowing, EncodeCrossCrate::No,
530 rustc_attr!(rustc_allowed_through_unstable_modules,
960531 "rustc_allowed_through_unstable_modules special cases accidental stabilizations of stable items \
961532 through unstable paths"
962533 ),
963 rustc_attr!(
964 rustc_deprecated_safe_2024, Normal, template!(List: &[r#"audit_that = "...""#]),
965 ErrorFollowing, EncodeCrossCrate::Yes,
966 "`#[rustc_deprecated_safe_2024]` is used to declare functions unsafe across the edition 2024 boundary",
534 rustc_attr!(rustc_deprecated_safe_2024,"`#[rustc_deprecated_safe_2024]` is used to declare functions unsafe across the edition 2024 boundary",
967535 ),
968 rustc_attr!(
969 rustc_pub_transparent, Normal, template!(Word),
970 ErrorFollowing, EncodeCrossCrate::Yes,
971 "used internally to mark types with a `transparent` representation when it is guaranteed by the documentation",
536 rustc_attr!(rustc_pub_transparent,"used internally to mark types with a `transparent` representation when it is guaranteed by the documentation",
972537 ),
973538
974539
......@@ -976,25 +541,13 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
976541 // Internal attributes: Type system related:
977542 // ==========================================================================
978543
979 gated!(fundamental, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes, experimental!(fundamental)),
544 gated!(fundamental, experimental!(fundamental)),
980545 gated!(
981 may_dangle, Normal, template!(Word), WarnFollowing,
982 EncodeCrossCrate::No, dropck_eyepatch,
983 "`may_dangle` has unstable semantics and may be removed in the future",
546 may_dangle, dropck_eyepatch,
547 "`may_dangle` has unstable semantics and may be removed in the future"
984548 ),
985549
986 rustc_attr!(
987 rustc_never_type_options,
988 Normal,
989 template!(List: &[
990 "",
991 r#"fallback = "unit""#,
992 r#"fallback = "niko""#,
993 r#"fallback = "never""#,
994 r#"fallback = "no""#,
995 ]),
996 ErrorFollowing,
997 EncodeCrossCrate::No,
550 rustc_attr!(rustc_never_type_options,
998551 "`rustc_never_type_options` is used to experiment with never type fallback and work on \
999552 never type stabilization"
1000553 ),
......@@ -1003,57 +556,33 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
1003556 // Internal attributes: Runtime related:
1004557 // ==========================================================================
1005558
1006 rustc_attr!(
1007 rustc_allocator, Normal, template!(Word), WarnFollowing,
1008 EncodeCrossCrate::No,
1009 ),
1010 rustc_attr!(
1011 rustc_nounwind, Normal, template!(Word), WarnFollowing,
1012 EncodeCrossCrate::No,
1013 ),
1014 rustc_attr!(
1015 rustc_reallocator, Normal, template!(Word), WarnFollowing,
1016 EncodeCrossCrate::No,
1017 ),
1018 rustc_attr!(
1019 rustc_deallocator, Normal, template!(Word), WarnFollowing,
1020 EncodeCrossCrate::No,
1021 ),
1022 rustc_attr!(
1023 rustc_allocator_zeroed, Normal, template!(Word), WarnFollowing,
1024 EncodeCrossCrate::No,
1025 ),
1026 rustc_attr!(
1027 rustc_allocator_zeroed_variant, Normal, template!(NameValueStr: "function"), ErrorPreceding,
1028 EncodeCrossCrate::Yes,
1029 ),
559 rustc_attr!(rustc_allocator),
560 rustc_attr!(rustc_nounwind),
561 rustc_attr!(rustc_reallocator),
562 rustc_attr!(rustc_deallocator),
563 rustc_attr!(rustc_allocator_zeroed),
564 rustc_attr!(rustc_allocator_zeroed_variant),
1030565 gated!(
1031 default_lib_allocator, Normal, template!(Word), WarnFollowing,
1032 EncodeCrossCrate::No, allocator_internals, experimental!(default_lib_allocator),
566 default_lib_allocator, allocator_internals, experimental!(default_lib_allocator),
1033567 ),
1034568 gated!(
1035 needs_allocator, Normal, template!(Word), WarnFollowing,
1036 EncodeCrossCrate::No, allocator_internals, experimental!(needs_allocator),
569 needs_allocator, allocator_internals, experimental!(needs_allocator),
1037570 ),
1038571 gated!(
1039 panic_runtime, CrateLevel, template!(Word), WarnFollowing,
1040 EncodeCrossCrate::No, experimental!(panic_runtime)
572 panic_runtime, experimental!(panic_runtime)
1041573 ),
1042574 gated!(
1043 needs_panic_runtime, CrateLevel, template!(Word), WarnFollowing,
1044 EncodeCrossCrate::No, experimental!(needs_panic_runtime)
575 needs_panic_runtime, experimental!(needs_panic_runtime)
1045576 ),
1046577 gated!(
1047 compiler_builtins, CrateLevel, template!(Word), WarnFollowing,
1048 EncodeCrossCrate::No,
578 compiler_builtins,
1049579 "the `#[compiler_builtins]` attribute is used to identify the `compiler_builtins` crate \
1050 which contains compiler-rt intrinsics and will never be stable",
580 which contains compiler-rt intrinsics and will never be stable"
1051581 ),
1052582 gated!(
1053 profiler_runtime, CrateLevel, template!(Word), WarnFollowing,
1054 EncodeCrossCrate::No,
583 profiler_runtime,
1055584 "the `#[profiler_runtime]` attribute is used to identify the `profiler_builtins` crate \
1056 which contains the profiler runtime and will never be stable",
585 which contains the profiler runtime and will never be stable"
1057586 ),
1058587
1059588 // ==========================================================================
......@@ -1061,277 +590,123 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
1061590 // ==========================================================================
1062591
1063592 gated!(
1064 linkage, Normal, template!(NameValueStr: [
1065 "available_externally",
1066 "common",
1067 "extern_weak",
1068 "external",
1069 "internal",
1070 "linkonce",
1071 "linkonce_odr",
1072 "weak",
1073 "weak_odr",
1074 ], "https://doc.rust-lang.org/reference/linkage.html"),
1075 ErrorPreceding, EncodeCrossCrate::No,
1076 "the `linkage` attribute is experimental and not portable across platforms",
1077 ),
1078 rustc_attr!(
1079 rustc_std_internal_symbol, Normal, template!(Word), WarnFollowing,
1080 EncodeCrossCrate::No,
1081 ),
1082 rustc_attr!(
1083 rustc_objc_class, Normal, template!(NameValueStr: "ClassName"), ErrorPreceding,
1084 EncodeCrossCrate::No,
1085 ),
1086 rustc_attr!(
1087 rustc_objc_selector, Normal, template!(NameValueStr: "methodName"), ErrorPreceding,
1088 EncodeCrossCrate::No,
593 linkage,
594 "the `linkage` attribute is experimental and not portable across platforms"
1089595 ),
596 rustc_attr!(rustc_std_internal_symbol),
597 rustc_attr!(rustc_objc_class),
598 rustc_attr!(rustc_objc_selector),
1090599
1091600 // ==========================================================================
1092601 // Internal attributes, Macro related:
1093602 // ==========================================================================
1094603
1095 rustc_attr!(
1096 rustc_builtin_macro, Normal,
1097 template!(Word, List: &["name", "name, /*opt*/ attributes(name1, name2, ...)"]), ErrorFollowing,
1098 EncodeCrossCrate::Yes,
1099 ),
1100 rustc_attr!(
1101 rustc_proc_macro_decls, Normal, template!(Word), WarnFollowing,
1102 EncodeCrossCrate::No,
1103 ),
1104 rustc_attr!(
1105 rustc_macro_transparency, Normal,
1106 template!(NameValueStr: ["transparent", "semiopaque", "opaque"]), ErrorFollowing,
1107 EncodeCrossCrate::Yes, "used internally for testing macro hygiene",
1108 ),
1109 rustc_attr!(
1110 rustc_autodiff, Normal,
1111 template!(Word, List: &[r#""...""#]), DuplicatesOk,
1112 EncodeCrossCrate::Yes,
1113 ),
1114 rustc_attr!(
1115 rustc_offload_kernel, Normal,
1116 template!(Word), DuplicatesOk,
1117 EncodeCrossCrate::Yes,
604 rustc_attr!(rustc_builtin_macro),
605 rustc_attr!(rustc_proc_macro_decls),
606 rustc_attr!(rustc_macro_transparency,
607 "used internally for testing macro hygiene"
1118608 ),
609 rustc_attr!(rustc_autodiff),
610 rustc_attr!(rustc_offload_kernel),
1119611 // Traces that are left when `cfg` and `cfg_attr` attributes are expanded.
1120612 // The attributes are not gated, to avoid stability errors, but they cannot be used in stable
1121613 // or unstable code directly because `sym::cfg_(attr_)trace` are not valid identifiers, they
1122614 // can only be generated by the compiler.
1123 ungated!(
1124 cfg_trace, Normal, template!(Word /* irrelevant */), DuplicatesOk,
1125 EncodeCrossCrate::Yes
615 ungated!(cfg_trace
1126616 ),
1127 ungated!(
1128 cfg_attr_trace, Normal, template!(Word /* irrelevant */), DuplicatesOk,
1129 EncodeCrossCrate::No
617 ungated!(cfg_attr_trace
1130618 ),
1131619
1132620 // ==========================================================================
1133621 // Internal attributes, Diagnostics related:
1134622 // ==========================================================================
1135623
1136 rustc_attr!(
1137 rustc_on_unimplemented, Normal,
1138 template!(
1139 List: &[r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#],
1140 NameValueStr: "message"
1141 ),
1142 ErrorFollowing, EncodeCrossCrate::Yes,
1143 "see `#[diagnostic::on_unimplemented]` for the stable equivalent of this attribute"
1144 ),
1145 rustc_attr!(
1146 rustc_confusables, Normal,
1147 template!(List: &[r#""name1", "name2", ..."#]),
1148 ErrorFollowing, EncodeCrossCrate::Yes,
624 rustc_attr!(rustc_on_unimplemented,"see `#[diagnostic::on_unimplemented]` for the stable equivalent of this attribute"
1149625 ),
626 rustc_attr!(rustc_confusables),
1150627 // Enumerates "identity-like" conversion methods to suggest on type mismatch.
1151 rustc_attr!(
1152 rustc_conversion_suggestion, Normal, template!(Word),
1153 WarnFollowing, EncodeCrossCrate::Yes,
1154 ),
628 rustc_attr!(rustc_conversion_suggestion),
1155629 // Prevents field reads in the marked trait or method to be considered
1156630 // during dead code analysis.
1157 rustc_attr!(
1158 rustc_trivial_field_reads, Normal, template!(Word),
1159 WarnFollowing, EncodeCrossCrate::Yes,
1160 ),
631 rustc_attr!(rustc_trivial_field_reads),
1161632 // Used by the `rustc::potential_query_instability` lint to warn methods which
1162633 // might not be stable during incremental compilation.
1163 rustc_attr!(
1164 rustc_lint_query_instability, Normal, template!(Word),
1165 WarnFollowing, EncodeCrossCrate::Yes,
1166 ),
634 rustc_attr!(rustc_lint_query_instability),
1167635 // Used by the `rustc::untracked_query_information` lint to warn methods which
1168636 // might not be stable during incremental compilation.
1169 rustc_attr!(
1170 rustc_lint_untracked_query_information, Normal, template!(Word),
1171 WarnFollowing, EncodeCrossCrate::Yes,
1172 ),
637 rustc_attr!(rustc_lint_untracked_query_information),
1173638 // Used by the `rustc::bad_opt_access` lint to identify `DebuggingOptions` and `CodegenOptions`
1174639 // types (as well as any others in future).
1175 rustc_attr!(
1176 rustc_lint_opt_ty, Normal, template!(Word),
1177 WarnFollowing, EncodeCrossCrate::Yes,
1178 ),
640 rustc_attr!(rustc_lint_opt_ty),
1179641 // Used by the `rustc::bad_opt_access` lint on fields
1180642 // types (as well as any others in future).
1181 rustc_attr!(
1182 rustc_lint_opt_deny_field_access, Normal, template!(List: &["message"]),
1183 WarnFollowing, EncodeCrossCrate::Yes,
1184 ),
643 rustc_attr!(rustc_lint_opt_deny_field_access),
1185644
1186645 // ==========================================================================
1187646 // Internal attributes, Const related:
1188647 // ==========================================================================
1189648
1190 rustc_attr!(
1191 rustc_promotable, Normal, template!(Word), WarnFollowing,
1192 EncodeCrossCrate::No, ),
1193 rustc_attr!(
1194 rustc_legacy_const_generics, Normal, template!(List: &["N"]), ErrorFollowing,
1195 EncodeCrossCrate::Yes,
1196 ),
649 rustc_attr!(rustc_promotable),
650 rustc_attr!(rustc_legacy_const_generics),
1197651 // Do not const-check this function's body. It will always get replaced during CTFE via `hook_special_const_fn`.
1198 rustc_attr!(
1199 rustc_do_not_const_check, Normal, template!(Word), WarnFollowing,
1200 EncodeCrossCrate::Yes, "`#[rustc_do_not_const_check]` skips const-check for this function's body",
1201 ),
1202 rustc_attr!(
1203 rustc_const_stable_indirect, Normal,
1204 template!(Word),
1205 WarnFollowing,
1206 EncodeCrossCrate::No,
1207 "this is an internal implementation detail",
1208 ),
1209 rustc_attr!(
1210 rustc_intrinsic_const_stable_indirect, Normal,
1211 template!(Word), WarnFollowing, EncodeCrossCrate::No, "this is an internal implementation detail",
1212 ),
1213 rustc_attr!(
1214 rustc_allow_const_fn_unstable, Normal,
1215 template!(Word, List: &["feat1, feat2, ..."]), DuplicatesOk, EncodeCrossCrate::No,
1216 "rustc_allow_const_fn_unstable side-steps feature gating and stability checks"
652 rustc_attr!(rustc_do_not_const_check, "`#[rustc_do_not_const_check]` skips const-check for this function's body"),
653 rustc_attr!(rustc_const_stable_indirect,
654 "this is an internal implementation detail"),
655 rustc_attr!(rustc_intrinsic_const_stable_indirect,
656 "this is an internal implementation detail"),
657 rustc_attr!(rustc_allow_const_fn_unstable,
658 "rustc_allow_const_fn_unstable side-steps feature gating and stability checks"
1217659 ),
1218660
1219661 // ==========================================================================
1220662 // Internal attributes, Layout related:
1221663 // ==========================================================================
1222664
1223 rustc_attr!(
1224 rustc_layout_scalar_valid_range_start, Normal, template!(List: &["value"]), ErrorFollowing,
1225 EncodeCrossCrate::Yes,
1226 "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \
1227 niche optimizations in the standard library",
1228 ),
1229 rustc_attr!(
1230 rustc_layout_scalar_valid_range_end, Normal, template!(List: &["value"]), ErrorFollowing,
1231 EncodeCrossCrate::Yes,
1232 "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \
1233 niche optimizations in the standard library",
1234 ),
1235 rustc_attr!(
1236 rustc_simd_monomorphize_lane_limit, Normal, template!(NameValueStr: "N"), ErrorFollowing,
1237 EncodeCrossCrate::Yes,
1238 "the `#[rustc_simd_monomorphize_lane_limit]` attribute is just used by std::simd \
1239 for better error messages",
1240 ),
1241 rustc_attr!(
1242 rustc_nonnull_optimization_guaranteed, Normal, template!(Word), WarnFollowing,
1243 EncodeCrossCrate::Yes,
665 rustc_attr!(rustc_layout_scalar_valid_range_start, "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \
666 niche optimizations in the standard library"),
667 rustc_attr!(rustc_layout_scalar_valid_range_end, "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \
668 niche optimizations in the standard library"),
669 rustc_attr!(rustc_simd_monomorphize_lane_limit, "the `#[rustc_simd_monomorphize_lane_limit]` attribute is just used by std::simd \
670 for better error messages"),
671 rustc_attr!(rustc_nonnull_optimization_guaranteed,
1244672 "the `#[rustc_nonnull_optimization_guaranteed]` attribute is just used to document \
1245673 guaranteed niche optimizations in the standard library",
1246674 "the compiler does not even check whether the type indeed is being non-null-optimized; \
1247 it is your responsibility to ensure that the attribute is only used on types that are optimized",
1248 ),
675 it is your responsibility to ensure that the attribute is only used on types that are optimized"),
1249676
1250677 // ==========================================================================
1251678 // Internal attributes, Misc:
1252679 // ==========================================================================
1253680 gated!(
1254 lang, Normal, template!(NameValueStr: "name"), DuplicatesOk, EncodeCrossCrate::No, lang_items,
1255 "lang items are subject to change",
1256 ),
1257 rustc_attr!(
1258 rustc_as_ptr, Normal, template!(Word), ErrorFollowing,
1259 EncodeCrossCrate::Yes,
1260 "`#[rustc_as_ptr]` is used to mark functions returning pointers to their inner allocations"
1261 ),
1262 rustc_attr!(
1263 rustc_should_not_be_called_on_const_items, Normal, template!(Word), ErrorFollowing,
1264 EncodeCrossCrate::Yes,
1265 "`#[rustc_should_not_be_called_on_const_items]` is used to mark methods that don't make sense to be called on interior mutable consts"
1266 ),
1267 rustc_attr!(
1268 rustc_pass_by_value, Normal, template!(Word), ErrorFollowing,
1269 EncodeCrossCrate::Yes,
1270 "`#[rustc_pass_by_value]` is used to mark types that must be passed by value instead of reference"
1271 ),
1272 rustc_attr!(
1273 rustc_never_returns_null_ptr, Normal, template!(Word), ErrorFollowing,
1274 EncodeCrossCrate::Yes,
1275 "`#[rustc_never_returns_null_ptr]` is used to mark functions returning non-null pointers"
1276 ),
1277 rustc_attr!(
1278 rustc_no_implicit_autorefs, AttributeType::Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes,
1279 "`#[rustc_no_implicit_autorefs]` is used to mark functions for which an autoref to the dereference of a raw pointer should not be used as an argument"
1280 ),
1281 rustc_attr!(
1282 rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
1283 "`#![rustc_coherence_is_core]` allows inherent methods on builtin types, only intended to be used in `core`"
1284 ),
1285 rustc_attr!(
1286 rustc_coinductive, AttributeType::Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
1287 "`#[rustc_coinductive]` changes a trait to be coinductive, allowing cycles in the trait solver"
1288 ),
1289 rustc_attr!(
1290 rustc_allow_incoherent_impl, AttributeType::Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
1291 "`#[rustc_allow_incoherent_impl]` has to be added to all impl items of an incoherent inherent impl"
1292 ),
1293 rustc_attr!(
1294 rustc_preserve_ub_checks, AttributeType::CrateLevel, template!(Word), ErrorFollowing, EncodeCrossCrate::No,
1295 "`#![rustc_preserve_ub_checks]` prevents the designated crate from evaluating whether UB checks are enabled when optimizing MIR",
1296 ),
1297 rustc_attr!(
1298 rustc_deny_explicit_impl,
1299 AttributeType::Normal,
1300 template!(Word),
1301 ErrorFollowing,
1302 EncodeCrossCrate::No,
681 lang,lang_items,
682 "lang items are subject to change"
683 ),
684 rustc_attr!(rustc_as_ptr, "`#[rustc_as_ptr]` is used to mark functions returning pointers to their inner allocations"),
685 rustc_attr!(rustc_should_not_be_called_on_const_items, "`#[rustc_should_not_be_called_on_const_items]` is used to mark methods that don't make sense to be called on interior mutable consts"),
686 rustc_attr!(rustc_pass_by_value, "`#[rustc_pass_by_value]` is used to mark types that must be passed by value instead of reference"),
687 rustc_attr!(rustc_never_returns_null_ptr, "`#[rustc_never_returns_null_ptr]` is used to mark functions returning non-null pointers"),
688 rustc_attr!(rustc_no_implicit_autorefs, "`#[rustc_no_implicit_autorefs]` is used to mark functions for which an autoref to the dereference of a raw pointer should not be used as an argument"),
689 rustc_attr!(rustc_coherence_is_core, "`#![rustc_coherence_is_core]` allows inherent methods on builtin types, only intended to be used in `core`"),
690 rustc_attr!(rustc_coinductive, "`#[rustc_coinductive]` changes a trait to be coinductive, allowing cycles in the trait solver"),
691 rustc_attr!(rustc_allow_incoherent_impl, "`#[rustc_allow_incoherent_impl]` has to be added to all impl items of an incoherent inherent impl"),
692 rustc_attr!(rustc_preserve_ub_checks, "`#![rustc_preserve_ub_checks]` prevents the designated crate from evaluating whether UB checks are enabled when optimizing MIR"),
693 rustc_attr!(rustc_deny_explicit_impl,
1303694 "`#[rustc_deny_explicit_impl]` enforces that a trait can have no user-provided impls"
1304695 ),
1305 rustc_attr!(
1306 rustc_dyn_incompatible_trait,
1307 AttributeType::Normal,
1308 template!(Word),
1309 ErrorFollowing,
1310 EncodeCrossCrate::No,
696 rustc_attr!(rustc_dyn_incompatible_trait,
1311697 "`#[rustc_dyn_incompatible_trait]` marks a trait as dyn-incompatible, \
1312698 even if it otherwise satisfies the requirements to be dyn-compatible."
1313699 ),
1314 rustc_attr!(
1315 rustc_has_incoherent_inherent_impls, AttributeType::Normal, template!(Word),
1316 ErrorFollowing, EncodeCrossCrate::Yes,
1317 "`#[rustc_has_incoherent_inherent_impls]` allows the addition of incoherent inherent impls for \
700 rustc_attr!(rustc_has_incoherent_inherent_impls, "`#[rustc_has_incoherent_inherent_impls]` allows the addition of incoherent inherent impls for \
1318701 the given type by annotating all impl items with `#[rustc_allow_incoherent_impl]`"
1319702 ),
1320 rustc_attr!(
1321 rustc_non_const_trait_method, AttributeType::Normal, template!(Word),
1322 ErrorFollowing, EncodeCrossCrate::No,
1323 "`#[rustc_non_const_trait_method]` should only used by the standard library to mark trait methods \
703 rustc_attr!(rustc_non_const_trait_method, "`#[rustc_non_const_trait_method]` should only used by the standard library to mark trait methods \
1324704 as non-const to allow large traits an easier transition to const"
1325705 ),
1326706
1327707 BuiltinAttribute {
1328708 name: sym::rustc_diagnostic_item,
1329 // FIXME: This can be `true` once we always use `tcx.is_diagnostic_item`.
1330 encode_cross_crate: EncodeCrossCrate::Yes,
1331 type_: Normal,
1332709 safety: AttributeSafety::Normal,
1333 template: template!(NameValueStr: "name"),
1334 duplicates: ErrorFollowing,
1335710 gate: Gated {
1336711 feature: sym::rustc_attrs,
1337712 message: "use of an internal attribute",
......@@ -1342,236 +717,87 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
1342717 },
1343718 gated!(
1344719 // Used in resolve:
1345 prelude_import, Normal, template!(Word), WarnFollowing,
1346 EncodeCrossCrate::No, "`#[prelude_import]` is for use by rustc only",
720 prelude_import, "`#[prelude_import]` is for use by rustc only",
1347721 ),
1348722 gated!(
1349 rustc_paren_sugar, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
1350 unboxed_closures, "unboxed_closures are still evolving",
723 rustc_paren_sugar,unboxed_closures, "unboxed_closures are still evolving",
1351724 ),
1352 rustc_attr!(
1353 rustc_inherit_overflow_checks, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
1354 "the `#[rustc_inherit_overflow_checks]` attribute is just used to control \
725 rustc_attr!(rustc_inherit_overflow_checks,"the `#[rustc_inherit_overflow_checks]` attribute is just used to control \
1355726 overflow checking behavior of several functions in the standard library that are inlined \
1356 across crates",
727 across crates"
1357728 ),
1358 rustc_attr!(
1359 rustc_reservation_impl, Normal,
1360 template!(NameValueStr: "reservation message"), ErrorFollowing, EncodeCrossCrate::Yes,
1361 "the `#[rustc_reservation_impl]` attribute is internally used \
729 rustc_attr!(rustc_reservation_impl,"the `#[rustc_reservation_impl]` attribute is internally used \
1362730 for reserving `impl<T> From<!> for T` as part of the effort to stabilize `!`"
1363731 ),
1364 rustc_attr!(
1365 rustc_test_marker, Normal, template!(NameValueStr: "name"), WarnFollowing,
1366 EncodeCrossCrate::No, "the `#[rustc_test_marker]` attribute is used internally to track tests",
1367 ),
1368 rustc_attr!(
1369 rustc_unsafe_specialization_marker, Normal, template!(Word),
1370 WarnFollowing, EncodeCrossCrate::No,
732 rustc_attr!(rustc_test_marker, "the `#[rustc_test_marker]` attribute is used internally to track tests"),
733 rustc_attr!(rustc_unsafe_specialization_marker,
1371734 "the `#[rustc_unsafe_specialization_marker]` attribute is used to check specializations"
1372735 ),
1373 rustc_attr!(
1374 rustc_specialization_trait, Normal, template!(Word),
1375 WarnFollowing, EncodeCrossCrate::No,
736 rustc_attr!(rustc_specialization_trait,
1376737 "the `#[rustc_specialization_trait]` attribute is used to check specializations"
1377738 ),
1378 rustc_attr!(
1379 rustc_main, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
1380 "the `#[rustc_main]` attribute is used internally to specify test entry point function",
1381 ),
1382 rustc_attr!(
1383 rustc_skip_during_method_dispatch, Normal, template!(List: &["array, boxed_slice"]), ErrorFollowing,
1384 EncodeCrossCrate::No,
1385 "the `#[rustc_skip_during_method_dispatch]` attribute is used to exclude a trait \
739 rustc_attr!(rustc_main,"the `#[rustc_main]` attribute is used internally to specify test entry point function"),
740 rustc_attr!(rustc_skip_during_method_dispatch, "the `#[rustc_skip_during_method_dispatch]` attribute is used to exclude a trait \
1386741 from method dispatch when the receiver is of the following type, for compatibility in \
1387742 editions < 2021 (array) or editions < 2024 (boxed_slice)"
1388743 ),
1389 rustc_attr!(
1390 rustc_must_implement_one_of, Normal, template!(List: &["function1, function2, ..."]),
1391 ErrorFollowing, EncodeCrossCrate::No,
1392 "the `#[rustc_must_implement_one_of]` attribute is used to change minimal complete \
744 rustc_attr!(rustc_must_implement_one_of,"the `#[rustc_must_implement_one_of]` attribute is used to change minimal complete \
1393745 definition of a trait. Its syntax and semantics are highly experimental and will be \
1394746 subject to change before stabilization",
1395747 ),
1396 rustc_attr!(
1397 rustc_doc_primitive, Normal, template!(NameValueStr: "primitive name"), ErrorFollowing,
1398 EncodeCrossCrate::Yes, "the `#[rustc_doc_primitive]` attribute is used by the standard library \
748 rustc_attr!(rustc_doc_primitive,"the `#[rustc_doc_primitive]` attribute is used by the standard library \
1399749 to provide a way to generate documentation for primitive types",
1400750 ),
1401751 gated!(
1402 rustc_intrinsic, Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes, intrinsics,
1403 "the `#[rustc_intrinsic]` attribute is used to declare intrinsics as function items",
1404 ),
1405 rustc_attr!(
1406 rustc_no_mir_inline, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes,
1407 "`#[rustc_no_mir_inline]` prevents the MIR inliner from inlining a function while not affecting codegen"
1408 ),
1409 rustc_attr!(
1410 rustc_force_inline, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing, EncodeCrossCrate::Yes,
1411 "`#[rustc_force_inline]` forces a free function to be inlined"
1412 ),
1413 rustc_attr!(
1414 rustc_scalable_vector, Normal, template!(List: &["count"]), WarnFollowing, EncodeCrossCrate::Yes,
1415 "`#[rustc_scalable_vector]` defines a scalable vector type"
752 rustc_intrinsic,intrinsics,
753 "the `#[rustc_intrinsic]` attribute is used to declare intrinsics as function items"),
754 rustc_attr!(rustc_no_mir_inline,"`#[rustc_no_mir_inline]` prevents the MIR inliner from inlining a function while not affecting codegen"
1416755 ),
756 rustc_attr!(rustc_force_inline,"`#[rustc_force_inline]` forces a free function to be inlined"),
757 rustc_attr!(rustc_scalable_vector,"`#[rustc_scalable_vector]` defines a scalable vector type"),
1417758
1418759 // ==========================================================================
1419760 // Internal attributes, Testing:
1420761 // ==========================================================================
1421762
1422 rustc_attr!(TEST, rustc_effective_visibility, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes),
1423 rustc_attr!(
1424 TEST, rustc_dump_inferred_outlives, Normal, template!(Word),
1425 WarnFollowing, EncodeCrossCrate::No
1426 ),
1427 rustc_attr!(
1428 TEST, rustc_capture_analysis, Normal, template!(Word),
1429 WarnFollowing, EncodeCrossCrate::No
1430 ),
1431 rustc_attr!(
1432 TEST, rustc_insignificant_dtor, Normal, template!(Word),
1433 WarnFollowing, EncodeCrossCrate::Yes
1434 ),
1435 rustc_attr!(
1436 TEST, rustc_no_implicit_bounds, CrateLevel, template!(Word),
1437 WarnFollowing, EncodeCrossCrate::No
1438 ),
1439 rustc_attr!(
1440 TEST, rustc_strict_coherence, Normal, template!(Word),
1441 WarnFollowing, EncodeCrossCrate::Yes
1442 ),
1443 rustc_attr!(
1444 TEST, rustc_dump_variances, Normal, template!(Word),
1445 WarnFollowing, EncodeCrossCrate::No
1446 ),
1447 rustc_attr!(
1448 TEST, rustc_dump_variances_of_opaques, Normal, template!(Word),
1449 WarnFollowing, EncodeCrossCrate::No
1450 ),
1451 rustc_attr!(
1452 TEST, rustc_hidden_type_of_opaques, Normal, template!(Word),
1453 WarnFollowing, EncodeCrossCrate::No
1454 ),
1455 rustc_attr!(
1456 TEST, rustc_layout, Normal, template!(List: &["field1, field2, ..."]),
1457 WarnFollowing, EncodeCrossCrate::Yes
1458 ),
1459 rustc_attr!(
1460 TEST, rustc_abi, Normal, template!(List: &["field1, field2, ..."]),
1461 WarnFollowing, EncodeCrossCrate::No
1462 ),
1463 rustc_attr!(
1464 TEST, rustc_regions, Normal, template!(Word),
1465 WarnFollowing, EncodeCrossCrate::No
1466 ),
1467 rustc_attr!(
1468 TEST, rustc_delayed_bug_from_inside_query, Normal,
1469 template!(Word),
1470 WarnFollowing, EncodeCrossCrate::No
1471 ),
1472 rustc_attr!(
1473 TEST, rustc_dump_user_args, Normal, template!(Word),
1474 WarnFollowing, EncodeCrossCrate::No
1475 ),
1476 rustc_attr!(
1477 TEST, rustc_evaluate_where_clauses, Normal, template!(Word), WarnFollowing,
1478 EncodeCrossCrate::Yes
1479 ),
1480 rustc_attr!(
1481 TEST, rustc_if_this_changed, Normal, template!(Word, List: &["DepNode"]), DuplicatesOk,
1482 EncodeCrossCrate::No
1483 ),
1484 rustc_attr!(
1485 TEST, rustc_then_this_would_need, Normal, template!(List: &["DepNode"]), DuplicatesOk,
1486 EncodeCrossCrate::No
1487 ),
1488 rustc_attr!(
1489 TEST, rustc_clean, Normal,
1490 template!(List: &[r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#]),
1491 DuplicatesOk, EncodeCrossCrate::No
1492 ),
1493 rustc_attr!(
1494 TEST, rustc_partition_reused, Normal,
1495 template!(List: &[r#"cfg = "...", module = "...""#]), DuplicatesOk, EncodeCrossCrate::No
1496 ),
1497 rustc_attr!(
1498 TEST, rustc_partition_codegened, Normal,
1499 template!(List: &[r#"cfg = "...", module = "...""#]), DuplicatesOk, EncodeCrossCrate::No
1500 ),
1501 rustc_attr!(
1502 TEST, rustc_expected_cgu_reuse, Normal,
1503 template!(List: &[r#"cfg = "...", module = "...", kind = "...""#]), DuplicatesOk,
1504 EncodeCrossCrate::No
1505 ),
1506 rustc_attr!(
1507 TEST, rustc_symbol_name, Normal, template!(Word),
1508 WarnFollowing, EncodeCrossCrate::No
1509 ),
1510 rustc_attr!(
1511 TEST, rustc_def_path, Normal, template!(Word),
1512 WarnFollowing, EncodeCrossCrate::No
1513 ),
1514 rustc_attr!(
1515 TEST, rustc_mir, Normal, template!(List: &["arg1, arg2, ..."]),
1516 DuplicatesOk, EncodeCrossCrate::Yes
1517 ),
1518 gated!(
1519 custom_mir, Normal, template!(List: &[r#"dialect = "...", phase = "...""#]),
1520 ErrorFollowing, EncodeCrossCrate::No,
1521 "the `#[custom_mir]` attribute is just used for the Rust test suite",
1522 ),
1523 rustc_attr!(
1524 TEST, rustc_dump_item_bounds, Normal, template!(Word),
1525 WarnFollowing, EncodeCrossCrate::No
1526 ),
1527 rustc_attr!(
1528 TEST, rustc_dump_predicates, Normal, template!(Word),
1529 WarnFollowing, EncodeCrossCrate::No
1530 ),
1531 rustc_attr!(
1532 TEST, rustc_dump_def_parents, Normal, template!(Word),
1533 WarnFollowing, EncodeCrossCrate::No
1534 ),
1535 rustc_attr!(
1536 TEST, rustc_dump_object_lifetime_defaults, Normal, template!(Word),
1537 WarnFollowing, EncodeCrossCrate::No
1538 ),
1539 rustc_attr!(
1540 TEST, rustc_dump_vtable, Normal, template!(Word),
1541 WarnFollowing, EncodeCrossCrate::No
1542 ),
1543 rustc_attr!(
1544 TEST, rustc_dummy, Normal, template!(Word /* doesn't matter*/),
1545 DuplicatesOk, EncodeCrossCrate::No
1546 ),
1547 rustc_attr!(
1548 TEST, pattern_complexity_limit, CrateLevel, template!(NameValueStr: "N"),
1549 ErrorFollowing, EncodeCrossCrate::No,
1550 ),
763 rustc_attr!(TEST, rustc_effective_visibility),
764 rustc_attr!(TEST, rustc_dump_inferred_outlives),
765 rustc_attr!(TEST, rustc_capture_analysis),
766 rustc_attr!(TEST, rustc_insignificant_dtor),
767 rustc_attr!(TEST, rustc_no_implicit_bounds),
768 rustc_attr!(TEST, rustc_strict_coherence),
769 rustc_attr!(TEST, rustc_dump_variances),
770 rustc_attr!(TEST, rustc_dump_variances_of_opaques),
771 rustc_attr!(TEST, rustc_hidden_type_of_opaques),
772 rustc_attr!(TEST, rustc_layout),
773 rustc_attr!(TEST, rustc_abi),
774 rustc_attr!(TEST, rustc_regions),
775 rustc_attr!(TEST, rustc_delayed_bug_from_inside_query),
776 rustc_attr!(TEST, rustc_dump_user_args),
777 rustc_attr!(TEST, rustc_evaluate_where_clauses),
778 rustc_attr!(TEST, rustc_if_this_changed),
779 rustc_attr!(TEST, rustc_then_this_would_need),
780 rustc_attr!(TEST, rustc_clean),
781 rustc_attr!(TEST, rustc_partition_reused),
782 rustc_attr!(TEST, rustc_partition_codegened),
783 rustc_attr!(TEST, rustc_expected_cgu_reuse),
784 rustc_attr!(TEST, rustc_symbol_name),
785 rustc_attr!(TEST, rustc_def_path),
786 rustc_attr!(TEST, rustc_mir),
787 gated!(custom_mir,"the `#[custom_mir]` attribute is just used for the Rust test suite"),
788 rustc_attr!(TEST, rustc_dump_item_bounds),
789 rustc_attr!(TEST, rustc_dump_predicates),
790 rustc_attr!(TEST, rustc_dump_def_parents),
791 rustc_attr!(TEST, rustc_dump_object_lifetime_defaults),
792 rustc_attr!(TEST, rustc_dump_vtable),
793 rustc_attr!(TEST, rustc_dummy),
794 rustc_attr!(TEST, pattern_complexity_limit),
1551795];
1552796
1553797pub fn is_builtin_attr_name(name: Symbol) -> bool {
1554798 BUILTIN_ATTRIBUTE_MAP.get(&name).is_some()
1555799}
1556800
1557/// Whether this builtin attribute is encoded cross crate.
1558/// This means it can be used cross crate.
1559pub fn encode_cross_crate(name: Symbol) -> bool {
1560 if let Some(attr) = BUILTIN_ATTRIBUTE_MAP.get(&name) {
1561 attr.encode_cross_crate == EncodeCrossCrate::Yes
1562 } else {
1563 true
1564 }
1565}
1566
1567pub fn is_valid_for_get_attr(name: Symbol) -> bool {
1568 BUILTIN_ATTRIBUTE_MAP.get(&name).is_some_and(|attr| match attr.duplicates {
1569 WarnFollowing | ErrorFollowing | ErrorPreceding | FutureWarnFollowing
1570 | FutureWarnPreceding => true,
1571 DuplicatesOk | WarnFollowingWordOnly => false,
1572 })
1573}
1574
1575801pub static BUILTIN_ATTRIBUTE_MAP: LazyLock<FxHashMap<Symbol, &BuiltinAttribute>> =
1576802 LazyLock::new(|| {
1577803 let mut map = FxHashMap::default();
compiler/rustc_feature/src/lib.rs+3-4
......@@ -129,10 +129,9 @@ pub fn find_feature_issue(feature: Symbol, issue: GateIssue) -> Option<NonZero<u
129129
130130pub use accepted::ACCEPTED_LANG_FEATURES;
131131pub use builtin_attrs::{
132 AttrSuggestionStyle, AttributeDuplicates, AttributeGate, AttributeSafety, AttributeTemplate,
133 AttributeType, BUILTIN_ATTRIBUTE_MAP, BUILTIN_ATTRIBUTES, BuiltinAttribute, GatedCfg,
134 encode_cross_crate, find_gated_cfg, is_builtin_attr_name, is_stable_diagnostic_attribute,
135 is_valid_for_get_attr,
132 AttrSuggestionStyle, AttributeGate, AttributeSafety, AttributeTemplate, BUILTIN_ATTRIBUTE_MAP,
133 BUILTIN_ATTRIBUTES, BuiltinAttribute, GatedCfg, find_gated_cfg, is_builtin_attr_name,
134 is_stable_diagnostic_attribute,
136135};
137136pub use removed::REMOVED_LANG_FEATURES;
138137pub use unstable::{
compiler/rustc_lint/src/early/diagnostics/check_cfg.rs+5-3
......@@ -438,10 +438,10 @@ pub(super) fn unexpected_cfg_value(
438438 }
439439}
440440
441/// Ordering of the output is not stable, use this only in diagnostic code.
442441fn possible_well_known_names_for_cfg_value(sess: &Session, value: Symbol) -> Vec<Symbol> {
443442 #[allow(rustc::potential_query_instability)]
444 sess.psess
443 let mut names = sess
444 .psess
445445 .check_config
446446 .well_known_names
447447 .iter()
......@@ -454,5 +454,7 @@ fn possible_well_known_names_for_cfg_value(sess: &Session, value: Symbol) -> Vec
454454 .unwrap_or_default()
455455 })
456456 .copied()
457 .collect()
457 .collect::<Vec<_>>();
458 names.sort_by(|a, b| a.as_str().cmp(b.as_str()));
459 names
458460}
compiler/rustc_metadata/src/native_libs.rs+5-3
......@@ -224,7 +224,7 @@ impl<'tcx> Collector<'tcx> {
224224 let dll_imports = match attr.kind {
225225 NativeLibKind::RawDylib { .. } => foreign_items
226226 .iter()
227 .map(|&child_item| {
227 .filter_map(|&child_item| {
228228 self.build_dll_import(
229229 abi,
230230 attr.import_name_type.map(|(import_name_type, _)| import_name_type),
......@@ -388,7 +388,7 @@ impl<'tcx> Collector<'tcx> {
388388 abi: ExternAbi,
389389 import_name_type: Option<PeImportNameType>,
390390 item: DefId,
391 ) -> DllImport {
391 ) -> Option<DllImport> {
392392 let span = self.tcx.def_span(item);
393393
394394 // This `extern` block should have been checked for general ABI support before, but let's
......@@ -465,6 +465,8 @@ impl<'tcx> Collector<'tcx> {
465465 } else {
466466 DllImportSymbolType::Static
467467 }
468 } else if def_kind == DefKind::ForeignTy {
469 return None;
468470 } else {
469471 bug!("Unexpected type for raw-dylib: {}", def_kind.descr(item));
470472 };
......@@ -482,6 +484,6 @@ impl<'tcx> Collector<'tcx> {
482484 }
483485 };
484486
485 DllImport { name, import_name_type, calling_convention, span, symbol_type, size }
487 Some(DllImport { name, import_name_type, calling_convention, span, symbol_type, size })
486488 }
487489}
compiler/rustc_metadata/src/rmeta/encoder.rs-4
......@@ -864,10 +864,6 @@ fn analyze_attr(attr: &hir::Attribute, state: &mut AnalyzeAttrState<'_>) -> bool
864864 && p.encode_cross_crate() == EncodeCrossCrate::No
865865 {
866866 // Attributes not marked encode-cross-crate don't need to be encoded for downstream crates.
867 } else if let Some(name) = attr.name()
868 && !rustc_feature::encode_cross_crate(name)
869 {
870 // Attributes not marked encode-cross-crate don't need to be encoded for downstream crates.
871867 } else if let hir::Attribute::Parsed(AttributeKind::DocComment { .. }) = attr {
872868 // We keep all doc comments reachable to rustdoc because they might be "imported" into
873869 // downstream crates if they use `#[doc(inline)]` to copy an item's documentation into
compiler/rustc_middle/src/query/plumbing.rs-24
......@@ -464,30 +464,6 @@ macro_rules! define_callbacks {
464464 )*
465465 }
466466 }
467
468 pub fn def_kind(&self, tcx: TyCtxt<'tcx>) -> Option<DefKind> {
469 // This is used to reduce code generation as it
470 // can be reused for queries with the same key type.
471 fn inner<'tcx>(key: &impl $crate::query::QueryKey, tcx: TyCtxt<'tcx>)
472 -> Option<DefKind>
473 {
474 key
475 .key_as_def_id()
476 .and_then(|def_id| def_id.as_local())
477 .map(|def_id| tcx.def_kind(def_id))
478 }
479
480 if let TaggedQueryKey::def_kind(..) = self {
481 // Try to avoid infinite recursion.
482 return None
483 }
484
485 match self {
486 $(
487 TaggedQueryKey::$name(key) => inner(key, tcx),
488 )*
489 }
490 }
491467 }
492468
493469 /// Holds a `QueryVTable` for each query.
compiler/rustc_middle/src/ty/mod.rs+2-7
......@@ -1725,13 +1725,8 @@ impl<'tcx> TyCtxt<'tcx> {
17251725
17261726 #[deprecated = "Though there are valid usecases for this method, especially when your attribute is not a parsed attribute, usually you want to call rustc_hir::find_attr! instead."]
17271727 pub fn get_attr(self, did: impl Into<DefId>, attr: Symbol) -> Option<&'tcx hir::Attribute> {
1728 if cfg!(debug_assertions) && !rustc_feature::is_valid_for_get_attr(attr) {
1729 let did: DefId = did.into();
1730 bug!("get_attr: unexpected called with DefId `{:?}`, attr `{:?}`", did, attr);
1731 } else {
1732 #[allow(deprecated)]
1733 self.get_attrs(did, attr).next()
1734 }
1728 #[allow(deprecated)]
1729 self.get_attrs(did, attr).next()
17351730 }
17361731
17371732 /// Determines whether an item is annotated with an attribute.
compiler/rustc_passes/src/check_attr.rs+1-123
......@@ -6,17 +6,15 @@
66//! item.
77
88use std::cell::Cell;
9use std::collections::hash_map::Entry;
109use std::slice;
1110
1211use rustc_abi::ExternAbi;
1312use rustc_ast::ast;
1413use rustc_attr_parsing::{AttributeParser, Late};
15use rustc_data_structures::fx::FxHashMap;
1614use rustc_data_structures::thin_vec::ThinVec;
1715use rustc_data_structures::unord::UnordMap;
1816use rustc_errors::{DiagCtxtHandle, IntoDiagArg, MultiSpan, msg};
19use rustc_feature::{AttributeDuplicates, AttributeType, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute};
17use rustc_feature::BUILTIN_ATTRIBUTE_MAP;
2018use rustc_hir::attrs::diagnostic::Directive;
2119use rustc_hir::attrs::{
2220 AttributeKind, CrateType, DocAttribute, DocInline, EiiDecl, EiiImpl, EiiImplResolution,
......@@ -137,7 +135,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
137135 target: Target,
138136 item: Option<ItemLike<'_>>,
139137 ) {
140 let mut seen = FxHashMap::default();
141138 let attrs = self.tcx.hir_attrs(hir_id);
142139 for attr in attrs {
143140 match attr {
......@@ -404,64 +401,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
404401 }
405402 }
406403
407 if hir_id != CRATE_HIR_ID {
408 match attr {
409 Attribute::Parsed(_) => { /* Already validated. */ }
410 Attribute::Unparsed(attr) => {
411 // FIXME(jdonszelmann): remove once all crate-level attrs are parsed and caught by
412 // the above
413 if let Some(BuiltinAttribute { type_: AttributeType::CrateLevel, .. }) =
414 attr.path
415 .segments
416 .first()
417 .and_then(|name| BUILTIN_ATTRIBUTE_MAP.get(&name))
418 {
419 match attr.style {
420 ast::AttrStyle::Outer => {
421 let attr_span = attr.span;
422 let bang_position = self
423 .tcx
424 .sess
425 .source_map()
426 .span_until_char(attr_span, '[')
427 .shrink_to_hi();
428
429 self.tcx.emit_node_span_lint(
430 UNUSED_ATTRIBUTES,
431 hir_id,
432 attr.span,
433 errors::OuterCrateLevelAttr {
434 suggestion: errors::OuterCrateLevelAttrSuggestion {
435 bang_position,
436 },
437 },
438 )
439 }
440 ast::AttrStyle::Inner => self.tcx.emit_node_span_lint(
441 UNUSED_ATTRIBUTES,
442 hir_id,
443 attr.span,
444 errors::InnerCrateLevelAttr,
445 ),
446 }
447 }
448 }
449 }
450 }
451
452 if let Attribute::Unparsed(unparsed_attr) = attr
453 && let Some(BuiltinAttribute { duplicates, .. }) =
454 attr.name().and_then(|name| BUILTIN_ATTRIBUTE_MAP.get(&name))
455 {
456 check_duplicates(
457 self.tcx,
458 unparsed_attr.span,
459 attr,
460 hir_id,
461 *duplicates,
462 &mut seen,
463 );
464 }
465404 self.check_unused_attribute(hir_id, attr)
466405 }
467406
......@@ -1994,67 +1933,6 @@ pub(crate) fn provide(providers: &mut Providers) {
19941933 *providers = Providers { check_mod_attrs, ..*providers };
19951934}
19961935
1997// FIXME(jdonszelmann): remove, check during parsing
1998fn check_duplicates(
1999 tcx: TyCtxt<'_>,
2000 attr_span: Span,
2001 attr: &Attribute,
2002 hir_id: HirId,
2003 duplicates: AttributeDuplicates,
2004 seen: &mut FxHashMap<Symbol, Span>,
2005) {
2006 use AttributeDuplicates::*;
2007 if matches!(duplicates, WarnFollowingWordOnly) && !attr.is_word() {
2008 return;
2009 }
2010 let attr_name = attr.name().unwrap();
2011 match duplicates {
2012 DuplicatesOk => {}
2013 WarnFollowing | FutureWarnFollowing | WarnFollowingWordOnly | FutureWarnPreceding => {
2014 match seen.entry(attr_name) {
2015 Entry::Occupied(mut entry) => {
2016 let (this, other) = if matches!(duplicates, FutureWarnPreceding) {
2017 let to_remove = entry.insert(attr_span);
2018 (to_remove, attr_span)
2019 } else {
2020 (attr_span, *entry.get())
2021 };
2022 tcx.emit_node_span_lint(
2023 UNUSED_ATTRIBUTES,
2024 hir_id,
2025 this,
2026 errors::UnusedDuplicate {
2027 this,
2028 other,
2029 warning: matches!(
2030 duplicates,
2031 FutureWarnFollowing | FutureWarnPreceding
2032 ),
2033 },
2034 );
2035 }
2036 Entry::Vacant(entry) => {
2037 entry.insert(attr_span);
2038 }
2039 }
2040 }
2041 ErrorFollowing | ErrorPreceding => match seen.entry(attr_name) {
2042 Entry::Occupied(mut entry) => {
2043 let (this, other) = if matches!(duplicates, ErrorPreceding) {
2044 let to_remove = entry.insert(attr_span);
2045 (to_remove, attr_span)
2046 } else {
2047 (attr_span, *entry.get())
2048 };
2049 tcx.dcx().emit_err(errors::UnusedMultiple { this, other, name: attr_name });
2050 }
2051 Entry::Vacant(entry) => {
2052 entry.insert(attr_span);
2053 }
2054 },
2055 }
2056}
2057
20581936fn doc_fake_variadic_is_allowed_self_ty(self_ty: &hir::Ty<'_>) -> bool {
20591937 matches!(&self_ty.kind, hir::TyKind::Tup([_]))
20601938 || if let hir::TyKind::FnPtr(fn_ptr_ty) = &self_ty.kind {
compiler/rustc_passes/src/errors.rs-24
......@@ -326,30 +326,6 @@ pub(crate) struct InvalidMayDangle {
326326 pub attr_span: Span,
327327}
328328
329#[derive(Diagnostic)]
330#[diag("unused attribute")]
331pub(crate) struct UnusedDuplicate {
332 #[suggestion("remove this attribute", code = "", applicability = "machine-applicable")]
333 pub this: Span,
334 #[note("attribute also specified here")]
335 pub other: Span,
336 #[warning(
337 "this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
338 )]
339 pub warning: bool,
340}
341
342#[derive(Diagnostic)]
343#[diag("multiple `{$name}` attributes")]
344pub(crate) struct UnusedMultiple {
345 #[primary_span]
346 #[suggestion("remove this attribute", code = "", applicability = "machine-applicable")]
347 pub this: Span,
348 #[note("attribute also specified here")]
349 pub other: Span,
350 pub name: Symbol,
351}
352
353329#[derive(Diagnostic)]
354330#[diag("this `#[deprecated]` annotation has no effect")]
355331pub(crate) struct DeprecatedAnnotationHasNoEffect {
compiler/rustc_passes/src/reachable.rs+15-7
......@@ -214,18 +214,26 @@ impl<'tcx> ReachableContext<'tcx> {
214214 self.visit_const_item_rhs(init);
215215 }
216216 hir::ItemKind::Const(_, _, _, init) => {
217 // Only things actually ending up in the final constant value are reachable
218 // for codegen. Everything else is only needed during const-eval, so even if
219 // const-eval happens in a downstream crate, all they need is
220 // `mir_for_ctfe`.
217 if self.tcx.generics_of(item.owner_id).own_requires_monomorphization() {
218 // In this case, we don't want to evaluate the const initializer.
219 // In lieu of that, we have to consider everything mentioned in it
220 // as reachable, since it *may* end up in the final value.
221 self.visit_const_item_rhs(init);
222 return;
223 }
224
221225 match self.tcx.const_eval_poly_to_alloc(item.owner_id.def_id.into()) {
222226 Ok(alloc) => {
227 // Only things actually ending up in the final constant value are
228 // reachable for codegen. Everything else is only needed during
229 // const-eval, so even if const-eval happens in a downstream crate,
230 // all they need is `mir_for_ctfe`.
223231 let alloc = self.tcx.global_alloc(alloc.alloc_id).unwrap_memory();
224232 self.propagate_from_alloc(alloc);
225233 }
226 // We can't figure out which value the constant will evaluate to. In
227 // lieu of that, we have to consider everything mentioned in the const
228 // initializer reachable, since it *may* end up in the final value.
234 // Trivially unsatisfiable bounds on the item prevented us from
235 // normalizing the initializer. Similar to the other case, we have to
236 // everything mentioned in it as reachable.
229237 Err(ErrorHandled::TooGeneric(_)) => self.visit_const_item_rhs(init),
230238 // If there was an error evaluating the const, nothing can be reachable
231239 // via it, and anyway compilation will fail.
compiler/rustc_query_impl/src/job.rs+91-79
......@@ -229,6 +229,80 @@ fn connected_to_root<'tcx>(
229229 false
230230}
231231
232/// Processes a found query cycle into a `Cycle`
233fn process_cycle<'tcx>(job_map: &QueryJobMap<'tcx>, stack: Vec<(Span, QueryJobId)>) -> Cycle<'tcx> {
234 // The stack is a vector of pairs of spans and queries; reverse it so that
235 // the earlier entries require later entries
236 let (mut spans, queries): (Vec<_>, Vec<_>) = stack.into_iter().rev().unzip();
237
238 // Shift the spans so that queries are matched with the span for their waitee
239 spans.rotate_right(1);
240
241 // Zip them back together
242 let mut stack: Vec<_> = iter::zip(spans, queries).collect();
243
244 struct EntryPoint {
245 query_in_cycle: QueryJobId,
246 query_waiting_on_cycle: Option<(Span, QueryJobId)>,
247 }
248
249 // Find the queries in the cycle which are
250 // connected to queries outside the cycle
251 let entry_points = stack
252 .iter()
253 .filter_map(|&(_, query_in_cycle)| {
254 let mut entrypoint = false;
255 let mut query_waiting_on_cycle = None;
256
257 // Find a direct waiter who leads to the root
258 for abstracted_waiter in abstracted_waiters_of(job_map, query_in_cycle) {
259 let Some(parent) = abstracted_waiter.parent else {
260 // The query in the cycle is directly connected to root.
261 entrypoint = true;
262 continue;
263 };
264
265 // Mark all the other queries in the cycle as already visited,
266 // so paths to the root through the cycle itself won't count.
267 let mut visited = FxHashSet::from_iter(stack.iter().map(|q| q.1));
268
269 if connected_to_root(job_map, parent, &mut visited) {
270 query_waiting_on_cycle = Some((abstracted_waiter.span, parent));
271 entrypoint = true;
272 break;
273 }
274 }
275
276 entrypoint.then_some(EntryPoint { query_in_cycle, query_waiting_on_cycle })
277 })
278 .collect::<Vec<EntryPoint>>();
279
280 // Pick an entry point, preferring ones with waiters
281 let entry_point = entry_points
282 .iter()
283 .find(|entry_point| entry_point.query_waiting_on_cycle.is_some())
284 .unwrap_or(&entry_points[0]);
285
286 // Shift the stack so that our entry point is first
287 let entry_point_pos = stack.iter().position(|(_, query)| *query == entry_point.query_in_cycle);
288 if let Some(pos) = entry_point_pos {
289 stack.rotate_left(pos);
290 }
291
292 let usage = entry_point
293 .query_waiting_on_cycle
294 .map(|(span, job)| QueryStackFrame { span, tagged_key: job_map.tagged_key_of(job) });
295
296 // Create the cycle error
297 Cycle {
298 usage,
299 frames: stack
300 .iter()
301 .map(|&(span, job)| QueryStackFrame { span, tagged_key: job_map.tagged_key_of(job) })
302 .collect(),
303 }
304}
305
232306/// Looks for a query cycle using the last query in `jobs`.
233307/// If a cycle is found, all queries in the cycle is removed from `jobs` and
234308/// the function return true.
......@@ -245,16 +319,6 @@ fn remove_cycle<'tcx>(
245319 if let ControlFlow::Break(resumable) =
246320 find_cycle(job_map, jobs.pop().unwrap(), DUMMY_SP, &mut stack, &mut visited)
247321 {
248 // The stack is a vector of pairs of spans and queries; reverse it so that
249 // the earlier entries require later entries
250 let (mut spans, queries): (Vec<_>, Vec<_>) = stack.into_iter().rev().unzip();
251
252 // Shift the spans so that queries are matched with the span for their waitee
253 spans.rotate_right(1);
254
255 // Zip them back together
256 let mut stack: Vec<_> = iter::zip(spans, queries).collect();
257
258322 // Remove the queries in our cycle from the list of jobs to look at
259323 for r in &stack {
260324 if let Some(pos) = jobs.iter().position(|j| j == &r.1) {
......@@ -262,70 +326,8 @@ fn remove_cycle<'tcx>(
262326 }
263327 }
264328
265 struct EntryPoint {
266 query_in_cycle: QueryJobId,
267 query_waiting_on_cycle: Option<(Span, QueryJobId)>,
268 }
269
270 // Find the queries in the cycle which are
271 // connected to queries outside the cycle
272 let entry_points = stack
273 .iter()
274 .filter_map(|&(_, query_in_cycle)| {
275 let mut entrypoint = false;
276 let mut query_waiting_on_cycle = None;
277
278 // Find a direct waiter who leads to the root
279 for abstracted_waiter in abstracted_waiters_of(job_map, query_in_cycle) {
280 let Some(parent) = abstracted_waiter.parent else {
281 // The query in the cycle is directly connected to root.
282 entrypoint = true;
283 continue;
284 };
285
286 // Mark all the other queries in the cycle as already visited,
287 // so paths to the root through the cycle itself won't count.
288 let mut visited = FxHashSet::from_iter(stack.iter().map(|q| q.1));
289
290 if connected_to_root(job_map, parent, &mut visited) {
291 query_waiting_on_cycle = Some((abstracted_waiter.span, parent));
292 entrypoint = true;
293 break;
294 }
295 }
296
297 entrypoint.then_some(EntryPoint { query_in_cycle, query_waiting_on_cycle })
298 })
299 .collect::<Vec<EntryPoint>>();
300
301 // Pick an entry point, preferring ones with waiters
302 let entry_point = entry_points
303 .iter()
304 .find(|entry_point| entry_point.query_waiting_on_cycle.is_some())
305 .unwrap_or(&entry_points[0]);
306
307 // Shift the stack so that our entry point is first
308 let entry_point_pos =
309 stack.iter().position(|(_, query)| *query == entry_point.query_in_cycle);
310 if let Some(pos) = entry_point_pos {
311 stack.rotate_left(pos);
312 }
313
314 let usage = entry_point
315 .query_waiting_on_cycle
316 .map(|(span, job)| QueryStackFrame { span, tagged_key: job_map.tagged_key_of(job) });
317
318329 // Create the cycle error
319 let error = Cycle {
320 usage,
321 frames: stack
322 .iter()
323 .map(|&(span, job)| QueryStackFrame {
324 span,
325 tagged_key: job_map.tagged_key_of(job),
326 })
327 .collect(),
328 };
330 let error = process_cycle(job_map, stack);
329331
330332 // We unwrap `resumable` here since there must always be one
331333 // edge which is resumable / waited using a query latch
......@@ -481,13 +483,23 @@ pub(crate) fn create_cycle_error<'tcx>(
481483 usage: usage.tagged_key.description(tcx),
482484 });
483485
484 let alias = if frames
485 .iter()
486 .all(|frame| frame.tagged_key.def_kind(tcx) == Some(DefKind::TyAlias))
487 {
486 let is_all_def_kind = |def_kind| {
487 // Trivial type alias and trait alias cycles consists of `type_of` and
488 // `explicit_implied_predicates_of` queries, so we just check just these here.
489 frames.iter().all(|frame| match frame.tagged_key {
490 TaggedQueryKey::type_of(def_id)
491 | TaggedQueryKey::explicit_implied_predicates_of(def_id)
492 if tcx.def_kind(def_id) == def_kind =>
493 {
494 true
495 }
496 _ => false,
497 })
498 };
499
500 let alias = if is_all_def_kind(DefKind::TyAlias) {
488501 Some(crate::error::Alias::Ty)
489 } else if frames.iter().all(|frame| frame.tagged_key.def_kind(tcx) == Some(DefKind::TraitAlias))
490 {
502 } else if is_all_def_kind(DefKind::TraitAlias) {
491503 Some(crate::error::Alias::Trait)
492504 } else {
493505 None
library/compiler-builtins/compiler-builtins/src/math/mod.rs+4
......@@ -144,8 +144,12 @@ pub mod partial_availability {
144144 libm_intrinsics! {
145145 fn acos(x: f64) -> f64;
146146 fn acosf(n: f32) -> f32;
147 fn acosh(x: f64) -> f64;
148 fn acoshf(x: f32) -> f32;
147149 fn asin(x: f64) -> f64;
148150 fn asinf(n: f32) -> f32;
151 fn asinh(x: f64) -> f64;
152 fn asinhf(x: f32) -> f32;
149153 fn atan(x: f64) -> f64;
150154 fn atan2(x: f64, y: f64) -> f64;
151155 fn atan2f(a: f32, b: f32) -> f32;
library/core/src/autodiff.md created+157
......@@ -0,0 +1,157 @@
1This module provides support for automatic differentiation. For precise information on
2differences between the `autodiff_forward` and `autodiff_reverse` macros and how to
3use them, see their respective documentation.
4
5## General usage
6
7Autodiff macros can be applied to almost all function definitions, see below for examples.
8They can be applied to functions accepting structs, arrays, slices, vectors, tuples, and more.
9
10It is possible to apply multiple autodiff macros to the same function. As an example, this can
11be helpful to compute the partial derivatives with respect to `x` and `y` independently:
12```rust,ignore (optional component)
13#[autodiff_forward(dsquare1, Dual, Const, Dual)]
14#[autodiff_forward(dsquare2, Const, Dual, Dual)]
15#[autodiff_forward(dsquare3, Active, Active, Active)]
16fn square(x: f64, y: f64) -> f64 {
17 x * x + 2.0 * y
18}
19```
20
21We also support autodiff on functions with generic parameters:
22```rust,ignore (optional component)
23#[autodiff_forward(generic_derivative, Duplicated, Active)]
24fn generic_f<T: std::ops::Mul<Output = T> + Copy>(x: &T) -> T {
25 x * x
26}
27```
28
29or applying autodiff to nested functions:
30```rust,ignore (optional component)
31fn outer(x: f64) -> f64 {
32 #[autodiff_forward(inner_derivative, Dual, Const)]
33 fn inner(y: f64) -> f64 {
34 y * y
35 }
36 inner_derivative(x, 1.0)
37}
38
39fn main() {
40 assert_eq!(outer(3.14), 6.28);
41}
42```
43The generated function will be available in the same scope as the function differentiated, and
44have the same private/pub usability.
45
46## Traits and impls
47Autodiff macros can be used in multiple ways in combination with traits:
48```rust,ignore (optional component)
49struct Foo {
50 a: f64,
51}
52
53trait MyTrait {
54 #[autodiff_reverse(df, Const, Active, Active)]
55 fn f(&self, x: f64) -> f64;
56}
57
58impl MyTrait for Foo {
59 fn f(&self, x: f64) -> f64 {
60 x.sin()
61 }
62}
63
64fn main() {
65 let foo = Foo { a: 3.0f64 };
66 assert_eq!(foo.f(2.0), 2.0_f64.sin());
67 assert_eq!(foo.df(2.0, 1.0).1, 2.0_f64.cos());
68}
69```
70In this case `df` will be the default implementation provided by the library who provided the
71trait. A user implementing `MyTrait` could then decide to use the default implementation of
72`df`, or overwrite it with a custom implementation as a form of "custom derivatives".
73
74On the other hand, a function generated by either autodiff macro can also be used to implement a
75trait:
76```rust,ignore (optional component)
77struct Foo {
78 a: f64,
79}
80
81trait MyTrait {
82 fn f(&self, x: f64) -> f64;
83 fn df(&self, x: f64, seed: f64) -> (f64, f64);
84}
85
86impl MyTrait for Foo {
87 #[autodiff_reverse(df, Const, Active, Active)]
88 fn f(&self, x: f64) -> f64 {
89 self.a * 0.25 * (x * x - 1.0 - 2.0 * x.ln())
90 }
91}
92```
93
94Simple `impl` blocks without traits are also supported. Differentiating with respect to the
95implemented struct will then require the use of a "shadow struct" to hold the derivatives of the
96struct fields:
97
98```rust,ignore (optional component)
99struct OptProblem {
100 a: f64,
101 b: f64,
102}
103
104impl OptProblem {
105 #[autodiff_reverse(d_objective, Duplicated, Duplicated, Duplicated)]
106 fn objective(&self, x: &[f64], out: &mut f64) {
107 *out = self.a + x[0].sqrt() * self.b
108 }
109}
110fn main() {
111 let p = OptProblem { a: 1., b: 2. };
112 let mut p_shadow = OptProblem { a: 0., b: 0. };
113 let mut dx = [0.0];
114 let mut out = 0.0;
115 let mut dout = 1.0;
116
117 p.d_objective(&mut p_shadow, &x, &mut dx, &mut out, &mut dout);
118}
119```
120
121## Higher-order derivatives
122Finally, it is possible to generate higher-order derivatives (e.g. Hessian) by applying an
123autodiff macro to a function that is already generated by an autodiff macro, via a thin wrapper.
124The following example uses Forward mode over Reverse mode
125
126```rust,ignore (optional component)
127#[autodiff_reverse(df, Duplicated, Duplicated)]
128fn f(x: &[f64;2], y: &mut f64) {
129 *y = x[0] * x[0] + x[1] * x[0]
130}
131
132#[autodiff_forward(h, Dual, Dual, Dual, Dual)]
133fn wrapper(x: &[f64;2], dx: &mut [f64;2], y: &mut f64, dy: &mut f64) {
134 df(x, dx, y, dy);
135}
136
137fn main() {
138 let mut y = 0.0;
139 let x = [2.0, 2.0];
140
141 let mut dy = 0.0;
142 let mut dx = [1.0, 0.0];
143
144 let mut bx = [0.0, 0.0];
145 let mut by = 1.0;
146 let mut dbx = [0.0, 0.0];
147 let mut dby = 0.0;
148 h(&x, &mut dx, &mut bx, &mut dbx, &mut y, &mut dy, &mut by, &mut dby);
149 assert_eq!(&dbx, [2.0, 1.0]);
150}
151```
152
153## Current limitations:
154
155- Differentiating a function which accepts a `dyn Trait` is currently not supported.
156- Builds without `lto="fat"` are not yet supported.
157- Builds in debug mode are currently more likely to fail compilation.
library/core/src/intrinsics/simd/scalable.rs-6
......@@ -19,7 +19,6 @@
1919/// * Not be `NaN`
2020/// * Not be infinite
2121/// * Be representable in the return type, after truncating off its fractional part
22#[cfg(target_arch = "aarch64")]
2322#[rustc_intrinsic]
2423#[rustc_nounwind]
2524pub unsafe fn sve_cast<T, U>(x: T) -> U;
......@@ -31,7 +30,6 @@ pub unsafe fn sve_cast<T, U>(x: T) -> U;
3130/// type `SVec`.
3231///
3332/// Corresponds to Clang's `__builtin_sve_svcreate2*` builtins.
34#[cfg(target_arch = "aarch64")]
3533#[rustc_nounwind]
3634#[rustc_intrinsic]
3735pub unsafe fn sve_tuple_create2<SVec, SVecTup>(x0: SVec, x1: SVec) -> SVecTup;
......@@ -43,7 +41,6 @@ pub unsafe fn sve_tuple_create2<SVec, SVecTup>(x0: SVec, x1: SVec) -> SVecTup;
4341/// type `SVec`.
4442///
4543/// Corresponds to Clang's `__builtin_sve_svcreate3*` builtins.
46#[cfg(target_arch = "aarch64")]
4744#[rustc_intrinsic]
4845#[rustc_nounwind]
4946pub unsafe fn sve_tuple_create3<SVec, SVecTup>(x0: SVec, x1: SVec, x2: SVec) -> SVecTup;
......@@ -55,7 +52,6 @@ pub unsafe fn sve_tuple_create3<SVec, SVecTup>(x0: SVec, x1: SVec, x2: SVec) ->
5552/// type `SVec`.
5653///
5754/// Corresponds to Clang's `__builtin_sve_svcreate4*` builtins.
58#[cfg(target_arch = "aarch64")]
5955#[rustc_intrinsic]
6056#[rustc_nounwind]
6157pub unsafe fn sve_tuple_create4<SVec, SVecTup>(x0: SVec, x1: SVec, x2: SVec, x3: SVec) -> SVecTup;
......@@ -71,7 +67,6 @@ pub unsafe fn sve_tuple_create4<SVec, SVecTup>(x0: SVec, x1: SVec, x2: SVec, x3:
7167/// # Safety
7268///
7369/// `IDX` must be in-bounds of the tuple.
74#[cfg(target_arch = "aarch64")]
7570#[rustc_intrinsic]
7671#[rustc_nounwind]
7772pub unsafe fn sve_tuple_get<SVecTup, SVec, const IDX: i32>(tuple: SVecTup) -> SVec;
......@@ -87,7 +82,6 @@ pub unsafe fn sve_tuple_get<SVecTup, SVec, const IDX: i32>(tuple: SVecTup) -> SV
8782/// # Safety
8883///
8984/// `IDX` must be in-bounds of the tuple.
90#[cfg(target_arch = "aarch64")]
9185#[rustc_intrinsic]
9286#[rustc_nounwind]
9387pub unsafe fn sve_tuple_set<SVecTup, SVec, const IDX: i32>(tuple: SVecTup, x: SVec) -> SVecTup;
library/core/src/iter/range.rs+4-2
......@@ -513,7 +513,8 @@ macro_rules! step_nonzero_impls {
513513 $(
514514 #[allow(unreachable_patterns)]
515515 #[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
516 impl Step for NonZero<$narrower> {
516 #[rustc_const_unstable(feature = "step_trait", issue = "42168")]
517 impl const Step for NonZero<$narrower> {
517518 step_nonzero_identical_methods!($narrower);
518519
519520 #[inline]
......@@ -538,7 +539,8 @@ macro_rules! step_nonzero_impls {
538539 $(
539540 #[allow(unreachable_patterns)]
540541 #[unstable(feature = "step_trait", reason = "recently redesigned", issue = "42168")]
541 impl Step for NonZero<$wider> {
542 #[rustc_const_unstable(feature = "step_trait", issue = "42168")]
543 impl const Step for NonZero<$wider> {
542544 step_nonzero_identical_methods!($wider);
543545
544546 #[inline]
library/core/src/lib.rs+1-1
......@@ -227,7 +227,7 @@ mod sealed {
227227
228228// We don't export this through #[macro_export] for now, to avoid breakage.
229229#[unstable(feature = "autodiff", issue = "124509")]
230/// Unstable module containing the unstable `autodiff` macro.
230#[doc = include_str!("../../core/src/autodiff.md")]
231231pub mod autodiff {
232232 #[unstable(feature = "autodiff", issue = "124509")]
233233 pub use crate::macros::builtin::{autodiff_forward, autodiff_reverse};
library/core/src/num/nonzero.rs+4-2
......@@ -184,7 +184,8 @@ impl_nonzero_auto_trait!(Unpin);
184184impl_nonzero_auto_trait!(UnwindSafe);
185185
186186#[stable(feature = "nonzero", since = "1.28.0")]
187impl<T> Clone for NonZero<T>
187#[rustc_const_unstable(feature = "const_clone", issue = "142757")]
188impl<T> const Clone for NonZero<T>
188189where
189190 T: ZeroablePrimitive,
190191{
......@@ -202,7 +203,8 @@ impl<T> Copy for NonZero<T> where T: ZeroablePrimitive {}
202203
203204#[doc(hidden)]
204205#[unstable(feature = "trivial_clone", issue = "none")]
205unsafe impl<T> TrivialClone for NonZero<T> where T: ZeroablePrimitive {}
206#[rustc_const_unstable(feature = "const_clone", issue = "142757")]
207unsafe impl<T> const TrivialClone for NonZero<T> where T: ZeroablePrimitive {}
206208
207209#[stable(feature = "nonzero", since = "1.28.0")]
208210#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
library/core/src/pin.rs+3-3
......@@ -474,9 +474,9 @@
474474//!
475475//! In an intrusive doubly-linked list, the collection itself does not own the memory in which
476476//! each of its elements is stored. Instead, each client is free to allocate space for elements it
477//! adds to the list in whichever manner it likes, including on the stack! Elements can live on a
478//! stack frame that lives shorter than the collection does provided the elements that live in a
479//! given stack frame are removed from the list before going out of scope.
477//! adds to the list in whichever manner it likes, including on the stack! Elements can be stored
478//! in a stack frame shorter-lived than the collection, provided they are removed from the list
479//! before that frame goes out of scope.
480480//!
481481//! To make such an intrusive data structure work, every element stores pointers to its predecessor
482482//! and successor within its own data, rather than having the list structure itself managing those
library/coretests/tests/cmp.rs+31
......@@ -48,6 +48,37 @@ fn test_ord_min_max_by() {
4848 assert_eq!(cmp::max_by(2, -1, f), 2);
4949}
5050
51// Regression test for #136307 / #139357: ensure compare() receives (v1, v2), not (v2, v1).
52#[test]
53fn min_by_compare_argument_order() {
54 let mut order = vec![];
55 let _ = cmp::min_by(1i32, 2, |a, b| {
56 order.push((*a, *b));
57 a.cmp(b)
58 });
59 assert_eq!(order, [(1, 2)]);
60}
61
62#[test]
63fn max_by_compare_argument_order() {
64 let mut order = vec![];
65 let _ = cmp::max_by(1i32, 2, |a, b| {
66 order.push((*a, *b));
67 a.cmp(b)
68 });
69 assert_eq!(order, [(1, 2)]);
70}
71
72#[test]
73fn minmax_by_compare_argument_order() {
74 let mut order = vec![];
75 let _ = cmp::minmax_by(1i32, 2, |a, b| {
76 order.push((*a, *b));
77 a.cmp(b)
78 });
79 assert_eq!(order, [(1, 2)]);
80}
81
5182#[test]
5283fn test_ord_min_max_by_key() {
5384 let f = |x: &i32| x.abs();
library/coretests/tests/lib.rs+1
......@@ -14,6 +14,7 @@
1414#![feature(char_internals)]
1515#![feature(char_max_len)]
1616#![feature(clone_to_uninit)]
17#![feature(cmp_minmax)]
1718#![feature(const_array)]
1819#![feature(const_bool)]
1920#![feature(const_cell_traits)]
library/std/src/lib.rs+1-1
......@@ -637,7 +637,7 @@ pub mod simd {
637637}
638638
639639#[unstable(feature = "autodiff", issue = "124509")]
640/// This module provides support for automatic differentiation.
640#[doc = include_str!("../../core/src/autodiff.md")]
641641pub mod autodiff {
642642 /// This macro handles automatic differentiation.
643643 pub use core::autodiff::{autodiff_forward, autodiff_reverse};
library/std/src/sys/pal/motor/mod.rs+1-1
......@@ -42,5 +42,5 @@ pub fn unsupported_err() -> io::Error {
4242}
4343
4444pub fn abort_internal() -> ! {
45 core::intrinsics::abort();
45 moto_rt::process::exit(-1)
4646}
license-metadata.json+1-1
......@@ -114,10 +114,10 @@
114114 {
115115 "directories": [],
116116 "files": [
117 "Fira-LICENSE.txt",
117118 "FiraMono-Medium.woff2",
118119 "FiraMono-Regular.woff2",
119120 "FiraSans-Italic.woff2",
120 "FiraSans-LICENSE.txt",
121121 "FiraSans-Medium.woff2",
122122 "FiraSans-MediumItalic.woff2",
123123 "FiraSans-Regular.woff2"
src/bootstrap/src/core/config/config.rs+20-5
......@@ -78,6 +78,7 @@ pub const RUSTC_IF_UNCHANGED_ALLOWED_PATHS: &[&str] = &[
7878 ":!src/rustdoc-json-types",
7979 ":!tests",
8080 ":!triagebot.toml",
81 ":!src/bootstrap/defaults",
8182];
8283
8384/// Global configuration for the entire build and/or bootstrap.
......@@ -2237,11 +2238,7 @@ pub fn download_ci_rustc_commit<'a>(
22372238 });
22382239 match freshness {
22392240 PathFreshness::LastModifiedUpstream { upstream } => upstream,
2240 PathFreshness::HasLocalModifications { upstream } => {
2241 if if_unchanged {
2242 return None;
2243 }
2244
2241 PathFreshness::HasLocalModifications { upstream, modifications } => {
22452242 if dwn_ctx.is_running_on_ci() {
22462243 eprintln!("CI rustc commit matches with HEAD and we are in CI.");
22472244 eprintln!(
......@@ -2250,6 +2247,24 @@ pub fn download_ci_rustc_commit<'a>(
22502247 return None;
22512248 }
22522249
2250 eprintln!(
2251 "NOTE: detected {} modifications that could affect a build of rustc",
2252 modifications.len()
2253 );
2254 for file in modifications.iter().take(10) {
2255 eprintln!("- {}", file.display());
2256 }
2257 if modifications.len() > 10 {
2258 eprintln!("- ... and {} more", modifications.len() - 10);
2259 }
2260
2261 if if_unchanged {
2262 eprintln!("skipping rustc download due to `download-rustc = 'if-unchanged'`");
2263 return None;
2264 } else {
2265 eprintln!("downloading unconditionally due to `download-rustc = true`");
2266 }
2267
22532268 upstream
22542269 }
22552270 PathFreshness::MissingUpstream => {
src/bootstrap/src/core/config/tests.rs+14-16
......@@ -32,6 +32,13 @@ fn get_toml(file: &Path) -> Result<TomlConfig, toml::de::Error> {
3232 toml::from_str(&contents).and_then(|table: toml::Value| TomlConfig::deserialize(table))
3333}
3434
35fn modified(upstream: impl Into<String>, changes: &[&str]) -> PathFreshness {
36 PathFreshness::HasLocalModifications {
37 upstream: upstream.into(),
38 modifications: changes.iter().copied().map(PathBuf::from).collect(),
39 }
40}
41
3542#[test]
3643fn download_ci_llvm() {
3744 let config = TestCtx::new().config("check").create_config();
......@@ -692,7 +699,7 @@ fn test_pr_ci_changed_in_pr() {
692699 let sha = ctx.create_upstream_merge(&["a"]);
693700 ctx.create_nonupstream_merge(&["b"]);
694701 let src = ctx.check_modifications(&["b"], CiEnv::GitHubActions);
695 assert_eq!(src, PathFreshness::HasLocalModifications { upstream: sha });
702 assert_eq!(src, modified(sha, &["b"]));
696703 });
697704}
698705
......@@ -712,7 +719,7 @@ fn test_auto_ci_changed_in_pr() {
712719 let sha = ctx.create_upstream_merge(&["a"]);
713720 ctx.create_upstream_merge(&["b", "c"]);
714721 let src = ctx.check_modifications(&["c", "d"], CiEnv::GitHubActions);
715 assert_eq!(src, PathFreshness::HasLocalModifications { upstream: sha });
722 assert_eq!(src, modified(sha, &["c"]));
716723 });
717724}
718725
......@@ -723,10 +730,7 @@ fn test_local_uncommitted_modifications() {
723730 ctx.create_branch("feature");
724731 ctx.modify("a");
725732
726 assert_eq!(
727 ctx.check_modifications(&["a", "d"], CiEnv::None),
728 PathFreshness::HasLocalModifications { upstream: sha }
729 );
733 assert_eq!(ctx.check_modifications(&["a", "d"], CiEnv::None), modified(sha, &["a"]),);
730734 });
731735}
732736
......@@ -741,10 +745,7 @@ fn test_local_committed_modifications() {
741745 ctx.modify("a");
742746 ctx.commit();
743747
744 assert_eq!(
745 ctx.check_modifications(&["a", "d"], CiEnv::None),
746 PathFreshness::HasLocalModifications { upstream: sha }
747 );
748 assert_eq!(ctx.check_modifications(&["a", "d"], CiEnv::None), modified(sha, &["a"]),);
748749 });
749750}
750751
......@@ -757,10 +758,7 @@ fn test_local_committed_modifications_subdirectory() {
757758 ctx.modify("a/b/d");
758759 ctx.commit();
759760
760 assert_eq!(
761 ctx.check_modifications(&["a/b"], CiEnv::None),
762 PathFreshness::HasLocalModifications { upstream: sha }
763 );
761 assert_eq!(ctx.check_modifications(&["a/b"], CiEnv::None), modified(sha, &["a/b/d"]),);
764762 });
765763}
766764
......@@ -836,11 +834,11 @@ fn test_local_changes_negative_path() {
836834 );
837835 assert_eq!(
838836 ctx.check_modifications(&[":!c"], CiEnv::None),
839 PathFreshness::HasLocalModifications { upstream: upstream.clone() }
837 modified(&upstream, &["b", "d"]),
840838 );
841839 assert_eq!(
842840 ctx.check_modifications(&[":!d", ":!x"], CiEnv::None),
843 PathFreshness::HasLocalModifications { upstream }
841 modified(&upstream, &["b"]),
844842 );
845843 });
846844}
src/bootstrap/src/core/download.rs+1-1
......@@ -266,7 +266,7 @@ impl Config {
266266 });
267267 let llvm_sha = match llvm_freshness {
268268 PathFreshness::LastModifiedUpstream { upstream } => upstream,
269 PathFreshness::HasLocalModifications { upstream } => upstream,
269 PathFreshness::HasLocalModifications { upstream, modifications: _ } => upstream,
270270 PathFreshness::MissingUpstream => {
271271 eprintln!("error: could not find commit hash for downloading LLVM");
272272 eprintln!("HELP: maybe your repository history is too shallow?");
src/build_helper/src/git.rs+22-9
......@@ -1,4 +1,4 @@
1use std::path::Path;
1use std::path::{Path, PathBuf};
22use std::process::{Command, Stdio};
33
44use crate::ci::CiEnv;
......@@ -38,7 +38,7 @@ pub enum PathFreshness {
3838 /// "Local" essentially means "not-upstream" here.
3939 /// `upstream` is the latest upstream merge commit that made modifications to the
4040 /// set of paths.
41 HasLocalModifications { upstream: String },
41 HasLocalModifications { upstream: String, modifications: Vec<PathBuf> },
4242 /// No upstream commit was found.
4343 /// This should not happen in most reasonable circumstances, but one never knows.
4444 MissingUpstream,
......@@ -134,21 +134,34 @@ pub fn check_path_modifications(
134134 // However, that should be equivalent to checking if something has changed
135135 // from the latest upstream commit *that modified `target_paths`*, and
136136 // with this approach we do not need to invoke git an additional time.
137 if has_changed_since(git_dir, &upstream_sha, target_paths) {
138 Ok(PathFreshness::HasLocalModifications { upstream: upstream_sha })
137 let modifications = changes_since(git_dir, &upstream_sha, target_paths)?;
138 if !modifications.is_empty() {
139 Ok(PathFreshness::HasLocalModifications { upstream: upstream_sha, modifications })
139140 } else {
140141 Ok(PathFreshness::LastModifiedUpstream { upstream: upstream_sha })
141142 }
142143}
143144
144145/// Returns true if any of the passed `paths` have changed since the `base` commit.
145pub fn has_changed_since(git_dir: &Path, base: &str, paths: &[&str]) -> bool {
146pub fn changes_since(git_dir: &Path, base: &str, paths: &[&str]) -> Result<Vec<PathBuf>, String> {
147 use std::io::BufRead;
148
146149 run_git_diff_index(Some(git_dir), |cmd| {
147 cmd.args(["--quiet", base, "--"]).args(paths);
150 cmd.args([base, "--name-only", "--"]).args(paths);
151
152 let output = cmd.stderr(Stdio::inherit()).output().expect("cannot run git diff-index");
153 if !output.status.success() {
154 return Err(format!("failed to run: {cmd:?}: {:?}", output.status));
155 }
148156
149 // Exit code 0 => no changes
150 // Exit code 1 => some changes were detected
151 !cmd.status().expect("cannot run git diff-index").success()
157 output
158 .stdout
159 .lines()
160 .map(|res| match res {
161 Ok(line) => Ok(PathBuf::from(line)),
162 Err(e) => Err(format!("invalid UTF-8 in diff-index: {e:?}")),
163 })
164 .collect()
152165 })
153166}
154167
src/ci/github-actions/jobs.yml+2
......@@ -94,6 +94,7 @@ jobs:
9494 dist-x86_64-linux: &job-dist-x86_64-linux
9595 name: dist-x86_64-linux
9696 env:
97 IMAGE: dist-x86_64-linux
9798 CODEGEN_BACKENDS: llvm,cranelift
9899 DOCKER_SCRIPT: dist.sh
99100 <<: *job-linux-36c-codebuild
......@@ -150,6 +151,7 @@ pr:
150151# it in each job definition.
151152try:
152153 - <<: *job-dist-x86_64-linux
154 name: dist-x86_64-linux-quick
153155
154156# Jobs that only run when explicitly invoked in one of the following ways:
155157# - comment `@bors try jobs=<job-name>`
src/doc/rustc-dev-guide/src/tests/ci.md+4-1
......@@ -150,7 +150,10 @@ Such a try build will not execute any tests, and it will allow compilation warni
150150It is useful when you want to
151151get an optimized toolchain as fast as possible, for a Crater run or performance benchmarks,
152152even if it might not be working fully correctly.
153If you want to do a full build for the default try job,
153
154The CI job executed in fast try builds has a special suffix (`-quick`),
155to distinguish it from a full build of the default try job.
156If you want to do the full build instead,
154157specify its job name in a job pattern (explained below).
155158
156159If you want to run custom CI jobs in a try build and make sure that they pass all tests and do
src/librustdoc/build.rs+1-1
......@@ -27,7 +27,7 @@ fn main() {
2727 "static/fonts/FiraSans-MediumItalic.woff2",
2828 "static/fonts/FiraMono-Regular.woff2",
2929 "static/fonts/FiraMono-Medium.woff2",
30 "static/fonts/FiraSans-LICENSE.txt",
30 "static/fonts/Fira-LICENSE.txt",
3131 "static/fonts/SourceSerif4-Regular.ttf.woff2",
3232 "static/fonts/SourceSerif4-Semibold.ttf.woff2",
3333 "static/fonts/SourceSerif4-Bold.ttf.woff2",
src/librustdoc/html/static/COPYRIGHT.txt+4-3
......@@ -4,15 +4,16 @@ These documentation pages include resources by third parties. This copyright
44file applies only to those resources. The following third party resources are
55included, and carry their own copyright notices and license terms:
66
7* Fira Sans (FiraSans-Regular.woff2, FiraSans-Medium.woff2):
7* Fira (FiraSans-Regular.woff2, FiraSans-Medium.woff2,
8 FiraMono-Regular.woff2, FiraMono-Medium.woff2):
89
910 Copyright (c) 2014, Mozilla Foundation https://mozilla.org/
10 with Reserved Font Name Fira Sans.
11 with Reserved Font Name < Fira >.
1112
1213 Copyright (c) 2014, Telefonica S.A.
1314
1415 Licensed under the SIL Open Font License, Version 1.1.
15 See FiraSans-LICENSE.txt.
16 See Fira-LICENSE.txt.
1617
1718* rustdoc.css, main.js, and playpen.js:
1819
src/librustdoc/html/static/fonts/Fira-LICENSE.txt created+98
......@@ -0,0 +1,98 @@
1// REUSE-IgnoreStart
2
3Digitized data copyright (c) 2012-2015, The Mozilla Foundation and Telefonica S.A.
4with Reserved Font Name < Fira >,
5
6This Font Software is licensed under the SIL Open Font License, Version 1.1.
7This license is copied below, and is also available with a FAQ at:
8http://scripts.sil.org/OFL
9
10
11-----------------------------------------------------------
12SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
13-----------------------------------------------------------
14
15PREAMBLE
16The goals of the Open Font License (OFL) are to stimulate worldwide
17development of collaborative font projects, to support the font creation
18efforts of academic and linguistic communities, and to provide a free and
19open framework in which fonts may be shared and improved in partnership
20with others.
21
22The OFL allows the licensed fonts to be used, studied, modified and
23redistributed freely as long as they are not sold by themselves. The
24fonts, including any derivative works, can be bundled, embedded,
25redistributed and/or sold with any software provided that any reserved
26names are not used by derivative works. The fonts and derivatives,
27however, cannot be released under any other type of license. The
28requirement for fonts to remain under this license does not apply
29to any document created using the fonts or their derivatives.
30
31DEFINITIONS
32"Font Software" refers to the set of files released by the Copyright
33Holder(s) under this license and clearly marked as such. This may
34include source files, build scripts and documentation.
35
36"Reserved Font Name" refers to any names specified as such after the
37copyright statement(s).
38
39"Original Version" refers to the collection of Font Software components as
40distributed by the Copyright Holder(s).
41
42"Modified Version" refers to any derivative made by adding to, deleting,
43or substituting -- in part or in whole -- any of the components of the
44Original Version, by changing formats or by porting the Font Software to a
45new environment.
46
47"Author" refers to any designer, engineer, programmer, technical
48writer or other person who contributed to the Font Software.
49
50PERMISSION & CONDITIONS
51Permission is hereby granted, free of charge, to any person obtaining
52a copy of the Font Software, to use, study, copy, merge, embed, modify,
53redistribute, and sell modified and unmodified copies of the Font
54Software, subject to the following conditions:
55
561) Neither the Font Software nor any of its individual components,
57in Original or Modified Versions, may be sold by itself.
58
592) Original or Modified Versions of the Font Software may be bundled,
60redistributed and/or sold with any software, provided that each copy
61contains the above copyright notice and this license. These can be
62included either as stand-alone text files, human-readable headers or
63in the appropriate machine-readable metadata fields within text or
64binary files as long as those fields can be easily viewed by the user.
65
663) No Modified Version of the Font Software may use the Reserved Font
67Name(s) unless explicit written permission is granted by the corresponding
68Copyright Holder. This restriction only applies to the primary font name as
69presented to the users.
70
714) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
72Software shall not be used to promote, endorse or advertise any
73Modified Version, except to acknowledge the contribution(s) of the
74Copyright Holder(s) and the Author(s) or with their explicit written
75permission.
76
775) The Font Software, modified or unmodified, in part or in whole,
78must be distributed entirely under this license, and must not be
79distributed under any other license. The requirement for fonts to
80remain under this license does not apply to any document created
81using the Font Software.
82
83TERMINATION
84This license becomes null and void if any of the above conditions are
85not met.
86
87DISCLAIMER
88THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
89EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
90MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
91OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
92COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
93INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
94DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
95FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
96OTHER DEALINGS IN THE FONT SOFTWARE.
97
98// REUSE-IgnoreEnd
src/librustdoc/html/static/fonts/FiraSans-LICENSE.txt deleted-98
......@@ -1,98 +0,0 @@
1// REUSE-IgnoreStart
2
3Digitized data copyright (c) 2012-2015, The Mozilla Foundation and Telefonica S.A.
4with Reserved Font Name < Fira >,
5
6This Font Software is licensed under the SIL Open Font License, Version 1.1.
7This license is copied below, and is also available with a FAQ at:
8http://scripts.sil.org/OFL
9
10
11-----------------------------------------------------------
12SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
13-----------------------------------------------------------
14
15PREAMBLE
16The goals of the Open Font License (OFL) are to stimulate worldwide
17development of collaborative font projects, to support the font creation
18efforts of academic and linguistic communities, and to provide a free and
19open framework in which fonts may be shared and improved in partnership
20with others.
21
22The OFL allows the licensed fonts to be used, studied, modified and
23redistributed freely as long as they are not sold by themselves. The
24fonts, including any derivative works, can be bundled, embedded,
25redistributed and/or sold with any software provided that any reserved
26names are not used by derivative works. The fonts and derivatives,
27however, cannot be released under any other type of license. The
28requirement for fonts to remain under this license does not apply
29to any document created using the fonts or their derivatives.
30
31DEFINITIONS
32"Font Software" refers to the set of files released by the Copyright
33Holder(s) under this license and clearly marked as such. This may
34include source files, build scripts and documentation.
35
36"Reserved Font Name" refers to any names specified as such after the
37copyright statement(s).
38
39"Original Version" refers to the collection of Font Software components as
40distributed by the Copyright Holder(s).
41
42"Modified Version" refers to any derivative made by adding to, deleting,
43or substituting -- in part or in whole -- any of the components of the
44Original Version, by changing formats or by porting the Font Software to a
45new environment.
46
47"Author" refers to any designer, engineer, programmer, technical
48writer or other person who contributed to the Font Software.
49
50PERMISSION & CONDITIONS
51Permission is hereby granted, free of charge, to any person obtaining
52a copy of the Font Software, to use, study, copy, merge, embed, modify,
53redistribute, and sell modified and unmodified copies of the Font
54Software, subject to the following conditions:
55
561) Neither the Font Software nor any of its individual components,
57in Original or Modified Versions, may be sold by itself.
58
592) Original or Modified Versions of the Font Software may be bundled,
60redistributed and/or sold with any software, provided that each copy
61contains the above copyright notice and this license. These can be
62included either as stand-alone text files, human-readable headers or
63in the appropriate machine-readable metadata fields within text or
64binary files as long as those fields can be easily viewed by the user.
65
663) No Modified Version of the Font Software may use the Reserved Font
67Name(s) unless explicit written permission is granted by the corresponding
68Copyright Holder. This restriction only applies to the primary font name as
69presented to the users.
70
714) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
72Software shall not be used to promote, endorse or advertise any
73Modified Version, except to acknowledge the contribution(s) of the
74Copyright Holder(s) and the Author(s) or with their explicit written
75permission.
76
775) The Font Software, modified or unmodified, in part or in whole,
78must be distributed entirely under this license, and must not be
79distributed under any other license. The requirement for fonts to
80remain under this license does not apply to any document created
81using the Font Software.
82
83TERMINATION
84This license becomes null and void if any of the above conditions are
85not met.
86
87DISCLAIMER
88THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
89EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
90MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
91OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
92COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
93INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
94DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
95FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
96OTHER DEALINGS IN THE FONT SOFTWARE.
97
98// REUSE-IgnoreEnd
src/librustdoc/html/static/js/search.js+13-10
......@@ -4749,11 +4749,16 @@ class DocSearch {
47494749 })(),
47504750 "query": parsedQuery,
47514751 };
4752 } else if (parsedQuery.error !== null) {
4752 } else if (parsedQuery.error !== null || parsedQuery.foundElems === 0) {
4753 // Symbol-only queries like `==` do not parse into type elements,
4754 // but can still match exact item names or doc aliases.
4755 const others = parsedQuery.userQuery.length === 0 ?
4756 (async function*() {})() :
4757 innerRunNameQuery(currentCrate);
47534758 return {
47544759 "in_args": (async function*() {})(),
47554760 "returned": (async function*() {})(),
4756 "others": innerRunNameQuery(currentCrate),
4761 "others": others,
47574762 "query": parsedQuery,
47584763 };
47594764 } else {
......@@ -4764,14 +4769,12 @@ class DocSearch {
47644769 return {
47654770 "in_args": (async function*() {})(),
47664771 "returned": (async function*() {})(),
4767 "others": parsedQuery.foundElems === 0 ?
4768 (async function*() {})() :
4769 innerRunTypeQuery(
4770 parsedQuery.elems,
4771 parsedQuery.returned,
4772 typeInfo,
4773 currentCrate,
4774 ),
4772 "others": innerRunTypeQuery(
4773 parsedQuery.elems,
4774 parsedQuery.returned,
4775 typeInfo,
4776 currentCrate,
4777 ),
47754778 "query": parsedQuery,
47764779 };
47774780 }
src/librustdoc/html/static_files.rs+1-1
......@@ -97,7 +97,7 @@ static_files! {
9797 fira_sans_medium_italic => "static/fonts/FiraSans-MediumItalic.woff2",
9898 fira_mono_regular => "static/fonts/FiraMono-Regular.woff2",
9999 fira_mono_medium => "static/fonts/FiraMono-Medium.woff2",
100 fira_sans_license => "static/fonts/FiraSans-LICENSE.txt",
100 fira_license => "static/fonts/Fira-LICENSE.txt",
101101 source_serif_4_regular => "static/fonts/SourceSerif4-Regular.ttf.woff2",
102102 source_serif_4_semibold => "static/fonts/SourceSerif4-Semibold.ttf.woff2",
103103 source_serif_4_bold => "static/fonts/SourceSerif4-Bold.ttf.woff2",
src/tools/wasm-component-ld/Cargo.toml+1-1
......@@ -10,4 +10,4 @@ name = "wasm-component-ld"
1010path = "src/main.rs"
1111
1212[dependencies]
13wasm-component-ld = "0.5.21"
13wasm-component-ld = "0.5.22"
tests/codegen-llvm/dont_codegen_private_const_fn_only_used_in_const_eval.rs deleted-27
......@@ -1,27 +0,0 @@
1//! This test checks that we do not monomorphize functions that are only
2//! used to evaluate static items, but never used in runtime code.
3
4//@compile-flags: --crate-type=lib -Copt-level=0
5
6#![feature(generic_const_items)]
7
8const fn foo() {}
9
10pub static FOO: () = foo();
11
12// CHECK-NOT: define{{.*}}foo{{.*}}
13
14const fn bar() {}
15
16pub const BAR: () = bar();
17
18// CHECK-NOT: define{{.*}}bar{{.*}}
19
20const fn baz() {}
21
22#[rustfmt::skip]
23pub const BAZ<const C: bool>: () = if C {
24 baz()
25};
26
27// CHECK: define{{.*}}baz{{.*}}
tests/codegen-llvm/private-const-fn-only-used-in-const-eval.rs created+38
......@@ -0,0 +1,38 @@
1// Check that we — where possible — don't codegen functions that are only used to evaluate
2// static / const items, but never used in runtime code.
3
4//@ compile-flags: --crate-type=lib -Copt-level=0
5
6#![feature(generic_const_items)] // only used in the last few test cases
7
8pub static STATIC: () = func0();
9const fn func0() {}
10// CHECK-NOT: define{{.*}}func0{{.*}}
11
12pub const CONSTANT: () = func1();
13const fn func1() {}
14// CHECK-NOT: define{{.*}}func1{{.*}}
15
16// We generally don't want to evaluate the initializer of free const items if they have
17// non-region params (and even if we did, const eval would fail anyway with "too polymorphic"
18// if the initializer actually referenced such a param).
19//
20// As a result of not being able to look at the final value, during reachability analysis we
21// can't tell for sure if for example certain functions end up in the final value or if they're
22// only used during const eval. We fall back to a conservative HIR-based approach.
23
24// `func2` isn't needed at runtime but the compiler can't tell for the reason mentioned above.
25pub const POLY_CONST_0<const C: bool>: () = func2();
26const fn func2() {}
27// CHECK: define{{.*}}func2{{.*}}
28
29// `func3` isn't needed at runtime but the compiler can't tell for the reason mentioned above.
30pub const POLY_CONST_1<const C: bool>: () = if C { func3() };
31const fn func3() {}
32// CHECK: define{{.*}}func3{{.*}}
33
34// `func4` *is* needed at runtime (here, the HIR-based approach gets it right).
35pub const POLY_CONST_2<const C: bool>: Option<fn() /* or a TAIT */> =
36 if C { Some(func4) } else { None };
37const fn func4() {}
38// CHECK: define{{.*}}func4{{.*}}
tests/run-make/raw-dylib-elf-extern-types/bin.rs created+21
......@@ -0,0 +1,21 @@
1#![feature(extern_types)]
2#![feature(raw_dylib_elf)]
3
4use std::ffi::c_char;
5
6#[link(name = "extern", kind = "raw-dylib")]
7unsafe extern "C" {
8 type FOO;
9 fn create_foo() -> *const FOO;
10 fn get_foo(foo: *const FOO) -> c_char;
11 fn set_foo(foo: *const FOO, value: c_char);
12}
13
14pub fn main() {
15 let value = unsafe {
16 let foo = create_foo();
17 set_foo(foo, 42);
18 get_foo(foo)
19 };
20 println!("{}", value);
21}
tests/run-make/raw-dylib-elf-extern-types/extern.c created+16
......@@ -0,0 +1,16 @@
1typedef struct FOO {
2 char val;
3} FOO;
4
5FOO* create_foo() {
6 static FOO foo;
7 return &foo;
8}
9
10void set_foo(FOO* foo, char val) {
11 foo->val = val;
12}
13
14char get_foo(FOO* foo) {
15 return foo->val;
16}
tests/run-make/raw-dylib-elf-extern-types/output.txt created+1
......@@ -0,0 +1 @@
142
tests/run-make/raw-dylib-elf-extern-types/rmake.rs created+18
......@@ -0,0 +1,18 @@
1//@ only-elf
2//@ ignore-cross-compile: Runs a binary.
3//@ needs-dynamic-linking
4// FIXME(raw_dylib_elf): Debug the failures on other targets.
5//@ only-gnu
6//@ only-x86_64
7
8//@ ignore-rustc-debug-assertions
9
10use run_make_support::{build_native_dynamic_lib, diff, run, rustc};
11
12fn main() {
13 rustc().crate_type("bin").crate_name("raw_dylib_test").input("bin.rs").run();
14 build_native_dynamic_lib("extern");
15
16 let out_raw = run("raw_dylib_test").stdout_utf8();
17 diff().expected_file("output.txt").actual_text("actual", out_raw).normalize(r#"\r"#, "").run();
18}
tests/rustdoc-js-std/doc-alias-symbols-150921.js created+24
......@@ -0,0 +1,24 @@
1// exact-check
2// Regression test for <https://github.com/rust-lang/rust/issues/150921>.
3
4const EXPECTED = [
5 {
6 'query': '==',
7 'others': [
8 {
9 'path': 'std::cmp',
10 'name': 'Eq',
11 'alias': '==',
12 'href': '../std/cmp/trait.Eq.html',
13 'is_alias': true,
14 },
15 {
16 'path': 'std::cmp',
17 'name': 'PartialEq',
18 'alias': '==',
19 'href': '../std/cmp/trait.PartialEq.html',
20 'is_alias': true,
21 },
22 ],
23 },
24];
tests/rustdoc-js/doc-alias-symbols-150921.js created+29
......@@ -0,0 +1,29 @@
1// exact-check
2// Regression test for <https://github.com/rust-lang/rust/issues/150921>.
3
4const EXPECTED = [
5 {
6 'query': '==',
7 'others': [
8 {
9 'path': 'doc_alias_symbols_150921',
10 'name': 'OperatorEqEqAlias',
11 'alias': '==',
12 'href': '../doc_alias_symbols_150921/struct.OperatorEqEqAlias.html',
13 'is_alias': true,
14 },
15 ],
16 },
17 {
18 'query': '!=',
19 'others': [
20 {
21 'path': 'doc_alias_symbols_150921',
22 'name': 'OperatorNotEqAlias',
23 'alias': '!=',
24 'href': '../doc_alias_symbols_150921/struct.OperatorNotEqAlias.html',
25 'is_alias': true,
26 },
27 ],
28 },
29];
tests/rustdoc-js/doc-alias-symbols-150921.rs created+7
......@@ -0,0 +1,7 @@
1// Regression test for <https://github.com/rust-lang/rust/issues/150921>.
2
3#[doc(alias = "==")]
4pub struct OperatorEqEqAlias;
5
6#[doc(alias = "!=")]
7pub struct OperatorNotEqAlias;
tests/ui/cfg/suggest-alternative-name-on-target.rs+1-1
......@@ -32,8 +32,8 @@ struct D;
3232#[cfg(target_abi = "windows")]
3333//~^ ERROR unexpected `cfg` condition value:
3434//~| NOTE see <https://doc.rust-lang.org
35//~| HELP `windows` is an expected value for `target_os`
3635//~| HELP `windows` is an expected value for `target_family`
36//~| HELP `windows` is an expected value for `target_os`
3737struct E;
3838
3939fn main() {}
tests/ui/cfg/suggest-alternative-name-on-target.stderr+4-4
......@@ -62,15 +62,15 @@ LL | #[cfg(target_abi = "windows")]
6262 | ^^^^^^^^^^^^^^^^^^^^^^
6363 |
6464 = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
65help: `windows` is an expected value for `target_os`
65help: `windows` is an expected value for `target_family`
6666 |
6767LL - #[cfg(target_abi = "windows")]
68LL + #[cfg(target_os = "windows")]
68LL + #[cfg(target_family = "windows")]
6969 |
70help: `windows` is an expected value for `target_family`
70help: `windows` is an expected value for `target_os`
7171 |
7272LL - #[cfg(target_abi = "windows")]
73LL + #[cfg(target_family = "windows")]
73LL + #[cfg(target_os = "windows")]
7474 |
7575
7676error: aborting due to 5 previous errors
tests/ui/delegation/duplicate-definition-inside-trait-impl.rs+2
......@@ -18,6 +18,8 @@ impl Trait for S {
1818 reuse to_reuse::foo { self }
1919 reuse Trait::foo;
2020 //~^ ERROR duplicate definitions with name `foo`
21 //~| ERROR: this function takes 1 argument but 0 arguments were supplied
22 //~| ERROR: mismatched types
2123}
2224
2325fn main() {}
tests/ui/delegation/duplicate-definition-inside-trait-impl.stderr+28-2
......@@ -9,6 +9,32 @@ LL | reuse to_reuse::foo { self }
99LL | reuse Trait::foo;
1010 | ^^^^^^^^^^^^^^^^^ duplicate definition
1111
12error: aborting due to 1 previous error
12error[E0061]: this function takes 1 argument but 0 arguments were supplied
13 --> $DIR/duplicate-definition-inside-trait-impl.rs:19:18
14 |
15LL | reuse Trait::foo;
16 | ^^^ argument #1 of type `&_` is missing
17 |
18note: method defined here
19 --> $DIR/duplicate-definition-inside-trait-impl.rs:5:8
20 |
21LL | fn foo(&self) -> u32 { 0 }
22 | ^^^ -----
23help: provide the argument
24 |
25LL | reuse Trait::foo(/* value */);
26 | +++++++++++++
27
28error[E0308]: mismatched types
29 --> $DIR/duplicate-definition-inside-trait-impl.rs:19:18
30 |
31LL | reuse Trait::foo;
32 | ^^^- help: consider using a semicolon here: `;`
33 | |
34 | expected `()`, found `u32`
35 | expected `()` because of default return type
36
37error: aborting due to 3 previous errors
1338
14For more information about this error, try `rustc --explain E0201`.
39Some errors have detailed explanations: E0061, E0201, E0308.
40For more information about an error, try `rustc --explain E0061`.
tests/ui/delegation/glob-glob-conflict.rs+4
......@@ -3,9 +3,13 @@
33
44trait Trait1 {
55 fn method(&self) -> u8;
6 //~^ ERROR: this function takes 1 argument but 0 arguments were supplied
7 //~| ERROR: mismatched types
68}
79trait Trait2 {
810 fn method(&self) -> u8;
11 //~^ ERROR: this function takes 1 argument but 0 arguments were supplied
12 //~| ERROR: mismatched types
913}
1014trait Trait {
1115 fn method(&self) -> u8;
tests/ui/delegation/glob-glob-conflict.stderr+55-4
......@@ -1,5 +1,5 @@
11error[E0201]: duplicate definitions with name `method`:
2 --> $DIR/glob-glob-conflict.rs:26:5
2 --> $DIR/glob-glob-conflict.rs:30:5
33 |
44LL | fn method(&self) -> u8;
55 | ----------------------- item in trait
......@@ -10,7 +10,7 @@ LL | reuse Trait2::*;
1010 | ^^^^^^^^^^^^^^^^ duplicate definition
1111
1212error[E0201]: duplicate definitions with name `method`:
13 --> $DIR/glob-glob-conflict.rs:30:5
13 --> $DIR/glob-glob-conflict.rs:34:5
1414 |
1515LL | fn method(&self) -> u8;
1616 | ----------------------- item in trait
......@@ -20,6 +20,57 @@ LL | reuse Trait1::*;
2020LL | reuse Trait1::*;
2121 | ^^^^^^^^^^^^^^^^ duplicate definition
2222
23error: aborting due to 2 previous errors
23error[E0061]: this function takes 1 argument but 0 arguments were supplied
24 --> $DIR/glob-glob-conflict.rs:10:8
25 |
26LL | fn method(&self) -> u8;
27 | ^^^^^^ argument #1 of type `&_` is missing
28 |
29note: method defined here
30 --> $DIR/glob-glob-conflict.rs:10:8
31 |
32LL | fn method(&self) -> u8;
33 | ^^^^^^ ----
34help: provide the argument
35 |
36LL | fn method(/* value */)(&self) -> u8;
37 | +++++++++++++
38
39error[E0308]: mismatched types
40 --> $DIR/glob-glob-conflict.rs:10:8
41 |
42LL | fn method(&self) -> u8;
43 | ^^^^^^- help: consider using a semicolon here: `;`
44 | |
45 | expected `()`, found `u8`
46 | expected `()` because of default return type
47
48error[E0061]: this function takes 1 argument but 0 arguments were supplied
49 --> $DIR/glob-glob-conflict.rs:5:8
50 |
51LL | fn method(&self) -> u8;
52 | ^^^^^^ argument #1 of type `&_` is missing
53 |
54note: method defined here
55 --> $DIR/glob-glob-conflict.rs:5:8
56 |
57LL | fn method(&self) -> u8;
58 | ^^^^^^ ----
59help: provide the argument
60 |
61LL | fn method(/* value */)(&self) -> u8;
62 | +++++++++++++
63
64error[E0308]: mismatched types
65 --> $DIR/glob-glob-conflict.rs:5:8
66 |
67LL | fn method(&self) -> u8;
68 | ^^^^^^- help: consider using a semicolon here: `;`
69 | |
70 | expected `()`, found `u8`
71 | expected `()` because of default return type
72
73error: aborting due to 6 previous errors
2474
25For more information about this error, try `rustc --explain E0201`.
75Some errors have detailed explanations: E0061, E0201, E0308.
76For more information about an error, try `rustc --explain E0061`.
tests/ui/delegation/ice-issue-124347.rs+2
......@@ -4,9 +4,11 @@
44trait Trait {
55 reuse Trait::foo { &self.0 }
66 //~^ ERROR failed to resolve delegation callee
7 //~| ERROR: this function takes 0 arguments but 1 argument was supplied
78}
89
910reuse foo;
1011//~^ ERROR failed to resolve delegation callee
12//~| WARN: function cannot return without recursing
1113
1214fn main() {}
tests/ui/delegation/ice-issue-124347.stderr+32-2
......@@ -5,10 +5,40 @@ LL | reuse Trait::foo { &self.0 }
55 | ^^^
66
77error: failed to resolve delegation callee
8 --> $DIR/ice-issue-124347.rs:9:7
8 --> $DIR/ice-issue-124347.rs:10:7
99 |
1010LL | reuse foo;
1111 | ^^^
1212
13error: aborting due to 2 previous errors
13error[E0061]: this function takes 0 arguments but 1 argument was supplied
14 --> $DIR/ice-issue-124347.rs:5:18
15 |
16LL | reuse Trait::foo { &self.0 }
17 | ^^^ ------- unexpected argument
18 |
19note: associated function defined here
20 --> $DIR/ice-issue-124347.rs:5:18
21 |
22LL | reuse Trait::foo { &self.0 }
23 | ^^^
24help: remove the extra argument
25 |
26LL - reuse Trait::foo { &self.0 }
27LL + reuse Trait::fo&self.0 }
28 |
29
30warning: function cannot return without recursing
31 --> $DIR/ice-issue-124347.rs:10:7
32 |
33LL | reuse foo;
34 | ^^^
35 | |
36 | cannot return without recursing
37 | recursive call site
38 |
39 = help: a `loop` may express intention better if this is on purpose
40 = note: `#[warn(unconditional_recursion)]` on by default
41
42error: aborting due to 3 previous errors; 1 warning emitted
1443
44For more information about this error, try `rustc --explain E0061`.
tests/ui/delegation/recursive-delegation-errors.rs+6
......@@ -5,6 +5,7 @@
55mod first_mod {
66 reuse foo;
77 //~^ ERROR failed to resolve delegation callee
8 //~| WARN: function cannot return without recursing
89}
910
1011mod second_mod {
......@@ -33,8 +34,10 @@ mod fourth_mod {
3334 trait Trait {
3435 reuse Trait::foo as bar;
3536 //~^ ERROR encountered a cycle during delegation signature resolution
37 //~| ERROR: type annotations needed
3638 reuse Trait::bar as foo;
3739 //~^ ERROR encountered a cycle during delegation signature resolution
40 //~| ERROR: type annotations needed
3841 }
3942}
4043
......@@ -48,6 +51,9 @@ mod fifth_mod {
4851 //~^ ERROR encountered a cycle during delegation signature resolution
4952 //~| ERROR encountered a cycle during delegation signature resolution
5053 //~| ERROR encountered a cycle during delegation signature resolution
54 //~| ERROR: type annotations needed
55 //~| ERROR: type annotations needed
56 //~| ERROR: type annotations needed
5157 }
5258}
5359
tests/ui/delegation/recursive-delegation-errors.stderr+69-16
......@@ -5,94 +5,147 @@ LL | reuse foo;
55 | ^^^
66
77error: encountered a cycle during delegation signature resolution
8 --> $DIR/recursive-delegation-errors.rs:11:11
8 --> $DIR/recursive-delegation-errors.rs:12:11
99 |
1010LL | reuse foo as bar;
1111 | ^^^
1212
1313error: encountered a cycle during delegation signature resolution
14 --> $DIR/recursive-delegation-errors.rs:13:11
14 --> $DIR/recursive-delegation-errors.rs:14:11
1515 |
1616LL | reuse bar as foo;
1717 | ^^^
1818
1919error: encountered a cycle during delegation signature resolution
20 --> $DIR/recursive-delegation-errors.rs:18:11
20 --> $DIR/recursive-delegation-errors.rs:19:11
2121 |
2222LL | reuse foo as foo1;
2323 | ^^^
2424
2525error: encountered a cycle during delegation signature resolution
26 --> $DIR/recursive-delegation-errors.rs:20:11
26 --> $DIR/recursive-delegation-errors.rs:21:11
2727 |
2828LL | reuse foo1 as foo2;
2929 | ^^^^
3030
3131error: encountered a cycle during delegation signature resolution
32 --> $DIR/recursive-delegation-errors.rs:22:11
32 --> $DIR/recursive-delegation-errors.rs:23:11
3333 |
3434LL | reuse foo2 as foo3;
3535 | ^^^^
3636
3737error: encountered a cycle during delegation signature resolution
38 --> $DIR/recursive-delegation-errors.rs:24:11
38 --> $DIR/recursive-delegation-errors.rs:25:11
3939 |
4040LL | reuse foo3 as foo4;
4141 | ^^^^
4242
4343error: encountered a cycle during delegation signature resolution
44 --> $DIR/recursive-delegation-errors.rs:26:11
44 --> $DIR/recursive-delegation-errors.rs:27:11
4545 |
4646LL | reuse foo4 as foo5;
4747 | ^^^^
4848
4949error: encountered a cycle during delegation signature resolution
50 --> $DIR/recursive-delegation-errors.rs:28:11
50 --> $DIR/recursive-delegation-errors.rs:29:11
5151 |
5252LL | reuse foo5 as foo;
5353 | ^^^^
5454
5555error: encountered a cycle during delegation signature resolution
56 --> $DIR/recursive-delegation-errors.rs:34:22
56 --> $DIR/recursive-delegation-errors.rs:35:22
5757 |
5858LL | reuse Trait::foo as bar;
5959 | ^^^
6060
6161error: encountered a cycle during delegation signature resolution
62 --> $DIR/recursive-delegation-errors.rs:36:22
62 --> $DIR/recursive-delegation-errors.rs:38:22
6363 |
6464LL | reuse Trait::bar as foo;
6565 | ^^^
6666
6767error: encountered a cycle during delegation signature resolution
68 --> $DIR/recursive-delegation-errors.rs:42:30
68 --> $DIR/recursive-delegation-errors.rs:45:30
6969 |
7070LL | reuse super::fifth_mod::{bar as foo, foo as bar};
7171 | ^^^
7272
7373error: encountered a cycle during delegation signature resolution
74 --> $DIR/recursive-delegation-errors.rs:42:42
74 --> $DIR/recursive-delegation-errors.rs:45:42
7575 |
7676LL | reuse super::fifth_mod::{bar as foo, foo as bar};
7777 | ^^^
7878
7979error: encountered a cycle during delegation signature resolution
80 --> $DIR/recursive-delegation-errors.rs:47:27
80 --> $DIR/recursive-delegation-errors.rs:50:27
8181 |
8282LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo};
8383 | ^^^
8484
8585error: encountered a cycle during delegation signature resolution
86 --> $DIR/recursive-delegation-errors.rs:47:39
86 --> $DIR/recursive-delegation-errors.rs:50:39
8787 |
8888LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo};
8989 | ^^^
9090
9191error: encountered a cycle during delegation signature resolution
92 --> $DIR/recursive-delegation-errors.rs:47:51
92 --> $DIR/recursive-delegation-errors.rs:50:51
9393 |
9494LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo};
9595 | ^^^
9696
97error: aborting due to 16 previous errors
97error[E0283]: type annotations needed
98 --> $DIR/recursive-delegation-errors.rs:35:22
99 |
100LL | reuse Trait::foo as bar;
101 | ^^^ cannot infer type
102 |
103 = note: the type must implement `fourth_mod::Trait`
104
105error[E0283]: type annotations needed
106 --> $DIR/recursive-delegation-errors.rs:38:22
107 |
108LL | reuse Trait::bar as foo;
109 | ^^^ cannot infer type
110 |
111 = note: the type must implement `fourth_mod::Trait`
112
113error[E0283]: type annotations needed
114 --> $DIR/recursive-delegation-errors.rs:50:27
115 |
116LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo};
117 | ^^^ cannot infer type
118 |
119 = note: the type must implement `GlobReuse`
120
121error[E0283]: type annotations needed
122 --> $DIR/recursive-delegation-errors.rs:50:39
123 |
124LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo};
125 | ^^^ cannot infer type
126 |
127 = note: the type must implement `GlobReuse`
128
129error[E0283]: type annotations needed
130 --> $DIR/recursive-delegation-errors.rs:50:51
131 |
132LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo};
133 | ^^^ cannot infer type
134 |
135 = note: the type must implement `GlobReuse`
136
137warning: function cannot return without recursing
138 --> $DIR/recursive-delegation-errors.rs:6:11
139 |
140LL | reuse foo;
141 | ^^^
142 | |
143 | cannot return without recursing
144 | recursive call site
145 |
146 = help: a `loop` may express intention better if this is on purpose
147 = note: `#[warn(unconditional_recursion)]` on by default
148
149error: aborting due to 21 previous errors; 1 warning emitted
98150
151For more information about this error, try `rustc --explain E0283`.
tests/ui/delegation/unlowered-path-ice-154820.rs created+12
......@@ -0,0 +1,12 @@
1#![feature(fn_delegation)]
2#![allow(incomplete_features)]
3
4reuse foo:: < { //~ ERROR: failed to resolve delegation callee
5 //~^ ERROR: function takes 0 generic arguments but 1 generic argument was supplied
6 fn foo() {}
7 reuse foo;
8 //~^ ERROR: the name `foo` is defined multiple times
9 }
10 >;
11
12fn main() {}
tests/ui/delegation/unlowered-path-ice-154820.stderr created+40
......@@ -0,0 +1,40 @@
1error[E0428]: the name `foo` is defined multiple times
2 --> $DIR/unlowered-path-ice-154820.rs:7:5
3 |
4LL | fn foo() {}
5 | -------- previous definition of the value `foo` here
6LL | reuse foo;
7 | ^^^^^^^^^^ `foo` redefined here
8 |
9 = note: `foo` must be defined only once in the value namespace of this block
10
11error: failed to resolve delegation callee
12 --> $DIR/unlowered-path-ice-154820.rs:4:7
13 |
14LL | reuse foo:: < {
15 | ^^^
16
17error[E0107]: function takes 0 generic arguments but 1 generic argument was supplied
18 --> $DIR/unlowered-path-ice-154820.rs:4:7
19 |
20LL | reuse foo:: < {
21 | _______^^^-
22 | | |
23 | | expected 0 generic arguments
24LL | |
25LL | | fn foo() {}
26LL | | reuse foo;
27... |
28LL | | >;
29 | |___- help: remove the unnecessary generics
30 |
31note: function defined here, with 0 generic parameters
32 --> $DIR/unlowered-path-ice-154820.rs:4:7
33 |
34LL | reuse foo:: < {
35 | ^^^
36
37error: aborting due to 3 previous errors
38
39Some errors have detailed explanations: E0107, E0428.
40For more information about an error, try `rustc --explain E0107`.
tests/ui/generic-const-items/def-site-eval.fail.stderr+1-1
......@@ -1,5 +1,5 @@
11error[E0080]: evaluation panicked: explicit panic
2 --> $DIR/def-site-eval.rs:13:20
2 --> $DIR/def-site-eval.rs:32:20
33 |
44LL | const _<'_a>: () = panic!();
55 | ^^^^^^^^ evaluation of `_` failed here
tests/ui/generic-const-items/def-site-eval.rs+23-6
......@@ -1,15 +1,32 @@
1//! Test that we only evaluate free const items (their def site to be clear)
2//! whose generics don't require monomorphization.
1// Test that we don't evaluate the initializer of free const items if they have
2// non-region generic parameters (i.e., ones that "require monomorphization").
3//
4// To peek behind the curtains for a bit, at the time of writing there are three places where we
5// usually evaluate the initializer: "analysis", mono item collection & reachability analysis.
6// We must ensure that all of them take the generics into account.
7//
8//@ revisions: fail pass
9//@[pass] check-pass
10
311#![feature(generic_const_items)]
412#![expect(incomplete_features)]
13#![crate_type = "lib"] // (*)
514
6//@ revisions: fail pass
7//@[pass] check-pass
15// All of these constants are intentionally unused since we want to test the
16// behavior at the def site, not at use sites.
817
918const _<_T>: () = panic!();
1019const _<const _N: usize>: () = panic!();
1120
21// Check *public* const items specifically to exercise reachability analysis which normally
22// evaluates const initializers to look for function pointers in the final const value.
23//
24// (*): While reachability analysis also runs for purely binary crates (to find e.g., extern items)
25// setting the crate type to library (1) makes the case below 'more realistic' since
26// hypothetical downstream crates that require runtime MIR could actually exist.
27// (2) It ensures that we exercise the relevant part of the compiler under test.
28pub const K<_T>: () = panic!();
29pub const Q<const _N: usize>: () = loop {};
30
1231#[cfg(fail)]
1332const _<'_a>: () = panic!(); //[fail]~ ERROR evaluation panicked: explicit panic
14
15fn main() {}
tests/ui/generic-const-items/trivially-unsatisfied-bounds-0.rs deleted-12
......@@ -1,12 +0,0 @@
1#![feature(generic_const_items, trivial_bounds)]
2#![allow(incomplete_features)]
3
4// Ensure that we check if trivial bounds on const items hold or not.
5
6const UNUSABLE: () = () //~ ERROR entering unreachable code
7where
8 String: Copy;
9
10fn main() {
11 let _ = UNUSABLE; //~ ERROR the trait bound `String: Copy` is not satisfied
12}
tests/ui/generic-const-items/trivially-unsatisfied-bounds-0.stderr deleted-27
......@@ -1,27 +0,0 @@
1error[E0080]: entering unreachable code
2 --> $DIR/trivially-unsatisfied-bounds-0.rs:6:1
3 |
4LL | / const UNUSABLE: () = ()
5LL | | where
6LL | | String: Copy;
7 | |_________________^ evaluation of `UNUSABLE` failed here
8
9error[E0277]: the trait bound `String: Copy` is not satisfied
10 --> $DIR/trivially-unsatisfied-bounds-0.rs:11:13
11 |
12LL | let _ = UNUSABLE;
13 | ^^^^^^^^ the trait `Copy` is not implemented for `String`
14 |
15note: required by a bound in `UNUSABLE`
16 --> $DIR/trivially-unsatisfied-bounds-0.rs:8:13
17 |
18LL | const UNUSABLE: () = ()
19 | -------- required by a bound in this constant
20LL | where
21LL | String: Copy;
22 | ^^^^ required by this bound in `UNUSABLE`
23
24error: aborting due to 2 previous errors
25
26Some errors have detailed explanations: E0080, E0277.
27For more information about an error, try `rustc --explain E0080`.
tests/ui/generic-const-items/trivially-unsatisfied-bounds-1.rs deleted-12
......@@ -1,12 +0,0 @@
1#![feature(generic_const_items, trivial_bounds)]
2#![allow(incomplete_features, dead_code, trivial_bounds)]
3
4// FIXME(generic_const_items): This looks like a bug to me. I expected that we wouldn't emit any
5// errors. I thought we'd skip the evaluation of consts whose bounds don't hold.
6
7const UNUSED: () = ()
8where
9 String: Copy;
10//~^^^ ERROR unreachable code
11
12fn main() {}
tests/ui/generic-const-items/trivially-unsatisfied-bounds-1.stderr deleted-11
......@@ -1,11 +0,0 @@
1error[E0080]: entering unreachable code
2 --> $DIR/trivially-unsatisfied-bounds-1.rs:7:1
3 |
4LL | / const UNUSED: () = ()
5LL | | where
6LL | | String: Copy;
7 | |_________________^ evaluation of `UNUSED` failed here
8
9error: aborting due to 1 previous error
10
11For more information about this error, try `rustc --explain E0080`.
tests/ui/generic-const-items/trivially-unsatisfied-bounds.mentioned.stderr created+27
......@@ -0,0 +1,27 @@
1error[E0080]: entering unreachable code
2 --> $DIR/trivially-unsatisfied-bounds.rs:17:1
3 |
4LL | / const UNUSABLE: () = ()
5LL | | where
6LL | | for<'_delay> String: Copy;
7 | |______________________________^ evaluation of `UNUSABLE` failed here
8
9error[E0277]: the trait bound `String: Copy` is not satisfied
10 --> $DIR/trivially-unsatisfied-bounds.rs:24:13
11 |
12LL | let _ = UNUSABLE;
13 | ^^^^^^^^ the trait `Copy` is not implemented for `String`
14 |
15note: required by a bound in `UNUSABLE`
16 --> $DIR/trivially-unsatisfied-bounds.rs:19:26
17 |
18LL | const UNUSABLE: () = ()
19 | -------- required by a bound in this constant
20LL | where
21LL | for<'_delay> String: Copy;
22 | ^^^^ required by this bound in `UNUSABLE`
23
24error: aborting due to 2 previous errors
25
26Some errors have detailed explanations: E0080, E0277.
27For more information about an error, try `rustc --explain E0080`.
tests/ui/generic-const-items/trivially-unsatisfied-bounds.rs created+33
......@@ -0,0 +1,33 @@
1// Exercise trivially unsatisfied bounds on free const items.
2// Their interaction with the evaluation of the initializer is interesting.
3//
4//@ revisions: mentioned unmentioned
5
6#![feature(generic_const_items)]
7
8// FIXME(generic_const_items): Try to get rid of error "entering unreachable error", it's
9// unnecessary and actually caused by MIR pass `ImpossiblePredicates` replacing the body with the
10// terminator `Unreachable` due to the unsatisfied bound which is subsequently reached.
11//
12// NOTE(#142293): However, don't think about suppressing the evaluation of the initializer if the
13// bounds are "impossible". That'd be a SemVer hazard since it could cause downstream to fail to
14// compile if upstream added a new trait impl which is undesirable[^1].
15// [^1]: Strictly speaking that's already possible due to the one-impl rule.
16
17const UNUSABLE: () = () //~ ERROR entering unreachable code
18where
19 for<'_delay> String: Copy;
20
21fn scope() {
22 // Ensure that we successfully reject references of consts with trivially unsatisfied bounds.
23 #[cfg(mentioned)]
24 let _ = UNUSABLE; //[mentioned]~ ERROR the trait bound `String: Copy` is not satisfied
25}
26
27const _BAD: () = <() as Unimplemented>::CT
28where
29 for<'_delay> (): Unimplemented;
30
31trait Unimplemented { const CT: (); }
32
33fn main() {}
tests/ui/generic-const-items/trivially-unsatisfied-bounds.unmentioned.stderr created+11
......@@ -0,0 +1,11 @@
1error[E0080]: entering unreachable code
2 --> $DIR/trivially-unsatisfied-bounds.rs:17:1
3 |
4LL | / const UNUSABLE: () = ()
5LL | | where
6LL | | for<'_delay> String: Copy;
7 | |______________________________^ evaluation of `UNUSABLE` failed here
8
9error: aborting due to 1 previous error
10
11For more information about this error, try `rustc --explain E0080`.
tests/ui/impl-trait/associated-impl-trait-type-into-emplacable.rs created+52
......@@ -0,0 +1,52 @@
1//! add regression test for <https://github.com/rust-lang/rust/issues/146514>.
2
3//@ check-pass
4
5#![feature(impl_trait_in_assoc_type)]
6
7use std::marker::PhantomData;
8
9struct Emp<T, F> {
10 phantom: PhantomData<(*const T, F)>,
11}
12
13impl<T, F> Emp<T, F> {
14 fn from_fn(_: F) -> Emp<T, F> {
15 loop {}
16 }
17
18 fn unsize(self) -> Emp<Slice, impl Sized> {
19 Emp::from_fn(|| ())
20 }
21}
22
23trait IntoEmplacable {
24 type Closure;
25
26 fn into_emplacable(self) -> Emp<Slice, Self::Closure>;
27}
28
29impl<F> IntoEmplacable for Emp<Arr, F> {
30 type Closure = impl Sized;
31
32 fn into_emplacable(self) -> Emp<Slice, Self::Closure> {
33 self.unsize()
34 }
35}
36
37impl<F> Into<Emp<Slice, <Emp<Arr, F> as IntoEmplacable>::Closure>> for Emp<Arr, F> {
38 fn into(self) -> Emp<Slice, <Emp<Arr, F> as IntoEmplacable>::Closure> {
39 self.into_emplacable()
40 }
41}
42
43fn box_new_with(_: Emp<Slice, impl Sized>) {}
44
45pub struct Arr;
46pub struct Slice;
47
48pub fn foo() {
49 let e: Emp<Arr, ()> = Emp { phantom: PhantomData };
50 box_new_with(e.into());
51}
52fn main() {}
tests/ui/intrinsics/transmute-phantomdata-generic-unequal-size.rs created+20
......@@ -0,0 +1,20 @@
1//! regression test for <https://github.com/rust-lang/rust/issues/32377>
2//@ normalize-stderr: "\d+ bits" -> "N bits"
3
4use std::mem;
5use std::marker::PhantomData;
6
7trait Foo {
8 type Error;
9}
10
11struct Bar<U: Foo> {
12 stream: PhantomData<U::Error>,
13}
14
15fn foo<U: Foo>(x: [usize; 2]) -> Bar<U> {
16 unsafe { mem::transmute(x) }
17 //~^ ERROR cannot transmute between types of different sizes, or dependently-sized types
18}
19
20fn main() {}
tests/ui/intrinsics/transmute-phantomdata-generic-unequal-size.stderr created+12
......@@ -0,0 +1,12 @@
1error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
2 --> $DIR/transmute-phantomdata-generic-unequal-size.rs:16:14
3 |
4LL | unsafe { mem::transmute(x) }
5 | ^^^^^^^^^^^^^^
6 |
7 = note: source type: `[usize; 2]` (N bits)
8 = note: target type: `Bar<U>` (N bits)
9
10error: aborting due to 1 previous error
11
12For more information about this error, try `rustc --explain E0512`.
tests/ui/issues/issue-25746-bool-transmute.rs deleted-12
......@@ -1,12 +0,0 @@
1//@ run-pass
2#![allow(unnecessary_transmutes)]
3use std::mem::transmute;
4
5fn main() {
6 unsafe {
7 let _: i8 = transmute(false);
8 let _: i8 = transmute(true);
9 let _: bool = transmute(0u8);
10 let _: bool = transmute(1u8);
11 }
12}
tests/ui/issues/issue-32377.rs deleted-19
......@@ -1,19 +0,0 @@
1//@ normalize-stderr: "\d+ bits" -> "N bits"
2
3use std::mem;
4use std::marker::PhantomData;
5
6trait Foo {
7 type Error;
8}
9
10struct Bar<U: Foo> {
11 stream: PhantomData<U::Error>,
12}
13
14fn foo<U: Foo>(x: [usize; 2]) -> Bar<U> {
15 unsafe { mem::transmute(x) }
16 //~^ ERROR cannot transmute between types of different sizes, or dependently-sized types
17}
18
19fn main() {}
tests/ui/issues/issue-32377.stderr deleted-12
......@@ -1,12 +0,0 @@
1error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
2 --> $DIR/issue-32377.rs:15:14
3 |
4LL | unsafe { mem::transmute(x) }
5 | ^^^^^^^^^^^^^^
6 |
7 = note: source type: `[usize; 2]` (N bits)
8 = note: target type: `Bar<U>` (N bits)
9
10error: aborting due to 1 previous error
11
12For more information about this error, try `rustc --explain E0512`.
tests/ui/transmute/transmute-bool-u8.rs created+13
......@@ -0,0 +1,13 @@
1//! regression test for <https://github.com/rust-lang/rust/issues/25746>
2//@ build-pass
3#![allow(unnecessary_transmutes)]
4use std::mem::transmute;
5
6fn main() {
7 unsafe {
8 let _: i8 = transmute(false);
9 let _: i8 = transmute(true);
10 let _: bool = transmute(0u8);
11 let _: bool = transmute(1u8);
12 }
13}