Merge from rustc

This commit is contained in:
The Miri Conjob Bot 2024-01-31 05:01:22 +00:00
commit 38b8bd3737
914 changed files with 11126 additions and 6975 deletions

View file

@ -28,6 +28,7 @@ name: CI
- "**"
permissions:
contents: read
packages: write
defaults:
run:
shell: bash
@ -42,6 +43,7 @@ jobs:
CI_JOB_NAME: "${{ matrix.name }}"
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
DOCKER_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
SCCACHE_BUCKET: rust-lang-ci-sccache2
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"
CACHE_DOMAIN: ci-caches.rust-lang.org
@ -172,6 +174,7 @@ jobs:
CI_JOB_NAME: "${{ matrix.name }}"
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
DOCKER_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
SCCACHE_BUCKET: rust-lang-ci-sccache2
DEPLOY_BUCKET: rust-lang-ci2
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"
@ -554,6 +557,7 @@ jobs:
CI_JOB_NAME: "${{ matrix.name }}"
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
DOCKER_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
SCCACHE_BUCKET: rust-lang-ci-sccache2
DEPLOY_BUCKET: rust-lang-ci2
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"

View file

@ -382,9 +382,9 @@ dependencies = [
[[package]]
name = "byteorder"
version = "1.4.3"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "bytes"
@ -596,11 +596,11 @@ dependencies = [
name = "clippy_dev"
version = "0.0.1"
dependencies = [
"aho-corasick 0.7.20",
"aho-corasick 1.0.2",
"clap",
"indoc",
"itertools",
"opener 0.5.2",
"opener",
"shell-escape",
"walkdir",
]
@ -610,7 +610,7 @@ name = "clippy_lints"
version = "0.1.77"
dependencies = [
"arrayvec",
"cargo_metadata 0.15.4",
"cargo_metadata 0.18.0",
"clippy_config",
"clippy_utils",
"declare_clippy_lint",
@ -1268,7 +1268,6 @@ name = "error_index_generator"
version = "0.0.0"
dependencies = [
"mdbook",
"rustc_error_codes",
]
[[package]]
@ -2351,7 +2350,7 @@ dependencies = [
"log",
"memchr",
"once_cell",
"opener 0.6.1",
"opener",
"pathdiff",
"pulldown-cmark",
"regex",
@ -2596,9 +2595,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
[[package]]
name = "object"
version = "0.32.1"
version = "0.32.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0"
checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
dependencies = [
"compiler_builtins",
"crc32fast",
@ -2626,16 +2625,6 @@ version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]]
name = "opener"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "293c15678e37254c15bd2f092314abb4e51d7fdde05c2021279c12631b54f005"
dependencies = [
"bstr",
"winapi",
]
[[package]]
name = "opener"
version = "0.6.1"
@ -3014,11 +3003,11 @@ dependencies = [
[[package]]
name = "pulldown-cmark"
version = "0.9.3"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a1a2f1f0a7ecff9c31abbe177637be0e97a0aef46cf8738ece09327985d998"
checksum = "57206b407293d2bcd3af849ce869d52068623f19e1b5ff8e8778e3309439682b"
dependencies = [
"bitflags 1.3.2",
"bitflags 2.4.1",
"memchr",
"unicase",
]
@ -3711,7 +3700,6 @@ dependencies = [
"rustc_codegen_ssa",
"rustc_const_eval",
"rustc_data_structures",
"rustc_error_codes",
"rustc_errors",
"rustc_expand",
"rustc_feature",
@ -3784,9 +3772,11 @@ dependencies = [
"rustc_ast",
"rustc_ast_pretty",
"rustc_data_structures",
"rustc_error_codes",
"rustc_error_messages",
"rustc_fluent_macro",
"rustc_hir",
"rustc_index",
"rustc_lint_defs",
"rustc_macros",
"rustc_serialize",
@ -4352,7 +4342,6 @@ dependencies = [
name = "rustc_pattern_analysis"
version = "0.0.0"
dependencies = [
"derivative",
"rustc-hash",
"rustc_apfloat",
"rustc_arena",
@ -4797,12 +4786,12 @@ checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06"
[[package]]
name = "ruzstd"
version = "0.4.0"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3ffab8f9715a0d455df4bbb9d21e91135aab3cd3ca187af0cd0c3c3f868fdc"
checksum = "58c4eb8a81997cf040a091d1f7e1938aeab6749d3a0dfa73af43cdc32393483d"
dependencies = [
"byteorder",
"thiserror-core",
"derive_more",
"twox-hash",
]
@ -5365,26 +5354,6 @@ dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-core"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d97345f6437bb2004cd58819d8a9ef8e36cdd7661c2abc4bbde0a7c40d9f497"
dependencies = [
"thiserror-core-impl",
]
[[package]]
name = "thiserror-core-impl"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10ac1c5050e43014d16b2f94d0d2ce79e65ffdd8b38d8048f9c8f6a8a6da62ac"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "thiserror-impl"
version = "1.0.47"
@ -5757,9 +5726,9 @@ dependencies = [
[[package]]
name = "unic-langid"
version = "0.9.1"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "398f9ad7239db44fd0f80fe068d12ff22d78354080332a5077dc6f52f14dcf2f"
checksum = "238722e6d794ed130f91f4ea33e01fcff4f188d92337a21297892521c72df516"
dependencies = [
"unic-langid-impl",
"unic-langid-macros",
@ -5767,18 +5736,18 @@ dependencies = [
[[package]]
name = "unic-langid-impl"
version = "0.9.1"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e35bfd2f2b8796545b55d7d3fd3e89a0613f68a0d1c8bc28cb7ff96b411a35ff"
checksum = "4bd55a2063fdea4ef1f8633243a7b0524cbeef1905ae04c31a1c9b9775c55bc6"
dependencies = [
"tinystr",
]
[[package]]
name = "unic-langid-macros"
version = "0.9.1"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "055e618bf694161ffff0466d95cef3e1a5edc59f6ba1888e97801f2b4ebdc4fe"
checksum = "5c854cefb82ff2816410ce606acbad1b3af065140907b29be9229040752b83ec"
dependencies = [
"proc-macro-hack",
"tinystr",
@ -5788,13 +5757,13 @@ dependencies = [
[[package]]
name = "unic-langid-macros-impl"
version = "0.9.1"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f5cdec05b907f4e2f6843f4354f4ce6a5bebe1a56df320a49134944477ce4d8"
checksum = "fea2a4c80deb4fb3ca51f66b5e2dd91e3642bbce52234bcf22e41668281208e4"
dependencies = [
"proc-macro-hack",
"quote",
"syn 1.0.109",
"syn 2.0.32",
"unic-langid-impl",
]

View file

@ -13,13 +13,11 @@
#![feature(rustdoc_internals)]
#![feature(associated_type_bounds)]
#![feature(box_patterns)]
#![feature(const_trait_impl)]
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(min_specialization)]
#![feature(negative_impls)]
#![feature(stmt_expr_attributes)]
#![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]

View file

@ -3,8 +3,7 @@
use crate::ast::{self, LitKind, MetaItemLit, StrStyle};
use crate::token::{self, Token};
use rustc_lexer::unescape::{
byte_from_char, unescape_byte, unescape_c_string, unescape_char, unescape_literal, CStrUnit,
Mode,
byte_from_char, unescape_byte, unescape_char, unescape_mixed, unescape_unicode, MixedUnit, Mode,
};
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::Span;
@ -48,6 +47,9 @@ impl LitKind {
return Err(LitError::InvalidSuffix);
}
// For byte/char/string literals, chars and escapes have already been
// checked in the lexer (in `cook_lexer_literal`). So we can assume all
// chars and escapes are valid here.
Ok(match kind {
token::Bool => {
assert!(symbol.is_bool_lit());
@ -56,12 +58,12 @@ impl LitKind {
token::Byte => {
return unescape_byte(symbol.as_str())
.map(LitKind::Byte)
.map_err(|_| LitError::LexerError);
.map_err(|_| panic!("failed to unescape byte literal"));
}
token::Char => {
return unescape_char(symbol.as_str())
.map(LitKind::Char)
.map_err(|_| LitError::LexerError);
.map_err(|_| panic!("failed to unescape char literal"));
}
// There are some valid suffixes for integer and float literals,
@ -77,26 +79,22 @@ impl LitKind {
let s = symbol.as_str();
// Vanilla strings are so common we optimize for the common case where no chars
// requiring special behaviour are present.
let symbol = if s.contains(['\\', '\r']) {
let symbol = if s.contains('\\') {
let mut buf = String::with_capacity(s.len());
let mut error = Ok(());
// Force-inlining here is aggressive but the closure is
// called on every char in the string, so it can be
// hot in programs with many long strings.
unescape_literal(
// called on every char in the string, so it can be hot in
// programs with many long strings containing escapes.
unescape_unicode(
s,
Mode::Str,
&mut #[inline(always)]
|_, unescaped_char| match unescaped_char {
|_, c| match c {
Ok(c) => buf.push(c),
Err(err) => {
if err.is_fatal() {
error = Err(LitError::LexerError);
}
assert!(!err.is_fatal(), "failed to unescape string literal")
}
},
);
error?;
Symbol::intern(&buf)
} else {
symbol
@ -104,86 +102,46 @@ impl LitKind {
LitKind::Str(symbol, ast::StrStyle::Cooked)
}
token::StrRaw(n) => {
// Raw strings have no escapes, so we only need to check for invalid chars, and we
// can reuse the symbol on success.
let mut error = Ok(());
unescape_literal(symbol.as_str(), Mode::RawStr, &mut |_, unescaped_char| {
match unescaped_char {
Ok(_) => {}
Err(err) => {
if err.is_fatal() {
error = Err(LitError::LexerError);
}
}
}
});
error?;
// Raw strings have no escapes so no work is needed here.
LitKind::Str(symbol, ast::StrStyle::Raw(n))
}
token::ByteStr => {
let s = symbol.as_str();
let mut buf = Vec::with_capacity(s.len());
let mut error = Ok(());
unescape_literal(s, Mode::ByteStr, &mut |_, c| match c {
unescape_unicode(s, Mode::ByteStr, &mut |_, c| match c {
Ok(c) => buf.push(byte_from_char(c)),
Err(err) => {
if err.is_fatal() {
error = Err(LitError::LexerError);
}
assert!(!err.is_fatal(), "failed to unescape string literal")
}
});
error?;
LitKind::ByteStr(buf.into(), StrStyle::Cooked)
}
token::ByteStrRaw(n) => {
// Raw strings have no escapes, so we only need to check for invalid chars, and we
// can convert the symbol directly to a `Lrc<u8>` on success.
let s = symbol.as_str();
let mut error = Ok(());
unescape_literal(s, Mode::RawByteStr, &mut |_, c| match c {
Ok(_) => {}
Err(err) => {
if err.is_fatal() {
error = Err(LitError::LexerError);
}
}
});
LitKind::ByteStr(s.to_owned().into_bytes().into(), StrStyle::Raw(n))
// Raw strings have no escapes so we can convert the symbol
// directly to a `Lrc<u8>`.
let buf = symbol.as_str().to_owned().into_bytes();
LitKind::ByteStr(buf.into(), StrStyle::Raw(n))
}
token::CStr => {
let s = symbol.as_str();
let mut buf = Vec::with_capacity(s.len());
let mut error = Ok(());
unescape_c_string(s, Mode::CStr, &mut |_span, c| match c {
Ok(CStrUnit::Byte(b)) => buf.push(b),
Ok(CStrUnit::Char(c)) => {
unescape_mixed(s, Mode::CStr, &mut |_span, c| match c {
Ok(MixedUnit::Char(c)) => {
buf.extend_from_slice(c.encode_utf8(&mut [0; 4]).as_bytes())
}
Ok(MixedUnit::HighByte(b)) => buf.push(b),
Err(err) => {
if err.is_fatal() {
error = Err(LitError::LexerError);
}
assert!(!err.is_fatal(), "failed to unescape C string literal")
}
});
error?;
buf.push(0);
LitKind::CStr(buf.into(), StrStyle::Cooked)
}
token::CStrRaw(n) => {
// Raw strings have no escapes, so we only need to check for invalid chars, and we
// can convert the symbol directly to a `Lrc<u8>` on success.
let s = symbol.as_str();
let mut error = Ok(());
unescape_c_string(s, Mode::RawCStr, &mut |_, c| match c {
Ok(_) => {}
Err(err) => {
if err.is_fatal() {
error = Err(LitError::LexerError);
}
}
});
error?;
let mut buf = s.to_owned().into_bytes();
// Raw strings have no escapes so we can convert the symbol
// directly to a `Lrc<u8>` after appending the terminating NUL
// char.
let mut buf = symbol.as_str().to_owned().into_bytes();
buf.push(0);
LitKind::CStr(buf.into(), StrStyle::Raw(n))
}

View file

@ -1,9 +1,9 @@
use rustc_errors::DiagnosticArgFromDisplay;
use rustc_errors::{codes::*, DiagnosticArgFromDisplay};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{symbol::Ident, Span, Symbol};
#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_generic_type_with_parentheses, code = "E0214")]
#[diag(ast_lowering_generic_type_with_parentheses, code = E0214)]
pub struct GenericTypeWithParentheses {
#[primary_span]
#[label]
@ -22,7 +22,7 @@ pub struct UseAngleBrackets {
}
#[derive(Diagnostic)]
#[diag(ast_lowering_invalid_abi, code = "E0703")]
#[diag(ast_lowering_invalid_abi, code = E0703)]
#[note]
pub struct InvalidAbi {
#[primary_span]
@ -89,7 +89,7 @@ pub enum AssocTyParenthesesSub {
}
#[derive(Diagnostic)]
#[diag(ast_lowering_misplaced_impl_trait, code = "E0562")]
#[diag(ast_lowering_misplaced_impl_trait, code = E0562)]
#[note]
pub struct MisplacedImplTrait<'a> {
#[primary_span]
@ -114,7 +114,7 @@ pub struct UnderscoreExprLhsAssign {
}
#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_base_expression_double_dot, code = "E0797")]
#[diag(ast_lowering_base_expression_double_dot, code = E0797)]
pub struct BaseExpressionDoubleDot {
#[primary_span]
#[suggestion(code = "/* expr */", applicability = "has-placeholders", style = "verbose")]
@ -122,7 +122,7 @@ pub struct BaseExpressionDoubleDot {
}
#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_await_only_in_async_fn_and_blocks, code = "E0728")]
#[diag(ast_lowering_await_only_in_async_fn_and_blocks, code = E0728)]
pub struct AwaitOnlyInAsyncFnAndBlocks {
#[primary_span]
#[label]
@ -132,14 +132,14 @@ pub struct AwaitOnlyInAsyncFnAndBlocks {
}
#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_coroutine_too_many_parameters, code = "E0628")]
#[diag(ast_lowering_coroutine_too_many_parameters, code = E0628)]
pub struct CoroutineTooManyParameters {
#[primary_span]
pub fn_decl_span: Span,
}
#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_closure_cannot_be_static, code = "E0697")]
#[diag(ast_lowering_closure_cannot_be_static, code = E0697)]
pub struct ClosureCannotBeStatic {
#[primary_span]
pub fn_decl_span: Span,
@ -154,14 +154,14 @@ pub struct FunctionalRecordUpdateDestructuringAssignment {
}
#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_async_coroutines_not_supported, code = "E0727")]
#[diag(ast_lowering_async_coroutines_not_supported, code = E0727)]
pub struct AsyncCoroutinesNotSupported {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_inline_asm_unsupported_target, code = "E0472")]
#[diag(ast_lowering_inline_asm_unsupported_target, code = E0472)]
pub struct InlineAsmUnsupportedTarget {
#[primary_span]
pub span: Span,

View file

@ -153,7 +153,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
ExprKind::Let(pat, scrutinee, span, is_recovered) => {
hir::ExprKind::Let(self.arena.alloc(hir::Let {
hir_id: self.next_id(),
span: self.lower_span(*span),
pat: self.lower_pat(pat),
ty: None,

View file

@ -33,10 +33,8 @@
#![allow(internal_features)]
#![feature(rustdoc_internals)]
#![doc(rust_logo)]
#![feature(if_let_guard)]
#![feature(box_patterns)]
#![feature(let_chains)]
#![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
@ -2307,7 +2305,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
match c.value.kind {
ExprKind::Underscore => {
if self.tcx.features().generic_arg_infer {
hir::ArrayLen::Infer(self.lower_node_id(c.id), self.lower_span(c.value.span))
hir::ArrayLen::Infer(hir::InferArg {
hir_id: self.lower_node_id(c.id),
span: self.lower_span(c.value.span),
})
} else {
feature_err(
&self.tcx.sess,

View file

@ -1,7 +1,7 @@
//! Errors emitted by ast_passes.
use rustc_ast::ParamKindOrd;
use rustc_errors::{AddToDiagnostic, Applicability};
use rustc_errors::{codes::*, AddToDiagnostic, Applicability};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{symbol::Ident, Span, Symbol};
@ -23,7 +23,7 @@ pub struct InvalidLabel {
}
#[derive(Diagnostic)]
#[diag(ast_passes_visibility_not_permitted, code = "E0449")]
#[diag(ast_passes_visibility_not_permitted, code = E0449)]
pub struct VisibilityNotPermitted {
#[primary_span]
pub span: Span,
@ -44,7 +44,7 @@ pub enum VisibilityNotPermittedNote {
}
#[derive(Diagnostic)]
#[diag(ast_passes_trait_fn_const, code = "E0379")]
#[diag(ast_passes_trait_fn_const, code = E0379)]
pub struct TraitFnConst {
#[primary_span]
#[label]
@ -302,14 +302,14 @@ pub struct ItemUnderscore<'a> {
}
#[derive(Diagnostic)]
#[diag(ast_passes_nomangle_ascii, code = "E0754")]
#[diag(ast_passes_nomangle_ascii, code = E0754)]
pub struct NoMangleAscii {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_module_nonascii, code = "E0754")]
#[diag(ast_passes_module_nonascii, code = E0754)]
#[help]
pub struct ModuleNonAscii {
#[primary_span]
@ -318,7 +318,7 @@ pub struct ModuleNonAscii {
}
#[derive(Diagnostic)]
#[diag(ast_passes_auto_generic, code = "E0567")]
#[diag(ast_passes_auto_generic, code = E0567)]
pub struct AutoTraitGeneric {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable")]
@ -328,7 +328,7 @@ pub struct AutoTraitGeneric {
}
#[derive(Diagnostic)]
#[diag(ast_passes_auto_super_lifetime, code = "E0568")]
#[diag(ast_passes_auto_super_lifetime, code = E0568)]
pub struct AutoTraitBounds {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable")]
@ -338,7 +338,7 @@ pub struct AutoTraitBounds {
}
#[derive(Diagnostic)]
#[diag(ast_passes_auto_items, code = "E0380")]
#[diag(ast_passes_auto_items, code = E0380)]
pub struct AutoTraitItems {
#[primary_span]
pub spans: Vec<Span>,
@ -384,28 +384,28 @@ impl AddToDiagnostic for EmptyLabelManySpans {
}
#[derive(Diagnostic)]
#[diag(ast_passes_pattern_in_fn_pointer, code = "E0561")]
#[diag(ast_passes_pattern_in_fn_pointer, code = E0561)]
pub struct PatternFnPointer {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_trait_object_single_bound, code = "E0226")]
#[diag(ast_passes_trait_object_single_bound, code = E0226)]
pub struct TraitObjectBound {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_impl_trait_path, code = "E0667")]
#[diag(ast_passes_impl_trait_path, code = E0667)]
pub struct ImplTraitPath {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_nested_impl_trait, code = "E0666")]
#[diag(ast_passes_nested_impl_trait, code = E0666)]
pub struct NestedImplTrait {
#[primary_span]
pub span: Span,
@ -443,7 +443,7 @@ pub struct ObsoleteAuto {
}
#[derive(Diagnostic)]
#[diag(ast_passes_unsafe_negative_impl, code = "E0198")]
#[diag(ast_passes_unsafe_negative_impl, code = E0198)]
pub struct UnsafeNegativeImpl {
#[primary_span]
pub span: Span,
@ -468,7 +468,7 @@ pub struct InherentImplCannot<'a> {
}
#[derive(Diagnostic)]
#[diag(ast_passes_inherent_cannot_be, code = "E0197")]
#[diag(ast_passes_inherent_cannot_be, code = E0197)]
pub struct InherentImplCannotUnsafe<'a> {
#[primary_span]
pub span: Span,
@ -536,7 +536,7 @@ pub struct GenericDefaultTrailing {
}
#[derive(Diagnostic)]
#[diag(ast_passes_nested_lifetimes, code = "E0316")]
#[diag(ast_passes_nested_lifetimes, code = E0316)]
pub struct NestedLifetimes {
#[primary_span]
pub span: Span,
@ -655,7 +655,7 @@ pub struct ConstAndCVariadic {
}
#[derive(Diagnostic)]
#[diag(ast_passes_pattern_in_foreign, code = "E0130")]
#[diag(ast_passes_pattern_in_foreign, code = E0130)]
pub struct PatternInForeign {
#[primary_span]
#[label]
@ -663,7 +663,7 @@ pub struct PatternInForeign {
}
#[derive(Diagnostic)]
#[diag(ast_passes_pattern_in_bodiless, code = "E0642")]
#[diag(ast_passes_pattern_in_bodiless, code = E0642)]
pub struct PatternInBodiless {
#[primary_span]
#[label]
@ -711,14 +711,14 @@ pub struct AssociatedSuggestion2 {
}
#[derive(Diagnostic)]
#[diag(ast_passes_stability_outside_std, code = "E0734")]
#[diag(ast_passes_stability_outside_std, code = E0734)]
pub struct StabilityOutsideStd {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ast_passes_feature_on_non_nightly, code = "E0554")]
#[diag(ast_passes_feature_on_non_nightly, code = E0554)]
pub struct FeatureOnNonNightly {
#[primary_span]
pub span: Span,

View file

@ -11,7 +11,6 @@
#![feature(if_let_guard)]
#![feature(iter_is_partitioned)]
#![feature(let_chains)]
#![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]

View file

@ -4,8 +4,6 @@
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
#![feature(box_patterns)]
#![feature(let_chains)]
#![recursion_limit = "256"]
mod helpers;
pub mod pp;

View file

@ -160,6 +160,10 @@ fn space_between(tt1: &TokenTree, tt2: &TokenTree) -> bool {
use TokenTree::Delimited as Del;
use TokenTree::Token as Tok;
fn is_punct(tt: &TokenTree) -> bool {
matches!(tt, TokenTree::Token(tok, _) if tok.is_punct())
}
// Each match arm has one or more examples in comments. The default is to
// insert space between adjacent tokens, except for the cases listed in
// this match.
@ -167,24 +171,35 @@ fn space_between(tt1: &TokenTree, tt2: &TokenTree) -> bool {
// No space after line doc comments.
(Tok(Token { kind: DocComment(CommentKind::Line, ..), .. }, _), _) => false,
// `.` + ANYTHING: `x.y`, `tup.0`
// `$` + ANYTHING: `$e`
(Tok(Token { kind: Dot | Dollar, .. }, _), _) => false,
// `.` + NON-PUNCT: `x.y`, `tup.0`
(Tok(Token { kind: Dot, .. }, _), tt2) if !is_punct(tt2) => false,
// ANYTHING + `,`: `foo,`
// ANYTHING + `.`: `x.y`, `tup.0`
// ANYTHING + `!`: `foo! { ... }`
//
// FIXME: Incorrect cases:
// - Logical not: `x =! y`, `if! x { f(); }`
// - Never type: `Fn() ->!`
(_, Tok(Token { kind: Comma | Dot | Not, .. }, _)) => false,
// `$` + IDENT: `$e`
(Tok(Token { kind: Dollar, .. }, _), Tok(Token { kind: Ident(..), .. }, _)) => false,
// IDENT + `(`: `f(3)`
//
// FIXME: Incorrect cases:
// - Let: `let(a, b) = (1, 2)`
(Tok(Token { kind: Ident(..), .. }, _), Del(_, _, Parenthesis, _)) => false,
// NON-PUNCT + `,`: `foo,`
// NON-PUNCT + `;`: `x = 3;`, `[T; 3]`
// NON-PUNCT + `.`: `x.y`, `tup.0`
(tt1, Tok(Token { kind: Comma | Semi | Dot, .. }, _)) if !is_punct(tt1) => false,
// IDENT + `!`: `println!()`, but `if !x { ... }` needs a space after the `if`
(Tok(Token { kind: Ident(sym, is_raw), span }, _), Tok(Token { kind: Not, .. }, _))
if !Ident::new(*sym, *span).is_reserved() || *is_raw =>
{
false
}
// IDENT|`fn`|`Self`|`pub` + `(`: `f(3)`, `fn(x: u8)`, `Self()`, `pub(crate)`,
// but `let (a, b) = (1, 2)` needs a space after the `let`
(Tok(Token { kind: Ident(sym, is_raw), span }, _), Del(_, _, Parenthesis, _))
if !Ident::new(*sym, *span).is_reserved()
|| *sym == kw::Fn
|| *sym == kw::SelfUpper
|| *sym == kw::Pub
|| *is_raw =>
{
false
}
// `#` + `[`: `#[attr]`
(Tok(Token { kind: Pound, .. }, _), Del(_, _, Bracket, _)) => false,

View file

@ -2,8 +2,7 @@ use std::num::IntErrorKind;
use rustc_ast as ast;
use rustc_errors::{
error_code, Applicability, DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic,
Level,
codes::*, Applicability, DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, Level,
};
use rustc_macros::Diagnostic;
use rustc_span::{Span, Symbol};
@ -12,14 +11,14 @@ use crate::fluent_generated as fluent;
use crate::UnsupportedLiteralReason;
#[derive(Diagnostic)]
#[diag(attr_expected_one_cfg_pattern, code = "E0536")]
#[diag(attr_expected_one_cfg_pattern, code = E0536)]
pub(crate) struct ExpectedOneCfgPattern {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_invalid_predicate, code = "E0537")]
#[diag(attr_invalid_predicate, code = E0537)]
pub(crate) struct InvalidPredicate {
#[primary_span]
pub span: Span,
@ -28,7 +27,7 @@ pub(crate) struct InvalidPredicate {
}
#[derive(Diagnostic)]
#[diag(attr_multiple_item, code = "E0538")]
#[diag(attr_multiple_item, code = E0538)]
pub(crate) struct MultipleItem {
#[primary_span]
pub span: Span,
@ -37,7 +36,7 @@ pub(crate) struct MultipleItem {
}
#[derive(Diagnostic)]
#[diag(attr_incorrect_meta_item, code = "E0539")]
#[diag(attr_incorrect_meta_item, code = E0539)]
pub(crate) struct IncorrectMetaItem {
#[primary_span]
pub span: Span,
@ -56,7 +55,7 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UnknownMetaItem<'_> {
let expected = self.expected.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>();
DiagnosticBuilder::new(dcx, level, fluent::attr_unknown_meta_item)
.with_span(self.span)
.with_code(error_code!(E0541))
.with_code(E0541)
.with_arg("item", self.item)
.with_arg("expected", expected.join(", "))
.with_span_label(self.span, fluent::attr_label)
@ -64,28 +63,28 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UnknownMetaItem<'_> {
}
#[derive(Diagnostic)]
#[diag(attr_missing_since, code = "E0542")]
#[diag(attr_missing_since, code = E0542)]
pub(crate) struct MissingSince {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_missing_note, code = "E0543")]
#[diag(attr_missing_note, code = E0543)]
pub(crate) struct MissingNote {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_multiple_stability_levels, code = "E0544")]
#[diag(attr_multiple_stability_levels, code = E0544)]
pub(crate) struct MultipleStabilityLevels {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_invalid_issue_string, code = "E0545")]
#[diag(attr_invalid_issue_string, code = E0545)]
pub(crate) struct InvalidIssueString {
#[primary_span]
pub span: Span,
@ -143,21 +142,21 @@ impl InvalidIssueStringCause {
}
#[derive(Diagnostic)]
#[diag(attr_missing_feature, code = "E0546")]
#[diag(attr_missing_feature, code = E0546)]
pub(crate) struct MissingFeature {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_non_ident_feature, code = "E0546")]
#[diag(attr_non_ident_feature, code = E0546)]
pub(crate) struct NonIdentFeature {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_missing_issue, code = "E0547")]
#[diag(attr_missing_issue, code = E0547)]
pub(crate) struct MissingIssue {
#[primary_span]
pub span: Span,
@ -166,14 +165,14 @@ 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_incorrect_repr_format_packed_one_or_zero_arg, code = "E0552")]
#[diag(attr_incorrect_repr_format_packed_one_or_zero_arg, code = E0552)]
pub(crate) struct IncorrectReprFormatPackedOneOrZeroArg {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_invalid_repr_hint_no_paren, code = "E0552")]
#[diag(attr_invalid_repr_hint_no_paren, code = E0552)]
pub(crate) struct InvalidReprHintNoParen {
#[primary_span]
pub span: Span,
@ -182,7 +181,7 @@ pub(crate) struct InvalidReprHintNoParen {
}
#[derive(Diagnostic)]
#[diag(attr_invalid_repr_hint_no_value, code = "E0552")]
#[diag(attr_invalid_repr_hint_no_value, code = E0552)]
pub(crate) struct InvalidReprHintNoValue {
#[primary_span]
pub span: Span,
@ -215,7 +214,7 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UnsupportedLiteral {
},
);
diag.span(self.span);
diag.code(error_code!(E0565));
diag.code(E0565);
if self.is_bytestr {
diag.span_suggestion(
self.start_point_span,
@ -229,7 +228,7 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UnsupportedLiteral {
}
#[derive(Diagnostic)]
#[diag(attr_invalid_repr_align_need_arg, code = "E0589")]
#[diag(attr_invalid_repr_align_need_arg, code = E0589)]
pub(crate) struct InvalidReprAlignNeedArg {
#[primary_span]
#[suggestion(code = "align(...)", applicability = "has-placeholders")]
@ -237,7 +236,7 @@ pub(crate) struct InvalidReprAlignNeedArg {
}
#[derive(Diagnostic)]
#[diag(attr_invalid_repr_generic, code = "E0589")]
#[diag(attr_invalid_repr_generic, code = E0589)]
pub(crate) struct InvalidReprGeneric<'a> {
#[primary_span]
pub span: Span,
@ -247,14 +246,14 @@ pub(crate) struct InvalidReprGeneric<'a> {
}
#[derive(Diagnostic)]
#[diag(attr_incorrect_repr_format_align_one_arg, code = "E0693")]
#[diag(attr_incorrect_repr_format_align_one_arg, code = E0693)]
pub(crate) struct IncorrectReprFormatAlignOneArg {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_incorrect_repr_format_generic, code = "E0693")]
#[diag(attr_incorrect_repr_format_generic, code = E0693)]
pub(crate) struct IncorrectReprFormatGeneric<'a> {
#[primary_span]
pub span: Span,
@ -305,14 +304,14 @@ impl<'a> IncorrectReprFormatGenericCause<'a> {
}
#[derive(Diagnostic)]
#[diag(attr_rustc_promotable_pairing, code = "E0717")]
#[diag(attr_rustc_promotable_pairing, code = E0717)]
pub(crate) struct RustcPromotablePairing {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(attr_rustc_allowed_unstable_pairing, code = "E0789")]
#[diag(attr_rustc_allowed_unstable_pairing, code = E0789)]
pub(crate) struct RustcAllowedUnstablePairing {
#[primary_span]
pub span: Span,

View file

@ -1,4 +1,4 @@
use rustc_errors::{struct_span_code_err, DiagCtxt, DiagnosticBuilder};
use rustc_errors::{codes::*, struct_span_code_err, DiagCtxt, DiagnosticBuilder};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::Span;

View file

@ -3,7 +3,9 @@
use either::Either;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::{struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder, MultiSpan};
use rustc_errors::{
codes::*, struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder, MultiSpan,
};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};

View file

@ -188,7 +188,7 @@ impl Display for RegionName {
}
impl rustc_errors::IntoDiagnosticArg for RegionName {
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue {
self.to_string().into_diagnostic_arg()
}
}

View file

@ -8,12 +8,9 @@
#![feature(let_chains)]
#![feature(min_specialization)]
#![feature(never_type)]
#![feature(lazy_cell)]
#![feature(rustc_attrs)]
#![feature(stmt_expr_attributes)]
#![feature(trusted_step)]
#![feature(try_blocks)]
#![recursion_limit = "256"]
#[macro_use]
extern crate rustc_middle;

View file

@ -1,4 +1,4 @@
use rustc_errors::MultiSpan;
use rustc_errors::{codes::*, MultiSpan};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::{GenericArg, Ty};
use rustc_span::Span;
@ -6,7 +6,7 @@ use rustc_span::Span;
use crate::diagnostics::RegionName;
#[derive(Diagnostic)]
#[diag(borrowck_move_unsized, code = "E0161")]
#[diag(borrowck_move_unsized, code = E0161)]
pub(crate) struct MoveUnsized<'tcx> {
pub ty: Ty<'tcx>,
#[primary_span]
@ -281,7 +281,7 @@ pub(crate) enum CaptureVarCause {
}
#[derive(Diagnostic)]
#[diag(borrowck_cannot_move_when_borrowed, code = "E0505")]
#[diag(borrowck_cannot_move_when_borrowed, code = E0505)]
pub(crate) struct MoveBorrow<'a> {
pub place: &'a str,
pub borrow_place: &'a str,
@ -294,7 +294,7 @@ pub(crate) struct MoveBorrow<'a> {
}
#[derive(Diagnostic)]
#[diag(borrowck_opaque_type_non_generic_param, code = "E0792")]
#[diag(borrowck_opaque_type_non_generic_param, code = E0792)]
pub(crate) struct NonGenericOpaqueTypeParam<'a, 'tcx> {
pub ty: GenericArg<'tcx>,
pub kind: &'a str,

View file

@ -33,7 +33,7 @@ pub(crate) struct ConstraintConversion<'a, 'tcx> {
/// our special inference variable there, we would mess that up.
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
implicit_region_bound: ty::Region<'tcx>,
param_env: ty::ParamEnv<'tcx>,
known_type_outlives_obligations: &'tcx [ty::PolyTypeOutlivesPredicate<'tcx>],
locations: Locations,
span: Span,
category: ConstraintCategory<'tcx>,
@ -47,7 +47,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
universal_regions: &'a UniversalRegions<'tcx>,
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
implicit_region_bound: ty::Region<'tcx>,
param_env: ty::ParamEnv<'tcx>,
known_type_outlives_obligations: &'tcx [ty::PolyTypeOutlivesPredicate<'tcx>],
locations: Locations,
span: Span,
category: ConstraintCategory<'tcx>,
@ -59,7 +59,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
universal_regions,
region_bound_pairs,
implicit_region_bound,
param_env,
known_type_outlives_obligations,
locations,
span,
category,
@ -136,7 +136,11 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
// Extract out various useful fields we'll need below.
let ConstraintConversion {
tcx, region_bound_pairs, implicit_region_bound, param_env, ..
tcx,
region_bound_pairs,
implicit_region_bound,
known_type_outlives_obligations,
..
} = *self;
let ty::OutlivesPredicate(k1, r2) = predicate;
@ -157,7 +161,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
tcx,
region_bound_pairs,
Some(implicit_region_bound),
param_env,
known_type_outlives_obligations,
)
.type_must_outlive(origin, t1, r2, constraint_category);
}

View file

@ -45,12 +45,14 @@ type NormalizedInputsAndOutput<'tcx> = Vec<Ty<'tcx>>;
pub(crate) struct CreateResult<'tcx> {
pub(crate) universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
pub(crate) region_bound_pairs: RegionBoundPairs<'tcx>,
pub(crate) known_type_outlives_obligations: &'tcx [ty::PolyTypeOutlivesPredicate<'tcx>],
pub(crate) normalized_inputs_and_output: NormalizedInputsAndOutput<'tcx>,
}
pub(crate) fn create<'tcx>(
infcx: &InferCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
known_type_outlives_obligations: &'tcx [ty::PolyTypeOutlivesPredicate<'tcx>],
implicit_region_bound: ty::Region<'tcx>,
universal_regions: &Rc<UniversalRegions<'tcx>>,
constraints: &mut MirTypeckRegionConstraints<'tcx>,
@ -58,6 +60,7 @@ pub(crate) fn create<'tcx>(
UniversalRegionRelationsBuilder {
infcx,
param_env,
known_type_outlives_obligations,
implicit_region_bound,
constraints,
universal_regions: universal_regions.clone(),
@ -175,6 +178,7 @@ impl UniversalRegionRelations<'_> {
struct UniversalRegionRelationsBuilder<'this, 'tcx> {
infcx: &'this InferCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
known_type_outlives_obligations: &'tcx [ty::PolyTypeOutlivesPredicate<'tcx>],
universal_regions: Rc<UniversalRegions<'tcx>>,
implicit_region_bound: ty::Region<'tcx>,
constraints: &'this mut MirTypeckRegionConstraints<'tcx>,
@ -200,7 +204,8 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
let defining_ty_def_id = self.universal_regions.defining_ty.def_id().expect_local();
let span = tcx.def_span(defining_ty_def_id);
// Insert the facts we know from the predicates. Why? Why not.
// Insert the `'a: 'b` we know from the predicates.
// This does not consider the type-outlives.
let param_env = self.param_env;
self.add_outlives_bounds(outlives::explicit_outlives_bounds(param_env));
@ -308,6 +313,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
outlives: self.outlives.freeze(),
inverse_outlives: self.inverse_outlives.freeze(),
}),
known_type_outlives_obligations: self.known_type_outlives_obligations,
region_bound_pairs: self.region_bound_pairs,
normalized_inputs_and_output,
}
@ -322,7 +328,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
&self.universal_regions,
&self.region_bound_pairs,
self.implicit_region_bound,
self.param_env,
self.known_type_outlives_obligations,
Locations::All(span),
span,
ConstraintCategory::Internal,

View file

@ -152,9 +152,14 @@ pub(crate) fn type_check<'mir, 'tcx>(
universal_region_relations,
region_bound_pairs,
normalized_inputs_and_output,
known_type_outlives_obligations,
} = free_region_relations::create(
infcx,
param_env,
// FIXME(-Znext-solver): These are unnormalized. Normalize them.
infcx.tcx.arena.alloc_from_iter(
param_env.caller_bounds().iter().filter_map(|clause| clause.as_type_outlives_clause()),
),
implicit_region_bound,
universal_regions,
&mut constraints,
@ -176,6 +181,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
body,
param_env,
&region_bound_pairs,
known_type_outlives_obligations,
implicit_region_bound,
&mut borrowck_context,
);
@ -850,6 +856,7 @@ struct TypeChecker<'a, 'tcx> {
/// all of the promoted items.
user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
known_type_outlives_obligations: &'tcx [ty::PolyTypeOutlivesPredicate<'tcx>],
implicit_region_bound: ty::Region<'tcx>,
reported_errors: FxIndexSet<(Ty<'tcx>, Span)>,
borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>,
@ -1000,6 +1007,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
body: &'a Body<'tcx>,
param_env: ty::ParamEnv<'tcx>,
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
known_type_outlives_obligations: &'tcx [ty::PolyTypeOutlivesPredicate<'tcx>],
implicit_region_bound: ty::Region<'tcx>,
borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>,
) -> Self {
@ -1010,6 +1018,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
user_type_annotations: &body.user_type_annotations,
param_env,
region_bound_pairs,
known_type_outlives_obligations,
implicit_region_bound,
borrowck_context,
reported_errors: Default::default(),
@ -1099,10 +1108,17 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
#[instrument(skip(self), level = "debug")]
fn check_user_type_annotations(&mut self) {
debug!(?self.user_type_annotations);
let tcx = self.tcx();
for user_annotation in self.user_type_annotations {
let CanonicalUserTypeAnnotation { span, ref user_ty, inferred_ty } = *user_annotation;
let annotation = self.instantiate_canonical_with_fresh_inference_vars(span, user_ty);
self.ascribe_user_type(inferred_ty, annotation, span);
if let ty::UserType::TypeOf(def, args) = annotation
&& let DefKind::InlineConst = tcx.def_kind(def)
{
self.check_inline_const(inferred_ty, def.expect_local(), args, span);
} else {
self.ascribe_user_type(inferred_ty, annotation, span);
}
}
}
@ -1120,7 +1136,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
self.borrowck_context.universal_regions,
self.region_bound_pairs,
self.implicit_region_bound,
self.param_env,
self.known_type_outlives_obligations,
locations,
locations.span(self.body),
category,
@ -1195,6 +1211,36 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
Ok(())
}
fn check_inline_const(
&mut self,
inferred_ty: Ty<'tcx>,
def_id: LocalDefId,
args: UserArgs<'tcx>,
span: Span,
) {
assert!(args.user_self_ty.is_none());
let tcx = self.tcx();
let const_ty = tcx.type_of(def_id).instantiate(tcx, args.args);
if let Err(terr) =
self.eq_types(const_ty, inferred_ty, Locations::All(span), ConstraintCategory::Boring)
{
span_bug!(
span,
"bad inline const pattern: ({:?} = {:?}) {:?}",
const_ty,
inferred_ty,
terr
);
}
let args = self.infcx.resolve_vars_if_possible(args.args);
let predicates = self.prove_closure_bounds(tcx, def_id, args, Locations::All(span));
self.normalize_and_prove_instantiated_predicates(
def_id.to_def_id(),
predicates,
Locations::All(span),
);
}
fn tcx(&self) -> TyCtxt<'tcx> {
self.infcx.tcx
}
@ -1851,7 +1897,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let def_id = uv.def;
if tcx.def_kind(def_id) == DefKind::InlineConst {
let def_id = def_id.expect_local();
let predicates = self.prove_closure_bounds(tcx, def_id, uv.args, location);
let predicates = self.prove_closure_bounds(
tcx,
def_id,
uv.args,
location.to_locations(),
);
self.normalize_and_prove_instantiated_predicates(
def_id.to_def_id(),
predicates,
@ -2654,9 +2705,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// desugaring. A closure gets desugared to a struct, and
// these extra requirements are basically like where
// clauses on the struct.
AggregateKind::Closure(def_id, args) | AggregateKind::Coroutine(def_id, args) => {
(def_id, self.prove_closure_bounds(tcx, def_id.expect_local(), args, location))
}
AggregateKind::Closure(def_id, args) | AggregateKind::Coroutine(def_id, args) => (
def_id,
self.prove_closure_bounds(
tcx,
def_id.expect_local(),
args,
location.to_locations(),
),
),
AggregateKind::Array(_) | AggregateKind::Tuple => {
(CRATE_DEF_ID.to_def_id(), ty::InstantiatedPredicates::empty())
@ -2675,7 +2732,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
def_id: LocalDefId,
args: GenericArgsRef<'tcx>,
location: Location,
locations: Locations,
) -> ty::InstantiatedPredicates<'tcx> {
if let Some(closure_requirements) = &tcx.mir_borrowck(def_id).closure_requirements {
constraint_conversion::ConstraintConversion::new(
@ -2683,8 +2740,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
self.borrowck_context.universal_regions,
self.region_bound_pairs,
self.implicit_region_bound,
self.param_env,
location.to_locations(),
self.known_type_outlives_obligations,
locations,
DUMMY_SP, // irrelevant; will be overridden.
ConstraintCategory::Boring, // same as above.
self.borrowck_context.constraints,
@ -2710,7 +2767,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
if let Err(_) = self.eq_args(
typeck_root_args,
parent_args,
location.to_locations(),
locations,
ConstraintCategory::BoringNoLocation,
) {
span_mirbug!(

View file

@ -1,6 +1,6 @@
use rustc_errors::{
AddToDiagnostic, DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, Level,
MultiSpan, SingleLabelManySpans,
codes::*, AddToDiagnostic, DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic,
Level, MultiSpan, SingleLabelManySpans,
};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{symbol::Ident, Span, Symbol};
@ -269,7 +269,7 @@ pub(crate) struct ConcatIdentsIdentArgs {
}
#[derive(Diagnostic)]
#[diag(builtin_macros_bad_derive_target, code = "E0774")]
#[diag(builtin_macros_bad_derive_target, code = E0774)]
pub(crate) struct BadDeriveTarget {
#[primary_span]
#[label]
@ -283,7 +283,7 @@ pub(crate) struct BadDeriveTarget {
pub(crate) struct TestsNotSupport {}
#[derive(Diagnostic)]
#[diag(builtin_macros_unexpected_lit, code = "E0777")]
#[diag(builtin_macros_unexpected_lit, code = E0777)]
pub(crate) struct BadDeriveLit {
#[primary_span]
#[label]

View file

@ -139,7 +139,7 @@ fn parse_args<'a>(ecx: &mut ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<
_ => {
let expr = p.parse_expr()?;
if !args.named_args().is_empty() {
ecx.dcx().emit_err(errors::PositionalAfterNamed {
return Err(ecx.dcx().create_err(errors::PositionalAfterNamed {
span: expr.span,
args: args
.named_args()
@ -147,7 +147,7 @@ fn parse_args<'a>(ecx: &mut ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<
.filter_map(|a| a.kind.ident().map(|ident| (a, ident)))
.map(|(arg, n)| n.span.to(arg.expr.span))
.collect(),
});
}));
}
args.add(FormatArgument { kind: FormatArgumentKind::Normal, expr });
}
@ -313,6 +313,8 @@ fn make_format_args(
}
use ArgRef::*;
let mut unnamed_arg_after_named_arg = false;
let mut lookup_arg = |arg: ArgRef<'_>,
span: Option<Span>,
used_as: PositionUsedAs,
@ -352,6 +354,7 @@ fn make_format_args(
// For the moment capturing variables from format strings expanded from macros is
// disabled (see RFC #2795)
ecx.dcx().emit_err(errors::FormatNoArgNamed { span, name });
unnamed_arg_after_named_arg = true;
DummyResult::raw_expr(span, true)
};
Ok(args.add(FormatArgument { kind: FormatArgumentKind::Captured(ident), expr }))
@ -510,7 +513,8 @@ fn make_format_args(
})
.collect::<Vec<_>>();
if !unused.is_empty() {
let has_unused = !unused.is_empty();
if has_unused {
// If there's a lot of unused arguments,
// let's check if this format arguments looks like another syntax (printf / shell).
let detect_foreign_fmt = unused.len() > args.explicit_args().len() / 2;
@ -529,7 +533,7 @@ fn make_format_args(
// Only check for unused named argument names if there are no other errors to avoid causing
// too much noise in output errors, such as when a named argument is entirely unused.
if invalid_refs.is_empty() && ecx.dcx().has_errors().is_none() {
if invalid_refs.is_empty() && !has_unused && !unnamed_arg_after_named_arg {
for &(index, span, used_as) in &numeric_refences_to_named_arg {
let (position_sp_to_replace, position_sp_for_msg) = match used_as {
Placeholder(pspan) => (span, pspan),

View file

@ -5,17 +5,14 @@
#![feature(rustdoc_internals)]
#![doc(rust_logo)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(array_windows)]
#![feature(assert_matches)]
#![feature(box_patterns)]
#![feature(decl_macro)]
#![feature(if_let_guard)]
#![feature(is_sorted)]
#![feature(let_chains)]
#![feature(lint_reasons)]
#![feature(proc_macro_internals)]
#![feature(proc_macro_quote)]
#![recursion_limit = "256"]
extern crate proc_macro;

View file

@ -33,14 +33,14 @@ jobs:
TARGET_TRIPLE: x86_64-pc-windows-gnu
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: CPU features
if: matrix.os == 'ubuntu-latest'
run: cat /proc/cpuinfo
- name: Cache cargo target dir
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: build/cg_clif
key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}

View file

@ -10,7 +10,7 @@ jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: |
sed -i 's/components.*/components = []/' rust-toolchain
echo 'profile = "minimal"' >> rust-toolchain

View file

@ -10,7 +10,7 @@ jobs:
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Avoid installing rustc-dev
run: |
@ -64,14 +64,14 @@ jobs:
TARGET_TRIPLE: x86_64-pc-windows-gnu
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: CPU features
if: matrix.os == 'ubuntu-latest'
run: cat /proc/cpuinfo
- name: Cache cargo target dir
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: build/cg_clif
key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
@ -138,7 +138,7 @@ jobs:
shell: bash
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: CPU features
run: cat /proc/cpuinfo
@ -164,13 +164,13 @@ jobs:
shell: bash
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: CPU features
run: cat /proc/cpuinfo
- name: Cache cargo target dir
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: build/cg_clif
key: ${{ runner.os }}-x86_64-unknown-linux-gnu-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
@ -221,10 +221,10 @@ jobs:
TARGET_TRIPLE: x86_64-pc-windows-gnu
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Cache cargo target dir
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: build/cg_clif
key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-dist-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
@ -276,7 +276,7 @@ jobs:
cancel-in-progress: true
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Download all built artifacts
uses: actions/download-artifact@v4

View file

@ -9,13 +9,13 @@ jobs:
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: CPU features
run: cat /proc/cpuinfo
- name: Cache cargo target dir
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: build/cg_clif
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
@ -32,13 +32,13 @@ jobs:
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: CPU features
run: cat /proc/cpuinfo
- name: Cache cargo target dir
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: build/cg_clif
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}

View file

@ -1,8 +1,9 @@
{
"editor.formatOnSave": true,
// source for rustc_* is not included in the rust-src component; disable the errors about this
// in case rustc.source is disabled for performance reasons; disable the errors about this
"rust-analyzer.diagnostics.disabled": ["unresolved-extern-crate", "unresolved-macro-call"],
"rust-analyzer.rustc.source": "discover",
"rust-analyzer.imports.granularity.enforce": true,
"rust-analyzer.imports.granularity.group": "module",
"rust-analyzer.imports.prefix": "crate",

View file

@ -45,18 +45,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cranelift-bforest"
version = "0.103.0"
version = "0.104.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c22542c0b95bd3302f7ed6839869c561f2324bac2fd5e7e99f5cfa65fdc8b92"
checksum = "d819feeda4c420a18f1e28236ca0ce1177b22bf7c8a44ddee92dfe40de15bcf0"
dependencies = [
"cranelift-entity",
]
[[package]]
name = "cranelift-codegen"
version = "0.103.0"
version = "0.104.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b3db903ef2e9c8a4de2ea6db5db052c7857282952f9df604aa55d169e6000d8"
checksum = "e9b8d03d5bdbca7e5f72b0e0a0f69933ed1f09e24be6c075aa6fe3f802b0cc0c"
dependencies = [
"bumpalo",
"cranelift-bforest",
@ -75,39 +75,39 @@ dependencies = [
[[package]]
name = "cranelift-codegen-meta"
version = "0.103.0"
version = "0.104.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6590feb5a1d6438f974bf6a5ac4dddf69fca14e1f07f3265d880f69e61a94463"
checksum = "a3fd3664e38e51649b17dc30cfdd561273fe2f590dcd013fb75d9eabc6272dfb"
dependencies = [
"cranelift-codegen-shared",
]
[[package]]
name = "cranelift-codegen-shared"
version = "0.103.0"
version = "0.104.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7239038c56fafe77fddc8788fc8533dd6c474dc5bdc5637216404f41ba807330"
checksum = "4b031ec5e605828975952622b5a77d49126f20ffe88d33719a0af66b23a0fc36"
[[package]]
name = "cranelift-control"
version = "0.103.0"
version = "0.104.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7dc9c595341404d381d27a3d950160856b35b402275f0c3990cd1ad683c8053"
checksum = "fada054d017cf2ed8f7ed2336e0517fc1b19e6825be1790de9eb00c94788362b"
dependencies = [
"arbitrary",
]
[[package]]
name = "cranelift-entity"
version = "0.103.0"
version = "0.104.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44e3ee532fc4776c69bcedf7e62f9632cbb3f35776fa9a525cdade3195baa3f7"
checksum = "177b6f94ae8de6348eb45bf977c79ab9e3c40fc3ac8cb7ed8109560ea39bee7d"
[[package]]
name = "cranelift-frontend"
version = "0.103.0"
version = "0.104.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a612c94d09e653662ec37681dc2d6fd2b9856e6df7147be0afc9aabb0abf19df"
checksum = "ebebd23a69a23e3ddea78e98ff3a2de222e88c8e045d81ef4a72f042e0d79dbd"
dependencies = [
"cranelift-codegen",
"log",
@ -117,15 +117,15 @@ dependencies = [
[[package]]
name = "cranelift-isle"
version = "0.103.0"
version = "0.104.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85db9830abeb1170b7d29b536ffd55af1d4d26ac8a77570b5d1aca003bf225cc"
checksum = "1571bfc14df8966d12c6121b5325026591a4b4009e22fea0fe3765ab7cd33b96"
[[package]]
name = "cranelift-jit"
version = "0.103.0"
version = "0.104.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4946271f1055e26544ef8c90fa24776f201566419dfac4b3962c39d5a804ff67"
checksum = "2f61e236d7622c3c43016e8b0f3ba27136e21ac7de328c7fda902e61db1de851"
dependencies = [
"anyhow",
"cranelift-codegen",
@ -138,14 +138,14 @@ dependencies = [
"region",
"target-lexicon",
"wasmtime-jit-icache-coherence",
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
name = "cranelift-module"
version = "0.103.0"
version = "0.104.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb7e3bdae2597556e59edeb8ecb62eb32c7e054c4f042d393732902979db69c3"
checksum = "f30c6820342015c5009070e3e48d1da7b13521399de904663f1c84f5ee839657"
dependencies = [
"anyhow",
"cranelift-codegen",
@ -154,9 +154,9 @@ dependencies = [
[[package]]
name = "cranelift-native"
version = "0.103.0"
version = "0.104.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "301ef0edafeaeda5771a5d2db64ac53e1818ae3111220a185677025fe91db4a1"
checksum = "35a69c37e0c10b46fe5527f2397ac821046efbf5f7ec112c8b84df25712f465b"
dependencies = [
"cranelift-codegen",
"libc",
@ -165,9 +165,9 @@ dependencies = [
[[package]]
name = "cranelift-object"
version = "0.103.0"
version = "0.104.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59e0ee3d013728903e0c513c31afa389b559bfd4fe8a44f80335c799e3132a41"
checksum = "24425a329b4343177d5f1852243841dcec17f929d72c0e7f41262140155e55e7"
dependencies = [
"anyhow",
"cranelift-codegen",
@ -251,7 +251,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161"
dependencies = [
"cfg-if",
"windows-sys",
"windows-sys 0.48.0",
]
[[package]]
@ -374,13 +374,13 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasmtime-jit-icache-coherence"
version = "16.0.0"
version = "17.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b6d197fcc34ad32ed440e1f9552fd57d1f377d9699d31dee1b5b457322c1f8a"
checksum = "bdc26415bb89e9ccd3bdc498fef63aabf665c4c0dd710c107691deb9694955da"
dependencies = [
"cfg-if",
"libc",
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
@ -411,7 +411,16 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets",
"windows-targets 0.48.5",
]
[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets 0.52.0",
]
[[package]]
@ -420,13 +429,28 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
"windows_aarch64_gnullvm 0.48.5",
"windows_aarch64_msvc 0.48.5",
"windows_i686_gnu 0.48.5",
"windows_i686_msvc 0.48.5",
"windows_x86_64_gnu 0.48.5",
"windows_x86_64_gnullvm 0.48.5",
"windows_x86_64_msvc 0.48.5",
]
[[package]]
name = "windows-targets"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
dependencies = [
"windows_aarch64_gnullvm 0.52.0",
"windows_aarch64_msvc 0.52.0",
"windows_i686_gnu 0.52.0",
"windows_i686_msvc 0.52.0",
"windows_x86_64_gnu 0.52.0",
"windows_x86_64_gnullvm 0.52.0",
"windows_x86_64_msvc 0.52.0",
]
[[package]]
@ -435,38 +459,80 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_gnu"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_i686_msvc"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"

View file

@ -8,12 +8,12 @@ crate-type = ["dylib"]
[dependencies]
# These have to be in sync with each other
cranelift-codegen = { version = "0.103", default-features = false, features = ["std", "unwind", "all-arch"] }
cranelift-frontend = { version = "0.103" }
cranelift-module = { version = "0.103" }
cranelift-native = { version = "0.103" }
cranelift-jit = { version = "0.103", optional = true }
cranelift-object = { version = "0.103" }
cranelift-codegen = { version = "0.104", default-features = false, features = ["std", "unwind", "all-arch"] }
cranelift-frontend = { version = "0.104" }
cranelift-module = { version = "0.104" }
cranelift-native = { version = "0.104" }
cranelift-jit = { version = "0.104", optional = true }
cranelift-object = { version = "0.104" }
target-lexicon = "0.12.0"
gimli = { version = "0.28", default-features = false, features = ["write"]}
object = { version = "0.32", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }

View file

@ -62,6 +62,27 @@ $ ./test.sh
For more docs on how to build and test see [build_system/usage.txt](build_system/usage.txt) or the help message of `./y.sh`.
## Platform support
|OS \ architecture|x86\_64|AArch64|Riscv64|s390x (System-Z)|
|---|---|---|---|---|
|Linux|✅|✅|✅[^no-rustup]|✅[^no-rustup]|
|FreeBSD|✅[^no-rustup]|❓|❓|❓|
|AIX|❌[^xcoff]|N/A|N/A|❌[^xcoff]|
|Other unixes|❓|❓|❓|❓|
|macOS|✅|❌[^apple-silicon]|N/A|N/A|
|Windows|✅[^no-rustup]|❌|N/A|N/A|
✅: Fully supported and tested
❓: Maybe supported, not tested
❌: Not supported at all
Not all targets are available as rustup component for nightly. See notes in the platform support matrix.
[^xcoff]: XCOFF object file format is not supported.
[^apple-silicon]: Tracked in [#1248](https://github.com/rust-lang/rustc_codegen_cranelift/issues/1248).
[^no-rustup]: Not available as rustup component for nightly. You can build it yourself.
## Usage
rustc_codegen_cranelift can be used as a near-drop-in replacement for `cargo build` or `cargo run` for existing projects.
@ -100,6 +121,8 @@ You need to do this steps to successfully compile and use the cranelift backend
* (Optional) run tests: `rustup run stage2 ./y.sh test`
8. Now you can use your cg_clif build to compile other Rust programs, e.g. you can open any Rust crate and run commands like `$RustCheckoutDir/compiler/rustc_codegen_cranelift/dist/cargo-clif build --release`.
You can also set `rust-analyzer.rustc.source` to your rust workspace to get rust-analyzer to understand your changes.
## Configuration
See the documentation on the `BackendConfig` struct in [config.rs](src/config.rs) for all

View file

@ -113,8 +113,8 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
pub(crate) static RAND_REPO: GitRepo = GitRepo::github(
"rust-random",
"rand",
"9a02c819cc1e4ec6959ae25eafbb5cf6acb68234",
"4934f0afb1d1c2ca",
"1f4507a8e1cf8050e4ceef95eeda8f64645b6719",
"981f8bf489338978",
"rand",
);
@ -133,8 +133,8 @@ pub(crate) static REGEX: CargoProject = CargoProject::new(&REGEX_REPO.source_dir
pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github(
"rust-lang",
"portable-simd",
"4825b2a64d765317066948867e8714674419359b",
"9e67d07c00f5fb0b",
"97007cc2e70df8c97326ce896a79e2f0ce4dd98b",
"e54a16035cedf205",
"portable-simd",
);

View file

@ -1,22 +0,0 @@
From a101a43b795431ce617e7782afb451f4853afc00 Mon Sep 17 00:00:00 2001
From: bjorn3 <17426603+bjorn3@users.noreply.github.com>
Date: Thu, 7 Dec 2023 14:51:35 +0000
Subject: [PATCH] Enable the exposed_provenance feature
---
crates/core_simd/tests/pointers.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/crates/core_simd/tests/pointers.rs b/crates/core_simd/tests/pointers.rs
index 0ae8f83..06620d6 100644
--- a/crates/core_simd/tests/pointers.rs
+++ b/crates/core_simd/tests/pointers.rs
@@ -1,4 +1,4 @@
-#![feature(portable_simd, strict_provenance)]
+#![feature(exposed_provenance, portable_simd, strict_provenance)]
use core_simd::simd::{Simd, SimdConstPtr, SimdMutPtr};
--
2.34.1

View file

@ -21,7 +21,7 @@ index 897a5e9..331f66f 100644
-#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
#![cfg_attr(test, feature(cfg_match))]
#![feature(int_roundings)]
#![feature(slice_group_by)]
#![feature(split_array)]
diff --git a/atomic.rs b/atomic.rs
index b735957..ea728b6 100644
--- a/atomic.rs

View file

@ -487,6 +487,7 @@ dependencies = [
"rand_pcg",
"rayon",
"serde",
"zerocopy",
]
[[package]]
@ -505,6 +506,7 @@ version = "0.7.0"
dependencies = [
"getrandom",
"serde",
"zerocopy",
]
[[package]]
@ -525,6 +527,7 @@ name = "rand_pcg"
version = "0.4.0"
dependencies = [
"bincode",
"rand",
"rand_core",
"serde",
]
@ -823,3 +826,23 @@ name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "zerocopy"
version = "0.7.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.37",
]

View file

@ -61,9 +61,9 @@ dependencies = [
[[package]]
name = "compiler_builtins"
version = "0.1.104"
version = "0.1.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99c3f9035afc33f4358773239573f7d121099856753e1bbd2a6a5207098fc741"
checksum = "f4ab134a739bafec76aa91ccb15d519a54e569350644a1fea6528d5a0d407e22"
dependencies = [
"cc",
"rustc-std-workspace-core",

View file

@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-12-31"
channel = "nightly-2024-01-26"
components = ["rust-src", "rustc-dev", "llvm-tools"]

View file

@ -13,17 +13,14 @@ use gimli::write::{
};
use gimli::{Encoding, Format, LineEncoding, RunTimeEndian};
use indexmap::IndexSet;
use rustc_session::Session;
pub(crate) use self::emit::{DebugReloc, DebugRelocName};
pub(crate) use self::unwind::UnwindContext;
use crate::prelude::*;
pub(crate) fn producer() -> String {
format!(
"rustc version {} with cranelift {}",
rustc_interface::util::rustc_version_str().unwrap_or("unknown version"),
cranelift_codegen::VERSION,
)
pub(crate) fn producer(sess: &Session) -> String {
format!("rustc version {} with cranelift {}", sess.cfg_version, cranelift_codegen::VERSION)
}
pub(crate) struct DebugContext {
@ -67,7 +64,7 @@ impl DebugContext {
let should_remap_filepaths = tcx.sess.should_prefer_remapped_for_codegen();
let producer = producer();
let producer = producer(tcx.sess);
let comp_dir = tcx
.sess
.opts

View file

@ -143,6 +143,7 @@ fn emit_cgu(
debug: Option<DebugContext>,
unwind_context: UnwindContext,
global_asm_object_file: Option<PathBuf>,
producer: &str,
) -> Result<ModuleCodegenResult, String> {
let mut product = module.finish();
@ -152,8 +153,14 @@ fn emit_cgu(
unwind_context.emit(&mut product);
let module_regular =
emit_module(output_filenames, prof, product.object, ModuleKind::Regular, name.clone())?;
let module_regular = emit_module(
output_filenames,
prof,
product.object,
ModuleKind::Regular,
name.clone(),
producer,
)?;
Ok(ModuleCodegenResult {
module_regular,
@ -174,6 +181,7 @@ fn emit_module(
mut object: cranelift_object::object::write::Object<'_>,
kind: ModuleKind,
name: String,
producer_str: &str,
) -> Result<CompiledModule, String> {
if object.format() == cranelift_object::object::BinaryFormat::Elf {
let comment_section = object.add_section(
@ -182,7 +190,7 @@ fn emit_module(
cranelift_object::object::SectionKind::OtherString,
);
let mut producer = vec![0];
producer.extend(crate::debuginfo::producer().as_bytes());
producer.extend(producer_str.as_bytes());
producer.push(0);
object.set_section_data(comment_section, producer, 1);
}
@ -321,6 +329,8 @@ fn module_codegen(
(cgu_name, cx, module, codegened_functions)
});
let producer = crate::debuginfo::producer(tcx.sess);
OngoingModuleCodegen::Async(std::thread::spawn(move || {
cx.profiler.clone().generic_activity_with_arg("compile functions", &*cgu_name).run(|| {
cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
@ -348,6 +358,7 @@ fn module_codegen(
cx.debug_context,
cx.unwind_context,
global_asm_object_file,
&producer,
)
});
std::mem::drop(token);
@ -453,6 +464,7 @@ pub(crate) fn run_aot(
product.object,
ModuleKind::Allocator,
"allocator_shim".to_owned(),
&crate::debuginfo::producer(tcx.sess),
) {
Ok(allocator_module) => Some(allocator_module),
Err(err) => tcx.dcx().fatal(err),
@ -467,7 +479,7 @@ pub(crate) fn run_aot(
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);
let metadata_cgu_name = cgu_name_builder
.build_cgu_name(LOCAL_CRATE, &["crate"], Some("metadata"))
.build_cgu_name(LOCAL_CRATE, ["crate"], Some("metadata"))
.as_str()
.to_string();

View file

@ -321,10 +321,9 @@ fn dep_symbol_lookup_fn(
Linkage::NotLinked | Linkage::IncludedFromDylib => {}
Linkage::Static => {
let name = crate_info.crate_name[&cnum];
sess.dcx()
.struct_err(format!("Can't load static lib {}", name))
.note("rustc_codegen_cranelift can only load dylibs in JIT mode.")
.emit();
let mut diag = sess.dcx().struct_err(format!("Can't load static lib {}", name));
diag.note("rustc_codegen_cranelift can only load dylibs in JIT mode.");
diag.emit();
}
Linkage::Dynamic => {
dylib_paths.push(src.dylib.as_ref().unwrap().0.clone());

View file

@ -52,7 +52,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
}
let operands = operands
.into_iter()
.iter()
.map(|operand| match *operand {
InlineAsmOperand::In { reg, ref value } => CInlineAsmOperand::In {
reg,
@ -506,10 +506,34 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
if self.options.contains(InlineAsmOptions::ATT_SYNTAX) {
generated_asm.push('%');
}
self.registers[*operand_idx]
.unwrap()
.emit(&mut generated_asm, self.arch, *modifier)
.unwrap();
let reg = self.registers[*operand_idx].unwrap();
match self.arch {
InlineAsmArch::X86_64 => match reg {
InlineAsmReg::X86(reg)
if reg as u32 >= X86InlineAsmReg::xmm0 as u32
&& reg as u32 <= X86InlineAsmReg::xmm15 as u32 =>
{
// rustc emits x0 rather than xmm0
let class = match *modifier {
None | Some('x') => "xmm",
Some('y') => "ymm",
Some('z') => "zmm",
_ => unreachable!(),
};
write!(
generated_asm,
"{class}{}",
reg as u32 - X86InlineAsmReg::xmm0 as u32
)
.unwrap();
}
_ => reg
.emit(&mut generated_asm, InlineAsmArch::X86_64, *modifier)
.unwrap(),
},
_ => reg.emit(&mut generated_asm, self.arch, *modifier).unwrap(),
}
}
CInlineAsmOperand::Const { ref value } => {
generated_asm.push_str(value);
@ -739,7 +763,7 @@ fn call_inline_asm<'tcx>(
},
)
.unwrap();
let inline_asm_func = fx.module.declare_func_in_func(inline_asm_func, &mut fx.bcx.func);
let inline_asm_func = fx.module.declare_func_in_func(inline_asm_func, fx.bcx.func);
if fx.clif_comments.enabled() {
fx.add_comment(inline_asm_func, asm_name);
}

View file

@ -35,6 +35,10 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
}
match intrinsic {
"llvm.prefetch" => {
// Nothing to do. This is merely a perf hint.
}
_ if intrinsic.starts_with("llvm.ctlz.v") => {
intrinsic_args!(fx, args => (a); intrinsic);

View file

@ -243,6 +243,20 @@ pub(crate) fn codegen_aarch64_llvm_intrinsic_call<'tcx>(
}
// FIXME generalize vector types
"llvm.aarch64.neon.tbl1.v8i8" => {
intrinsic_args!(fx, args => (t, idx); intrinsic);
let zero = fx.bcx.ins().iconst(types::I8, 0);
for i in 0..8 {
let idx_lane = idx.value_lane(fx, i).load_scalar(fx);
let is_zero =
fx.bcx.ins().icmp_imm(IntCC::UnsignedGreaterThanOrEqual, idx_lane, 16);
let t_idx = fx.bcx.ins().uextend(fx.pointer_type, idx_lane);
let t_lane = t.value_lane_dyn(fx, t_idx).load_scalar(fx);
let res = fx.bcx.ins().select(is_zero, zero, t_lane);
ret.place_lane(fx, i).to_ptr().store(fx, res, MemFlags::trusted());
}
}
"llvm.aarch64.neon.tbl1.v16i8" => {
intrinsic_args!(fx, args => (t, idx); intrinsic);

View file

@ -610,230 +610,56 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_packus_epi16&ig_expand=4903
intrinsic_args!(fx, args => (a, b); intrinsic);
assert_eq!(a.layout(), b.layout());
let layout = a.layout();
pack_instruction(fx, a, b, ret, PackSize::U8, PackWidth::Sse);
}
let (lane_count, lane_ty) = layout.ty.simd_size_and_type(fx.tcx);
let (ret_lane_count, ret_lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx);
assert_eq!(lane_ty, fx.tcx.types.i16);
assert_eq!(ret_lane_ty, fx.tcx.types.u8);
assert_eq!(lane_count * 2, ret_lane_count);
"llvm.x86.sse2.packsswb.128" => {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_packs_epi16&ig_expand=4848
intrinsic_args!(fx, args => (a, b); intrinsic);
let zero = fx.bcx.ins().iconst(types::I16, 0);
let max_u8 = fx.bcx.ins().iconst(types::I16, 255);
let ret_lane_layout = fx.layout_of(fx.tcx.types.u8);
for idx in 0..lane_count {
let lane = a.value_lane(fx, idx).load_scalar(fx);
let sat = fx.bcx.ins().smax(lane, zero);
let sat = fx.bcx.ins().umin(sat, max_u8);
let res = fx.bcx.ins().ireduce(types::I8, sat);
let res_lane = CValue::by_val(res, ret_lane_layout);
ret.place_lane(fx, idx).write_cvalue(fx, res_lane);
}
for idx in 0..lane_count {
let lane = b.value_lane(fx, idx).load_scalar(fx);
let sat = fx.bcx.ins().smax(lane, zero);
let sat = fx.bcx.ins().umin(sat, max_u8);
let res = fx.bcx.ins().ireduce(types::I8, sat);
let res_lane = CValue::by_val(res, ret_lane_layout);
ret.place_lane(fx, lane_count + idx).write_cvalue(fx, res_lane);
}
pack_instruction(fx, a, b, ret, PackSize::S8, PackWidth::Sse);
}
"llvm.x86.avx2.packuswb" => {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_packus_epi16&ig_expand=4906
intrinsic_args!(fx, args => (a, b); intrinsic);
assert_eq!(a.layout(), b.layout());
let layout = a.layout();
let (lane_count, lane_ty) = layout.ty.simd_size_and_type(fx.tcx);
let (ret_lane_count, ret_lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx);
assert_eq!(lane_ty, fx.tcx.types.i16);
assert_eq!(ret_lane_ty, fx.tcx.types.u8);
assert_eq!(lane_count * 2, ret_lane_count);
let zero = fx.bcx.ins().iconst(types::I16, 0);
let max_u8 = fx.bcx.ins().iconst(types::I16, 255);
let ret_lane_layout = fx.layout_of(fx.tcx.types.u8);
for idx in 0..lane_count / 2 {
let lane = a.value_lane(fx, idx).load_scalar(fx);
let sat = fx.bcx.ins().smax(lane, zero);
let sat = fx.bcx.ins().umin(sat, max_u8);
let res = fx.bcx.ins().ireduce(types::I8, sat);
let res_lane = CValue::by_val(res, ret_lane_layout);
ret.place_lane(fx, idx).write_cvalue(fx, res_lane);
}
for idx in 0..lane_count / 2 {
let lane = b.value_lane(fx, idx).load_scalar(fx);
let sat = fx.bcx.ins().smax(lane, zero);
let sat = fx.bcx.ins().umin(sat, max_u8);
let res = fx.bcx.ins().ireduce(types::I8, sat);
let res_lane = CValue::by_val(res, ret_lane_layout);
ret.place_lane(fx, lane_count / 2 + idx).write_cvalue(fx, res_lane);
}
for idx in 0..lane_count / 2 {
let lane = a.value_lane(fx, idx).load_scalar(fx);
let sat = fx.bcx.ins().smax(lane, zero);
let sat = fx.bcx.ins().umin(sat, max_u8);
let res = fx.bcx.ins().ireduce(types::I8, sat);
let res_lane = CValue::by_val(res, ret_lane_layout);
ret.place_lane(fx, lane_count / 2 * 2 + idx).write_cvalue(fx, res_lane);
}
for idx in 0..lane_count / 2 {
let lane = b.value_lane(fx, idx).load_scalar(fx);
let sat = fx.bcx.ins().smax(lane, zero);
let sat = fx.bcx.ins().umin(sat, max_u8);
let res = fx.bcx.ins().ireduce(types::I8, sat);
let res_lane = CValue::by_val(res, ret_lane_layout);
ret.place_lane(fx, lane_count / 2 * 3 + idx).write_cvalue(fx, res_lane);
}
pack_instruction(fx, a, b, ret, PackSize::U8, PackWidth::Avx);
}
"llvm.x86.sse2.packssdw.128" => {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_packs_epi32&ig_expand=4889
"llvm.x86.avx2.packsswb" => {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_packs_epi16&ig_expand=4851
intrinsic_args!(fx, args => (a, b); intrinsic);
assert_eq!(a.layout(), b.layout());
let layout = a.layout();
let (lane_count, lane_ty) = layout.ty.simd_size_and_type(fx.tcx);
let (ret_lane_count, ret_lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx);
assert_eq!(lane_ty, fx.tcx.types.i32);
assert_eq!(ret_lane_ty, fx.tcx.types.i16);
assert_eq!(lane_count * 2, ret_lane_count);
let min_i16 = fx.bcx.ins().iconst(types::I32, i32::from(i16::MIN) as u32 as i64);
let max_i16 = fx.bcx.ins().iconst(types::I32, i32::from(i16::MAX) as u32 as i64);
let ret_lane_layout = fx.layout_of(fx.tcx.types.i16);
for idx in 0..lane_count {
let lane = a.value_lane(fx, idx).load_scalar(fx);
let sat = fx.bcx.ins().smax(lane, min_i16);
let sat = fx.bcx.ins().smin(sat, max_i16);
let res = fx.bcx.ins().ireduce(types::I16, sat);
let res_lane = CValue::by_val(res, ret_lane_layout);
ret.place_lane(fx, idx).write_cvalue(fx, res_lane);
}
for idx in 0..lane_count {
let lane = b.value_lane(fx, idx).load_scalar(fx);
let sat = fx.bcx.ins().smax(lane, min_i16);
let sat = fx.bcx.ins().smin(sat, max_i16);
let res = fx.bcx.ins().ireduce(types::I16, sat);
let res_lane = CValue::by_val(res, ret_lane_layout);
ret.place_lane(fx, lane_count + idx).write_cvalue(fx, res_lane);
}
pack_instruction(fx, a, b, ret, PackSize::S8, PackWidth::Avx);
}
"llvm.x86.sse41.packusdw" => {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_packus_epi32&ig_expand=4912
intrinsic_args!(fx, args => (a, b); intrinsic);
assert_eq!(a.layout(), b.layout());
let layout = a.layout();
pack_instruction(fx, a, b, ret, PackSize::U16, PackWidth::Sse);
}
let (lane_count, lane_ty) = layout.ty.simd_size_and_type(fx.tcx);
let (ret_lane_count, ret_lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx);
assert_eq!(lane_ty, fx.tcx.types.i32);
assert_eq!(ret_lane_ty, fx.tcx.types.u16);
assert_eq!(lane_count * 2, ret_lane_count);
"llvm.x86.sse2.packssdw.128" => {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_packs_epi32&ig_expand=4889
intrinsic_args!(fx, args => (a, b); intrinsic);
let min_u16 = fx.bcx.ins().iconst(types::I32, i64::from(u16::MIN));
let max_u16 = fx.bcx.ins().iconst(types::I32, i64::from(u16::MAX));
let ret_lane_layout = fx.layout_of(fx.tcx.types.u16);
pack_instruction(fx, a, b, ret, PackSize::S16, PackWidth::Sse);
}
for idx in 0..lane_count {
let lane = a.value_lane(fx, idx).load_scalar(fx);
let sat = fx.bcx.ins().smax(lane, min_u16);
let sat = fx.bcx.ins().smin(sat, max_u16);
let res = fx.bcx.ins().ireduce(types::I16, sat);
"llvm.x86.avx2.packusdw" => {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_packus_epi32&ig_expand=4883
intrinsic_args!(fx, args => (a, b); intrinsic);
let res_lane = CValue::by_val(res, ret_lane_layout);
ret.place_lane(fx, idx).write_cvalue(fx, res_lane);
}
for idx in 0..lane_count {
let lane = b.value_lane(fx, idx).load_scalar(fx);
let sat = fx.bcx.ins().smax(lane, min_u16);
let sat = fx.bcx.ins().smin(sat, max_u16);
let res = fx.bcx.ins().ireduce(types::I16, sat);
let res_lane = CValue::by_val(res, ret_lane_layout);
ret.place_lane(fx, lane_count + idx).write_cvalue(fx, res_lane);
}
pack_instruction(fx, a, b, ret, PackSize::U16, PackWidth::Avx);
}
"llvm.x86.avx2.packssdw" => {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_packs_epi32&ig_expand=4892
intrinsic_args!(fx, args => (a, b); intrinsic);
assert_eq!(a.layout(), b.layout());
let layout = a.layout();
let (lane_count, lane_ty) = layout.ty.simd_size_and_type(fx.tcx);
let (ret_lane_count, ret_lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx);
assert_eq!(lane_ty, fx.tcx.types.i32);
assert_eq!(ret_lane_ty, fx.tcx.types.i16);
assert_eq!(lane_count * 2, ret_lane_count);
let min_i16 = fx.bcx.ins().iconst(types::I32, i32::from(i16::MIN) as u32 as i64);
let max_i16 = fx.bcx.ins().iconst(types::I32, i32::from(i16::MAX) as u32 as i64);
let ret_lane_layout = fx.layout_of(fx.tcx.types.i16);
for idx in 0..lane_count / 2 {
let lane = a.value_lane(fx, idx).load_scalar(fx);
let sat = fx.bcx.ins().smax(lane, min_i16);
let sat = fx.bcx.ins().smin(sat, max_i16);
let res = fx.bcx.ins().ireduce(types::I16, sat);
let res_lane = CValue::by_val(res, ret_lane_layout);
ret.place_lane(fx, idx).write_cvalue(fx, res_lane);
}
for idx in 0..lane_count / 2 {
let lane = b.value_lane(fx, idx).load_scalar(fx);
let sat = fx.bcx.ins().smax(lane, min_i16);
let sat = fx.bcx.ins().smin(sat, max_i16);
let res = fx.bcx.ins().ireduce(types::I16, sat);
let res_lane = CValue::by_val(res, ret_lane_layout);
ret.place_lane(fx, lane_count / 2 + idx).write_cvalue(fx, res_lane);
}
for idx in 0..lane_count / 2 {
let lane = a.value_lane(fx, idx).load_scalar(fx);
let sat = fx.bcx.ins().smax(lane, min_i16);
let sat = fx.bcx.ins().smin(sat, max_i16);
let res = fx.bcx.ins().ireduce(types::I16, sat);
let res_lane = CValue::by_val(res, ret_lane_layout);
ret.place_lane(fx, lane_count / 2 * 2 + idx).write_cvalue(fx, res_lane);
}
for idx in 0..lane_count / 2 {
let lane = b.value_lane(fx, idx).load_scalar(fx);
let sat = fx.bcx.ins().smax(lane, min_i16);
let sat = fx.bcx.ins().smin(sat, max_i16);
let res = fx.bcx.ins().ireduce(types::I16, sat);
let res_lane = CValue::by_val(res, ret_lane_layout);
ret.place_lane(fx, lane_count / 2 * 3 + idx).write_cvalue(fx, res_lane);
}
pack_instruction(fx, a, b, ret, PackSize::S16, PackWidth::Avx);
}
"llvm.x86.fma.vfmaddsub.ps"
@ -1407,3 +1233,115 @@ fn llvm_add_sub<'tcx>(
(cb_out, c)
}
enum PackSize {
U8,
U16,
S8,
S16,
}
impl PackSize {
fn ret_clif_type(&self) -> Type {
match self {
Self::U8 | Self::S8 => types::I8,
Self::U16 | Self::S16 => types::I16,
}
}
fn src_clif_type(&self) -> Type {
match self {
Self::U8 | Self::S8 => types::I16,
Self::U16 | Self::S16 => types::I32,
}
}
fn src_ty<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
match self {
Self::U8 | Self::S8 => tcx.types.i16,
Self::U16 | Self::S16 => tcx.types.i32,
}
}
fn ret_ty<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
match self {
Self::U8 => tcx.types.u8,
Self::S8 => tcx.types.i8,
Self::U16 => tcx.types.u16,
Self::S16 => tcx.types.i16,
}
}
fn max(&self) -> i64 {
match self {
Self::U8 => u8::MAX as u64 as i64,
Self::S8 => i8::MAX as u8 as u64 as i64,
Self::U16 => u16::MAX as u64 as i64,
Self::S16 => i16::MAX as u64 as u64 as i64,
}
}
fn min(&self) -> i64 {
match self {
Self::U8 | Self::U16 => 0,
Self::S8 => i16::from(i8::MIN) as u16 as i64,
Self::S16 => i32::from(i16::MIN) as u32 as i64,
}
}
}
enum PackWidth {
Sse = 1,
Avx = 2,
}
impl PackWidth {
fn divisor(&self) -> u64 {
match self {
Self::Sse => 1,
Self::Avx => 2,
}
}
}
/// Implement an x86 pack instruction with the intrinsic `_mm{,256}pack{us,s}_epi{16,32}`.
/// Validated for correctness against LLVM, see commit `c8f5d35508e062bd2d95e6c03429bfec831db6d3`.
fn pack_instruction<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>,
a: CValue<'tcx>,
b: CValue<'tcx>,
ret: CPlace<'tcx>,
ret_size: PackSize,
width: PackWidth,
) {
assert_eq!(a.layout(), b.layout());
let layout = a.layout();
let (src_lane_count, src_lane_ty) = layout.ty.simd_size_and_type(fx.tcx);
let (ret_lane_count, ret_lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx);
assert_eq!(src_lane_ty, ret_size.src_ty(fx.tcx));
assert_eq!(ret_lane_ty, ret_size.ret_ty(fx.tcx));
assert_eq!(src_lane_count * 2, ret_lane_count);
let min = fx.bcx.ins().iconst(ret_size.src_clif_type(), ret_size.min());
let max = fx.bcx.ins().iconst(ret_size.src_clif_type(), ret_size.max());
let ret_lane_layout = fx.layout_of(ret_size.ret_ty(fx.tcx));
let mut round = |source: CValue<'tcx>, source_offset: u64, dest_offset: u64| {
let step_amount = src_lane_count / width.divisor();
let dest_offset = step_amount * dest_offset;
for idx in 0..step_amount {
let lane = source.value_lane(fx, step_amount * source_offset + idx).load_scalar(fx);
let sat = fx.bcx.ins().smax(lane, min);
let sat = match ret_size {
PackSize::U8 | PackSize::U16 => fx.bcx.ins().umin(sat, max),
PackSize::S8 | PackSize::S16 => fx.bcx.ins().smin(sat, max),
};
let res = fx.bcx.ins().ireduce(ret_size.ret_clif_type(), sat);
let res_lane = CValue::by_val(res, ret_lane_layout);
ret.place_lane(fx, dest_offset + idx).write_cvalue(fx, res_lane);
}
};
round(a, 0, 0);
round(b, 0, 1);
if let PackWidth::Avx = width {
round(a, 1, 2);
round(b, 1, 3);
}
}

View file

@ -293,7 +293,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
}
ret.write_cvalue(fx, base);
let ret_lane = ret.place_lane(fx, idx.try_into().unwrap());
let ret_lane = ret.place_lane(fx, idx.into());
ret_lane.write_cvalue(fx, val);
}
@ -340,7 +340,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
);
}
let ret_lane = v.value_lane(fx, idx.try_into().unwrap());
let ret_lane = v.value_lane(fx, idx.into());
ret.write_cvalue(fx, ret_lane);
}
@ -822,7 +822,35 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
let (lane_count, lane_ty) = a.layout().ty.simd_size_and_type(fx.tcx);
let lane_layout = fx.layout_of(lane_ty);
let m = m.load_scalar(fx);
let expected_int_bits = lane_count.max(8);
let expected_bytes = expected_int_bits / 8 + ((expected_int_bits % 8 > 0) as u64);
let m = match m.layout().ty.kind() {
ty::Uint(i) if i.bit_width() == Some(expected_int_bits) => m.load_scalar(fx),
ty::Array(elem, len)
if matches!(elem.kind(), ty::Uint(ty::UintTy::U8))
&& len.try_eval_target_usize(fx.tcx, ty::ParamEnv::reveal_all())
== Some(expected_bytes) =>
{
m.force_stack(fx).0.load(
fx,
Type::int(expected_int_bits as u16).unwrap(),
MemFlags::trusted(),
)
}
_ => {
fx.tcx.dcx().span_fatal(
span,
format!(
"invalid monomorphization of `simd_select_bitmask` intrinsic: \
cannot accept `{}` as mask, expected `u{}` or `[u8; {}]`",
ret.layout().ty,
expected_int_bits,
expected_bytes
),
);
}
};
for lane in 0..lane_count {
let m_lane = fx.bcx.ins().ushr_imm(m, u64::from(lane) as i64);

View file

@ -18,7 +18,6 @@ extern crate rustc_fs_util;
extern crate rustc_hir;
extern crate rustc_incremental;
extern crate rustc_index;
extern crate rustc_interface;
extern crate rustc_metadata;
extern crate rustc_session;
extern crate rustc_span;
@ -42,7 +41,7 @@ use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_session::config::OutputFilenames;
use rustc_session::Session;
use rustc_span::Symbol;
use rustc_span::{sym, Symbol};
pub use crate::config::*;
use crate::prelude::*;
@ -190,8 +189,17 @@ impl CodegenBackend for CraneliftCodegenBackend {
}
}
fn target_features(&self, _sess: &Session, _allow_unstable: bool) -> Vec<rustc_span::Symbol> {
vec![] // FIXME necessary for #[cfg(target_feature]
fn target_features(&self, sess: &Session, _allow_unstable: bool) -> Vec<rustc_span::Symbol> {
// FIXME return the actually used target features. this is necessary for #[cfg(target_feature)]
if sess.target.arch == "x86_64" && sess.target.os != "none" {
// x86_64 mandates SSE2 support
vec![Symbol::intern("fxsr"), sym::sse, Symbol::intern("sse2")]
} else if sess.target.arch == "aarch64" && sess.target.os != "none" {
// AArch64 mandates Neon support
vec![sym::neon]
} else {
vec![]
}
}
fn print_version(&self) {
@ -305,16 +313,13 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn isa::Tar
let flags = settings::Flags::new(flags_builder);
let isa_builder = match sess.opts.cg.target_cpu.as_deref() {
Some("native") => {
let builder = cranelift_native::builder_with_options(true).unwrap();
builder
}
Some("native") => cranelift_native::builder_with_options(true).unwrap(),
Some(value) => {
let mut builder =
cranelift_codegen::isa::lookup(target_triple.clone()).unwrap_or_else(|err| {
sess.dcx().fatal(format!("can't compile for {}: {}", target_triple, err));
});
if let Err(_) = builder.enable(value) {
if builder.enable(value).is_err() {
sess.dcx()
.fatal("the specified target cpu isn't currently supported by Cranelift.");
}

View file

@ -28,10 +28,9 @@ pub(crate) fn unsized_info<'tcx>(
.bcx
.ins()
.iconst(fx.pointer_type, len.eval_target_usize(fx.tcx, ParamEnv::reveal_all()) as i64),
(
&ty::Dynamic(ref data_a, _, src_dyn_kind),
&ty::Dynamic(ref data_b, _, target_dyn_kind),
) if src_dyn_kind == target_dyn_kind => {
(&ty::Dynamic(data_a, _, src_dyn_kind), &ty::Dynamic(data_b, _, target_dyn_kind))
if src_dyn_kind == target_dyn_kind =>
{
let old_info =
old_info.expect("unsized_info: missing old info for trait upcasting coercion");
if data_a.principal_def_id() == data_b.principal_def_id() {

View file

@ -95,7 +95,7 @@ pub(crate) fn get_vtable<'tcx>(
let alloc_id = fx.tcx.vtable_allocation((ty, trait_ref));
let data_id =
data_id_for_alloc_id(&mut fx.constants_cx, &mut *fx.module, alloc_id, Mutability::Not);
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
let local_data_id = fx.module.declare_data_in_func(data_id, fx.bcx.func);
if fx.clif_comments.enabled() {
fx.add_comment(local_data_id, format!("vtable: {:?}", alloc_id));
}

View file

@ -35,7 +35,7 @@ pub(crate) enum PossibleFeature<'a> {
struct ExitCode(Option<i32>);
impl IntoDiagnosticArg for ExitCode {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
let ExitCode(exit_code) = self;
match exit_code {
Some(t) => t.into_diagnostic_arg(),

View file

@ -39,6 +39,9 @@ codegen_llvm_lto_dylib = lto cannot be used for `dylib` crate type without `-Zdy
codegen_llvm_lto_proc_macro = lto cannot be used for `proc-macro` crate type without `-Zdylib-lto`
codegen_llvm_mismatch_data_layout =
data-layout for target `{$rustc_target}`, `{$rustc_layout}`, differs from LLVM target's `{$llvm_target}` default layout, `{$llvm_layout}`
codegen_llvm_missing_features =
add the missing features in a `target_feature` attribute

View file

@ -34,6 +34,7 @@ use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel};
use smallvec::SmallVec;
use libc::c_uint;
use std::borrow::Borrow;
use std::cell::{Cell, RefCell};
use std::ffi::CStr;
use std::str;
@ -155,8 +156,7 @@ pub unsafe fn create_module<'ll>(
}
// Ensure the data-layout values hardcoded remain the defaults.
if sess.target.is_builtin {
// tm is disposed by its drop impl
{
let tm = crate::back::write::create_informational_target_machine(tcx.sess);
llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, &tm);
@ -164,33 +164,13 @@ pub unsafe fn create_module<'ll>(
let llvm_data_layout = str::from_utf8(CStr::from_ptr(llvm_data_layout).to_bytes())
.expect("got a non-UTF8 data-layout from LLVM");
// Unfortunately LLVM target specs change over time, and right now we
// don't have proper support to work with any more than one
// `data_layout` than the one that is in the rust-lang/rust repo. If
// this compiler is configured against a custom LLVM, we may have a
// differing data layout, even though we should update our own to use
// that one.
//
// As an interim hack, if CFG_LLVM_ROOT is not an empty string then we
// disable this check entirely as we may be configured with something
// that has a different target layout.
//
// Unsure if this will actually cause breakage when rustc is configured
// as such.
//
// FIXME(#34960)
let cfg_llvm_root = option_env!("CFG_LLVM_ROOT").unwrap_or("");
let custom_llvm_used = !cfg_llvm_root.trim().is_empty();
if !custom_llvm_used && target_data_layout != llvm_data_layout {
bug!(
"data-layout for target `{rustc_target}`, `{rustc_layout}`, \
differs from LLVM target's `{llvm_target}` default layout, `{llvm_layout}`",
rustc_target = sess.opts.target_triple,
rustc_layout = target_data_layout,
llvm_target = sess.target.llvm_target,
llvm_layout = llvm_data_layout
);
if target_data_layout != llvm_data_layout {
tcx.dcx().emit_err(crate::errors::MismatchedDataLayout {
rustc_target: sess.opts.target_triple.to_string().as_str(),
rustc_layout: target_data_layout.as_str(),
llvm_target: sess.target.llvm_target.borrow(),
llvm_layout: llvm_data_layout,
});
}
}

View file

@ -403,6 +403,7 @@ fn codegenned_and_inlined_items(tcx: TyCtxt<'_>) -> DefIdSet {
let mut result = items.clone();
for cgu in cgus {
#[allow(rustc::potential_query_instability)]
for item in cgu.items().keys() {
if let mir::mono::MonoItem::Fn(ref instance) = item {
let did = instance.def_id();

View file

@ -244,3 +244,12 @@ pub(crate) struct CopyBitcode {
pub struct UnknownCompression {
pub algorithm: &'static str,
}
#[derive(Diagnostic)]
#[diag(codegen_llvm_mismatch_data_layout)]
pub struct MismatchedDataLayout<'a> {
pub rustc_target: &'a str,
pub rustc_layout: &'a str,
pub llvm_target: &'a str,
pub llvm_layout: &'a str,
}

View file

@ -14,9 +14,7 @@
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(min_specialization)]
#![feature(never_type)]
#![feature(impl_trait_in_assoc_type)]
#![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]

View file

@ -206,7 +206,7 @@ impl fmt::Display for CguReuse {
}
impl IntoDiagnosticArg for CguReuse {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
}
}
@ -267,6 +267,7 @@ impl CguReuseTracker {
fn check_expected_reuse(&self, sess: &Session) {
if let Some(ref data) = self.data {
#[allow(rustc::potential_query_instability)]
let mut keys = data.expected_reuse.keys().collect::<Vec<_>>();
keys.sort_unstable();
for cgu_name in keys {

View file

@ -682,6 +682,7 @@ fn link_dwarf_object<'a>(
}
// Input rlibs contain .o/.dwo files from dependencies.
#[allow(rustc::potential_query_instability)]
let input_rlibs = cg_results
.crate_info
.used_crate_source

View file

@ -14,8 +14,11 @@ use rustc_data_structures::memmap::Mmap;
use rustc_data_structures::profiling::{SelfProfilerRef, VerboseTimingGuard};
use rustc_data_structures::sync::Lrc;
use rustc_errors::emitter::Emitter;
use rustc_errors::{translation::Translate, DiagCtxt, FatalError, Level};
use rustc_errors::{DiagnosticBuilder, DiagnosticMessage, Style};
use rustc_errors::translation::Translate;
use rustc_errors::{
DiagCtxt, DiagnosticArgName, DiagnosticArgValue, DiagnosticBuilder, DiagnosticMessage, ErrCode,
FatalError, FluentBundle, Level, Style,
};
use rustc_fs_util::link_or_copy;
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc_incremental::{
@ -995,12 +998,10 @@ pub(crate) enum Message<B: WriteBackendMethods> {
/// process another codegen unit.
pub struct CguMessage;
type DiagnosticArgName<'source> = Cow<'source, str>;
struct Diagnostic {
msgs: Vec<(DiagnosticMessage, Style)>,
args: FxHashMap<DiagnosticArgName<'static>, rustc_errors::DiagnosticArgValue<'static>>,
code: Option<String>,
args: FxHashMap<DiagnosticArgName, DiagnosticArgValue>,
code: Option<ErrCode>,
lvl: Level,
}
@ -1800,18 +1801,18 @@ impl SharedEmitter {
}
impl Translate for SharedEmitter {
fn fluent_bundle(&self) -> Option<&Lrc<rustc_errors::FluentBundle>> {
fn fluent_bundle(&self) -> Option<&Lrc<FluentBundle>> {
None
}
fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle {
fn fallback_fluent_bundle(&self) -> &FluentBundle {
panic!("shared emitter attempted to translate a diagnostic");
}
}
impl Emitter for SharedEmitter {
fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) {
let args: FxHashMap<Cow<'_, str>, rustc_errors::DiagnosticArgValue<'_>> =
let args: FxHashMap<Cow<'_, str>, DiagnosticArgValue> =
diag.args().map(|(name, arg)| (name.clone(), arg.clone())).collect();
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
msgs: diag.messages.clone(),

View file

@ -1,6 +1,6 @@
use rustc_ast::{ast, attr, MetaItemKind, NestedMetaItem};
use rustc_attr::{list_contains_name, InlineAttr, InstructionSetAttr, OptimizeAttr};
use rustc_errors::struct_span_code_err;
use rustc_errors::{codes::*, struct_span_code_err};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};

View file

@ -4,7 +4,7 @@ use crate::assert_module_sources::CguReuse;
use crate::back::command::Command;
use crate::fluent_generated as fluent;
use rustc_errors::{
DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic,
codes::*, DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic,
IntoDiagnosticArg, Level,
};
use rustc_macros::Diagnostic;
@ -147,7 +147,7 @@ impl<'a> CopyPath<'a> {
struct DebugArgPath<'a>(pub &'a Path);
impl IntoDiagnosticArg for DebugArgPath<'_> {
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self.0)))
}
}
@ -612,7 +612,7 @@ pub struct UnknownAtomicOperation;
#[derive(Diagnostic)]
pub enum InvalidMonomorphization<'tcx> {
#[diag(codegen_ssa_invalid_monomorphization_basic_integer_type, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_basic_integer_type, code = E0511)]
BasicIntegerType {
#[primary_span]
span: Span,
@ -620,7 +620,7 @@ pub enum InvalidMonomorphization<'tcx> {
ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_basic_float_type, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_basic_float_type, code = E0511)]
BasicFloatType {
#[primary_span]
span: Span,
@ -628,14 +628,14 @@ pub enum InvalidMonomorphization<'tcx> {
ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_float_to_int_unchecked, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_float_to_int_unchecked, code = E0511)]
FloatToIntUnchecked {
#[primary_span]
span: Span,
ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_floating_point_vector, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_floating_point_vector, code = E0511)]
FloatingPointVector {
#[primary_span]
span: Span,
@ -644,7 +644,7 @@ pub enum InvalidMonomorphization<'tcx> {
in_ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_floating_point_type, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_floating_point_type, code = E0511)]
FloatingPointType {
#[primary_span]
span: Span,
@ -652,14 +652,14 @@ pub enum InvalidMonomorphization<'tcx> {
in_ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_unrecognized_intrinsic, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_unrecognized_intrinsic, code = E0511)]
UnrecognizedIntrinsic {
#[primary_span]
span: Span,
name: Symbol,
},
#[diag(codegen_ssa_invalid_monomorphization_simd_argument, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_simd_argument, code = E0511)]
SimdArgument {
#[primary_span]
span: Span,
@ -667,7 +667,7 @@ pub enum InvalidMonomorphization<'tcx> {
ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_simd_input, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_simd_input, code = E0511)]
SimdInput {
#[primary_span]
span: Span,
@ -675,7 +675,7 @@ pub enum InvalidMonomorphization<'tcx> {
ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_simd_first, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_simd_first, code = E0511)]
SimdFirst {
#[primary_span]
span: Span,
@ -683,7 +683,7 @@ pub enum InvalidMonomorphization<'tcx> {
ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_simd_second, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_simd_second, code = E0511)]
SimdSecond {
#[primary_span]
span: Span,
@ -691,7 +691,7 @@ pub enum InvalidMonomorphization<'tcx> {
ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_simd_third, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_simd_third, code = E0511)]
SimdThird {
#[primary_span]
span: Span,
@ -699,7 +699,7 @@ pub enum InvalidMonomorphization<'tcx> {
ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_simd_return, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_simd_return, code = E0511)]
SimdReturn {
#[primary_span]
span: Span,
@ -707,7 +707,7 @@ pub enum InvalidMonomorphization<'tcx> {
ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_invalid_bitmask, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_invalid_bitmask, code = E0511)]
InvalidBitmask {
#[primary_span]
span: Span,
@ -717,7 +717,7 @@ pub enum InvalidMonomorphization<'tcx> {
expected_bytes: u64,
},
#[diag(codegen_ssa_invalid_monomorphization_return_length_input_type, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_return_length_input_type, code = E0511)]
ReturnLengthInputType {
#[primary_span]
span: Span,
@ -728,7 +728,7 @@ pub enum InvalidMonomorphization<'tcx> {
out_len: u64,
},
#[diag(codegen_ssa_invalid_monomorphization_second_argument_length, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_second_argument_length, code = E0511)]
SecondArgumentLength {
#[primary_span]
span: Span,
@ -739,7 +739,7 @@ pub enum InvalidMonomorphization<'tcx> {
out_len: u64,
},
#[diag(codegen_ssa_invalid_monomorphization_third_argument_length, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_third_argument_length, code = E0511)]
ThirdArgumentLength {
#[primary_span]
span: Span,
@ -750,7 +750,7 @@ pub enum InvalidMonomorphization<'tcx> {
out_len: u64,
},
#[diag(codegen_ssa_invalid_monomorphization_return_integer_type, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_return_integer_type, code = E0511)]
ReturnIntegerType {
#[primary_span]
span: Span,
@ -759,7 +759,7 @@ pub enum InvalidMonomorphization<'tcx> {
out_ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_simd_shuffle, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_simd_shuffle, code = E0511)]
SimdShuffle {
#[primary_span]
span: Span,
@ -767,7 +767,7 @@ pub enum InvalidMonomorphization<'tcx> {
ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_return_length, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_return_length, code = E0511)]
ReturnLength {
#[primary_span]
span: Span,
@ -777,7 +777,7 @@ pub enum InvalidMonomorphization<'tcx> {
out_len: u64,
},
#[diag(codegen_ssa_invalid_monomorphization_return_element, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_return_element, code = E0511)]
ReturnElement {
#[primary_span]
span: Span,
@ -788,7 +788,7 @@ pub enum InvalidMonomorphization<'tcx> {
out_ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_shuffle_index_not_constant, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_shuffle_index_not_constant, code = E0511)]
ShuffleIndexNotConstant {
#[primary_span]
span: Span,
@ -796,7 +796,7 @@ pub enum InvalidMonomorphization<'tcx> {
arg_idx: u64,
},
#[diag(codegen_ssa_invalid_monomorphization_shuffle_index_out_of_bounds, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_shuffle_index_out_of_bounds, code = E0511)]
ShuffleIndexOutOfBounds {
#[primary_span]
span: Span,
@ -805,7 +805,7 @@ pub enum InvalidMonomorphization<'tcx> {
total_len: u128,
},
#[diag(codegen_ssa_invalid_monomorphization_inserted_type, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_inserted_type, code = E0511)]
InsertedType {
#[primary_span]
span: Span,
@ -815,7 +815,7 @@ pub enum InvalidMonomorphization<'tcx> {
out_ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_return_type, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_return_type, code = E0511)]
ReturnType {
#[primary_span]
span: Span,
@ -825,7 +825,7 @@ pub enum InvalidMonomorphization<'tcx> {
ret_ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_expected_return_type, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_expected_return_type, code = E0511)]
ExpectedReturnType {
#[primary_span]
span: Span,
@ -834,7 +834,7 @@ pub enum InvalidMonomorphization<'tcx> {
ret_ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_mismatched_lengths, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_mismatched_lengths, code = E0511)]
MismatchedLengths {
#[primary_span]
span: Span,
@ -843,7 +843,7 @@ pub enum InvalidMonomorphization<'tcx> {
v_len: u64,
},
#[diag(codegen_ssa_invalid_monomorphization_mask_type, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_mask_type, code = E0511)]
MaskType {
#[primary_span]
span: Span,
@ -851,7 +851,7 @@ pub enum InvalidMonomorphization<'tcx> {
ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_vector_argument, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_vector_argument, code = E0511)]
VectorArgument {
#[primary_span]
span: Span,
@ -860,7 +860,7 @@ pub enum InvalidMonomorphization<'tcx> {
in_elem: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_cannot_return, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_cannot_return, code = E0511)]
CannotReturn {
#[primary_span]
span: Span,
@ -870,7 +870,7 @@ pub enum InvalidMonomorphization<'tcx> {
expected_bytes: u64,
},
#[diag(codegen_ssa_invalid_monomorphization_expected_element_type, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_expected_element_type, code = E0511)]
ExpectedElementType {
#[primary_span]
span: Span,
@ -882,7 +882,7 @@ pub enum InvalidMonomorphization<'tcx> {
mutability: ExpectedPointerMutability,
},
#[diag(codegen_ssa_invalid_monomorphization_third_arg_element_type, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_third_arg_element_type, code = E0511)]
ThirdArgElementType {
#[primary_span]
span: Span,
@ -891,7 +891,7 @@ pub enum InvalidMonomorphization<'tcx> {
third_arg: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_unsupported_symbol_of_size, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_unsupported_symbol_of_size, code = E0511)]
UnsupportedSymbolOfSize {
#[primary_span]
span: Span,
@ -903,7 +903,7 @@ pub enum InvalidMonomorphization<'tcx> {
ret_ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_unsupported_symbol, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_unsupported_symbol, code = E0511)]
UnsupportedSymbol {
#[primary_span]
span: Span,
@ -914,7 +914,7 @@ pub enum InvalidMonomorphization<'tcx> {
ret_ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_cast_fat_pointer, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_cast_fat_pointer, code = E0511)]
CastFatPointer {
#[primary_span]
span: Span,
@ -922,7 +922,7 @@ pub enum InvalidMonomorphization<'tcx> {
ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_expected_pointer, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_expected_pointer, code = E0511)]
ExpectedPointer {
#[primary_span]
span: Span,
@ -930,7 +930,7 @@ pub enum InvalidMonomorphization<'tcx> {
ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_expected_usize, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_expected_usize, code = E0511)]
ExpectedUsize {
#[primary_span]
span: Span,
@ -938,7 +938,7 @@ pub enum InvalidMonomorphization<'tcx> {
ty: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_unsupported_cast, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_unsupported_cast, code = E0511)]
UnsupportedCast {
#[primary_span]
span: Span,
@ -949,7 +949,7 @@ pub enum InvalidMonomorphization<'tcx> {
out_elem: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_unsupported_operation, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_unsupported_operation, code = E0511)]
UnsupportedOperation {
#[primary_span]
span: Span,
@ -958,7 +958,7 @@ pub enum InvalidMonomorphization<'tcx> {
in_elem: Ty<'tcx>,
},
#[diag(codegen_ssa_invalid_monomorphization_expected_vector_element_type, code = "E0511")]
#[diag(codegen_ssa_invalid_monomorphization_expected_vector_element_type, code = E0511)]
ExpectedVectorElementType {
#[primary_span]
span: Span,
@ -974,7 +974,7 @@ pub enum ExpectedPointerMutability {
}
impl IntoDiagnosticArg for ExpectedPointerMutability {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
match self {
ExpectedPointerMutability::Mut => DiagnosticArgValue::Str(Cow::Borrowed("*mut")),
ExpectedPointerMutability::Not => DiagnosticArgValue::Str(Cow::Borrowed("*_")),

View file

@ -7,10 +7,8 @@
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(negative_impls)]
#![feature(never_type)]
#![feature(strict_provenance)]
#![feature(try_blocks)]
#![recursion_limit = "256"]
//! This crate contains codegen code that is used by all codegen backends (LLVM and others).
//! The backend-agnostic functions of this crate use functions defined in various traits that

View file

@ -34,7 +34,7 @@ impl MachineStopType for ConstEvalErrKind {
}
fn add_args(
self: Box<Self>,
adder: &mut dyn FnMut(std::borrow::Cow<'static, str>, DiagnosticArgValue<'static>),
adder: &mut dyn FnMut(std::borrow::Cow<'static, str>, DiagnosticArgValue),
) {
use ConstEvalErrKind::*;
match *self {

View file

@ -1,8 +1,8 @@
use std::borrow::Cow;
use rustc_errors::{
DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee,
IntoDiagnostic, Level,
codes::*, DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, DiagnosticMessage,
EmissionGuarantee, IntoDiagnostic, Level,
};
use rustc_hir::ConstContext;
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
@ -55,14 +55,14 @@ pub(crate) struct UnstableInStable {
}
#[derive(Diagnostic)]
#[diag(const_eval_thread_local_access, code = "E0625")]
#[diag(const_eval_thread_local_access, code = E0625)]
pub(crate) struct NonConstOpErr {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(const_eval_static_access, code = "E0013")]
#[diag(const_eval_static_access, code = E0013)]
#[help]
pub(crate) struct StaticAccessErr {
#[primary_span]
@ -98,7 +98,7 @@ pub(crate) struct PanicNonStrErr {
}
#[derive(Diagnostic)]
#[diag(const_eval_mut_deref, code = "E0658")]
#[diag(const_eval_mut_deref, code = E0658)]
pub(crate) struct MutDerefErr {
#[primary_span]
pub span: Span,
@ -106,7 +106,7 @@ pub(crate) struct MutDerefErr {
}
#[derive(Diagnostic)]
#[diag(const_eval_transient_mut_borrow, code = "E0658")]
#[diag(const_eval_transient_mut_borrow, code = E0658)]
pub(crate) struct TransientMutBorrowErr {
#[primary_span]
pub span: Span,
@ -114,7 +114,7 @@ pub(crate) struct TransientMutBorrowErr {
}
#[derive(Diagnostic)]
#[diag(const_eval_transient_mut_raw, code = "E0658")]
#[diag(const_eval_transient_mut_raw, code = E0658)]
pub(crate) struct TransientMutRawErr {
#[primary_span]
pub span: Span,
@ -146,7 +146,7 @@ pub(crate) struct UnstableConstFn {
}
#[derive(Diagnostic)]
#[diag(const_eval_unallowed_mutable_refs, code = "E0764")]
#[diag(const_eval_unallowed_mutable_refs, code = E0764)]
pub(crate) struct UnallowedMutableRefs {
#[primary_span]
pub span: Span,
@ -156,7 +156,7 @@ pub(crate) struct UnallowedMutableRefs {
}
#[derive(Diagnostic)]
#[diag(const_eval_unallowed_mutable_raw, code = "E0764")]
#[diag(const_eval_unallowed_mutable_raw, code = E0764)]
pub(crate) struct UnallowedMutableRaw {
#[primary_span]
pub span: Span,
@ -165,7 +165,7 @@ pub(crate) struct UnallowedMutableRaw {
pub teach: Option<()>,
}
#[derive(Diagnostic)]
#[diag(const_eval_non_const_fmt_macro_call, code = "E0015")]
#[diag(const_eval_non_const_fmt_macro_call, code = E0015)]
pub(crate) struct NonConstFmtMacroCall {
#[primary_span]
pub span: Span,
@ -173,7 +173,7 @@ pub(crate) struct NonConstFmtMacroCall {
}
#[derive(Diagnostic)]
#[diag(const_eval_non_const_fn_call, code = "E0015")]
#[diag(const_eval_non_const_fn_call, code = E0015)]
pub(crate) struct NonConstFnCall {
#[primary_span]
pub span: Span,
@ -190,7 +190,7 @@ pub(crate) struct UnallowedOpInConstContext {
}
#[derive(Diagnostic)]
#[diag(const_eval_unallowed_heap_allocations, code = "E0010")]
#[diag(const_eval_unallowed_heap_allocations, code = E0010)]
pub(crate) struct UnallowedHeapAllocations {
#[primary_span]
#[label]
@ -201,7 +201,7 @@ pub(crate) struct UnallowedHeapAllocations {
}
#[derive(Diagnostic)]
#[diag(const_eval_unallowed_inline_asm, code = "E0015")]
#[diag(const_eval_unallowed_inline_asm, code = E0015)]
pub(crate) struct UnallowedInlineAsm {
#[primary_span]
pub span: Span,
@ -209,7 +209,7 @@ pub(crate) struct UnallowedInlineAsm {
}
#[derive(Diagnostic)]
#[diag(const_eval_interior_mutable_data_refer, code = "E0492")]
#[diag(const_eval_interior_mutable_data_refer, code = E0492)]
pub(crate) struct InteriorMutableDataRefer {
#[primary_span]
#[label]
@ -274,7 +274,7 @@ pub struct RawBytesNote {
// FIXME(fee1-dead) do not use stringly typed `ConstContext`
#[derive(Diagnostic)]
#[diag(const_eval_match_eq_non_const, code = "E0015")]
#[diag(const_eval_match_eq_non_const, code = E0015)]
#[note]
pub struct NonConstMatchEq<'tcx> {
#[primary_span]
@ -284,7 +284,7 @@ pub struct NonConstMatchEq<'tcx> {
}
#[derive(Diagnostic)]
#[diag(const_eval_for_loop_into_iter_non_const, code = "E0015")]
#[diag(const_eval_for_loop_into_iter_non_const, code = E0015)]
pub struct NonConstForLoopIntoIter<'tcx> {
#[primary_span]
pub span: Span,
@ -293,7 +293,7 @@ pub struct NonConstForLoopIntoIter<'tcx> {
}
#[derive(Diagnostic)]
#[diag(const_eval_question_branch_non_const, code = "E0015")]
#[diag(const_eval_question_branch_non_const, code = E0015)]
pub struct NonConstQuestionBranch<'tcx> {
#[primary_span]
pub span: Span,
@ -302,7 +302,7 @@ pub struct NonConstQuestionBranch<'tcx> {
}
#[derive(Diagnostic)]
#[diag(const_eval_question_from_residual_non_const, code = "E0015")]
#[diag(const_eval_question_from_residual_non_const, code = E0015)]
pub struct NonConstQuestionFromResidual<'tcx> {
#[primary_span]
pub span: Span,
@ -311,7 +311,7 @@ pub struct NonConstQuestionFromResidual<'tcx> {
}
#[derive(Diagnostic)]
#[diag(const_eval_try_block_from_output_non_const, code = "E0015")]
#[diag(const_eval_try_block_from_output_non_const, code = E0015)]
pub struct NonConstTryBlockFromOutput<'tcx> {
#[primary_span]
pub span: Span,
@ -320,7 +320,7 @@ pub struct NonConstTryBlockFromOutput<'tcx> {
}
#[derive(Diagnostic)]
#[diag(const_eval_await_non_const, code = "E0015")]
#[diag(const_eval_await_non_const, code = E0015)]
pub struct NonConstAwait<'tcx> {
#[primary_span]
pub span: Span,
@ -329,7 +329,7 @@ pub struct NonConstAwait<'tcx> {
}
#[derive(Diagnostic)]
#[diag(const_eval_closure_non_const, code = "E0015")]
#[diag(const_eval_closure_non_const, code = E0015)]
pub struct NonConstClosure {
#[primary_span]
pub span: Span,
@ -362,7 +362,7 @@ pub struct ConsiderDereferencing {
}
#[derive(Diagnostic)]
#[diag(const_eval_operator_non_const, code = "E0015")]
#[diag(const_eval_operator_non_const, code = E0015)]
pub struct NonConstOperator {
#[primary_span]
pub span: Span,
@ -372,7 +372,7 @@ pub struct NonConstOperator {
}
#[derive(Diagnostic)]
#[diag(const_eval_deref_coercion_non_const, code = "E0015")]
#[diag(const_eval_deref_coercion_non_const, code = E0015)]
#[note]
pub struct NonConstDerefCoercion<'tcx> {
#[primary_span]
@ -385,7 +385,7 @@ pub struct NonConstDerefCoercion<'tcx> {
}
#[derive(Diagnostic)]
#[diag(const_eval_live_drop, code = "E0493")]
#[diag(const_eval_live_drop, code = E0493)]
pub struct LiveDrop<'tcx> {
#[primary_span]
#[label]
@ -397,7 +397,7 @@ pub struct LiveDrop<'tcx> {
}
#[derive(Diagnostic)]
#[diag(const_eval_error, code = "E0080")]
#[diag(const_eval_error, code = E0080)]
pub struct ConstEvalError {
#[primary_span]
pub span: Span,
@ -423,7 +423,7 @@ pub struct NullaryIntrinsicError {
}
#[derive(Diagnostic)]
#[diag(const_eval_undefined_behavior, code = "E0080")]
#[diag(const_eval_undefined_behavior, code = E0080)]
pub struct UndefinedBehavior {
#[primary_span]
pub span: Span,
@ -906,7 +906,7 @@ impl ReportErrorExt for ResourceExhaustionInfo {
}
impl rustc_errors::IntoDiagnosticArg for InternKind {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::Borrowed(match self {
InternKind::Static(Mutability::Not) => "static",
InternKind::Static(Mutability::Mut) => "static_mut",

View file

@ -396,7 +396,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
/// to the allocation it points to. Supports both shared and mutable references, as the actual
/// checking is offloaded to a helper closure.
///
/// If this returns `None`, the size is 0; it can however return `Some` even for size 0.
/// Returns `None` if and only if the size is 0.
fn check_and_deref_ptr<T>(
&self,
ptr: Pointer<Option<M::Provenance>>,
@ -1214,10 +1214,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let size_in_bytes = size.bytes_usize();
// For particularly large arrays (where this is perf-sensitive) it's common that
// we're writing a single byte repeatedly. So, optimize that case to a memset.
if size_in_bytes == 1 && num_copies >= 1 {
// SAFETY: `src_bytes` would be read from anyway by copies below (num_copies >= 1).
// Since size_in_bytes = 1, then the `init.no_bytes_init()` check above guarantees
// that this read at type `u8` is OK -- it must be an initialized byte.
if size_in_bytes == 1 {
debug_assert!(num_copies >= 1); // we already handled the zero-sized cases above.
// SAFETY: `src_bytes` would be read from anyway by `copy` below (num_copies >= 1).
let value = *src_bytes;
dest_bytes.write_bytes(value, (size * num_copies).bytes_usize());
} else if src_alloc_id == dest_alloc_id {

View file

@ -260,8 +260,12 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
// This makes several assumptions about what layouts we will encounter; we match what
// codegen does as good as we can (see `extract_field` in `rustc_codegen_ssa/src/mir/operand.rs`).
let inner_val: Immediate<_> = match (**self, self.layout.abi) {
// if the entire value is uninit, then so is the field (can happen in ConstProp)
// If the entire value is uninit, then so is the field (can happen in ConstProp).
(Immediate::Uninit, _) => Immediate::Uninit,
// If the field is uninhabited, we can forget the data (can happen in ConstProp).
// `enum S { A(!), B, C }` is an example of an enum with Scalar layout that
// has an `Uninhabited` variant, which means this case is possible.
_ if layout.abi.is_uninhabited() => Immediate::Uninit,
// the field contains no information, can be left uninit
// (Scalar/ScalarPair can contain even aligned ZST, not just 1-ZST)
_ if layout.is_zst() => Immediate::Uninit,

View file

@ -201,25 +201,8 @@ where
// see https://github.com/rust-lang/rust/issues/93688#issuecomment-1032929496.)
// So we just "offset" by 0.
let layout = base.layout().for_variant(self, variant);
// In the future we might want to allow this to permit code like this:
// (this is a Rust/MIR pseudocode mix)
// ```
// enum Option2 {
// Some(i32, !),
// None,
// }
//
// fn panic() -> ! { panic!() }
//
// let x: Option2;
// x.Some.0 = 42;
// x.Some.1 = panic();
// SetDiscriminant(x, Some);
// ```
// However, for now we don't generate such MIR, and this check here *has* found real
// bugs (see https://github.com/rust-lang/rust/issues/115145), so we will keep rejecting
// it.
assert!(!layout.abi.is_uninhabited());
// This variant may in fact be uninhabited.
// See <https://github.com/rust-lang/rust/issues/120337>.
// This cannot be `transmute` as variants *can* have a smaller size than the entire enum.
base.offset(Size::ZERO, layout, self)

View file

@ -11,20 +11,13 @@ Rust MIR: a lowered representation of Rust.
#![feature(assert_matches)]
#![feature(box_patterns)]
#![feature(decl_macro)]
#![feature(exact_size_is_empty)]
#![feature(let_chains)]
#![feature(map_try_insert)]
#![feature(min_specialization)]
#![feature(slice_ptr_get)]
#![feature(option_get_or_insert_default)]
#![feature(never_type)]
#![feature(trait_alias)]
#![feature(trusted_len)]
#![feature(trusted_step)]
#![feature(try_blocks)]
#![feature(yeet_expr)]
#![feature(if_let_guard)]
#![recursion_limit = "256"]
#[macro_use]
extern crate tracing;

View file

@ -2,7 +2,7 @@
use hir::def_id::LocalDefId;
use hir::{ConstContext, LangItem};
use rustc_errors::{error_code, DiagnosticBuilder};
use rustc_errors::{codes::*, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_infer::infer::TyCtxtInferExt;
@ -372,7 +372,7 @@ impl<'tcx> NonConstOp<'tcx> for HeapAllocation {
ccx.dcx().create_err(errors::UnallowedHeapAllocations {
span,
kind: ccx.const_kind(),
teach: ccx.tcx.sess.teach(&error_code!(E0010)).then_some(()),
teach: ccx.tcx.sess.teach(E0010).then_some(()),
})
}
}
@ -434,14 +434,14 @@ impl<'tcx> NonConstOp<'tcx> for CellBorrow {
span,
opt_help: Some(()),
kind: ccx.const_kind(),
teach: ccx.tcx.sess.teach(&error_code!(E0492)).then_some(()),
teach: ccx.tcx.sess.teach(E0492).then_some(()),
})
} else {
ccx.dcx().create_err(errors::InteriorMutableDataRefer {
span,
opt_help: None,
kind: ccx.const_kind(),
teach: ccx.tcx.sess.teach(&error_code!(E0492)).then_some(()),
teach: ccx.tcx.sess.teach(E0492).then_some(()),
})
}
}
@ -469,12 +469,12 @@ impl<'tcx> NonConstOp<'tcx> for MutBorrow {
hir::BorrowKind::Raw => ccx.tcx.dcx().create_err(errors::UnallowedMutableRaw {
span,
kind: ccx.const_kind(),
teach: ccx.tcx.sess.teach(&error_code!(E0764)).then_some(()),
teach: ccx.tcx.sess.teach(E0764).then_some(()),
}),
hir::BorrowKind::Ref => ccx.dcx().create_err(errors::UnallowedMutableRefs {
span,
kind: ccx.const_kind(),
teach: ccx.tcx.sess.teach(&error_code!(E0764)).then_some(()),
teach: ccx.tcx.sess.teach(E0764).then_some(()),
}),
}
}
@ -588,7 +588,7 @@ impl<'tcx> NonConstOp<'tcx> for StaticAccess {
ccx.dcx().create_err(errors::StaticAccessErr {
span,
kind: ccx.const_kind(),
teach: ccx.tcx.sess.teach(&error_code!(E0013)).then_some(()),
teach: ccx.tcx.sess.teach(E0013).then_some(()),
})
}
}

View file

@ -810,13 +810,18 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
let adt_def = self.tcx.adt_def(def_id);
assert!(adt_def.is_union());
assert_eq!(idx, FIRST_VARIANT);
let dest = adt_def.non_enum_variant().fields[field].ty(self.tcx, args);
if fields.len() != 1 {
let dest_ty = self.tcx.normalize_erasing_regions(
self.param_env,
adt_def.non_enum_variant().fields[field].ty(self.tcx, args),
);
if fields.len() == 1 {
let src_ty = fields.raw[0].ty(self.body, self.tcx);
if !self.mir_assign_valid_types(src_ty, dest_ty) {
self.fail(location, "union field has the wrong type");
}
} else {
self.fail(location, "unions should have one initialized field");
}
if !self.mir_assign_valid_types(fields.raw[0].ty(self.body, self.tcx), dest) {
self.fail(location, "union field has the wrong type");
}
}
AggregateKind::Adt(def_id, idx, args, _, None) => {
let adt_def = self.tcx.adt_def(def_id);
@ -826,10 +831,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
self.fail(location, "adt has the wrong number of initialized fields");
}
for (src, dest) in std::iter::zip(fields, &variant.fields) {
if !self.mir_assign_valid_types(
src.ty(self.body, self.tcx),
dest.ty(self.tcx, args),
) {
let dest_ty = self
.tcx
.normalize_erasing_regions(self.param_env, dest.ty(self.tcx, args));
if !self.mir_assign_valid_types(src.ty(self.body, self.tcx), dest_ty) {
self.fail(location, "adt field has the wrong type");
}
}

View file

@ -10,6 +10,7 @@
#![allow(internal_features)]
#![allow(rustc::default_hash_types)]
#![allow(rustc::potential_query_instability)]
#![cfg_attr(not(parallel_compiler), feature(cell_leak))]
#![deny(rustc::diagnostic_outside_of_impl)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(unsafe_op_in_unsafe_fn)]
@ -18,7 +19,6 @@
#![feature(allocator_api)]
#![feature(array_windows)]
#![feature(auto_traits)]
#![feature(cell_leak)]
#![feature(cfg_match)]
#![feature(core_intrinsics)]
#![feature(extend_one)]

View file

@ -15,7 +15,6 @@ rustc_builtin_macros = { path = "../rustc_builtin_macros" }
rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }
rustc_const_eval = { path = "../rustc_const_eval" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_error_codes = { path = "../rustc_error_codes" }
rustc_errors = { path = "../rustc_errors" }
rustc_expand = { path = "../rustc_expand" }
rustc_feature = { path = "../rustc_feature" }

View file

@ -9,11 +9,9 @@
#![feature(rustdoc_internals)]
#![allow(internal_features)]
#![feature(decl_macro)]
#![feature(lazy_cell)]
#![feature(let_chains)]
#![feature(panic_update_hook)]
#![feature(result_flattening)]
#![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
@ -25,9 +23,8 @@ use rustc_codegen_ssa::{traits::CodegenBackend, CodegenErrors, CodegenResults};
use rustc_data_structures::profiling::{
get_resident_set_size, print_time_passes_entry, TimePassesFormat,
};
use rustc_errors::registry::{InvalidErrorCode, Registry};
use rustc_errors::{markdown, ColorConfig};
use rustc_errors::{DiagCtxt, ErrorGuaranteed, PResult};
use rustc_errors::registry::Registry;
use rustc_errors::{markdown, ColorConfig, DiagCtxt, ErrCode, ErrorGuaranteed, PResult};
use rustc_feature::find_gated_cfg;
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
use rustc_interface::{interface, Queries};
@ -209,7 +206,7 @@ impl Callbacks for TimePassesCallbacks {
}
pub fn diagnostics_registry() -> Registry {
Registry::new(rustc_error_codes::DIAGNOSTICS)
Registry::new(rustc_errors::codes::DIAGNOSTICS)
}
/// This is the primary entry point for rustc.
@ -537,37 +534,36 @@ pub enum Compilation {
}
fn handle_explain(early_dcx: &EarlyDiagCtxt, registry: Registry, code: &str, color: ColorConfig) {
// Allow "E0123" or "0123" form.
let upper_cased_code = code.to_ascii_uppercase();
let normalised =
if upper_cased_code.starts_with('E') { upper_cased_code } else { format!("E{code:0>4}") };
match registry.try_find_description(&normalised) {
Ok(description) => {
let mut is_in_code_block = false;
let mut text = String::new();
// Slice off the leading newline and print.
for line in description.lines() {
let indent_level =
line.find(|c: char| !c.is_whitespace()).unwrap_or_else(|| line.len());
let dedented_line = &line[indent_level..];
if dedented_line.starts_with("```") {
is_in_code_block = !is_in_code_block;
text.push_str(&line[..(indent_level + 3)]);
} else if is_in_code_block && dedented_line.starts_with("# ") {
continue;
} else {
text.push_str(line);
}
text.push('\n');
}
if io::stdout().is_terminal() {
show_md_content_with_pager(&text, color);
let start = if upper_cased_code.starts_with('E') { 1 } else { 0 };
if let Ok(code) = upper_cased_code[start..].parse::<u32>()
&& let Ok(description) = registry.try_find_description(ErrCode::from_u32(code))
{
let mut is_in_code_block = false;
let mut text = String::new();
// Slice off the leading newline and print.
for line in description.lines() {
let indent_level =
line.find(|c: char| !c.is_whitespace()).unwrap_or_else(|| line.len());
let dedented_line = &line[indent_level..];
if dedented_line.starts_with("```") {
is_in_code_block = !is_in_code_block;
text.push_str(&line[..(indent_level + 3)]);
} else if is_in_code_block && dedented_line.starts_with("# ") {
continue;
} else {
safe_print!("{text}");
text.push_str(line);
}
text.push('\n');
}
Err(InvalidErrorCode) => {
early_dcx.early_fatal(format!("{code} is not a valid error code"));
if io::stdout().is_terminal() {
show_md_content_with_pager(&text, color);
} else {
safe_print!("{text}");
}
} else {
early_dcx.early_fatal(format!("{code} is not a valid error code"));
}
}

View file

@ -1,658 +0,0 @@
// Error messages for EXXXX errors. Each message should start and end with a
// new line, and be wrapped to 80 characters. In vim you can `:set tw=80` and
// use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
//
// /!\ IMPORTANT /!\
//
// Error messages' format must follow the RFC 1567 available here:
// https://rust-lang.github.io/rfcs/1567-long-error-codes-explanation-normalization.html
register_diagnostics! {
E0001: include_str!("./error_codes/E0001.md"),
E0002: include_str!("./error_codes/E0002.md"),
E0004: include_str!("./error_codes/E0004.md"),
E0005: include_str!("./error_codes/E0005.md"),
E0007: include_str!("./error_codes/E0007.md"),
E0009: include_str!("./error_codes/E0009.md"),
E0010: include_str!("./error_codes/E0010.md"),
E0013: include_str!("./error_codes/E0013.md"),
E0014: include_str!("./error_codes/E0014.md"),
E0015: include_str!("./error_codes/E0015.md"),
E0023: include_str!("./error_codes/E0023.md"),
E0025: include_str!("./error_codes/E0025.md"),
E0026: include_str!("./error_codes/E0026.md"),
E0027: include_str!("./error_codes/E0027.md"),
E0029: include_str!("./error_codes/E0029.md"),
E0030: include_str!("./error_codes/E0030.md"),
E0033: include_str!("./error_codes/E0033.md"),
E0034: include_str!("./error_codes/E0034.md"),
E0038: include_str!("./error_codes/E0038.md"),
E0040: include_str!("./error_codes/E0040.md"),
E0044: include_str!("./error_codes/E0044.md"),
E0045: include_str!("./error_codes/E0045.md"),
E0046: include_str!("./error_codes/E0046.md"),
E0049: include_str!("./error_codes/E0049.md"),
E0050: include_str!("./error_codes/E0050.md"),
E0053: include_str!("./error_codes/E0053.md"),
E0054: include_str!("./error_codes/E0054.md"),
E0055: include_str!("./error_codes/E0055.md"),
E0057: include_str!("./error_codes/E0057.md"),
E0059: include_str!("./error_codes/E0059.md"),
E0060: include_str!("./error_codes/E0060.md"),
E0061: include_str!("./error_codes/E0061.md"),
E0062: include_str!("./error_codes/E0062.md"),
E0063: include_str!("./error_codes/E0063.md"),
E0067: include_str!("./error_codes/E0067.md"),
E0069: include_str!("./error_codes/E0069.md"),
E0070: include_str!("./error_codes/E0070.md"),
E0071: include_str!("./error_codes/E0071.md"),
E0072: include_str!("./error_codes/E0072.md"),
E0073: include_str!("./error_codes/E0073.md"),
E0074: include_str!("./error_codes/E0074.md"),
E0075: include_str!("./error_codes/E0075.md"),
E0076: include_str!("./error_codes/E0076.md"),
E0077: include_str!("./error_codes/E0077.md"),
E0080: include_str!("./error_codes/E0080.md"),
E0081: include_str!("./error_codes/E0081.md"),
E0084: include_str!("./error_codes/E0084.md"),
E0087: include_str!("./error_codes/E0087.md"),
E0088: include_str!("./error_codes/E0088.md"),
E0089: include_str!("./error_codes/E0089.md"),
E0090: include_str!("./error_codes/E0090.md"),
E0091: include_str!("./error_codes/E0091.md"),
E0092: include_str!("./error_codes/E0092.md"),
E0093: include_str!("./error_codes/E0093.md"),
E0094: include_str!("./error_codes/E0094.md"),
E0106: include_str!("./error_codes/E0106.md"),
E0107: include_str!("./error_codes/E0107.md"),
E0109: include_str!("./error_codes/E0109.md"),
E0110: include_str!("./error_codes/E0110.md"),
E0116: include_str!("./error_codes/E0116.md"),
E0117: include_str!("./error_codes/E0117.md"),
E0118: include_str!("./error_codes/E0118.md"),
E0119: include_str!("./error_codes/E0119.md"),
E0120: include_str!("./error_codes/E0120.md"),
E0121: include_str!("./error_codes/E0121.md"),
E0124: include_str!("./error_codes/E0124.md"),
E0128: include_str!("./error_codes/E0128.md"),
E0130: include_str!("./error_codes/E0130.md"),
E0131: include_str!("./error_codes/E0131.md"),
E0132: include_str!("./error_codes/E0132.md"),
E0133: include_str!("./error_codes/E0133.md"),
E0136: include_str!("./error_codes/E0136.md"),
E0137: include_str!("./error_codes/E0137.md"),
E0138: include_str!("./error_codes/E0138.md"),
E0139: include_str!("./error_codes/E0139.md"),
E0152: include_str!("./error_codes/E0152.md"),
E0154: include_str!("./error_codes/E0154.md"),
E0158: include_str!("./error_codes/E0158.md"),
E0161: include_str!("./error_codes/E0161.md"),
E0162: include_str!("./error_codes/E0162.md"),
E0164: include_str!("./error_codes/E0164.md"),
E0165: include_str!("./error_codes/E0165.md"),
E0170: include_str!("./error_codes/E0170.md"),
E0178: include_str!("./error_codes/E0178.md"),
E0183: include_str!("./error_codes/E0183.md"),
E0184: include_str!("./error_codes/E0184.md"),
E0185: include_str!("./error_codes/E0185.md"),
E0186: include_str!("./error_codes/E0186.md"),
E0191: include_str!("./error_codes/E0191.md"),
E0192: include_str!("./error_codes/E0192.md"),
E0193: include_str!("./error_codes/E0193.md"),
E0195: include_str!("./error_codes/E0195.md"),
E0197: include_str!("./error_codes/E0197.md"),
E0198: include_str!("./error_codes/E0198.md"),
E0199: include_str!("./error_codes/E0199.md"),
E0200: include_str!("./error_codes/E0200.md"),
E0201: include_str!("./error_codes/E0201.md"),
E0203: include_str!("./error_codes/E0203.md"),
E0204: include_str!("./error_codes/E0204.md"),
E0205: include_str!("./error_codes/E0205.md"),
E0206: include_str!("./error_codes/E0206.md"),
E0207: include_str!("./error_codes/E0207.md"),
E0208: include_str!("./error_codes/E0208.md"),
E0210: include_str!("./error_codes/E0210.md"),
E0211: include_str!("./error_codes/E0211.md"),
E0212: include_str!("./error_codes/E0212.md"),
E0214: include_str!("./error_codes/E0214.md"),
E0220: include_str!("./error_codes/E0220.md"),
E0221: include_str!("./error_codes/E0221.md"),
E0222: include_str!("./error_codes/E0222.md"),
E0223: include_str!("./error_codes/E0223.md"),
E0224: include_str!("./error_codes/E0224.md"),
E0225: include_str!("./error_codes/E0225.md"),
E0226: include_str!("./error_codes/E0226.md"),
E0227: include_str!("./error_codes/E0227.md"),
E0228: include_str!("./error_codes/E0228.md"),
E0229: include_str!("./error_codes/E0229.md"),
E0230: include_str!("./error_codes/E0230.md"),
E0231: include_str!("./error_codes/E0231.md"),
E0232: include_str!("./error_codes/E0232.md"),
E0243: include_str!("./error_codes/E0243.md"),
E0244: include_str!("./error_codes/E0244.md"),
E0251: include_str!("./error_codes/E0251.md"),
E0252: include_str!("./error_codes/E0252.md"),
E0253: include_str!("./error_codes/E0253.md"),
E0254: include_str!("./error_codes/E0254.md"),
E0255: include_str!("./error_codes/E0255.md"),
E0256: include_str!("./error_codes/E0256.md"),
E0259: include_str!("./error_codes/E0259.md"),
E0260: include_str!("./error_codes/E0260.md"),
E0261: include_str!("./error_codes/E0261.md"),
E0262: include_str!("./error_codes/E0262.md"),
E0263: include_str!("./error_codes/E0263.md"),
E0264: include_str!("./error_codes/E0264.md"),
E0267: include_str!("./error_codes/E0267.md"),
E0268: include_str!("./error_codes/E0268.md"),
E0271: include_str!("./error_codes/E0271.md"),
E0275: include_str!("./error_codes/E0275.md"),
E0276: include_str!("./error_codes/E0276.md"),
E0277: include_str!("./error_codes/E0277.md"),
E0281: include_str!("./error_codes/E0281.md"),
E0282: include_str!("./error_codes/E0282.md"),
E0283: include_str!("./error_codes/E0283.md"),
E0284: include_str!("./error_codes/E0284.md"),
E0297: include_str!("./error_codes/E0297.md"),
E0301: include_str!("./error_codes/E0301.md"),
E0302: include_str!("./error_codes/E0302.md"),
E0303: include_str!("./error_codes/E0303.md"),
E0307: include_str!("./error_codes/E0307.md"),
E0308: include_str!("./error_codes/E0308.md"),
E0309: include_str!("./error_codes/E0309.md"),
E0310: include_str!("./error_codes/E0310.md"),
E0311: include_str!("./error_codes/E0311.md"),
E0312: include_str!("./error_codes/E0312.md"),
E0316: include_str!("./error_codes/E0316.md"),
E0317: include_str!("./error_codes/E0317.md"),
E0320: include_str!("./error_codes/E0320.md"),
E0321: include_str!("./error_codes/E0321.md"),
E0322: include_str!("./error_codes/E0322.md"),
E0323: include_str!("./error_codes/E0323.md"),
E0324: include_str!("./error_codes/E0324.md"),
E0325: include_str!("./error_codes/E0325.md"),
E0326: include_str!("./error_codes/E0326.md"),
E0328: include_str!("./error_codes/E0328.md"),
E0329: include_str!("./error_codes/E0329.md"),
E0364: include_str!("./error_codes/E0364.md"),
E0365: include_str!("./error_codes/E0365.md"),
E0366: include_str!("./error_codes/E0366.md"),
E0367: include_str!("./error_codes/E0367.md"),
E0368: include_str!("./error_codes/E0368.md"),
E0369: include_str!("./error_codes/E0369.md"),
E0370: include_str!("./error_codes/E0370.md"),
E0371: include_str!("./error_codes/E0371.md"),
E0373: include_str!("./error_codes/E0373.md"),
E0374: include_str!("./error_codes/E0374.md"),
E0375: include_str!("./error_codes/E0375.md"),
E0376: include_str!("./error_codes/E0376.md"),
E0377: include_str!("./error_codes/E0377.md"),
E0378: include_str!("./error_codes/E0378.md"),
E0379: include_str!("./error_codes/E0379.md"),
E0380: include_str!("./error_codes/E0380.md"),
E0381: include_str!("./error_codes/E0381.md"),
E0382: include_str!("./error_codes/E0382.md"),
E0383: include_str!("./error_codes/E0383.md"),
E0384: include_str!("./error_codes/E0384.md"),
E0386: include_str!("./error_codes/E0386.md"),
E0387: include_str!("./error_codes/E0387.md"),
E0388: include_str!("./error_codes/E0388.md"),
E0389: include_str!("./error_codes/E0389.md"),
E0390: include_str!("./error_codes/E0390.md"),
E0391: include_str!("./error_codes/E0391.md"),
E0392: include_str!("./error_codes/E0392.md"),
E0393: include_str!("./error_codes/E0393.md"),
E0398: include_str!("./error_codes/E0398.md"),
E0399: include_str!("./error_codes/E0399.md"),
E0401: include_str!("./error_codes/E0401.md"),
E0403: include_str!("./error_codes/E0403.md"),
E0404: include_str!("./error_codes/E0404.md"),
E0405: include_str!("./error_codes/E0405.md"),
E0407: include_str!("./error_codes/E0407.md"),
E0408: include_str!("./error_codes/E0408.md"),
E0409: include_str!("./error_codes/E0409.md"),
E0411: include_str!("./error_codes/E0411.md"),
E0412: include_str!("./error_codes/E0412.md"),
E0415: include_str!("./error_codes/E0415.md"),
E0416: include_str!("./error_codes/E0416.md"),
E0422: include_str!("./error_codes/E0422.md"),
E0423: include_str!("./error_codes/E0423.md"),
E0424: include_str!("./error_codes/E0424.md"),
E0425: include_str!("./error_codes/E0425.md"),
E0426: include_str!("./error_codes/E0426.md"),
E0428: include_str!("./error_codes/E0428.md"),
E0429: include_str!("./error_codes/E0429.md"),
E0430: include_str!("./error_codes/E0430.md"),
E0431: include_str!("./error_codes/E0431.md"),
E0432: include_str!("./error_codes/E0432.md"),
E0433: include_str!("./error_codes/E0433.md"),
E0434: include_str!("./error_codes/E0434.md"),
E0435: include_str!("./error_codes/E0435.md"),
E0436: include_str!("./error_codes/E0436.md"),
E0437: include_str!("./error_codes/E0437.md"),
E0438: include_str!("./error_codes/E0438.md"),
E0439: include_str!("./error_codes/E0439.md"),
E0445: include_str!("./error_codes/E0445.md"),
E0446: include_str!("./error_codes/E0446.md"),
E0447: include_str!("./error_codes/E0447.md"),
E0448: include_str!("./error_codes/E0448.md"),
E0449: include_str!("./error_codes/E0449.md"),
E0451: include_str!("./error_codes/E0451.md"),
E0452: include_str!("./error_codes/E0452.md"),
E0453: include_str!("./error_codes/E0453.md"),
E0454: include_str!("./error_codes/E0454.md"),
E0455: include_str!("./error_codes/E0455.md"),
E0457: include_str!("./error_codes/E0457.md"),
E0458: include_str!("./error_codes/E0458.md"),
E0459: include_str!("./error_codes/E0459.md"),
E0460: include_str!("./error_codes/E0460.md"),
E0461: include_str!("./error_codes/E0461.md"),
E0462: include_str!("./error_codes/E0462.md"),
E0463: include_str!("./error_codes/E0463.md"),
E0464: include_str!("./error_codes/E0464.md"),
E0466: include_str!("./error_codes/E0466.md"),
E0468: include_str!("./error_codes/E0468.md"),
E0469: include_str!("./error_codes/E0469.md"),
E0472: include_str!("./error_codes/E0472.md"),
E0476: include_str!("./error_codes/E0476.md"),
E0477: include_str!("./error_codes/E0477.md"),
E0478: include_str!("./error_codes/E0478.md"),
E0482: include_str!("./error_codes/E0482.md"),
E0491: include_str!("./error_codes/E0491.md"),
E0492: include_str!("./error_codes/E0492.md"),
E0493: include_str!("./error_codes/E0493.md"),
E0495: include_str!("./error_codes/E0495.md"),
E0496: include_str!("./error_codes/E0496.md"),
E0497: include_str!("./error_codes/E0497.md"),
E0498: include_str!("./error_codes/E0498.md"),
E0499: include_str!("./error_codes/E0499.md"),
E0500: include_str!("./error_codes/E0500.md"),
E0501: include_str!("./error_codes/E0501.md"),
E0502: include_str!("./error_codes/E0502.md"),
E0503: include_str!("./error_codes/E0503.md"),
E0504: include_str!("./error_codes/E0504.md"),
E0505: include_str!("./error_codes/E0505.md"),
E0506: include_str!("./error_codes/E0506.md"),
E0507: include_str!("./error_codes/E0507.md"),
E0508: include_str!("./error_codes/E0508.md"),
E0509: include_str!("./error_codes/E0509.md"),
E0510: include_str!("./error_codes/E0510.md"),
E0511: include_str!("./error_codes/E0511.md"),
E0512: include_str!("./error_codes/E0512.md"),
E0514: include_str!("./error_codes/E0514.md"),
E0515: include_str!("./error_codes/E0515.md"),
E0516: include_str!("./error_codes/E0516.md"),
E0517: include_str!("./error_codes/E0517.md"),
E0518: include_str!("./error_codes/E0518.md"),
E0519: include_str!("./error_codes/E0519.md"),
E0520: include_str!("./error_codes/E0520.md"),
E0521: include_str!("./error_codes/E0521.md"),
E0522: include_str!("./error_codes/E0522.md"),
E0523: include_str!("./error_codes/E0523.md"),
E0524: include_str!("./error_codes/E0524.md"),
E0525: include_str!("./error_codes/E0525.md"),
E0527: include_str!("./error_codes/E0527.md"),
E0528: include_str!("./error_codes/E0528.md"),
E0529: include_str!("./error_codes/E0529.md"),
E0530: include_str!("./error_codes/E0530.md"),
E0531: include_str!("./error_codes/E0531.md"),
E0532: include_str!("./error_codes/E0532.md"),
E0533: include_str!("./error_codes/E0533.md"),
E0534: include_str!("./error_codes/E0534.md"),
E0535: include_str!("./error_codes/E0535.md"),
E0536: include_str!("./error_codes/E0536.md"),
E0537: include_str!("./error_codes/E0537.md"),
E0538: include_str!("./error_codes/E0538.md"),
E0539: include_str!("./error_codes/E0539.md"),
E0541: include_str!("./error_codes/E0541.md"),
E0542: include_str!("./error_codes/E0542.md"),
E0543: include_str!("./error_codes/E0543.md"),
E0544: include_str!("./error_codes/E0544.md"),
E0545: include_str!("./error_codes/E0545.md"),
E0546: include_str!("./error_codes/E0546.md"),
E0547: include_str!("./error_codes/E0547.md"),
E0549: include_str!("./error_codes/E0549.md"),
E0550: include_str!("./error_codes/E0550.md"),
E0551: include_str!("./error_codes/E0551.md"),
E0552: include_str!("./error_codes/E0552.md"),
E0554: include_str!("./error_codes/E0554.md"),
E0556: include_str!("./error_codes/E0556.md"),
E0557: include_str!("./error_codes/E0557.md"),
E0559: include_str!("./error_codes/E0559.md"),
E0560: include_str!("./error_codes/E0560.md"),
E0561: include_str!("./error_codes/E0561.md"),
E0562: include_str!("./error_codes/E0562.md"),
E0565: include_str!("./error_codes/E0565.md"),
E0566: include_str!("./error_codes/E0566.md"),
E0567: include_str!("./error_codes/E0567.md"),
E0568: include_str!("./error_codes/E0568.md"),
E0569: include_str!("./error_codes/E0569.md"),
E0570: include_str!("./error_codes/E0570.md"),
E0571: include_str!("./error_codes/E0571.md"),
E0572: include_str!("./error_codes/E0572.md"),
E0573: include_str!("./error_codes/E0573.md"),
E0574: include_str!("./error_codes/E0574.md"),
E0575: include_str!("./error_codes/E0575.md"),
E0576: include_str!("./error_codes/E0576.md"),
E0577: include_str!("./error_codes/E0577.md"),
E0578: include_str!("./error_codes/E0578.md"),
E0579: include_str!("./error_codes/E0579.md"),
E0580: include_str!("./error_codes/E0580.md"),
E0581: include_str!("./error_codes/E0581.md"),
E0582: include_str!("./error_codes/E0582.md"),
E0583: include_str!("./error_codes/E0583.md"),
E0584: include_str!("./error_codes/E0584.md"),
E0585: include_str!("./error_codes/E0585.md"),
E0586: include_str!("./error_codes/E0586.md"),
E0587: include_str!("./error_codes/E0587.md"),
E0588: include_str!("./error_codes/E0588.md"),
E0589: include_str!("./error_codes/E0589.md"),
E0590: include_str!("./error_codes/E0590.md"),
E0591: include_str!("./error_codes/E0591.md"),
E0592: include_str!("./error_codes/E0592.md"),
E0593: include_str!("./error_codes/E0593.md"),
E0594: include_str!("./error_codes/E0594.md"),
E0595: include_str!("./error_codes/E0595.md"),
E0596: include_str!("./error_codes/E0596.md"),
E0597: include_str!("./error_codes/E0597.md"),
E0599: include_str!("./error_codes/E0599.md"),
E0600: include_str!("./error_codes/E0600.md"),
E0601: include_str!("./error_codes/E0601.md"),
E0602: include_str!("./error_codes/E0602.md"),
E0603: include_str!("./error_codes/E0603.md"),
E0604: include_str!("./error_codes/E0604.md"),
E0605: include_str!("./error_codes/E0605.md"),
E0606: include_str!("./error_codes/E0606.md"),
E0607: include_str!("./error_codes/E0607.md"),
E0608: include_str!("./error_codes/E0608.md"),
E0609: include_str!("./error_codes/E0609.md"),
E0610: include_str!("./error_codes/E0610.md"),
E0614: include_str!("./error_codes/E0614.md"),
E0615: include_str!("./error_codes/E0615.md"),
E0616: include_str!("./error_codes/E0616.md"),
E0617: include_str!("./error_codes/E0617.md"),
E0618: include_str!("./error_codes/E0618.md"),
E0619: include_str!("./error_codes/E0619.md"),
E0620: include_str!("./error_codes/E0620.md"),
E0621: include_str!("./error_codes/E0621.md"),
E0622: include_str!("./error_codes/E0622.md"),
E0623: include_str!("./error_codes/E0623.md"),
E0624: include_str!("./error_codes/E0624.md"),
E0625: include_str!("./error_codes/E0625.md"),
E0626: include_str!("./error_codes/E0626.md"),
E0627: include_str!("./error_codes/E0627.md"),
E0628: include_str!("./error_codes/E0628.md"),
E0631: include_str!("./error_codes/E0631.md"),
E0632: include_str!("./error_codes/E0632.md"),
E0633: include_str!("./error_codes/E0633.md"),
E0634: include_str!("./error_codes/E0634.md"),
E0635: include_str!("./error_codes/E0635.md"),
E0636: include_str!("./error_codes/E0636.md"),
E0637: include_str!("./error_codes/E0637.md"),
E0638: include_str!("./error_codes/E0638.md"),
E0639: include_str!("./error_codes/E0639.md"),
E0640: include_str!("./error_codes/E0640.md"),
E0641: include_str!("./error_codes/E0641.md"),
E0642: include_str!("./error_codes/E0642.md"),
E0643: include_str!("./error_codes/E0643.md"),
E0644: include_str!("./error_codes/E0644.md"),
E0646: include_str!("./error_codes/E0646.md"),
E0647: include_str!("./error_codes/E0647.md"),
E0648: include_str!("./error_codes/E0648.md"),
E0657: include_str!("./error_codes/E0657.md"),
E0658: include_str!("./error_codes/E0658.md"),
E0659: include_str!("./error_codes/E0659.md"),
E0660: include_str!("./error_codes/E0660.md"),
E0661: include_str!("./error_codes/E0661.md"),
E0662: include_str!("./error_codes/E0662.md"),
E0663: include_str!("./error_codes/E0663.md"),
E0664: include_str!("./error_codes/E0664.md"),
E0665: include_str!("./error_codes/E0665.md"),
E0666: include_str!("./error_codes/E0666.md"),
E0667: include_str!("./error_codes/E0667.md"),
E0668: include_str!("./error_codes/E0668.md"),
E0669: include_str!("./error_codes/E0669.md"),
E0670: include_str!("./error_codes/E0670.md"),
E0671: include_str!("./error_codes/E0671.md"),
E0687: include_str!("./error_codes/E0687.md"),
E0688: include_str!("./error_codes/E0688.md"),
E0689: include_str!("./error_codes/E0689.md"),
E0690: include_str!("./error_codes/E0690.md"),
E0691: include_str!("./error_codes/E0691.md"),
E0692: include_str!("./error_codes/E0692.md"),
E0693: include_str!("./error_codes/E0693.md"),
E0695: include_str!("./error_codes/E0695.md"),
E0696: include_str!("./error_codes/E0696.md"),
E0697: include_str!("./error_codes/E0697.md"),
E0698: include_str!("./error_codes/E0698.md"),
E0699: include_str!("./error_codes/E0699.md"),
E0700: include_str!("./error_codes/E0700.md"),
E0701: include_str!("./error_codes/E0701.md"),
E0703: include_str!("./error_codes/E0703.md"),
E0704: include_str!("./error_codes/E0704.md"),
E0705: include_str!("./error_codes/E0705.md"),
E0706: include_str!("./error_codes/E0706.md"),
E0708: include_str!("./error_codes/E0708.md"),
E0710: include_str!("./error_codes/E0710.md"),
E0712: include_str!("./error_codes/E0712.md"),
E0713: include_str!("./error_codes/E0713.md"),
E0714: include_str!("./error_codes/E0714.md"),
E0715: include_str!("./error_codes/E0715.md"),
E0716: include_str!("./error_codes/E0716.md"),
E0711: include_str!("./error_codes/E0711.md"),
E0717: include_str!("./error_codes/E0717.md"),
E0718: include_str!("./error_codes/E0718.md"),
E0719: include_str!("./error_codes/E0719.md"),
E0720: include_str!("./error_codes/E0720.md"),
E0722: include_str!("./error_codes/E0722.md"),
E0724: include_str!("./error_codes/E0724.md"),
E0725: include_str!("./error_codes/E0725.md"),
E0726: include_str!("./error_codes/E0726.md"),
E0727: include_str!("./error_codes/E0727.md"),
E0728: include_str!("./error_codes/E0728.md"),
E0729: include_str!("./error_codes/E0729.md"),
E0730: include_str!("./error_codes/E0730.md"),
E0731: include_str!("./error_codes/E0731.md"),
E0732: include_str!("./error_codes/E0732.md"),
E0733: include_str!("./error_codes/E0733.md"),
E0734: include_str!("./error_codes/E0734.md"),
E0735: include_str!("./error_codes/E0735.md"),
E0736: include_str!("./error_codes/E0736.md"),
E0737: include_str!("./error_codes/E0737.md"),
E0739: include_str!("./error_codes/E0739.md"),
E0740: include_str!("./error_codes/E0740.md"),
E0741: include_str!("./error_codes/E0741.md"),
E0742: include_str!("./error_codes/E0742.md"),
E0743: include_str!("./error_codes/E0743.md"),
E0744: include_str!("./error_codes/E0744.md"),
E0745: include_str!("./error_codes/E0745.md"),
E0746: include_str!("./error_codes/E0746.md"),
E0747: include_str!("./error_codes/E0747.md"),
E0748: include_str!("./error_codes/E0748.md"),
E0749: include_str!("./error_codes/E0749.md"),
E0750: include_str!("./error_codes/E0750.md"),
E0751: include_str!("./error_codes/E0751.md"),
E0752: include_str!("./error_codes/E0752.md"),
E0753: include_str!("./error_codes/E0753.md"),
E0754: include_str!("./error_codes/E0754.md"),
E0755: include_str!("./error_codes/E0755.md"),
E0756: include_str!("./error_codes/E0756.md"),
E0757: include_str!("./error_codes/E0757.md"),
E0758: include_str!("./error_codes/E0758.md"),
E0759: include_str!("./error_codes/E0759.md"),
E0760: include_str!("./error_codes/E0760.md"),
E0761: include_str!("./error_codes/E0761.md"),
E0762: include_str!("./error_codes/E0762.md"),
E0763: include_str!("./error_codes/E0763.md"),
E0764: include_str!("./error_codes/E0764.md"),
E0765: include_str!("./error_codes/E0765.md"),
E0766: include_str!("./error_codes/E0766.md"),
E0767: include_str!("./error_codes/E0767.md"),
E0768: include_str!("./error_codes/E0768.md"),
E0769: include_str!("./error_codes/E0769.md"),
E0770: include_str!("./error_codes/E0770.md"),
E0771: include_str!("./error_codes/E0771.md"),
E0772: include_str!("./error_codes/E0772.md"),
E0773: include_str!("./error_codes/E0773.md"),
E0774: include_str!("./error_codes/E0774.md"),
E0775: include_str!("./error_codes/E0775.md"),
E0776: include_str!("./error_codes/E0776.md"),
E0777: include_str!("./error_codes/E0777.md"),
E0778: include_str!("./error_codes/E0778.md"),
E0779: include_str!("./error_codes/E0779.md"),
E0780: include_str!("./error_codes/E0780.md"),
E0781: include_str!("./error_codes/E0781.md"),
E0782: include_str!("./error_codes/E0782.md"),
E0783: include_str!("./error_codes/E0783.md"),
E0784: include_str!("./error_codes/E0784.md"),
E0785: include_str!("./error_codes/E0785.md"),
E0786: include_str!("./error_codes/E0786.md"),
E0787: include_str!("./error_codes/E0787.md"),
E0788: include_str!("./error_codes/E0788.md"),
E0789: include_str!("./error_codes/E0789.md"),
E0790: include_str!("./error_codes/E0790.md"),
E0791: include_str!("./error_codes/E0791.md"),
E0792: include_str!("./error_codes/E0792.md"),
E0793: include_str!("./error_codes/E0793.md"),
E0794: include_str!("./error_codes/E0794.md"),
E0795: include_str!("./error_codes/E0795.md"),
E0796: include_str!("./error_codes/E0796.md"),
E0797: include_str!("./error_codes/E0797.md"),
}
// Undocumented removed error codes. Note that many removed error codes are kept in the list above
// and marked as no-longer emitted with a note in the markdown file (see E0001 for an example).
// E0006, // merged with E0005
// E0008, // cannot bind by-move into a pattern guard
// E0019, // merged into E0015
// E0035, // merged into E0087/E0089
// E0036, // merged into E0087/E0089
// E0068,
// E0085,
// E0086,
// E0101, // replaced with E0282
// E0102, // replaced with E0282
// E0103,
// E0104,
// E0122, // bounds in type aliases are ignored, turned into proper lint
// E0123,
// E0127,
// E0129,
// E0134,
// E0135,
// E0141,
// E0153, // unused error code
// E0157, // unused error code
// E0159, // use of trait `{}` as struct constructor
// E0163, // merged into E0071
// E0167,
// E0168,
// E0172, // non-trait found in a type sum, moved to resolve
// E0173, // manual implementations of unboxed closure traits are experimental
// E0174,
// E0182, // merged into E0229
// E0187, // cannot infer the kind of the closure
// E0188, // can not cast an immutable reference to a mutable pointer
// E0189, // deprecated: can only cast a boxed pointer to a boxed object
// E0190, // deprecated: can only cast a &-pointer to an &-object
// E0194, // merged into E0403
// E0196, // cannot determine a type for this closure
// E0209, // builtin traits can only be implemented on structs or enums
// E0213, // associated types are not accepted in this context
// E0215, // angle-bracket notation is not stable with `Fn`
// E0216, // parenthetical notation is only stable with `Fn`
// E0217, // ambiguous associated type, defined in multiple supertraits
// E0218, // no associated type defined
// E0219, // associated type defined in higher-ranked supertrait
// E0233,
// E0234,
// E0235, // structure constructor specifies a structure of type but
// E0236, // no lang item for range syntax
// E0237, // no lang item for range syntax
// E0238, // parenthesized parameters may only be used with a trait
// E0239, // `next` method of `Iterator` trait has unexpected type
// E0240,
// E0241,
// E0242,
// E0245, // not a trait
// E0246, // invalid recursive type
// E0247,
// E0248, // value used as a type, now reported earlier during resolution
// // as E0412
// E0249,
// E0257,
// E0258,
// E0272, // on_unimplemented #0
// E0273, // on_unimplemented #1
// E0274, // on_unimplemented #2
// E0278, // requirement is not satisfied
// E0279,
// E0280, // changed to ICE
// E0285, // overflow evaluation builtin bounds
// E0296, // replaced with a generic attribute input check
// E0298, // cannot compare constants
// E0299, // mismatched types between arms
// E0300, // unexpanded macro
// E0304, // expected signed integer constant
// E0305, // expected constant
// E0313, // removed: found unreachable
// E0314, // closure outlives stack frame
// E0315, // cannot invoke closure outside of its lifetime
// E0319, // trait impls for defaulted traits allowed just for structs/enums
// E0372, // coherence not object safe
// E0385, // {} in an aliasable location
// E0402, // cannot use an outer type parameter in this context
// E0406, // merged into 420
// E0410, // merged into 408
// E0413, // merged into 530
// E0414, // merged into 530
// E0417, // merged into 532
// E0418, // merged into 532
// E0419, // merged into 531
// E0420, // merged into 532
// E0421, // merged into 531
// E0427, // merged into 530
// E0445, // merged into 446 and type privacy lints
// E0456, // plugin `..` is not available for triple `..`
// E0465, // removed: merged with E0464
// E0467, // removed
// E0470, // removed
// E0471, // constant evaluation error (in pattern)
// E0473, // dereference of reference outside its lifetime
// E0474, // captured variable `..` does not outlive the enclosing closure
// E0475, // index of slice outside its lifetime
// E0479, // the type `..` (provided as the value of a type parameter) is...
// E0480, // lifetime of method receiver does not outlive the method call
// E0481, // lifetime of function argument does not outlive the function call
// E0483, // lifetime of operand does not outlive the operation
// E0484, // reference is not valid at the time of borrow
// E0485, // automatically reference is not valid at the time of borrow
// E0486, // type of expression contains references that are not valid during..
// E0487, // unsafe use of destructor: destructor might be called while...
// E0488, // lifetime of variable does not enclose its declaration
// E0489, // type/lifetime parameter not in scope here
// E0490, // removed: unreachable
// E0526, // shuffle indices are not constant
// E0540, // multiple rustc_deprecated attributes
// E0548, // replaced with a generic attribute input check
// E0553, // multiple rustc_const_unstable attributes
// E0555, // replaced with a generic attribute input check
// E0558, // replaced with a generic attribute input check
// E0563, // cannot determine a type for this `impl Trait` removed in 6383de15
// E0564, // only named lifetimes are allowed in `impl Trait`,
// // but `{}` was found in the type `{}`
// E0598, // lifetime of {} is too short to guarantee its contents can be...
// E0611, // merged into E0616
// E0612, // merged into E0609
// E0613, // Removed (merged with E0609)
// E0629, // missing 'feature' (rustc_const_unstable)
// E0630, // rustc_const_unstable attribute must be paired with stable/unstable
// // attribute
// E0645, // trait aliases not finished
// E0694, // an unknown tool name found in scoped attributes
// E0702, // replaced with a generic attribute input check
// E0707, // multiple elided lifetimes used in arguments of `async fn`
// E0709, // multiple different lifetimes used in arguments of `async fn`
// E0721, // `await` keyword
// E0723, // unstable feature in `const` context
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
// E0744, // merged into E0728

View file

@ -1,19 +1,679 @@
//! This library is used to gather all error codes into one place, to make
//! their maintenance easier.
#![allow(internal_features)]
#![feature(rustdoc_internals)]
#![doc(rust_logo)]
#![deny(rustdoc::invalid_codeblock_attributes)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
//! This library is used to gather all error codes into one place,
//! the goal being to make their maintenance easier.
macro_rules! register_diagnostics {
($($ecode:ident: $message:expr,)*) => (
pub static DIAGNOSTICS: &[(&str, &str)] = &[
$( (stringify!($ecode), $message), )*
];
// This higher-order macro defines the error codes that are in use. It is used
// in the `rustc_errors` crate. Removed error codes are listed in the comment
// below.
//
// /!\ IMPORTANT /!\
//
// Error code explanation are defined in `error_codes/EXXXX.md` files. They must follow the RFC
// 1567 available here:
// https://rust-lang.github.io/rfcs/1567-long-error-codes-explanation-normalization.html
//
// Also, the contents of this macro is checked by tidy (in `check_error_codes_docs`). If you change
// the macro syntax you will need to change tidy as well.
//
// Both columns are necessary because it's not possible in Rust to create a new identifier such as
// `E0123` from an integer literal such as `0123`, unfortunately.
#[macro_export]
macro_rules! error_codes {
($macro:path) => (
$macro!(
E0001: 0001,
E0002: 0002,
E0004: 0004,
E0005: 0005,
E0007: 0007,
E0009: 0009,
E0010: 0010,
E0013: 0013,
E0014: 0014,
E0015: 0015,
E0023: 0023,
E0025: 0025,
E0026: 0026,
E0027: 0027,
E0029: 0029,
E0030: 0030,
E0033: 0033,
E0034: 0034,
E0038: 0038,
E0040: 0040,
E0044: 0044,
E0045: 0045,
E0046: 0046,
E0049: 0049,
E0050: 0050,
E0053: 0053,
E0054: 0054,
E0055: 0055,
E0057: 0057,
E0059: 0059,
E0060: 0060,
E0061: 0061,
E0062: 0062,
E0063: 0063,
E0067: 0067,
E0069: 0069,
E0070: 0070,
E0071: 0071,
E0072: 0072,
E0073: 0073,
E0074: 0074,
E0075: 0075,
E0076: 0076,
E0077: 0077,
E0080: 0080,
E0081: 0081,
E0084: 0084,
E0087: 0087,
E0088: 0088,
E0089: 0089,
E0090: 0090,
E0091: 0091,
E0092: 0092,
E0093: 0093,
E0094: 0094,
E0106: 0106,
E0107: 0107,
E0109: 0109,
E0110: 0110,
E0116: 0116,
E0117: 0117,
E0118: 0118,
E0119: 0119,
E0120: 0120,
E0121: 0121,
E0124: 0124,
E0128: 0128,
E0130: 0130,
E0131: 0131,
E0132: 0132,
E0133: 0133,
E0136: 0136,
E0137: 0137,
E0138: 0138,
E0139: 0139,
E0152: 0152,
E0154: 0154,
E0158: 0158,
E0161: 0161,
E0162: 0162,
E0164: 0164,
E0165: 0165,
E0170: 0170,
E0178: 0178,
E0183: 0183,
E0184: 0184,
E0185: 0185,
E0186: 0186,
E0191: 0191,
E0192: 0192,
E0193: 0193,
E0195: 0195,
E0197: 0197,
E0198: 0198,
E0199: 0199,
E0200: 0200,
E0201: 0201,
E0203: 0203,
E0204: 0204,
E0205: 0205,
E0206: 0206,
E0207: 0207,
E0208: 0208,
E0210: 0210,
E0211: 0211,
E0212: 0212,
E0214: 0214,
E0220: 0220,
E0221: 0221,
E0222: 0222,
E0223: 0223,
E0224: 0224,
E0225: 0225,
E0226: 0226,
E0227: 0227,
E0228: 0228,
E0229: 0229,
E0230: 0230,
E0231: 0231,
E0232: 0232,
E0243: 0243,
E0244: 0244,
E0251: 0251,
E0252: 0252,
E0253: 0253,
E0254: 0254,
E0255: 0255,
E0256: 0256,
E0259: 0259,
E0260: 0260,
E0261: 0261,
E0262: 0262,
E0263: 0263,
E0264: 0264,
E0267: 0267,
E0268: 0268,
E0271: 0271,
E0275: 0275,
E0276: 0276,
E0277: 0277,
E0281: 0281,
E0282: 0282,
E0283: 0283,
E0284: 0284,
E0297: 0297,
E0301: 0301,
E0302: 0302,
E0303: 0303,
E0307: 0307,
E0308: 0308,
E0309: 0309,
E0310: 0310,
E0311: 0311,
E0312: 0312,
E0316: 0316,
E0317: 0317,
E0320: 0320,
E0321: 0321,
E0322: 0322,
E0323: 0323,
E0324: 0324,
E0325: 0325,
E0326: 0326,
E0328: 0328,
E0329: 0329,
E0364: 0364,
E0365: 0365,
E0366: 0366,
E0367: 0367,
E0368: 0368,
E0369: 0369,
E0370: 0370,
E0371: 0371,
E0373: 0373,
E0374: 0374,
E0375: 0375,
E0376: 0376,
E0377: 0377,
E0378: 0378,
E0379: 0379,
E0380: 0380,
E0381: 0381,
E0382: 0382,
E0383: 0383,
E0384: 0384,
E0386: 0386,
E0387: 0387,
E0388: 0388,
E0389: 0389,
E0390: 0390,
E0391: 0391,
E0392: 0392,
E0393: 0393,
E0398: 0398,
E0399: 0399,
E0401: 0401,
E0403: 0403,
E0404: 0404,
E0405: 0405,
E0407: 0407,
E0408: 0408,
E0409: 0409,
E0411: 0411,
E0412: 0412,
E0415: 0415,
E0416: 0416,
E0422: 0422,
E0423: 0423,
E0424: 0424,
E0425: 0425,
E0426: 0426,
E0428: 0428,
E0429: 0429,
E0430: 0430,
E0431: 0431,
E0432: 0432,
E0433: 0433,
E0434: 0434,
E0435: 0435,
E0436: 0436,
E0437: 0437,
E0438: 0438,
E0439: 0439,
E0445: 0445,
E0446: 0446,
E0447: 0447,
E0448: 0448,
E0449: 0449,
E0451: 0451,
E0452: 0452,
E0453: 0453,
E0454: 0454,
E0455: 0455,
E0457: 0457,
E0458: 0458,
E0459: 0459,
E0460: 0460,
E0461: 0461,
E0462: 0462,
E0463: 0463,
E0464: 0464,
E0466: 0466,
E0468: 0468,
E0469: 0469,
E0472: 0472,
E0476: 0476,
E0477: 0477,
E0478: 0478,
E0482: 0482,
E0491: 0491,
E0492: 0492,
E0493: 0493,
E0495: 0495,
E0496: 0496,
E0497: 0497,
E0498: 0498,
E0499: 0499,
E0500: 0500,
E0501: 0501,
E0502: 0502,
E0503: 0503,
E0504: 0504,
E0505: 0505,
E0506: 0506,
E0507: 0507,
E0508: 0508,
E0509: 0509,
E0510: 0510,
E0511: 0511,
E0512: 0512,
E0514: 0514,
E0515: 0515,
E0516: 0516,
E0517: 0517,
E0518: 0518,
E0519: 0519,
E0520: 0520,
E0521: 0521,
E0522: 0522,
E0523: 0523,
E0524: 0524,
E0525: 0525,
E0527: 0527,
E0528: 0528,
E0529: 0529,
E0530: 0530,
E0531: 0531,
E0532: 0532,
E0533: 0533,
E0534: 0534,
E0535: 0535,
E0536: 0536,
E0537: 0537,
E0538: 0538,
E0539: 0539,
E0541: 0541,
E0542: 0542,
E0543: 0543,
E0544: 0544,
E0545: 0545,
E0546: 0546,
E0547: 0547,
E0549: 0549,
E0550: 0550,
E0551: 0551,
E0552: 0552,
E0554: 0554,
E0556: 0556,
E0557: 0557,
E0559: 0559,
E0560: 0560,
E0561: 0561,
E0562: 0562,
E0565: 0565,
E0566: 0566,
E0567: 0567,
E0568: 0568,
E0569: 0569,
E0570: 0570,
E0571: 0571,
E0572: 0572,
E0573: 0573,
E0574: 0574,
E0575: 0575,
E0576: 0576,
E0577: 0577,
E0578: 0578,
E0579: 0579,
E0580: 0580,
E0581: 0581,
E0582: 0582,
E0583: 0583,
E0584: 0584,
E0585: 0585,
E0586: 0586,
E0587: 0587,
E0588: 0588,
E0589: 0589,
E0590: 0590,
E0591: 0591,
E0592: 0592,
E0593: 0593,
E0594: 0594,
E0595: 0595,
E0596: 0596,
E0597: 0597,
E0599: 0599,
E0600: 0600,
E0601: 0601,
E0602: 0602,
E0603: 0603,
E0604: 0604,
E0605: 0605,
E0606: 0606,
E0607: 0607,
E0608: 0608,
E0609: 0609,
E0610: 0610,
E0614: 0614,
E0615: 0615,
E0616: 0616,
E0617: 0617,
E0618: 0618,
E0619: 0619,
E0620: 0620,
E0621: 0621,
E0622: 0622,
E0623: 0623,
E0624: 0624,
E0625: 0625,
E0626: 0626,
E0627: 0627,
E0628: 0628,
E0631: 0631,
E0632: 0632,
E0633: 0633,
E0634: 0634,
E0635: 0635,
E0636: 0636,
E0637: 0637,
E0638: 0638,
E0639: 0639,
E0640: 0640,
E0641: 0641,
E0642: 0642,
E0643: 0643,
E0644: 0644,
E0646: 0646,
E0647: 0647,
E0648: 0648,
E0657: 0657,
E0658: 0658,
E0659: 0659,
E0660: 0660,
E0661: 0661,
E0662: 0662,
E0663: 0663,
E0664: 0664,
E0665: 0665,
E0666: 0666,
E0667: 0667,
E0668: 0668,
E0669: 0669,
E0670: 0670,
E0671: 0671,
E0687: 0687,
E0688: 0688,
E0689: 0689,
E0690: 0690,
E0691: 0691,
E0692: 0692,
E0693: 0693,
E0695: 0695,
E0696: 0696,
E0697: 0697,
E0698: 0698,
E0699: 0699,
E0700: 0700,
E0701: 0701,
E0703: 0703,
E0704: 0704,
E0705: 0705,
E0706: 0706,
E0708: 0708,
E0710: 0710,
E0712: 0712,
E0713: 0713,
E0714: 0714,
E0715: 0715,
E0716: 0716,
E0711: 0711,
E0717: 0717,
E0718: 0718,
E0719: 0719,
E0720: 0720,
E0722: 0722,
E0724: 0724,
E0725: 0725,
E0726: 0726,
E0727: 0727,
E0728: 0728,
E0729: 0729,
E0730: 0730,
E0731: 0731,
E0732: 0732,
E0733: 0733,
E0734: 0734,
E0735: 0735,
E0736: 0736,
E0737: 0737,
E0739: 0739,
E0740: 0740,
E0741: 0741,
E0742: 0742,
E0743: 0743,
E0744: 0744,
E0745: 0745,
E0746: 0746,
E0747: 0747,
E0748: 0748,
E0749: 0749,
E0750: 0750,
E0751: 0751,
E0752: 0752,
E0753: 0753,
E0754: 0754,
E0755: 0755,
E0756: 0756,
E0757: 0757,
E0758: 0758,
E0759: 0759,
E0760: 0760,
E0761: 0761,
E0762: 0762,
E0763: 0763,
E0764: 0764,
E0765: 0765,
E0766: 0766,
E0767: 0767,
E0768: 0768,
E0769: 0769,
E0770: 0770,
E0771: 0771,
E0772: 0772,
E0773: 0773,
E0774: 0774,
E0775: 0775,
E0776: 0776,
E0777: 0777,
E0778: 0778,
E0779: 0779,
E0780: 0780,
E0781: 0781,
E0782: 0782,
E0783: 0783,
E0784: 0784,
E0785: 0785,
E0786: 0786,
E0787: 0787,
E0788: 0788,
E0789: 0789,
E0790: 0790,
E0791: 0791,
E0792: 0792,
E0793: 0793,
E0794: 0794,
E0795: 0795,
E0796: 0796,
E0797: 0797,
);
)
}
mod error_codes;
pub use error_codes::DIAGNOSTICS;
// Undocumented removed error codes. Note that many removed error codes are kept in the list above
// and marked as no-longer emitted with a note in the markdown file (see E0001 for an example).
// E0006, // merged with E0005
// E0008, // cannot bind by-move into a pattern guard
// E0019, // merged into E0015
// E0035, // merged into E0087/E0089
// E0036, // merged into E0087/E0089
// E0068,
// E0085,
// E0086,
// E0101, // replaced with E0282
// E0102, // replaced with E0282
// E0103,
// E0104,
// E0122, // bounds in type aliases are ignored, turned into proper lint
// E0123,
// E0127,
// E0129,
// E0134,
// E0135,
// E0141,
// E0153, // unused error code
// E0157, // unused error code
// E0159, // use of trait `{}` as struct constructor
// E0163, // merged into E0071
// E0167,
// E0168,
// E0172, // non-trait found in a type sum, moved to resolve
// E0173, // manual implementations of unboxed closure traits are experimental
// E0174,
// E0182, // merged into E0229
// E0187, // cannot infer the kind of the closure
// E0188, // can not cast an immutable reference to a mutable pointer
// E0189, // deprecated: can only cast a boxed pointer to a boxed object
// E0190, // deprecated: can only cast a &-pointer to an &-object
// E0194, // merged into E0403
// E0196, // cannot determine a type for this closure
// E0209, // builtin traits can only be implemented on structs or enums
// E0213, // associated types are not accepted in this context
// E0215, // angle-bracket notation is not stable with `Fn`
// E0216, // parenthetical notation is only stable with `Fn`
// E0217, // ambiguous associated type, defined in multiple supertraits
// E0218, // no associated type defined
// E0219, // associated type defined in higher-ranked supertrait
// E0233,
// E0234,
// E0235, // structure constructor specifies a structure of type but
// E0236, // no lang item for range syntax
// E0237, // no lang item for range syntax
// E0238, // parenthesized parameters may only be used with a trait
// E0239, // `next` method of `Iterator` trait has unexpected type
// E0240,
// E0241,
// E0242,
// E0245, // not a trait
// E0246, // invalid recursive type
// E0247,
// E0248, // value used as a type, now reported earlier during resolution
// // as E0412
// E0249,
// E0257,
// E0258,
// E0272, // on_unimplemented #0
// E0273, // on_unimplemented #1
// E0274, // on_unimplemented #2
// E0278, // requirement is not satisfied
// E0279,
// E0280, // changed to ICE
// E0285, // overflow evaluation builtin bounds
// E0296, // replaced with a generic attribute input check
// E0298, // cannot compare constants
// E0299, // mismatched types between arms
// E0300, // unexpanded macro
// E0304, // expected signed integer constant
// E0305, // expected constant
// E0313, // removed: found unreachable
// E0314, // closure outlives stack frame
// E0315, // cannot invoke closure outside of its lifetime
// E0319, // trait impls for defaulted traits allowed just for structs/enums
// E0372, // coherence not object safe
// E0385, // {} in an aliasable location
// E0402, // cannot use an outer type parameter in this context
// E0406, // merged into 420
// E0410, // merged into 408
// E0413, // merged into 530
// E0414, // merged into 530
// E0417, // merged into 532
// E0418, // merged into 532
// E0419, // merged into 531
// E0420, // merged into 532
// E0421, // merged into 531
// E0427, // merged into 530
// E0445, // merged into 446 and type privacy lints
// E0456, // plugin `..` is not available for triple `..`
// E0465, // removed: merged with E0464
// E0467, // removed
// E0470, // removed
// E0471, // constant evaluation error (in pattern)
// E0473, // dereference of reference outside its lifetime
// E0474, // captured variable `..` does not outlive the enclosing closure
// E0475, // index of slice outside its lifetime
// E0479, // the type `..` (provided as the value of a type parameter) is...
// E0480, // lifetime of method receiver does not outlive the method call
// E0481, // lifetime of function argument does not outlive the function call
// E0483, // lifetime of operand does not outlive the operation
// E0484, // reference is not valid at the time of borrow
// E0485, // automatically reference is not valid at the time of borrow
// E0486, // type of expression contains references that are not valid during..
// E0487, // unsafe use of destructor: destructor might be called while...
// E0488, // lifetime of variable does not enclose its declaration
// E0489, // type/lifetime parameter not in scope here
// E0490, // removed: unreachable
// E0526, // shuffle indices are not constant
// E0540, // multiple rustc_deprecated attributes
// E0548, // replaced with a generic attribute input check
// E0553, // multiple rustc_const_unstable attributes
// E0555, // replaced with a generic attribute input check
// E0558, // replaced with a generic attribute input check
// E0563, // cannot determine a type for this `impl Trait` removed in 6383de15
// E0564, // only named lifetimes are allowed in `impl Trait`,
// // but `{}` was found in the type `{}`
// E0598, // lifetime of {} is too short to guarantee its contents can be...
// E0611, // merged into E0616
// E0612, // merged into E0609
// E0613, // Removed (merged with E0609)
// E0629, // missing 'feature' (rustc_const_unstable)
// E0630, // rustc_const_unstable attribute must be paired with stable/unstable
// // attribute
// E0645, // trait aliases not finished
// E0694, // an unknown tool name found in scoped attributes
// E0702, // replaced with a generic attribute input check
// E0707, // multiple elided lifetimes used in arguments of `async fn`
// E0709, // multiple different lifetimes used in arguments of `async fn`
// E0721, // `await` keyword
// E0723, // unstable feature in `const` context
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
// E0744, // merged into E0728

View file

@ -1,6 +1,5 @@
#![doc(rust_logo)]
#![feature(rustdoc_internals)]
#![feature(let_chains)]
#![feature(lazy_cell)]
#![feature(rustc_attrs)]
#![feature(type_alias_impl_trait)]

View file

@ -10,9 +10,11 @@ derive_setters = "0.1.6"
rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_error_codes = { path = "../rustc_error_codes" }
rustc_error_messages = { path = "../rustc_error_messages" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }
rustc_lint_defs = { path = "../rustc_lint_defs" }
rustc_macros = { path = "../rustc_macros" }
rustc_serialize = { path = "../rustc_serialize" }

View file

@ -9,8 +9,8 @@ use crate::emitter::FileWithAnnotatedLines;
use crate::snippet::Line;
use crate::translation::{to_fluent_args, Translate};
use crate::{
CodeSuggestion, Diagnostic, DiagnosticMessage, Emitter, FluentBundle, LazyFallbackBundle,
Level, MultiSpan, Style, SubDiagnostic,
CodeSuggestion, Diagnostic, DiagnosticMessage, Emitter, ErrCode, FluentBundle,
LazyFallbackBundle, Level, MultiSpan, Style, SubDiagnostic,
};
use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation};
use rustc_data_structures::sync::Lrc;
@ -127,7 +127,7 @@ impl AnnotateSnippetEmitter {
level: &Level,
messages: &[(DiagnosticMessage, Style)],
args: &FluentArgs<'_>,
code: &Option<String>,
code: &Option<ErrCode>,
msp: &MultiSpan,
_children: &[SubDiagnostic],
_suggestions: &[CodeSuggestion],
@ -178,6 +178,7 @@ impl AnnotateSnippetEmitter {
.collect::<Vec<Owned>>()
})
.collect();
let code = code.map(|code| code.to_string());
let snippet = Snippet {
title: Some(Annotation {
label: Some(&message),

View file

@ -0,0 +1,39 @@
//! This module defines the following.
//! - The `ErrCode` type.
//! - A constant for every error code, with a name like `E0123`.
//! - A static table `DIAGNOSTICS` pairing every error code constant with its
//! long description text.
use std::fmt;
rustc_index::newtype_index! {
#[max = 9999] // Because all error codes have four digits.
#[orderable]
#[encodable]
#[debug_format = "ErrCode({})"]
pub struct ErrCode {}
}
impl fmt::Display for ErrCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "E{:04}", self.as_u32())
}
}
macro_rules! define_error_code_constants_and_diagnostics_table {
($($name:ident: $num:literal,)*) => (
$(
pub const $name: $crate::ErrCode = $crate::ErrCode::from_u32($num);
)*
pub static DIAGNOSTICS: &[($crate::ErrCode, &str)] = &[
$( (
$name,
include_str!(
concat!("../../rustc_error_codes/src/error_codes/", stringify!($name), ".md")
)
), )*
];
)
}
rustc_error_codes::error_codes!(define_error_code_constants_and_diagnostics_table);

View file

@ -1,7 +1,8 @@
use crate::snippet::Style;
use crate::{
CodeSuggestion, DelayedBugKind, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, Level,
MultiSpan, SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle,
CodeSuggestion, DelayedBugKind, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee,
ErrCode, Level, MultiSpan, SubdiagnosticMessage, Substitution, SubstitutionPart,
SuggestionStyle,
};
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_error_messages::fluent_value_from_str_list_sep_by_and;
@ -22,19 +23,18 @@ pub struct SuggestionsDisabled;
/// Simplified version of `FluentArg` that can implement `Encodable` and `Decodable`. Collection of
/// `DiagnosticArg` are converted to `FluentArgs` (consuming the collection) at the start of
/// diagnostic emission.
pub type DiagnosticArg<'iter, 'source> =
(&'iter DiagnosticArgName<'source>, &'iter DiagnosticArgValue<'source>);
pub type DiagnosticArg<'iter> = (&'iter DiagnosticArgName, &'iter DiagnosticArgValue);
/// Name of a diagnostic argument.
pub type DiagnosticArgName<'source> = Cow<'source, str>;
pub type DiagnosticArgName = Cow<'static, str>;
/// Simplified version of `FluentValue` that can implement `Encodable` and `Decodable`. Converted
/// to a `FluentValue` by the emitter to be used in diagnostic translation.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
pub enum DiagnosticArgValue<'source> {
Str(Cow<'source, str>),
pub enum DiagnosticArgValue {
Str(Cow<'static, str>),
Number(i128),
StrListSepByAnd(Vec<Cow<'source, str>>),
StrListSepByAnd(Vec<Cow<'static, str>>),
}
/// Converts a value of a type into a `DiagnosticArg` (typically a field of an `IntoDiagnostic`
@ -42,23 +42,17 @@ pub enum DiagnosticArgValue<'source> {
/// being converted rather than on `DiagnosticArgValue`, which enables types from other `rustc_*`
/// crates to implement this.
pub trait IntoDiagnosticArg {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static>;
fn into_diagnostic_arg(self) -> DiagnosticArgValue;
}
impl<'source> IntoDiagnosticArg for DiagnosticArgValue<'source> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
match self {
DiagnosticArgValue::Str(s) => DiagnosticArgValue::Str(Cow::Owned(s.into_owned())),
DiagnosticArgValue::Number(n) => DiagnosticArgValue::Number(n),
DiagnosticArgValue::StrListSepByAnd(l) => DiagnosticArgValue::StrListSepByAnd(
l.into_iter().map(|s| Cow::Owned(s.into_owned())).collect(),
),
}
impl IntoDiagnosticArg for DiagnosticArgValue {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
self
}
}
impl<'source> Into<FluentValue<'source>> for DiagnosticArgValue<'source> {
fn into(self) -> FluentValue<'source> {
impl Into<FluentValue<'static>> for DiagnosticArgValue {
fn into(self) -> FluentValue<'static> {
match self {
DiagnosticArgValue::Str(s) => From::from(s),
DiagnosticArgValue::Number(n) => From::from(n),
@ -104,11 +98,11 @@ pub struct Diagnostic {
pub(crate) level: Level,
pub messages: Vec<(DiagnosticMessage, Style)>,
pub code: Option<String>,
pub code: Option<ErrCode>,
pub span: MultiSpan,
pub children: Vec<SubDiagnostic>,
pub suggestions: Result<Vec<CodeSuggestion>, SuggestionsDisabled>,
args: FxHashMap<DiagnosticArgName<'static>, DiagnosticArgValue<'static>>,
args: FxHashMap<DiagnosticArgName, DiagnosticArgValue>,
/// This is not used for highlighting or rendering any error message. Rather, it can be used
/// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of
@ -893,8 +887,8 @@ impl Diagnostic {
self
}
pub fn code(&mut self, s: String) -> &mut Self {
self.code = Some(s);
pub fn code(&mut self, code: ErrCode) -> &mut Self {
self.code = Some(code);
self
}
@ -903,8 +897,8 @@ impl Diagnostic {
self
}
pub fn get_code(&self) -> Option<&str> {
self.code.as_deref()
pub fn get_code(&self) -> Option<ErrCode> {
self.code
}
pub fn primary_message(&mut self, msg: impl Into<DiagnosticMessage>) -> &mut Self {
@ -915,7 +909,7 @@ impl Diagnostic {
// Exact iteration order of diagnostic arguments shouldn't make a difference to output because
// they're only used in interpolation.
#[allow(rustc::potential_query_instability)]
pub fn args(&self) -> impl Iterator<Item = DiagnosticArg<'_, 'static>> {
pub fn args(&self) -> impl Iterator<Item = DiagnosticArg<'_>> {
self.args.iter()
}
@ -928,10 +922,7 @@ impl Diagnostic {
self
}
pub fn replace_args(
&mut self,
args: FxHashMap<DiagnosticArgName<'static>, DiagnosticArgValue<'static>>,
) {
pub fn replace_args(&mut self, args: FxHashMap<DiagnosticArgName, DiagnosticArgValue>) {
self.args = args;
}
@ -989,8 +980,8 @@ impl Diagnostic {
) -> (
&Level,
&[(DiagnosticMessage, Style)],
Vec<(&Cow<'static, str>, &DiagnosticArgValue<'static>)>,
&Option<String>,
Vec<(&Cow<'static, str>, &DiagnosticArgValue)>,
&Option<ErrCode>,
&Option<IsLint>,
&MultiSpan,
&Result<Vec<CodeSuggestion>, SuggestionsDisabled>,

View file

@ -1,7 +1,7 @@
use crate::diagnostic::IntoDiagnosticArg;
use crate::{DiagCtxt, Level, MultiSpan, StashKey};
use crate::{
Diagnostic, DiagnosticMessage, DiagnosticStyledString, ErrorGuaranteed, ExplicitBug,
Diagnostic, DiagnosticMessage, DiagnosticStyledString, ErrCode, ErrorGuaranteed, ExplicitBug,
SubdiagnosticMessage,
};
use rustc_lint_defs::Applicability;
@ -399,7 +399,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
name: String, has_future_breakage: bool,
));
forward!((code, with_code)(
s: String,
code: ErrCode,
));
forward!((arg, with_arg)(
name: impl Into<Cow<'static, str>>, arg: impl IntoDiagnosticArg,
@ -439,12 +439,7 @@ impl<G: EmissionGuarantee> Drop for DiagnosticBuilder<'_, G> {
#[macro_export]
macro_rules! struct_span_code_err {
($dcx:expr, $span:expr, $code:ident, $($message:tt)*) => ({
$dcx.struct_span_err($span, format!($($message)*)).with_code($crate::error_code!($code))
($dcx:expr, $span:expr, $code:expr, $($message:tt)*) => ({
$dcx.struct_span_err($span, format!($($message)*)).with_code($code)
})
}
#[macro_export]
macro_rules! error_code {
($code:ident) => {{ stringify!($code).to_owned() }};
}

View file

@ -1,7 +1,7 @@
use crate::diagnostic::DiagnosticLocation;
use crate::{fluent_generated as fluent, AddToDiagnostic};
use crate::{
DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic,
DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, ErrCode, IntoDiagnostic,
IntoDiagnosticArg, Level,
};
use rustc_ast as ast;
@ -23,7 +23,7 @@ use std::process::ExitStatus;
pub struct DiagnosticArgFromDisplay<'a>(pub &'a dyn fmt::Display);
impl IntoDiagnosticArg for DiagnosticArgFromDisplay<'_> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
self.0.to_string().into_diagnostic_arg()
}
}
@ -41,7 +41,7 @@ impl<'a, T: fmt::Display> From<&'a T> for DiagnosticArgFromDisplay<'a> {
}
impl<'a, T: Clone + IntoDiagnosticArg> IntoDiagnosticArg for &'a T {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
self.clone().into_diagnostic_arg()
}
}
@ -50,7 +50,7 @@ macro_rules! into_diagnostic_arg_using_display {
($( $ty:ty ),+ $(,)?) => {
$(
impl IntoDiagnosticArg for $ty {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
self.to_string().into_diagnostic_arg()
}
}
@ -58,16 +58,29 @@ macro_rules! into_diagnostic_arg_using_display {
}
}
macro_rules! into_diagnostic_arg_for_number {
($( $ty:ty ),+ $(,)?) => {
$(
impl IntoDiagnosticArg for $ty {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
// HACK: `FluentNumber` the underline backing struct represent
// numbers using a f64 which can't represent all the i128 numbers
// So in order to be able to use fluent selectors and still
// have all the numbers representable we only convert numbers
// below a certain threshold.
if let Ok(n) = TryInto::<i128>::try_into(self) && n >= -100 && n <= 100 {
DiagnosticArgValue::Number(n)
} else {
self.to_string().into_diagnostic_arg()
}
}
}
)+
}
}
into_diagnostic_arg_using_display!(
ast::ParamKindOrd,
i8,
u8,
i16,
u16,
u32,
i64,
i128,
u128,
std::io::Error,
Box<dyn std::error::Error>,
std::num::NonZeroU32,
@ -80,22 +93,13 @@ into_diagnostic_arg_using_display!(
&TargetTriple,
SplitDebuginfo,
ExitStatus,
ErrCode,
);
impl IntoDiagnosticArg for i32 {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
DiagnosticArgValue::Number(self.into())
}
}
impl IntoDiagnosticArg for u64 {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
DiagnosticArgValue::Number(self.into())
}
}
into_diagnostic_arg_for_number!(i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize);
impl IntoDiagnosticArg for bool {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
if self {
DiagnosticArgValue::Str(Cow::Borrowed("true"))
} else {
@ -105,13 +109,13 @@ impl IntoDiagnosticArg for bool {
}
impl IntoDiagnosticArg for char {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::Owned(format!("{self:?}")))
}
}
impl IntoDiagnosticArg for Vec<char> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::StrListSepByAnd(
self.into_iter().map(|c| Cow::Owned(format!("{c:?}"))).collect(),
)
@ -119,55 +123,49 @@ impl IntoDiagnosticArg for Vec<char> {
}
impl IntoDiagnosticArg for Symbol {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
self.to_ident_string().into_diagnostic_arg()
}
}
impl<'a> IntoDiagnosticArg for &'a str {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
self.to_string().into_diagnostic_arg()
}
}
impl IntoDiagnosticArg for String {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::Owned(self))
}
}
impl<'a> IntoDiagnosticArg for Cow<'a, str> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::Owned(self.into_owned()))
}
}
impl<'a> IntoDiagnosticArg for &'a Path {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::Owned(self.display().to_string()))
}
}
impl IntoDiagnosticArg for PathBuf {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::Owned(self.display().to_string()))
}
}
impl IntoDiagnosticArg for usize {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
DiagnosticArgValue::Number(self as i128)
}
}
impl IntoDiagnosticArg for PanicStrategy {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::Owned(self.desc().to_string()))
}
}
impl IntoDiagnosticArg for hir::ConstContext {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::Borrowed(match self {
hir::ConstContext::ConstFn => "const_fn",
hir::ConstContext::Static(_) => "static",
@ -177,49 +175,49 @@ impl IntoDiagnosticArg for hir::ConstContext {
}
impl IntoDiagnosticArg for ast::Expr {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::Owned(pprust::expr_to_string(&self)))
}
}
impl IntoDiagnosticArg for ast::Path {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::Owned(pprust::path_to_string(&self)))
}
}
impl IntoDiagnosticArg for ast::token::Token {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(pprust::token_to_string(&self))
}
}
impl IntoDiagnosticArg for ast::token::TokenKind {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(pprust::token_kind_to_string(&self))
}
}
impl IntoDiagnosticArg for type_ir::FloatTy {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::Borrowed(self.name_str()))
}
}
impl IntoDiagnosticArg for std::ffi::CString {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned()))
}
}
impl IntoDiagnosticArg for rustc_data_structures::small_c_str::SmallCStr {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned()))
}
}
impl IntoDiagnosticArg for ast::Visibility {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
let s = pprust::vis_to_string(&self);
let s = s.trim_end().to_string();
DiagnosticArgValue::Str(Cow::Owned(s))
@ -227,7 +225,7 @@ impl IntoDiagnosticArg for ast::Visibility {
}
impl IntoDiagnosticArg for rustc_lint_defs::Level {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::Borrowed(self.to_cmd_flag()))
}
}
@ -242,7 +240,7 @@ impl From<Vec<Symbol>> for DiagnosticSymbolList {
}
impl IntoDiagnosticArg for DiagnosticSymbolList {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::StrListSepByAnd(
self.0.into_iter().map(|sym| Cow::Owned(format!("`{sym}`"))).collect(),
)
@ -250,7 +248,7 @@ impl IntoDiagnosticArg for DiagnosticSymbolList {
}
impl<Id> IntoDiagnosticArg for hir::def::Res<Id> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::Borrowed(self.descr()))
}
}
@ -336,13 +334,13 @@ pub struct DelayedAtWithoutNewline {
}
impl IntoDiagnosticArg for DiagnosticLocation {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::from(self.to_string()))
}
}
impl IntoDiagnosticArg for Backtrace {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::from(self.to_string()))
}
}
@ -355,7 +353,7 @@ pub struct InvalidFlushedDelayedDiagnosticLevel {
pub level: Level,
}
impl IntoDiagnosticArg for Level {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(Cow::from(self.to_string()))
}
}
@ -370,7 +368,7 @@ pub struct IndicateAnonymousLifetime {
}
impl IntoDiagnosticArg for type_ir::ClosureKind {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
DiagnosticArgValue::Str(self.as_str().into())
}
}

View file

@ -17,8 +17,8 @@ use crate::styled_buffer::StyledBuffer;
use crate::translation::{to_fluent_args, Translate};
use crate::{
diagnostic::DiagnosticLocation, CodeSuggestion, DiagCtxt, Diagnostic, DiagnosticMessage,
FluentBundle, LazyFallbackBundle, Level, MultiSpan, SubDiagnostic, SubstitutionHighlight,
SuggestionStyle, TerminalUrl,
ErrCode, FluentBundle, LazyFallbackBundle, Level, MultiSpan, SubDiagnostic,
SubstitutionHighlight, SuggestionStyle, TerminalUrl,
};
use rustc_lint_defs::pluralize;
@ -1309,7 +1309,7 @@ impl HumanEmitter {
msp: &MultiSpan,
msgs: &[(DiagnosticMessage, Style)],
args: &FluentArgs<'_>,
code: &Option<String>,
code: &Option<ErrCode>,
level: &Level,
max_line_num_len: usize,
is_secondary: bool,
@ -1340,9 +1340,9 @@ impl HumanEmitter {
buffer.append(0, "[", Style::Level(*level));
let code = if let TerminalUrl::Yes = self.terminal_url {
let path = "https://doc.rust-lang.org/error_codes";
Cow::Owned(format!("\x1b]8;;{path}/{code}.html\x07{code}\x1b]8;;\x07"))
format!("\x1b]8;;{path}/{code}.html\x07{code}\x1b]8;;\x07")
} else {
Cow::Borrowed(code)
code.to_string()
};
buffer.append(0, &code, Style::Level(*level));
buffer.append(0, "]", Style::Level(*level));
@ -2076,7 +2076,7 @@ impl HumanEmitter {
level: &Level,
messages: &[(DiagnosticMessage, Style)],
args: &FluentArgs<'_>,
code: &Option<String>,
code: &Option<ErrCode>,
span: &MultiSpan,
children: &[SubDiagnostic],
suggestions: &[CodeSuggestion],

View file

@ -400,10 +400,10 @@ impl Diagnostic {
let translated_message = je.translate_messages(&diag.messages, &args);
let code = if let Some(code) = &diag.code {
let code = if let Some(code) = diag.code {
Some(DiagnosticCode {
code: code.to_string(),
explanation: je.registry.as_ref().unwrap().try_find_description(&code).ok(),
explanation: je.registry.as_ref().unwrap().try_find_description(code).ok(),
})
} else if let Some(IsLint { name, .. }) = &diag.is_lint {
Some(DiagnosticCode { code: name.to_string(), explanation: None })

View file

@ -2,24 +2,26 @@
//!
//! This module contains the code for creating and emitting diagnostics.
// tidy-alphabetical-start
#![allow(incomplete_features)]
#![allow(internal_features)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
#![feature(rustdoc_internals)]
#![feature(array_windows)]
#![feature(associated_type_defaults)]
#![feature(box_into_inner)]
#![feature(box_patterns)]
#![feature(error_reporter)]
#![feature(extract_if)]
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(min_specialization)]
#![feature(negative_impls)]
#![feature(never_type)]
#![feature(rustc_attrs)]
#![feature(yeet_expr)]
#![feature(rustdoc_internals)]
#![feature(try_blocks)]
#![feature(box_patterns)]
#![feature(error_reporter)]
#![allow(incomplete_features)]
#![allow(internal_features)]
#![feature(yeet_expr)]
// tidy-alphabetical-end
#[macro_use]
extern crate rustc_macros;
@ -29,9 +31,10 @@ extern crate tracing;
extern crate self as rustc_errors;
pub use codes::*;
pub use diagnostic::{
AddToDiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgValue,
DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
AddToDiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgName,
DiagnosticArgValue, DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
};
pub use diagnostic_builder::{
BugAbort, DiagnosticBuilder, EmissionGuarantee, FatalAbort, IntoDiagnostic,
@ -77,6 +80,7 @@ use std::path::{Path, PathBuf};
use Level::*;
pub mod annotate_snippet_emitter_writer;
pub mod codes;
mod diagnostic;
mod diagnostic_builder;
mod diagnostic_impls;
@ -445,10 +449,10 @@ struct DiagCtxtInner {
/// This set contains the code of all emitted diagnostics to avoid
/// emitting the same diagnostic with extended help (`--teach`) twice, which
/// would be unnecessary repetition.
taught_diagnostics: FxHashSet<String>,
taught_diagnostics: FxHashSet<ErrCode>,
/// Used to suggest rustc --explain `<error code>`
emitted_diagnostic_codes: FxIndexSet<String>,
emitted_diagnostic_codes: FxIndexSet<ErrCode>,
/// This set contains a hash of every diagnostic that has been emitted by
/// this `DiagCtxt`. These hashes is used to avoid emitting the same error
@ -510,6 +514,7 @@ pub enum StashKey {
MaybeForgetReturn,
/// Query cycle detected, stashing in favor of a better error.
Cycle,
UndeterminedMacroResolution,
}
fn default_track_diagnostic(diag: Diagnostic, f: &mut dyn FnMut(Diagnostic)) {
@ -624,7 +629,7 @@ impl DiagCtxt {
pub fn eagerly_translate<'a>(
&self,
message: DiagnosticMessage,
args: impl Iterator<Item = DiagnosticArg<'a, 'static>>,
args: impl Iterator<Item = DiagnosticArg<'a>>,
) -> SubdiagnosticMessage {
SubdiagnosticMessage::Eager(Cow::from(self.eagerly_translate_to_string(message, args)))
}
@ -633,7 +638,7 @@ impl DiagCtxt {
pub fn eagerly_translate_to_string<'a>(
&self,
message: DiagnosticMessage,
args: impl Iterator<Item = DiagnosticArg<'a, 'static>>,
args: impl Iterator<Item = DiagnosticArg<'a>>,
) -> String {
let inner = self.inner.borrow();
let args = crate::translation::to_fluent_args(args);
@ -1003,9 +1008,9 @@ impl DiagCtxt {
let mut error_codes = inner
.emitted_diagnostic_codes
.iter()
.filter_map(|code| {
.filter_map(|&code| {
if registry.try_find_description(code).is_ok().clone() {
Some(code.clone())
Some(code.to_string())
} else {
None
}
@ -1051,8 +1056,8 @@ impl DiagCtxt {
///
/// Used to suppress emitting the same error multiple times with extended explanation when
/// calling `-Zteach`.
pub fn must_teach(&self, code: &str) -> bool {
self.inner.borrow_mut().taught_diagnostics.insert(code.to_string())
pub fn must_teach(&self, code: ErrCode) -> bool {
self.inner.borrow_mut().taught_diagnostics.insert(code)
}
pub fn force_print_diagnostic(&self, db: Diagnostic) {
@ -1312,8 +1317,8 @@ impl DiagCtxtInner {
let mut guaranteed = None;
(*TRACK_DIAGNOSTIC)(diagnostic, &mut |mut diagnostic| {
if let Some(ref code) = diagnostic.code {
self.emitted_diagnostic_codes.insert(code.clone());
if let Some(code) = diagnostic.code {
self.emitted_diagnostic_codes.insert(code);
}
let already_emitted = {

View file

@ -1,3 +1,4 @@
use crate::ErrCode;
use rustc_data_structures::fx::FxHashMap;
#[derive(Debug)]
@ -5,17 +6,17 @@ pub struct InvalidErrorCode;
#[derive(Clone)]
pub struct Registry {
long_descriptions: FxHashMap<&'static str, &'static str>,
long_descriptions: FxHashMap<ErrCode, &'static str>,
}
impl Registry {
pub fn new(long_descriptions: &[(&'static str, &'static str)]) -> Registry {
pub fn new(long_descriptions: &[(ErrCode, &'static str)]) -> Registry {
Registry { long_descriptions: long_descriptions.iter().copied().collect() }
}
/// Returns `InvalidErrorCode` if the code requested does not exist in the
/// registry.
pub fn try_find_description(&self, code: &str) -> Result<&'static str, InvalidErrorCode> {
self.long_descriptions.get(code).copied().ok_or(InvalidErrorCode)
pub fn try_find_description(&self, code: ErrCode) -> Result<&'static str, InvalidErrorCode> {
self.long_descriptions.get(&code).copied().ok_or(InvalidErrorCode)
}
}

View file

@ -12,9 +12,9 @@ use std::error::Report;
///
/// Typically performed once for each diagnostic at the start of `emit_diagnostic` and then
/// passed around as a reference thereafter.
pub fn to_fluent_args<'iter, 'arg: 'iter>(
iter: impl Iterator<Item = DiagnosticArg<'iter, 'arg>>,
) -> FluentArgs<'arg> {
pub fn to_fluent_args<'iter>(
iter: impl Iterator<Item = DiagnosticArg<'iter>>,
) -> FluentArgs<'static> {
let mut args = if let Some(size) = iter.size_hint().1 {
FluentArgs::with_capacity(size)
} else {

View file

@ -796,9 +796,15 @@ impl SyntaxExtension {
/// | external | no | if-ext | if-ext | yes |
/// | yes | yes | yes | yes | yes |
fn get_collapse_debuginfo(sess: &Session, attrs: &[ast::Attribute], is_local: bool) -> bool {
let collapse_debuginfo_attr = attr::find_by_name(attrs, sym::collapse_debuginfo)
let mut collapse_debuginfo_attr = attr::find_by_name(attrs, sym::collapse_debuginfo)
.map(|v| Self::collapse_debuginfo_by_name(sess, v))
.unwrap_or(CollapseMacroDebuginfo::Unspecified);
if collapse_debuginfo_attr == CollapseMacroDebuginfo::Unspecified
&& attr::contains_name(attrs, sym::rustc_builtin_macro)
{
collapse_debuginfo_attr = CollapseMacroDebuginfo::Yes;
}
let flag = sess.opts.unstable_opts.collapse_macro_debuginfo;
let attr = collapse_debuginfo_attr;
let ext = !is_local;

View file

@ -373,7 +373,9 @@ impl<'a> StripUnconfigured<'a> {
/// If attributes are not allowed on expressions, emit an error for `attr`
#[instrument(level = "trace", skip(self))]
pub(crate) fn maybe_emit_expr_attr_err(&self, attr: &Attribute) {
if self.features.is_some_and(|features| !features.stmt_expr_attributes) {
if self.features.is_some_and(|features| !features.stmt_expr_attributes)
&& !attr.span.allows_unstable(sym::stmt_expr_attributes)
{
let mut err = feature_err(
&self.sess,
sym::stmt_expr_attributes,

View file

@ -1,4 +1,5 @@
use rustc_ast::ast;
use rustc_errors::codes::*;
use rustc_macros::Diagnostic;
use rustc_session::Limit;
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent};
@ -175,7 +176,7 @@ pub(crate) struct TakesNoArguments<'a> {
}
#[derive(Diagnostic)]
#[diag(expand_feature_removed, code = "E0557")]
#[diag(expand_feature_removed, code = E0557)]
pub(crate) struct FeatureRemoved<'a> {
#[primary_span]
#[label]
@ -191,7 +192,7 @@ pub(crate) struct FeatureRemovedReason<'a> {
}
#[derive(Diagnostic)]
#[diag(expand_feature_not_allowed, code = "E0725")]
#[diag(expand_feature_not_allowed, code = E0725)]
pub(crate) struct FeatureNotAllowed {
#[primary_span]
pub span: Span,
@ -210,7 +211,7 @@ pub(crate) struct RecursionLimitReached<'a> {
}
#[derive(Diagnostic)]
#[diag(expand_malformed_feature_attribute, code = "E0556")]
#[diag(expand_malformed_feature_attribute, code = E0556)]
pub(crate) struct MalformedFeatureAttribute {
#[primary_span]
pub span: Span,
@ -347,7 +348,7 @@ pub(crate) struct ModuleInBlockName {
}
#[derive(Diagnostic)]
#[diag(expand_module_file_not_found, code = "E0583")]
#[diag(expand_module_file_not_found, code = E0583)]
#[help]
#[note]
pub(crate) struct ModuleFileNotFound {
@ -359,7 +360,7 @@ pub(crate) struct ModuleFileNotFound {
}
#[derive(Diagnostic)]
#[diag(expand_module_multiple_candidates, code = "E0761")]
#[diag(expand_module_multiple_candidates, code = E0761)]
#[help]
pub(crate) struct ModuleMultipleCandidates {
#[primary_span]

View file

@ -9,9 +9,7 @@
#![feature(proc_macro_diagnostic)]
#![feature(proc_macro_internals)]
#![feature(proc_macro_span)]
#![feature(rustc_attrs)]
#![feature(try_blocks)]
#![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)]
#![allow(internal_features)]

View file

@ -485,7 +485,9 @@ pub fn compile_declarative_macro(
)
.pop()
.unwrap();
valid &= check_lhs_nt_follows(sess, def, &tt);
// We don't handle errors here, the driver will abort
// after parsing/expansion. we can report every error in every macro this way.
valid &= check_lhs_nt_follows(sess, def, &tt).is_ok();
return tt;
}
sess.dcx().span_bug(def.span, "wrong-structured lhs")
@ -589,18 +591,19 @@ pub fn compile_declarative_macro(
(mk_syn_ext(expander), rule_spans)
}
fn check_lhs_nt_follows(sess: &Session, def: &ast::Item, lhs: &mbe::TokenTree) -> bool {
fn check_lhs_nt_follows(
sess: &Session,
def: &ast::Item,
lhs: &mbe::TokenTree,
) -> Result<(), ErrorGuaranteed> {
// lhs is going to be like TokenTree::Delimited(...), where the
// entire lhs is those tts. Or, it can be a "bare sequence", not wrapped in parens.
if let mbe::TokenTree::Delimited(.., delimited) = lhs {
check_matcher(sess, def, &delimited.tts)
} else {
let msg = "invalid macro matcher; matchers must be contained in balanced delimiters";
sess.dcx().span_err(lhs.span(), msg);
false
Err(sess.dcx().span_err(lhs.span(), msg))
}
// we don't abort on errors on rejection, the driver will do that for us
// after parsing/expansion. we can report every error in every macro this way.
}
fn is_empty_token_tree(sess: &Session, seq: &mbe::SequenceRepetition) -> bool {
@ -675,12 +678,15 @@ fn check_rhs(sess: &Session, rhs: &mbe::TokenTree) -> bool {
false
}
fn check_matcher(sess: &Session, def: &ast::Item, matcher: &[mbe::TokenTree]) -> bool {
fn check_matcher(
sess: &Session,
def: &ast::Item,
matcher: &[mbe::TokenTree],
) -> Result<(), ErrorGuaranteed> {
let first_sets = FirstSets::new(matcher);
let empty_suffix = TokenSet::empty();
let err = sess.dcx().err_count();
check_matcher_core(sess, def, &first_sets, matcher, &empty_suffix);
err == sess.dcx().err_count()
check_matcher_core(sess, def, &first_sets, matcher, &empty_suffix)?;
Ok(())
}
fn has_compile_error_macro(rhs: &mbe::TokenTree) -> bool {
@ -1020,11 +1026,13 @@ fn check_matcher_core<'tt>(
first_sets: &FirstSets<'tt>,
matcher: &'tt [mbe::TokenTree],
follow: &TokenSet<'tt>,
) -> TokenSet<'tt> {
) -> Result<TokenSet<'tt>, ErrorGuaranteed> {
use mbe::TokenTree;
let mut last = TokenSet::empty();
let mut errored = Ok(());
// 2. For each token and suffix [T, SUFFIX] in M:
// ensure that T can be followed by SUFFIX, and if SUFFIX may be empty,
// then ensure T can also be followed by any element of FOLLOW.
@ -1068,7 +1076,7 @@ fn check_matcher_core<'tt>(
token::CloseDelim(d.delim),
span.close,
));
check_matcher_core(sess, def, first_sets, &d.tts, &my_suffix);
check_matcher_core(sess, def, first_sets, &d.tts, &my_suffix)?;
// don't track non NT tokens
last.replace_with_irrelevant();
@ -1100,7 +1108,7 @@ fn check_matcher_core<'tt>(
// At this point, `suffix_first` is built, and
// `my_suffix` is some TokenSet that we can use
// for checking the interior of `seq_rep`.
let next = check_matcher_core(sess, def, first_sets, &seq_rep.tts, my_suffix);
let next = check_matcher_core(sess, def, first_sets, &seq_rep.tts, my_suffix)?;
if next.maybe_empty {
last.add_all(&next);
} else {
@ -1206,14 +1214,15 @@ fn check_matcher_core<'tt>(
));
}
}
err.emit();
errored = Err(err.emit());
}
}
}
}
}
}
last
errored?;
Ok(last)
}
fn token_can_be_followed_by_any(tok: &mbe::TokenTree) -> bool {

View file

@ -516,6 +516,9 @@ declare_features! (
(unstable, macro_metavar_expr, "1.61.0", Some(83527)),
/// Allows `#[marker]` on certain traits allowing overlapping implementations.
(unstable, marker_trait_attr, "1.30.0", Some(29864)),
/// Allows exhaustive pattern matching on types that contain uninhabited types in cases that are
/// unambiguously sound.
(incomplete, min_exhaustive_patterns, "CURRENT_RUSTC_VERSION", Some(119612)),
/// A minimal, sound subset of specialization intended to be used by the
/// standard library until the soundness issues with specialization
/// are fixed.

View file

@ -1273,7 +1273,6 @@ pub struct Arm<'hir> {
/// desugaring to if-let. Only let-else supports the type annotation at present.
#[derive(Debug, Clone, Copy, HashStable_Generic)]
pub struct Let<'hir> {
pub hir_id: HirId,
pub span: Span,
pub pat: &'hir Pat<'hir>,
pub ty: Option<&'hir Ty<'hir>>,
@ -1532,14 +1531,16 @@ pub type Lit = Spanned<LitKind>;
#[derive(Copy, Clone, Debug, HashStable_Generic)]
pub enum ArrayLen {
Infer(HirId, Span),
Infer(InferArg),
Body(AnonConst),
}
impl ArrayLen {
pub fn hir_id(&self) -> HirId {
match self {
&ArrayLen::Infer(hir_id, _) | &ArrayLen::Body(AnonConst { hir_id, .. }) => hir_id,
ArrayLen::Infer(InferArg { hir_id, .. }) | ArrayLen::Body(AnonConst { hir_id, .. }) => {
*hir_id
}
}
}
}
@ -2424,7 +2425,7 @@ impl<'hir> Ty<'hir> {
TyKind::Infer => true,
TyKind::Slice(ty) => ty.is_suggestable_infer_ty(),
TyKind::Array(ty, length) => {
ty.is_suggestable_infer_ty() || matches!(length, ArrayLen::Infer(_, _))
ty.is_suggestable_infer_ty() || matches!(length, ArrayLen::Infer(..))
}
TyKind::Tup(tys) => tys.iter().any(Self::is_suggestable_infer_ty),
TyKind::Ptr(mut_ty) | TyKind::Ref(_, mut_ty) => mut_ty.ty.is_suggestable_infer_ty(),

View file

@ -341,9 +341,6 @@ pub trait Visitor<'v>: Sized {
fn visit_expr(&mut self, ex: &'v Expr<'v>) {
walk_expr(self, ex)
}
fn visit_let_expr(&mut self, lex: &'v Let<'v>) {
walk_let_expr(self, lex)
}
fn visit_expr_field(&mut self, field: &'v ExprField<'v>) {
walk_expr_field(self, field)
}
@ -672,7 +669,7 @@ pub fn walk_pat_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v PatField<'
pub fn walk_array_len<'v, V: Visitor<'v>>(visitor: &mut V, len: &'v ArrayLen) {
match len {
&ArrayLen::Infer(hir_id, _span) => visitor.visit_id(hir_id),
ArrayLen::Infer(InferArg { hir_id, span: _ }) => visitor.visit_id(*hir_id),
ArrayLen::Body(c) => visitor.visit_anon_const(c),
}
}
@ -729,7 +726,12 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
ExprKind::DropTemps(ref subexpression) => {
visitor.visit_expr(subexpression);
}
ExprKind::Let(ref let_expr) => visitor.visit_let_expr(let_expr),
ExprKind::Let(Let { span: _, pat, ty, init, is_recovered: _ }) => {
// match the visit order in walk_local
visitor.visit_expr(init);
visitor.visit_pat(pat);
walk_list!(visitor, visit_ty, ty);
}
ExprKind::If(ref cond, ref then, ref else_opt) => {
visitor.visit_expr(cond);
visitor.visit_expr(then);
@ -806,14 +808,6 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
}
}
pub fn walk_let_expr<'v, V: Visitor<'v>>(visitor: &mut V, let_expr: &'v Let<'v>) {
// match the visit order in walk_local
visitor.visit_expr(let_expr.init);
visitor.visit_id(let_expr.hir_id);
visitor.visit_pat(let_expr.pat);
walk_list!(visitor, visit_ty, let_expr.ty);
}
pub fn walk_expr_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v ExprField<'v>) {
visitor.visit_id(field.hir_id);
visitor.visit_ident(field.ident);

View file

@ -9,7 +9,6 @@
#![feature(never_type)]
#![feature(rustc_attrs)]
#![feature(variant_count)]
#![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
#![allow(internal_features)]

View file

@ -1,5 +1,5 @@
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::struct_span_code_err;
use rustc_errors::{codes::*, struct_span_code_err};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LocalDefId};

View file

@ -6,8 +6,11 @@ use crate::errors::{
use crate::fluent_generated as fluent;
use crate::traits::error_reporting::report_object_safety_error;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::unord::UnordMap;
use rustc_errors::{pluralize, struct_span_code_err, Applicability, Diagnostic, ErrorGuaranteed};
use rustc_errors::{
codes::*, pluralize, struct_span_code_err, Applicability, Diagnostic, ErrorGuaranteed,
};
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_infer::traits::FulfillmentError;
@ -461,22 +464,23 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
return err.emit();
}
let mut bound_spans = Vec::new();
let mut bound_spans: SortedMap<Span, Vec<String>> = Default::default();
let mut bound_span_label = |self_ty: Ty<'_>, obligation: &str, quiet: &str| {
let msg = format!(
"doesn't satisfy `{}`",
if obligation.len() > 50 { quiet } else { obligation }
);
let msg = format!("`{}`", if obligation.len() > 50 { quiet } else { obligation });
match &self_ty.kind() {
// Point at the type that couldn't satisfy the bound.
ty::Adt(def, _) => bound_spans.push((tcx.def_span(def.did()), msg)),
ty::Adt(def, _) => {
bound_spans.get_mut_or_insert_default(tcx.def_span(def.did())).push(msg)
}
// Point at the trait object that couldn't satisfy the bound.
ty::Dynamic(preds, _, _) => {
for pred in preds.iter() {
match pred.skip_binder() {
ty::ExistentialPredicate::Trait(tr) => {
bound_spans.push((tcx.def_span(tr.def_id), msg.clone()))
bound_spans
.get_mut_or_insert_default(tcx.def_span(tr.def_id))
.push(msg.clone());
}
ty::ExistentialPredicate::Projection(_)
| ty::ExistentialPredicate::AutoTrait(_) => {}
@ -485,7 +489,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
// Point at the closure that couldn't satisfy the bound.
ty::Closure(def_id, _) => {
bound_spans.push((tcx.def_span(*def_id), format!("doesn't satisfy `{quiet}`")))
bound_spans
.get_mut_or_insert_default(tcx.def_span(*def_id))
.push(format!("`{quiet}`"));
}
_ => {}
}
@ -554,12 +560,18 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
format!("associated type cannot be referenced on `{self_ty}` due to unsatisfied trait bounds")
);
bound_spans.sort();
bound_spans.dedup();
for (span, msg) in bound_spans {
for (span, mut bounds) in bound_spans {
if !tcx.sess.source_map().is_span_accessible(span) {
continue;
}
bounds.sort();
bounds.dedup();
let msg = match &bounds[..] {
[bound] => format!("doesn't satisfy {bound}"),
bounds if bounds.len() > 4 => format!("doesn't satisfy {} bounds", bounds.len()),
[bounds @ .., last] => format!("doesn't satisfy {} or {last}", bounds.join(", ")),
[] => unreachable!(),
};
err.span_label(span, msg);
}
add_def_label(&mut err);

View file

@ -5,7 +5,9 @@ use crate::astconv::{
};
use crate::structured_errors::{GenericArgsInfo, StructuredDiagnostic, WrongNumberOfGenericArgs};
use rustc_ast::ast::ParamKindOrd;
use rustc_errors::{struct_span_code_err, Applicability, Diagnostic, ErrorGuaranteed, MultiSpan};
use rustc_errors::{
codes::*, struct_span_code_err, Applicability, Diagnostic, ErrorGuaranteed, MultiSpan,
};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId;

View file

@ -1,5 +1,5 @@
use rustc_ast::TraitObjectSyntax;
use rustc_errors::{Diagnostic, StashKey};
use rustc_errors::{codes::*, Diagnostic, StashKey};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_lint_defs::{builtin::BARE_TRAIT_OBJECTS, Applicability};
@ -132,7 +132,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
],
Applicability::MachineApplicable,
);
} else if diag.is_error() && is_downgradable {
} else if is_downgradable {
// We'll emit the object safety error already, with a structured suggestion.
diag.downgrade_to_delayed_bug();
}
@ -158,7 +158,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
if !is_object_safe {
diag.note(format!("`{trait_name}` it is not object safe, so it can't be `dyn`"));
if diag.is_error() && is_downgradable {
if is_downgradable {
// We'll emit the object safety error already, with a structured suggestion.
diag.downgrade_to_delayed_bug();
}
@ -241,9 +241,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} else {
let msg = "trait objects without an explicit `dyn` are deprecated";
tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, msg, |lint| {
if self_ty.span.can_be_used_for_suggestions()
&& !self.maybe_lint_impl_trait(self_ty, lint)
{
if self_ty.span.can_be_used_for_suggestions() {
lint.multipart_suggestion_verbose(
"use `dyn`",
sugg,

View file

@ -18,8 +18,8 @@ use crate::require_c_abi_if_c_variadic;
use rustc_ast::TraitObjectSyntax;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::{
error_code, struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder,
ErrorGuaranteed, FatalError, MultiSpan,
codes::*, struct_span_code_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
FatalError, MultiSpan,
};
use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
@ -1072,9 +1072,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if let Some(binding) = binding
&& let ConvertedBindingKind::Equality(_) = binding.kind
{
error_code!(E0222)
E0222
} else {
error_code!(E0221)
E0221
},
);
@ -1630,7 +1630,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let reported = tcx
.dcx()
.struct_span_err(span, msg)
.with_code(rustc_errors::error_code!(E0624))
.with_code(E0624)
.with_span_label(span, format!("private {kind}"))
.with_span_label(def_span, format!("{kind} defined here"))
.emit();
@ -2529,7 +2529,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
hir::TyKind::Array(ty, length) => {
let length = match length {
&hir::ArrayLen::Infer(_, span) => self.ct_infer(tcx.types.usize, None, span),
hir::ArrayLen::Infer(inf) => self.ct_infer(tcx.types.usize, None, inf.span),
hir::ArrayLen::Body(constant) => {
ty::Const::from_anon_const(tcx, constant.def_id)
}

View file

@ -2,7 +2,7 @@ use crate::astconv::{GenericArgCountMismatch, GenericArgCountResult, OnlySelfBou
use crate::bounds::Bounds;
use crate::errors::TraitObjectDeclaredWithNoTraits;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_errors::struct_span_code_err;
use rustc_errors::{codes::*, struct_span_code_err};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId;

Some files were not shown because too many files have changed in this diff Show more