Auto merge of #152063 - JonathanBrouwer:rollup-EwTnVaj, r=JonathanBrouwer

Rollup of 12 pull requests

Successful merges:

 - rust-lang/rust#152034 (Show largest job duration changes in hours and minutes in the post-merge report)
 - rust-lang/rust#152039 (coverage: Add a test case for a previously-unknown span mismatch)
 - rust-lang/rust#152045 (Convert to inline diagnostics in `rustc_infer`)
 - rust-lang/rust#149263 (Forbid manual `Unpin` impls for structurally pinned types)
 - rust-lang/rust#151754 (Check proj's parent is trait or not when checking dyn compatibility)
 - rust-lang/rust#151848 (Port `rustc_mir` to attribute parser)
 - rust-lang/rust#151874 (error on unsized AnonConsts)
 - rust-lang/rust#151944 (Convert to inline diagnostics in `rustc_attr_parsing`)
 - rust-lang/rust#152019 (`NativeLib` cleanups)
 - rust-lang/rust#152029 (disable socket tests in Miri)
 - rust-lang/rust#152041 (Convert to inline diagnostics in `rustc_query_system`)
 - rust-lang/rust#152050 (Try to fix `rustdoc-gui/globals.goml` flakyness)

Failed merges:

 - rust-lang/rust#152046 (Use glob imports for attribute parsers)
This commit is contained in:
bors 2026-02-03 19:08:19 +00:00
commit 366a1b93e7
64 changed files with 1007 additions and 669 deletions

View file

@ -3543,7 +3543,6 @@ dependencies = [
"rustc_ast_pretty",
"rustc_errors",
"rustc_feature",
"rustc_fluent_macro",
"rustc_hir",
"rustc_lexer",
"rustc_macros",
@ -3684,7 +3683,6 @@ dependencies = [
"rustc_macros",
"rustc_metadata",
"rustc_middle",
"rustc_query_system",
"rustc_serialize",
"rustc_session",
"rustc_span",
@ -3780,7 +3778,6 @@ dependencies = [
"rustc_ast_lowering",
"rustc_ast_passes",
"rustc_ast_pretty",
"rustc_attr_parsing",
"rustc_borrowck",
"rustc_builtin_macros",
"rustc_codegen_ssa",
@ -3794,7 +3791,6 @@ dependencies = [
"rustc_hir_typeck",
"rustc_incremental",
"rustc_index",
"rustc_infer",
"rustc_interface",
"rustc_lexer",
"rustc_lint",
@ -3811,7 +3807,6 @@ dependencies = [
"rustc_pattern_analysis",
"rustc_privacy",
"rustc_public",
"rustc_query_system",
"rustc_resolve",
"rustc_session",
"rustc_span",
@ -4092,7 +4087,6 @@ version = "0.0.0"
dependencies = [
"rustc_data_structures",
"rustc_errors",
"rustc_fluent_macro",
"rustc_hir",
"rustc_index",
"rustc_macros",
@ -4337,11 +4331,11 @@ dependencies = [
"polonius-engine",
"regex",
"rustc_abi",
"rustc_ast",
"rustc_data_structures",
"rustc_errors",
"rustc_fluent_macro",
"rustc_graphviz",
"rustc_hir",
"rustc_index",
"rustc_macros",
"rustc_middle",
@ -4571,7 +4565,6 @@ dependencies = [
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
"rustc_fluent_macro",
"rustc_hashes",
"rustc_hir",
"rustc_index",

View file

@ -10,7 +10,6 @@ rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_errors = { path = "../rustc_errors" }
rustc_feature = { path = "../rustc_feature" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
rustc_hir = { path = "../rustc_hir" }
rustc_lexer = { path = "../rustc_lexer" }
rustc_macros = { path = "../rustc_macros" }

View file

@ -1,246 +0,0 @@
attr_parsing_as_needed_compatibility =
linking modifier `as-needed` is only compatible with `dylib`, `framework` and `raw-dylib` linking kinds
attr_parsing_bundle_needs_static =
linking modifier `bundle` is only compatible with `static` linking kind
attr_parsing_cfg_attr_bad_delim = wrong `cfg_attr` delimiters
attr_parsing_deprecated_item_suggestion =
suggestions on deprecated items are unstable
.help = add `#![feature(deprecated_suggestion)]` to the crate root
.note = see #94785 for more details
attr_parsing_doc_alias_bad_char =
{$char_} character isn't allowed in {$attr_str}
attr_parsing_doc_alias_empty =
{$attr_str} attribute cannot have empty value
attr_parsing_doc_alias_malformed =
doc alias attribute expects a string `#[doc(alias = "a")]` or a list of strings `#[doc(alias("a", "b"))]`
attr_parsing_doc_alias_start_end =
{$attr_str} cannot start or end with ' '
attr_parsing_doc_attr_not_crate_level =
`#![doc({$attr_name} = "...")]` isn't allowed as a crate-level attribute
attr_parsing_doc_attribute_not_attribute =
nonexistent builtin attribute `{$attribute}` used in `#[doc(attribute = "...")]`
.help = only existing builtin attributes are allowed in core/std
attr_parsing_doc_keyword_not_keyword =
nonexistent keyword `{$keyword}` used in `#[doc(keyword = "...")]`
.help = only existing keywords are allowed in core/std
attr_parsing_empty_confusables =
expected at least one confusable name
attr_parsing_empty_link_name =
link name must not be empty
.label = empty link name
attr_parsing_expected_single_version_literal =
expected single version literal
attr_parsing_expected_version_literal =
expected a version literal
attr_parsing_expects_feature_list =
`{$name}` expects a list of feature names
attr_parsing_expects_features =
`{$name}` expects feature names
attr_parsing_import_name_type_raw =
import name type can only be used with link kind `raw-dylib`
attr_parsing_import_name_type_x86 =
import name type is only supported on x86
attr_parsing_incompatible_wasm_link =
`wasm_import_module` is incompatible with other arguments in `#[link]` attributes
attr_parsing_incorrect_repr_format_align_one_arg =
incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses
attr_parsing_incorrect_repr_format_expect_literal_integer =
incorrect `repr(align)` attribute format: `align` expects a literal integer as argument
attr_parsing_incorrect_repr_format_generic =
incorrect `repr({$repr_arg})` attribute format
.suggestion = use parentheses instead
attr_parsing_incorrect_repr_format_packed_expect_integer =
incorrect `repr(packed)` attribute format: `packed` expects a literal integer as argument
attr_parsing_incorrect_repr_format_packed_one_or_zero_arg =
incorrect `repr(packed)` attribute format: `packed` takes exactly one parenthesized argument, or no parentheses at all
attr_parsing_invalid_alignment_value =
invalid alignment value: {$error_part}
attr_parsing_invalid_attr_unsafe = `{$name}` is not an unsafe attribute
.label = this is not an unsafe attribute
.suggestion = remove the `unsafe(...)`
.note = extraneous unsafe is not allowed in attributes
attr_parsing_invalid_issue_string =
`issue` must be a non-zero numeric string or "none"
.must_not_be_zero = `issue` must not be "0", use "none" instead
.empty = cannot parse integer from empty string
.invalid_digit = invalid digit found in string
.pos_overflow = number too large to fit in target type
.neg_overflow = number too small to fit in target type
attr_parsing_invalid_link_modifier =
invalid linking modifier syntax, expected '+' or '-' prefix before one of: bundle, verbatim, whole-archive, as-needed
attr_parsing_invalid_meta_item = expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found {$descr}
.remove_neg_sugg = negative numbers are not literals, try removing the `-` sign
.quote_ident_sugg = surround the identifier with quotation marks to make it into a string literal
.label = {$descr}s are not allowed here
attr_parsing_invalid_predicate =
invalid predicate `{$predicate}`
attr_parsing_invalid_repr_align_need_arg =
invalid `repr(align)` attribute: `align` needs an argument
.suggestion = supply an argument here
attr_parsing_invalid_repr_generic =
invalid `repr({$repr_arg})` attribute: {$error_part}
attr_parsing_invalid_repr_hint_no_paren =
invalid representation hint: `{$name}` does not take a parenthesized argument list
attr_parsing_invalid_repr_hint_no_value =
invalid representation hint: `{$name}` does not take a value
attr_parsing_invalid_since =
'since' must be a Rust version number, such as "1.31.0"
attr_parsing_invalid_target = `#[{$name}]` attribute cannot be used on {$target}
.help = `#[{$name}]` can {$only}be applied to {$applied}
.suggestion = remove the attribute
attr_parsing_limit_invalid =
`limit` must be a non-negative integer
.label = {$error_str}
attr_parsing_link_arg_unstable =
link kind `link-arg` is unstable
attr_parsing_link_cfg_unstable =
link cfg is unstable
attr_parsing_link_framework_apple =
link kind `framework` is only supported on Apple targets
attr_parsing_link_ordinal_out_of_range = ordinal value in `link_ordinal` is too large: `{$ordinal}`
.note = the value may not exceed `u16::MAX`
attr_parsing_link_requires_name =
`#[link]` attribute requires a `name = "string"` argument
.label = missing `name` argument
attr_parsing_meta_bad_delim = wrong meta list delimiters
attr_parsing_meta_bad_delim_suggestion = the delimiters should be `(` and `)`
attr_parsing_missing_feature =
missing 'feature'
attr_parsing_missing_issue =
missing 'issue'
attr_parsing_missing_note =
missing 'note'
attr_parsing_missing_since =
missing 'since'
attr_parsing_multiple_modifiers =
multiple `{$modifier}` modifiers in a single `modifiers` argument
attr_parsing_multiple_stability_levels =
multiple stability levels
attr_parsing_naked_functions_incompatible_attribute =
attribute incompatible with `#[unsafe(naked)]`
.label = the `{$attr}` attribute is incompatible with `#[unsafe(naked)]`
.naked_attribute = function marked with `#[unsafe(naked)]` here
attr_parsing_non_ident_feature =
'feature' is not an identifier
attr_parsing_null_on_export = `export_name` may not contain null characters
attr_parsing_null_on_link_section = `link_section` may not contain null characters
attr_parsing_null_on_objc_class = `objc::class!` may not contain null characters
attr_parsing_null_on_objc_selector = `objc::selector!` may not contain null characters
attr_parsing_objc_class_expected_string_literal = `objc::class!` expected a string literal
attr_parsing_objc_selector_expected_string_literal = `objc::selector!` expected a string literal
attr_parsing_raw_dylib_elf_unstable =
link kind `raw-dylib` is unstable on ELF platforms
attr_parsing_raw_dylib_no_nul =
link name must not contain NUL characters if link kind is `raw-dylib`
attr_parsing_raw_dylib_only_windows =
link kind `raw-dylib` is only supported on Windows targets
attr_parsing_repr_ident =
meta item in `repr` must be an identifier
attr_parsing_rustc_allowed_unstable_pairing =
`rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute
attr_parsing_rustc_promotable_pairing =
`rustc_promotable` attribute must be paired with either a `rustc_const_unstable` or a `rustc_const_stable` attribute
attr_parsing_rustc_scalable_vector_count_out_of_range = element count in `rustc_scalable_vector` is too large: `{$n}`
.note = the value may not exceed `u16::MAX`
attr_parsing_soft_no_args =
`soft` should not have any arguments
attr_parsing_stability_outside_std = stability attributes may not be used outside of the standard library
attr_parsing_suffixed_literal_in_attribute = suffixed literals are not allowed in attributes
.help = instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.)
attr_parsing_unknown_version_literal =
unknown version literal format, assuming it refers to a future version
attr_parsing_unrecognized_repr_hint =
unrecognized representation hint
.help = valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
.note = for more information, visit <https://doc.rust-lang.org/reference/type-layout.html?highlight=repr#representations>
attr_parsing_unsafe_attr_outside_unsafe = unsafe attribute used without unsafe
.label = usage of unsafe attribute
attr_parsing_unsafe_attr_outside_unsafe_suggestion = wrap the attribute in `unsafe(...)`
attr_parsing_unstable_cfg_target_compact =
compact `cfg(target(..))` is experimental and subject to change
attr_parsing_unstable_feature_bound_incompatible_stability = item annotated with `#[unstable_feature_bound]` should not be stable
.help = if this item is meant to be stable, do not use any functions annotated with `#[unstable_feature_bound]`. Otherwise, mark this item as unstable with `#[unstable]`
attr_parsing_unsupported_instruction_set = target `{$current_target}` does not support `#[instruction_set({$instruction_set}::*)]`
attr_parsing_unsupported_literal_suggestion =
consider removing the prefix
attr_parsing_unused_multiple =
multiple `{$name}` attributes
.suggestion = remove this attribute
.note = attribute also specified here
attr_parsing_whole_archive_needs_static =
linking modifier `whole-archive` is only compatible with `static` linking kind

View file

@ -3,7 +3,7 @@ use std::convert::identity;
use rustc_ast::token::Delimiter;
use rustc_ast::tokenstream::DelimSpan;
use rustc_ast::{AttrItem, Attribute, CRATE_NODE_ID, LitKind, ast, token};
use rustc_errors::{Applicability, PResult};
use rustc_errors::{Applicability, PResult, inline_fluent};
use rustc_feature::{
AttrSuggestionStyle, AttributeTemplate, Features, GatedCfg, find_gated_cfg, template,
};
@ -25,7 +25,7 @@ use crate::session_diagnostics::{
AttributeParseError, AttributeParseErrorReason, CfgAttrBadDelim, MetaBadDelimSugg,
ParsedDescription,
};
use crate::{AttributeParser, fluent_generated, parse_version, session_diagnostics};
use crate::{AttributeParser, parse_version, session_diagnostics};
pub const CFG_TEMPLATE: AttributeTemplate = template!(
List: &["predicate"],
@ -141,7 +141,7 @@ fn parse_cfg_entry_target<S: Stage>(
cx.sess(),
sym::cfg_target_compact,
meta_span,
fluent_generated::attr_parsing_unstable_cfg_target_compact,
inline_fluent!("compact `cfg(target(..))` is experimental and subject to change"),
)
.emit();
}

View file

@ -1,3 +1,4 @@
use rustc_errors::inline_fluent;
use rustc_feature::Features;
use rustc_hir::attrs::AttributeKind::{LinkName, LinkOrdinal, LinkSection};
use rustc_hir::attrs::*;
@ -10,7 +11,6 @@ use rustc_target::spec::{Arch, BinaryFormat};
use super::prelude::*;
use super::util::parse_single_integer;
use crate::attributes::cfg::parse_cfg_entry;
use crate::fluent_generated;
use crate::session_diagnostics::{
AsNeededCompatibility, BundleNeedsStatic, EmptyLinkName, ImportNameTypeRaw, ImportNameTypeX86,
IncompatibleWasmLink, InvalidLinkModifier, LinkFrameworkApple, LinkOrdinalOutOfRange,
@ -305,7 +305,7 @@ impl LinkParser {
sess,
sym::raw_dylib_elf,
nv.value_span,
fluent_generated::attr_parsing_raw_dylib_elf_unstable,
inline_fluent!("link kind `raw-dylib` is unstable on ELF platforms"),
)
.emit();
} else {
@ -320,7 +320,7 @@ impl LinkParser {
sess,
sym::link_arg_attribute,
nv.value_span,
fluent_generated::attr_parsing_link_arg_unstable,
inline_fluent!("link kind `link-arg` is unstable"),
)
.emit();
}
@ -385,13 +385,8 @@ impl LinkParser {
return true;
};
if !features.link_cfg() {
feature_err(
sess,
sym::link_cfg,
item.span(),
fluent_generated::attr_parsing_link_cfg_unstable,
)
.emit();
feature_err(sess, sym::link_cfg, item.span(), inline_fluent!("link cfg is unstable"))
.emit();
}
*cfg = parse_cfg_entry(cx, link_cfg).ok();
true

View file

@ -1,5 +1,7 @@
use std::path::PathBuf;
use rustc_ast::{LitIntType, LitKind, MetaItemLit};
use rustc_hir::attrs::RustcLayoutType;
use rustc_hir::attrs::{BorrowckGraphvizFormatKind, RustcLayoutType, RustcMirKind};
use rustc_session::errors;
use super::prelude::*;
@ -357,7 +359,6 @@ impl<S: Stage> CombineAttributeParser<S> for RustcLayoutParser {
const TEMPLATE: AttributeTemplate =
template!(List: &["abi", "align", "size", "homogenous_aggregate", "debug"]);
fn extend(
cx: &mut AcceptContext<'_, '_, S>,
args: &ArgParser,
@ -397,6 +398,94 @@ impl<S: Stage> CombineAttributeParser<S> for RustcLayoutParser {
}
}
pub(crate) struct RustcMirParser;
impl<S: Stage> CombineAttributeParser<S> for RustcMirParser {
const PATH: &[rustc_span::Symbol] = &[sym::rustc_mir];
type Item = RustcMirKind;
const CONVERT: ConvertFn<Self::Item> = |items, _| AttributeKind::RustcMir(items);
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
Allow(Target::Fn),
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Method(MethodKind::TraitImpl)),
Allow(Target::Method(MethodKind::Trait { body: false })),
Allow(Target::Method(MethodKind::Trait { body: true })),
]);
const TEMPLATE: AttributeTemplate = template!(List: &["arg1, arg2, ..."]);
fn extend(
cx: &mut AcceptContext<'_, '_, S>,
args: &ArgParser,
) -> impl IntoIterator<Item = Self::Item> {
let Some(list) = args.list() else {
cx.expected_list(cx.attr_span, args);
return ThinVec::new();
};
list.mixed()
.filter_map(|arg| arg.meta_item())
.filter_map(|mi| {
if let Some(ident) = mi.ident() {
match ident.name {
sym::rustc_peek_maybe_init => Some(RustcMirKind::PeekMaybeInit),
sym::rustc_peek_maybe_uninit => Some(RustcMirKind::PeekMaybeUninit),
sym::rustc_peek_liveness => Some(RustcMirKind::PeekLiveness),
sym::stop_after_dataflow => Some(RustcMirKind::StopAfterDataflow),
sym::borrowck_graphviz_postflow => {
let Some(nv) = mi.args().name_value() else {
cx.expected_name_value(
mi.span(),
Some(sym::borrowck_graphviz_postflow),
);
return None;
};
let Some(path) = nv.value_as_str() else {
cx.expected_string_literal(nv.value_span, None);
return None;
};
let path = PathBuf::from(path.to_string());
if path.file_name().is_some() {
Some(RustcMirKind::BorrowckGraphvizPostflow { path })
} else {
cx.expected_filename_literal(nv.value_span);
None
}
}
sym::borrowck_graphviz_format => {
let Some(nv) = mi.args().name_value() else {
cx.expected_name_value(
mi.span(),
Some(sym::borrowck_graphviz_format),
);
return None;
};
let Some(format) = nv.value_as_ident() else {
cx.expected_identifier(nv.value_span);
return None;
};
match format.name {
sym::two_phase => Some(RustcMirKind::BorrowckGraphvizFormat {
format: BorrowckGraphvizFormatKind::TwoPhase,
}),
_ => {
cx.expected_specific_argument(format.span, &[sym::two_phase]);
None
}
}
}
_ => None,
}
} else {
None
}
})
.collect()
}
}
pub(crate) struct RustcNonConstTraitMethodParser;
impl<S: Stage> NoArgsAttributeParser<S> for RustcNonConstTraitMethodParser {

View file

@ -81,7 +81,7 @@ use crate::attributes::rustc_internal::{
RustcLayoutScalarValidRangeEndParser, RustcLayoutScalarValidRangeStartParser,
RustcLegacyConstGenericsParser, RustcLintOptDenyFieldAccessParser, RustcLintOptTyParser,
RustcLintQueryInstabilityParser, RustcLintUntrackedQueryInformationParser, RustcMainParser,
RustcMustImplementOneOfParser, RustcNeverReturnsNullPointerParser,
RustcMirParser, RustcMustImplementOneOfParser, RustcNeverReturnsNullPointerParser,
RustcNoImplicitAutorefsParser, RustcNonConstTraitMethodParser, RustcNounwindParser,
RustcObjectLifetimeDefaultParser, RustcOffloadKernelParser, RustcScalableVectorParser,
RustcSimdMonomorphizeLaneLimitParser,
@ -202,6 +202,7 @@ attribute_parsers!(
Combine<LinkParser>,
Combine<ReprParser>,
Combine<RustcLayoutParser>,
Combine<RustcMirParser>,
Combine<TargetFeatureParser>,
Combine<UnstableFeatureBoundParser>,
// tidy-alphabetical-end
@ -517,6 +518,11 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
)
}
/// Error that a filename string literal was expected.
pub(crate) fn expected_filename_literal(&self, span: Span) {
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedFilenameLiteral);
}
pub(crate) fn expected_integer_literal(&self, span: Span) -> ErrorGuaranteed {
self.emit_parse_error(span, AttributeParseErrorReason::ExpectedIntegerLiteral)
}

View file

@ -113,5 +113,3 @@ pub use attributes::util::{is_builtin_attr, parse_version};
pub use context::{Early, Late, OmitDoc, ShouldEmit};
pub use interface::AttributeParser;
pub use session_diagnostics::ParsedDescription;
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

View file

@ -11,10 +11,8 @@ use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Span, Symbol};
use rustc_target::spec::TargetTuple;
use crate::fluent_generated as fluent;
#[derive(Diagnostic)]
#[diag(attr_parsing_invalid_predicate, code = E0537)]
#[diag("invalid predicate `{$predicate}`", code = E0537)]
pub(crate) struct InvalidPredicate {
#[primary_span]
pub span: Span,
@ -23,7 +21,7 @@ pub(crate) struct InvalidPredicate {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_doc_alias_empty)]
#[diag("{$attr_str} attribute cannot have empty value")]
pub(crate) struct DocAliasEmpty<'a> {
#[primary_span]
pub span: Span,
@ -31,7 +29,7 @@ pub(crate) struct DocAliasEmpty<'a> {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_doc_alias_bad_char)]
#[diag("{$char_} character isn't allowed in {$attr_str}")]
pub(crate) struct DocAliasBadChar<'a> {
#[primary_span]
pub span: Span,
@ -40,7 +38,7 @@ pub(crate) struct DocAliasBadChar<'a> {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_doc_alias_start_end)]
#[diag("{$attr_str} cannot start or end with ' '")]
pub(crate) struct DocAliasStartEnd<'a> {
#[primary_span]
pub span: Span,
@ -48,7 +46,7 @@ pub(crate) struct DocAliasStartEnd<'a> {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_doc_attr_not_crate_level)]
#[diag("`#![doc({$attr_name} = \"...\")]` isn't allowed as a crate-level attribute")]
pub(crate) struct DocAttrNotCrateLevel {
#[primary_span]
pub span: Span,
@ -56,8 +54,8 @@ pub(crate) struct DocAttrNotCrateLevel {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_doc_keyword_not_keyword)]
#[help]
#[diag("nonexistent keyword `{$keyword}` used in `#[doc(keyword = \"...\")]`")]
#[help("only existing keywords are allowed in core/std")]
pub(crate) struct DocKeywordNotKeyword {
#[primary_span]
pub span: Span,
@ -65,8 +63,8 @@ pub(crate) struct DocKeywordNotKeyword {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_doc_attribute_not_attribute)]
#[help]
#[diag("nonexistent builtin attribute `{$attribute}` used in `#[doc(attribute = \"...\")]`")]
#[help("only existing builtin attributes are allowed in core/std")]
pub(crate) struct DocAttributeNotAttribute {
#[primary_span]
pub span: Span,
@ -74,28 +72,28 @@ pub(crate) struct DocAttributeNotAttribute {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_missing_since, code = E0542)]
#[diag("missing 'since'", code = E0542)]
pub(crate) struct MissingSince {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_missing_note, code = E0543)]
#[diag("missing 'note'", code = E0543)]
pub(crate) struct MissingNote {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_multiple_stability_levels, code = E0544)]
#[diag("multiple stability levels", code = E0544)]
pub(crate) struct MultipleStabilityLevels {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_invalid_issue_string, code = E0545)]
#[diag("`issue` must be a non-zero numeric string or \"none\"", code = E0545)]
pub(crate) struct InvalidIssueString {
#[primary_span]
pub span: Span,
@ -108,31 +106,31 @@ pub(crate) struct InvalidIssueString {
// translatable.
#[derive(Subdiagnostic)]
pub(crate) enum InvalidIssueStringCause {
#[label(attr_parsing_must_not_be_zero)]
#[label("`issue` must not be \"0\", use \"none\" instead")]
MustNotBeZero {
#[primary_span]
span: Span,
},
#[label(attr_parsing_empty)]
#[label("cannot parse integer from empty string")]
Empty {
#[primary_span]
span: Span,
},
#[label(attr_parsing_invalid_digit)]
#[label("invalid digit found in string")]
InvalidDigit {
#[primary_span]
span: Span,
},
#[label(attr_parsing_pos_overflow)]
#[label("number too large to fit in target type")]
PosOverflow {
#[primary_span]
span: Span,
},
#[label(attr_parsing_neg_overflow)]
#[label("number too small to fit in target type")]
NegOverflow {
#[primary_span]
span: Span,
@ -153,21 +151,21 @@ impl InvalidIssueStringCause {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_missing_feature, code = E0546)]
#[diag("missing 'feature'", code = E0546)]
pub(crate) struct MissingFeature {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_non_ident_feature, code = E0546)]
#[diag("'feature' is not an identifier", code = E0546)]
pub(crate) struct NonIdentFeature {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_missing_issue, code = E0547)]
#[diag("missing 'issue'", code = E0547)]
pub(crate) struct MissingIssue {
#[primary_span]
pub span: Span,
@ -176,20 +174,20 @@ pub(crate) struct MissingIssue {
// FIXME: Why is this the same error code as `InvalidReprHintNoParen` and `InvalidReprHintNoValue`?
// It is more similar to `IncorrectReprFormatGeneric`.
#[derive(Diagnostic)]
#[diag(attr_parsing_incorrect_repr_format_packed_one_or_zero_arg, code = E0552)]
#[diag("incorrect `repr(packed)` attribute format: `packed` takes exactly one parenthesized argument, or no parentheses at all", code = E0552)]
pub(crate) struct IncorrectReprFormatPackedOneOrZeroArg {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_incorrect_repr_format_packed_expect_integer, code = E0552)]
#[diag("incorrect `repr(packed)` attribute format: `packed` expects a literal integer as argument", code = E0552)]
pub(crate) struct IncorrectReprFormatPackedExpectInteger {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_invalid_repr_hint_no_paren, code = E0552)]
#[diag("invalid representation hint: `{$name}` does not take a parenthesized argument list", code = E0552)]
pub(crate) struct InvalidReprHintNoParen {
#[primary_span]
pub span: Span,
@ -198,7 +196,7 @@ pub(crate) struct InvalidReprHintNoParen {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_invalid_repr_hint_no_value, code = E0552)]
#[diag("invalid representation hint: `{$name}` does not take a value", code = E0552)]
pub(crate) struct InvalidReprHintNoValue {
#[primary_span]
pub span: Span,
@ -207,15 +205,19 @@ pub(crate) struct InvalidReprHintNoValue {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_invalid_repr_align_need_arg, code = E0589)]
#[diag("invalid `repr(align)` attribute: `align` needs an argument", code = E0589)]
pub(crate) struct InvalidReprAlignNeedArg {
#[primary_span]
#[suggestion(code = "align(...)", applicability = "has-placeholders")]
#[suggestion(
"supply an argument here",
code = "align(...)",
applicability = "has-placeholders"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_invalid_repr_generic, code = E0589)]
#[diag("invalid `repr({$repr_arg})` attribute: {$error_part}", code = E0589)]
pub(crate) struct InvalidReprGeneric<'a> {
#[primary_span]
pub span: Span,
@ -225,21 +227,21 @@ pub(crate) struct InvalidReprGeneric<'a> {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_incorrect_repr_format_align_one_arg, code = E0693)]
#[diag("incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses", code = E0693)]
pub(crate) struct IncorrectReprFormatAlignOneArg {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_incorrect_repr_format_expect_literal_integer, code = E0693)]
#[diag("incorrect `repr(align)` attribute format: `align` expects a literal integer as argument", code = E0693)]
pub(crate) struct IncorrectReprFormatExpectInteger {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_incorrect_repr_format_generic, code = E0693)]
#[diag("incorrect `repr({$repr_arg})` attribute format", code = E0693)]
pub(crate) struct IncorrectReprFormatGeneric {
#[primary_span]
pub span: Span,
@ -253,7 +255,7 @@ pub(crate) struct IncorrectReprFormatGeneric {
#[derive(Subdiagnostic)]
pub(crate) enum IncorrectReprFormatGenericCause {
#[suggestion(
attr_parsing_suggestion,
"use parentheses instead",
code = "{name}({value})",
applicability = "machine-applicable"
)]
@ -269,7 +271,7 @@ pub(crate) enum IncorrectReprFormatGenericCause {
},
#[suggestion(
attr_parsing_suggestion,
"use parentheses instead",
code = "{name}({value})",
applicability = "machine-applicable"
)]
@ -298,48 +300,48 @@ impl IncorrectReprFormatGenericCause {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_rustc_promotable_pairing, code = E0717)]
#[diag("`rustc_promotable` attribute must be paired with either a `rustc_const_unstable` or a `rustc_const_stable` attribute", code = E0717)]
pub(crate) struct RustcPromotablePairing {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_rustc_allowed_unstable_pairing, code = E0789)]
#[diag("`rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute", code = E0789)]
pub(crate) struct RustcAllowedUnstablePairing {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_deprecated_item_suggestion)]
#[diag("suggestions on deprecated items are unstable")]
pub(crate) struct DeprecatedItemSuggestion {
#[primary_span]
pub span: Span,
#[help]
#[help("add `#![feature(deprecated_suggestion)]` to the crate root")]
pub is_nightly: bool,
#[note]
#[note("see #94785 for more details")]
pub details: (),
}
#[derive(Diagnostic)]
#[diag(attr_parsing_expected_single_version_literal)]
#[diag("expected single version literal")]
pub(crate) struct ExpectedSingleVersionLiteral {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_expected_version_literal)]
#[diag("expected a version literal")]
pub(crate) struct ExpectedVersionLiteral {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_expects_feature_list)]
#[diag("`{$name}` expects a list of feature names")]
pub(crate) struct ExpectsFeatureList {
#[primary_span]
pub span: Span,
@ -348,7 +350,7 @@ pub(crate) struct ExpectsFeatureList {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_expects_features)]
#[diag("`{$name}` expects feature names")]
pub(crate) struct ExpectsFeatures {
#[primary_span]
pub span: Span,
@ -357,21 +359,21 @@ pub(crate) struct ExpectsFeatures {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_invalid_since)]
#[diag("'since' must be a Rust version number, such as \"1.31.0\"")]
pub(crate) struct InvalidSince {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_soft_no_args)]
#[diag("`soft` should not have any arguments")]
pub(crate) struct SoftNoArgs {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_unknown_version_literal)]
#[diag("unknown version literal format, assuming it refers to a future version")]
pub(crate) struct UnknownVersionLiteral {
#[primary_span]
pub span: Span,
@ -379,78 +381,83 @@ pub(crate) struct UnknownVersionLiteral {
// FIXME(jdonszelmann) duplicated from `rustc_passes`, remove once `check_attr` is integrated.
#[derive(Diagnostic)]
#[diag(attr_parsing_unused_multiple)]
#[diag("multiple `{$name}` attributes")]
pub(crate) struct UnusedMultiple {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable")]
#[suggestion("remove this attribute", code = "", applicability = "machine-applicable")]
pub this: Span,
#[note]
#[note("attribute also specified here")]
pub other: Span,
pub name: Symbol,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_null_on_export, code = E0648)]
#[diag("`export_name` may not contain null characters", code = E0648)]
pub(crate) struct NullOnExport {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_null_on_link_section, code = E0648)]
#[diag("`link_section` may not contain null characters", code = E0648)]
pub(crate) struct NullOnLinkSection {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_null_on_objc_class)]
#[diag("`objc::class!` may not contain null characters")]
pub(crate) struct NullOnObjcClass {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_null_on_objc_selector)]
#[diag("`objc::selector!` may not contain null characters")]
pub(crate) struct NullOnObjcSelector {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_objc_class_expected_string_literal)]
#[diag("`objc::class!` expected a string literal")]
pub(crate) struct ObjcClassExpectedStringLiteral {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_objc_selector_expected_string_literal)]
#[diag("`objc::selector!` expected a string literal")]
pub(crate) struct ObjcSelectorExpectedStringLiteral {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_stability_outside_std, code = E0734)]
#[diag("stability attributes may not be used outside of the standard library", code = E0734)]
pub(crate) struct StabilityOutsideStd {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_empty_confusables)]
#[diag("expected at least one confusable name")]
pub(crate) struct EmptyConfusables {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[help]
#[diag(attr_parsing_invalid_target)]
#[help("`#[{$name}]` can {$only}be applied to {$applied}")]
#[diag("`#[{$name}]` attribute cannot be used on {$target}")]
pub(crate) struct InvalidTarget {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
#[suggestion(
"remove the attribute",
code = "",
applicability = "machine-applicable",
style = "tool-only"
)]
pub span: Span,
pub name: AttrPath,
pub target: &'static str,
@ -459,7 +466,7 @@ pub(crate) struct InvalidTarget {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_invalid_alignment_value, code = E0589)]
#[diag("invalid alignment value: {$error_part}", code = E0589)]
pub(crate) struct InvalidAlignmentValue {
#[primary_span]
pub span: Span,
@ -467,43 +474,49 @@ pub(crate) struct InvalidAlignmentValue {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_repr_ident, code = E0565)]
#[diag("meta item in `repr` must be an identifier", code = E0565)]
pub(crate) struct ReprIdent {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_unrecognized_repr_hint, code = E0552)]
#[help]
#[note]
#[diag("unrecognized representation hint", code = E0552)]
#[help(
"valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`"
)]
#[note(
"for more information, visit <https://doc.rust-lang.org/reference/type-layout.html?highlight=repr#representations>"
)]
pub(crate) struct UnrecognizedReprHint {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_unstable_feature_bound_incompatible_stability)]
#[help]
#[diag("item annotated with `#[unstable_feature_bound]` should not be stable")]
#[help(
"if this item is meant to be stable, do not use any functions annotated with `#[unstable_feature_bound]`. Otherwise, mark this item as unstable with `#[unstable]`"
)]
pub(crate) struct UnstableFeatureBoundIncompatibleStability {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_naked_functions_incompatible_attribute, code = E0736)]
#[diag("attribute incompatible with `#[unsafe(naked)]`", code = E0736)]
pub(crate) struct NakedFunctionIncompatibleAttribute {
#[primary_span]
#[label]
#[label("the `{$attr}` attribute is incompatible with `#[unsafe(naked)]`")]
pub span: Span,
#[label(attr_parsing_naked_attribute)]
#[label("function marked with `#[unsafe(naked)]` here")]
pub naked_span: Span,
pub attr: String,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_link_ordinal_out_of_range)]
#[note]
#[diag("ordinal value in `link_ordinal` is too large: `{$ordinal}`")]
#[note("the value may not exceed `u16::MAX`")]
pub(crate) struct LinkOrdinalOutOfRange {
#[primary_span]
pub span: Span,
@ -511,8 +524,8 @@ pub(crate) struct LinkOrdinalOutOfRange {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_rustc_scalable_vector_count_out_of_range)]
#[note]
#[diag("element count in `rustc_scalable_vector` is too large: `{$n}`")]
#[note("the value may not exceed `u16::MAX`")]
pub(crate) struct RustcScalableVectorCountOutOfRange {
#[primary_span]
pub span: Span,
@ -524,6 +537,7 @@ pub(crate) enum AttributeParseErrorReason<'a> {
ExpectedStringLiteral {
byte_string: Option<Span>,
},
ExpectedFilenameLiteral,
ExpectedIntegerLiteral,
ExpectedIntegerLiteralInRange {
lower_bound: isize,
@ -586,7 +600,7 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError<'_> {
if let Some(start_point_span) = byte_string {
diag.span_suggestion(
start_point_span,
fluent::attr_parsing_unsupported_literal_suggestion,
"consider removing the prefix",
"",
Applicability::MaybeIncorrect,
);
@ -597,6 +611,9 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError<'_> {
diag.span_label(self.span, "expected a string literal here");
}
}
AttributeParseErrorReason::ExpectedFilenameLiteral => {
diag.span_label(self.span, "expected a filename string literal here");
}
AttributeParseErrorReason::ExpectedIntegerLiteral => {
diag.span_label(self.span, "expected an integer literal here");
}
@ -751,30 +768,27 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError<'_> {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_invalid_attr_unsafe)]
#[note]
#[diag("`{$name}` is not an unsafe attribute")]
#[note("extraneous unsafe is not allowed in attributes")]
pub(crate) struct InvalidAttrUnsafe {
#[primary_span]
#[label]
#[label("this is not an unsafe attribute")]
pub span: Span,
pub name: AttrPath,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_unsafe_attr_outside_unsafe)]
#[diag("unsafe attribute used without unsafe")]
pub(crate) struct UnsafeAttrOutsideUnsafe {
#[primary_span]
#[label]
#[label("usage of unsafe attribute")]
pub span: Span,
#[subdiagnostic]
pub suggestion: Option<UnsafeAttrOutsideUnsafeSuggestion>,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
attr_parsing_unsafe_attr_outside_unsafe_suggestion,
applicability = "machine-applicable"
)]
#[multipart_suggestion("wrap the attribute in `unsafe(...)`", applicability = "machine-applicable")]
pub(crate) struct UnsafeAttrOutsideUnsafeSuggestion {
#[suggestion_part(code = "unsafe(")]
pub left: Span,
@ -783,7 +797,7 @@ pub(crate) struct UnsafeAttrOutsideUnsafeSuggestion {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_meta_bad_delim)]
#[diag("wrong meta list delimiters")]
pub(crate) struct MetaBadDelim {
#[primary_span]
pub span: Span,
@ -793,7 +807,7 @@ pub(crate) struct MetaBadDelim {
#[derive(Subdiagnostic)]
#[multipart_suggestion(
attr_parsing_meta_bad_delim_suggestion,
"the delimiters should be `(` and `)`",
applicability = "machine-applicable"
)]
pub(crate) struct MetaBadDelimSugg {
@ -804,7 +818,7 @@ pub(crate) struct MetaBadDelimSugg {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_invalid_meta_item)]
#[diag("expected a literal (`1u8`, `1.0f32`, `\"string\"`, etc.) here, found {$descr}")]
pub(crate) struct InvalidMetaItem {
#[primary_span]
pub span: Span,
@ -813,12 +827,15 @@ pub(crate) struct InvalidMetaItem {
pub quote_ident_sugg: Option<InvalidMetaItemQuoteIdentSugg>,
#[subdiagnostic]
pub remove_neg_sugg: Option<InvalidMetaItemRemoveNegSugg>,
#[label]
#[label("{$descr}s are not allowed here")]
pub label: Option<Span>,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(attr_parsing_quote_ident_sugg, applicability = "machine-applicable")]
#[multipart_suggestion(
"surround the identifier with quotation marks to make it into a string literal",
applicability = "machine-applicable"
)]
pub(crate) struct InvalidMetaItemQuoteIdentSugg {
#[suggestion_part(code = "\"")]
pub before: Span,
@ -827,73 +844,80 @@ pub(crate) struct InvalidMetaItemQuoteIdentSugg {
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(attr_parsing_remove_neg_sugg, applicability = "machine-applicable")]
#[multipart_suggestion(
"negative numbers are not literals, try removing the `-` sign",
applicability = "machine-applicable"
)]
pub(crate) struct InvalidMetaItemRemoveNegSugg {
#[suggestion_part(code = "")]
pub negative_sign: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_suffixed_literal_in_attribute)]
#[help]
#[diag("suffixed literals are not allowed in attributes")]
#[help(
"instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.)"
)]
pub(crate) struct SuffixedLiteralInAttribute {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_empty_link_name, code = E0454)]
#[diag("link name must not be empty", code = E0454)]
pub(crate) struct EmptyLinkName {
#[primary_span]
#[label]
#[label("empty link name")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_link_framework_apple, code = E0455)]
#[diag("link kind `framework` is only supported on Apple targets", code = E0455)]
pub(crate) struct LinkFrameworkApple {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_incompatible_wasm_link)]
#[diag("`wasm_import_module` is incompatible with other arguments in `#[link]` attributes")]
pub(crate) struct IncompatibleWasmLink {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_link_requires_name, code = E0459)]
#[diag("`#[link]` attribute requires a `name = \"string\"` argument", code = E0459)]
pub(crate) struct LinkRequiresName {
#[primary_span]
#[label]
#[label("missing `name` argument")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_raw_dylib_no_nul)]
#[diag("link name must not contain NUL characters if link kind is `raw-dylib`")]
pub(crate) struct RawDylibNoNul {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_raw_dylib_only_windows, code = E0455)]
#[diag("link kind `raw-dylib` is only supported on Windows targets", code = E0455)]
pub(crate) struct RawDylibOnlyWindows {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_invalid_link_modifier)]
#[diag(
"invalid linking modifier syntax, expected '+' or '-' prefix before one of: bundle, verbatim, whole-archive, as-needed"
)]
pub(crate) struct InvalidLinkModifier {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_multiple_modifiers)]
#[diag("multiple `{$modifier}` modifiers in a single `modifiers` argument")]
pub(crate) struct MultipleModifiers {
#[primary_span]
pub span: Span,
@ -901,52 +925,54 @@ pub(crate) struct MultipleModifiers {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_import_name_type_x86)]
#[diag("import name type is only supported on x86")]
pub(crate) struct ImportNameTypeX86 {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_bundle_needs_static)]
#[diag("linking modifier `bundle` is only compatible with `static` linking kind")]
pub(crate) struct BundleNeedsStatic {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_whole_archive_needs_static)]
#[diag("linking modifier `whole-archive` is only compatible with `static` linking kind")]
pub(crate) struct WholeArchiveNeedsStatic {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_as_needed_compatibility)]
#[diag(
"linking modifier `as-needed` is only compatible with `dylib`, `framework` and `raw-dylib` linking kinds"
)]
pub(crate) struct AsNeededCompatibility {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_import_name_type_raw)]
#[diag("import name type can only be used with link kind `raw-dylib`")]
pub(crate) struct ImportNameTypeRaw {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_limit_invalid)]
#[diag("`limit` must be a non-negative integer")]
pub(crate) struct LimitInvalid<'a> {
#[primary_span]
pub span: Span,
#[label]
#[label("{$error_str}")]
pub value_span: Span,
pub error_str: &'a str,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_cfg_attr_bad_delim)]
#[diag("wrong `cfg_attr` delimiters")]
pub(crate) struct CfgAttrBadDelim {
#[primary_span]
pub span: Span,
@ -955,14 +981,16 @@ pub(crate) struct CfgAttrBadDelim {
}
#[derive(Diagnostic)]
#[diag(attr_parsing_doc_alias_malformed)]
#[diag(
"doc alias attribute expects a string `#[doc(alias = \"a\")]` or a list of strings `#[doc(alias(\"a\", \"b\"))]`"
)]
pub(crate) struct DocAliasMalformed {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_parsing_unsupported_instruction_set)]
#[diag("target `{$current_target}` does not support `#[instruction_set({$instruction_set}::*)]`")]
pub(crate) struct UnsupportedInstructionSet<'a> {
#[primary_span]
pub span: Span,

View file

@ -28,7 +28,6 @@ rustc_lint_defs = { path = "../rustc_lint_defs" }
rustc_macros = { path = "../rustc_macros" }
rustc_metadata = { path = "../rustc_metadata" }
rustc_middle = { path = "../rustc_middle" }
rustc_query_system = { path = "../rustc_query_system" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }

View file

@ -24,7 +24,7 @@ use rustc_data_structures::unord::UnordMap;
use rustc_hir::CRATE_HIR_ID;
use rustc_hir::attrs::{CfgEntry, NativeLibKind, WindowsSubsystemKind};
use rustc_hir::def_id::CrateNum;
use rustc_macros::{Decodable, Encodable, HashStable};
use rustc_macros::{Decodable, Encodable};
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::WorkProduct;
use rustc_middle::lint::LevelAndSource;
@ -175,7 +175,12 @@ bitflags::bitflags! {
}
}
#[derive(Clone, Debug, Encodable, Decodable, HashStable)]
// This is the same as `rustc_session::cstore::NativeLib`, except:
// - (important) the `foreign_module` field is missing, because it contains a `DefId`, which can't
// be encoded with `FileEncoder`.
// - (less important) the `verbatim` field is a `bool` rather than an `Option<bool>`, because here
// we can treat `false` and `absent` the same.
#[derive(Clone, Debug, Encodable, Decodable)]
pub struct NativeLib {
pub kind: NativeLibKind,
pub name: Symbol,

View file

@ -12,7 +12,6 @@ rustc_ast = { path = "../rustc_ast" }
rustc_ast_lowering = { path = "../rustc_ast_lowering" }
rustc_ast_passes = { path = "../rustc_ast_passes" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
rustc_borrowck = { path = "../rustc_borrowck" }
rustc_builtin_macros = { path = "../rustc_builtin_macros" }
rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }
@ -26,7 +25,6 @@ rustc_hir_pretty = { path = "../rustc_hir_pretty" }
rustc_hir_typeck = { path = "../rustc_hir_typeck" }
rustc_incremental = { path = "../rustc_incremental" }
rustc_index = { path = "../rustc_index" }
rustc_infer = { path = "../rustc_infer" }
rustc_interface = { path = "../rustc_interface" }
rustc_lexer = { path = "../rustc_lexer" }
rustc_lint = { path = "../rustc_lint" }
@ -43,7 +41,6 @@ rustc_passes = { path = "../rustc_passes" }
rustc_pattern_analysis = { path = "../rustc_pattern_analysis" }
rustc_privacy = { path = "../rustc_privacy" }
rustc_public = { path = "../rustc_public", features = ["rustc_internal"] }
rustc_query_system = { path = "../rustc_query_system" }
rustc_resolve = { path = "../rustc_resolve" }
rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }

View file

@ -116,7 +116,6 @@ pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
// tidy-alphabetical-start
rustc_ast_lowering::DEFAULT_LOCALE_RESOURCE,
rustc_ast_passes::DEFAULT_LOCALE_RESOURCE,
rustc_attr_parsing::DEFAULT_LOCALE_RESOURCE,
rustc_borrowck::DEFAULT_LOCALE_RESOURCE,
rustc_builtin_macros::DEFAULT_LOCALE_RESOURCE,
rustc_codegen_ssa::DEFAULT_LOCALE_RESOURCE,
@ -126,7 +125,6 @@ pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
rustc_hir_analysis::DEFAULT_LOCALE_RESOURCE,
rustc_hir_typeck::DEFAULT_LOCALE_RESOURCE,
rustc_incremental::DEFAULT_LOCALE_RESOURCE,
rustc_infer::DEFAULT_LOCALE_RESOURCE,
rustc_interface::DEFAULT_LOCALE_RESOURCE,
rustc_lint::DEFAULT_LOCALE_RESOURCE,
rustc_metadata::DEFAULT_LOCALE_RESOURCE,
@ -139,7 +137,6 @@ pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
rustc_passes::DEFAULT_LOCALE_RESOURCE,
rustc_pattern_analysis::DEFAULT_LOCALE_RESOURCE,
rustc_privacy::DEFAULT_LOCALE_RESOURCE,
rustc_query_system::DEFAULT_LOCALE_RESOURCE,
rustc_resolve::DEFAULT_LOCALE_RESOURCE,
rustc_session::DEFAULT_LOCALE_RESOURCE,
rustc_trait_selection::DEFAULT_LOCALE_RESOURCE,

View file

@ -166,3 +166,14 @@ impl Translator {
}
}
}
/// This macro creates a translatable `DiagMessage` from a literal string.
/// It should be used in places where a translatable message is needed, but struct diagnostics are undesired.
///
/// This is a macro because in the future we may want to globally register these messages.
#[macro_export]
macro_rules! inline_fluent {
($inline: literal) => {
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed($inline))
};
}

View file

@ -699,6 +699,21 @@ pub enum RustcLayoutType {
Debug,
}
#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute, PartialEq, Eq)]
pub enum RustcMirKind {
PeekMaybeInit,
PeekMaybeUninit,
PeekLiveness,
StopAfterDataflow,
BorrowckGraphvizPostflow { path: PathBuf },
BorrowckGraphvizFormat { format: BorrowckGraphvizFormatKind },
}
#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute, PartialEq, Eq)]
pub enum BorrowckGraphvizFormatKind {
TwoPhase,
}
/// Represents parsed *built-in* inert attributes.
///
/// ## Overview
@ -1090,6 +1105,9 @@ pub enum AttributeKind {
/// Represents `#[rustc_main]`.
RustcMain,
/// Represents `#[rustc_mir]`.
RustcMir(ThinVec<RustcMirKind>),
/// Represents `#[rustc_must_implement_one_of]`
RustcMustImplementOneOf { attr_span: Span, fn_names: ThinVec<Ident> },

View file

@ -122,6 +122,7 @@ impl AttributeKind {
RustcLintUntrackedQueryInformation => Yes,
RustcMacroTransparency(..) => Yes,
RustcMain => No,
RustcMir(..) => Yes,
RustcMustImplementOneOf { .. } => No,
RustcNeverReturnsNullPointer => Yes,
RustcNoImplicitAutorefs => Yes,

View file

@ -1,5 +1,6 @@
use std::num::NonZero;
use std::ops::Deref;
use std::path::PathBuf;
use rustc_abi::Align;
use rustc_ast::attr::data_structures::CfgEntry;
@ -96,7 +97,15 @@ impl<T: PrintAttribute> PrintAttribute for FxIndexMap<T, Span> {
p.word("]");
}
}
impl PrintAttribute for PathBuf {
fn should_render(&self) -> bool {
true
}
fn print_attribute(&self, p: &mut Printer) {
p.word(self.display().to_string());
}
}
macro_rules! print_skip {
($($t: ty),* $(,)?) => {$(
impl PrintAttribute for $t {

View file

@ -224,6 +224,10 @@ hir_analysis_impl_not_marked_default = `{$ident}` specializes an item from a par
hir_analysis_impl_not_marked_default_err = `{$ident}` specializes an item from a parent `impl`, but that item is not marked `default`
.note = parent implementation is in crate `{$cname}`
hir_analysis_impl_unpin_for_pin_projected_type = explicit impls for the `Unpin` trait are not permitted for structurally pinned types
.label = impl of `Unpin` not allowed
.help = `{$adt_name}` is structurally pinned because it is marked as `#[pin_v2]`
hir_analysis_inherent_dyn = cannot define inherent `impl` for a dyn auto trait
.label = impl requires at least one non-auto trait
.note = define and implement a new trait or type instead

View file

@ -38,6 +38,7 @@ pub(super) fn check_trait<'tcx>(
checker.check(lang_items.drop_trait(), visit_implementation_of_drop)?;
checker.check(lang_items.async_drop_trait(), visit_implementation_of_drop)?;
checker.check(lang_items.copy_trait(), visit_implementation_of_copy)?;
checker.check(lang_items.unpin_trait(), visit_implementation_of_unpin)?;
checker.check(lang_items.const_param_ty_trait(), |checker| {
visit_implementation_of_const_param_ty(checker)
})?;
@ -134,6 +135,41 @@ fn visit_implementation_of_copy(checker: &Checker<'_>) -> Result<(), ErrorGuaran
}
}
fn visit_implementation_of_unpin(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {
let tcx = checker.tcx;
let impl_header = checker.impl_header;
let impl_did = checker.impl_def_id;
debug!("visit_implementation_of_unpin: impl_did={:?}", impl_did);
let self_type = impl_header.trait_ref.instantiate_identity().self_ty();
debug!("visit_implementation_of_unpin: self_type={:?}", self_type);
let span = tcx.def_span(impl_did);
if tcx.features().pin_ergonomics() {
match self_type.kind() {
// Soundness concerns: a type `T` annotated with `#[pin_v2]` is allowed to project
// `Pin<&mut T>` to its field `Pin<&mut U>` safely (even if `U: !Unpin`).
// If `T` is allowed to impl `Unpin` manually (note that `Unpin` is a safe trait,
// which cannot carry safety properties), then `&mut U` could be obtained from
// `&mut T` that dereferenced by `Pin<&mut T>`, which breaks the safety contract of
// `Pin<&mut U>` for `U: !Unpin`.
ty::Adt(adt, _) if adt.is_pin_project() => {
return Err(tcx.dcx().emit_err(crate::errors::ImplUnpinForPinProjectedType {
span,
adt_span: tcx.def_span(adt.did()),
adt_name: tcx.item_name(adt.did()),
}));
}
ty::Adt(_, _) => {}
_ => {
return Err(tcx.dcx().span_delayed_bug(span, "impl of `Unpin` for a non-adt type"));
}
};
}
Ok(())
}
fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {
let tcx = checker.tcx;
let header = checker.impl_header;

View file

@ -1690,3 +1690,14 @@ pub(crate) struct EiiWithGenerics {
pub eii_name: Symbol,
pub impl_name: Symbol,
}
#[derive(Diagnostic)]
#[diag(hir_analysis_impl_unpin_for_pin_projected_type)]
pub(crate) struct ImplUnpinForPinProjectedType {
#[primary_span]
#[label]
pub span: Span,
#[help]
pub adt_span: Span,
pub adt_name: Symbol,
}

View file

@ -200,6 +200,14 @@ fn typeck_with_inspect<'tcx>(
let wf_code = ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(def_id)));
fcx.register_wf_obligation(expected_type.into(), body.value.span, wf_code);
if let hir::Node::AnonConst(_) = node {
fcx.require_type_is_sized(
expected_type,
body.value.span,
ObligationCauseCode::SizedConstOrStatic,
);
}
fcx.check_expr_coercible_to_type(body.value, expected_type, None);
fcx.write_ty(id, expected_type);

View file

@ -10,7 +10,6 @@ doctest = false
# tidy-alphabetical-start
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }
rustc_macros = { path = "../rustc_macros" }

View file

@ -1,5 +0,0 @@
infer_opaque_hidden_type =
opaque type's hidden type cannot be another opaque type from the same scope
.label = one of the two opaque types used here has to be outside its defining scope
.opaque_type = opaque type whose hidden type is being assigned
.hidden_type = opaque type being used as hidden type

View file

@ -2,13 +2,13 @@ use rustc_macros::Diagnostic;
use rustc_span::Span;
#[derive(Diagnostic)]
#[diag(infer_opaque_hidden_type)]
#[diag("opaque type's hidden type cannot be another opaque type from the same scope")]
pub(crate) struct OpaqueHiddenTypeDiag {
#[primary_span]
#[label]
#[label("one of the two opaque types used here has to be outside its defining scope")]
pub span: Span,
#[note(infer_opaque_type)]
#[note("opaque type whose hidden type is being assigned")]
pub opaque_type: Span,
#[note(infer_hidden_type)]
#[note("opaque type being used as hidden type")]
pub hidden_type: Span,
}

View file

@ -22,5 +22,3 @@
mod errors;
pub mod infer;
pub mod traits;
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

View file

@ -31,7 +31,7 @@ impl<'a> DiagnosticDerive<'a> {
return DiagnosticDeriveError::ErrorHandled.to_compile_error();
};
messages.borrow_mut().push(message.clone());
let message = message.diag_message(variant);
let message = message.diag_message(Some(variant));
let init = quote! {
let mut diag = rustc_errors::Diag::new(
@ -97,7 +97,7 @@ impl<'a> LintDiagnosticDerive<'a> {
return DiagnosticDeriveError::ErrorHandled.to_compile_error();
};
messages.borrow_mut().push(message.clone());
let message = message.diag_message(variant);
let message = message.diag_message(Some(variant));
let primary_message = quote! {
diag.primary_message(#message);
};

View file

@ -456,7 +456,7 @@ impl DiagnosticDeriveVariantBuilder {
applicability.set_once(quote! { #static_applicability }, span);
}
let message = slug.diag_message(variant);
let message = slug.diag_message(Some(variant));
let applicability = applicability
.value()
.unwrap_or_else(|| quote! { rustc_errors::Applicability::Unspecified });
@ -487,7 +487,7 @@ impl DiagnosticDeriveVariantBuilder {
variant: &VariantInfo<'_>,
) -> TokenStream {
let fn_name = format_ident!("span_{}", kind);
let message = message.diag_message(variant);
let message = message.diag_message(Some(variant));
quote! {
diag.#fn_name(
#field_binding,
@ -504,7 +504,7 @@ impl DiagnosticDeriveVariantBuilder {
message: Message,
variant: &VariantInfo<'_>,
) -> TokenStream {
let message = message.diag_message(variant);
let message = message.diag_message(Some(variant));
quote! {
diag.#kind(#message);
}

View file

@ -14,13 +14,18 @@ pub(crate) enum Message {
}
impl Message {
pub(crate) fn diag_message(&self, variant: &VariantInfo<'_>) -> TokenStream {
/// Get the diagnostic message for this diagnostic
/// The passed `variant` is used to check whether all variables in the message are used.
/// For subdiagnostics, we cannot check this.
pub(crate) fn diag_message(&self, variant: Option<&VariantInfo<'_>>) -> TokenStream {
match self {
Message::Slug(slug) => {
quote! { crate::fluent_generated::#slug }
}
Message::Inline(message_span, message) => {
verify_fluent_message(*message_span, &message, variant);
if let Some(variant) = variant {
verify_fluent_message(*message_span, &message, variant);
}
quote! { rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed(#message)) }
}
}

View file

@ -75,7 +75,7 @@ impl SubdiagnosticDerive {
has_subdiagnostic: false,
is_enum,
};
builder.into_tokens(variant).unwrap_or_else(|v| v.to_compile_error())
builder.into_tokens().unwrap_or_else(|v| v.to_compile_error())
});
quote! {
@ -497,10 +497,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
}
}
pub(crate) fn into_tokens(
&mut self,
variant: &VariantInfo<'_>,
) -> Result<TokenStream, DiagnosticDeriveError> {
pub(crate) fn into_tokens(&mut self) -> Result<TokenStream, DiagnosticDeriveError> {
let kind_slugs = self.identify_kind()?;
let kind_stats: KindsStatistics = kind_slugs.iter().map(|(kind, _slug)| kind).collect();
@ -538,7 +535,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
let mut calls = TokenStream::new();
for (kind, slug) in kind_slugs {
let message = format_ident!("__message");
let message_stream = slug.diag_message(variant);
let message_stream = slug.diag_message(None);
calls.extend(quote! { let #message = #diag.eagerly_translate(#message_stream); });
let name = format_ident!("{}{}", if span_field.is_some() { "span_" } else { "" }, kind);

View file

@ -8,11 +8,11 @@ edition = "2024"
polonius-engine = "0.13.0"
regex = "1"
rustc_abi = { path = "../rustc_abi" }
rustc_ast = { path = "../rustc_ast" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
rustc_graphviz = { path = "../rustc_graphviz" }
rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }
rustc_macros = { path = "../rustc_macros" }
rustc_middle = { path = "../rustc_middle" }

View file

@ -1,9 +1,3 @@
mir_dataflow_duplicate_values_for =
duplicate values for `{$name}`
mir_dataflow_path_must_end_in_filename =
path must end in a filename
mir_dataflow_peek_argument_not_a_local =
rustc_peek: argument was not a local
@ -19,11 +13,5 @@ mir_dataflow_peek_must_be_not_temporary =
mir_dataflow_peek_must_be_place_or_ref_place =
rustc_peek: argument expression must be either `place` or `&place`
mir_dataflow_requires_an_argument =
`{$name}` requires an argument
mir_dataflow_stop_after_dataflow_ended_compilation =
stop_after_dataflow ended compilation
mir_dataflow_unknown_formatter =
unknown formatter

View file

@ -1,35 +1,5 @@
use rustc_macros::Diagnostic;
use rustc_span::{Span, Symbol};
#[derive(Diagnostic)]
#[diag(mir_dataflow_path_must_end_in_filename)]
pub(crate) struct PathMustEndInFilename {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(mir_dataflow_unknown_formatter)]
pub(crate) struct UnknownFormatter {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(mir_dataflow_duplicate_values_for)]
pub(crate) struct DuplicateValuesFor {
#[primary_span]
pub span: Span,
pub name: Symbol,
}
#[derive(Diagnostic)]
#[diag(mir_dataflow_requires_an_argument)]
pub(crate) struct RequiresAnArgument {
#[primary_span]
pub span: Span,
pub name: Symbol,
}
use rustc_span::Span;
#[derive(Diagnostic)]
#[diag(mir_dataflow_stop_after_dataflow_ended_compilation)]

View file

@ -7,6 +7,9 @@ use std::sync::OnceLock;
use std::{io, ops, str};
use regex::Regex;
use rustc_graphviz as dot;
use rustc_hir::attrs::{AttributeKind, BorrowckGraphvizFormatKind, RustcMirKind};
use rustc_hir::find_attr;
use rustc_index::bit_set::DenseBitSet;
use rustc_middle::mir::{
self, BasicBlock, Body, Location, MirDumper, graphviz_safe_def_name, traversal,
@ -14,17 +17,12 @@ use rustc_middle::mir::{
use rustc_middle::ty::TyCtxt;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_span::def_id::DefId;
use rustc_span::{Symbol, sym};
use tracing::debug;
use {rustc_ast as ast, rustc_graphviz as dot};
use super::fmt::{DebugDiffWithAdapter, DebugWithAdapter, DebugWithContext};
use super::{
Analysis, CallReturnPlaces, Direction, Results, ResultsCursor, ResultsVisitor, visit_results,
};
use crate::errors::{
DuplicateValuesFor, PathMustEndInFilename, RequiresAnArgument, UnknownFormatter,
};
/// Writes a DOT file containing the results of a dataflow analysis if the user requested it via
/// `rustc_mir` attributes and `-Z dump-mir-dataflow`. The `Result` in and the `Results` out are
@ -43,10 +41,7 @@ where
use std::io::Write;
let def_id = body.source.def_id();
let Ok(attrs) = RustcMirAttrs::parse(tcx, def_id) else {
// Invalid `rustc_mir` attrs are reported in `RustcMirAttrs::parse`
return Ok(());
};
let attrs = RustcMirAttrs::parse(tcx, def_id);
let file = try {
match attrs.output_path(A::NAME) {
@ -72,10 +67,7 @@ where
Err(e) => return Err(e),
};
let style = match attrs.formatter {
Some(sym::two_phase) => OutputStyle::BeforeAndAfter,
_ => OutputStyle::AfterOnly,
};
let style = attrs.formatter.unwrap_or(OutputStyle::AfterOnly);
let mut buf = Vec::new();
@ -98,71 +90,33 @@ where
#[derive(Default)]
struct RustcMirAttrs {
basename_and_suffix: Option<PathBuf>,
formatter: Option<Symbol>,
formatter: Option<OutputStyle>,
}
impl RustcMirAttrs {
fn parse(tcx: TyCtxt<'_>, def_id: DefId) -> Result<Self, ()> {
let mut result = Ok(());
fn parse(tcx: TyCtxt<'_>, def_id: DefId) -> Self {
let mut ret = RustcMirAttrs::default();
let rustc_mir_attrs = tcx
.get_attrs(def_id, sym::rustc_mir)
.flat_map(|attr| attr.meta_item_list().into_iter().flat_map(|v| v.into_iter()));
for attr in rustc_mir_attrs {
let attr_result = match attr.name() {
Some(name @ sym::borrowck_graphviz_postflow) => {
Self::set_field(&mut ret.basename_and_suffix, tcx, name, &attr, |s| {
let path = PathBuf::from(s.to_string());
match path.file_name() {
Some(_) => Ok(path),
None => {
tcx.dcx().emit_err(PathMustEndInFilename { span: attr.span() });
Err(())
let attrs = tcx.get_all_attrs(def_id);
if let Some(rustc_mir_attrs) = find_attr!(attrs, AttributeKind::RustcMir(kind) => kind) {
for attr in rustc_mir_attrs {
match attr {
RustcMirKind::BorrowckGraphvizPostflow { path } => {
ret.basename_and_suffix = Some(path.clone());
}
RustcMirKind::BorrowckGraphvizFormat { format } => {
ret.formatter = match format {
BorrowckGraphvizFormatKind::TwoPhase => {
Some(OutputStyle::BeforeAndAfter)
}
}
})
}
Some(name @ sym::borrowck_graphviz_format) => {
Self::set_field(&mut ret.formatter, tcx, name, &attr, |s| match s {
sym::two_phase => Ok(s),
_ => {
tcx.dcx().emit_err(UnknownFormatter { span: attr.span() });
Err(())
}
})
}
_ => Ok(()),
};
result = result.and(attr_result);
};
}
_ => (),
};
}
}
result.map(|()| ret)
}
fn set_field<T>(
field: &mut Option<T>,
tcx: TyCtxt<'_>,
name: Symbol,
attr: &ast::MetaItemInner,
mapper: impl FnOnce(Symbol) -> Result<T, ()>,
) -> Result<(), ()> {
if field.is_some() {
tcx.dcx().emit_err(DuplicateValuesFor { span: attr.span(), name });
return Err(());
}
if let Some(s) = attr.value_str() {
*field = Some(mapper(s)?);
Ok(())
} else {
tcx.dcx()
.emit_err(RequiresAnArgument { span: attr.span(), name: attr.name().unwrap() });
Err(())
}
ret
}
/// Returns the path where dataflow results should be written, or `None`

View file

@ -1,8 +1,8 @@
use rustc_ast::MetaItem;
use rustc_hir::attrs::{AttributeKind, RustcMirKind};
use rustc_hir::find_attr;
use rustc_middle::mir::{self, Body, Local, Location};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::def_id::DefId;
use rustc_span::{Span, Symbol, sym};
use rustc_span::{Span, sym};
use tracing::{debug, info};
use crate::errors::{
@ -14,52 +14,37 @@ use crate::impls::{MaybeInitializedPlaces, MaybeLiveLocals, MaybeUninitializedPl
use crate::move_paths::{HasMoveData, LookupResult, MoveData, MovePathIndex};
use crate::{Analysis, JoinSemiLattice, ResultsCursor};
fn has_rustc_mir_with(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) -> Option<MetaItem> {
for attr in tcx.get_attrs(def_id, sym::rustc_mir) {
let items = attr.meta_item_list();
for item in items.iter().flat_map(|l| l.iter()) {
match item.meta_item() {
Some(mi) if mi.has_name(name) => return Some(mi.clone()),
_ => continue,
}
}
}
None
}
pub fn sanity_check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
let def_id = body.source.def_id();
if !tcx.has_attr(def_id, sym::rustc_mir) {
debug!("skipping rustc_peek::SanityCheck on {}", tcx.def_path_str(def_id));
return;
} else {
let attrs = tcx.get_all_attrs(def_id);
if let Some(kind) = find_attr!(attrs, AttributeKind::RustcMir(kind) => kind) {
let move_data = MoveData::gather_moves(body, tcx, |_| true);
debug!("running rustc_peek::SanityCheck on {}", tcx.def_path_str(def_id));
}
if kind.contains(&RustcMirKind::PeekMaybeInit) {
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &move_data)
.iterate_to_fixpoint(tcx, body, None)
.into_results_cursor(body);
sanity_check_via_rustc_peek(tcx, flow_inits);
}
let move_data = MoveData::gather_moves(body, tcx, |_| true);
if kind.contains(&RustcMirKind::PeekMaybeUninit) {
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &move_data)
.iterate_to_fixpoint(tcx, body, None)
.into_results_cursor(body);
sanity_check_via_rustc_peek(tcx, flow_uninits);
}
if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_maybe_init).is_some() {
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &move_data)
.iterate_to_fixpoint(tcx, body, None)
.into_results_cursor(body);
sanity_check_via_rustc_peek(tcx, flow_inits);
}
if kind.contains(&RustcMirKind::PeekLiveness) {
let flow_liveness =
MaybeLiveLocals.iterate_to_fixpoint(tcx, body, None).into_results_cursor(body);
sanity_check_via_rustc_peek(tcx, flow_liveness);
}
if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_maybe_uninit).is_some() {
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &move_data)
.iterate_to_fixpoint(tcx, body, None)
.into_results_cursor(body);
sanity_check_via_rustc_peek(tcx, flow_uninits);
}
if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_liveness).is_some() {
let flow_liveness =
MaybeLiveLocals.iterate_to_fixpoint(tcx, body, None).into_results_cursor(body);
sanity_check_via_rustc_peek(tcx, flow_liveness);
}
if has_rustc_mir_with(tcx, def_id, sym::stop_after_dataflow).is_some() {
tcx.dcx().emit_fatal(StopAfterDataFlowEndedCompilation);
if kind.contains(&RustcMirKind::StopAfterDataflow) {
tcx.dcx().emit_fatal(StopAfterDataFlowEndedCompilation);
}
} else {
debug!("skipping rustc_peek::SanityCheck on {}", tcx.def_path_str(def_id));
}
}

View file

@ -55,12 +55,10 @@ pub(super) fn extract_refined_covspans<'tcx>(
}
// Each pushed covspan should have the same context as the body span.
// If it somehow doesn't, discard the covspan, or panic in debug builds.
// If it somehow doesn't, discard the covspan.
if !body_span.eq_ctxt(covspan_span) {
debug_assert!(
false,
"span context mismatch: body_span={body_span:?}, covspan.span={covspan_span:?}"
);
// FIXME(Zalathar): Investigate how and why this is triggered
// by `tests/coverage/macros/context-mismatch-issue-147339.rs`.
return false;
}

View file

@ -309,6 +309,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| AttributeKind::RustcLintUntrackedQueryInformation
| AttributeKind::RustcMacroTransparency(_)
| AttributeKind::RustcMain
| AttributeKind::RustcMir(_)
| AttributeKind::RustcNeverReturnsNullPointer
| AttributeKind::RustcNoImplicitAutorefs
| AttributeKind::RustcNonConstTraitMethod

View file

@ -11,7 +11,6 @@ rustc_ast = { path = "../rustc_ast" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_feature = { path = "../rustc_feature" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
rustc_hashes = { path = "../rustc_hashes" }
rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }

View file

@ -1,30 +0,0 @@
query_system_cycle = cycle detected when {$stack_bottom}
.note = see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
query_system_cycle_recursive_trait_alias = trait aliases cannot be recursive
query_system_cycle_recursive_ty_alias = type aliases cannot be recursive
query_system_cycle_recursive_ty_alias_help1 = consider using a struct, enum, or union instead to break the cycle
query_system_cycle_recursive_ty_alias_help2 = see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information
query_system_cycle_stack_middle = ...which requires {$desc}...
query_system_cycle_stack_multiple = ...which again requires {$stack_bottom}, completing the cycle
query_system_cycle_stack_single = ...which immediately requires {$stack_bottom} again
query_system_cycle_usage = cycle used when {$usage}
query_system_increment_compilation = internal compiler error: encountered incremental compilation error with {$dep_node}
query_system_increment_compilation_note1 = please follow the instructions below to create a bug report with the provided information
query_system_increment_compilation_note2 = for incremental compilation bugs, having a reproduction is vital
query_system_increment_compilation_note3 = an ideal reproduction consists of the code before and some patch that then triggers the bug when applied and compiled again
query_system_increment_compilation_note4 = as a workaround, you can run {$run_cmd} to allow your project to compile
query_system_overflow_note = query depth increased by {$depth} when {$desc}
query_system_query_overflow = queries overflow the depth limit!
.help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`)
query_system_reentrant = internal compiler error: reentrant incremental verify failure, suppressing message

View file

@ -4,7 +4,7 @@ use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Span, Symbol};
#[derive(Subdiagnostic)]
#[note(query_system_cycle_stack_middle)]
#[note("...which requires {$desc}...")]
pub(crate) struct CycleStack {
#[primary_span]
pub span: Span,
@ -13,24 +13,26 @@ pub(crate) struct CycleStack {
#[derive(Subdiagnostic)]
pub(crate) enum StackCount {
#[note(query_system_cycle_stack_single)]
#[note("...which immediately requires {$stack_bottom} again")]
Single,
#[note(query_system_cycle_stack_multiple)]
#[note("...which again requires {$stack_bottom}, completing the cycle")]
Multiple,
}
#[derive(Subdiagnostic)]
pub(crate) enum Alias {
#[note(query_system_cycle_recursive_ty_alias)]
#[help(query_system_cycle_recursive_ty_alias_help1)]
#[help(query_system_cycle_recursive_ty_alias_help2)]
#[note("type aliases cannot be recursive")]
#[help("consider using a struct, enum, or union instead to break the cycle")]
#[help(
"see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information"
)]
Ty,
#[note(query_system_cycle_recursive_trait_alias)]
#[note("trait aliases cannot be recursive")]
Trait,
}
#[derive(Subdiagnostic)]
#[note(query_system_cycle_usage)]
#[note("cycle used when {$usage}")]
pub(crate) struct CycleUsage {
#[primary_span]
pub span: Span,
@ -38,7 +40,7 @@ pub(crate) struct CycleUsage {
}
#[derive(Diagnostic)]
#[diag(query_system_cycle, code = E0391)]
#[diag("cycle detected when {$stack_bottom}", code = E0391)]
pub(crate) struct Cycle {
#[primary_span]
pub span: Span,
@ -51,28 +53,34 @@ pub(crate) struct Cycle {
pub alias: Option<Alias>,
#[subdiagnostic]
pub cycle_usage: Option<CycleUsage>,
#[note]
#[note(
"see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information"
)]
pub note_span: (),
}
#[derive(Diagnostic)]
#[diag(query_system_reentrant)]
#[diag("internal compiler error: reentrant incremental verify failure, suppressing message")]
pub(crate) struct Reentrant;
#[derive(Diagnostic)]
#[diag(query_system_increment_compilation)]
#[note(query_system_increment_compilation_note1)]
#[note(query_system_increment_compilation_note2)]
#[note(query_system_increment_compilation_note3)]
#[note(query_system_increment_compilation_note4)]
#[diag("internal compiler error: encountered incremental compilation error with {$dep_node}")]
#[note("please follow the instructions below to create a bug report with the provided information")]
#[note("for incremental compilation bugs, having a reproduction is vital")]
#[note(
"an ideal reproduction consists of the code before and some patch that then triggers the bug when applied and compiled again"
)]
#[note("as a workaround, you can run {$run_cmd} to allow your project to compile")]
pub(crate) struct IncrementCompilation {
pub run_cmd: String,
pub dep_node: String,
}
#[derive(Diagnostic)]
#[help]
#[diag(query_system_query_overflow)]
#[help(
"consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]` attribute to your crate (`{$crate_name}`)"
)]
#[diag("queries overflow the depth limit!")]
pub struct QueryOverflow {
#[primary_span]
pub span: Span,
@ -83,7 +91,7 @@ pub struct QueryOverflow {
}
#[derive(Subdiagnostic)]
#[note(query_system_overflow_note)]
#[note("query depth increased by {$depth} when {$desc}")]
pub struct QueryOverflowNote {
pub desc: String,
pub depth: usize,

View file

@ -14,5 +14,3 @@ mod values;
pub use error::{QueryOverflow, QueryOverflowNote};
pub use values::Value;
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

View file

@ -8,6 +8,7 @@ use std::ops::ControlFlow;
use rustc_errors::FatalError;
use rustc_hir::attrs::AttributeKind;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId;
use rustc_hir::{self as hir, LangItem, find_attr};
use rustc_middle::query::Providers;
@ -833,8 +834,10 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalSelfTypeVisitor<'tcx> {
match ct.kind() {
ty::ConstKind::Unevaluated(proj) if self.tcx.features().min_generic_const_args() => {
match self.allow_self_projections {
AllowSelfProjections::Yes => {
let trait_def_id = self.tcx.parent(proj.def);
AllowSelfProjections::Yes
if let trait_def_id = self.tcx.parent(proj.def)
&& self.tcx.def_kind(trait_def_id) == DefKind::Trait =>
{
let trait_ref = ty::TraitRef::from_assoc(self.tcx, trait_def_id, proj.args);
// Only walk contained consts if the parent trait is not a supertrait.
@ -844,7 +847,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalSelfTypeVisitor<'tcx> {
ct.super_visit_with(self)
}
}
AllowSelfProjections::No => ct.super_visit_with(self),
_ => ct.super_visit_with(self),
}
}
_ => ct.super_visit_with(self),

View file

@ -1,4 +1,5 @@
#![cfg(windows)]
#![cfg(not(miri))] // no socket support in Miri
#![feature(windows_unix_domain_sockets)]
// Now only test windows_unix_domain_sockets feature
// in the future, will test both unix and windows uds

View file

@ -66,9 +66,9 @@ checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
[[package]]
name = "askama"
version = "0.15.1"
version = "0.15.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb7125972258312e79827b60c9eb93938334100245081cf701a2dee981b17427"
checksum = "08e1676b346cadfec169374f949d7490fd80a24193d37d2afce0c047cf695e57"
dependencies = [
"askama_macros",
"itoa",
@ -79,9 +79,9 @@ dependencies = [
[[package]]
name = "askama_derive"
version = "0.15.1"
version = "0.15.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ba5e7259a1580c61571e3116ebaaa01e3c001b2132b17c4cc5c70780ca3e994"
checksum = "7661ff56517787343f376f75db037426facd7c8d3049cef8911f1e75016f3a37"
dependencies = [
"askama_parser",
"basic-toml",
@ -96,18 +96,18 @@ dependencies = [
[[package]]
name = "askama_macros"
version = "0.15.1"
version = "0.15.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "236ce20b77cb13506eaf5024899f4af6e12e8825f390bd943c4c37fd8f322e46"
checksum = "713ee4dbfd1eb719c2dab859465b01fa1d21cb566684614a713a6b7a99a4e47b"
dependencies = [
"askama_derive",
]
[[package]]
name = "askama_parser"
version = "0.15.1"
version = "0.15.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3c63392767bb2df6aa65a6e1e3b80fd89bb7af6d58359b924c0695620f1512e"
checksum = "1d62d674238a526418b30c0def480d5beadb9d8964e7f38d635b03bf639c704c"
dependencies = [
"rustc-hash",
"serde",

View file

@ -194,8 +194,8 @@ pub fn output_test_diffs(
report_test_diffs(aggregated_test_diffs, job_metrics, job_info_resolver);
}
/// Prints the ten largest differences in bootstrap durations.
pub fn output_largest_duration_changes(
/// Prints the ten largest differences in job durations.
pub fn output_largest_job_duration_changes(
job_metrics: &HashMap<JobName, JobMetrics>,
job_info_resolver: &mut JobInfoResolver,
) {
@ -237,11 +237,11 @@ pub fn output_largest_duration_changes(
println!("# Job duration changes");
for (index, entry) in changes.into_iter().take(10).enumerate() {
println!(
"{}. {}: {:.1}s -> {:.1}s ({:+.1}%)",
"{}. {}: {} -> {} ({:+.1}%)",
index + 1,
format_job_link(job_info_resolver, job_metrics, entry.job),
entry.before.as_secs_f64(),
entry.after.as_secs_f64(),
format_duration(entry.before),
format_duration(entry.after),
entry.change
);
}
@ -256,6 +256,27 @@ mostly for t-infra members, for simpler debugging of potential CI slow-downs."#
});
}
fn format_duration(duration: Duration) -> String {
let total_secs = duration.as_secs();
let hours = total_secs / 3600;
let minutes = (total_secs % 3600) / 60;
let seconds = total_secs % 60;
let mut res = String::new();
if hours > 0 {
res.push_str(&format!("{hours}h "));
}
if minutes > 0 {
res.push_str(&format!("{minutes}m "));
}
if hours == 0 && seconds > 0 {
res.push_str(&format!("{seconds}s"));
}
res.trim().to_string()
}
#[derive(Default)]
struct TestSuiteRecord {
passed: u64,

View file

@ -17,7 +17,7 @@ use clap::Parser;
use jobs::JobDatabase;
use serde_yaml::Value;
use crate::analysis::{output_largest_duration_changes, output_test_diffs};
use crate::analysis::{output_largest_job_duration_changes, output_test_diffs};
use crate::cpu_usage::load_cpu_usage;
use crate::datadog::upload_datadog_metric;
use crate::github::JobInfoResolver;
@ -205,7 +205,7 @@ And then open `test-dashboard/index.html` in your browser to see an overview of
);
});
output_largest_duration_changes(&metrics, &mut job_info_resolver);
output_largest_job_duration_changes(&metrics, &mut job_info_resolver);
Ok(())
}

View file

@ -0,0 +1,40 @@
Function name: context_mismatch_issue_147339::a (unused)
Raw bytes (14): 0x[01, 01, 00, 02, 00, 0c, 27, 00, 35, 00, 00, 3b, 00, 3c]
Number of files: 1
- file 0 => $DIR/context-mismatch-issue-147339.rs
Number of expressions: 0
Number of file 0 mappings: 2
- Code(Zero) at (prev + 12, 39) to (start + 0, 53)
- Code(Zero) at (prev + 0, 59) to (start + 0, 60)
Highest counter ID seen: (none)
Function name: context_mismatch_issue_147339::b (unused)
Raw bytes (14): 0x[01, 01, 00, 02, 00, 0c, 27, 00, 35, 00, 00, 3b, 00, 3c]
Number of files: 1
- file 0 => $DIR/context-mismatch-issue-147339.rs
Number of expressions: 0
Number of file 0 mappings: 2
- Code(Zero) at (prev + 12, 39) to (start + 0, 53)
- Code(Zero) at (prev + 0, 59) to (start + 0, 60)
Highest counter ID seen: (none)
Function name: context_mismatch_issue_147339::c (unused)
Raw bytes (14): 0x[01, 01, 00, 02, 00, 0c, 27, 00, 35, 00, 00, 3b, 00, 3c]
Number of files: 1
- file 0 => $DIR/context-mismatch-issue-147339.rs
Number of expressions: 0
Number of file 0 mappings: 2
- Code(Zero) at (prev + 12, 39) to (start + 0, 53)
- Code(Zero) at (prev + 0, 59) to (start + 0, 60)
Highest counter ID seen: (none)
Function name: context_mismatch_issue_147339::main
Raw bytes (14): 0x[01, 01, 00, 02, 01, 14, 01, 00, 0a, 01, 00, 0c, 00, 0d]
Number of files: 1
- file 0 => $DIR/context-mismatch-issue-147339.rs
Number of expressions: 0
Number of file 0 mappings: 2
- Code(Counter(0)) at (prev + 20, 1) to (start + 0, 10)
- Code(Counter(0)) at (prev + 0, 12) to (start + 0, 13)
Highest counter ID seen: c0

View file

@ -0,0 +1,28 @@
LL| |//@ edition: 2024
LL| |
LL| |// These nested macro expansions were found to cause span refinement to produce
LL| |// spans with a context that doesn't match the function body span, triggering
LL| |// a defensive check that discards the span.
LL| |//
LL| |// Reported in <https://github.com/rust-lang/rust/issues/147339>.
LL| |
LL| |macro_rules! foo {
LL| | ($($m:ident $($f:ident $v:tt)+),*) => {
LL| | $($(macro_rules! $f { () => { $v } })+)*
LL| 0| $(macro_rules! $m { () => { $(fn $f() -> i32 { $v })+ } })*
------------------
| Unexecuted instantiation: context_mismatch_issue_147339::a
------------------
| Unexecuted instantiation: context_mismatch_issue_147339::b
------------------
| Unexecuted instantiation: context_mismatch_issue_147339::c
------------------
LL| | }
LL| |}
LL| |
LL| |foo!(m a 1 b 2, n c 3);
LL| |m!();
LL| |n!();
LL| |
LL| 1|fn main() {}

View file

@ -0,0 +1,20 @@
//@ edition: 2024
// These nested macro expansions were found to cause span refinement to produce
// spans with a context that doesn't match the function body span, triggering
// a defensive check that discards the span.
//
// Reported in <https://github.com/rust-lang/rust/issues/147339>.
macro_rules! foo {
($($m:ident $($f:ident $v:tt)+),*) => {
$($(macro_rules! $f { () => { $v } })+)*
$(macro_rules! $m { () => { $(fn $f() -> i32 { $v })+ } })*
}
}
foo!(m a 1 b 2, n c 3);
m!();
n!();
fn main() {}

View file

@ -1,16 +0,0 @@
//@ known-bug: #137582
#![feature(adt_const_params)]
mod lib {
pub type Matrix = [&'static u32];
const EMPTY_MATRIX: Matrix = [[0; 4]; 4];
pub struct Walk<const CURRENT: usize, const REMAINING: Matrix> {
_p: (),
}
impl<const CURRENT: usize> Walk<CURRENT, EMPTY_MATRIX> {}
}
fn main() {}

View file

@ -6,7 +6,7 @@ include: "utils.goml"
// URL query
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html?search=sa"
wait-for: "#search-tabs"
assert-window-property-false: {"searchIndex": null}
wait-for-window-property-false: {"searchIndex": null}
// Form input
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"

View file

@ -0,0 +1,22 @@
// regression test for issue #137582, where constant evaluating an unsized AnonConst would ICE
#![feature(adt_const_params)]
mod lib {
pub type Matrix = [&'static u32];
const EMPTY_MATRIX: Matrix = [[0; 4]; 4];
//~^ ERROR the size for values of type `[&'static u32]` cannot be known at compilation time
//~| ERROR mismatched types
//~| ERROR mismatched types
pub struct Walk<const CURRENT: usize, const REMAINING: Matrix> {
//~^ ERROR use of unstable library feature `unsized_const_params`
_p: (),
}
impl<const CURRENT: usize> Walk<CURRENT, EMPTY_MATRIX> {}
//~^ ERROR the size for values of type `[&'static u32]` cannot be known at compilation time
}
fn main() {}

View file

@ -0,0 +1,44 @@
error[E0277]: the size for values of type `[&'static u32]` cannot be known at compilation time
--> $DIR/unsized-anon-const-err-1.rs:8:25
|
LL | const EMPTY_MATRIX: Matrix = [[0; 4]; 4];
| ^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[&'static u32]`
= note: statics and constants must have a statically known size
error[E0658]: use of unstable library feature `unsized_const_params`
--> $DIR/unsized-anon-const-err-1.rs:13:43
|
LL | pub struct Walk<const CURRENT: usize, const REMAINING: Matrix> {
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add `#![feature(unsized_const_params)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: required for `[&'static u32]` to implement `ConstParamTy_`
error[E0277]: the size for values of type `[&'static u32]` cannot be known at compilation time
--> $DIR/unsized-anon-const-err-1.rs:18:46
|
LL | impl<const CURRENT: usize> Walk<CURRENT, EMPTY_MATRIX> {}
| ^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[&'static u32]`
= note: statics and constants must have a statically known size
error[E0308]: mismatched types
--> $DIR/unsized-anon-const-err-1.rs:8:35
|
LL | const EMPTY_MATRIX: Matrix = [[0; 4]; 4];
| ^^^^^^ expected `&u32`, found `[{integer}; 4]`
error[E0308]: mismatched types
--> $DIR/unsized-anon-const-err-1.rs:8:34
|
LL | const EMPTY_MATRIX: Matrix = [[0; 4]; 4];
| ^^^^^^^^^^^ expected `[&u32]`, found `[&u32; 4]`
error: aborting due to 5 previous errors
Some errors have detailed explanations: E0277, E0308, E0658.
For more information about an error, try `rustc --explain E0277`.

View file

@ -0,0 +1,21 @@
// regression test for issue #151591, where constant evaluating an unsized AnonConst would ICE
#![feature(adt_const_params)]
#![feature(unsized_const_params)]
//~^ WARN the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
#[derive(Clone)]
struct S<const L: [u8]>;
const A: [u8];
//~^ ERROR free constant item without body
//~| ERROR the size for values of type `[u8]` cannot be known at compilation time
impl<const N: i32> Copy for S<A> {}
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time
//~| ERROR the const parameter `N` is not constrained by the impl trait, self type, or predicates
impl<const M: usize> Copy for S<A> {}
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time
//~| ERROR the const parameter `M` is not constrained by the impl trait, self type, or predicates
fn main() {}

View file

@ -0,0 +1,66 @@
error: free constant item without body
--> $DIR/unsized-anon-const-err-2.rs:10:1
|
LL | const A: [u8];
| ^^^^^^^^^^^^^-
| |
| help: provide a definition for the constant: `= <expr>;`
warning: the feature `unsized_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/unsized-anon-const-err-2.rs:4:12
|
LL | #![feature(unsized_const_params)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
= note: `#[warn(incomplete_features)]` on by default
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/unsized-anon-const-err-2.rs:10:10
|
LL | const A: [u8];
| ^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[u8]`
= note: statics and constants must have a statically known size
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/unsized-anon-const-err-2.rs:14:31
|
LL | impl<const N: i32> Copy for S<A> {}
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[u8]`
= note: statics and constants must have a statically known size
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/unsized-anon-const-err-2.rs:17:33
|
LL | impl<const M: usize> Copy for S<A> {}
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[u8]`
= note: statics and constants must have a statically known size
error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates
--> $DIR/unsized-anon-const-err-2.rs:14:6
|
LL | impl<const N: i32> Copy for S<A> {}
| ^^^^^^^^^^^^ unconstrained const parameter
|
= note: expressions using a const parameter must map each value to a distinct output value
= note: proving the result of expressions other than the parameter are unique is not supported
error[E0207]: the const parameter `M` is not constrained by the impl trait, self type, or predicates
--> $DIR/unsized-anon-const-err-2.rs:17:6
|
LL | impl<const M: usize> Copy for S<A> {}
| ^^^^^^^^^^^^^^ unconstrained const parameter
|
= note: expressions using a const parameter must map each value to a distinct output value
= note: proving the result of expressions other than the parameter are unique is not supported
error: aborting due to 6 previous errors; 1 warning emitted
Some errors have detailed explanations: E0207, E0277.
For more information about an error, try `rustc --explain E0207`.

View file

@ -0,0 +1,16 @@
// manually reduced reproduction of issue #137582, where constant evaluating an unsized AnonConst
// would ICE
#![feature(adt_const_params)]
fn func<const V: [u32]>() {}
//~^ ERROR use of unstable library feature `unsized_const_params`
const VALUE: [u32] = [0; 4];
//~^ ERROR mismatched types
//~| ERROR the size for values of type `[u32]` cannot be known at compilation time
fn main() {
func::<VALUE>();
//~^ ERROR the size for values of type `[u32]` cannot be known at compilation time
}

View file

@ -0,0 +1,38 @@
error[E0658]: use of unstable library feature `unsized_const_params`
--> $DIR/unsized-anon-const-func-err.rs:6:9
|
LL | fn func<const V: [u32]>() {}
| ^^^^^^^^^^^^^^
|
= help: add `#![feature(unsized_const_params)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: required for `[u32]` to implement `ConstParamTy_`
error[E0277]: the size for values of type `[u32]` cannot be known at compilation time
--> $DIR/unsized-anon-const-func-err.rs:9:14
|
LL | const VALUE: [u32] = [0; 4];
| ^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[u32]`
= note: statics and constants must have a statically known size
error[E0308]: mismatched types
--> $DIR/unsized-anon-const-func-err.rs:9:22
|
LL | const VALUE: [u32] = [0; 4];
| ^^^^^^ expected `[u32]`, found `[u32; 4]`
error[E0277]: the size for values of type `[u32]` cannot be known at compilation time
--> $DIR/unsized-anon-const-func-err.rs:14:12
|
LL | func::<VALUE>();
| ^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[u32]`
= note: statics and constants must have a statically known size
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0277, E0308, E0658.
For more information about an error, try `rustc --explain E0277`.

View file

@ -0,0 +1,16 @@
// manually reduced reproduction of issue #137582, where constant evaluating an unsized AnonConst
// would ICE
#![feature(adt_const_params)]
const VALUE: [u32] = [0; 4];
//~^ ERROR the size for values of type `[u32]` cannot be known at compilation time
//~| ERROR mismatched types
struct SomeStruct<const V: [u32]> {}
//~^ ERROR use of unstable library feature `unsized_const_params`
impl SomeStruct<VALUE> {}
//~^ ERROR the size for values of type `[u32]` cannot be known at compilation time
fn main() {}

View file

@ -0,0 +1,38 @@
error[E0277]: the size for values of type `[u32]` cannot be known at compilation time
--> $DIR/unsized-anon-const-struct-err.rs:6:14
|
LL | const VALUE: [u32] = [0; 4];
| ^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[u32]`
= note: statics and constants must have a statically known size
error[E0658]: use of unstable library feature `unsized_const_params`
--> $DIR/unsized-anon-const-struct-err.rs:10:19
|
LL | struct SomeStruct<const V: [u32]> {}
| ^^^^^^^^^^^^^^
|
= help: add `#![feature(unsized_const_params)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: required for `[u32]` to implement `ConstParamTy_`
error[E0277]: the size for values of type `[u32]` cannot be known at compilation time
--> $DIR/unsized-anon-const-struct-err.rs:13:17
|
LL | impl SomeStruct<VALUE> {}
| ^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[u32]`
= note: statics and constants must have a statically known size
error[E0308]: mismatched types
--> $DIR/unsized-anon-const-struct-err.rs:6:22
|
LL | const VALUE: [u32] = [0; 4];
| ^^^^^^ expected `[u32]`, found `[u32; 4]`
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0277, E0308, E0658.
For more information about an error, try `rustc --explain E0277`.

View file

@ -0,0 +1,13 @@
//@ check-pass
#![feature(min_generic_const_args)]
#![expect(incomplete_features)]
#[type_const]
const N: usize = 2;
trait CollectArray<A> {
fn inner_array(&mut self) -> [A; N];
}
fn main() {}

View file

@ -0,0 +1,14 @@
error: explicit impls for the `Unpin` trait are not permitted for structurally pinned types
--> $DIR/impl-unpin.rs:14:5
|
LL | impl Unpin for Foo {}
| ^^^^^^^^^^^^^^^^^^ impl of `Unpin` not allowed
|
help: `Foo` is structurally pinned because it is marked as `#[pin_v2]`
--> $DIR/impl-unpin.rs:7:1
|
LL | struct Foo;
| ^^^^^^^^^^
error: aborting due to 1 previous error

View file

@ -0,0 +1,15 @@
error[E0321]: cross-crate traits with a default impl, like `Unpin`, can only be implemented for a struct/enum type, not `<Foo as Identity>::Assoc`
--> $DIR/impl-unpin.rs:68:5
|
LL | impl Unpin for <Foo as Identity>::Assoc {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type
error[E0321]: cross-crate traits with a default impl, like `Unpin`, can only be implemented for a struct/enum type, not `<Bar as Identity>::Assoc`
--> $DIR/impl-unpin.rs:70:5
|
LL | impl Unpin for <Bar as Identity>::Assoc {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0321`.

View file

@ -0,0 +1,74 @@
//@ revisions: adt tait ty_alias assoc
#![feature(pin_ergonomics)]
#![cfg_attr(tait, feature(type_alias_impl_trait))]
#![allow(incomplete_features)]
#[pin_v2]
struct Foo;
struct Bar;
#[cfg(adt)]
mod adt {
use super::*;
impl Unpin for Foo {}
//[adt]~^ ERROR explicit impls for the `Unpin` trait are not permitted for structurally pinned types
impl Unpin for Bar {} // ok
}
#[cfg(ty_alias)]
mod ty_alias {
use super::*;
type Identity<T> = T;
impl Unpin for Identity<Foo> {}
//[ty_alias]~^ ERROR explicit impls for the `Unpin` trait are not permitted for structurally pinned types
impl Unpin for Identity<Bar> {} // ok
}
#[cfg(tait)]
mod tait {
use super::*;
trait Identity<T> {}
impl<T> Identity<T> for T {}
type FooAlias = impl Identity<Foo>;
type BarAlias = impl Identity<Bar>;
#[define_opaque(FooAlias)]
fn foo_alias() -> FooAlias {
Foo
}
#[define_opaque(BarAlias)]
fn bar_alias() -> BarAlias {
Bar
}
impl Unpin for FooAlias {}
//[tait]~^ ERROR only traits defined in the current crate can be implemented for arbitrary types
impl Unpin for BarAlias {}
//[tait]~^ ERROR only traits defined in the current crate can be implemented for arbitrary types
}
#[cfg(assoc)]
mod assoc {
use super::*;
trait Identity {
type Assoc;
}
impl<T> Identity for T {
type Assoc = T;
}
impl Unpin for <Foo as Identity>::Assoc {}
//[assoc]~^ ERROR cross-crate traits with a default impl, like `Unpin`, can only be implemented for a struct/enum type, not `<Foo as Identity>::Assoc`
impl Unpin for <Bar as Identity>::Assoc {}
//[assoc]~^ ERROR cross-crate traits with a default impl, like `Unpin`, can only be implemented for a struct/enum type, not `<Bar as Identity>::Assoc`
}
fn main() {}

View file

@ -0,0 +1,27 @@
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/impl-unpin.rs:50:5
|
LL | impl Unpin for FooAlias {}
| ^^^^^^^^^^^^^^^--------
| |
| type alias impl trait is treated as if it were foreign, because its hidden type could be from a foreign crate
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/impl-unpin.rs:52:5
|
LL | impl Unpin for BarAlias {}
| ^^^^^^^^^^^^^^^--------
| |
| type alias impl trait is treated as if it were foreign, because its hidden type could be from a foreign crate
|
= note: impl doesn't have any local type before any uncovered type parameters
= note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
= note: define and implement a trait or new type instead
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0117`.

View file

@ -0,0 +1,14 @@
error: explicit impls for the `Unpin` trait are not permitted for structurally pinned types
--> $DIR/impl-unpin.rs:25:5
|
LL | impl Unpin for Identity<Foo> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of `Unpin` not allowed
|
help: `Foo` is structurally pinned because it is marked as `#[pin_v2]`
--> $DIR/impl-unpin.rs:7:1
|
LL | struct Foo;
| ^^^^^^^^^^
error: aborting due to 1 previous error