mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 02:33:55 +00:00
Auto merge of #3335 - rust-lang:rustup-2024-02-29, r=saethlin
Automatic Rustup
This commit is contained in:
commit
5717e52d17
138
Cargo.lock
138
Cargo.lock
@ -129,20 +129,6 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon 2.1.0",
|
||||
"colorchoice",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.11"
|
||||
@ -152,7 +138,7 @@ dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon 3.0.2",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"utf8parse",
|
||||
]
|
||||
@ -181,16 +167,6 @@ dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.2"
|
||||
@ -534,7 +510,7 @@ version = "4.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "458bf1f341769dfcf849846f65dffdf9146daa56bcd2a47cb4e1de9915567c99"
|
||||
dependencies = [
|
||||
"anstream 0.6.11",
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"clap_lex",
|
||||
"strsim 0.11.0",
|
||||
@ -572,7 +548,7 @@ checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
|
||||
name = "clippy"
|
||||
version = "0.1.78"
|
||||
dependencies = [
|
||||
"anstream 0.5.0",
|
||||
"anstream",
|
||||
"clippy_config",
|
||||
"clippy_lints",
|
||||
"clippy_utils",
|
||||
@ -580,7 +556,7 @@ dependencies = [
|
||||
"filetime",
|
||||
"futures",
|
||||
"if_chain",
|
||||
"itertools",
|
||||
"itertools 0.12.1",
|
||||
"parking_lot",
|
||||
"quote",
|
||||
"regex",
|
||||
@ -592,7 +568,7 @@ dependencies = [
|
||||
"tester",
|
||||
"tokio",
|
||||
"toml 0.7.8",
|
||||
"ui_test",
|
||||
"ui_test 0.22.2",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
@ -613,7 +589,7 @@ dependencies = [
|
||||
"aho-corasick",
|
||||
"clap",
|
||||
"indoc",
|
||||
"itertools",
|
||||
"itertools 0.12.1",
|
||||
"opener",
|
||||
"shell-escape",
|
||||
"walkdir",
|
||||
@ -628,7 +604,7 @@ dependencies = [
|
||||
"clippy_config",
|
||||
"clippy_utils",
|
||||
"declare_clippy_lint",
|
||||
"itertools",
|
||||
"itertools 0.12.1",
|
||||
"quine-mc_cluskey",
|
||||
"regex",
|
||||
"regex-syntax 0.8.2",
|
||||
@ -650,7 +626,7 @@ version = "0.1.78"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"clippy_config",
|
||||
"itertools",
|
||||
"itertools 0.12.1",
|
||||
"rustc-semver",
|
||||
]
|
||||
|
||||
@ -974,7 +950,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"
|
||||
name = "declare_clippy_lint"
|
||||
version = "0.1.78"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"itertools 0.12.1",
|
||||
"quote",
|
||||
"syn 2.0.48",
|
||||
]
|
||||
@ -1230,7 +1206,7 @@ version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c012a26a7f605efc424dd53697843a72be7dc86ad2d01f7814337794a12231d"
|
||||
dependencies = [
|
||||
"anstream 0.6.11",
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"env_filter",
|
||||
"humantime",
|
||||
@ -2054,6 +2030,15 @@ dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.10"
|
||||
@ -2476,7 +2461,7 @@ dependencies = [
|
||||
"regex",
|
||||
"rustc_version",
|
||||
"smallvec",
|
||||
"ui_test",
|
||||
"ui_test 0.21.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3432,18 +3417,29 @@ version = "0.0.0"
|
||||
dependencies = [
|
||||
"bitflags 2.4.2",
|
||||
"memchr",
|
||||
"rustc_ast_ir",
|
||||
"rustc_data_structures",
|
||||
"rustc_index",
|
||||
"rustc_lexer",
|
||||
"rustc_macros",
|
||||
"rustc_serialize",
|
||||
"rustc_span",
|
||||
"rustc_type_ir",
|
||||
"smallvec",
|
||||
"thin-vec",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_ast_ir"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"rustc_data_structures",
|
||||
"rustc_macros",
|
||||
"rustc_serialize",
|
||||
"rustc_span",
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_ast_lowering"
|
||||
version = "0.0.0"
|
||||
@ -3469,7 +3465,7 @@ dependencies = [
|
||||
name = "rustc_ast_passes"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"itertools 0.11.0",
|
||||
"rustc_ast",
|
||||
"rustc_ast_pretty",
|
||||
"rustc_attr",
|
||||
@ -3489,7 +3485,7 @@ dependencies = [
|
||||
name = "rustc_ast_pretty"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"itertools 0.11.0",
|
||||
"rustc_ast",
|
||||
"rustc_span",
|
||||
"thin-vec",
|
||||
@ -3529,7 +3525,7 @@ name = "rustc_borrowck"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"either",
|
||||
"itertools",
|
||||
"itertools 0.11.0",
|
||||
"polonius-engine",
|
||||
"rustc_data_structures",
|
||||
"rustc_errors",
|
||||
@ -3582,7 +3578,7 @@ name = "rustc_codegen_llvm"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"bitflags 2.4.2",
|
||||
"itertools",
|
||||
"itertools 0.11.0",
|
||||
"libc",
|
||||
"measureme",
|
||||
"object",
|
||||
@ -3618,7 +3614,7 @@ dependencies = [
|
||||
"ar_archive_writer",
|
||||
"bitflags 2.4.2",
|
||||
"cc",
|
||||
"itertools",
|
||||
"itertools 0.11.0",
|
||||
"jobserver",
|
||||
"libc",
|
||||
"object",
|
||||
@ -3899,7 +3895,7 @@ dependencies = [
|
||||
name = "rustc_hir_analysis"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"itertools 0.11.0",
|
||||
"rustc_arena",
|
||||
"rustc_ast",
|
||||
"rustc_attr",
|
||||
@ -3938,7 +3934,7 @@ dependencies = [
|
||||
name = "rustc_hir_typeck"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"itertools 0.11.0",
|
||||
"rustc_ast",
|
||||
"rustc_attr",
|
||||
"rustc_data_structures",
|
||||
@ -4196,6 +4192,7 @@ dependencies = [
|
||||
"rustc_apfloat",
|
||||
"rustc_arena",
|
||||
"rustc_ast",
|
||||
"rustc_ast_ir",
|
||||
"rustc_attr",
|
||||
"rustc_data_structures",
|
||||
"rustc_error_messages",
|
||||
@ -4222,7 +4219,7 @@ name = "rustc_mir_build"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"either",
|
||||
"itertools",
|
||||
"itertools 0.11.0",
|
||||
"rustc_apfloat",
|
||||
"rustc_arena",
|
||||
"rustc_ast",
|
||||
@ -4269,7 +4266,7 @@ name = "rustc_mir_transform"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"either",
|
||||
"itertools",
|
||||
"itertools 0.11.0",
|
||||
"rustc_arena",
|
||||
"rustc_ast",
|
||||
"rustc_attr",
|
||||
@ -4349,7 +4346,7 @@ dependencies = [
|
||||
name = "rustc_passes"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"itertools 0.11.0",
|
||||
"rustc_ast",
|
||||
"rustc_ast_pretty",
|
||||
"rustc_attr",
|
||||
@ -4599,7 +4596,7 @@ name = "rustc_trait_selection"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"bitflags 2.4.2",
|
||||
"itertools",
|
||||
"itertools 0.11.0",
|
||||
"rustc_ast",
|
||||
"rustc_attr",
|
||||
"rustc_data_structures",
|
||||
@ -4638,7 +4635,7 @@ dependencies = [
|
||||
name = "rustc_transmute"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"itertools 0.11.0",
|
||||
"rustc_data_structures",
|
||||
"rustc_hir",
|
||||
"rustc_infer",
|
||||
@ -4653,7 +4650,7 @@ dependencies = [
|
||||
name = "rustc_ty_utils"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"itertools 0.11.0",
|
||||
"rustc_data_structures",
|
||||
"rustc_errors",
|
||||
"rustc_fluent_macro",
|
||||
@ -4676,6 +4673,7 @@ version = "0.0.0"
|
||||
dependencies = [
|
||||
"bitflags 2.4.2",
|
||||
"derivative",
|
||||
"rustc_ast_ir",
|
||||
"rustc_data_structures",
|
||||
"rustc_index",
|
||||
"rustc_macros",
|
||||
@ -4701,7 +4699,7 @@ dependencies = [
|
||||
"askama",
|
||||
"expect-test",
|
||||
"indexmap",
|
||||
"itertools",
|
||||
"itertools 0.11.0",
|
||||
"minifier",
|
||||
"once_cell",
|
||||
"regex",
|
||||
@ -4783,7 +4781,7 @@ dependencies = [
|
||||
"dirs",
|
||||
"getopts",
|
||||
"ignore",
|
||||
"itertools",
|
||||
"itertools 0.11.0",
|
||||
"lazy_static",
|
||||
"regex",
|
||||
"rustfmt-config_proc_macro",
|
||||
@ -5045,6 +5043,16 @@ dependencies = [
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spanned"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad48ded9f0734eca7058107cc170767b8758e41e4088fb0020e7ff7ec6b0d92d"
|
||||
dependencies = [
|
||||
"bstr",
|
||||
"color-eyre",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spdx-expression"
|
||||
version = "0.5.2"
|
||||
@ -5796,6 +5804,34 @@ dependencies = [
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ui_test"
|
||||
version = "0.22.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b1ded30ff8c9d83e8d85d7e8e8aabbaf2c282a2b0ea09ef3f1accd4906134c7"
|
||||
dependencies = [
|
||||
"annotate-snippets 0.10.1",
|
||||
"anyhow",
|
||||
"bstr",
|
||||
"cargo-platform",
|
||||
"cargo_metadata 0.18.1",
|
||||
"color-eyre",
|
||||
"colored",
|
||||
"comma",
|
||||
"crossbeam-channel",
|
||||
"indicatif",
|
||||
"lazy_static",
|
||||
"levenshtein",
|
||||
"prettydiff",
|
||||
"regex",
|
||||
"rustc_version",
|
||||
"rustfix",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"spanned",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unic-langid"
|
||||
version = "0.9.4"
|
||||
|
@ -8,14 +8,13 @@ edition = "2021"
|
||||
# tidy-alphabetical-start
|
||||
bitflags = "2.4.1"
|
||||
memchr = "=2.5.0"
|
||||
rustc_ast_ir = { path = "../rustc_ast_ir" }
|
||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||
rustc_index = { path = "../rustc_index" }
|
||||
rustc_lexer = { path = "../rustc_lexer" }
|
||||
rustc_macros = { path = "../rustc_macros" }
|
||||
rustc_serialize = { path = "../rustc_serialize" }
|
||||
rustc_span = { path = "../rustc_span" }
|
||||
# For Mutability and Movability, which could be uplifted into a common crate.
|
||||
rustc_type_ir = { path = "../rustc_type_ir" }
|
||||
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
||||
thin-vec = "0.2.12"
|
||||
tracing = "0.1"
|
||||
|
@ -27,6 +27,7 @@ pub use UnsafeSource::*;
|
||||
use crate::ptr::P;
|
||||
use crate::token::{self, CommentKind, Delimiter};
|
||||
use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream};
|
||||
pub use rustc_ast_ir::{Movability, Mutability};
|
||||
use rustc_data_structures::packed::Pu128;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
@ -35,7 +36,6 @@ use rustc_macros::HashStable_Generic;
|
||||
use rustc_span::source_map::{respan, Spanned};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
|
||||
pub use rustc_type_ir::{Movability, Mutability};
|
||||
use std::fmt;
|
||||
use std::mem;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
22
compiler/rustc_ast_ir/Cargo.toml
Normal file
22
compiler/rustc_ast_ir/Cargo.toml
Normal file
@ -0,0 +1,22 @@
|
||||
[package]
|
||||
name = "rustc_ast_ir"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
# tidy-alphabetical-start
|
||||
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
|
||||
rustc_macros = { path = "../rustc_macros", optional = true }
|
||||
rustc_serialize = { path = "../rustc_serialize", optional = true }
|
||||
rustc_span = { path = "../rustc_span", optional = true }
|
||||
smallvec = { version = "1.8.1" }
|
||||
# tidy-alphabetical-end
|
||||
|
||||
[features]
|
||||
default = ["nightly"]
|
||||
nightly = [
|
||||
"rustc_serialize",
|
||||
"rustc_data_structures",
|
||||
"rustc_macros",
|
||||
"rustc_span",
|
||||
]
|
68
compiler/rustc_ast_ir/src/lib.rs
Normal file
68
compiler/rustc_ast_ir/src/lib.rs
Normal file
@ -0,0 +1,68 @@
|
||||
#![cfg_attr(feature = "nightly", feature(rustc_attrs))]
|
||||
#![cfg_attr(feature = "nightly", allow(internal_features))]
|
||||
|
||||
#[cfg(feature = "nightly")]
|
||||
#[macro_use]
|
||||
extern crate rustc_macros;
|
||||
|
||||
/// The movability of a coroutine / closure literal:
|
||||
/// whether a coroutine contains self-references, causing it to be `!Unpin`.
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
|
||||
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
|
||||
pub enum Movability {
|
||||
/// May contain self-references, `!Unpin`.
|
||||
Static,
|
||||
/// Must not contain self-references, `Unpin`.
|
||||
Movable,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
|
||||
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
|
||||
pub enum Mutability {
|
||||
// N.B. Order is deliberate, so that Not < Mut
|
||||
Not,
|
||||
Mut,
|
||||
}
|
||||
|
||||
impl Mutability {
|
||||
pub fn invert(self) -> Self {
|
||||
match self {
|
||||
Mutability::Mut => Mutability::Not,
|
||||
Mutability::Not => Mutability::Mut,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `""` (empty string) or `"mut "` depending on the mutability.
|
||||
pub fn prefix_str(self) -> &'static str {
|
||||
match self {
|
||||
Mutability::Mut => "mut ",
|
||||
Mutability::Not => "",
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `"&"` or `"&mut "` depending on the mutability.
|
||||
pub fn ref_prefix_str(self) -> &'static str {
|
||||
match self {
|
||||
Mutability::Not => "&",
|
||||
Mutability::Mut => "&mut ",
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `""` (empty string) or `"mutably "` depending on the mutability.
|
||||
pub fn mutably_str(self) -> &'static str {
|
||||
match self {
|
||||
Mutability::Not => "",
|
||||
Mutability::Mut => "mutably ",
|
||||
}
|
||||
}
|
||||
|
||||
/// Return `true` if self is mutable
|
||||
pub fn is_mut(self) -> bool {
|
||||
matches!(self, Self::Mut)
|
||||
}
|
||||
|
||||
/// Return `true` if self is **not** mutable
|
||||
pub fn is_not(self) -> bool {
|
||||
matches!(self, Self::Not)
|
||||
}
|
||||
}
|
@ -103,12 +103,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
span: Span,
|
||||
) -> Result<DefId, ErrorGuaranteed> {
|
||||
let sig_id = if self.is_in_trait_impl { item_id } else { path_id };
|
||||
let sig_id = self
|
||||
.resolver
|
||||
.get_partial_res(sig_id)
|
||||
.map(|r| r.expect_full_res().opt_def_id())
|
||||
.unwrap_or(None);
|
||||
|
||||
let sig_id =
|
||||
self.resolver.get_partial_res(sig_id).and_then(|r| r.expect_full_res().opt_def_id());
|
||||
sig_id.ok_or_else(|| {
|
||||
self.tcx
|
||||
.dcx()
|
||||
|
@ -1,6 +1,5 @@
|
||||
use rustc_errors::{
|
||||
codes::*, AddToDiagnostic, DiagnosticArgFromDisplay, DiagnosticBuilder, EmissionGuarantee,
|
||||
SubdiagnosticMessageOp,
|
||||
codes::*, AddToDiagnostic, Diag, DiagArgFromDisplay, EmissionGuarantee, SubdiagnosticMessageOp,
|
||||
};
|
||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||
use rustc_span::{symbol::Ident, Span, Symbol};
|
||||
@ -44,7 +43,7 @@ pub struct InvalidAbiReason(pub &'static str);
|
||||
impl AddToDiagnostic for InvalidAbiReason {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
_: F,
|
||||
) {
|
||||
#[allow(rustc::untranslatable_diagnostic)]
|
||||
@ -95,7 +94,7 @@ pub enum AssocTyParenthesesSub {
|
||||
pub struct MisplacedImplTrait<'a> {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub position: DiagnosticArgFromDisplay<'a>,
|
||||
pub position: DiagArgFromDisplay<'a>,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
@ -51,7 +51,7 @@ use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::sorted_map::SortedMap;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::{DiagCtxt, DiagnosticArgFromDisplay, StashKey};
|
||||
use rustc_errors::{DiagArgFromDisplay, DiagCtxt, StashKey};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
|
||||
use rustc_hir::def_id::{LocalDefId, LocalDefIdMap, CRATE_DEF_ID, LOCAL_CRATE};
|
||||
@ -1473,7 +1473,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
.create_feature_err(
|
||||
MisplacedImplTrait {
|
||||
span: t.span,
|
||||
position: DiagnosticArgFromDisplay(&position),
|
||||
position: DiagArgFromDisplay(&position),
|
||||
},
|
||||
feature,
|
||||
)
|
||||
@ -1483,7 +1483,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
ImplTraitContext::Disallowed(position) => {
|
||||
let guar = self.dcx().emit_err(MisplacedImplTrait {
|
||||
span: t.span,
|
||||
position: DiagnosticArgFromDisplay(&position),
|
||||
position: DiagArgFromDisplay(&position),
|
||||
});
|
||||
hir::TyKind::Err(guar)
|
||||
}
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
use rustc_ast::ParamKindOrd;
|
||||
use rustc_errors::{
|
||||
codes::*, AddToDiagnostic, Applicability, DiagnosticBuilder, EmissionGuarantee,
|
||||
SubdiagnosticMessageOp,
|
||||
codes::*, AddToDiagnostic, Applicability, Diag, EmissionGuarantee, SubdiagnosticMessageOp,
|
||||
};
|
||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||
use rustc_span::{symbol::Ident, Span, Symbol};
|
||||
@ -377,7 +376,7 @@ pub struct EmptyLabelManySpans(pub Vec<Span>);
|
||||
impl AddToDiagnostic for EmptyLabelManySpans {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
_: F,
|
||||
) {
|
||||
diag.span_labels(self.0, "");
|
||||
@ -738,7 +737,7 @@ pub struct StableFeature {
|
||||
impl AddToDiagnostic for StableFeature {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
_: F,
|
||||
) {
|
||||
diag.arg("name", self.name);
|
||||
|
@ -2,7 +2,7 @@ use std::num::IntErrorKind;
|
||||
|
||||
use rustc_ast as ast;
|
||||
use rustc_errors::{
|
||||
codes::*, Applicability, DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, Level,
|
||||
codes::*, Applicability, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level,
|
||||
};
|
||||
use rustc_macros::Diagnostic;
|
||||
use rustc_span::{Span, Symbol};
|
||||
@ -51,9 +51,9 @@ pub(crate) struct UnknownMetaItem<'a> {
|
||||
|
||||
// Manual implementation to be able to format `expected` items correctly.
|
||||
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UnknownMetaItem<'_> {
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> {
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
|
||||
let expected = self.expected.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>();
|
||||
DiagnosticBuilder::new(dcx, level, fluent::attr_unknown_meta_item)
|
||||
Diag::new(dcx, level, fluent::attr_unknown_meta_item)
|
||||
.with_span(self.span)
|
||||
.with_code(E0541)
|
||||
.with_arg("item", self.item)
|
||||
@ -198,8 +198,8 @@ pub(crate) struct UnsupportedLiteral {
|
||||
}
|
||||
|
||||
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for UnsupportedLiteral {
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> {
|
||||
let mut diag = DiagnosticBuilder::new(
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
|
||||
let mut diag = Diag::new(
|
||||
dcx,
|
||||
level,
|
||||
match self.reason {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![allow(rustc::diagnostic_outside_of_impl)]
|
||||
#![allow(rustc::untranslatable_diagnostic)]
|
||||
|
||||
use rustc_errors::{codes::*, struct_span_code_err, DiagCtxt, DiagnosticBuilder};
|
||||
use rustc_errors::{codes::*, struct_span_code_err, Diag, DiagCtxt};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_span::Span;
|
||||
|
||||
@ -17,7 +17,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
place: &str,
|
||||
borrow_place: &str,
|
||||
value_place: &str,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
self.dcx().create_err(crate::session_diagnostics::MoveBorrow {
|
||||
place,
|
||||
span,
|
||||
@ -33,7 +33,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
desc: &str,
|
||||
borrow_span: Span,
|
||||
borrow_desc: &str,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
@ -53,7 +53,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
old_loan_span: Span,
|
||||
old_opt_via: &str,
|
||||
old_load_end_span: Option<Span>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let via = |msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {msg})") };
|
||||
let mut err = struct_span_code_err!(
|
||||
self.dcx(),
|
||||
@ -100,7 +100,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
desc: &str,
|
||||
old_loan_span: Span,
|
||||
old_load_end_span: Option<Span>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let mut err = struct_span_code_err!(
|
||||
self.dcx(),
|
||||
new_loan_span,
|
||||
@ -133,7 +133,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
noun_old: &str,
|
||||
old_opt_via: &str,
|
||||
previous_end_span: Option<Span>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let mut err = struct_span_code_err!(
|
||||
self.dcx(),
|
||||
new_loan_span,
|
||||
@ -165,7 +165,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
old_opt_via: &str,
|
||||
previous_end_span: Option<Span>,
|
||||
second_borrow_desc: &str,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let mut err = struct_span_code_err!(
|
||||
self.dcx(),
|
||||
new_loan_span,
|
||||
@ -197,7 +197,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
kind_old: &str,
|
||||
msg_old: &str,
|
||||
old_load_end_span: Option<Span>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let via = |msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {msg})") };
|
||||
let mut err = struct_span_code_err!(
|
||||
self.dcx(),
|
||||
@ -238,7 +238,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
span: Span,
|
||||
borrow_span: Span,
|
||||
desc: &str,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
@ -255,12 +255,12 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
span: Span,
|
||||
desc: &str,
|
||||
is_arg: bool,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let msg = if is_arg { "to immutable argument" } else { "twice to immutable variable" };
|
||||
struct_span_code_err!(self.dcx(), span, E0384, "cannot assign {} {}", msg, desc)
|
||||
}
|
||||
|
||||
pub(crate) fn cannot_assign(&self, span: Span, desc: &str) -> DiagnosticBuilder<'tcx> {
|
||||
pub(crate) fn cannot_assign(&self, span: Span, desc: &str) -> Diag<'tcx> {
|
||||
struct_span_code_err!(self.dcx(), span, E0594, "cannot assign to {}", desc)
|
||||
}
|
||||
|
||||
@ -268,7 +268,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
&self,
|
||||
move_from_span: Span,
|
||||
move_from_desc: &str,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
move_from_span,
|
||||
@ -286,7 +286,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
move_from_span: Span,
|
||||
ty: Ty<'_>,
|
||||
is_index: Option<bool>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let type_name = match (&ty.kind(), is_index) {
|
||||
(&ty::Array(_, _), Some(true)) | (&ty::Array(_, _), None) => "array",
|
||||
(&ty::Slice(_), _) => "slice",
|
||||
@ -307,7 +307,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
&self,
|
||||
move_from_span: Span,
|
||||
container_ty: Ty<'_>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
move_from_span,
|
||||
@ -324,7 +324,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
verb: &str,
|
||||
optional_adverb_for_moved: &str,
|
||||
moved_path: Option<String>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let moved_path = moved_path.map(|mp| format!(": `{mp}`")).unwrap_or_default();
|
||||
|
||||
struct_span_code_err!(
|
||||
@ -343,7 +343,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
span: Span,
|
||||
path: &str,
|
||||
reason: &str,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
@ -361,7 +361,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
immutable_place: &str,
|
||||
immutable_section: &str,
|
||||
action: &str,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
mutate_span,
|
||||
@ -379,7 +379,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
&self,
|
||||
span: Span,
|
||||
yield_span: Span,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let coroutine_kind = self.body.coroutine.as_ref().unwrap().coroutine_kind;
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
@ -390,10 +390,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
.with_span_label(yield_span, "possible yield occurs here")
|
||||
}
|
||||
|
||||
pub(crate) fn cannot_borrow_across_destructor(
|
||||
&self,
|
||||
borrow_span: Span,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
pub(crate) fn cannot_borrow_across_destructor(&self, borrow_span: Span) -> Diag<'tcx> {
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
borrow_span,
|
||||
@ -402,11 +399,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn path_does_not_live_long_enough(
|
||||
&self,
|
||||
span: Span,
|
||||
path: &str,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
pub(crate) fn path_does_not_live_long_enough(&self, span: Span, path: &str) -> Diag<'tcx> {
|
||||
struct_span_code_err!(self.dcx(), span, E0597, "{} does not live long enough", path,)
|
||||
}
|
||||
|
||||
@ -416,7 +409,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
return_kind: &str,
|
||||
reference_desc: &str,
|
||||
path_desc: &str,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
@ -439,7 +432,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
borrowed_path: &str,
|
||||
capture_span: Span,
|
||||
scope: &str,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
closure_span,
|
||||
@ -451,10 +444,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
.with_span_label(closure_span, format!("may outlive borrowed value {borrowed_path}"))
|
||||
}
|
||||
|
||||
pub(crate) fn thread_local_value_does_not_live_long_enough(
|
||||
&self,
|
||||
span: Span,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
pub(crate) fn thread_local_value_does_not_live_long_enough(&self, span: Span) -> Diag<'tcx> {
|
||||
struct_span_code_err!(
|
||||
self.dcx(),
|
||||
span,
|
||||
@ -463,10 +453,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn temporary_value_borrowed_for_too_long(
|
||||
&self,
|
||||
span: Span,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
pub(crate) fn temporary_value_borrowed_for_too_long(&self, span: Span) -> Diag<'tcx> {
|
||||
struct_span_code_err!(self.dcx(), span, E0716, "temporary value dropped while borrowed",)
|
||||
}
|
||||
}
|
||||
@ -475,7 +462,7 @@ pub(crate) fn borrowed_data_escapes_closure<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
escape_span: Span,
|
||||
escapes_from: &str,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
struct_span_code_err!(
|
||||
tcx.dcx(),
|
||||
escape_span,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use rustc_errors::DiagnosticBuilder;
|
||||
use rustc_errors::Diag;
|
||||
use rustc_infer::infer::canonical::Canonical;
|
||||
use rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError;
|
||||
use rustc_infer::infer::region_constraints::Constraint;
|
||||
@ -144,7 +144,7 @@ impl<'tcx> ToUniverseInfo<'tcx> for ! {
|
||||
trait TypeOpInfo<'tcx> {
|
||||
/// Returns an error to be reported if rerunning the type op fails to
|
||||
/// recover the error's cause.
|
||||
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx>;
|
||||
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> Diag<'tcx>;
|
||||
|
||||
fn base_universe(&self) -> ty::UniverseIndex;
|
||||
|
||||
@ -154,7 +154,7 @@ trait TypeOpInfo<'tcx> {
|
||||
cause: ObligationCause<'tcx>,
|
||||
placeholder_region: ty::Region<'tcx>,
|
||||
error_region: Option<ty::Region<'tcx>>,
|
||||
) -> Option<DiagnosticBuilder<'tcx>>;
|
||||
) -> Option<Diag<'tcx>>;
|
||||
|
||||
#[instrument(level = "debug", skip(self, mbcx))]
|
||||
fn report_error(
|
||||
@ -217,7 +217,7 @@ struct PredicateQuery<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
|
||||
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> Diag<'tcx> {
|
||||
tcx.dcx().create_err(HigherRankedLifetimeError {
|
||||
cause: Some(HigherRankedErrorCause::CouldNotProve {
|
||||
predicate: self.canonical_query.value.value.predicate.to_string(),
|
||||
@ -236,7 +236,7 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
|
||||
cause: ObligationCause<'tcx>,
|
||||
placeholder_region: ty::Region<'tcx>,
|
||||
error_region: Option<ty::Region<'tcx>>,
|
||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
) -> Option<Diag<'tcx>> {
|
||||
let (infcx, key, _) =
|
||||
mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
|
||||
let ocx = ObligationCtxt::new(&infcx);
|
||||
@ -254,7 +254,7 @@ impl<'tcx, T> TypeOpInfo<'tcx> for NormalizeQuery<'tcx, T>
|
||||
where
|
||||
T: Copy + fmt::Display + TypeFoldable<TyCtxt<'tcx>> + 'tcx,
|
||||
{
|
||||
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> Diag<'tcx> {
|
||||
tcx.dcx().create_err(HigherRankedLifetimeError {
|
||||
cause: Some(HigherRankedErrorCause::CouldNotNormalize {
|
||||
value: self.canonical_query.value.value.value.to_string(),
|
||||
@ -273,7 +273,7 @@ where
|
||||
cause: ObligationCause<'tcx>,
|
||||
placeholder_region: ty::Region<'tcx>,
|
||||
error_region: Option<ty::Region<'tcx>>,
|
||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
) -> Option<Diag<'tcx>> {
|
||||
let (infcx, key, _) =
|
||||
mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
|
||||
let ocx = ObligationCtxt::new(&infcx);
|
||||
@ -297,7 +297,7 @@ struct AscribeUserTypeQuery<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
|
||||
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> Diag<'tcx> {
|
||||
// FIXME: This error message isn't great, but it doesn't show up in the existing UI tests,
|
||||
// and is only the fallback when the nice error fails. Consider improving this some more.
|
||||
tcx.dcx().create_err(HigherRankedLifetimeError { cause: None, span })
|
||||
@ -313,7 +313,7 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
|
||||
cause: ObligationCause<'tcx>,
|
||||
placeholder_region: ty::Region<'tcx>,
|
||||
error_region: Option<ty::Region<'tcx>>,
|
||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
) -> Option<Diag<'tcx>> {
|
||||
let (infcx, key, _) =
|
||||
mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
|
||||
let ocx = ObligationCtxt::new(&infcx);
|
||||
@ -323,7 +323,7 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
|
||||
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> Diag<'tcx> {
|
||||
// FIXME: This error message isn't great, but it doesn't show up in the existing UI tests,
|
||||
// and is only the fallback when the nice error fails. Consider improving this some more.
|
||||
tcx.dcx().create_err(HigherRankedLifetimeError { cause: None, span })
|
||||
@ -339,7 +339,7 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
|
||||
_cause: ObligationCause<'tcx>,
|
||||
placeholder_region: ty::Region<'tcx>,
|
||||
error_region: Option<ty::Region<'tcx>>,
|
||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
) -> Option<Diag<'tcx>> {
|
||||
try_extract_error_from_region_constraints(
|
||||
mbcx.infcx,
|
||||
placeholder_region,
|
||||
@ -360,7 +360,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
|
||||
ocx: &ObligationCtxt<'_, 'tcx>,
|
||||
placeholder_region: ty::Region<'tcx>,
|
||||
error_region: Option<ty::Region<'tcx>>,
|
||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
) -> Option<Diag<'tcx>> {
|
||||
// We generally shouldn't have errors here because the query was
|
||||
// already run, but there's no point using `span_delayed_bug`
|
||||
// when we're going to emit an error here anyway.
|
||||
@ -384,7 +384,7 @@ fn try_extract_error_from_region_constraints<'tcx>(
|
||||
region_constraints: &RegionConstraintData<'tcx>,
|
||||
mut region_var_origin: impl FnMut(RegionVid) -> RegionVariableOrigin,
|
||||
mut universe_of_region: impl FnMut(RegionVid) -> UniverseIndex,
|
||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
) -> Option<Diag<'tcx>> {
|
||||
let placeholder_universe = match placeholder_region.kind() {
|
||||
ty::RePlaceholder(p) => p.universe,
|
||||
ty::ReVar(vid) => universe_of_region(vid),
|
||||
|
@ -6,7 +6,7 @@
|
||||
use either::Either;
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_errors::{codes::*, struct_span_code_err, Applicability, DiagnosticBuilder, MultiSpan};
|
||||
use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag, MultiSpan};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
|
||||
@ -334,7 +334,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
&mut self,
|
||||
mpi: MovePathIndex,
|
||||
move_span: Span,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
err: &mut Diag<'tcx>,
|
||||
in_pattern: &mut bool,
|
||||
move_spans: UseSpans<'_>,
|
||||
) {
|
||||
@ -486,7 +486,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
desired_action: InitializationRequiringAction,
|
||||
span: Span,
|
||||
use_spans: UseSpans<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
// We need all statements in the body where the binding was assigned to later find all
|
||||
// the branching code paths where the binding *wasn't* assigned to.
|
||||
let inits = &self.move_data.init_path_map[mpi];
|
||||
@ -633,7 +633,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
|
||||
fn suggest_assign_value(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
moved_place: PlaceRef<'tcx>,
|
||||
sugg_span: Span,
|
||||
) {
|
||||
@ -672,7 +672,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
|
||||
fn suggest_borrow_fn_like(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
ty: Ty<'tcx>,
|
||||
move_sites: &[MoveSite],
|
||||
value_name: &str,
|
||||
@ -738,13 +738,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
true
|
||||
}
|
||||
|
||||
fn suggest_cloning(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
ty: Ty<'tcx>,
|
||||
expr: &hir::Expr<'_>,
|
||||
span: Span,
|
||||
) {
|
||||
fn suggest_cloning(&self, err: &mut Diag<'_>, ty: Ty<'tcx>, expr: &hir::Expr<'_>, span: Span) {
|
||||
let tcx = self.infcx.tcx;
|
||||
// Try to find predicates on *generic params* that would allow copying `ty`
|
||||
let suggestion =
|
||||
@ -776,12 +770,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn suggest_adding_copy_bounds(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
ty: Ty<'tcx>,
|
||||
span: Span,
|
||||
) {
|
||||
fn suggest_adding_copy_bounds(&self, err: &mut Diag<'_>, ty: Ty<'tcx>, span: Span) {
|
||||
let tcx = self.infcx.tcx;
|
||||
let generics = tcx.generics_of(self.mir_def_id());
|
||||
|
||||
@ -891,7 +880,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
location: Location,
|
||||
(place, _span): (Place<'tcx>, Span),
|
||||
borrow: &BorrowData<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let borrow_spans = self.retrieve_borrow_spans(borrow);
|
||||
let borrow_span = borrow_spans.args_or_use();
|
||||
|
||||
@ -941,7 +930,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
(place, span): (Place<'tcx>, Span),
|
||||
gen_borrow_kind: BorrowKind,
|
||||
issued_borrow: &BorrowData<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let issued_spans = self.retrieve_borrow_spans(issued_borrow);
|
||||
let issued_span = issued_spans.args_or_use();
|
||||
|
||||
@ -1228,7 +1217,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
#[instrument(level = "debug", skip(self, err))]
|
||||
fn suggest_using_local_if_applicable(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
location: Location,
|
||||
issued_borrow: &BorrowData<'tcx>,
|
||||
explanation: BorrowExplanation<'tcx>,
|
||||
@ -1324,7 +1313,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
|
||||
fn suggest_slice_method_if_applicable(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
place: Place<'tcx>,
|
||||
borrowed_place: Place<'tcx>,
|
||||
) {
|
||||
@ -1433,7 +1422,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
/// ```
|
||||
pub(crate) fn explain_iterator_advancement_in_for_loop_if_applicable(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
span: Span,
|
||||
issued_spans: &UseSpans<'tcx>,
|
||||
) {
|
||||
@ -1620,7 +1609,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
/// ```
|
||||
fn suggest_using_closure_argument_instead_of_capture(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
borrowed_place: Place<'tcx>,
|
||||
issued_spans: &UseSpans<'tcx>,
|
||||
) {
|
||||
@ -1754,7 +1743,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
|
||||
fn suggest_binding_for_closure_capture_self(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
issued_spans: &UseSpans<'tcx>,
|
||||
) {
|
||||
let UseSpans::ClosureUse { capture_kind_span, .. } = issued_spans else { return };
|
||||
@ -2149,7 +2138,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
drop_span: Span,
|
||||
borrow_spans: UseSpans<'tcx>,
|
||||
explanation: BorrowExplanation<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
debug!(
|
||||
"report_local_value_does_not_live_long_enough(\
|
||||
{:?}, {:?}, {:?}, {:?}, {:?}\
|
||||
@ -2324,7 +2313,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
&mut self,
|
||||
drop_span: Span,
|
||||
borrow_span: Span,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
debug!(
|
||||
"report_thread_local_value_does_not_live_long_enough(\
|
||||
{:?}, {:?}\
|
||||
@ -2349,7 +2338,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
borrow_spans: UseSpans<'tcx>,
|
||||
proper_span: Span,
|
||||
explanation: BorrowExplanation<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
if let BorrowExplanation::MustBeValidFor { category, span, from_closure: false, .. } =
|
||||
explanation
|
||||
{
|
||||
@ -2515,7 +2504,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
return_span: Span,
|
||||
category: ConstraintCategory<'tcx>,
|
||||
opt_place_desc: Option<&String>,
|
||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
) -> Option<Diag<'tcx>> {
|
||||
let return_kind = match category {
|
||||
ConstraintCategory::Return(_) => "return",
|
||||
ConstraintCategory::Yield => "yield",
|
||||
@ -2610,7 +2599,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
constraint_span: Span,
|
||||
captured_var: &str,
|
||||
scope: &str,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let tcx = self.infcx.tcx;
|
||||
let args_span = use_span.args_or_use();
|
||||
|
||||
@ -2718,7 +2707,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
upvar_span: Span,
|
||||
upvar_name: Symbol,
|
||||
escape_span: Span,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let tcx = self.infcx.tcx;
|
||||
|
||||
let escapes_from = tcx.def_descr(self.mir_def_id().to_def_id());
|
||||
@ -3000,7 +2989,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
self.buffer_error(err);
|
||||
}
|
||||
|
||||
fn explain_deref_coercion(&mut self, loan: &BorrowData<'tcx>, err: &mut DiagnosticBuilder<'_>) {
|
||||
fn explain_deref_coercion(&mut self, loan: &BorrowData<'tcx>, err: &mut Diag<'_>) {
|
||||
let tcx = self.infcx.tcx;
|
||||
if let (
|
||||
Some(Terminator {
|
||||
@ -3535,11 +3524,7 @@ enum AnnotatedBorrowFnSignature<'tcx> {
|
||||
impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
|
||||
/// Annotate the provided diagnostic with information about borrow from the fn signature that
|
||||
/// helps explain.
|
||||
pub(crate) fn emit(
|
||||
&self,
|
||||
cx: &mut MirBorrowckCtxt<'_, 'tcx>,
|
||||
diag: &mut DiagnosticBuilder<'_>,
|
||||
) -> String {
|
||||
pub(crate) fn emit(&self, cx: &mut MirBorrowckCtxt<'_, 'tcx>, diag: &mut Diag<'_>) -> String {
|
||||
match self {
|
||||
&AnnotatedBorrowFnSignature::Closure { argument_ty, argument_span } => {
|
||||
diag.span_label(
|
||||
|
@ -3,7 +3,7 @@
|
||||
#![allow(rustc::diagnostic_outside_of_impl)]
|
||||
#![allow(rustc::untranslatable_diagnostic)]
|
||||
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
||||
use rustc_errors::{Applicability, Diag};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_index::IndexSlice;
|
||||
@ -65,7 +65,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
body: &Body<'tcx>,
|
||||
local_names: &IndexSlice<Local, Option<Symbol>>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
borrow_desc: &str,
|
||||
borrow_span: Option<Span>,
|
||||
multiple_borrow_span: Option<(Span, Span)>,
|
||||
@ -306,7 +306,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
|
||||
fn add_object_lifetime_default_note(
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
unsize_ty: Ty<'tcx>,
|
||||
) {
|
||||
if let ty::Adt(def, args) = unsize_ty.kind() {
|
||||
@ -359,7 +359,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
|
||||
|
||||
fn add_lifetime_bound_suggestion_to_diagnostic(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
category: &ConstraintCategory<'tcx>,
|
||||
span: Span,
|
||||
region_name: &RegionName,
|
||||
|
@ -5,7 +5,7 @@ use crate::session_diagnostics::{
|
||||
CaptureVarKind, CaptureVarPathUseCause, OnClosureNote,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
||||
use rustc_errors::{Applicability, Diag};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorKind, Namespace};
|
||||
use rustc_hir::CoroutineKind;
|
||||
@ -80,7 +80,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
&self,
|
||||
location: Location,
|
||||
place: PlaceRef<'tcx>,
|
||||
diag: &mut DiagnosticBuilder<'_>,
|
||||
diag: &mut Diag<'_>,
|
||||
) -> bool {
|
||||
debug!("add_moved_or_invoked_closure_note: location={:?} place={:?}", location, place);
|
||||
let mut target = place.local_or_deref_local();
|
||||
@ -588,7 +588,7 @@ impl UseSpans<'_> {
|
||||
pub(super) fn args_subdiag(
|
||||
self,
|
||||
dcx: &rustc_errors::DiagCtxt,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
f: impl FnOnce(Span) -> CaptureArgLabel,
|
||||
) {
|
||||
if let UseSpans::ClosureUse { args_span, .. } = self {
|
||||
@ -601,7 +601,7 @@ impl UseSpans<'_> {
|
||||
pub(super) fn var_path_only_subdiag(
|
||||
self,
|
||||
dcx: &rustc_errors::DiagCtxt,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
action: crate::InitializationRequiringAction,
|
||||
) {
|
||||
use crate::InitializationRequiringAction::*;
|
||||
@ -638,7 +638,7 @@ impl UseSpans<'_> {
|
||||
pub(super) fn var_subdiag(
|
||||
self,
|
||||
dcx: &rustc_errors::DiagCtxt,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
kind: Option<rustc_middle::mir::BorrowKind>,
|
||||
f: impl FnOnce(hir::ClosureKind, Span) -> CaptureVarCause,
|
||||
) {
|
||||
@ -1010,7 +1010,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
|
||||
fn explain_captures(
|
||||
&mut self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
span: Span,
|
||||
move_span: Span,
|
||||
move_spans: UseSpans<'tcx>,
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![allow(rustc::diagnostic_outside_of_impl)]
|
||||
#![allow(rustc::untranslatable_diagnostic)]
|
||||
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
||||
use rustc_errors::{Applicability, Diag};
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_mir_dataflow::move_paths::{LookupResult, MovePathIndex};
|
||||
@ -287,11 +287,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
self.buffer_error(err);
|
||||
}
|
||||
|
||||
fn report_cannot_move_from_static(
|
||||
&mut self,
|
||||
place: Place<'tcx>,
|
||||
span: Span,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
fn report_cannot_move_from_static(&mut self, place: Place<'tcx>, span: Span) -> Diag<'tcx> {
|
||||
let description = if place.projection.len() == 1 {
|
||||
format!("static item {}", self.describe_any_place(place.as_ref()))
|
||||
} else {
|
||||
@ -313,7 +309,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
deref_target_place: Place<'tcx>,
|
||||
span: Span,
|
||||
use_spans: Option<UseSpans<'tcx>>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
// Inspect the type of the content behind the
|
||||
// borrow to provide feedback about why this
|
||||
// was a move rather than a copy.
|
||||
@ -437,12 +433,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
err
|
||||
}
|
||||
|
||||
fn add_move_hints(
|
||||
&self,
|
||||
error: GroupedMoveError<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
span: Span,
|
||||
) {
|
||||
fn add_move_hints(&self, error: GroupedMoveError<'tcx>, err: &mut Diag<'_>, span: Span) {
|
||||
match error {
|
||||
GroupedMoveError::MovesFromPlace { mut binds_to, move_from, .. } => {
|
||||
self.add_borrow_suggestions(err, span);
|
||||
@ -505,7 +496,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_borrow_suggestions(&self, err: &mut DiagnosticBuilder<'_>, span: Span) {
|
||||
fn add_borrow_suggestions(&self, err: &mut Diag<'_>, span: Span) {
|
||||
match self.infcx.tcx.sess.source_map().span_to_snippet(span) {
|
||||
Ok(snippet) if snippet.starts_with('*') => {
|
||||
err.span_suggestion_verbose(
|
||||
@ -526,7 +517,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_move_error_suggestions(&self, err: &mut DiagnosticBuilder<'_>, binds_to: &[Local]) {
|
||||
fn add_move_error_suggestions(&self, err: &mut Diag<'_>, binds_to: &[Local]) {
|
||||
let mut suggestions: Vec<(Span, String, String)> = Vec::new();
|
||||
for local in binds_to {
|
||||
let bind_to = &self.body.local_decls[*local];
|
||||
@ -578,7 +569,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_move_error_details(&self, err: &mut DiagnosticBuilder<'_>, binds_to: &[Local]) {
|
||||
fn add_move_error_details(&self, err: &mut Diag<'_>, binds_to: &[Local]) {
|
||||
for (j, local) in binds_to.iter().enumerate() {
|
||||
let bind_to = &self.body.local_decls[*local];
|
||||
let binding_span = bind_to.source_info.span;
|
||||
@ -615,7 +606,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
/// expansion of a packed struct.
|
||||
/// Such errors happen because derive macro expansions shy away from taking
|
||||
/// references to the struct's fields since doing so would be undefined behaviour
|
||||
fn add_note_for_packed_struct_derive(&self, err: &mut DiagnosticBuilder<'_>, local: Local) {
|
||||
fn add_note_for_packed_struct_derive(&self, err: &mut Diag<'_>, local: Local) {
|
||||
let local_place: PlaceRef<'tcx> = local.into();
|
||||
let local_ty = local_place.ty(self.body.local_decls(), self.infcx.tcx).ty.peel_refs();
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
#![allow(rustc::untranslatable_diagnostic)]
|
||||
|
||||
use hir::ExprKind;
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
||||
use rustc_errors::{Applicability, Diag};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_hir::Node;
|
||||
@ -540,12 +540,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn suggest_map_index_mut_alternatives(
|
||||
&self,
|
||||
ty: Ty<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'tcx>,
|
||||
span: Span,
|
||||
) {
|
||||
fn suggest_map_index_mut_alternatives(&self, ty: Ty<'tcx>, err: &mut Diag<'tcx>, span: Span) {
|
||||
let Some(adt) = ty.ty_adt_def() else { return };
|
||||
let did = adt.did();
|
||||
if self.infcx.tcx.is_diagnostic_item(sym::HashMap, did)
|
||||
@ -553,7 +548,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
{
|
||||
struct V<'a, 'tcx> {
|
||||
assign_span: Span,
|
||||
err: &'a mut DiagnosticBuilder<'tcx>,
|
||||
err: &'a mut Diag<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
suggested: bool,
|
||||
}
|
||||
@ -717,7 +712,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
|
||||
fn construct_mut_suggestion_for_local_binding_patterns(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
local: Local,
|
||||
) {
|
||||
let local_decl = &self.body.local_decls[local];
|
||||
@ -795,7 +790,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
tcx: TyCtxt<'_>,
|
||||
closure_local_def_id: hir::def_id::LocalDefId,
|
||||
the_place_err: PlaceRef<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
) {
|
||||
let tables = tcx.typeck(closure_local_def_id);
|
||||
if let Some((span, closure_kind_origin)) = tcx.closure_kind_origin(closure_local_def_id) {
|
||||
@ -857,7 +852,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
|
||||
// Attempt to search similar mutable associated items for suggestion.
|
||||
// In the future, attempt in all path but initially for RHS of for_loop
|
||||
fn suggest_similar_mut_method_for_for_loop(&self, err: &mut DiagnosticBuilder<'_>, span: Span) {
|
||||
fn suggest_similar_mut_method_for_for_loop(&self, err: &mut Diag<'_>, span: Span) {
|
||||
use hir::{
|
||||
BorrowKind, Expr,
|
||||
ExprKind::{AddrOf, Block, Call, MethodCall},
|
||||
@ -941,7 +936,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
}
|
||||
|
||||
/// Targeted error when encountering an `FnMut` closure where an `Fn` closure was expected.
|
||||
fn expected_fn_found_fn_mut_call(&self, err: &mut DiagnosticBuilder<'_>, sp: Span, act: &str) {
|
||||
fn expected_fn_found_fn_mut_call(&self, err: &mut Diag<'_>, sp: Span, act: &str) {
|
||||
err.span_label(sp, format!("cannot {act}"));
|
||||
|
||||
let hir = self.infcx.tcx.hir();
|
||||
@ -1031,7 +1026,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn suggest_using_iter_mut(&self, err: &mut DiagnosticBuilder<'_>) {
|
||||
fn suggest_using_iter_mut(&self, err: &mut Diag<'_>) {
|
||||
let source = self.body.source;
|
||||
let hir = self.infcx.tcx.hir();
|
||||
if let InstanceDef::Item(def_id) = source.instance
|
||||
@ -1072,7 +1067,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn suggest_make_local_mut(&self, err: &mut DiagnosticBuilder<'_>, local: Local, name: Symbol) {
|
||||
fn suggest_make_local_mut(&self, err: &mut Diag<'_>, local: Local, name: Symbol) {
|
||||
let local_decl = &self.body.local_decls[local];
|
||||
|
||||
let (pointer_sigil, pointer_desc) =
|
||||
|
@ -5,7 +5,7 @@
|
||||
#![allow(rustc::untranslatable_diagnostic)]
|
||||
|
||||
use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_errors::DiagnosticBuilder;
|
||||
use rustc_errors::Diag;
|
||||
use rustc_middle::ty::RegionVid;
|
||||
use smallvec::SmallVec;
|
||||
use std::collections::BTreeMap;
|
||||
@ -157,13 +157,12 @@ impl OutlivesSuggestionBuilder {
|
||||
self.constraints_to_add.entry(fr).or_default().push(outlived_fr);
|
||||
}
|
||||
|
||||
/// Emit an intermediate note on the given `DiagnosticBuilder` if the involved regions are
|
||||
/// suggestable.
|
||||
/// Emit an intermediate note on the given `Diag` if the involved regions are suggestable.
|
||||
pub(crate) fn intermediate_suggestion(
|
||||
&mut self,
|
||||
mbcx: &MirBorrowckCtxt<'_, '_>,
|
||||
errci: &ErrorConstraintInfo<'_>,
|
||||
diag: &mut DiagnosticBuilder<'_>,
|
||||
diag: &mut Diag<'_>,
|
||||
) {
|
||||
// Emit an intermediate note.
|
||||
let fr_name = self.region_vid_to_name(mbcx, errci.fr);
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! Error reporting machinery for lifetime errors.
|
||||
|
||||
use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder, MultiSpan};
|
||||
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::Res::Def;
|
||||
use rustc_hir::def_id::DefId;
|
||||
@ -73,7 +73,7 @@ impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> {
|
||||
///
|
||||
/// Usually we expect this to either be empty or contain a small number of items, so we can avoid
|
||||
/// allocation most of the time.
|
||||
pub(crate) struct RegionErrors<'tcx>(Vec<RegionErrorKind<'tcx>>, TyCtxt<'tcx>);
|
||||
pub(crate) struct RegionErrors<'tcx>(Vec<(RegionErrorKind<'tcx>, ErrorGuaranteed)>, TyCtxt<'tcx>);
|
||||
|
||||
impl<'tcx> RegionErrors<'tcx> {
|
||||
pub fn new(tcx: TyCtxt<'tcx>) -> Self {
|
||||
@ -82,15 +82,18 @@ impl<'tcx> RegionErrors<'tcx> {
|
||||
#[track_caller]
|
||||
pub fn push(&mut self, val: impl Into<RegionErrorKind<'tcx>>) {
|
||||
let val = val.into();
|
||||
self.1.sess.dcx().delayed_bug(format!("{val:?}"));
|
||||
self.0.push(val);
|
||||
let guar = self.1.sess.dcx().delayed_bug(format!("{val:?}"));
|
||||
self.0.push((val, guar));
|
||||
}
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
pub fn into_iter(self) -> impl Iterator<Item = RegionErrorKind<'tcx>> {
|
||||
pub fn into_iter(self) -> impl Iterator<Item = (RegionErrorKind<'tcx>, ErrorGuaranteed)> {
|
||||
self.0.into_iter()
|
||||
}
|
||||
pub fn has_errors(&self) -> Option<ErrorGuaranteed> {
|
||||
self.0.get(0).map(|x| x.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for RegionErrors<'_> {
|
||||
@ -200,7 +203,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
// and the span which bounded to the trait for adding 'static lifetime suggestion
|
||||
fn suggest_static_lifetime_for_gat_from_hrtb(
|
||||
&self,
|
||||
diag: &mut DiagnosticBuilder<'_>,
|
||||
diag: &mut Diag<'_>,
|
||||
lower_bound: RegionVid,
|
||||
) {
|
||||
let mut suggestions = vec![];
|
||||
@ -304,10 +307,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
let mut last_unexpected_hidden_region: Option<(Span, Ty<'_>, ty::OpaqueTypeKey<'tcx>)> =
|
||||
None;
|
||||
|
||||
for nll_error in nll_errors.into_iter() {
|
||||
for (nll_error, _) in nll_errors.into_iter() {
|
||||
match nll_error {
|
||||
RegionErrorKind::TypeTestError { type_test } => {
|
||||
// Try to convert the lower-bound region into something named we can print for the user.
|
||||
// Try to convert the lower-bound region into something named we can print for
|
||||
// the user.
|
||||
let lower_bound_region = self.to_error_region(type_test.lower_bound);
|
||||
|
||||
let type_test_span = type_test.span;
|
||||
@ -580,7 +584,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
&self,
|
||||
errci: &ErrorConstraintInfo<'tcx>,
|
||||
kind: ReturnConstraint,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let ErrorConstraintInfo { outlived_fr, span, .. } = errci;
|
||||
|
||||
let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty;
|
||||
@ -649,10 +653,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
/// | ^^^^^^^^^^ `x` escapes the function body here
|
||||
/// ```
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
fn report_escaping_data_error(
|
||||
&self,
|
||||
errci: &ErrorConstraintInfo<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
fn report_escaping_data_error(&self, errci: &ErrorConstraintInfo<'tcx>) -> Diag<'tcx> {
|
||||
let ErrorConstraintInfo { span, category, .. } = errci;
|
||||
|
||||
let fr_name_and_span = self.regioncx.get_var_name_and_span_for_region(
|
||||
@ -760,7 +761,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
/// | ^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'a` but it
|
||||
/// | is returning data with lifetime `'b`
|
||||
/// ```
|
||||
fn report_general_error(&self, errci: &ErrorConstraintInfo<'tcx>) -> DiagnosticBuilder<'tcx> {
|
||||
fn report_general_error(&self, errci: &ErrorConstraintInfo<'tcx>) -> Diag<'tcx> {
|
||||
let ErrorConstraintInfo {
|
||||
fr,
|
||||
fr_is_local,
|
||||
@ -823,7 +824,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
/// ```
|
||||
fn add_static_impl_trait_suggestion(
|
||||
&self,
|
||||
diag: &mut DiagnosticBuilder<'_>,
|
||||
diag: &mut Diag<'_>,
|
||||
fr: RegionVid,
|
||||
// We need to pass `fr_name` - computing it again will label it twice.
|
||||
fr_name: RegionName,
|
||||
@ -912,7 +913,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
|
||||
fn maybe_suggest_constrain_dyn_trait_impl(
|
||||
&self,
|
||||
diag: &mut DiagnosticBuilder<'_>,
|
||||
diag: &mut Diag<'_>,
|
||||
f: Region<'tcx>,
|
||||
o: Region<'tcx>,
|
||||
category: &ConstraintCategory<'tcx>,
|
||||
@ -974,7 +975,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
#[instrument(skip(self, err), level = "debug")]
|
||||
fn suggest_constrain_dyn_trait_in_impl(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
found_dids: &FxIndexSet<DefId>,
|
||||
ident: Ident,
|
||||
self_ty: &hir::Ty<'_>,
|
||||
@ -1007,12 +1008,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
suggested
|
||||
}
|
||||
|
||||
fn suggest_adding_lifetime_params(
|
||||
&self,
|
||||
diag: &mut DiagnosticBuilder<'_>,
|
||||
sub: RegionVid,
|
||||
sup: RegionVid,
|
||||
) {
|
||||
fn suggest_adding_lifetime_params(&self, diag: &mut Diag<'_>, sub: RegionVid, sup: RegionVid) {
|
||||
let (Some(sub), Some(sup)) = (self.to_error_region(sub), self.to_error_region(sup)) else {
|
||||
return;
|
||||
};
|
||||
@ -1038,7 +1034,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||
suggest_adding_lifetime_params(self.infcx.tcx, sub, ty_sup, ty_sub, diag);
|
||||
}
|
||||
|
||||
fn suggest_move_on_borrowing_closure(&self, diag: &mut DiagnosticBuilder<'_>) {
|
||||
fn suggest_move_on_borrowing_closure(&self, diag: &mut Diag<'_>) {
|
||||
let map = self.infcx.tcx.hir();
|
||||
let body_id = map.body_owned_by(self.mir_def_id());
|
||||
let expr = &map.body(body_id).value.peel_blocks();
|
||||
|
@ -5,7 +5,7 @@ use std::fmt::{self, Display};
|
||||
use std::iter;
|
||||
|
||||
use rustc_data_structures::fx::IndexEntry;
|
||||
use rustc_errors::DiagnosticBuilder;
|
||||
use rustc_errors::Diag;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_middle::ty::print::RegionHighlightMode;
|
||||
@ -106,7 +106,7 @@ impl RegionName {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn highlight_region_name(&self, diag: &mut DiagnosticBuilder<'_>) {
|
||||
pub(crate) fn highlight_region_name(&self, diag: &mut Diag<'_>) {
|
||||
match &self.source {
|
||||
RegionNameSource::NamedLateParamRegion(span)
|
||||
| RegionNameSource::NamedEarlyParamRegion(span) => {
|
||||
@ -192,7 +192,7 @@ impl Display for RegionName {
|
||||
}
|
||||
|
||||
impl rustc_errors::IntoDiagnosticArg for RegionName {
|
||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue {
|
||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue {
|
||||
self.to_string().into_diagnostic_arg()
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ extern crate tracing;
|
||||
|
||||
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::graph::dominators::Dominators;
|
||||
use rustc_errors::DiagnosticBuilder;
|
||||
use rustc_errors::Diag;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_index::bit_set::{BitSet, ChunkedBitSet};
|
||||
@ -2395,8 +2395,8 @@ mod diags {
|
||||
use super::*;
|
||||
|
||||
enum BufferedDiag<'tcx> {
|
||||
Error(DiagnosticBuilder<'tcx>),
|
||||
NonError(DiagnosticBuilder<'tcx, ()>),
|
||||
Error(Diag<'tcx>),
|
||||
NonError(Diag<'tcx, ()>),
|
||||
}
|
||||
|
||||
impl<'tcx> BufferedDiag<'tcx> {
|
||||
@ -2423,10 +2423,9 @@ mod diags {
|
||||
/// `BTreeMap` is used to preserve the order of insertions when iterating. This is necessary
|
||||
/// when errors in the map are being re-added to the error buffer so that errors with the
|
||||
/// same primary span come out in a consistent order.
|
||||
buffered_move_errors:
|
||||
BTreeMap<Vec<MoveOutIndex>, (PlaceRef<'tcx>, DiagnosticBuilder<'tcx>)>,
|
||||
buffered_move_errors: BTreeMap<Vec<MoveOutIndex>, (PlaceRef<'tcx>, Diag<'tcx>)>,
|
||||
|
||||
buffered_mut_errors: FxIndexMap<Span, (DiagnosticBuilder<'tcx>, usize)>,
|
||||
buffered_mut_errors: FxIndexMap<Span, (Diag<'tcx>, usize)>,
|
||||
|
||||
/// Buffer of diagnostics to be reported. A mixture of error and non-error diagnostics.
|
||||
buffered_diags: Vec<BufferedDiag<'tcx>>,
|
||||
@ -2441,28 +2440,28 @@ mod diags {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn buffer_error(&mut self, t: DiagnosticBuilder<'tcx>) {
|
||||
self.buffered_diags.push(BufferedDiag::Error(t));
|
||||
pub fn buffer_error(&mut self, diag: Diag<'tcx>) {
|
||||
self.buffered_diags.push(BufferedDiag::Error(diag));
|
||||
}
|
||||
|
||||
pub fn buffer_non_error(&mut self, t: DiagnosticBuilder<'tcx, ()>) {
|
||||
self.buffered_diags.push(BufferedDiag::NonError(t));
|
||||
pub fn buffer_non_error(&mut self, diag: Diag<'tcx, ()>) {
|
||||
self.buffered_diags.push(BufferedDiag::NonError(diag));
|
||||
}
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
pub fn buffer_error(&mut self, t: DiagnosticBuilder<'tcx>) {
|
||||
self.diags.buffer_error(t);
|
||||
pub fn buffer_error(&mut self, diag: Diag<'tcx>) {
|
||||
self.diags.buffer_error(diag);
|
||||
}
|
||||
|
||||
pub fn buffer_non_error(&mut self, t: DiagnosticBuilder<'tcx, ()>) {
|
||||
self.diags.buffer_non_error(t);
|
||||
pub fn buffer_non_error(&mut self, diag: Diag<'tcx, ()>) {
|
||||
self.diags.buffer_non_error(diag);
|
||||
}
|
||||
|
||||
pub fn buffer_move_error(
|
||||
&mut self,
|
||||
move_out_indices: Vec<MoveOutIndex>,
|
||||
place_and_err: (PlaceRef<'tcx>, DiagnosticBuilder<'tcx>),
|
||||
place_and_err: (PlaceRef<'tcx>, Diag<'tcx>),
|
||||
) -> bool {
|
||||
if let Some((_, diag)) =
|
||||
self.diags.buffered_move_errors.insert(move_out_indices, place_and_err)
|
||||
@ -2475,16 +2474,13 @@ mod diags {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_buffered_mut_error(
|
||||
&mut self,
|
||||
span: Span,
|
||||
) -> Option<(DiagnosticBuilder<'tcx>, usize)> {
|
||||
pub fn get_buffered_mut_error(&mut self, span: Span) -> Option<(Diag<'tcx>, usize)> {
|
||||
// FIXME(#120456) - is `swap_remove` correct?
|
||||
self.diags.buffered_mut_errors.swap_remove(&span)
|
||||
}
|
||||
|
||||
pub fn buffer_mut_error(&mut self, span: Span, t: DiagnosticBuilder<'tcx>, count: usize) {
|
||||
self.diags.buffered_mut_errors.insert(span, (t, count));
|
||||
pub fn buffer_mut_error(&mut self, span: Span, diag: Diag<'tcx>, count: usize) {
|
||||
self.diags.buffered_mut_errors.insert(span, (diag, count));
|
||||
}
|
||||
|
||||
pub fn emit_errors(&mut self) -> Option<ErrorGuaranteed> {
|
||||
@ -2524,7 +2520,7 @@ mod diags {
|
||||
pub fn has_move_error(
|
||||
&self,
|
||||
move_out_indices: &[MoveOutIndex],
|
||||
) -> Option<&(PlaceRef<'tcx>, DiagnosticBuilder<'tcx>)> {
|
||||
) -> Option<&(PlaceRef<'tcx>, Diag<'tcx>)> {
|
||||
self.diags.buffered_move_errors.get(move_out_indices)
|
||||
}
|
||||
}
|
||||
|
@ -184,12 +184,9 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
|
||||
let (closure_region_requirements, nll_errors) =
|
||||
regioncx.solve(infcx, body, polonius_output.clone());
|
||||
|
||||
if !nll_errors.is_empty() {
|
||||
if let Some(guar) = nll_errors.has_errors() {
|
||||
// Suppress unhelpful extra errors in `infer_opaque_types`.
|
||||
infcx.set_tainted_by_errors(infcx.dcx().span_delayed_bug(
|
||||
body.span,
|
||||
"`compute_regions` tainted `infcx` with errors but did not emit any errors",
|
||||
));
|
||||
infcx.set_tainted_by_errors(guar);
|
||||
}
|
||||
|
||||
let remapped_opaque_tys = regioncx.infer_opaque_types(infcx, opaque_type_values);
|
||||
|
@ -5,7 +5,7 @@ use rustc_data_structures::binary_search_util;
|
||||
use rustc_data_structures::frozen::Frozen;
|
||||
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::graph::scc::Sccs;
|
||||
use rustc_errors::DiagnosticBuilder;
|
||||
use rustc_errors::Diag;
|
||||
use rustc_hir::def_id::CRATE_DEF_ID;
|
||||
use rustc_index::{IndexSlice, IndexVec};
|
||||
use rustc_infer::infer::outlives::test_type_match;
|
||||
@ -592,7 +592,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
}
|
||||
|
||||
/// Adds annotations for `#[rustc_regions]`; see `UniversalRegions::annotate`.
|
||||
pub(crate) fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut DiagnosticBuilder<'_, ()>) {
|
||||
pub(crate) fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diag<'_, ()>) {
|
||||
self.universal_regions.annotate(tcx, err)
|
||||
}
|
||||
|
||||
|
@ -311,17 +311,14 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
|
||||
// Add implied bounds from impl header.
|
||||
if matches!(tcx.def_kind(defining_ty_def_id), DefKind::AssocFn | DefKind::AssocConst) {
|
||||
for &(ty, _) in tcx.assumed_wf_types(tcx.local_parent(defining_ty_def_id)) {
|
||||
let Ok(TypeOpOutput { output: norm_ty, constraints: c, .. }) = self
|
||||
let result: Result<_, ErrorGuaranteed> = self
|
||||
.param_env
|
||||
.and(type_op::normalize::Normalize::new(ty))
|
||||
.fully_perform(self.infcx, span)
|
||||
else {
|
||||
// Note: this path is currently not reached in any test, so
|
||||
// any example that triggers this would be worth minimizing
|
||||
// and converting into a test.
|
||||
tcx.dcx().span_delayed_bug(span, format!("failed to normalize {ty:?}"));
|
||||
.fully_perform(self.infcx, span);
|
||||
let Ok(TypeOpOutput { output: norm_ty, constraints: c, .. }) = result else {
|
||||
continue;
|
||||
};
|
||||
|
||||
constraints.extend(c);
|
||||
|
||||
// We currently add implied bounds from the normalized ty only.
|
||||
|
@ -16,7 +16,7 @@
|
||||
#![allow(rustc::untranslatable_diagnostic)]
|
||||
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_errors::DiagnosticBuilder;
|
||||
use rustc_errors::Diag;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_hir::BodyOwnerKind;
|
||||
@ -343,7 +343,7 @@ impl<'tcx> UniversalRegions<'tcx> {
|
||||
/// that this region imposes on others. The methods in this file
|
||||
/// handle the part about dumping the inference context internal
|
||||
/// state.
|
||||
pub(crate) fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut DiagnosticBuilder<'_, ()>) {
|
||||
pub(crate) fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diag<'_, ()>) {
|
||||
match self.defining_ty {
|
||||
DefiningTy::Closure(def_id, args) => {
|
||||
let v = with_no_trimmed_paths!(
|
||||
|
@ -1,6 +1,6 @@
|
||||
use rustc_errors::{
|
||||
codes::*, AddToDiagnostic, DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic,
|
||||
Level, MultiSpan, SingleLabelManySpans, SubdiagnosticMessageOp,
|
||||
codes::*, AddToDiagnostic, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level, MultiSpan,
|
||||
SingleLabelManySpans, SubdiagnosticMessageOp,
|
||||
};
|
||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||
use rustc_span::{symbol::Ident, Span, Symbol};
|
||||
@ -448,12 +448,12 @@ pub(crate) struct EnvNotDefinedWithUserMessage {
|
||||
// Hand-written implementation to support custom user messages.
|
||||
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for EnvNotDefinedWithUserMessage {
|
||||
#[track_caller]
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> {
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
|
||||
#[expect(
|
||||
rustc::untranslatable_diagnostic,
|
||||
reason = "cannot translate user-provided messages"
|
||||
)]
|
||||
let mut diag = DiagnosticBuilder::new(dcx, level, self.msg_from_user.to_string());
|
||||
let mut diag = Diag::new(dcx, level, self.msg_from_user.to_string());
|
||||
diag.span(self.span);
|
||||
diag
|
||||
}
|
||||
@ -613,7 +613,7 @@ pub(crate) struct FormatUnusedArg {
|
||||
impl AddToDiagnostic for FormatUnusedArg {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
f: F,
|
||||
) {
|
||||
diag.arg("named", self.named);
|
||||
@ -800,7 +800,7 @@ pub(crate) struct AsmClobberNoReg {
|
||||
}
|
||||
|
||||
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for AsmClobberNoReg {
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> {
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
|
||||
// eager translation as `span_labels` takes `AsRef<str>`
|
||||
let lbl1 = dcx.eagerly_translate_to_string(
|
||||
crate::fluent_generated::builtin_macros_asm_clobber_abi,
|
||||
@ -810,14 +810,10 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for AsmClobberNoReg {
|
||||
crate::fluent_generated::builtin_macros_asm_clobber_outputs,
|
||||
[].into_iter(),
|
||||
);
|
||||
DiagnosticBuilder::new(
|
||||
dcx,
|
||||
level,
|
||||
crate::fluent_generated::builtin_macros_asm_clobber_no_reg,
|
||||
)
|
||||
.with_span(self.spans.clone())
|
||||
.with_span_labels(self.clobbers, &lbl1)
|
||||
.with_span_labels(self.spans, &lbl2)
|
||||
Diag::new(dcx, level, crate::fluent_generated::builtin_macros_asm_clobber_no_reg)
|
||||
.with_span(self.spans.clone())
|
||||
.with_span_labels(self.clobbers, &lbl1)
|
||||
.with_span_labels(self.spans, &lbl2)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ use rustc_ast::{
|
||||
FormatDebugHex, FormatOptions, FormatPlaceholder, FormatSign, FormatTrait,
|
||||
};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder, MultiSpan, PResult, SingleLabelManySpans};
|
||||
use rustc_errors::{Applicability, Diag, MultiSpan, PResult, SingleLabelManySpans};
|
||||
use rustc_expand::base::{self, *};
|
||||
use rustc_parse::parser::Recovered;
|
||||
use rustc_parse_format as parse;
|
||||
@ -730,7 +730,7 @@ fn report_redundant_format_arguments<'a>(
|
||||
args: &FormatArguments,
|
||||
used: &[bool],
|
||||
placeholders: Vec<(Span, &str)>,
|
||||
) -> Option<DiagnosticBuilder<'a>> {
|
||||
) -> Option<Diag<'a>> {
|
||||
let mut fmt_arg_indices = vec![];
|
||||
let mut args_spans = vec![];
|
||||
let mut fmt_spans = vec![];
|
||||
|
@ -5,7 +5,7 @@ use crate::util::{check_builtin_macro_attribute, warn_on_duplicate_attribute};
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{self as ast, attr, GenericParamKind};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder, Level};
|
||||
use rustc_errors::{Applicability, Diag, Level};
|
||||
use rustc_expand::base::*;
|
||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::{ErrorGuaranteed, FileNameDisplayPreference, Span};
|
||||
@ -410,7 +410,7 @@ fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>)
|
||||
Some(ast::ItemKind::MacCall(_)) => Level::Warning,
|
||||
_ => Level::Error,
|
||||
};
|
||||
let mut err = DiagnosticBuilder::<()>::new(dcx, level, msg);
|
||||
let mut err = Diag::<()>::new(dcx, level, msg);
|
||||
err.span(attr_sp);
|
||||
if let Some(item) = item {
|
||||
err.span_label(
|
||||
|
@ -8,7 +8,7 @@ use rustc_session::Session;
|
||||
pub(crate) struct ArArchiveBuilderBuilder;
|
||||
|
||||
impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
|
||||
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder<'a> + 'a> {
|
||||
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder + 'a> {
|
||||
Box::new(ArArchiveBuilder::new(sess, get_native_object_symbols))
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ use rustc_session::cstore::DllImport;
|
||||
pub(crate) struct ArArchiveBuilderBuilder;
|
||||
|
||||
impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
|
||||
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder<'a> + 'a> {
|
||||
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder + 'a> {
|
||||
Box::new(ArArchiveBuilder::new(sess, get_native_object_symbols))
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
use rustc_errors::{
|
||||
DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic,
|
||||
IntoDiagnosticArg, Level,
|
||||
DiagCtxt, DiagArgValue, Diag, EmissionGuarantee, IntoDiagnostic, IntoDiagnosticArg, Level,
|
||||
};
|
||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||
use rustc_span::Span;
|
||||
@ -35,11 +34,11 @@ pub(crate) enum PossibleFeature<'a> {
|
||||
struct ExitCode(Option<i32>);
|
||||
|
||||
impl IntoDiagnosticArg for ExitCode {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
let ExitCode(exit_code) = self;
|
||||
match exit_code {
|
||||
Some(t) => t.into_diagnostic_arg(),
|
||||
None => DiagnosticArgValue::Str(Cow::Borrowed("<signal>")),
|
||||
None => DiagArgValue::Str(Cow::Borrowed("<signal>")),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -112,12 +111,8 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> {
|
||||
pub(crate) struct MissingFeatures;
|
||||
|
||||
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> {
|
||||
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
|
||||
let mut diag = DiagnosticBuilder::new(
|
||||
dcx,
|
||||
level,
|
||||
fluent::codegen_gcc_target_feature_disable_or_enable
|
||||
);
|
||||
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> {
|
||||
let mut diag = Diag::new(dcx, level, fluent::codegen_gcc_target_feature_disable_or_enable);
|
||||
if let Some(span) = self.span {
|
||||
diag.span(span);
|
||||
};
|
||||
|
@ -60,7 +60,7 @@ fn llvm_machine_type(cpu: &str) -> LLVMMachineType {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
|
||||
impl<'a> ArchiveBuilder for LlvmArchiveBuilder<'a> {
|
||||
fn add_archive(
|
||||
&mut self,
|
||||
archive: &Path,
|
||||
@ -107,7 +107,7 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
|
||||
pub struct LlvmArchiveBuilderBuilder;
|
||||
|
||||
impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
|
||||
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder<'a> + 'a> {
|
||||
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder + 'a> {
|
||||
// FIXME use ArArchiveBuilder on most targets again once reading thin archives is
|
||||
// implemented
|
||||
if true {
|
||||
|
@ -4,7 +4,7 @@ use std::path::Path;
|
||||
|
||||
use crate::fluent_generated as fluent;
|
||||
use rustc_data_structures::small_c_str::SmallCStr;
|
||||
use rustc_errors::{DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, Level};
|
||||
use rustc_errors::{Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level};
|
||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||
use rustc_span::Span;
|
||||
|
||||
@ -100,11 +100,11 @@ pub(crate) struct DynamicLinkingWithLTO;
|
||||
pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>);
|
||||
|
||||
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_> {
|
||||
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
|
||||
let diag: DiagnosticBuilder<'_, G> = self.0.into_diagnostic(dcx, level);
|
||||
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> {
|
||||
let diag: Diag<'_, G> = self.0.into_diagnostic(dcx, level);
|
||||
let (message, _) = diag.messages.first().expect("`LlvmError` with no message");
|
||||
let message = dcx.eagerly_translate_to_string(message.clone(), diag.args.iter());
|
||||
DiagnosticBuilder::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config)
|
||||
Diag::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config)
|
||||
.with_arg("error", message)
|
||||
}
|
||||
}
|
||||
@ -120,12 +120,8 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> {
|
||||
pub(crate) struct MissingFeatures;
|
||||
|
||||
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> {
|
||||
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
|
||||
let mut diag = DiagnosticBuilder::new(
|
||||
dcx,
|
||||
level,
|
||||
fluent::codegen_llvm_target_feature_disable_or_enable,
|
||||
);
|
||||
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> {
|
||||
let mut diag = Diag::new(dcx, level, fluent::codegen_llvm_target_feature_disable_or_enable);
|
||||
if let Some(span) = self.span {
|
||||
diag.span(span);
|
||||
};
|
||||
@ -184,7 +180,7 @@ pub enum LlvmError<'a> {
|
||||
pub(crate) struct WithLlvmError<'a>(pub LlvmError<'a>, pub String);
|
||||
|
||||
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for WithLlvmError<'_> {
|
||||
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
|
||||
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> Diag<'_, G> {
|
||||
use LlvmError::*;
|
||||
let msg_with_llvm_err = match &self.0 {
|
||||
WriteOutput { .. } => fluent::codegen_llvm_write_output_with_llvm_err,
|
||||
|
@ -27,7 +27,7 @@ use crate::errors;
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::unord::UnordMap;
|
||||
use rustc_data_structures::unord::UnordSet;
|
||||
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
|
||||
use rustc_errors::{DiagArgValue, IntoDiagnosticArg};
|
||||
use rustc_hir::def_id::LOCAL_CRATE;
|
||||
use rustc_middle::mir::mono::CodegenUnitNameBuilder;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
@ -206,8 +206,8 @@ impl fmt::Display for CguReuse {
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for CguReuse {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::Owned(self.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ use std::path::{Path, PathBuf};
|
||||
pub use crate::errors::{ArchiveBuildFailure, ExtractBundledLibsError, UnknownArchiveKind};
|
||||
|
||||
pub trait ArchiveBuilderBuilder {
|
||||
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder<'a> + 'a>;
|
||||
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder + 'a>;
|
||||
|
||||
/// Creates a DLL Import Library <https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-creation#creating-an-import-library>.
|
||||
/// and returns the path on disk to that import library.
|
||||
@ -74,7 +74,7 @@ pub trait ArchiveBuilderBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ArchiveBuilder<'a> {
|
||||
pub trait ArchiveBuilder {
|
||||
fn add_file(&mut self, path: &Path);
|
||||
|
||||
fn add_archive(
|
||||
@ -167,7 +167,7 @@ pub fn try_extract_macho_fat_archive(
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
|
||||
impl<'a> ArchiveBuilder for ArArchiveBuilder<'a> {
|
||||
fn add_archive(
|
||||
&mut self,
|
||||
archive_path: &Path,
|
||||
|
@ -308,7 +308,7 @@ fn link_rlib<'a>(
|
||||
codegen_results: &CodegenResults,
|
||||
flavor: RlibFlavor,
|
||||
tmpdir: &MaybeTempDir,
|
||||
) -> Result<Box<dyn ArchiveBuilder<'a> + 'a>, ErrorGuaranteed> {
|
||||
) -> Result<Box<dyn ArchiveBuilder + 'a>, ErrorGuaranteed> {
|
||||
let lib_search_paths = archive_search_paths(sess);
|
||||
|
||||
let mut ab = archive_builder_builder.new_archive_builder(sess);
|
||||
|
@ -16,8 +16,8 @@ use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::emitter::Emitter;
|
||||
use rustc_errors::translation::Translate;
|
||||
use rustc_errors::{
|
||||
DiagCtxt, DiagnosticArgMap, DiagnosticBuilder, DiagnosticMessage, ErrCode, FatalError,
|
||||
FluentBundle, Level, MultiSpan, Style,
|
||||
Diag, DiagArgMap, DiagCtxt, DiagnosticMessage, ErrCode, FatalError, FluentBundle, Level,
|
||||
MultiSpan, Style,
|
||||
};
|
||||
use rustc_fs_util::link_or_copy;
|
||||
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
|
||||
@ -373,7 +373,7 @@ pub struct CodegenContext<B: WriteBackendMethods> {
|
||||
|
||||
impl<B: WriteBackendMethods> CodegenContext<B> {
|
||||
pub fn create_dcx(&self) -> DiagCtxt {
|
||||
DiagCtxt::with_emitter(Box::new(self.diag_emitter.clone()))
|
||||
DiagCtxt::new(Box::new(self.diag_emitter.clone()))
|
||||
}
|
||||
|
||||
pub fn config(&self, kind: ModuleKind) -> &ModuleConfig {
|
||||
@ -1013,7 +1013,7 @@ struct Diagnostic {
|
||||
messages: Vec<(DiagnosticMessage, Style)>,
|
||||
code: Option<ErrCode>,
|
||||
children: Vec<Subdiagnostic>,
|
||||
args: DiagnosticArgMap,
|
||||
args: DiagArgMap,
|
||||
}
|
||||
|
||||
// A cut-down version of `rustc_errors::SubDiagnostic` that impls `Send`. It's
|
||||
@ -1829,16 +1829,16 @@ impl Translate for SharedEmitter {
|
||||
}
|
||||
|
||||
impl Emitter for SharedEmitter {
|
||||
fn emit_diagnostic(&mut self, mut diag: rustc_errors::Diagnostic) {
|
||||
fn emit_diagnostic(&mut self, mut diag: rustc_errors::DiagInner) {
|
||||
// Check that we aren't missing anything interesting when converting to
|
||||
// the cut-down local `Diagnostic`.
|
||||
// the cut-down local `DiagInner`.
|
||||
assert_eq!(diag.span, MultiSpan::new());
|
||||
assert_eq!(diag.suggestions, Ok(vec![]));
|
||||
assert_eq!(diag.sort_span, rustc_span::DUMMY_SP);
|
||||
assert_eq!(diag.is_lint, None);
|
||||
// No sensible check for `diag.emitted_at`.
|
||||
|
||||
let args = mem::replace(&mut diag.args, DiagnosticArgMap::default());
|
||||
let args = mem::replace(&mut diag.args, DiagArgMap::default());
|
||||
drop(
|
||||
self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
|
||||
level: diag.level(),
|
||||
@ -1880,12 +1880,12 @@ impl SharedEmitterMain {
|
||||
// Convert it back to a full `Diagnostic` and emit.
|
||||
let dcx = sess.dcx();
|
||||
let mut d =
|
||||
rustc_errors::Diagnostic::new_with_messages(diag.level, diag.messages);
|
||||
rustc_errors::DiagInner::new_with_messages(diag.level, diag.messages);
|
||||
d.code = diag.code; // may be `None`, that's ok
|
||||
d.children = diag
|
||||
.children
|
||||
.into_iter()
|
||||
.map(|sub| rustc_errors::SubDiagnostic {
|
||||
.map(|sub| rustc_errors::Subdiag {
|
||||
level: sub.level,
|
||||
messages: sub.messages,
|
||||
span: MultiSpan::new(),
|
||||
@ -1898,7 +1898,7 @@ impl SharedEmitterMain {
|
||||
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg, level, source)) => {
|
||||
assert!(matches!(level, Level::Error | Level::Warning | Level::Note));
|
||||
let msg = msg.strip_prefix("error: ").unwrap_or(&msg).to_string();
|
||||
let mut err = DiagnosticBuilder::<()>::new(sess.dcx(), level, msg);
|
||||
let mut err = Diag::<()>::new(sess.dcx(), level, msg);
|
||||
|
||||
// If the cookie is 0 then we don't have span information.
|
||||
if cookie != 0 {
|
||||
|
@ -4,8 +4,8 @@ use crate::assert_module_sources::CguReuse;
|
||||
use crate::back::command::Command;
|
||||
use crate::fluent_generated as fluent;
|
||||
use rustc_errors::{
|
||||
codes::*, DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic,
|
||||
IntoDiagnosticArg, Level,
|
||||
codes::*, Diag, DiagArgValue, DiagCtxt, EmissionGuarantee, IntoDiagnostic, IntoDiagnosticArg,
|
||||
Level,
|
||||
};
|
||||
use rustc_macros::Diagnostic;
|
||||
use rustc_middle::ty::layout::LayoutError;
|
||||
@ -153,8 +153,8 @@ impl<'a> CopyPath<'a> {
|
||||
struct DebugArgPath<'a>(pub &'a Path);
|
||||
|
||||
impl IntoDiagnosticArg for DebugArgPath<'_> {
|
||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self.0)))
|
||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue {
|
||||
DiagArgValue::Str(Cow::Owned(format!("{:?}", self.0)))
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,8 +216,8 @@ pub enum LinkRlibError {
|
||||
pub struct ThorinErrorWrapper(pub thorin::Error);
|
||||
|
||||
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ThorinErrorWrapper {
|
||||
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
|
||||
let build = |msg| DiagnosticBuilder::new(dcx, level, msg);
|
||||
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> {
|
||||
let build = |msg| Diag::new(dcx, level, msg);
|
||||
match self.0 {
|
||||
thorin::Error::ReadInput(_) => build(fluent::codegen_ssa_thorin_read_input_failure),
|
||||
thorin::Error::ParseFileKind(_) => {
|
||||
@ -349,8 +349,8 @@ pub struct LinkingFailed<'a> {
|
||||
}
|
||||
|
||||
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for LinkingFailed<'_> {
|
||||
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
|
||||
let mut diag = DiagnosticBuilder::new(dcx, level, fluent::codegen_ssa_linking_failed);
|
||||
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> {
|
||||
let mut diag = Diag::new(dcx, level, fluent::codegen_ssa_linking_failed);
|
||||
diag.arg("linker_path", format!("{}", self.linker_path.display()));
|
||||
diag.arg("exit_status", format!("{}", self.exit_status));
|
||||
|
||||
@ -975,10 +975,10 @@ pub enum ExpectedPointerMutability {
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for ExpectedPointerMutability {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
match self {
|
||||
ExpectedPointerMutability::Mut => DiagnosticArgValue::Str(Cow::Borrowed("*mut")),
|
||||
ExpectedPointerMutability::Not => DiagnosticArgValue::Str(Cow::Borrowed("*_")),
|
||||
ExpectedPointerMutability::Mut => DiagArgValue::Str(Cow::Borrowed("*mut")),
|
||||
ExpectedPointerMutability::Not => DiagArgValue::Str(Cow::Borrowed("*_")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::mem;
|
||||
|
||||
use rustc_errors::{
|
||||
DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage, IntoDiagnostic, IntoDiagnosticArg,
|
||||
DiagArgName, DiagArgValue, DiagnosticMessage, IntoDiagnostic, IntoDiagnosticArg,
|
||||
};
|
||||
use rustc_hir::CRATE_HIR_ID;
|
||||
use rustc_middle::mir::AssertKind;
|
||||
@ -36,7 +36,7 @@ impl MachineStopType for ConstEvalErrKind {
|
||||
AssertFailure(x) => x.diagnostic_message(),
|
||||
}
|
||||
}
|
||||
fn add_args(self: Box<Self>, adder: &mut dyn FnMut(DiagnosticArgName, DiagnosticArgValue)) {
|
||||
fn add_args(self: Box<Self>, adder: &mut dyn FnMut(DiagArgName, DiagArgValue)) {
|
||||
use ConstEvalErrKind::*;
|
||||
match *self {
|
||||
RecursiveStatic | ConstAccessesMutGlobal | ModifiedGlobal => {}
|
||||
|
@ -1,8 +1,8 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use rustc_errors::{
|
||||
codes::*, DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, DiagnosticMessage,
|
||||
EmissionGuarantee, IntoDiagnostic, Level,
|
||||
codes::*, Diag, DiagArgValue, DiagCtxt, DiagnosticMessage, EmissionGuarantee, IntoDiagnostic,
|
||||
Level,
|
||||
};
|
||||
use rustc_hir::ConstContext;
|
||||
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
||||
@ -11,11 +11,10 @@ use rustc_middle::mir::interpret::{
|
||||
PointerKind, ResourceExhaustionInfo, UndefinedBehaviorInfo, UnsupportedOpInfo,
|
||||
ValidationErrorInfo,
|
||||
};
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_middle::ty::{self, Mutability, Ty};
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::call::AdjustForForeignAbiError;
|
||||
use rustc_target::abi::{Size, WrappingRange};
|
||||
use rustc_type_ir::Mutability;
|
||||
|
||||
use crate::interpret::InternKind;
|
||||
|
||||
@ -426,7 +425,7 @@ pub struct UndefinedBehavior {
|
||||
pub trait ReportErrorExt {
|
||||
/// Returns the diagnostic message for this error.
|
||||
fn diagnostic_message(&self) -> DiagnosticMessage;
|
||||
fn add_args<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, G>);
|
||||
fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>);
|
||||
|
||||
fn debug(self) -> String
|
||||
where
|
||||
@ -505,7 +504,7 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_args<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, G>) {
|
||||
fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
||||
use UndefinedBehaviorInfo::*;
|
||||
let dcx = diag.dcx;
|
||||
match self {
|
||||
@ -671,7 +670,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_args<G: EmissionGuarantee>(self, err: &mut DiagnosticBuilder<'_, G>) {
|
||||
fn add_args<G: EmissionGuarantee>(self, err: &mut Diag<'_, G>) {
|
||||
use crate::fluent_generated as fluent;
|
||||
use rustc_middle::mir::interpret::ValidationErrorKind::*;
|
||||
|
||||
@ -683,7 +682,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
|
||||
let message = if let Some(path) = self.path {
|
||||
err.dcx.eagerly_translate_to_string(
|
||||
fluent::const_eval_validation_front_matter_invalid_value_with_path,
|
||||
[("path".into(), DiagnosticArgValue::Str(path.into()))].iter().map(|(a, b)| (a, b)),
|
||||
[("path".into(), DiagArgValue::Str(path.into()))].iter().map(|(a, b)| (a, b)),
|
||||
)
|
||||
} else {
|
||||
err.dcx.eagerly_translate_to_string(
|
||||
@ -697,7 +696,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
|
||||
fn add_range_arg<G: EmissionGuarantee>(
|
||||
r: WrappingRange,
|
||||
max_hi: u128,
|
||||
err: &mut DiagnosticBuilder<'_, G>,
|
||||
err: &mut Diag<'_, G>,
|
||||
) {
|
||||
let WrappingRange { start: lo, end: hi } = r;
|
||||
assert!(hi <= max_hi);
|
||||
@ -716,8 +715,8 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
|
||||
};
|
||||
|
||||
let args = [
|
||||
("lo".into(), DiagnosticArgValue::Str(lo.to_string().into())),
|
||||
("hi".into(), DiagnosticArgValue::Str(hi.to_string().into())),
|
||||
("lo".into(), DiagArgValue::Str(lo.to_string().into())),
|
||||
("hi".into(), DiagArgValue::Str(hi.to_string().into())),
|
||||
];
|
||||
let args = args.iter().map(|(a, b)| (a, b));
|
||||
let message = err.dcx.eagerly_translate_to_string(msg, args);
|
||||
@ -798,7 +797,7 @@ impl ReportErrorExt for UnsupportedOpInfo {
|
||||
UnsupportedOpInfo::ExternStatic(_) => const_eval_extern_static,
|
||||
}
|
||||
}
|
||||
fn add_args<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, G>) {
|
||||
fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
||||
use crate::fluent_generated::*;
|
||||
|
||||
use UnsupportedOpInfo::*;
|
||||
@ -831,7 +830,7 @@ impl<'tcx> ReportErrorExt for InterpError<'tcx> {
|
||||
InterpError::MachineStop(e) => e.diagnostic_message(),
|
||||
}
|
||||
}
|
||||
fn add_args<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, G>) {
|
||||
fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
||||
match self {
|
||||
InterpError::UndefinedBehavior(ub) => ub.add_args(diag),
|
||||
InterpError::Unsupported(e) => e.add_args(diag),
|
||||
@ -856,13 +855,13 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {
|
||||
}
|
||||
}
|
||||
}
|
||||
fn add_args<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, G>) {
|
||||
fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
||||
match self {
|
||||
InvalidProgramInfo::TooGeneric | InvalidProgramInfo::AlreadyReported(_) => {}
|
||||
InvalidProgramInfo::Layout(e) => {
|
||||
// The level doesn't matter, `dummy_diag` is consumed without it being used.
|
||||
let dummy_level = Level::Bug;
|
||||
let dummy_diag: DiagnosticBuilder<'_, ()> =
|
||||
let dummy_diag: Diag<'_, ()> =
|
||||
e.into_diagnostic().into_diagnostic(diag.dcx, dummy_level);
|
||||
for (name, val) in dummy_diag.args.iter() {
|
||||
diag.arg(name.clone(), val.clone());
|
||||
@ -888,12 +887,12 @@ impl ReportErrorExt for ResourceExhaustionInfo {
|
||||
ResourceExhaustionInfo::AddressSpaceFull => const_eval_address_space_full,
|
||||
}
|
||||
}
|
||||
fn add_args<G: EmissionGuarantee>(self, _: &mut DiagnosticBuilder<'_, G>) {}
|
||||
fn add_args<G: EmissionGuarantee>(self, _: &mut Diag<'_, G>) {}
|
||||
}
|
||||
|
||||
impl rustc_errors::IntoDiagnosticArg for InternKind {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::Borrowed(match self {
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::Borrowed(match self {
|
||||
InternKind::Static(Mutability::Not) => "static",
|
||||
InternKind::Static(Mutability::Mut) => "static_mut",
|
||||
InternKind::Constant => "const",
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! The `Visitor` responsible for actually checking a `mir::Body` for invalid operations.
|
||||
|
||||
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
|
||||
use rustc_errors::{Diag, ErrorGuaranteed};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_index::bit_set::BitSet;
|
||||
@ -187,7 +187,7 @@ pub struct Checker<'mir, 'tcx> {
|
||||
local_has_storage_dead: Option<BitSet<Local>>,
|
||||
|
||||
error_emitted: Option<ErrorGuaranteed>,
|
||||
secondary_errors: Vec<DiagnosticBuilder<'tcx>>,
|
||||
secondary_errors: Vec<Diag<'tcx>>,
|
||||
}
|
||||
|
||||
impl<'mir, 'tcx> Deref for Checker<'mir, 'tcx> {
|
||||
@ -318,12 +318,12 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
|
||||
assert!(err.is_error());
|
||||
|
||||
match op.importance() {
|
||||
ops::DiagnosticImportance::Primary => {
|
||||
ops::DiagImportance::Primary => {
|
||||
let reported = err.emit();
|
||||
self.error_emitted = Some(reported);
|
||||
}
|
||||
|
||||
ops::DiagnosticImportance::Secondary => self.secondary_errors.push(err),
|
||||
ops::DiagImportance::Secondary => self.secondary_errors.push(err),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use hir::def_id::LocalDefId;
|
||||
use hir::{ConstContext, LangItem};
|
||||
use rustc_errors::{codes::*, DiagnosticBuilder};
|
||||
use rustc_errors::{codes::*, Diag};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
@ -29,7 +29,7 @@ pub enum Status {
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum DiagnosticImportance {
|
||||
pub enum DiagImportance {
|
||||
/// An operation that must be removed for const-checking to pass.
|
||||
Primary,
|
||||
|
||||
@ -44,11 +44,11 @@ pub trait NonConstOp<'tcx>: std::fmt::Debug {
|
||||
Status::Forbidden
|
||||
}
|
||||
|
||||
fn importance(&self) -> DiagnosticImportance {
|
||||
DiagnosticImportance::Primary
|
||||
fn importance(&self) -> DiagImportance {
|
||||
DiagImportance::Primary
|
||||
}
|
||||
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx>;
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx>;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -62,7 +62,7 @@ impl<'tcx> NonConstOp<'tcx> for FloatingPointOp {
|
||||
}
|
||||
}
|
||||
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
feature_err(
|
||||
&ccx.tcx.sess,
|
||||
sym::const_fn_floating_point_arithmetic,
|
||||
@ -76,7 +76,7 @@ impl<'tcx> NonConstOp<'tcx> for FloatingPointOp {
|
||||
#[derive(Debug)]
|
||||
pub struct FnCallIndirect;
|
||||
impl<'tcx> NonConstOp<'tcx> for FnCallIndirect {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
ccx.dcx().create_err(errors::UnallowedFnPointerCall { span, kind: ccx.const_kind() })
|
||||
}
|
||||
}
|
||||
@ -96,7 +96,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||
// FIXME: make this translatable
|
||||
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||
#[allow(rustc::untranslatable_diagnostic)]
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, _: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, _: Span) -> Diag<'tcx> {
|
||||
let FnCallNonConst { caller, callee, args, span, call_source, feature } = *self;
|
||||
let ConstCx { tcx, param_env, .. } = *ccx;
|
||||
|
||||
@ -317,7 +317,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||
pub struct FnCallUnstable(pub DefId, pub Option<Symbol>);
|
||||
|
||||
impl<'tcx> NonConstOp<'tcx> for FnCallUnstable {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
let FnCallUnstable(def_id, feature) = *self;
|
||||
|
||||
let mut err = ccx
|
||||
@ -353,7 +353,7 @@ impl<'tcx> NonConstOp<'tcx> for Coroutine {
|
||||
}
|
||||
}
|
||||
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
let msg = format!("{:#}s are not allowed in {}s", self.0, ccx.const_kind());
|
||||
if let hir::CoroutineKind::Desugared(
|
||||
hir::CoroutineDesugaring::Async,
|
||||
@ -373,7 +373,7 @@ impl<'tcx> NonConstOp<'tcx> for Coroutine {
|
||||
#[derive(Debug)]
|
||||
pub struct HeapAllocation;
|
||||
impl<'tcx> NonConstOp<'tcx> for HeapAllocation {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
ccx.dcx().create_err(errors::UnallowedHeapAllocations {
|
||||
span,
|
||||
kind: ccx.const_kind(),
|
||||
@ -385,7 +385,7 @@ impl<'tcx> NonConstOp<'tcx> for HeapAllocation {
|
||||
#[derive(Debug)]
|
||||
pub struct InlineAsm;
|
||||
impl<'tcx> NonConstOp<'tcx> for InlineAsm {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
ccx.dcx().create_err(errors::UnallowedInlineAsm { span, kind: ccx.const_kind() })
|
||||
}
|
||||
}
|
||||
@ -396,7 +396,7 @@ pub struct LiveDrop<'tcx> {
|
||||
pub dropped_ty: Ty<'tcx>,
|
||||
}
|
||||
impl<'tcx> NonConstOp<'tcx> for LiveDrop<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
ccx.dcx().create_err(errors::LiveDrop {
|
||||
span,
|
||||
dropped_ty: self.dropped_ty,
|
||||
@ -414,7 +414,7 @@ impl<'tcx> NonConstOp<'tcx> for TransientCellBorrow {
|
||||
fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status {
|
||||
Status::Unstable(sym::const_refs_to_cell)
|
||||
}
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
ccx.tcx
|
||||
.sess
|
||||
.create_feature_err(errors::InteriorMutabilityBorrow { span }, sym::const_refs_to_cell)
|
||||
@ -427,12 +427,12 @@ impl<'tcx> NonConstOp<'tcx> for TransientCellBorrow {
|
||||
/// it in the future for static items.
|
||||
pub struct CellBorrow;
|
||||
impl<'tcx> NonConstOp<'tcx> for CellBorrow {
|
||||
fn importance(&self) -> DiagnosticImportance {
|
||||
fn importance(&self) -> DiagImportance {
|
||||
// Most likely the code will try to do mutation with these borrows, which
|
||||
// triggers its own errors. Only show this one if that does not happen.
|
||||
DiagnosticImportance::Secondary
|
||||
DiagImportance::Secondary
|
||||
}
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
// FIXME: Maybe a more elegant solution to this if else case
|
||||
if let hir::ConstContext::Static(_) = ccx.const_kind() {
|
||||
ccx.dcx().create_err(errors::InteriorMutableDataRefer {
|
||||
@ -463,13 +463,13 @@ impl<'tcx> NonConstOp<'tcx> for MutBorrow {
|
||||
Status::Forbidden
|
||||
}
|
||||
|
||||
fn importance(&self) -> DiagnosticImportance {
|
||||
fn importance(&self) -> DiagImportance {
|
||||
// Most likely the code will try to do mutation with these borrows, which
|
||||
// triggers its own errors. Only show this one if that does not happen.
|
||||
DiagnosticImportance::Secondary
|
||||
DiagImportance::Secondary
|
||||
}
|
||||
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
match self.0 {
|
||||
hir::BorrowKind::Raw => ccx.tcx.dcx().create_err(errors::UnallowedMutableRaw {
|
||||
span,
|
||||
@ -493,7 +493,7 @@ impl<'tcx> NonConstOp<'tcx> for TransientMutBorrow {
|
||||
Status::Unstable(sym::const_mut_refs)
|
||||
}
|
||||
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
let kind = ccx.const_kind();
|
||||
match self.0 {
|
||||
hir::BorrowKind::Raw => ccx
|
||||
@ -515,12 +515,12 @@ impl<'tcx> NonConstOp<'tcx> for MutDeref {
|
||||
Status::Unstable(sym::const_mut_refs)
|
||||
}
|
||||
|
||||
fn importance(&self) -> DiagnosticImportance {
|
||||
fn importance(&self) -> DiagImportance {
|
||||
// Usually a side-effect of a `TransientMutBorrow` somewhere.
|
||||
DiagnosticImportance::Secondary
|
||||
DiagImportance::Secondary
|
||||
}
|
||||
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
ccx.tcx.sess.create_feature_err(
|
||||
errors::MutDerefErr { span, kind: ccx.const_kind() },
|
||||
sym::const_mut_refs,
|
||||
@ -532,7 +532,7 @@ impl<'tcx> NonConstOp<'tcx> for MutDeref {
|
||||
#[derive(Debug)]
|
||||
pub struct PanicNonStr;
|
||||
impl<'tcx> NonConstOp<'tcx> for PanicNonStr {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
ccx.dcx().create_err(errors::PanicNonStrErr { span })
|
||||
}
|
||||
}
|
||||
@ -543,7 +543,7 @@ impl<'tcx> NonConstOp<'tcx> for PanicNonStr {
|
||||
#[derive(Debug)]
|
||||
pub struct RawPtrComparison;
|
||||
impl<'tcx> NonConstOp<'tcx> for RawPtrComparison {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
// FIXME(const_trait_impl): revert to span_bug?
|
||||
ccx.dcx().create_err(errors::RawPtrComparisonErr { span })
|
||||
}
|
||||
@ -556,7 +556,7 @@ impl<'tcx> NonConstOp<'tcx> for RawMutPtrDeref {
|
||||
Status::Unstable(sym::const_mut_refs)
|
||||
}
|
||||
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
feature_err(
|
||||
&ccx.tcx.sess,
|
||||
sym::const_mut_refs,
|
||||
@ -572,7 +572,7 @@ impl<'tcx> NonConstOp<'tcx> for RawMutPtrDeref {
|
||||
#[derive(Debug)]
|
||||
pub struct RawPtrToIntCast;
|
||||
impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
ccx.dcx().create_err(errors::RawPtrToIntErr { span })
|
||||
}
|
||||
}
|
||||
@ -589,7 +589,7 @@ impl<'tcx> NonConstOp<'tcx> for StaticAccess {
|
||||
}
|
||||
}
|
||||
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
let mut err = feature_err(
|
||||
&ccx.tcx.sess,
|
||||
sym::const_refs_to_static,
|
||||
@ -609,7 +609,7 @@ impl<'tcx> NonConstOp<'tcx> for StaticAccess {
|
||||
#[derive(Debug)]
|
||||
pub struct ThreadLocalAccess;
|
||||
impl<'tcx> NonConstOp<'tcx> for ThreadLocalAccess {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
ccx.dcx().create_err(errors::ThreadLocalAccessErr { span })
|
||||
}
|
||||
}
|
||||
@ -625,16 +625,14 @@ pub mod ty {
|
||||
Status::Unstable(sym::const_mut_refs)
|
||||
}
|
||||
|
||||
fn importance(&self) -> DiagnosticImportance {
|
||||
fn importance(&self) -> DiagImportance {
|
||||
match self.0 {
|
||||
mir::LocalKind::Temp => DiagnosticImportance::Secondary,
|
||||
mir::LocalKind::ReturnPointer | mir::LocalKind::Arg => {
|
||||
DiagnosticImportance::Primary
|
||||
}
|
||||
mir::LocalKind::Temp => DiagImportance::Secondary,
|
||||
mir::LocalKind::ReturnPointer | mir::LocalKind::Arg => DiagImportance::Primary,
|
||||
}
|
||||
}
|
||||
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
|
||||
feature_err(
|
||||
&ccx.tcx.sess,
|
||||
sym::const_mut_refs,
|
||||
|
@ -1,10 +1,9 @@
|
||||
use rustc_hir::LangItem;
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::query::TyCtxtAt;
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::layout::LayoutOf;
|
||||
use rustc_middle::ty::{self, Mutability};
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_type_ir::Mutability;
|
||||
|
||||
use crate::const_eval::{mk_eval_cx_to_read_const_val, CanAccessMutGlobal, CompileTimeEvalContext};
|
||||
use crate::interpret::*;
|
||||
|
@ -21,6 +21,7 @@ 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::emitter::stderr_destination;
|
||||
use rustc_errors::registry::Registry;
|
||||
use rustc_errors::{
|
||||
markdown, ColorConfig, DiagCtxt, ErrCode, ErrorGuaranteed, FatalError, PResult,
|
||||
@ -1384,11 +1385,11 @@ fn report_ice(
|
||||
) {
|
||||
let fallback_bundle =
|
||||
rustc_errors::fallback_fluent_bundle(crate::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
|
||||
let emitter = Box::new(rustc_errors::emitter::HumanEmitter::stderr(
|
||||
rustc_errors::ColorConfig::Auto,
|
||||
let emitter = Box::new(rustc_errors::emitter::HumanEmitter::new(
|
||||
stderr_destination(rustc_errors::ColorConfig::Auto),
|
||||
fallback_bundle,
|
||||
));
|
||||
let dcx = rustc_errors::DiagCtxt::with_emitter(emitter);
|
||||
let dcx = rustc_errors::DiagCtxt::new(emitter);
|
||||
|
||||
// a .span_bug or .bug call has already printed what
|
||||
// it wants to print.
|
||||
|
@ -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, ErrCode, FluentBundle,
|
||||
LazyFallbackBundle, Level, MultiSpan, Style, SubDiagnostic,
|
||||
CodeSuggestion, DiagInner, DiagnosticMessage, Emitter, ErrCode, FluentBundle,
|
||||
LazyFallbackBundle, Level, MultiSpan, Style, Subdiag,
|
||||
};
|
||||
use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
@ -44,7 +44,7 @@ impl Translate for AnnotateSnippetEmitter {
|
||||
|
||||
impl Emitter for AnnotateSnippetEmitter {
|
||||
/// The entry point for the diagnostics generation
|
||||
fn emit_diagnostic(&mut self, mut diag: Diagnostic) {
|
||||
fn emit_diagnostic(&mut self, mut diag: DiagInner) {
|
||||
let fluent_args = to_fluent_args(diag.args.iter());
|
||||
|
||||
let mut suggestions = diag.suggestions.unwrap_or(vec![]);
|
||||
@ -82,7 +82,7 @@ fn source_string(file: Lrc<SourceFile>, line: &Line) -> String {
|
||||
file.get_line(line.line_index - 1).map(|a| a.to_string()).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Maps `Diagnostic::Level` to `snippet::AnnotationType`
|
||||
/// Maps `diagnostic::Level` to `snippet::AnnotationType`
|
||||
fn annotation_type_for_level(level: Level) -> AnnotationType {
|
||||
match level {
|
||||
Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug => AnnotationType::Error,
|
||||
@ -129,7 +129,7 @@ impl AnnotateSnippetEmitter {
|
||||
args: &FluentArgs<'_>,
|
||||
code: &Option<ErrCode>,
|
||||
msp: &MultiSpan,
|
||||
_children: &[SubDiagnostic],
|
||||
_children: &[Subdiag],
|
||||
_suggestions: &[CodeSuggestion],
|
||||
) {
|
||||
let message = self.translate_messages(messages, args);
|
||||
|
@ -18,23 +18,23 @@ use std::ops::{Deref, DerefMut};
|
||||
use std::panic;
|
||||
use std::thread::panicking;
|
||||
|
||||
/// Error type for `Diagnostic`'s `suggestions` field, indicating that
|
||||
/// `.disable_suggestions()` was called on the `Diagnostic`.
|
||||
/// Error type for `DiagInner`'s `suggestions` field, indicating that
|
||||
/// `.disable_suggestions()` was called on the `DiagInner`.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
|
||||
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> = (&'iter DiagnosticArgName, &'iter DiagnosticArgValue);
|
||||
/// `DiagArg` are converted to `FluentArgs` (consuming the collection) at the start of diagnostic
|
||||
/// emission.
|
||||
pub type DiagArg<'iter> = (&'iter DiagArgName, &'iter DiagArgValue);
|
||||
|
||||
/// Name of a diagnostic argument.
|
||||
pub type DiagnosticArgName = Cow<'static, str>;
|
||||
pub type DiagArgName = 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 {
|
||||
pub enum DiagArgValue {
|
||||
Str(Cow<'static, str>),
|
||||
// This gets converted to a `FluentNumber`, which is an `f64`. An `i32`
|
||||
// safely fits in an `f64`. Any integers bigger than that will be converted
|
||||
@ -43,31 +43,31 @@ pub enum DiagnosticArgValue {
|
||||
StrListSepByAnd(Vec<Cow<'static, str>>),
|
||||
}
|
||||
|
||||
pub type DiagnosticArgMap = FxIndexMap<DiagnosticArgName, DiagnosticArgValue>;
|
||||
pub type DiagArgMap = FxIndexMap<DiagArgName, DiagArgValue>;
|
||||
|
||||
/// Trait for types that `DiagnosticBuilder::emit` can return as a "guarantee"
|
||||
/// (or "proof") token that the emission happened.
|
||||
/// Trait for types that `Diag::emit` can return as a "guarantee" (or "proof")
|
||||
/// token that the emission happened.
|
||||
pub trait EmissionGuarantee: Sized {
|
||||
/// This exists so that bugs and fatal errors can both result in `!` (an
|
||||
/// abort) when emitted, but have different aborting behaviour.
|
||||
type EmitResult = Self;
|
||||
|
||||
/// Implementation of `DiagnosticBuilder::emit`, fully controlled by each
|
||||
/// `impl` of `EmissionGuarantee`, to make it impossible to create a value
|
||||
/// of `Self::EmitResult` without actually performing the emission.
|
||||
/// Implementation of `Diag::emit`, fully controlled by each `impl` of
|
||||
/// `EmissionGuarantee`, to make it impossible to create a value of
|
||||
/// `Self::EmitResult` without actually performing the emission.
|
||||
#[track_caller]
|
||||
fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult;
|
||||
fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult;
|
||||
}
|
||||
|
||||
impl EmissionGuarantee for ErrorGuaranteed {
|
||||
fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
|
||||
db.emit_producing_error_guaranteed()
|
||||
fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult {
|
||||
diag.emit_producing_error_guaranteed()
|
||||
}
|
||||
}
|
||||
|
||||
impl EmissionGuarantee for () {
|
||||
fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
|
||||
db.emit_producing_nothing();
|
||||
fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult {
|
||||
diag.emit_producing_nothing();
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,8 +79,8 @@ pub struct BugAbort;
|
||||
impl EmissionGuarantee for BugAbort {
|
||||
type EmitResult = !;
|
||||
|
||||
fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
|
||||
db.emit_producing_nothing();
|
||||
fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult {
|
||||
diag.emit_producing_nothing();
|
||||
panic::panic_any(ExplicitBug);
|
||||
}
|
||||
}
|
||||
@ -93,15 +93,15 @@ pub struct FatalAbort;
|
||||
impl EmissionGuarantee for FatalAbort {
|
||||
type EmitResult = !;
|
||||
|
||||
fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
|
||||
db.emit_producing_nothing();
|
||||
fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult {
|
||||
diag.emit_producing_nothing();
|
||||
crate::FatalError.raise()
|
||||
}
|
||||
}
|
||||
|
||||
impl EmissionGuarantee for rustc_span::fatal_error::FatalError {
|
||||
fn emit_producing_guarantee(db: DiagnosticBuilder<'_, Self>) -> Self::EmitResult {
|
||||
db.emit_producing_nothing();
|
||||
fn emit_producing_guarantee(diag: Diag<'_, Self>) -> Self::EmitResult {
|
||||
diag.emit_producing_nothing();
|
||||
rustc_span::fatal_error::FatalError
|
||||
}
|
||||
}
|
||||
@ -112,7 +112,7 @@ impl EmissionGuarantee for rustc_span::fatal_error::FatalError {
|
||||
pub trait IntoDiagnostic<'a, G: EmissionGuarantee = ErrorGuaranteed> {
|
||||
/// Write out as a diagnostic out of `DiagCtxt`.
|
||||
#[must_use]
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G>;
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G>;
|
||||
}
|
||||
|
||||
impl<'a, T, G> IntoDiagnostic<'a, G> for Spanned<T>
|
||||
@ -120,31 +120,31 @@ where
|
||||
T: IntoDiagnostic<'a, G>,
|
||||
G: EmissionGuarantee,
|
||||
{
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> {
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
|
||||
self.node.into_diagnostic(dcx, level).with_span(self.span)
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a value of a type into a `DiagnosticArg` (typically a field of an `IntoDiagnostic`
|
||||
/// struct). Implemented as a custom trait rather than `From` so that it is implemented on the type
|
||||
/// being converted rather than on `DiagnosticArgValue`, which enables types from other `rustc_*`
|
||||
/// crates to implement this.
|
||||
/// Converts a value of a type into a `DiagArg` (typically a field of an `IntoDiagnostic` struct).
|
||||
/// Implemented as a custom trait rather than `From` so that it is implemented on the type being
|
||||
/// converted rather than on `DiagArgValue`, which enables types from other `rustc_*` crates to
|
||||
/// implement this.
|
||||
pub trait IntoDiagnosticArg {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue;
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue;
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for DiagnosticArgValue {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
impl IntoDiagnosticArg for DiagArgValue {
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<FluentValue<'static>> for DiagnosticArgValue {
|
||||
impl Into<FluentValue<'static>> for DiagArgValue {
|
||||
fn into(self) -> FluentValue<'static> {
|
||||
match self {
|
||||
DiagnosticArgValue::Str(s) => From::from(s),
|
||||
DiagnosticArgValue::Number(n) => From::from(n),
|
||||
DiagnosticArgValue::StrListSepByAnd(l) => fluent_value_from_str_list_sep_by_and(l),
|
||||
DiagArgValue::Str(s) => From::from(s),
|
||||
DiagArgValue::Number(n) => From::from(n),
|
||||
DiagArgValue::StrListSepByAnd(l) => fluent_value_from_str_list_sep_by_and(l),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -157,7 +157,7 @@ where
|
||||
Self: Sized,
|
||||
{
|
||||
/// Add a subdiagnostic to an existing diagnostic.
|
||||
fn add_to_diagnostic<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, G>) {
|
||||
fn add_to_diagnostic<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
||||
self.add_to_diagnostic_with(diag, |_, m| m);
|
||||
}
|
||||
|
||||
@ -165,40 +165,40 @@ where
|
||||
/// (to optionally perform eager translation).
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
f: F,
|
||||
);
|
||||
}
|
||||
|
||||
pub trait SubdiagnosticMessageOp<G> =
|
||||
Fn(&mut DiagnosticBuilder<'_, G>, SubdiagnosticMessage) -> SubdiagnosticMessage;
|
||||
Fn(&mut Diag<'_, G>, SubdiagnosticMessage) -> SubdiagnosticMessage;
|
||||
|
||||
/// Trait implemented by lint types. This should not be implemented manually. Instead, use
|
||||
/// `#[derive(LintDiagnostic)]` -- see [rustc_macros::LintDiagnostic].
|
||||
#[rustc_diagnostic_item = "DecorateLint"]
|
||||
pub trait DecorateLint<'a, G: EmissionGuarantee> {
|
||||
/// Decorate and emit a lint.
|
||||
fn decorate_lint<'b>(self, diag: &'b mut DiagnosticBuilder<'a, G>);
|
||||
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>);
|
||||
|
||||
fn msg(&self) -> DiagnosticMessage;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Encodable, Decodable)]
|
||||
pub struct DiagnosticLocation {
|
||||
pub struct DiagLocation {
|
||||
file: Cow<'static, str>,
|
||||
line: u32,
|
||||
col: u32,
|
||||
}
|
||||
|
||||
impl DiagnosticLocation {
|
||||
impl DiagLocation {
|
||||
#[track_caller]
|
||||
fn caller() -> Self {
|
||||
let loc = panic::Location::caller();
|
||||
DiagnosticLocation { file: loc.file().into(), line: loc.line(), col: loc.column() }
|
||||
DiagLocation { file: loc.file().into(), line: loc.line(), col: loc.column() }
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for DiagnosticLocation {
|
||||
impl fmt::Display for DiagLocation {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}:{}:{}", self.file, self.line, self.col)
|
||||
}
|
||||
@ -213,11 +213,11 @@ pub struct IsLint {
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct DiagnosticStyledString(pub Vec<StringPart>);
|
||||
pub struct DiagStyledString(pub Vec<StringPart>);
|
||||
|
||||
impl DiagnosticStyledString {
|
||||
pub fn new() -> DiagnosticStyledString {
|
||||
DiagnosticStyledString(vec![])
|
||||
impl DiagStyledString {
|
||||
pub fn new() -> DiagStyledString {
|
||||
DiagStyledString(vec![])
|
||||
}
|
||||
pub fn push_normal<S: Into<String>>(&mut self, t: S) {
|
||||
self.0.push(StringPart::normal(t));
|
||||
@ -232,12 +232,12 @@ impl DiagnosticStyledString {
|
||||
self.push_normal(t);
|
||||
}
|
||||
}
|
||||
pub fn normal<S: Into<String>>(t: S) -> DiagnosticStyledString {
|
||||
DiagnosticStyledString(vec![StringPart::normal(t)])
|
||||
pub fn normal<S: Into<String>>(t: S) -> DiagStyledString {
|
||||
DiagStyledString(vec![StringPart::normal(t)])
|
||||
}
|
||||
|
||||
pub fn highlighted<S: Into<String>>(t: S) -> DiagnosticStyledString {
|
||||
DiagnosticStyledString(vec![StringPart::highlighted(t)])
|
||||
pub fn highlighted<S: Into<String>>(t: S) -> DiagStyledString {
|
||||
DiagStyledString(vec![StringPart::highlighted(t)])
|
||||
}
|
||||
|
||||
pub fn content(&self) -> String {
|
||||
@ -261,13 +261,13 @@ impl StringPart {
|
||||
}
|
||||
}
|
||||
|
||||
/// The main part of a diagnostic. Note that `DiagnosticBuilder`, which wraps
|
||||
/// this type, is used for most operations, and should be used instead whenever
|
||||
/// possible. This type should only be used when `DiagnosticBuilder`'s lifetime
|
||||
/// causes difficulties, e.g. when storing diagnostics within `DiagCtxt`.
|
||||
/// The main part of a diagnostic. Note that `Diag`, which wraps this type, is
|
||||
/// used for most operations, and should be used instead whenever possible.
|
||||
/// This type should only be used when `Diag`'s lifetime causes difficulties,
|
||||
/// e.g. when storing diagnostics within `DiagCtxt`.
|
||||
#[must_use]
|
||||
#[derive(Clone, Debug, Encodable, Decodable)]
|
||||
pub struct Diagnostic {
|
||||
pub struct DiagInner {
|
||||
// NOTE(eddyb) this is private to disallow arbitrary after-the-fact changes,
|
||||
// outside of what methods in this crate themselves allow.
|
||||
pub(crate) level: Level,
|
||||
@ -275,9 +275,9 @@ pub struct Diagnostic {
|
||||
pub messages: Vec<(DiagnosticMessage, Style)>,
|
||||
pub code: Option<ErrCode>,
|
||||
pub span: MultiSpan,
|
||||
pub children: Vec<SubDiagnostic>,
|
||||
pub children: Vec<Subdiag>,
|
||||
pub suggestions: Result<Vec<CodeSuggestion>, SuggestionsDisabled>,
|
||||
pub args: DiagnosticArgMap,
|
||||
pub args: DiagArgMap,
|
||||
|
||||
/// 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
|
||||
@ -288,18 +288,18 @@ pub struct Diagnostic {
|
||||
|
||||
/// With `-Ztrack_diagnostics` enabled,
|
||||
/// we print where in rustc this error was emitted.
|
||||
pub(crate) emitted_at: DiagnosticLocation,
|
||||
pub(crate) emitted_at: DiagLocation,
|
||||
}
|
||||
|
||||
impl Diagnostic {
|
||||
impl DiagInner {
|
||||
#[track_caller]
|
||||
pub fn new<M: Into<DiagnosticMessage>>(level: Level, message: M) -> Self {
|
||||
Diagnostic::new_with_messages(level, vec![(message.into(), Style::NoStyle)])
|
||||
DiagInner::new_with_messages(level, vec![(message.into(), Style::NoStyle)])
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn new_with_messages(level: Level, messages: Vec<(DiagnosticMessage, Style)>) -> Self {
|
||||
Diagnostic {
|
||||
DiagInner {
|
||||
level,
|
||||
messages,
|
||||
code: None,
|
||||
@ -309,7 +309,7 @@ impl Diagnostic {
|
||||
args: Default::default(),
|
||||
sort_span: DUMMY_SP,
|
||||
is_lint: None,
|
||||
emitted_at: DiagnosticLocation::caller(),
|
||||
emitted_at: DiagLocation::caller(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -374,7 +374,7 @@ impl Diagnostic {
|
||||
}
|
||||
}
|
||||
|
||||
// See comment on `DiagnosticBuilder::subdiagnostic_message_to_diagnostic_message`.
|
||||
// See comment on `Diag::subdiagnostic_message_to_diagnostic_message`.
|
||||
pub(crate) fn subdiagnostic_message_to_diagnostic_message(
|
||||
&self,
|
||||
attr: impl Into<SubdiagnosticMessage>,
|
||||
@ -390,7 +390,7 @@ impl Diagnostic {
|
||||
message: impl Into<SubdiagnosticMessage>,
|
||||
span: MultiSpan,
|
||||
) {
|
||||
let sub = SubDiagnostic {
|
||||
let sub = Subdiag {
|
||||
level,
|
||||
messages: vec![(
|
||||
self.subdiagnostic_message_to_diagnostic_message(message),
|
||||
@ -401,7 +401,7 @@ impl Diagnostic {
|
||||
self.children.push(sub);
|
||||
}
|
||||
|
||||
pub(crate) fn arg(&mut self, name: impl Into<DiagnosticArgName>, arg: impl IntoDiagnosticArg) {
|
||||
pub(crate) fn arg(&mut self, name: impl Into<DiagArgName>, arg: impl IntoDiagnosticArg) {
|
||||
self.args.insert(name.into(), arg.into_diagnostic_arg());
|
||||
}
|
||||
|
||||
@ -413,9 +413,9 @@ impl Diagnostic {
|
||||
&[(DiagnosticMessage, Style)],
|
||||
&Option<ErrCode>,
|
||||
&MultiSpan,
|
||||
&[SubDiagnostic],
|
||||
&[Subdiag],
|
||||
&Result<Vec<CodeSuggestion>, SuggestionsDisabled>,
|
||||
Vec<(&DiagnosticArgName, &DiagnosticArgValue)>,
|
||||
Vec<(&DiagArgName, &DiagArgValue)>,
|
||||
&Option<IsLint>,
|
||||
) {
|
||||
(
|
||||
@ -433,7 +433,7 @@ impl Diagnostic {
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for Diagnostic {
|
||||
impl Hash for DiagInner {
|
||||
fn hash<H>(&self, state: &mut H)
|
||||
where
|
||||
H: Hasher,
|
||||
@ -442,7 +442,7 @@ impl Hash for Diagnostic {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Diagnostic {
|
||||
impl PartialEq for DiagInner {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.keys() == other.keys()
|
||||
}
|
||||
@ -451,75 +451,70 @@ impl PartialEq for Diagnostic {
|
||||
/// A "sub"-diagnostic attached to a parent diagnostic.
|
||||
/// For example, a note attached to an error.
|
||||
#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)]
|
||||
pub struct SubDiagnostic {
|
||||
pub struct Subdiag {
|
||||
pub level: Level,
|
||||
pub messages: Vec<(DiagnosticMessage, Style)>,
|
||||
pub span: MultiSpan,
|
||||
}
|
||||
|
||||
/// Used for emitting structured error messages and other diagnostic information.
|
||||
/// Wraps a `Diagnostic`, adding some useful things.
|
||||
/// Wraps a `DiagInner`, adding some useful things.
|
||||
/// - The `dcx` field, allowing it to (a) emit itself, and (b) do a drop check
|
||||
/// that it has been emitted or cancelled.
|
||||
/// - The `EmissionGuarantee`, which determines the type returned from `emit`.
|
||||
///
|
||||
/// Each constructed `DiagnosticBuilder` must be consumed by a function such as
|
||||
/// `emit`, `cancel`, `delay_as_bug`, or `into_diagnostic`. A panic occurrs if a
|
||||
/// `DiagnosticBuilder` is dropped without being consumed by one of these
|
||||
/// functions.
|
||||
/// Each constructed `Diag` must be consumed by a function such as `emit`,
|
||||
/// `cancel`, `delay_as_bug`, or `into_diagnostic`. A panic occurrs if a `Diag`
|
||||
/// is dropped without being consumed by one of these functions.
|
||||
///
|
||||
/// If there is some state in a downstream crate you would like to
|
||||
/// access in the methods of `DiagnosticBuilder` here, consider
|
||||
/// extending `DiagCtxtFlags`.
|
||||
/// If there is some state in a downstream crate you would like to access in
|
||||
/// the methods of `Diag` here, consider extending `DiagCtxtFlags`.
|
||||
#[must_use]
|
||||
pub struct DiagnosticBuilder<'a, G: EmissionGuarantee = ErrorGuaranteed> {
|
||||
pub struct Diag<'a, G: EmissionGuarantee = ErrorGuaranteed> {
|
||||
pub dcx: &'a DiagCtxt,
|
||||
|
||||
/// Why the `Option`? It is always `Some` until the `DiagnosticBuilder` is
|
||||
/// consumed via `emit`, `cancel`, etc. At that point it is consumed and
|
||||
/// replaced with `None`. Then `drop` checks that it is `None`; if not, it
|
||||
/// panics because a diagnostic was built but not used.
|
||||
/// Why the `Option`? It is always `Some` until the `Diag` is consumed via
|
||||
/// `emit`, `cancel`, etc. At that point it is consumed and replaced with
|
||||
/// `None`. Then `drop` checks that it is `None`; if not, it panics because
|
||||
/// a diagnostic was built but not used.
|
||||
///
|
||||
/// Why the Box? `Diagnostic` is a large type, and `DiagnosticBuilder` is
|
||||
/// often used as a return value, especially within the frequently-used
|
||||
/// `PResult` type. In theory, return value optimization (RVO) should avoid
|
||||
/// unnecessary copying. In practice, it does not (at the time of writing).
|
||||
diag: Option<Box<Diagnostic>>,
|
||||
/// Why the Box? `DiagInner` is a large type, and `Diag` is often used as a
|
||||
/// return value, especially within the frequently-used `PResult` type. In
|
||||
/// theory, return value optimization (RVO) should avoid unnecessary
|
||||
/// copying. In practice, it does not (at the time of writing).
|
||||
diag: Option<Box<DiagInner>>,
|
||||
|
||||
_marker: PhantomData<G>,
|
||||
}
|
||||
|
||||
// Cloning a `DiagnosticBuilder` is a recipe for a diagnostic being emitted
|
||||
// twice, which would be bad.
|
||||
impl<G> !Clone for DiagnosticBuilder<'_, G> {}
|
||||
// Cloning a `Diag` is a recipe for a diagnostic being emitted twice, which
|
||||
// would be bad.
|
||||
impl<G> !Clone for Diag<'_, G> {}
|
||||
|
||||
rustc_data_structures::static_assert_size!(
|
||||
DiagnosticBuilder<'_, ()>,
|
||||
2 * std::mem::size_of::<usize>()
|
||||
);
|
||||
rustc_data_structures::static_assert_size!(Diag<'_, ()>, 2 * std::mem::size_of::<usize>());
|
||||
|
||||
impl<G: EmissionGuarantee> Deref for DiagnosticBuilder<'_, G> {
|
||||
type Target = Diagnostic;
|
||||
impl<G: EmissionGuarantee> Deref for Diag<'_, G> {
|
||||
type Target = DiagInner;
|
||||
|
||||
fn deref(&self) -> &Diagnostic {
|
||||
fn deref(&self) -> &DiagInner {
|
||||
self.diag.as_ref().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: EmissionGuarantee> DerefMut for DiagnosticBuilder<'_, G> {
|
||||
fn deref_mut(&mut self) -> &mut Diagnostic {
|
||||
impl<G: EmissionGuarantee> DerefMut for Diag<'_, G> {
|
||||
fn deref_mut(&mut self) -> &mut DiagInner {
|
||||
self.diag.as_mut().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: EmissionGuarantee> Debug for DiagnosticBuilder<'_, G> {
|
||||
impl<G: EmissionGuarantee> Debug for Diag<'_, G> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.diag.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
/// `DiagnosticBuilder` impls many `&mut self -> &mut Self` methods. Each one
|
||||
/// modifies an existing diagnostic, either in a standalone fashion, e.g.
|
||||
/// `Diag` impls many `&mut self -> &mut Self` methods. Each one modifies an
|
||||
/// existing diagnostic, either in a standalone fashion, e.g.
|
||||
/// `err.code(code);`, or in a chained fashion to make multiple modifications,
|
||||
/// e.g. `err.code(code).span(span);`.
|
||||
///
|
||||
@ -546,14 +541,14 @@ macro_rules! with_fn {
|
||||
} => {
|
||||
// The original function.
|
||||
$(#[$attrs])*
|
||||
#[doc = concat!("See [`DiagnosticBuilder::", stringify!($f), "()`].")]
|
||||
#[doc = concat!("See [`Diag::", stringify!($f), "()`].")]
|
||||
pub fn $f(&mut $self, $($name: $ty),*) -> &mut Self {
|
||||
$($body)*
|
||||
}
|
||||
|
||||
// The `with_*` variant.
|
||||
$(#[$attrs])*
|
||||
#[doc = concat!("See [`DiagnosticBuilder::", stringify!($f), "()`].")]
|
||||
#[doc = concat!("See [`Diag::", stringify!($f), "()`].")]
|
||||
pub fn $with_f(mut $self, $($name: $ty),*) -> Self {
|
||||
$self.$f($($name),*);
|
||||
$self
|
||||
@ -561,17 +556,16 @@ macro_rules! with_fn {
|
||||
};
|
||||
}
|
||||
|
||||
impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
impl<'a, G: EmissionGuarantee> Diag<'a, G> {
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn new<M: Into<DiagnosticMessage>>(dcx: &'a DiagCtxt, level: Level, message: M) -> Self {
|
||||
Self::new_diagnostic(dcx, Diagnostic::new(level, message))
|
||||
Self::new_diagnostic(dcx, DiagInner::new(level, message))
|
||||
}
|
||||
|
||||
/// Creates a new `DiagnosticBuilder` with an already constructed
|
||||
/// diagnostic.
|
||||
/// Creates a new `Diag` with an already constructed diagnostic.
|
||||
#[track_caller]
|
||||
pub(crate) fn new_diagnostic(dcx: &'a DiagCtxt, diag: Diagnostic) -> Self {
|
||||
pub(crate) fn new_diagnostic(dcx: &'a DiagCtxt, diag: DiagInner) -> Self {
|
||||
debug!("Created new diagnostic");
|
||||
Self { dcx, diag: Some(Box::new(diag)), _marker: PhantomData }
|
||||
}
|
||||
@ -644,9 +638,9 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
pub fn note_expected_found(
|
||||
&mut self,
|
||||
expected_label: &dyn fmt::Display,
|
||||
expected: DiagnosticStyledString,
|
||||
expected: DiagStyledString,
|
||||
found_label: &dyn fmt::Display,
|
||||
found: DiagnosticStyledString,
|
||||
found: DiagStyledString,
|
||||
) -> &mut Self {
|
||||
self.note_expected_found_extra(expected_label, expected, found_label, found, &"", &"")
|
||||
}
|
||||
@ -654,9 +648,9 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
pub fn note_expected_found_extra(
|
||||
&mut self,
|
||||
expected_label: &dyn fmt::Display,
|
||||
expected: DiagnosticStyledString,
|
||||
expected: DiagStyledString,
|
||||
found_label: &dyn fmt::Display,
|
||||
found: DiagnosticStyledString,
|
||||
found: DiagStyledString,
|
||||
expected_extra: &dyn fmt::Display,
|
||||
found_extra: &dyn fmt::Display,
|
||||
) -> &mut Self {
|
||||
@ -715,7 +709,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
self
|
||||
}
|
||||
|
||||
/// This is like [`DiagnosticBuilder::note()`], but it's only printed once.
|
||||
/// This is like [`Diag::note()`], but it's only printed once.
|
||||
pub fn note_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
|
||||
self.sub(Level::OnceNote, msg, MultiSpan::new());
|
||||
self
|
||||
@ -723,7 +717,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
|
||||
with_fn! { with_span_note,
|
||||
/// Prints the span with a note above it.
|
||||
/// This is like [`DiagnosticBuilder::note()`], but it gets its own span.
|
||||
/// This is like [`Diag::note()`], but it gets its own span.
|
||||
#[rustc_lint_diagnostics]
|
||||
pub fn span_note(
|
||||
&mut self,
|
||||
@ -735,7 +729,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
} }
|
||||
|
||||
/// Prints the span with a note above it.
|
||||
/// This is like [`DiagnosticBuilder::note_once()`], but it gets its own span.
|
||||
/// This is like [`Diag::note_once()`], but it gets its own span.
|
||||
pub fn span_note_once<S: Into<MultiSpan>>(
|
||||
&mut self,
|
||||
sp: S,
|
||||
@ -754,7 +748,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
} }
|
||||
|
||||
/// Prints the span with a warning above it.
|
||||
/// This is like [`DiagnosticBuilder::warn()`], but it gets its own span.
|
||||
/// This is like [`Diag::warn()`], but it gets its own span.
|
||||
#[rustc_lint_diagnostics]
|
||||
pub fn span_warn<S: Into<MultiSpan>>(
|
||||
&mut self,
|
||||
@ -773,7 +767,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
self
|
||||
} }
|
||||
|
||||
/// This is like [`DiagnosticBuilder::help()`], but it's only printed once.
|
||||
/// This is like [`Diag::help()`], but it's only printed once.
|
||||
pub fn help_once(&mut self, msg: impl Into<SubdiagnosticMessage>) -> &mut Self {
|
||||
self.sub(Level::OnceHelp, msg, MultiSpan::new());
|
||||
self
|
||||
@ -786,7 +780,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
}
|
||||
|
||||
/// Prints the span with some help above it.
|
||||
/// This is like [`DiagnosticBuilder::help()`], but it gets its own span.
|
||||
/// This is like [`Diag::help()`], but it gets its own span.
|
||||
#[rustc_lint_diagnostics]
|
||||
pub fn span_help<S: Into<MultiSpan>>(
|
||||
&mut self,
|
||||
@ -856,7 +850,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
)
|
||||
}
|
||||
|
||||
/// [`DiagnosticBuilder::multipart_suggestion()`] but you can set the [`SuggestionStyle`].
|
||||
/// [`Diag::multipart_suggestion()`] but you can set the [`SuggestionStyle`].
|
||||
pub fn multipart_suggestion_with_style(
|
||||
&mut self,
|
||||
msg: impl Into<SubdiagnosticMessage>,
|
||||
@ -948,7 +942,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
self
|
||||
} }
|
||||
|
||||
/// [`DiagnosticBuilder::span_suggestion()`] but you can set the [`SuggestionStyle`].
|
||||
/// [`Diag::span_suggestion()`] but you can set the [`SuggestionStyle`].
|
||||
pub fn span_suggestion_with_style(
|
||||
&mut self,
|
||||
sp: Span,
|
||||
@ -993,7 +987,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
|
||||
with_fn! { with_span_suggestions,
|
||||
/// Prints out a message with multiple suggested edits of the code.
|
||||
/// See also [`DiagnosticBuilder::span_suggestion()`].
|
||||
/// See also [`Diag::span_suggestion()`].
|
||||
pub fn span_suggestions(
|
||||
&mut self,
|
||||
sp: Span,
|
||||
@ -1039,7 +1033,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
|
||||
/// Prints out a message with multiple suggested edits of the code, where each edit consists of
|
||||
/// multiple parts.
|
||||
/// See also [`DiagnosticBuilder::multipart_suggestion()`].
|
||||
/// See also [`Diag::multipart_suggestion()`].
|
||||
pub fn multipart_suggestions(
|
||||
&mut self,
|
||||
msg: impl Into<SubdiagnosticMessage>,
|
||||
@ -1199,7 +1193,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
/// Add an argument.
|
||||
pub fn arg(
|
||||
&mut self,
|
||||
name: impl Into<DiagnosticArgName>,
|
||||
name: impl Into<DiagArgName>,
|
||||
arg: impl IntoDiagnosticArg,
|
||||
) -> &mut Self {
|
||||
self.deref_mut().arg(name, arg);
|
||||
@ -1231,14 +1225,14 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
.into_iter()
|
||||
.map(|m| (self.subdiagnostic_message_to_diagnostic_message(m.content), m.style))
|
||||
.collect();
|
||||
let sub = SubDiagnostic { level, messages, span };
|
||||
let sub = Subdiag { level, messages, span };
|
||||
self.children.push(sub);
|
||||
}
|
||||
|
||||
/// Takes the diagnostic. For use by methods that consume the
|
||||
/// DiagnosticBuilder: `emit`, `cancel`, etc. Afterwards, `drop` is the
|
||||
/// only code that will be run on `self`.
|
||||
fn take_diag(&mut self) -> Diagnostic {
|
||||
/// Takes the diagnostic. For use by methods that consume the Diag: `emit`,
|
||||
/// `cancel`, etc. Afterwards, `drop` is the only code that will be run on
|
||||
/// `self`.
|
||||
fn take_diag(&mut self) -> DiagInner {
|
||||
Box::into_inner(self.diag.take().unwrap())
|
||||
}
|
||||
|
||||
@ -1257,7 +1251,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
// because delayed bugs have their level changed to `Bug` when they are
|
||||
// actually printed, so they produce an ICE.
|
||||
//
|
||||
// (Also, even though `level` isn't `pub`, the whole `Diagnostic` could
|
||||
// (Also, even though `level` isn't `pub`, the whole `DiagInner` could
|
||||
// be overwritten with a new one thanks to `DerefMut`. So this assert
|
||||
// protects against that, too.)
|
||||
assert!(
|
||||
@ -1319,13 +1313,13 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Destructor bomb: every `DiagnosticBuilder` must be consumed (emitted,
|
||||
/// cancelled, etc.) or we emit a bug.
|
||||
impl<G: EmissionGuarantee> Drop for DiagnosticBuilder<'_, G> {
|
||||
/// Destructor bomb: every `Diag` must be consumed (emitted, cancelled, etc.)
|
||||
/// or we emit a bug.
|
||||
impl<G: EmissionGuarantee> Drop for Diag<'_, G> {
|
||||
fn drop(&mut self) {
|
||||
match self.diag.take() {
|
||||
Some(diag) if !panicking() => {
|
||||
self.dcx.emit_diagnostic(Diagnostic::new(
|
||||
self.dcx.emit_diagnostic(DiagInner::new(
|
||||
Level::Bug,
|
||||
DiagnosticMessage::from("the following error was constructed but not emitted"),
|
||||
));
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::diagnostic::DiagnosticLocation;
|
||||
use crate::diagnostic::DiagLocation;
|
||||
use crate::{fluent_generated as fluent, AddToDiagnostic};
|
||||
use crate::{
|
||||
DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, ErrCode, IntoDiagnostic,
|
||||
IntoDiagnosticArg, Level, SubdiagnosticMessageOp,
|
||||
Diag, DiagArgValue, DiagCtxt, EmissionGuarantee, ErrCode, IntoDiagnostic, IntoDiagnosticArg,
|
||||
Level, SubdiagnosticMessageOp,
|
||||
};
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast_pretty::pprust;
|
||||
@ -20,28 +20,28 @@ use std::num::ParseIntError;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::ExitStatus;
|
||||
|
||||
pub struct DiagnosticArgFromDisplay<'a>(pub &'a dyn fmt::Display);
|
||||
pub struct DiagArgFromDisplay<'a>(pub &'a dyn fmt::Display);
|
||||
|
||||
impl IntoDiagnosticArg for DiagnosticArgFromDisplay<'_> {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
impl IntoDiagnosticArg for DiagArgFromDisplay<'_> {
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
self.0.to_string().into_diagnostic_arg()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a dyn fmt::Display> for DiagnosticArgFromDisplay<'a> {
|
||||
impl<'a> From<&'a dyn fmt::Display> for DiagArgFromDisplay<'a> {
|
||||
fn from(t: &'a dyn fmt::Display) -> Self {
|
||||
DiagnosticArgFromDisplay(t)
|
||||
DiagArgFromDisplay(t)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: fmt::Display> From<&'a T> for DiagnosticArgFromDisplay<'a> {
|
||||
impl<'a, T: fmt::Display> From<&'a T> for DiagArgFromDisplay<'a> {
|
||||
fn from(t: &'a T) -> Self {
|
||||
DiagnosticArgFromDisplay(t)
|
||||
DiagArgFromDisplay(t)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Clone + IntoDiagnosticArg> IntoDiagnosticArg for &'a T {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
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 {
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
self.to_string().into_diagnostic_arg()
|
||||
}
|
||||
}
|
||||
@ -62,10 +62,10 @@ macro_rules! into_diagnostic_arg_for_number {
|
||||
($( $ty:ty ),+ $(,)?) => {
|
||||
$(
|
||||
impl IntoDiagnosticArg for $ty {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
// Convert to a string if it won't fit into `Number`.
|
||||
if let Ok(n) = TryInto::<i32>::try_into(self) {
|
||||
DiagnosticArgValue::Number(n)
|
||||
DiagArgValue::Number(n)
|
||||
} else {
|
||||
self.to_string().into_diagnostic_arg()
|
||||
}
|
||||
@ -95,74 +95,74 @@ into_diagnostic_arg_using_display!(
|
||||
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 {
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
if self {
|
||||
DiagnosticArgValue::Str(Cow::Borrowed("true"))
|
||||
DiagArgValue::Str(Cow::Borrowed("true"))
|
||||
} else {
|
||||
DiagnosticArgValue::Str(Cow::Borrowed("false"))
|
||||
DiagArgValue::Str(Cow::Borrowed("false"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for char {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::Owned(format!("{self:?}")))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::Owned(format!("{self:?}")))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for Vec<char> {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::StrListSepByAnd(
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::StrListSepByAnd(
|
||||
self.into_iter().map(|c| Cow::Owned(format!("{c:?}"))).collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for Symbol {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
self.to_ident_string().into_diagnostic_arg()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoDiagnosticArg for &'a str {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
self.to_string().into_diagnostic_arg()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for String {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::Owned(self))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::Owned(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoDiagnosticArg for Cow<'a, str> {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::Owned(self.into_owned()))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::Owned(self.into_owned()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoDiagnosticArg for &'a Path {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::Owned(self.display().to_string()))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::Owned(self.display().to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for PathBuf {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::Owned(self.display().to_string()))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::Owned(self.display().to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for PanicStrategy {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::Owned(self.desc().to_string()))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::Owned(self.desc().to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for hir::ConstContext {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::Borrowed(match self {
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::Borrowed(match self {
|
||||
hir::ConstContext::ConstFn => "const_fn",
|
||||
hir::ConstContext::Static(_) => "static",
|
||||
hir::ConstContext::Const { .. } => "const",
|
||||
@ -171,123 +171,122 @@ impl IntoDiagnosticArg for hir::ConstContext {
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for ast::Expr {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::Owned(pprust::expr_to_string(&self)))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::Owned(pprust::expr_to_string(&self)))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for ast::Path {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::Owned(pprust::path_to_string(&self)))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::Owned(pprust::path_to_string(&self)))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for ast::token::Token {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(pprust::token_to_string(&self))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(pprust::token_to_string(&self))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for ast::token::TokenKind {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(pprust::token_kind_to_string(&self))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(pprust::token_kind_to_string(&self))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for type_ir::FloatTy {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::Borrowed(self.name_str()))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::Borrowed(self.name_str()))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for std::ffi::CString {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned()))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::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 {
|
||||
DiagnosticArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned()))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned()))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for ast::Visibility {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
let s = pprust::vis_to_string(&self);
|
||||
let s = s.trim_end().to_string();
|
||||
DiagnosticArgValue::Str(Cow::Owned(s))
|
||||
DiagArgValue::Str(Cow::Owned(s))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for rustc_lint_defs::Level {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::Borrowed(self.to_cmd_flag()))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::Borrowed(self.to_cmd_flag()))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DiagnosticSymbolList(Vec<Symbol>);
|
||||
pub struct DiagSymbolList(Vec<Symbol>);
|
||||
|
||||
impl From<Vec<Symbol>> for DiagnosticSymbolList {
|
||||
impl From<Vec<Symbol>> for DiagSymbolList {
|
||||
fn from(v: Vec<Symbol>) -> Self {
|
||||
DiagnosticSymbolList(v)
|
||||
DiagSymbolList(v)
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for DiagnosticSymbolList {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::StrListSepByAnd(
|
||||
impl IntoDiagnosticArg for DiagSymbolList {
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::StrListSepByAnd(
|
||||
self.0.into_iter().map(|sym| Cow::Owned(format!("`{sym}`"))).collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Id> IntoDiagnosticArg for hir::def::Res<Id> {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::Borrowed(self.descr()))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::Borrowed(self.descr()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetDataLayoutErrors<'_> {
|
||||
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
|
||||
fn into_diagnostic(self, dcx: &DiagCtxt, level: Level) -> Diag<'_, G> {
|
||||
match self {
|
||||
TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => {
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_address_space)
|
||||
Diag::new(dcx, level, fluent::errors_target_invalid_address_space)
|
||||
.with_arg("addr_space", addr_space)
|
||||
.with_arg("cause", cause)
|
||||
.with_arg("err", err)
|
||||
}
|
||||
TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => {
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_bits)
|
||||
Diag::new(dcx, level, fluent::errors_target_invalid_bits)
|
||||
.with_arg("kind", kind)
|
||||
.with_arg("bit", bit)
|
||||
.with_arg("cause", cause)
|
||||
.with_arg("err", err)
|
||||
}
|
||||
TargetDataLayoutErrors::MissingAlignment { cause } => {
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_missing_alignment)
|
||||
Diag::new(dcx, level, fluent::errors_target_missing_alignment)
|
||||
.with_arg("cause", cause)
|
||||
}
|
||||
TargetDataLayoutErrors::InvalidAlignment { cause, err } => {
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_alignment)
|
||||
Diag::new(dcx, level, fluent::errors_target_invalid_alignment)
|
||||
.with_arg("cause", cause)
|
||||
.with_arg("err_kind", err.diag_ident())
|
||||
.with_arg("align", err.align())
|
||||
}
|
||||
TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => {
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_inconsistent_architecture)
|
||||
Diag::new(dcx, level, fluent::errors_target_inconsistent_architecture)
|
||||
.with_arg("dl", dl)
|
||||
.with_arg("target", target)
|
||||
}
|
||||
TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => {
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_inconsistent_pointer_width)
|
||||
Diag::new(dcx, level, fluent::errors_target_inconsistent_pointer_width)
|
||||
.with_arg("pointer_size", pointer_size)
|
||||
.with_arg("target", target)
|
||||
}
|
||||
TargetDataLayoutErrors::InvalidBitsSize { err } => {
|
||||
DiagnosticBuilder::new(dcx, level, fluent::errors_target_invalid_bits_size)
|
||||
.with_arg("err", err)
|
||||
Diag::new(dcx, level, fluent::errors_target_invalid_bits_size).with_arg("err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -301,7 +300,7 @@ pub struct SingleLabelManySpans {
|
||||
impl AddToDiagnostic for SingleLabelManySpans {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
_: F,
|
||||
) {
|
||||
diag.span_labels(self.spans, self.label);
|
||||
@ -316,21 +315,21 @@ pub struct ExpectedLifetimeParameter {
|
||||
pub count: usize,
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for DiagnosticLocation {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::from(self.to_string()))
|
||||
impl IntoDiagnosticArg for DiagLocation {
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::from(self.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for Backtrace {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::from(self.to_string()))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::from(self.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for Level {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(Cow::from(self.to_string()))
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(Cow::from(self.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -344,7 +343,7 @@ pub struct IndicateAnonymousLifetime {
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for type_ir::ClosureKind {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
DiagnosticArgValue::Str(self.as_str().into())
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
DiagArgValue::Str(self.as_str().into())
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! The current rustc diagnostics emitter.
|
||||
//!
|
||||
//! An `Emitter` takes care of generating the output from a `DiagnosticBuilder` struct.
|
||||
//! An `Emitter` takes care of generating the output from a `Diag` struct.
|
||||
//!
|
||||
//! There are various `Emitter` implementations that generate different output formats such as
|
||||
//! JSON and human readable output.
|
||||
@ -17,16 +17,15 @@ use crate::snippet::{
|
||||
use crate::styled_buffer::StyledBuffer;
|
||||
use crate::translation::{to_fluent_args, Translate};
|
||||
use crate::{
|
||||
diagnostic::DiagnosticLocation, CodeSuggestion, DiagCtxt, Diagnostic, DiagnosticMessage,
|
||||
ErrCode, FluentBundle, LazyFallbackBundle, Level, MultiSpan, SubDiagnostic,
|
||||
SubstitutionHighlight, SuggestionStyle, TerminalUrl,
|
||||
diagnostic::DiagLocation, CodeSuggestion, DiagCtxt, DiagInner, DiagnosticMessage, ErrCode,
|
||||
FluentBundle, LazyFallbackBundle, Level, MultiSpan, Subdiag, SubstitutionHighlight,
|
||||
SuggestionStyle, TerminalUrl,
|
||||
};
|
||||
use rustc_lint_defs::pluralize;
|
||||
|
||||
use derive_setters::Setters;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::sync::{DynSend, IntoDynSyncSend, Lrc};
|
||||
use rustc_error_messages::{FluentArgs, SpanLabel};
|
||||
use rustc_lint_defs::pluralize;
|
||||
use rustc_span::hygiene::{ExpnKind, MacroKind};
|
||||
use std::borrow::Cow;
|
||||
use std::cmp::{max, min, Reverse};
|
||||
@ -35,7 +34,7 @@ use std::io::prelude::*;
|
||||
use std::io::{self, IsTerminal};
|
||||
use std::iter;
|
||||
use std::path::Path;
|
||||
use termcolor::{Ansi, Buffer, BufferWriter, ColorChoice, ColorSpec, StandardStream};
|
||||
use termcolor::{Buffer, BufferWriter, ColorChoice, ColorSpec, StandardStream};
|
||||
use termcolor::{Color, WriteColor};
|
||||
|
||||
/// Default column width, used in tests and when terminal dimensions cannot be determined.
|
||||
@ -58,18 +57,6 @@ impl HumanReadableErrorType {
|
||||
HumanReadableErrorType::AnnotateSnippet(cc) => (false, cc),
|
||||
}
|
||||
}
|
||||
pub fn new_emitter(
|
||||
self,
|
||||
mut dst: Box<dyn WriteColor + Send>,
|
||||
fallback_bundle: LazyFallbackBundle,
|
||||
) -> HumanEmitter {
|
||||
let (short, color_config) = self.unzip();
|
||||
let color = color_config.suggests_using_colors();
|
||||
if !dst.supports_color() && color {
|
||||
dst = Box::new(Ansi::new(dst));
|
||||
}
|
||||
HumanEmitter::new(dst, fallback_bundle).short_message(short)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@ -130,8 +117,8 @@ impl Margin {
|
||||
fn was_cut_right(&self, line_len: usize) -> bool {
|
||||
let right =
|
||||
if self.computed_right == self.span_right || self.computed_right == self.label_right {
|
||||
// Account for the "..." padding given above. Otherwise we end up with code lines that
|
||||
// do fit but end in "..." as if they were trimmed.
|
||||
// Account for the "..." padding given above. Otherwise we end up with code lines
|
||||
// that do fit but end in "..." as if they were trimmed.
|
||||
self.computed_right - 6
|
||||
} else {
|
||||
self.computed_right
|
||||
@ -194,7 +181,7 @@ pub type DynEmitter = dyn Emitter + DynSend;
|
||||
/// Emitter trait for emitting errors.
|
||||
pub trait Emitter: Translate {
|
||||
/// Emit a structured diagnostic.
|
||||
fn emit_diagnostic(&mut self, diag: Diagnostic);
|
||||
fn emit_diagnostic(&mut self, diag: DiagInner);
|
||||
|
||||
/// Emit a notification that an artifact has been output.
|
||||
/// Currently only supported for the JSON format.
|
||||
@ -202,7 +189,7 @@ pub trait Emitter: Translate {
|
||||
|
||||
/// Emit a report about future breakage.
|
||||
/// Currently only supported for the JSON format.
|
||||
fn emit_future_breakage_report(&mut self, _diags: Vec<Diagnostic>) {}
|
||||
fn emit_future_breakage_report(&mut self, _diags: Vec<DiagInner>) {}
|
||||
|
||||
/// Emit list of unused externs.
|
||||
/// Currently only supported for the JSON format.
|
||||
@ -229,12 +216,12 @@ pub trait Emitter: Translate {
|
||||
///
|
||||
/// There are a lot of conditions to this method, but in short:
|
||||
///
|
||||
/// * If the current `Diagnostic` has only one visible `CodeSuggestion`,
|
||||
/// * If the current `DiagInner` has only one visible `CodeSuggestion`,
|
||||
/// we format the `help` suggestion depending on the content of the
|
||||
/// substitutions. In that case, we modify the span and clear the
|
||||
/// suggestions.
|
||||
///
|
||||
/// * If the current `Diagnostic` has multiple suggestions,
|
||||
/// * If the current `DiagInner` has multiple suggestions,
|
||||
/// we leave `primary_span` and the suggestions untouched.
|
||||
fn primary_span_formatted(
|
||||
&mut self,
|
||||
@ -303,7 +290,7 @@ pub trait Emitter: Translate {
|
||||
fn fix_multispans_in_extern_macros_and_render_macro_backtrace(
|
||||
&self,
|
||||
span: &mut MultiSpan,
|
||||
children: &mut Vec<SubDiagnostic>,
|
||||
children: &mut Vec<Subdiag>,
|
||||
level: &Level,
|
||||
backtrace: bool,
|
||||
) {
|
||||
@ -350,7 +337,7 @@ pub trait Emitter: Translate {
|
||||
(in Nightly builds, run with -Z macro-backtrace for more info)",
|
||||
);
|
||||
|
||||
children.push(SubDiagnostic {
|
||||
children.push(Subdiag {
|
||||
level: Level::Note,
|
||||
messages: vec![(DiagnosticMessage::from(msg), Style::NoStyle)],
|
||||
span: MultiSpan::new(),
|
||||
@ -362,7 +349,7 @@ pub trait Emitter: Translate {
|
||||
fn render_multispans_macro_backtrace(
|
||||
&self,
|
||||
span: &mut MultiSpan,
|
||||
children: &mut Vec<SubDiagnostic>,
|
||||
children: &mut Vec<Subdiag>,
|
||||
backtrace: bool,
|
||||
) {
|
||||
for span in iter::once(span).chain(children.iter_mut().map(|child| &mut child.span)) {
|
||||
@ -461,11 +448,7 @@ pub trait Emitter: Translate {
|
||||
// This does a small "fix" for multispans by looking to see if it can find any that
|
||||
// point directly at external macros. Since these are often difficult to read,
|
||||
// this will change the span to point at the use site.
|
||||
fn fix_multispans_in_extern_macros(
|
||||
&self,
|
||||
span: &mut MultiSpan,
|
||||
children: &mut Vec<SubDiagnostic>,
|
||||
) {
|
||||
fn fix_multispans_in_extern_macros(&self, span: &mut MultiSpan, children: &mut Vec<Subdiag>) {
|
||||
debug!("fix_multispans_in_extern_macros: before: span={:?} children={:?}", span, children);
|
||||
self.fix_multispan_in_extern_macros(span);
|
||||
for child in children.iter_mut() {
|
||||
@ -518,7 +501,7 @@ impl Emitter for HumanEmitter {
|
||||
self.sm.as_ref()
|
||||
}
|
||||
|
||||
fn emit_diagnostic(&mut self, mut diag: Diagnostic) {
|
||||
fn emit_diagnostic(&mut self, mut diag: DiagInner) {
|
||||
let fluent_args = to_fluent_args(diag.args.iter());
|
||||
|
||||
let mut suggestions = diag.suggestions.unwrap_or(vec![]);
|
||||
@ -597,7 +580,7 @@ impl Emitter for SilentEmitter {
|
||||
None
|
||||
}
|
||||
|
||||
fn emit_diagnostic(&mut self, mut diag: Diagnostic) {
|
||||
fn emit_diagnostic(&mut self, mut diag: DiagInner) {
|
||||
if diag.level == Level::Fatal {
|
||||
diag.sub(Level::Note, self.fatal_note.clone(), MultiSpan::new());
|
||||
self.fatal_dcx.emit_diagnostic(diag);
|
||||
@ -632,12 +615,6 @@ impl ColorConfig {
|
||||
ColorConfig::Auto => ColorChoice::Never,
|
||||
}
|
||||
}
|
||||
fn suggests_using_colors(self) -> bool {
|
||||
match self {
|
||||
ColorConfig::Always | ColorConfig::Auto => true,
|
||||
ColorConfig::Never => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles the writing of `HumanReadableErrorType::Default` and `HumanReadableErrorType::Short`
|
||||
@ -661,19 +638,14 @@ pub struct HumanEmitter {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FileWithAnnotatedLines {
|
||||
pub file: Lrc<SourceFile>,
|
||||
pub lines: Vec<Line>,
|
||||
pub(crate) struct FileWithAnnotatedLines {
|
||||
pub(crate) file: Lrc<SourceFile>,
|
||||
pub(crate) lines: Vec<Line>,
|
||||
multiline_depth: usize,
|
||||
}
|
||||
|
||||
impl HumanEmitter {
|
||||
pub fn stderr(color_config: ColorConfig, fallback_bundle: LazyFallbackBundle) -> HumanEmitter {
|
||||
let dst = from_stderr(color_config);
|
||||
Self::create(dst, fallback_bundle)
|
||||
}
|
||||
|
||||
fn create(dst: Destination, fallback_bundle: LazyFallbackBundle) -> HumanEmitter {
|
||||
pub fn new(dst: Destination, fallback_bundle: LazyFallbackBundle) -> HumanEmitter {
|
||||
HumanEmitter {
|
||||
dst: IntoDynSyncSend(dst),
|
||||
sm: None,
|
||||
@ -690,13 +662,6 @@ impl HumanEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
dst: Box<dyn WriteColor + Send>,
|
||||
fallback_bundle: LazyFallbackBundle,
|
||||
) -> HumanEmitter {
|
||||
Self::create(dst, fallback_bundle)
|
||||
}
|
||||
|
||||
fn maybe_anonymized(&self, line_num: usize) -> Cow<'static, str> {
|
||||
if self.ui_testing {
|
||||
Cow::Borrowed(ANONYMIZED_LINE_NUM)
|
||||
@ -728,8 +693,9 @@ impl HumanEmitter {
|
||||
.skip(left)
|
||||
.take_while(|ch| {
|
||||
// Make sure that the trimming on the right will fall within the terminal width.
|
||||
// FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` is.
|
||||
// For now, just accept that sometimes the code line will be longer than desired.
|
||||
// FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char`
|
||||
// is. For now, just accept that sometimes the code line will be longer than
|
||||
// desired.
|
||||
let next = unicode_width::UnicodeWidthChar::width(*ch).unwrap_or(1);
|
||||
if taken + next > right - left {
|
||||
return false;
|
||||
@ -1235,7 +1201,7 @@ impl HumanEmitter {
|
||||
max
|
||||
}
|
||||
|
||||
fn get_max_line_num(&mut self, span: &MultiSpan, children: &[SubDiagnostic]) -> usize {
|
||||
fn get_max_line_num(&mut self, span: &MultiSpan, children: &[Subdiag]) -> usize {
|
||||
let primary = self.get_multispan_max_line_num(span);
|
||||
children
|
||||
.iter()
|
||||
@ -1331,7 +1297,7 @@ impl HumanEmitter {
|
||||
level: &Level,
|
||||
max_line_num_len: usize,
|
||||
is_secondary: bool,
|
||||
emitted_at: Option<&DiagnosticLocation>,
|
||||
emitted_at: Option<&DiagLocation>,
|
||||
) -> io::Result<()> {
|
||||
let mut buffer = StyledBuffer::new();
|
||||
|
||||
@ -2098,9 +2064,9 @@ impl HumanEmitter {
|
||||
args: &FluentArgs<'_>,
|
||||
code: &Option<ErrCode>,
|
||||
span: &MultiSpan,
|
||||
children: &[SubDiagnostic],
|
||||
children: &[Subdiag],
|
||||
suggestions: &[CodeSuggestion],
|
||||
emitted_at: Option<&DiagnosticLocation>,
|
||||
emitted_at: Option<&DiagLocation>,
|
||||
) {
|
||||
let max_line_num_len = if self.ui_testing {
|
||||
ANONYMIZED_LINE_NUM.len()
|
||||
@ -2232,8 +2198,8 @@ impl HumanEmitter {
|
||||
buffer.puts(*row_num - 1, max_line_num_len + 3, &line, Style::NoStyle);
|
||||
*row_num += 1;
|
||||
}
|
||||
// If the last line is exactly equal to the line we need to add, we can skip both of them.
|
||||
// This allows us to avoid output like the following:
|
||||
// If the last line is exactly equal to the line we need to add, we can skip both of
|
||||
// them. This allows us to avoid output like the following:
|
||||
// 2 - &
|
||||
// 2 + if true { true } else { false }
|
||||
// 3 - if true { true } else { false }
|
||||
@ -2590,6 +2556,7 @@ fn num_overlap(
|
||||
let extra = if inclusive { 1 } else { 0 };
|
||||
(b_start..b_end + extra).contains(&a_start) || (a_start..a_end + extra).contains(&b_start)
|
||||
}
|
||||
|
||||
fn overlaps(a1: &Annotation, a2: &Annotation, padding: usize) -> bool {
|
||||
num_overlap(
|
||||
a1.start_col.display,
|
||||
@ -2636,7 +2603,7 @@ fn emit_to_destination(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub type Destination = Box<(dyn WriteColor + Send)>;
|
||||
pub type Destination = Box<dyn WriteColor + Send>;
|
||||
|
||||
struct Buffy {
|
||||
buffer_writer: BufferWriter,
|
||||
@ -2678,7 +2645,7 @@ impl WriteColor for Buffy {
|
||||
}
|
||||
}
|
||||
|
||||
fn from_stderr(color: ColorConfig) -> Destination {
|
||||
pub fn stderr_destination(color: ColorConfig) -> Destination {
|
||||
let choice = color.to_color_choice();
|
||||
// On Windows we'll be performing global synchronization on the entire
|
||||
// system for emitting rustc errors, so there's no need to buffer
|
||||
|
@ -23,9 +23,11 @@ impl<'args> TranslateError<'args> {
|
||||
pub fn message(id: &'args Cow<'args, str>, args: &'args FluentArgs<'args>) -> Self {
|
||||
Self::One { id, args, kind: TranslateErrorKind::MessageMissing }
|
||||
}
|
||||
|
||||
pub fn primary(id: &'args Cow<'args, str>, args: &'args FluentArgs<'args>) -> Self {
|
||||
Self::One { id, args, kind: TranslateErrorKind::PrimaryBundleMissing }
|
||||
}
|
||||
|
||||
pub fn attribute(
|
||||
id: &'args Cow<'args, str>,
|
||||
args: &'args FluentArgs<'args>,
|
||||
@ -33,6 +35,7 @@ impl<'args> TranslateError<'args> {
|
||||
) -> Self {
|
||||
Self::One { id, args, kind: TranslateErrorKind::AttributeMissing { attr } }
|
||||
}
|
||||
|
||||
pub fn value(id: &'args Cow<'args, str>, args: &'args FluentArgs<'args>) -> Self {
|
||||
Self::One { id, args, kind: TranslateErrorKind::ValueMissing }
|
||||
}
|
||||
|
@ -9,42 +9,49 @@
|
||||
|
||||
// FIXME: spec the JSON output properly.
|
||||
|
||||
use rustc_span::source_map::{FilePathMapping, SourceMap};
|
||||
use termcolor::{ColorSpec, WriteColor};
|
||||
|
||||
use crate::emitter::{should_show_source_code, Emitter, HumanReadableErrorType};
|
||||
use crate::emitter::{
|
||||
should_show_source_code, ColorConfig, Destination, Emitter, HumanEmitter,
|
||||
HumanReadableErrorType,
|
||||
};
|
||||
use crate::registry::Registry;
|
||||
use crate::translation::{to_fluent_args, Translate};
|
||||
use crate::{
|
||||
diagnostic::IsLint, CodeSuggestion, FluentBundle, LazyFallbackBundle, MultiSpan, SpanLabel,
|
||||
SubDiagnostic, TerminalUrl,
|
||||
Subdiag, TerminalUrl,
|
||||
};
|
||||
use rustc_lint_defs::Applicability;
|
||||
|
||||
use derive_setters::Setters;
|
||||
use rustc_data_structures::sync::{IntoDynSyncSend, Lrc};
|
||||
use rustc_error_messages::FluentArgs;
|
||||
use rustc_lint_defs::Applicability;
|
||||
use rustc_span::hygiene::ExpnData;
|
||||
use rustc_span::source_map::SourceMap;
|
||||
use rustc_span::Span;
|
||||
use serde::Serialize;
|
||||
use std::error::Report;
|
||||
use std::io::{self, Write};
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::vec;
|
||||
|
||||
use serde::Serialize;
|
||||
use termcolor::{ColorSpec, WriteColor};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[derive(Setters)]
|
||||
pub struct JsonEmitter {
|
||||
#[setters(skip)]
|
||||
dst: IntoDynSyncSend<Box<dyn Write + Send>>,
|
||||
registry: Option<Registry>,
|
||||
#[setters(skip)]
|
||||
sm: Lrc<SourceMap>,
|
||||
fluent_bundle: Option<Lrc<FluentBundle>>,
|
||||
#[setters(skip)]
|
||||
fallback_bundle: LazyFallbackBundle,
|
||||
#[setters(skip)]
|
||||
pretty: bool,
|
||||
ui_testing: bool,
|
||||
ignored_directories_in_source_blocks: Vec<String>,
|
||||
#[setters(skip)]
|
||||
json_rendered: HumanReadableErrorType,
|
||||
diagnostic_width: Option<usize>,
|
||||
macro_backtrace: bool,
|
||||
@ -53,98 +60,30 @@ pub struct JsonEmitter {
|
||||
}
|
||||
|
||||
impl JsonEmitter {
|
||||
pub fn stderr(
|
||||
registry: Option<Registry>,
|
||||
source_map: Lrc<SourceMap>,
|
||||
fluent_bundle: Option<Lrc<FluentBundle>>,
|
||||
fallback_bundle: LazyFallbackBundle,
|
||||
pretty: bool,
|
||||
json_rendered: HumanReadableErrorType,
|
||||
diagnostic_width: Option<usize>,
|
||||
macro_backtrace: bool,
|
||||
track_diagnostics: bool,
|
||||
terminal_url: TerminalUrl,
|
||||
) -> JsonEmitter {
|
||||
JsonEmitter {
|
||||
dst: IntoDynSyncSend(Box::new(io::BufWriter::new(io::stderr()))),
|
||||
registry,
|
||||
sm: source_map,
|
||||
fluent_bundle,
|
||||
fallback_bundle,
|
||||
pretty,
|
||||
ui_testing: false,
|
||||
ignored_directories_in_source_blocks: Vec::new(),
|
||||
json_rendered,
|
||||
diagnostic_width,
|
||||
macro_backtrace,
|
||||
track_diagnostics,
|
||||
terminal_url,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn basic(
|
||||
pretty: bool,
|
||||
json_rendered: HumanReadableErrorType,
|
||||
fluent_bundle: Option<Lrc<FluentBundle>>,
|
||||
fallback_bundle: LazyFallbackBundle,
|
||||
diagnostic_width: Option<usize>,
|
||||
macro_backtrace: bool,
|
||||
track_diagnostics: bool,
|
||||
terminal_url: TerminalUrl,
|
||||
) -> JsonEmitter {
|
||||
let file_path_mapping = FilePathMapping::empty();
|
||||
JsonEmitter::stderr(
|
||||
None,
|
||||
Lrc::new(SourceMap::new(file_path_mapping)),
|
||||
fluent_bundle,
|
||||
fallback_bundle,
|
||||
pretty,
|
||||
json_rendered,
|
||||
diagnostic_width,
|
||||
macro_backtrace,
|
||||
track_diagnostics,
|
||||
terminal_url,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
dst: Box<dyn Write + Send>,
|
||||
registry: Option<Registry>,
|
||||
source_map: Lrc<SourceMap>,
|
||||
fluent_bundle: Option<Lrc<FluentBundle>>,
|
||||
sm: Lrc<SourceMap>,
|
||||
fallback_bundle: LazyFallbackBundle,
|
||||
pretty: bool,
|
||||
json_rendered: HumanReadableErrorType,
|
||||
diagnostic_width: Option<usize>,
|
||||
macro_backtrace: bool,
|
||||
track_diagnostics: bool,
|
||||
terminal_url: TerminalUrl,
|
||||
) -> JsonEmitter {
|
||||
JsonEmitter {
|
||||
dst: IntoDynSyncSend(dst),
|
||||
registry,
|
||||
sm: source_map,
|
||||
fluent_bundle,
|
||||
registry: None,
|
||||
sm,
|
||||
fluent_bundle: None,
|
||||
fallback_bundle,
|
||||
pretty,
|
||||
ui_testing: false,
|
||||
ignored_directories_in_source_blocks: Vec::new(),
|
||||
json_rendered,
|
||||
diagnostic_width,
|
||||
macro_backtrace,
|
||||
track_diagnostics,
|
||||
terminal_url,
|
||||
diagnostic_width: None,
|
||||
macro_backtrace: false,
|
||||
track_diagnostics: false,
|
||||
terminal_url: TerminalUrl::No,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ui_testing(self, ui_testing: bool) -> Self {
|
||||
Self { ui_testing, ..self }
|
||||
}
|
||||
|
||||
pub fn ignored_directories_in_source_blocks(self, value: Vec<String>) -> Self {
|
||||
Self { ignored_directories_in_source_blocks: value, ..self }
|
||||
}
|
||||
|
||||
fn emit(&mut self, val: EmitTyped<'_>) -> io::Result<()> {
|
||||
if self.pretty {
|
||||
serde_json::to_writer_pretty(&mut *self.dst, &val)?
|
||||
@ -162,7 +101,7 @@ enum EmitTyped<'a> {
|
||||
Diagnostic(Diagnostic),
|
||||
Artifact(ArtifactNotification<'a>),
|
||||
FutureIncompat(FutureIncompatReport<'a>),
|
||||
UnusedExtern(UnusedExterns<'a, 'a, 'a>),
|
||||
UnusedExtern(UnusedExterns<'a>),
|
||||
}
|
||||
|
||||
impl Translate for JsonEmitter {
|
||||
@ -176,7 +115,7 @@ impl Translate for JsonEmitter {
|
||||
}
|
||||
|
||||
impl Emitter for JsonEmitter {
|
||||
fn emit_diagnostic(&mut self, diag: crate::Diagnostic) {
|
||||
fn emit_diagnostic(&mut self, diag: crate::DiagInner) {
|
||||
let data = Diagnostic::from_errors_diagnostic(diag, self);
|
||||
let result = self.emit(EmitTyped::Diagnostic(data));
|
||||
if let Err(e) = result {
|
||||
@ -192,7 +131,7 @@ impl Emitter for JsonEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_future_breakage_report(&mut self, diags: Vec<crate::Diagnostic>) {
|
||||
fn emit_future_breakage_report(&mut self, diags: Vec<crate::DiagInner>) {
|
||||
let data: Vec<FutureBreakageItem<'_>> = diags
|
||||
.into_iter()
|
||||
.map(|mut diag| {
|
||||
@ -332,15 +271,16 @@ struct FutureIncompatReport<'a> {
|
||||
// We could unify this struct the one in rustdoc but they have different
|
||||
// ownership semantics, so doing so would create wasteful allocations.
|
||||
#[derive(Serialize)]
|
||||
struct UnusedExterns<'a, 'b, 'c> {
|
||||
struct UnusedExterns<'a> {
|
||||
/// The severity level of the unused dependencies lint
|
||||
lint_level: &'a str,
|
||||
/// List of unused externs by their names.
|
||||
unused_extern_names: &'b [&'c str],
|
||||
unused_extern_names: &'a [&'a str],
|
||||
}
|
||||
|
||||
impl Diagnostic {
|
||||
fn from_errors_diagnostic(diag: crate::Diagnostic, je: &JsonEmitter) -> Diagnostic {
|
||||
/// Converts from `rustc_errors::DiagInner` to `Diagnostic`.
|
||||
fn from_errors_diagnostic(diag: crate::DiagInner, je: &JsonEmitter) -> Diagnostic {
|
||||
let args = to_fluent_args(diag.args.iter());
|
||||
let sugg = diag.suggestions.iter().flatten().map(|sugg| {
|
||||
let translated_message =
|
||||
@ -405,9 +345,14 @@ impl Diagnostic {
|
||||
.collect();
|
||||
|
||||
let buf = BufWriter::default();
|
||||
let output = buf.clone();
|
||||
je.json_rendered
|
||||
.new_emitter(Box::new(buf), je.fallback_bundle.clone())
|
||||
let mut dst: Destination = Box::new(buf.clone());
|
||||
let (short, color_config) = je.json_rendered.unzip();
|
||||
match color_config {
|
||||
ColorConfig::Always | ColorConfig::Auto => dst = Box::new(termcolor::Ansi::new(dst)),
|
||||
ColorConfig::Never => {}
|
||||
}
|
||||
HumanEmitter::new(dst, je.fallback_bundle.clone())
|
||||
.short_message(short)
|
||||
.sm(Some(je.sm.clone()))
|
||||
.fluent_bundle(je.fluent_bundle.clone())
|
||||
.diagnostic_width(je.diagnostic_width)
|
||||
@ -417,8 +362,8 @@ impl Diagnostic {
|
||||
.ui_testing(je.ui_testing)
|
||||
.ignored_directories_in_source_blocks(je.ignored_directories_in_source_blocks.clone())
|
||||
.emit_diagnostic(diag);
|
||||
let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap();
|
||||
let output = String::from_utf8(output).unwrap();
|
||||
let buf = Arc::try_unwrap(buf.0).unwrap().into_inner().unwrap();
|
||||
let buf = String::from_utf8(buf).unwrap();
|
||||
|
||||
Diagnostic {
|
||||
message: translated_message.to_string(),
|
||||
@ -426,21 +371,21 @@ impl Diagnostic {
|
||||
level,
|
||||
spans,
|
||||
children,
|
||||
rendered: Some(output),
|
||||
rendered: Some(buf),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_sub_diagnostic(
|
||||
diag: &SubDiagnostic,
|
||||
subdiag: &Subdiag,
|
||||
args: &FluentArgs<'_>,
|
||||
je: &JsonEmitter,
|
||||
) -> Diagnostic {
|
||||
let translated_message = je.translate_messages(&diag.messages, args);
|
||||
let translated_message = je.translate_messages(&subdiag.messages, args);
|
||||
Diagnostic {
|
||||
message: translated_message.to_string(),
|
||||
code: None,
|
||||
level: diag.level.to_str(),
|
||||
spans: DiagnosticSpan::from_multispan(&diag.span, args, je),
|
||||
level: subdiag.level.to_str(),
|
||||
spans: DiagnosticSpan::from_multispan(&subdiag.span, args, je),
|
||||
children: vec![],
|
||||
rendered: None,
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use super::*;
|
||||
|
||||
use crate::emitter::ColorConfig;
|
||||
use crate::DiagCtxt;
|
||||
use rustc_span::source_map::FilePathMapping;
|
||||
use rustc_span::BytePos;
|
||||
|
||||
use std::str;
|
||||
@ -48,20 +48,14 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
|
||||
let output = Arc::new(Mutex::new(Vec::new()));
|
||||
let je = JsonEmitter::new(
|
||||
Box::new(Shared { data: output.clone() }),
|
||||
None,
|
||||
sm,
|
||||
None,
|
||||
fallback_bundle,
|
||||
true,
|
||||
true, // pretty
|
||||
HumanReadableErrorType::Short(ColorConfig::Never),
|
||||
None,
|
||||
false,
|
||||
false,
|
||||
TerminalUrl::No,
|
||||
);
|
||||
|
||||
let span = Span::with_root_ctxt(BytePos(span.0), BytePos(span.1));
|
||||
let dcx = DiagCtxt::with_emitter(Box::new(je));
|
||||
let dcx = DiagCtxt::new(Box::new(je));
|
||||
dcx.span_err(span, "foo");
|
||||
|
||||
let bytes = output.lock().unwrap();
|
||||
|
@ -37,14 +37,13 @@ extern crate self as rustc_errors;
|
||||
|
||||
pub use codes::*;
|
||||
pub use diagnostic::{
|
||||
AddToDiagnostic, BugAbort, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgMap,
|
||||
DiagnosticArgName, DiagnosticArgValue, DiagnosticBuilder, DiagnosticStyledString,
|
||||
EmissionGuarantee, FatalAbort, IntoDiagnostic, IntoDiagnosticArg, StringPart, SubDiagnostic,
|
||||
SubdiagnosticMessageOp,
|
||||
AddToDiagnostic, BugAbort, DecorateLint, Diag, DiagArg, DiagArgMap, DiagArgName, DiagArgValue,
|
||||
DiagInner, DiagStyledString, EmissionGuarantee, FatalAbort, IntoDiagnostic, IntoDiagnosticArg,
|
||||
StringPart, Subdiag, SubdiagnosticMessageOp,
|
||||
};
|
||||
pub use diagnostic_impls::{
|
||||
DiagnosticArgFromDisplay, DiagnosticSymbolList, ExpectedLifetimeParameter,
|
||||
IndicateAnonymousLifetime, SingleLabelManySpans,
|
||||
DiagArgFromDisplay, DiagSymbolList, ExpectedLifetimeParameter, IndicateAnonymousLifetime,
|
||||
SingleLabelManySpans,
|
||||
};
|
||||
pub use emitter::ColorConfig;
|
||||
pub use rustc_error_messages::{
|
||||
@ -60,11 +59,11 @@ pub use snippet::Style;
|
||||
// See https://github.com/rust-lang/rust/pull/115393.
|
||||
pub use termcolor::{Color, ColorSpec, WriteColor};
|
||||
|
||||
use emitter::{is_case_difference, DynEmitter, Emitter, HumanEmitter};
|
||||
use emitter::{is_case_difference, DynEmitter, Emitter};
|
||||
use registry::Registry;
|
||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
|
||||
use rustc_data_structures::sync::{Lock, Lrc};
|
||||
use rustc_data_structures::sync::Lock;
|
||||
use rustc_data_structures::AtomicRef;
|
||||
use rustc_lint_defs::LintExpectationId;
|
||||
use rustc_span::source_map::SourceMap;
|
||||
@ -98,7 +97,7 @@ mod styled_buffer;
|
||||
mod tests;
|
||||
pub mod translation;
|
||||
|
||||
pub type PErr<'a> = DiagnosticBuilder<'a>;
|
||||
pub type PErr<'a> = Diag<'a>;
|
||||
pub type PResult<'a, T> = Result<T, PErr<'a>>;
|
||||
|
||||
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
||||
@ -218,10 +217,10 @@ impl CodeSuggestion {
|
||||
|
||||
use rustc_span::{CharPos, Pos};
|
||||
|
||||
/// Extracts a substring from the provided `line_opt` based on the specified low and high indices,
|
||||
/// appends it to the given buffer `buf`, and returns the count of newline characters in the substring
|
||||
/// for accurate highlighting.
|
||||
/// If `line_opt` is `None`, a newline character is appended to the buffer, and 0 is returned.
|
||||
/// Extracts a substring from the provided `line_opt` based on the specified low and high
|
||||
/// indices, appends it to the given buffer `buf`, and returns the count of newline
|
||||
/// characters in the substring for accurate highlighting. If `line_opt` is `None`, a
|
||||
/// newline character is appended to the buffer, and 0 is returned.
|
||||
///
|
||||
/// ## Returns
|
||||
///
|
||||
@ -433,7 +432,7 @@ struct DiagCtxtInner {
|
||||
/// lint error count.
|
||||
lint_err_guars: Vec<ErrorGuaranteed>,
|
||||
/// The delayed bugs and their error guarantees.
|
||||
delayed_bugs: Vec<(DelayedDiagnostic, ErrorGuaranteed)>,
|
||||
delayed_bugs: Vec<(DelayedDiagInner, ErrorGuaranteed)>,
|
||||
|
||||
/// The number of stashed errors. Unlike the other counts, this can go up
|
||||
/// and down, so it doesn't guarantee anything.
|
||||
@ -476,9 +475,9 @@ struct DiagCtxtInner {
|
||||
/// add more information). All stashed diagnostics must be emitted with
|
||||
/// `emit_stashed_diagnostics` by the time the `DiagCtxtInner` is dropped,
|
||||
/// otherwise an assertion failure will occur.
|
||||
stashed_diagnostics: FxIndexMap<(Span, StashKey), Diagnostic>,
|
||||
stashed_diagnostics: FxIndexMap<(Span, StashKey), DiagInner>,
|
||||
|
||||
future_breakage_diagnostics: Vec<Diagnostic>,
|
||||
future_breakage_diagnostics: Vec<DiagInner>,
|
||||
|
||||
/// The [`Self::unstable_expect_diagnostics`] should be empty when this struct is
|
||||
/// dropped. However, it can have values if the compilation is stopped early
|
||||
@ -487,13 +486,13 @@ struct DiagCtxtInner {
|
||||
/// have been converted.
|
||||
check_unstable_expect_diagnostics: bool,
|
||||
|
||||
/// Expected [`Diagnostic`][struct@diagnostic::Diagnostic]s store a [`LintExpectationId`] as part of
|
||||
/// the lint level. [`LintExpectationId`]s created early during the compilation
|
||||
/// Expected [`DiagInner`][struct@diagnostic::DiagInner]s store a [`LintExpectationId`] as part
|
||||
/// of the lint level. [`LintExpectationId`]s created early during the compilation
|
||||
/// (before `HirId`s have been defined) are not stable and can therefore not be
|
||||
/// stored on disk. This buffer stores these diagnostics until the ID has been
|
||||
/// replaced by a stable [`LintExpectationId`]. The [`Diagnostic`][struct@diagnostic::Diagnostic]s are the
|
||||
/// submitted for storage and added to the list of fulfilled expectations.
|
||||
unstable_expect_diagnostics: Vec<Diagnostic>,
|
||||
/// replaced by a stable [`LintExpectationId`]. The [`DiagInner`][struct@diagnostic::DiagInner]s
|
||||
/// are submitted for storage and added to the list of fulfilled expectations.
|
||||
unstable_expect_diagnostics: Vec<DiagInner>,
|
||||
|
||||
/// expected diagnostic will have the level `Expect` which additionally
|
||||
/// carries the [`LintExpectationId`] of the expectation that can be
|
||||
@ -531,11 +530,11 @@ pub enum StashKey {
|
||||
UndeterminedMacroResolution,
|
||||
}
|
||||
|
||||
fn default_track_diagnostic(diag: Diagnostic, f: &mut dyn FnMut(Diagnostic)) {
|
||||
fn default_track_diagnostic(diag: DiagInner, f: &mut dyn FnMut(DiagInner)) {
|
||||
(*f)(diag)
|
||||
}
|
||||
|
||||
pub static TRACK_DIAGNOSTIC: AtomicRef<fn(Diagnostic, &mut dyn FnMut(Diagnostic))> =
|
||||
pub static TRACK_DIAGNOSTIC: AtomicRef<fn(DiagInner, &mut dyn FnMut(DiagInner))> =
|
||||
AtomicRef::new(&(default_track_diagnostic as _));
|
||||
|
||||
#[derive(Copy, Clone, Default)]
|
||||
@ -587,13 +586,6 @@ impl Drop for DiagCtxtInner {
|
||||
}
|
||||
|
||||
impl DiagCtxt {
|
||||
pub fn with_tty_emitter(
|
||||
sm: Option<Lrc<SourceMap>>,
|
||||
fallback_bundle: LazyFallbackBundle,
|
||||
) -> Self {
|
||||
let emitter = Box::new(HumanEmitter::stderr(ColorConfig::Auto, fallback_bundle).sm(sm));
|
||||
Self::with_emitter(emitter)
|
||||
}
|
||||
pub fn disable_warnings(mut self) -> Self {
|
||||
self.inner.get_mut().flags.can_emit_warnings = false;
|
||||
self
|
||||
@ -609,7 +601,7 @@ impl DiagCtxt {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_emitter(emitter: Box<DynEmitter>) -> Self {
|
||||
pub fn new(emitter: Box<DynEmitter>) -> Self {
|
||||
Self {
|
||||
inner: Lock::new(DiagCtxtInner {
|
||||
flags: DiagCtxtFlags { can_emit_warnings: true, ..Default::default() },
|
||||
@ -640,7 +632,7 @@ impl DiagCtxt {
|
||||
pub fn eagerly_translate<'a>(
|
||||
&self,
|
||||
message: DiagnosticMessage,
|
||||
args: impl Iterator<Item = DiagnosticArg<'a>>,
|
||||
args: impl Iterator<Item = DiagArg<'a>>,
|
||||
) -> SubdiagnosticMessage {
|
||||
let inner = self.inner.borrow();
|
||||
inner.eagerly_translate(message, args)
|
||||
@ -650,7 +642,7 @@ impl DiagCtxt {
|
||||
pub fn eagerly_translate_to_string<'a>(
|
||||
&self,
|
||||
message: DiagnosticMessage,
|
||||
args: impl Iterator<Item = DiagnosticArg<'a>>,
|
||||
args: impl Iterator<Item = DiagArg<'a>>,
|
||||
) -> String {
|
||||
let inner = self.inner.borrow();
|
||||
inner.eagerly_translate_to_string(message, args)
|
||||
@ -718,7 +710,7 @@ impl DiagCtxt {
|
||||
|
||||
/// Stash a given diagnostic with the given `Span` and [`StashKey`] as the key.
|
||||
/// Retrieve a stashed diagnostic with `steal_diagnostic`.
|
||||
pub fn stash_diagnostic(&self, span: Span, key: StashKey, diag: Diagnostic) {
|
||||
pub fn stash_diagnostic(&self, span: Span, key: StashKey, diag: DiagInner) {
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
|
||||
let key = (span.with_parent(None), key);
|
||||
@ -736,7 +728,7 @@ impl DiagCtxt {
|
||||
}
|
||||
|
||||
/// Steal a previously stashed diagnostic with the given `Span` and [`StashKey`] as the key.
|
||||
pub fn steal_diagnostic(&self, span: Span, key: StashKey) -> Option<DiagnosticBuilder<'_, ()>> {
|
||||
pub fn steal_diagnostic(&self, span: Span, key: StashKey) -> Option<Diag<'_, ()>> {
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
let key = (span.with_parent(None), key);
|
||||
// FIXME(#120456) - is `swap_remove` correct?
|
||||
@ -746,7 +738,7 @@ impl DiagCtxt {
|
||||
inner.stashed_err_count -= 1;
|
||||
}
|
||||
}
|
||||
Some(DiagnosticBuilder::new_diagnostic(self, diag))
|
||||
Some(Diag::new_diagnostic(self, diag))
|
||||
}
|
||||
|
||||
pub fn has_stashed_diagnostic(&self, span: Span, key: StashKey) -> bool {
|
||||
@ -824,16 +816,16 @@ impl DiagCtxt {
|
||||
(0, _) => {
|
||||
// Use `ForceWarning` rather than `Warning` to guarantee emission, e.g. with a
|
||||
// configuration like `--cap-lints allow --force-warn bare_trait_objects`.
|
||||
inner.emit_diagnostic(Diagnostic::new(
|
||||
inner.emit_diagnostic(DiagInner::new(
|
||||
ForceWarning(None),
|
||||
DiagnosticMessage::Str(warnings),
|
||||
));
|
||||
}
|
||||
(_, 0) => {
|
||||
inner.emit_diagnostic(Diagnostic::new(Error, errors));
|
||||
inner.emit_diagnostic(DiagInner::new(Error, errors));
|
||||
}
|
||||
(_, _) => {
|
||||
inner.emit_diagnostic(Diagnostic::new(Error, format!("{errors}; {warnings}")));
|
||||
inner.emit_diagnostic(DiagInner::new(Error, format!("{errors}; {warnings}")));
|
||||
}
|
||||
}
|
||||
|
||||
@ -864,14 +856,14 @@ impl DiagCtxt {
|
||||
"For more information about an error, try `rustc --explain {}`.",
|
||||
&error_codes[0]
|
||||
);
|
||||
inner.emit_diagnostic(Diagnostic::new(FailureNote, msg1));
|
||||
inner.emit_diagnostic(Diagnostic::new(FailureNote, msg2));
|
||||
inner.emit_diagnostic(DiagInner::new(FailureNote, msg1));
|
||||
inner.emit_diagnostic(DiagInner::new(FailureNote, msg2));
|
||||
} else {
|
||||
let msg = format!(
|
||||
"For more information about this error, try `rustc --explain {}`.",
|
||||
&error_codes[0]
|
||||
);
|
||||
inner.emit_diagnostic(Diagnostic::new(FailureNote, msg));
|
||||
inner.emit_diagnostic(DiagInner::new(FailureNote, msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -896,7 +888,7 @@ impl DiagCtxt {
|
||||
self.inner.borrow_mut().taught_diagnostics.insert(code)
|
||||
}
|
||||
|
||||
pub fn emit_diagnostic(&self, diagnostic: Diagnostic) -> Option<ErrorGuaranteed> {
|
||||
pub fn emit_diagnostic(&self, diagnostic: DiagInner) -> Option<ErrorGuaranteed> {
|
||||
self.inner.borrow_mut().emit_diagnostic(diagnostic)
|
||||
}
|
||||
|
||||
@ -1000,8 +992,8 @@ impl DiagCtxt {
|
||||
impl DiagCtxt {
|
||||
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
|
||||
#[track_caller]
|
||||
pub fn struct_bug(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, BugAbort> {
|
||||
DiagnosticBuilder::new(self, Bug, msg)
|
||||
pub fn struct_bug(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, BugAbort> {
|
||||
Diag::new(self, Bug, msg)
|
||||
}
|
||||
|
||||
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
|
||||
@ -1016,7 +1008,7 @@ impl DiagCtxt {
|
||||
&self,
|
||||
span: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, BugAbort> {
|
||||
) -> Diag<'_, BugAbort> {
|
||||
self.struct_bug(msg).with_span(span)
|
||||
}
|
||||
|
||||
@ -1027,10 +1019,7 @@ impl DiagCtxt {
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn create_bug<'a>(
|
||||
&'a self,
|
||||
bug: impl IntoDiagnostic<'a, BugAbort>,
|
||||
) -> DiagnosticBuilder<'a, BugAbort> {
|
||||
pub fn create_bug<'a>(&'a self, bug: impl IntoDiagnostic<'a, BugAbort>) -> Diag<'a, BugAbort> {
|
||||
bug.into_diagnostic(self, Bug)
|
||||
}
|
||||
|
||||
@ -1041,11 +1030,8 @@ impl DiagCtxt {
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn struct_fatal(
|
||||
&self,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, FatalAbort> {
|
||||
DiagnosticBuilder::new(self, Fatal, msg)
|
||||
pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, FatalAbort> {
|
||||
Diag::new(self, Fatal, msg)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
@ -1060,7 +1046,7 @@ impl DiagCtxt {
|
||||
&self,
|
||||
span: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, FatalAbort> {
|
||||
) -> Diag<'_, FatalAbort> {
|
||||
self.struct_fatal(msg).with_span(span)
|
||||
}
|
||||
|
||||
@ -1074,7 +1060,7 @@ impl DiagCtxt {
|
||||
pub fn create_fatal<'a>(
|
||||
&'a self,
|
||||
fatal: impl IntoDiagnostic<'a, FatalAbort>,
|
||||
) -> DiagnosticBuilder<'a, FatalAbort> {
|
||||
) -> Diag<'a, FatalAbort> {
|
||||
fatal.into_diagnostic(self, Fatal)
|
||||
}
|
||||
|
||||
@ -1087,7 +1073,7 @@ impl DiagCtxt {
|
||||
pub fn create_almost_fatal<'a>(
|
||||
&'a self,
|
||||
fatal: impl IntoDiagnostic<'a, FatalError>,
|
||||
) -> DiagnosticBuilder<'a, FatalError> {
|
||||
) -> Diag<'a, FatalError> {
|
||||
fatal.into_diagnostic(self, Fatal)
|
||||
}
|
||||
|
||||
@ -1102,8 +1088,8 @@ impl DiagCtxt {
|
||||
// FIXME: This method should be removed (every error should have an associated error code).
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn struct_err(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_> {
|
||||
DiagnosticBuilder::new(self, Error, msg)
|
||||
pub fn struct_err(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_> {
|
||||
Diag::new(self, Error, msg)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
@ -1118,7 +1104,7 @@ impl DiagCtxt {
|
||||
&self,
|
||||
span: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_> {
|
||||
) -> Diag<'_> {
|
||||
self.struct_err(msg).with_span(span)
|
||||
}
|
||||
|
||||
@ -1133,7 +1119,7 @@ impl DiagCtxt {
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn create_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> DiagnosticBuilder<'a> {
|
||||
pub fn create_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> Diag<'a> {
|
||||
err.into_diagnostic(self, Error)
|
||||
}
|
||||
|
||||
@ -1146,7 +1132,7 @@ impl DiagCtxt {
|
||||
// No `#[rustc_lint_diagnostics]` because bug messages aren't user-facing.
|
||||
#[track_caller]
|
||||
pub fn delayed_bug(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
|
||||
DiagnosticBuilder::<ErrorGuaranteed>::new(self, DelayedBug, msg).emit()
|
||||
Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg).emit()
|
||||
}
|
||||
|
||||
/// Ensures that an error is printed. See `Level::DelayedBug`.
|
||||
@ -1160,13 +1146,13 @@ impl DiagCtxt {
|
||||
sp: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> ErrorGuaranteed {
|
||||
DiagnosticBuilder::<ErrorGuaranteed>::new(self, DelayedBug, msg).with_span(sp).emit()
|
||||
Diag::<ErrorGuaranteed>::new(self, DelayedBug, msg).with_span(sp).emit()
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
|
||||
DiagnosticBuilder::new(self, Warning, msg)
|
||||
pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, ()> {
|
||||
Diag::new(self, Warning, msg)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
@ -1181,7 +1167,7 @@ impl DiagCtxt {
|
||||
&self,
|
||||
span: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
) -> Diag<'_, ()> {
|
||||
self.struct_warn(msg).with_span(span)
|
||||
}
|
||||
|
||||
@ -1192,10 +1178,7 @@ impl DiagCtxt {
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn create_warn<'a>(
|
||||
&'a self,
|
||||
warning: impl IntoDiagnostic<'a, ()>,
|
||||
) -> DiagnosticBuilder<'a, ()> {
|
||||
pub fn create_warn<'a>(&'a self, warning: impl IntoDiagnostic<'a, ()>) -> Diag<'a, ()> {
|
||||
warning.into_diagnostic(self, Warning)
|
||||
}
|
||||
|
||||
@ -1206,8 +1189,8 @@ impl DiagCtxt {
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn struct_note(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
|
||||
DiagnosticBuilder::new(self, Note, msg)
|
||||
pub fn struct_note(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, ()> {
|
||||
Diag::new(self, Note, msg)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
@ -1222,7 +1205,7 @@ impl DiagCtxt {
|
||||
&self,
|
||||
span: impl Into<MultiSpan>,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
) -> Diag<'_, ()> {
|
||||
self.struct_note(msg).with_span(span)
|
||||
}
|
||||
|
||||
@ -1233,10 +1216,7 @@ impl DiagCtxt {
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn create_note<'a>(
|
||||
&'a self,
|
||||
note: impl IntoDiagnostic<'a, ()>,
|
||||
) -> DiagnosticBuilder<'a, ()> {
|
||||
pub fn create_note<'a>(&'a self, note: impl IntoDiagnostic<'a, ()>) -> Diag<'a, ()> {
|
||||
note.into_diagnostic(self, Note)
|
||||
}
|
||||
|
||||
@ -1247,23 +1227,20 @@ impl DiagCtxt {
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn struct_help(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
|
||||
DiagnosticBuilder::new(self, Help, msg)
|
||||
pub fn struct_help(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, ()> {
|
||||
Diag::new(self, Help, msg)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn struct_failure_note(
|
||||
&self,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
DiagnosticBuilder::new(self, FailureNote, msg)
|
||||
pub fn struct_failure_note(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, ()> {
|
||||
Diag::new(self, FailureNote, msg)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
#[track_caller]
|
||||
pub fn struct_allow(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
|
||||
DiagnosticBuilder::new(self, Allow, msg)
|
||||
pub fn struct_allow(&self, msg: impl Into<DiagnosticMessage>) -> Diag<'_, ()> {
|
||||
Diag::new(self, Allow, msg)
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
@ -1272,8 +1249,8 @@ impl DiagCtxt {
|
||||
&self,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
id: LintExpectationId,
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
DiagnosticBuilder::new(self, Expect(id), msg)
|
||||
) -> Diag<'_, ()> {
|
||||
Diag::new(self, Expect(id), msg)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1305,7 +1282,7 @@ impl DiagCtxtInner {
|
||||
}
|
||||
|
||||
// Return value is only `Some` if the level is `Error` or `DelayedBug`.
|
||||
fn emit_diagnostic(&mut self, mut diagnostic: Diagnostic) -> Option<ErrorGuaranteed> {
|
||||
fn emit_diagnostic(&mut self, mut diagnostic: DiagInner) -> Option<ErrorGuaranteed> {
|
||||
assert!(diagnostic.level.can_be_top_or_sub().0);
|
||||
|
||||
if let Some(expectation_id) = diagnostic.level.get_expectation_id() {
|
||||
@ -1354,7 +1331,7 @@ impl DiagCtxtInner {
|
||||
#[allow(deprecated)]
|
||||
let guar = ErrorGuaranteed::unchecked_error_guaranteed();
|
||||
self.delayed_bugs
|
||||
.push((DelayedDiagnostic::with_backtrace(diagnostic, backtrace), guar));
|
||||
.push((DelayedDiagInner::with_backtrace(diagnostic, backtrace), guar));
|
||||
Some(guar)
|
||||
};
|
||||
}
|
||||
@ -1393,7 +1370,7 @@ impl DiagCtxtInner {
|
||||
debug!(?diagnostic);
|
||||
debug!(?self.emitted_diagnostics);
|
||||
|
||||
let already_emitted_sub = |sub: &mut SubDiagnostic| {
|
||||
let already_emitted_sub = |sub: &mut Subdiag| {
|
||||
debug!(?sub);
|
||||
if sub.level != OnceNote && sub.level != OnceHelp {
|
||||
return false;
|
||||
@ -1477,7 +1454,7 @@ impl DiagCtxtInner {
|
||||
pub fn eagerly_translate<'a>(
|
||||
&self,
|
||||
message: DiagnosticMessage,
|
||||
args: impl Iterator<Item = DiagnosticArg<'a>>,
|
||||
args: impl Iterator<Item = DiagArg<'a>>,
|
||||
) -> SubdiagnosticMessage {
|
||||
SubdiagnosticMessage::Translated(Cow::from(self.eagerly_translate_to_string(message, args)))
|
||||
}
|
||||
@ -1486,7 +1463,7 @@ impl DiagCtxtInner {
|
||||
pub fn eagerly_translate_to_string<'a>(
|
||||
&self,
|
||||
message: DiagnosticMessage,
|
||||
args: impl Iterator<Item = DiagnosticArg<'a>>,
|
||||
args: impl Iterator<Item = DiagArg<'a>>,
|
||||
) -> String {
|
||||
let args = crate::translation::to_fluent_args(args);
|
||||
self.emitter.translate_message(&message, &args).map_err(Report::new).unwrap().to_string()
|
||||
@ -1494,7 +1471,7 @@ impl DiagCtxtInner {
|
||||
|
||||
fn eagerly_translate_for_subdiag(
|
||||
&self,
|
||||
diag: &Diagnostic,
|
||||
diag: &DiagInner,
|
||||
msg: impl Into<SubdiagnosticMessage>,
|
||||
) -> SubdiagnosticMessage {
|
||||
let msg = diag.subdiagnostic_message_to_diagnostic_message(msg);
|
||||
@ -1539,8 +1516,8 @@ impl DiagCtxtInner {
|
||||
// could trigger `-Ztreat-err-as-bug`, which we don't want.
|
||||
let note1 = "no errors encountered even though delayed bugs were created";
|
||||
let note2 = "those delayed bugs will now be shown as internal compiler errors";
|
||||
self.emit_diagnostic(Diagnostic::new(Note, note1));
|
||||
self.emit_diagnostic(Diagnostic::new(Note, note2));
|
||||
self.emit_diagnostic(DiagInner::new(Note, note1));
|
||||
self.emit_diagnostic(DiagInner::new(Note, note2));
|
||||
}
|
||||
|
||||
let mut bug =
|
||||
@ -1551,9 +1528,9 @@ impl DiagCtxtInner {
|
||||
// NOTE(eddyb) not panicking here because we're already producing
|
||||
// an ICE, and the more information the merrier.
|
||||
//
|
||||
// We are at the `Diagnostic`/`DiagCtxtInner` level rather than
|
||||
// the usual `DiagnosticBuilder`/`DiagCtxt` level, so we must
|
||||
// augment `bug` in a lower-level fashion.
|
||||
// We are at the `DiagInner`/`DiagCtxtInner` level rather than
|
||||
// the usual `Diag`/`DiagCtxt` level, so we must augment `bug`
|
||||
// in a lower-level fashion.
|
||||
bug.arg("level", bug.level);
|
||||
let msg = crate::fluent_generated::errors_invalid_flushed_delayed_diagnostic_level;
|
||||
let msg = self.eagerly_translate_for_subdiag(&bug, msg); // after the `arg` call
|
||||
@ -1581,20 +1558,20 @@ impl DiagCtxtInner {
|
||||
}
|
||||
}
|
||||
|
||||
struct DelayedDiagnostic {
|
||||
inner: Diagnostic,
|
||||
struct DelayedDiagInner {
|
||||
inner: DiagInner,
|
||||
note: Backtrace,
|
||||
}
|
||||
|
||||
impl DelayedDiagnostic {
|
||||
fn with_backtrace(diagnostic: Diagnostic, backtrace: Backtrace) -> Self {
|
||||
DelayedDiagnostic { inner: diagnostic, note: backtrace }
|
||||
impl DelayedDiagInner {
|
||||
fn with_backtrace(diagnostic: DiagInner, backtrace: Backtrace) -> Self {
|
||||
DelayedDiagInner { inner: diagnostic, note: backtrace }
|
||||
}
|
||||
|
||||
fn decorate(self, dcx: &DiagCtxtInner) -> Diagnostic {
|
||||
// We are at the `Diagnostic`/`DiagCtxtInner` level rather than the
|
||||
// usual `DiagnosticBuilder`/`DiagCtxt` level, so we must construct
|
||||
// `diag` in a lower-level fashion.
|
||||
fn decorate(self, dcx: &DiagCtxtInner) -> DiagInner {
|
||||
// We are at the `DiagInner`/`DiagCtxtInner` level rather than the
|
||||
// usual `Diag`/`DiagCtxt` level, so we must construct `diag` in a
|
||||
// lower-level fashion.
|
||||
let mut diag = self.inner;
|
||||
let msg = match self.note.status() {
|
||||
BacktraceStatus::Captured => crate::fluent_generated::errors_delayed_at_with_newline,
|
||||
@ -1750,7 +1727,7 @@ impl Level {
|
||||
// FIXME(eddyb) this doesn't belong here AFAICT, should be moved to callsite.
|
||||
pub fn add_elided_lifetime_in_path_suggestion<G: EmissionGuarantee>(
|
||||
source_map: &SourceMap,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
n: usize,
|
||||
path_span: Span,
|
||||
incl_angl_brckt: bool,
|
||||
@ -1772,18 +1749,18 @@ pub fn add_elided_lifetime_in_path_suggestion<G: EmissionGuarantee>(
|
||||
}
|
||||
|
||||
pub fn report_ambiguity_error<'a, G: EmissionGuarantee>(
|
||||
db: &mut DiagnosticBuilder<'a, G>,
|
||||
diag: &mut Diag<'a, G>,
|
||||
ambiguity: rustc_lint_defs::AmbiguityErrorDiag,
|
||||
) {
|
||||
db.span_label(ambiguity.label_span, ambiguity.label_msg);
|
||||
db.note(ambiguity.note_msg);
|
||||
db.span_note(ambiguity.b1_span, ambiguity.b1_note_msg);
|
||||
diag.span_label(ambiguity.label_span, ambiguity.label_msg);
|
||||
diag.note(ambiguity.note_msg);
|
||||
diag.span_note(ambiguity.b1_span, ambiguity.b1_note_msg);
|
||||
for help_msg in ambiguity.b1_help_msgs {
|
||||
db.help(help_msg);
|
||||
diag.help(help_msg);
|
||||
}
|
||||
db.span_note(ambiguity.b2_span, ambiguity.b2_note_msg);
|
||||
diag.span_note(ambiguity.b2_span, ambiguity.b2_note_msg);
|
||||
for help_msg in ambiguity.b2_help_msgs {
|
||||
db.help(help_msg);
|
||||
diag.help(help_msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::error::{TranslateError, TranslateErrorKind};
|
||||
use crate::snippet::Style;
|
||||
use crate::{DiagnosticArg, DiagnosticMessage, FluentBundle};
|
||||
use crate::{DiagArg, DiagnosticMessage, FluentBundle};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
pub use rustc_error_messages::FluentArgs;
|
||||
use std::borrow::Cow;
|
||||
@ -12,9 +12,7 @@ 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>(
|
||||
iter: impl Iterator<Item = DiagnosticArg<'iter>>,
|
||||
) -> FluentArgs<'static> {
|
||||
pub fn to_fluent_args<'iter>(iter: impl Iterator<Item = DiagArg<'iter>>) -> FluentArgs<'static> {
|
||||
let mut args = if let Some(size) = iter.size_hint().1 {
|
||||
FluentArgs::with_capacity(size)
|
||||
} else {
|
||||
|
@ -13,7 +13,7 @@ use rustc_ast::{self as ast, AttrVec, Attribute, HasAttrs, Item, NodeId, PatKind
|
||||
use rustc_attr::{self as attr, Deprecation, Stability};
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::sync::{self, Lrc};
|
||||
use rustc_errors::{Applicability, DiagCtxt, DiagnosticBuilder, ErrorGuaranteed, PResult};
|
||||
use rustc_errors::{Applicability, Diag, DiagCtxt, ErrorGuaranteed, PResult};
|
||||
use rustc_feature::Features;
|
||||
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
|
||||
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics, RegisteredTools};
|
||||
@ -1260,7 +1260,7 @@ pub fn expr_to_spanned_string<'a>(
|
||||
err_msg: &'static str,
|
||||
) -> Result<
|
||||
(Symbol, ast::StrStyle, Span),
|
||||
Result<(DiagnosticBuilder<'a>, bool /* has_suggestions */), ErrorGuaranteed>,
|
||||
Result<(Diag<'a>, bool /* has_suggestions */), ErrorGuaranteed>,
|
||||
> {
|
||||
// Perform eager expansion on the expression.
|
||||
// We want to be able to handle e.g., `concat!("foo", "bar")`.
|
||||
|
@ -7,7 +7,7 @@ use crate::mbe::{
|
||||
use rustc_ast::token::{self, Token, TokenKind};
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_errors::{Applicability, DiagCtxt, DiagnosticBuilder, DiagnosticMessage};
|
||||
use rustc_errors::{Applicability, Diag, DiagCtxt, DiagnosticMessage};
|
||||
use rustc_parse::parser::{Parser, Recovery};
|
||||
use rustc_span::source_map::SourceMap;
|
||||
use rustc_span::symbol::Ident;
|
||||
@ -218,7 +218,7 @@ impl<'matcher> Tracker<'matcher> for FailureForwarder {
|
||||
}
|
||||
|
||||
pub(super) fn emit_frag_parse_err(
|
||||
mut e: DiagnosticBuilder<'_>,
|
||||
mut e: Diag<'_>,
|
||||
parser: &Parser<'_>,
|
||||
orig_parser: &mut Parser<'_>,
|
||||
site_span: Span,
|
||||
@ -285,11 +285,7 @@ pub(super) fn emit_frag_parse_err(
|
||||
e.emit()
|
||||
}
|
||||
|
||||
pub(crate) fn annotate_err_with_kind(
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
kind: AstFragmentKind,
|
||||
span: Span,
|
||||
) {
|
||||
pub(crate) fn annotate_err_with_kind(err: &mut Diag<'_>, kind: AstFragmentKind, span: Span) {
|
||||
match kind {
|
||||
AstFragmentKind::Ty => {
|
||||
err.span_label(span, "this macro call doesn't expand to a type");
|
||||
@ -315,12 +311,7 @@ enum ExplainDocComment {
|
||||
},
|
||||
}
|
||||
|
||||
pub(super) fn annotate_doc_comment(
|
||||
dcx: &DiagCtxt,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
sm: &SourceMap,
|
||||
span: Span,
|
||||
) {
|
||||
pub(super) fn annotate_doc_comment(dcx: &DiagCtxt, err: &mut Diag<'_>, sm: &SourceMap, span: Span) {
|
||||
if let Ok(src) = sm.span_to_snippet(span) {
|
||||
if src.starts_with("///") || src.starts_with("/**") {
|
||||
err.subdiagnostic(dcx, ExplainDocComment::Outer { span });
|
||||
|
@ -9,7 +9,7 @@ use rustc_ast::mut_visit::{self, MutVisitor};
|
||||
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
|
||||
use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::DiagnosticBuilder;
|
||||
use rustc_errors::Diag;
|
||||
use rustc_errors::{pluralize, PResult};
|
||||
use rustc_span::hygiene::{LocalExpnId, Transparency};
|
||||
use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent};
|
||||
@ -622,12 +622,7 @@ where
|
||||
|
||||
/// Used by meta-variable expressions when an user input is out of the actual declared bounds. For
|
||||
/// example, index(999999) in an repetition of only three elements.
|
||||
fn out_of_bounds_err<'a>(
|
||||
cx: &ExtCtxt<'a>,
|
||||
max: usize,
|
||||
span: Span,
|
||||
ty: &str,
|
||||
) -> DiagnosticBuilder<'a> {
|
||||
fn out_of_bounds_err<'a>(cx: &ExtCtxt<'a>, max: usize, span: Span, ty: &str) -> Diag<'a> {
|
||||
let msg = if max == 0 {
|
||||
format!(
|
||||
"meta-variable expression `{ty}` with depth parameter \
|
||||
|
@ -4,7 +4,7 @@ use crate::errors::{
|
||||
};
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{token, AttrVec, Attribute, Inline, Item, ModSpans};
|
||||
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
|
||||
use rustc_errors::{Diag, ErrorGuaranteed};
|
||||
use rustc_parse::new_parser_from_file;
|
||||
use rustc_parse::validate_attr;
|
||||
use rustc_session::parse::ParseSess;
|
||||
@ -43,7 +43,7 @@ pub enum ModError<'a> {
|
||||
ModInBlock(Option<Ident>),
|
||||
FileNotFound(Ident, PathBuf, PathBuf),
|
||||
MultipleCandidates(Ident, PathBuf, PathBuf),
|
||||
ParserError(DiagnosticBuilder<'a>),
|
||||
ParserError(Diag<'a>),
|
||||
}
|
||||
|
||||
pub(crate) fn parse_external_mod(
|
||||
|
@ -11,7 +11,7 @@ use rustc_ast::util::literal::escape_byte_str_symbol;
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, MultiSpan, PResult};
|
||||
use rustc_errors::{Diag, ErrorGuaranteed, MultiSpan, PResult};
|
||||
use rustc_parse::lexer::nfc_normalize;
|
||||
use rustc_parse::parse_stream_from_source_str;
|
||||
use rustc_session::parse::ParseSess;
|
||||
@ -513,8 +513,8 @@ impl server::FreeFunctions for Rustc<'_, '_> {
|
||||
|
||||
fn emit_diagnostic(&mut self, diagnostic: Diagnostic<Self::Span>) {
|
||||
let message = rustc_errors::DiagnosticMessage::from(diagnostic.message);
|
||||
let mut diag: DiagnosticBuilder<'_, ()> =
|
||||
DiagnosticBuilder::new(&self.sess().dcx, diagnostic.level.to_internal(), message);
|
||||
let mut diag: Diag<'_, ()> =
|
||||
Diag::new(&self.sess().dcx, diagnostic.level.to_internal(), message);
|
||||
diag.span(MultiSpan::from_spans(diagnostic.spans));
|
||||
for child in diagnostic.children {
|
||||
diag.sub(child.level.to_internal(), child.message, MultiSpan::from_spans(child.spans));
|
||||
|
@ -33,7 +33,7 @@ fn create_test_handler() -> (DiagCtxt, Lrc<SourceMap>, Arc<Mutex<Vec<u8>>>) {
|
||||
let emitter = HumanEmitter::new(Box::new(Shared { data: output.clone() }), fallback_bundle)
|
||||
.sm(Some(source_map.clone()))
|
||||
.diagnostic_width(Some(140));
|
||||
let dcx = DiagCtxt::with_emitter(Box::new(emitter));
|
||||
let dcx = DiagCtxt::new(Box::new(emitter));
|
||||
(dcx, source_map, output)
|
||||
}
|
||||
|
||||
|
@ -390,20 +390,21 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
|
||||
|
||||
// Entry point:
|
||||
gated!(unix_sigpipe, Normal, template!(Word, NameValueStr: "inherit|sig_ign|sig_dfl"), ErrorFollowing, experimental!(unix_sigpipe)),
|
||||
ungated!(start, Normal, template!(Word), WarnFollowing),
|
||||
ungated!(no_start, CrateLevel, template!(Word), WarnFollowing),
|
||||
ungated!(no_main, CrateLevel, template!(Word), WarnFollowing),
|
||||
ungated!(start, Normal, template!(Word), WarnFollowing, @only_local: true),
|
||||
ungated!(no_start, CrateLevel, template!(Word), WarnFollowing, @only_local: true),
|
||||
ungated!(no_main, CrateLevel, template!(Word), WarnFollowing, @only_local: true),
|
||||
|
||||
// Modules, prelude, and resolution:
|
||||
ungated!(path, Normal, template!(NameValueStr: "file"), FutureWarnFollowing),
|
||||
ungated!(no_std, CrateLevel, template!(Word), WarnFollowing),
|
||||
ungated!(no_implicit_prelude, Normal, template!(Word), WarnFollowing),
|
||||
ungated!(path, Normal, template!(NameValueStr: "file"), FutureWarnFollowing, @only_local: true),
|
||||
ungated!(no_std, CrateLevel, template!(Word), WarnFollowing, @only_local: true),
|
||||
ungated!(no_implicit_prelude, Normal, template!(Word), WarnFollowing, @only_local: true),
|
||||
ungated!(non_exhaustive, Normal, template!(Word), WarnFollowing),
|
||||
|
||||
// Runtime
|
||||
ungated!(
|
||||
windows_subsystem, CrateLevel,
|
||||
template!(NameValueStr: "windows|console"), FutureWarnFollowing
|
||||
template!(NameValueStr: "windows|console"), FutureWarnFollowing,
|
||||
@only_local: true
|
||||
),
|
||||
ungated!(panic_handler, Normal, template!(Word), WarnFollowing), // RFC 2070
|
||||
|
||||
@ -416,13 +417,17 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
|
||||
DuplicatesOk, @only_local: true,
|
||||
),
|
||||
ungated!(track_caller, Normal, template!(Word), WarnFollowing),
|
||||
ungated!(instruction_set, Normal, template!(List: "set"), ErrorPreceding),
|
||||
ungated!(instruction_set, Normal, template!(List: "set"), ErrorPreceding, @only_local: true),
|
||||
gated!(
|
||||
no_sanitize, Normal,
|
||||
template!(List: "address, kcfi, memory, thread"), DuplicatesOk,
|
||||
experimental!(no_sanitize)
|
||||
@only_local: true, experimental!(no_sanitize)
|
||||
),
|
||||
gated!(
|
||||
coverage, Normal, template!(Word, List: "on|off"),
|
||||
WarnFollowing, @only_local: true,
|
||||
coverage_attribute, experimental!(coverage)
|
||||
),
|
||||
gated!(coverage, Normal, template!(Word, List: "on|off"), WarnFollowing, coverage_attribute, experimental!(coverage)),
|
||||
|
||||
ungated!(
|
||||
doc, Normal, template!(List: "hidden|inline|...", NameValueStr: "string"), DuplicatesOk
|
||||
@ -431,7 +436,8 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
|
||||
// Debugging
|
||||
ungated!(
|
||||
debugger_visualizer, Normal,
|
||||
template!(List: r#"natvis_file = "...", gdb_script_file = "...""#), DuplicatesOk
|
||||
template!(List: r#"natvis_file = "...", gdb_script_file = "...""#),
|
||||
DuplicatesOk, @only_local: true
|
||||
),
|
||||
|
||||
// ==========================================================================
|
||||
@ -455,26 +461,35 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
|
||||
marker_trait_attr, experimental!(marker)
|
||||
),
|
||||
gated!(
|
||||
thread_local, Normal, template!(Word), WarnFollowing,
|
||||
thread_local, Normal, template!(Word), WarnFollowing, @only_local: true,
|
||||
"`#[thread_local]` is an experimental feature, and does not currently handle destructors",
|
||||
),
|
||||
gated!(no_core, CrateLevel, template!(Word), WarnFollowing, experimental!(no_core)),
|
||||
gated!(
|
||||
no_core, CrateLevel, template!(Word), WarnFollowing,
|
||||
@only_local: true, experimental!(no_core)
|
||||
),
|
||||
// RFC 2412
|
||||
gated!(
|
||||
optimize, Normal, template!(List: "size|speed"), ErrorPreceding, optimize_attribute,
|
||||
experimental!(optimize),
|
||||
optimize, Normal, template!(List: "size|speed"), ErrorPreceding,
|
||||
@only_local: true, optimize_attribute, experimental!(optimize)
|
||||
),
|
||||
|
||||
gated!(ffi_pure, Normal, template!(Word), WarnFollowing, experimental!(ffi_pure)),
|
||||
gated!(ffi_const, Normal, template!(Word), WarnFollowing, experimental!(ffi_const)),
|
||||
gated!(
|
||||
ffi_pure, Normal, template!(Word), WarnFollowing,
|
||||
@only_local: true, experimental!(ffi_pure)
|
||||
),
|
||||
gated!(
|
||||
ffi_const, Normal, template!(Word), WarnFollowing,
|
||||
@only_local: true, experimental!(ffi_const)
|
||||
),
|
||||
gated!(
|
||||
register_tool, CrateLevel, template!(List: "tool1, tool2, ..."), DuplicatesOk,
|
||||
experimental!(register_tool),
|
||||
@only_local: true, experimental!(register_tool),
|
||||
),
|
||||
|
||||
gated!(
|
||||
cmse_nonsecure_entry, Normal, template!(Word), WarnFollowing,
|
||||
experimental!(cmse_nonsecure_entry)
|
||||
@only_local: true, experimental!(cmse_nonsecure_entry)
|
||||
),
|
||||
// RFC 2632
|
||||
gated!(
|
||||
@ -492,11 +507,14 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
|
||||
// `#[collapse_debuginfo]`
|
||||
gated!(
|
||||
collapse_debuginfo, Normal, template!(Word, List: "no|external|yes"), ErrorFollowing,
|
||||
experimental!(collapse_debuginfo)
|
||||
@only_local: true, experimental!(collapse_debuginfo)
|
||||
),
|
||||
|
||||
// RFC 2397
|
||||
gated!(do_not_recommend, Normal, template!(Word), WarnFollowing, experimental!(do_not_recommend)),
|
||||
gated!(
|
||||
do_not_recommend, Normal, template!(Word), WarnFollowing,
|
||||
@only_local: true, experimental!(do_not_recommend)
|
||||
),
|
||||
|
||||
// `#[cfi_encoding = ""]`
|
||||
gated!(
|
||||
@ -528,7 +546,8 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
|
||||
),
|
||||
ungated!(
|
||||
rustc_default_body_unstable, Normal,
|
||||
template!(List: r#"feature = "name", reason = "...", issue = "N""#), DuplicatesOk
|
||||
template!(List: r#"feature = "name", reason = "...", issue = "N""#),
|
||||
DuplicatesOk, @only_local: true
|
||||
),
|
||||
gated!(
|
||||
allow_internal_unstable, Normal, template!(Word, List: "feat1, feat2, ..."), DuplicatesOk,
|
||||
|
@ -420,7 +420,9 @@ impl DefPathData {
|
||||
pub fn name(&self) -> DefPathDataName {
|
||||
use self::DefPathData::*;
|
||||
match *self {
|
||||
TypeNs(name) if name == kw::Empty => DefPathDataName::Anon { namespace: sym::opaque },
|
||||
TypeNs(name) if name == kw::Empty => {
|
||||
DefPathDataName::Anon { namespace: sym::synthetic }
|
||||
}
|
||||
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => {
|
||||
DefPathDataName::Named(name)
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::sorted_map::SortedMap;
|
||||
use rustc_data_structures::unord::UnordMap;
|
||||
use rustc_errors::{
|
||||
codes::*, pluralize, struct_span_code_err, Applicability, DiagnosticBuilder, ErrorGuaranteed,
|
||||
codes::*, pluralize, struct_span_code_err, Applicability, Diag, ErrorGuaranteed,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
@ -371,7 +371,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
// FIXME(fmease): Heavily adapted from `rustc_hir_typeck::method::suggest`. Deduplicate.
|
||||
fn note_ambiguous_inherent_assoc_type(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
candidates: Vec<DefId>,
|
||||
span: Span,
|
||||
) {
|
||||
@ -429,7 +429,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
let tcx = self.tcx();
|
||||
|
||||
let adt_did = self_ty.ty_adt_def().map(|def| def.did());
|
||||
let add_def_label = |err: &mut DiagnosticBuilder<'_>| {
|
||||
let add_def_label = |err: &mut Diag<'_>| {
|
||||
if let Some(did) = adt_did {
|
||||
err.span_label(
|
||||
tcx.def_span(did),
|
||||
|
@ -6,7 +6,7 @@ use crate::astconv::{
|
||||
use crate::structured_errors::{GenericArgsInfo, StructuredDiagnostic, WrongNumberOfGenericArgs};
|
||||
use rustc_ast::ast::ParamKindOrd;
|
||||
use rustc_errors::{
|
||||
codes::*, struct_span_code_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan,
|
||||
codes::*, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, MultiSpan,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
@ -47,7 +47,7 @@ fn generic_arg_mismatch_err(
|
||||
}
|
||||
}
|
||||
|
||||
let add_braces_suggestion = |arg: &GenericArg<'_>, err: &mut DiagnosticBuilder<'_>| {
|
||||
let add_braces_suggestion = |arg: &GenericArg<'_>, err: &mut Diag<'_>| {
|
||||
let suggestions = vec![
|
||||
(arg.span().shrink_to_lo(), String::from("{ ")),
|
||||
(arg.span().shrink_to_hi(), String::from(" }")),
|
||||
|
@ -1,5 +1,5 @@
|
||||
use rustc_ast::TraitObjectSyntax;
|
||||
use rustc_errors::{codes::*, DiagnosticBuilder, EmissionGuarantee, StashKey};
|
||||
use rustc_errors::{codes::*, Diag, EmissionGuarantee, StashKey};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_lint_defs::{builtin::BARE_TRAIT_OBJECTS, Applicability};
|
||||
@ -13,7 +13,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
pub(super) fn maybe_lint_blanket_trait_impl<G: EmissionGuarantee>(
|
||||
&self,
|
||||
self_ty: &hir::Ty<'_>,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
) {
|
||||
let tcx = self.tcx();
|
||||
let parent_id = tcx.hir().get_parent_item(self_ty.hir_id).def_id;
|
||||
@ -75,11 +75,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
}
|
||||
|
||||
/// Make sure that we are in the condition to suggest `impl Trait`.
|
||||
fn maybe_lint_impl_trait(
|
||||
&self,
|
||||
self_ty: &hir::Ty<'_>,
|
||||
diag: &mut DiagnosticBuilder<'_>,
|
||||
) -> bool {
|
||||
fn maybe_lint_impl_trait(&self, self_ty: &hir::Ty<'_>, diag: &mut Diag<'_>) -> bool {
|
||||
let tcx = self.tcx();
|
||||
let parent_id = tcx.hir().get_parent_item(self_ty.hir_id).def_id;
|
||||
let (sig, generics, owner) = match tcx.hir_node_by_def_id(parent_id) {
|
||||
|
@ -18,8 +18,7 @@ use crate::require_c_abi_if_c_variadic;
|
||||
use rustc_ast::TraitObjectSyntax;
|
||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
|
||||
use rustc_errors::{
|
||||
codes::*, struct_span_code_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, FatalError,
|
||||
MultiSpan,
|
||||
codes::*, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, FatalError, MultiSpan,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
|
||||
@ -1723,7 +1722,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
pub fn prohibit_generics<'a>(
|
||||
&self,
|
||||
segments: impl Iterator<Item = &'a hir::PathSegment<'a>> + Clone,
|
||||
extend: impl Fn(&mut DiagnosticBuilder<'_>),
|
||||
extend: impl Fn(&mut Diag<'_>),
|
||||
) -> bool {
|
||||
let args = segments.clone().flat_map(|segment| segment.args().args);
|
||||
|
||||
@ -2739,7 +2738,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
&self,
|
||||
constrained_regions: FxHashSet<ty::BoundRegionKind>,
|
||||
referenced_regions: FxHashSet<ty::BoundRegionKind>,
|
||||
generate_err: impl Fn(&str) -> DiagnosticBuilder<'tcx>,
|
||||
generate_err: impl Fn(&str) -> Diag<'tcx>,
|
||||
) {
|
||||
for br in referenced_regions.difference(&constrained_regions) {
|
||||
let br_name = match *br {
|
||||
|
@ -1236,7 +1236,7 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||
fn detect_discriminant_duplicate<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>) {
|
||||
// Helper closure to reduce duplicate code. This gets called everytime we detect a duplicate.
|
||||
// Here `idx` refers to the order of which the discriminant appears, and its index in `vs`
|
||||
let report = |dis: Discr<'tcx>, idx, err: &mut DiagnosticBuilder<'_>| {
|
||||
let report = |dis: Discr<'tcx>, idx, err: &mut Diag<'_>| {
|
||||
let var = adt.variant(idx); // HIR for the duplicate discriminant
|
||||
let (span, display_discr) = match var.discr {
|
||||
ty::VariantDiscr::Explicit(discr_def_id) => {
|
||||
@ -1296,7 +1296,7 @@ fn detect_discriminant_duplicate<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
|
||||
let mut i = 0;
|
||||
while i < discrs.len() {
|
||||
let var_i_idx = discrs[i].0;
|
||||
let mut error: Option<DiagnosticBuilder<'_, _>> = None;
|
||||
let mut error: Option<Diag<'_, _>> = None;
|
||||
|
||||
let mut o = i + 1;
|
||||
while o < discrs.len() {
|
||||
|
@ -1,9 +1,8 @@
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir_pretty::qpath_to_string;
|
||||
use rustc_lint_defs::builtin::STATIC_MUT_REFS;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_middle::ty::{Mutability, TyCtxt};
|
||||
use rustc_span::Span;
|
||||
use rustc_type_ir::Mutability;
|
||||
|
||||
use crate::errors;
|
||||
|
||||
|
@ -78,7 +78,7 @@ use std::num::NonZero;
|
||||
|
||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_errors::{pluralize, struct_span_code_err, DiagnosticBuilder};
|
||||
use rustc_errors::{pluralize, struct_span_code_err, Diag};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_index::bit_set::BitSet;
|
||||
|
@ -17,7 +17,7 @@
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
|
||||
use rustc_data_structures::unord::UnordMap;
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, StashKey};
|
||||
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, StashKey};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
|
||||
@ -186,7 +186,7 @@ pub(crate) fn placeholder_type_error_diag<'tcx>(
|
||||
suggest: bool,
|
||||
hir_ty: Option<&hir::Ty<'_>>,
|
||||
kind: &'static str,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
if placeholder_types.is_empty() {
|
||||
return bad_placeholder(tcx, additional_spans, kind);
|
||||
}
|
||||
@ -335,7 +335,7 @@ fn bad_placeholder<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
mut spans: Vec<Span>,
|
||||
kind: &'static str,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let kind = if kind.ends_with('s') { format!("{kind}es") } else { format!("{kind}s") };
|
||||
|
||||
spans.sort();
|
||||
@ -760,7 +760,7 @@ fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) {
|
||||
let wrapped_discr = prev_discr.map_or(initial, |d| d.wrap_incr(tcx));
|
||||
prev_discr = Some(
|
||||
if let ty::VariantDiscr::Explicit(const_def_id) = variant.discr {
|
||||
def.eval_explicit_discr(tcx, const_def_id)
|
||||
def.eval_explicit_discr(tcx, const_def_id).ok()
|
||||
} else if let Some(discr) = repr_type.disr_incr(tcx, prev_discr) {
|
||||
Some(discr)
|
||||
} else {
|
||||
|
@ -1181,13 +1181,12 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
||||
&& !self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id).is_async()
|
||||
&& !self.tcx.features().anonymous_lifetime_in_impl_trait
|
||||
{
|
||||
let mut diag: rustc_errors::DiagnosticBuilder<'_> =
|
||||
rustc_session::parse::feature_err(
|
||||
&self.tcx.sess,
|
||||
sym::anonymous_lifetime_in_impl_trait,
|
||||
lifetime_ref.ident.span,
|
||||
"anonymous lifetimes in `impl Trait` are unstable",
|
||||
);
|
||||
let mut diag: rustc_errors::Diag<'_> = rustc_session::parse::feature_err(
|
||||
&self.tcx.sess,
|
||||
sym::anonymous_lifetime_in_impl_trait,
|
||||
lifetime_ref.ident.span,
|
||||
"anonymous lifetimes in `impl Trait` are unstable",
|
||||
);
|
||||
|
||||
if let Some(generics) =
|
||||
self.tcx.hir().get_generics(lifetime_ref.hir_id.owner.def_id)
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
use crate::fluent_generated as fluent;
|
||||
use rustc_errors::{
|
||||
codes::*, Applicability, DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, Level,
|
||||
MultiSpan,
|
||||
codes::*, Applicability, Diag, DiagCtxt, EmissionGuarantee, IntoDiagnostic, Level, MultiSpan,
|
||||
};
|
||||
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
||||
use rustc_middle::ty::Ty;
|
||||
@ -359,8 +358,8 @@ pub struct MissingTypeParams {
|
||||
// Manual implementation of `IntoDiagnostic` to be able to call `span_to_snippet`.
|
||||
impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for MissingTypeParams {
|
||||
#[track_caller]
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> DiagnosticBuilder<'a, G> {
|
||||
let mut err = DiagnosticBuilder::new(dcx, level, fluent::hir_analysis_missing_type_params);
|
||||
fn into_diagnostic(self, dcx: &'a DiagCtxt, level: Level) -> Diag<'a, G> {
|
||||
let mut err = Diag::new(dcx, level, fluent::hir_analysis_missing_type_params);
|
||||
err.span(self.span);
|
||||
err.code(E0393);
|
||||
err.arg("parameterCount", self.missing_type_params.len());
|
||||
|
@ -6,7 +6,7 @@ pub use self::{
|
||||
missing_cast_for_variadic_arg::*, sized_unsized_cast::*, wrong_number_of_generic_args::*,
|
||||
};
|
||||
|
||||
use rustc_errors::{DiagnosticBuilder, ErrCode};
|
||||
use rustc_errors::{Diag, ErrCode};
|
||||
use rustc_session::Session;
|
||||
|
||||
pub trait StructuredDiagnostic<'tcx> {
|
||||
@ -14,7 +14,7 @@ pub trait StructuredDiagnostic<'tcx> {
|
||||
|
||||
fn code(&self) -> ErrCode;
|
||||
|
||||
fn diagnostic(&self) -> DiagnosticBuilder<'tcx> {
|
||||
fn diagnostic(&self) -> Diag<'tcx> {
|
||||
let err = self.diagnostic_common();
|
||||
|
||||
if self.session().teach(self.code()) {
|
||||
@ -24,13 +24,13 @@ pub trait StructuredDiagnostic<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx>;
|
||||
fn diagnostic_common(&self) -> Diag<'tcx>;
|
||||
|
||||
fn diagnostic_regular(&self, err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> {
|
||||
fn diagnostic_regular(&self, err: Diag<'tcx>) -> Diag<'tcx> {
|
||||
err
|
||||
}
|
||||
|
||||
fn diagnostic_extended(&self, err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> {
|
||||
fn diagnostic_extended(&self, err: Diag<'tcx>) -> Diag<'tcx> {
|
||||
err
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{errors, structured_errors::StructuredDiagnostic};
|
||||
use rustc_errors::{codes::*, DiagnosticBuilder};
|
||||
use rustc_errors::{codes::*, Diag};
|
||||
use rustc_middle::ty::{Ty, TypeVisitableExt};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::Span;
|
||||
@ -20,7 +20,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for MissingCastForVariadicArg<'tcx, '_> {
|
||||
E0617
|
||||
}
|
||||
|
||||
fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx> {
|
||||
fn diagnostic_common(&self) -> Diag<'tcx> {
|
||||
let (sugg_span, replace, help) =
|
||||
if let Ok(snippet) = self.sess.source_map().span_to_snippet(self.span) {
|
||||
(Some(self.span), format!("{} as {}", snippet, self.cast_ty), None)
|
||||
@ -44,7 +44,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for MissingCastForVariadicArg<'tcx, '_> {
|
||||
err
|
||||
}
|
||||
|
||||
fn diagnostic_extended(&self, mut err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> {
|
||||
fn diagnostic_extended(&self, mut err: Diag<'tcx>) -> Diag<'tcx> {
|
||||
err.note(format!(
|
||||
"certain types, like `{}`, must be casted before passing them to a \
|
||||
variadic function, because of arcane ABI rules dictated by the C \
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{errors, structured_errors::StructuredDiagnostic};
|
||||
use rustc_errors::{codes::*, DiagnosticBuilder};
|
||||
use rustc_errors::{codes::*, Diag};
|
||||
use rustc_middle::ty::{Ty, TypeVisitableExt};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::Span;
|
||||
@ -20,7 +20,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for SizedUnsizedCast<'tcx> {
|
||||
E0607
|
||||
}
|
||||
|
||||
fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx> {
|
||||
fn diagnostic_common(&self) -> Diag<'tcx> {
|
||||
let mut err = self.sess.dcx().create_err(errors::CastThinPointerToFatPointer {
|
||||
span: self.span,
|
||||
expr_ty: self.expr_ty,
|
||||
@ -34,7 +34,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for SizedUnsizedCast<'tcx> {
|
||||
err
|
||||
}
|
||||
|
||||
fn diagnostic_extended(&self, mut err: DiagnosticBuilder<'tcx>) -> DiagnosticBuilder<'tcx> {
|
||||
fn diagnostic_extended(&self, mut err: Diag<'tcx>) -> Diag<'tcx> {
|
||||
err.help(
|
||||
"Thin pointers are \"simple\" pointers: they are purely a reference to a
|
||||
memory address.
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::structured_errors::StructuredDiagnostic;
|
||||
use rustc_errors::{codes::*, pluralize, Applicability, DiagnosticBuilder, MultiSpan};
|
||||
use rustc_errors::{codes::*, pluralize, Applicability, Diag, MultiSpan};
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::ty::{self as ty, AssocItems, AssocKind, TyCtxt};
|
||||
use rustc_session::Session;
|
||||
@ -518,14 +518,14 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn start_diagnostics(&self) -> DiagnosticBuilder<'tcx> {
|
||||
fn start_diagnostics(&self) -> Diag<'tcx> {
|
||||
let span = self.path_segment.ident.span;
|
||||
let msg = self.create_error_message();
|
||||
self.tcx.dcx().struct_span_err(span, msg).with_code(self.code())
|
||||
}
|
||||
|
||||
/// Builds the `expected 1 type argument / supplied 2 type arguments` message.
|
||||
fn notify(&self, err: &mut DiagnosticBuilder<'_>) {
|
||||
fn notify(&self, err: &mut Diag<'_>) {
|
||||
let (quantifier, bound) = self.get_quantifier_and_bound();
|
||||
let provided_args = self.num_provided_args();
|
||||
|
||||
@ -577,7 +577,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn suggest(&self, err: &mut DiagnosticBuilder<'_>) {
|
||||
fn suggest(&self, err: &mut Diag<'_>) {
|
||||
debug!(
|
||||
"suggest(self.provided {:?}, self.gen_args.span(): {:?})",
|
||||
self.num_provided_args(),
|
||||
@ -605,7 +605,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
||||
/// ```text
|
||||
/// type Map = HashMap<String>;
|
||||
/// ```
|
||||
fn suggest_adding_args(&self, err: &mut DiagnosticBuilder<'_>) {
|
||||
fn suggest_adding_args(&self, err: &mut Diag<'_>) {
|
||||
if self.gen_args.parenthesized != hir::GenericArgsParentheses::No {
|
||||
return;
|
||||
}
|
||||
@ -624,7 +624,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn suggest_adding_lifetime_args(&self, err: &mut DiagnosticBuilder<'_>) {
|
||||
fn suggest_adding_lifetime_args(&self, err: &mut Diag<'_>) {
|
||||
debug!("suggest_adding_lifetime_args(path_segment: {:?})", self.path_segment);
|
||||
let num_missing_args = self.num_missing_lifetime_args();
|
||||
let num_params_to_take = num_missing_args;
|
||||
@ -678,7 +678,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn suggest_adding_type_and_const_args(&self, err: &mut DiagnosticBuilder<'_>) {
|
||||
fn suggest_adding_type_and_const_args(&self, err: &mut Diag<'_>) {
|
||||
let num_missing_args = self.num_missing_type_or_const_args();
|
||||
let msg = format!("add missing {} argument{}", self.kind(), pluralize!(num_missing_args));
|
||||
|
||||
@ -738,7 +738,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
||||
/// ```compile_fail
|
||||
/// Into::into::<Option<_>>(42) // suggests considering `Into::<Option<_>>::into(42)`
|
||||
/// ```
|
||||
fn suggest_moving_args_from_assoc_fn_to_trait(&self, err: &mut DiagnosticBuilder<'_>) {
|
||||
fn suggest_moving_args_from_assoc_fn_to_trait(&self, err: &mut Diag<'_>) {
|
||||
let trait_ = match self.tcx.trait_of_item(self.def_id) {
|
||||
Some(def_id) => def_id,
|
||||
None => return,
|
||||
@ -794,7 +794,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
||||
|
||||
fn suggest_moving_args_from_assoc_fn_to_trait_for_qualified_path(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
qpath: &'tcx hir::QPath<'tcx>,
|
||||
msg: String,
|
||||
num_assoc_fn_excess_args: usize,
|
||||
@ -827,7 +827,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
||||
|
||||
fn suggest_moving_args_from_assoc_fn_to_trait_for_method_call(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
trait_def_id: DefId,
|
||||
expr: &'tcx hir::Expr<'tcx>,
|
||||
msg: String,
|
||||
@ -881,7 +881,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
||||
/// ```text
|
||||
/// type Map = HashMap<String, String, String, String>;
|
||||
/// ```
|
||||
fn suggest_removing_args_or_generics(&self, err: &mut DiagnosticBuilder<'_>) {
|
||||
fn suggest_removing_args_or_generics(&self, err: &mut Diag<'_>) {
|
||||
let num_provided_lt_args = self.num_provided_lifetime_args();
|
||||
let num_provided_type_const_args = self.num_provided_type_or_const_args();
|
||||
let unbound_types = self.get_unbound_associated_types();
|
||||
@ -899,7 +899,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
||||
let provided_args_matches_unbound_traits =
|
||||
unbound_types.len() == num_redundant_type_or_const_args;
|
||||
|
||||
let remove_lifetime_args = |err: &mut DiagnosticBuilder<'_>| {
|
||||
let remove_lifetime_args = |err: &mut Diag<'_>| {
|
||||
let mut lt_arg_spans = Vec::new();
|
||||
let mut found_redundant = false;
|
||||
for arg in self.gen_args.args {
|
||||
@ -940,7 +940,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
||||
);
|
||||
};
|
||||
|
||||
let remove_type_or_const_args = |err: &mut DiagnosticBuilder<'_>| {
|
||||
let remove_type_or_const_args = |err: &mut Diag<'_>| {
|
||||
let mut gen_arg_spans = Vec::new();
|
||||
let mut found_redundant = false;
|
||||
for arg in self.gen_args.args {
|
||||
@ -1037,7 +1037,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
||||
}
|
||||
|
||||
/// Builds the `type defined here` message.
|
||||
fn show_definition(&self, err: &mut DiagnosticBuilder<'_>) {
|
||||
fn show_definition(&self, err: &mut Diag<'_>) {
|
||||
let mut spans: MultiSpan = if let Some(def_span) = self.tcx.def_ident_span(self.def_id) {
|
||||
if self.tcx.sess.source_map().is_span_accessible(def_span) {
|
||||
def_span.into()
|
||||
@ -1088,7 +1088,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
||||
}
|
||||
|
||||
/// Add note if `impl Trait` is explicitly specified.
|
||||
fn note_synth_provided(&self, err: &mut DiagnosticBuilder<'_>) {
|
||||
fn note_synth_provided(&self, err: &mut Diag<'_>) {
|
||||
if !self.is_synth_provided() {
|
||||
return;
|
||||
}
|
||||
@ -1106,7 +1106,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for WrongNumberOfGenericArgs<'_, 'tcx> {
|
||||
E0107
|
||||
}
|
||||
|
||||
fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx> {
|
||||
fn diagnostic_common(&self) -> Diag<'tcx> {
|
||||
let mut err = self.start_diagnostics();
|
||||
|
||||
self.notify(&mut err);
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::coercion::{AsCoercionSite, CoerceMany};
|
||||
use crate::{Diverges, Expectation, FnCtxt, Needs};
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
||||
use rustc_errors::{Applicability, Diag};
|
||||
use rustc_hir::{
|
||||
self as hir,
|
||||
def::{CtorOf, DefKind, Res},
|
||||
@ -177,7 +177,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn explain_never_type_coerced_to_unit(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
arm: &hir::Arm<'tcx>,
|
||||
arm_ty: Ty<'tcx>,
|
||||
prior_arm: Option<(Option<hir::HirId>, Ty<'tcx>, Span)>,
|
||||
@ -209,7 +209,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn suggest_removing_semicolon_for_coerce(
|
||||
&self,
|
||||
diag: &mut DiagnosticBuilder<'_>,
|
||||
diag: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'tcx>,
|
||||
arm_ty: Ty<'tcx>,
|
||||
prior_arm: Option<(Option<hir::HirId>, Ty<'tcx>, Span)>,
|
||||
@ -303,7 +303,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// `if let PAT = EXPR {}` expressions that could be turned into `let PAT = EXPR;`.
|
||||
fn explain_if_expr(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
ret_reason: Option<(Span, String)>,
|
||||
if_span: Span,
|
||||
cond_expr: &'tcx hir::Expr<'tcx>,
|
||||
|
@ -4,7 +4,7 @@ use super::{Expectation, FnCtxt, TupleArgumentsFlag};
|
||||
|
||||
use crate::errors;
|
||||
use rustc_ast::util::parser::PREC_POSTFIX;
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, StashKey};
|
||||
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, StashKey};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{self, CtorKind, Namespace, Res};
|
||||
use rustc_hir::def_id::DefId;
|
||||
@ -347,7 +347,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// likely intention is to call the closure, suggest `(||{})()`. (#55851)
|
||||
fn identify_bad_closure_def_and_call(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
hir_id: hir::HirId,
|
||||
callee_node: &hir::ExprKind<'_>,
|
||||
callee_span: Span,
|
||||
@ -410,7 +410,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// likely intention is to create an array containing tuples.
|
||||
fn maybe_suggest_bad_array_definition(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
call_expr: &'tcx hir::Expr<'tcx>,
|
||||
callee_expr: &'tcx hir::Expr<'tcx>,
|
||||
) -> bool {
|
||||
@ -601,7 +601,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// and suggesting the fix if the method probe is successful.
|
||||
fn suggest_call_as_method(
|
||||
&self,
|
||||
diag: &mut DiagnosticBuilder<'_, ()>,
|
||||
diag: &mut Diag<'_, ()>,
|
||||
segment: &'tcx hir::PathSegment<'tcx>,
|
||||
arg_exprs: &'tcx [hir::Expr<'tcx>],
|
||||
call_expr: &'tcx hir::Expr<'tcx>,
|
||||
|
@ -33,7 +33,7 @@ use super::FnCtxt;
|
||||
use crate::errors;
|
||||
use crate::type_error_struct;
|
||||
use hir::ExprKind;
|
||||
use rustc_errors::{codes::*, Applicability, DiagnosticBuilder, ErrorGuaranteed};
|
||||
use rustc_errors::{codes::*, Applicability, Diag, ErrorGuaranteed};
|
||||
use rustc_hir as hir;
|
||||
use rustc_macros::{TypeFoldable, TypeVisitable};
|
||||
use rustc_middle::mir::Mutability;
|
||||
@ -182,7 +182,7 @@ fn make_invalid_casting_error<'a, 'tcx>(
|
||||
expr_ty: Ty<'tcx>,
|
||||
cast_ty: Ty<'tcx>,
|
||||
fcx: &FnCtxt<'a, 'tcx>,
|
||||
) -> DiagnosticBuilder<'a> {
|
||||
) -> Diag<'a> {
|
||||
type_error_struct!(
|
||||
fcx.dcx(),
|
||||
span,
|
||||
@ -980,11 +980,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||
|
||||
/// Attempt to suggest using `.is_empty` when trying to cast from a
|
||||
/// collection type to a boolean.
|
||||
fn try_suggest_collection_to_bool(
|
||||
&self,
|
||||
fcx: &FnCtxt<'a, 'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
) {
|
||||
fn try_suggest_collection_to_bool(&self, fcx: &FnCtxt<'a, 'tcx>, err: &mut Diag<'_>) {
|
||||
if self.cast_ty.is_bool() {
|
||||
let derefed = fcx
|
||||
.autoderef(self.expr_span, self.expr_ty)
|
||||
|
@ -36,7 +36,7 @@
|
||||
//! ```
|
||||
|
||||
use crate::FnCtxt;
|
||||
use rustc_errors::{codes::*, struct_span_code_err, Applicability, DiagnosticBuilder, MultiSpan};
|
||||
use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag, MultiSpan};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
@ -636,6 +636,20 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||
{
|
||||
self.resolve_vars_if_possible(trait_pred)
|
||||
}
|
||||
// Eagerly process alias-relate obligations in new trait solver,
|
||||
// since these can be emitted in the process of solving trait goals,
|
||||
// but we need to constrain vars before processing goals mentioning
|
||||
// them.
|
||||
Some(ty::PredicateKind::AliasRelate(..)) => {
|
||||
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new(self);
|
||||
fulfill_cx.register_predicate_obligation(self, obligation);
|
||||
let errs = fulfill_cx.select_where_possible(self);
|
||||
if !errs.is_empty() {
|
||||
return Err(TypeError::Mismatch);
|
||||
}
|
||||
coercion.obligations.extend(fulfill_cx.pending_obligations());
|
||||
continue;
|
||||
}
|
||||
_ => {
|
||||
coercion.obligations.push(obligation);
|
||||
continue;
|
||||
@ -1437,7 +1451,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
||||
&mut self,
|
||||
fcx: &FnCtxt<'a, 'tcx>,
|
||||
cause: &ObligationCause<'tcx>,
|
||||
augment_error: impl FnOnce(&mut DiagnosticBuilder<'_>),
|
||||
augment_error: impl FnOnce(&mut Diag<'_>),
|
||||
label_unit_as_expected: bool,
|
||||
) {
|
||||
self.coerce_inner(
|
||||
@ -1460,7 +1474,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
||||
cause: &ObligationCause<'tcx>,
|
||||
expression: Option<&'tcx hir::Expr<'tcx>>,
|
||||
mut expression_ty: Ty<'tcx>,
|
||||
augment_error: impl FnOnce(&mut DiagnosticBuilder<'_>),
|
||||
augment_error: impl FnOnce(&mut Diag<'_>),
|
||||
label_expression_as_expected: bool,
|
||||
) {
|
||||
// Incorporate whatever type inference information we have
|
||||
@ -1671,7 +1685,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
||||
|
||||
fn note_unreachable_loop_return(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
expr: &hir::Expr<'tcx>,
|
||||
ret_exprs: &Vec<&'tcx hir::Expr<'tcx>>,
|
||||
@ -1783,7 +1797,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
||||
id: hir::HirId,
|
||||
expression: Option<&'tcx hir::Expr<'tcx>>,
|
||||
blk_id: Option<hir::HirId>,
|
||||
) -> DiagnosticBuilder<'a> {
|
||||
) -> Diag<'a> {
|
||||
let mut err = fcx.err_ctxt().report_mismatched_types(cause, expected, found, ty_err);
|
||||
|
||||
let parent_id = fcx.tcx.parent_hir_id(id);
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::FnCtxt;
|
||||
use rustc_errors::MultiSpan;
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
||||
use rustc_errors::{Applicability, Diag};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
@ -19,7 +19,7 @@ use super::method::probe;
|
||||
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
pub fn emit_type_mismatch_suggestions(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'tcx>,
|
||||
expr_ty: Ty<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
@ -70,7 +70,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub fn emit_coerce_suggestions(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'tcx>,
|
||||
expr_ty: Ty<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
@ -174,7 +174,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
sp: Span,
|
||||
expected: Ty<'tcx>,
|
||||
actual: Ty<'tcx>,
|
||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
) -> Option<Diag<'tcx>> {
|
||||
self.demand_suptype_with_origin(&self.misc(sp), expected, actual)
|
||||
}
|
||||
|
||||
@ -184,7 +184,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
cause: &ObligationCause<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
actual: Ty<'tcx>,
|
||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
) -> Option<Diag<'tcx>> {
|
||||
match self.at(cause, self.param_env).sup(DefineOpaqueTypes::Yes, expected, actual) {
|
||||
Ok(InferOk { obligations, value: () }) => {
|
||||
self.register_predicates(obligations);
|
||||
@ -205,7 +205,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
sp: Span,
|
||||
expected: Ty<'tcx>,
|
||||
actual: Ty<'tcx>,
|
||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
) -> Option<Diag<'tcx>> {
|
||||
self.demand_eqtype_with_origin(&self.misc(sp), expected, actual)
|
||||
}
|
||||
|
||||
@ -214,7 +214,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
cause: &ObligationCause<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
actual: Ty<'tcx>,
|
||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
) -> Option<Diag<'tcx>> {
|
||||
match self.at(cause, self.param_env).eq(DefineOpaqueTypes::Yes, expected, actual) {
|
||||
Ok(InferOk { obligations, value: () }) => {
|
||||
self.register_predicates(obligations);
|
||||
@ -252,7 +252,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
expected: Ty<'tcx>,
|
||||
mut expected_ty_expr: Option<&'tcx hir::Expr<'tcx>>,
|
||||
allow_two_phase: AllowTwoPhase,
|
||||
) -> (Ty<'tcx>, Option<DiagnosticBuilder<'tcx>>) {
|
||||
) -> (Ty<'tcx>, Option<Diag<'tcx>>) {
|
||||
let expected = self.resolve_vars_with_obligations(expected);
|
||||
|
||||
let e = match self.coerce(expr, checked_ty, expected, allow_two_phase, None) {
|
||||
@ -280,7 +280,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// with some expectation given by `source`.
|
||||
pub fn note_source_of_type_mismatch_constraint(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
source: TypeMismatchSource<'tcx>,
|
||||
) -> bool {
|
||||
@ -550,7 +550,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// expected type.
|
||||
pub fn annotate_loop_expected_due_to_inference(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
error: Option<TypeError<'tcx>>,
|
||||
) {
|
||||
@ -673,7 +673,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn annotate_expected_due_to_let_ty(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
error: Option<TypeError<'tcx>>,
|
||||
) {
|
||||
@ -782,7 +782,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn annotate_alternative_method_deref(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
error: Option<TypeError<'tcx>>,
|
||||
) {
|
||||
@ -1029,7 +1029,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn explain_self_literal(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
found: Ty<'tcx>,
|
||||
@ -1082,7 +1082,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn note_wrong_return_ty_due_to_generic_arg(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
checked_ty: Ty<'tcx>,
|
||||
) {
|
||||
|
@ -3,8 +3,8 @@ use std::borrow::Cow;
|
||||
|
||||
use crate::fluent_generated as fluent;
|
||||
use rustc_errors::{
|
||||
codes::*, AddToDiagnostic, Applicability, DiagnosticArgValue, DiagnosticBuilder,
|
||||
EmissionGuarantee, IntoDiagnosticArg, MultiSpan, SubdiagnosticMessageOp,
|
||||
codes::*, AddToDiagnostic, Applicability, Diag, DiagArgValue, EmissionGuarantee,
|
||||
IntoDiagnosticArg, MultiSpan, SubdiagnosticMessageOp,
|
||||
};
|
||||
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
||||
use rustc_middle::ty::Ty;
|
||||
@ -43,14 +43,14 @@ pub enum ReturnLikeStatementKind {
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for ReturnLikeStatementKind {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
|
||||
fn into_diagnostic_arg(self) -> DiagArgValue {
|
||||
let kind = match self {
|
||||
Self::Return => "return",
|
||||
Self::Become => "become",
|
||||
}
|
||||
.into();
|
||||
|
||||
DiagnosticArgValue::Str(kind)
|
||||
DiagArgValue::Str(kind)
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,7 +197,7 @@ pub struct TypeMismatchFruTypo {
|
||||
impl AddToDiagnostic for TypeMismatchFruTypo {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
_f: F,
|
||||
) {
|
||||
diag.arg("expr", self.expr.as_deref().unwrap_or("NONE"));
|
||||
@ -376,7 +376,7 @@ pub struct RemoveSemiForCoerce {
|
||||
impl AddToDiagnostic for RemoveSemiForCoerce {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
_f: F,
|
||||
) {
|
||||
let mut multispan: MultiSpan = self.semi.into();
|
||||
@ -552,7 +552,7 @@ pub enum CastUnknownPointerSub {
|
||||
impl rustc_errors::AddToDiagnostic for CastUnknownPointerSub {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
f: F,
|
||||
) {
|
||||
match self {
|
||||
|
@ -26,7 +26,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_data_structures::unord::UnordMap;
|
||||
use rustc_errors::{
|
||||
codes::*, pluralize, struct_span_code_err, AddToDiagnostic, Applicability, DiagnosticBuilder,
|
||||
codes::*, pluralize, struct_span_code_err, AddToDiagnostic, Applicability, Diag,
|
||||
ErrorGuaranteed, StashKey,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
@ -69,7 +69,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
&self,
|
||||
expr: &'tcx hir::Expr<'tcx>,
|
||||
expected_ty: Ty<'tcx>,
|
||||
extend_err: impl FnOnce(&mut DiagnosticBuilder<'_>),
|
||||
extend_err: impl FnOnce(&mut Diag<'_>),
|
||||
) -> Ty<'tcx> {
|
||||
let mut ty = self.check_expr_with_expectation(expr, ExpectHasType(expected_ty));
|
||||
|
||||
@ -954,7 +954,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
lhs: &'tcx hir::Expr<'tcx>,
|
||||
code: ErrCode,
|
||||
op_span: Span,
|
||||
adjust_err: impl FnOnce(&mut DiagnosticBuilder<'_>),
|
||||
adjust_err: impl FnOnce(&mut Diag<'_>),
|
||||
) {
|
||||
if lhs.is_syntactic_place_expr() {
|
||||
return;
|
||||
@ -980,11 +980,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
|
||||
/// Check if the expression that could not be assigned to was a typoed expression that
|
||||
pub fn check_for_missing_semi(
|
||||
&self,
|
||||
expr: &'tcx hir::Expr<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
) -> bool {
|
||||
pub fn check_for_missing_semi(&self, expr: &'tcx hir::Expr<'tcx>, err: &mut Diag<'_>) -> bool {
|
||||
if let hir::ExprKind::Binary(binop, lhs, rhs) = expr.kind
|
||||
&& let hir::BinOpKind::Mul = binop.node
|
||||
&& self.tcx.sess.source_map().is_multiline(lhs.span.between(rhs.span))
|
||||
@ -1219,7 +1215,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
let lhs_ty = self.check_expr_with_needs(lhs, Needs::MutPlace);
|
||||
|
||||
let suggest_deref_binop = |err: &mut DiagnosticBuilder<'_>, rhs_ty: Ty<'tcx>| {
|
||||
let suggest_deref_binop = |err: &mut Diag<'_>, rhs_ty: Ty<'tcx>| {
|
||||
if let Some(lhs_deref_ty) = self.deref_once_mutably_for_diagnostic(lhs_ty) {
|
||||
// Can only assign if the type is sized, so if `DerefMut` yields a type that is
|
||||
// unsized, do not suggest dereferencing it.
|
||||
@ -2003,7 +1999,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
last_expr_field: &hir::ExprField<'tcx>,
|
||||
variant: &ty::VariantDef,
|
||||
args: GenericArgsRef<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
) {
|
||||
// I don't use 'is_range_literal' because only double-sided, half-open ranges count.
|
||||
if let ExprKind::Struct(QPath::LangItem(LangItem::Range, ..), [range_start, range_end], _) =
|
||||
@ -2519,7 +2515,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn suggest_await_on_field_access(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
field_ident: Ident,
|
||||
base: &'tcx hir::Expr<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
@ -2718,7 +2714,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
err.emit()
|
||||
}
|
||||
|
||||
fn point_at_param_definition(&self, err: &mut DiagnosticBuilder<'_>, param: ty::ParamTy) {
|
||||
fn point_at_param_definition(&self, err: &mut Diag<'_>, param: ty::ParamTy) {
|
||||
let generics = self.tcx.generics_of(self.body_id);
|
||||
let generic_param = generics.type_param(¶m, self.tcx);
|
||||
if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param.kind {
|
||||
@ -2737,7 +2733,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn maybe_suggest_array_indexing(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
base: &hir::Expr<'_>,
|
||||
field: Ident,
|
||||
@ -2761,7 +2757,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn suggest_first_deref_field(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
base: &hir::Expr<'_>,
|
||||
field: Ident,
|
||||
@ -2774,12 +2770,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn no_such_field_err(
|
||||
&self,
|
||||
field: Ident,
|
||||
expr_t: Ty<'tcx>,
|
||||
id: HirId,
|
||||
) -> DiagnosticBuilder<'_> {
|
||||
fn no_such_field_err(&self, field: Ident, expr_t: Ty<'tcx>, id: HirId) -> Diag<'_> {
|
||||
let span = field.span;
|
||||
debug!("no_such_field_err(span: {:?}, field: {:?}, expr_t: {:?})", span, field, expr_t);
|
||||
|
||||
@ -2862,7 +2853,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
err
|
||||
}
|
||||
|
||||
fn private_field_err(&self, field: Ident, base_did: DefId) -> DiagnosticBuilder<'_> {
|
||||
fn private_field_err(&self, field: Ident, base_did: DefId) -> Diag<'_> {
|
||||
let struct_path = self.tcx().def_path_str(base_did);
|
||||
let kind_name = self.tcx().def_descr(base_did);
|
||||
struct_span_code_err!(
|
||||
|
@ -5,7 +5,7 @@ use crate::rvalue_scopes;
|
||||
use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy};
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, StashKey};
|
||||
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan, StashKey};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorOf, DefKind, Res};
|
||||
use rustc_hir::def_id::DefId;
|
||||
@ -1020,7 +1020,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub(in super::super) fn note_internal_mutation_in_method(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
expected: Option<Ty<'tcx>>,
|
||||
found: Ty<'tcx>,
|
||||
|
@ -17,7 +17,7 @@ use itertools::Itertools;
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_errors::{
|
||||
codes::*, pluralize, Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, StashKey,
|
||||
codes::*, pluralize, Applicability, Diag, ErrorGuaranteed, MultiSpan, StashKey,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorOf, DefKind, Res};
|
||||
@ -561,7 +561,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
None
|
||||
};
|
||||
|
||||
let suggest_confusable = |err: &mut DiagnosticBuilder<'_>| {
|
||||
let suggest_confusable = |err: &mut Diag<'_>| {
|
||||
let Some(call_name) = call_ident else {
|
||||
return;
|
||||
};
|
||||
@ -1369,7 +1369,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
expected_ty: Ty<'tcx>,
|
||||
provided_ty: Ty<'tcx>,
|
||||
arg: &hir::Expr<'tcx>,
|
||||
err: &mut rustc_errors::DiagnosticBuilder<'tcx>,
|
||||
err: &mut Diag<'tcx>,
|
||||
) {
|
||||
if let ty::RawPtr(ty::TypeAndMut { mutbl: hir::Mutability::Mut, .. }) = expected_ty.kind()
|
||||
&& let ty::RawPtr(ty::TypeAndMut { mutbl: hir::Mutability::Not, .. }) =
|
||||
@ -2047,7 +2047,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn label_fn_like(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
callable_def_id: Option<DefId>,
|
||||
callee_ty: Option<Ty<'tcx>>,
|
||||
call_expr: &'tcx hir::Expr<'tcx>,
|
||||
|
@ -12,7 +12,7 @@ use core::cmp::min;
|
||||
use core::iter;
|
||||
use rustc_ast::util::parser::{ExprPrecedence, PREC_POSTFIX};
|
||||
use rustc_data_structures::packed::Pu128;
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder, MultiSpan};
|
||||
use rustc_errors::{Applicability, Diag, MultiSpan};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::def::{CtorKind, CtorOf, DefKind};
|
||||
@ -48,11 +48,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
.copied()
|
||||
}
|
||||
|
||||
pub(in super::super) fn suggest_semicolon_at_end(
|
||||
&self,
|
||||
span: Span,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
) {
|
||||
pub(in super::super) fn suggest_semicolon_at_end(&self, span: Span, err: &mut Diag<'_>) {
|
||||
// This suggestion is incorrect for
|
||||
// fn foo() -> bool { match () { () => true } || match () { () => true } }
|
||||
err.span_suggestion_short(
|
||||
@ -70,7 +66,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// - Possible missing return type if the return type is the default, and not `fn main()`.
|
||||
pub fn suggest_mismatched_types_on_tail(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &'tcx hir::Expr<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
found: Ty<'tcx>,
|
||||
@ -101,7 +97,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// ```
|
||||
pub(crate) fn suggest_fn_call(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
found: Ty<'tcx>,
|
||||
can_satisfy: impl FnOnce(Ty<'tcx>) -> bool,
|
||||
@ -183,7 +179,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub fn suggest_two_fn_call(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
lhs_expr: &'tcx hir::Expr<'tcx>,
|
||||
lhs_ty: Ty<'tcx>,
|
||||
rhs_expr: &'tcx hir::Expr<'tcx>,
|
||||
@ -257,7 +253,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub fn suggest_remove_last_method_call(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
) -> bool {
|
||||
@ -286,7 +282,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub fn suggest_deref_ref_or_into(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
found: Ty<'tcx>,
|
||||
@ -544,7 +540,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// in the heap by calling `Box::new()`.
|
||||
pub(in super::super) fn suggest_boxing_when_appropriate(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
span: Span,
|
||||
hir_id: HirId,
|
||||
expected: Ty<'tcx>,
|
||||
@ -587,7 +583,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// suggest a non-capturing closure
|
||||
pub(in super::super) fn suggest_no_capture_closure(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expected: Ty<'tcx>,
|
||||
found: Ty<'tcx>,
|
||||
) -> bool {
|
||||
@ -624,7 +620,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
#[instrument(skip(self, err))]
|
||||
pub(in super::super) fn suggest_calling_boxed_future_when_appropriate(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
expected: Ty<'tcx>,
|
||||
found: Ty<'tcx>,
|
||||
@ -736,7 +732,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// block is needed to be added too (`|| { expr; }`). This is denoted by `needs_block`.
|
||||
pub fn suggest_missing_semicolon(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expression: &'tcx hir::Expr<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
needs_block: bool,
|
||||
@ -795,7 +791,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
#[instrument(level = "trace", skip(self, err))]
|
||||
pub(in super::super) fn suggest_missing_return_type(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
fn_decl: &hir::FnDecl<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
found: Ty<'tcx>,
|
||||
@ -913,7 +909,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// ```
|
||||
fn try_suggest_return_impl_trait(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expected: Ty<'tcx>,
|
||||
found: Ty<'tcx>,
|
||||
fn_id: hir::HirId,
|
||||
@ -1018,7 +1014,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub(in super::super) fn suggest_missing_break_or_return_expr(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &'tcx hir::Expr<'tcx>,
|
||||
fn_decl: &hir::FnDecl<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
@ -1117,7 +1113,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub(in super::super) fn suggest_missing_parentheses(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
) -> bool {
|
||||
let sp = self.tcx.sess.source_map().start_point(expr.span).with_parent(None);
|
||||
@ -1135,7 +1131,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// if it was possibly mistaken array syntax.
|
||||
pub(crate) fn suggest_block_to_brackets_peeling_refs(
|
||||
&self,
|
||||
diag: &mut DiagnosticBuilder<'_>,
|
||||
diag: &mut Diag<'_>,
|
||||
mut expr: &hir::Expr<'_>,
|
||||
mut expr_ty: Ty<'tcx>,
|
||||
mut expected_ty: Ty<'tcx>,
|
||||
@ -1162,7 +1158,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub(crate) fn suggest_clone_for_ref(
|
||||
&self,
|
||||
diag: &mut DiagnosticBuilder<'_>,
|
||||
diag: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
expr_ty: Ty<'tcx>,
|
||||
expected_ty: Ty<'tcx>,
|
||||
@ -1197,7 +1193,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub(crate) fn suggest_copied_cloned_or_as_ref(
|
||||
&self,
|
||||
diag: &mut DiagnosticBuilder<'_>,
|
||||
diag: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
expr_ty: Ty<'tcx>,
|
||||
expected_ty: Ty<'tcx>,
|
||||
@ -1247,7 +1243,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub(crate) fn suggest_into(
|
||||
&self,
|
||||
diag: &mut DiagnosticBuilder<'_>,
|
||||
diag: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
expr_ty: Ty<'tcx>,
|
||||
expected_ty: Ty<'tcx>,
|
||||
@ -1310,7 +1306,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// When expecting a `bool` and finding an `Option`, suggests using `let Some(..)` or `.is_some()`
|
||||
pub(crate) fn suggest_option_to_bool(
|
||||
&self,
|
||||
diag: &mut DiagnosticBuilder<'_>,
|
||||
diag: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
expr_ty: Ty<'tcx>,
|
||||
expected_ty: Ty<'tcx>,
|
||||
@ -1367,7 +1363,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// in case the block was mistaken array syntax, e.g. `{ 1 }` -> `[ 1 ]`.
|
||||
pub(crate) fn suggest_block_to_brackets(
|
||||
&self,
|
||||
diag: &mut DiagnosticBuilder<'_>,
|
||||
diag: &mut Diag<'_>,
|
||||
blk: &hir::Block<'_>,
|
||||
blk_ty: Ty<'tcx>,
|
||||
expected_ty: Ty<'tcx>,
|
||||
@ -1407,7 +1403,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
#[instrument(skip(self, err))]
|
||||
pub(crate) fn suggest_floating_point_literal(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
expected_ty: Ty<'tcx>,
|
||||
) -> bool {
|
||||
@ -1478,7 +1474,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
#[instrument(skip(self, err))]
|
||||
pub(crate) fn suggest_null_ptr_for_literal_zero_given_to_ptr_arg(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
expected_ty: Ty<'tcx>,
|
||||
) -> bool {
|
||||
@ -1516,7 +1512,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub(crate) fn suggest_associated_const(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'tcx>,
|
||||
expected_ty: Ty<'tcx>,
|
||||
) -> bool {
|
||||
@ -1610,7 +1606,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// which is a side-effect of autoref.
|
||||
pub(crate) fn note_type_is_not_clone(
|
||||
&self,
|
||||
diag: &mut DiagnosticBuilder<'_>,
|
||||
diag: &mut Diag<'_>,
|
||||
expected_ty: Ty<'tcx>,
|
||||
found_ty: Ty<'tcx>,
|
||||
expr: &hir::Expr<'_>,
|
||||
@ -1810,7 +1806,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
&self,
|
||||
blk: &'tcx hir::Block<'tcx>,
|
||||
expected_ty: Ty<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
) -> bool {
|
||||
if let Some((span_semi, boxed)) = self.err_ctxt().could_remove_semicolon(blk, expected_ty) {
|
||||
if let StatementAsExpression::NeedsBoxing = boxed {
|
||||
@ -1855,7 +1851,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub(crate) fn suggest_missing_unwrap_expect(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
found: Ty<'tcx>,
|
||||
@ -1938,7 +1934,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub(crate) fn suggest_coercing_result_via_try_operator(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
found: Ty<'tcx>,
|
||||
@ -1985,7 +1981,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// sole field is of the found type, suggest such variants. (Issue #42764)
|
||||
pub(crate) fn suggest_compatible_variants(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
expected: Ty<'tcx>,
|
||||
expr_ty: Ty<'tcx>,
|
||||
@ -2174,7 +2170,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub(crate) fn suggest_non_zero_new_unwrap(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
expected: Ty<'tcx>,
|
||||
expr_ty: Ty<'tcx>,
|
||||
@ -2718,7 +2714,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub(crate) fn suggest_cast(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
checked_ty: Ty<'tcx>,
|
||||
expected_ty: Ty<'tcx>,
|
||||
@ -2846,7 +2842,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let in_const_context = self.tcx.hir().is_inside_const_context(expr.hir_id);
|
||||
|
||||
let suggest_fallible_into_or_lhs_from =
|
||||
|err: &mut DiagnosticBuilder<'_>, exp_to_found_is_fallible: bool| {
|
||||
|err: &mut Diag<'_>, exp_to_found_is_fallible: bool| {
|
||||
// If we know the expression the expected type is derived from, we might be able
|
||||
// to suggest a widening conversion rather than a narrowing one (which may
|
||||
// panic). For example, given x: u8 and y: u32, if we know the span of "x",
|
||||
@ -2886,9 +2882,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
};
|
||||
|
||||
let suggest_to_change_suffix_or_into =
|
||||
|err: &mut DiagnosticBuilder<'_>,
|
||||
found_to_exp_is_fallible: bool,
|
||||
exp_to_found_is_fallible: bool| {
|
||||
|err: &mut Diag<'_>, found_to_exp_is_fallible: bool, exp_to_found_is_fallible: bool| {
|
||||
let exp_is_lhs = expected_ty_expr.is_some_and(|e| self.tcx.hir().is_lhs(e.hir_id));
|
||||
|
||||
if exp_is_lhs {
|
||||
@ -3084,7 +3078,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// Identify when the user has written `foo..bar()` instead of `foo.bar()`.
|
||||
pub(crate) fn suggest_method_call_on_range_literal(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'tcx>,
|
||||
checked_ty: Ty<'tcx>,
|
||||
expected_ty: Ty<'tcx>,
|
||||
@ -3162,7 +3156,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// block without a tail expression.
|
||||
pub(crate) fn suggest_return_binding_for_missing_tail_expr(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
checked_ty: Ty<'tcx>,
|
||||
expected_ty: Ty<'tcx>,
|
||||
|
@ -11,7 +11,7 @@ pub use self::suggest::SelfSource;
|
||||
pub use self::MethodError::*;
|
||||
|
||||
use crate::FnCtxt;
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder, SubdiagnosticMessage};
|
||||
use rustc_errors::{Applicability, Diag, SubdiagnosticMessage};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorOf, DefKind, Namespace};
|
||||
use rustc_hir::def_id::DefId;
|
||||
@ -126,7 +126,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
#[instrument(level = "debug", skip(self, err, call_expr))]
|
||||
pub(crate) fn suggest_method_call(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
msg: impl Into<SubdiagnosticMessage> + std::fmt::Debug,
|
||||
method_name: Ident,
|
||||
self_ty: Ty<'tcx>,
|
||||
|
@ -12,8 +12,7 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::sorted_map::SortedMap;
|
||||
use rustc_data_structures::unord::UnordSet;
|
||||
use rustc_errors::{
|
||||
codes::*, pluralize, struct_span_code_err, Applicability, DiagnosticBuilder, MultiSpan,
|
||||
StashKey,
|
||||
codes::*, pluralize, struct_span_code_err, Applicability, Diag, MultiSpan, StashKey,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
@ -208,7 +207,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
args: Option<&'tcx [hir::Expr<'tcx>]>,
|
||||
expected: Expectation<'tcx>,
|
||||
trait_missing_method: bool,
|
||||
) -> Option<DiagnosticBuilder<'_>> {
|
||||
) -> Option<Diag<'_>> {
|
||||
// Avoid suggestions when we don't know what's going on.
|
||||
if rcvr_ty.references_error() {
|
||||
return None;
|
||||
@ -344,11 +343,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
None
|
||||
}
|
||||
|
||||
fn suggest_missing_writer(
|
||||
&self,
|
||||
rcvr_ty: Ty<'tcx>,
|
||||
rcvr_expr: &hir::Expr<'tcx>,
|
||||
) -> DiagnosticBuilder<'_> {
|
||||
fn suggest_missing_writer(&self, rcvr_ty: Ty<'tcx>, rcvr_expr: &hir::Expr<'tcx>) -> Diag<'_> {
|
||||
let mut file = None;
|
||||
let ty_str = self.tcx.short_ty_string(rcvr_ty, &mut file);
|
||||
let mut err = struct_span_code_err!(
|
||||
@ -387,7 +382,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
no_match_data: &mut NoMatchData<'tcx>,
|
||||
expected: Expectation<'tcx>,
|
||||
trait_missing_method: bool,
|
||||
) -> Option<DiagnosticBuilder<'_>> {
|
||||
) -> Option<Diag<'_>> {
|
||||
let mode = no_match_data.mode;
|
||||
let tcx = self.tcx;
|
||||
let rcvr_ty = self.resolve_vars_if_possible(rcvr_ty);
|
||||
@ -1130,7 +1125,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
let label_span_not_found = |err: &mut DiagnosticBuilder<'_>| {
|
||||
let label_span_not_found = |err: &mut Diag<'_>| {
|
||||
if unsatisfied_predicates.is_empty() {
|
||||
err.span_label(span, format!("{item_kind} not found in `{ty_str}`"));
|
||||
let is_string_or_ref_str = match rcvr_ty.kind() {
|
||||
@ -1414,7 +1409,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn find_likely_intended_associated_item(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
similar_candidate: ty::AssocItem,
|
||||
span: Span,
|
||||
args: Option<&'tcx [hir::Expr<'tcx>]>,
|
||||
@ -1492,7 +1487,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub(crate) fn confusable_method_name(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
rcvr_ty: Ty<'tcx>,
|
||||
item_name: Ident,
|
||||
call_args: Option<Vec<Ty<'tcx>>>,
|
||||
@ -1559,7 +1554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
self_source: SelfSource<'tcx>,
|
||||
args: Option<&'tcx [hir::Expr<'tcx>]>,
|
||||
span: Span,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
sources: &mut Vec<CandidateSource>,
|
||||
sugg_span: Option<Span>,
|
||||
) {
|
||||
@ -1705,7 +1700,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
/// Look at all the associated functions without receivers in the type's inherent impls
|
||||
/// to look for builders that return `Self`, `Option<Self>` or `Result<Self, _>`.
|
||||
fn find_builder_fn(&self, err: &mut DiagnosticBuilder<'_>, rcvr_ty: Ty<'tcx>) {
|
||||
fn find_builder_fn(&self, err: &mut Diag<'_>, rcvr_ty: Ty<'tcx>) {
|
||||
let ty::Adt(adt_def, _) = rcvr_ty.kind() else {
|
||||
return;
|
||||
};
|
||||
@ -1790,7 +1785,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// doesn't take a `self` receiver.
|
||||
fn suggest_associated_call_syntax(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
static_candidates: &Vec<CandidateSource>,
|
||||
rcvr_ty: Ty<'tcx>,
|
||||
source: SelfSource<'tcx>,
|
||||
@ -1934,7 +1929,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
rcvr_ty: Ty<'tcx>,
|
||||
expr: &hir::Expr<'_>,
|
||||
item_name: Ident,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
) -> bool {
|
||||
let tcx = self.tcx;
|
||||
let field_receiver = self.autoderef(span, rcvr_ty).find_map(|(ty, _)| match ty.kind() {
|
||||
@ -2257,7 +2252,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// Suggest calling a method on a field i.e. `a.field.bar()` instead of `a.bar()`
|
||||
fn suggest_calling_method_on_field(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
source: SelfSource<'tcx>,
|
||||
span: Span,
|
||||
actual: Ty<'tcx>,
|
||||
@ -2337,7 +2332,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn suggest_unwrapping_inner_self(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
source: SelfSource<'tcx>,
|
||||
actual: Ty<'tcx>,
|
||||
item_name: Ident,
|
||||
@ -2526,7 +2521,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub(crate) fn note_unmet_impls_on_type(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
errors: Vec<FulfillmentError<'tcx>>,
|
||||
suggest_derive: bool,
|
||||
) {
|
||||
@ -2609,7 +2604,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn note_predicate_source_and_get_derives(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
unsatisfied_predicates: &[(
|
||||
ty::Predicate<'tcx>,
|
||||
Option<ty::Predicate<'tcx>>,
|
||||
@ -2691,7 +2686,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
pub(crate) fn suggest_derive(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
unsatisfied_predicates: &[(
|
||||
ty::Predicate<'tcx>,
|
||||
Option<ty::Predicate<'tcx>>,
|
||||
@ -2727,7 +2722,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn note_derefed_ty_has_method(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
self_source: SelfSource<'tcx>,
|
||||
rcvr_ty: Ty<'tcx>,
|
||||
item_name: Ident,
|
||||
@ -2807,7 +2802,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn suggest_await_before_method(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
item_name: Ident,
|
||||
ty: Ty<'tcx>,
|
||||
call: &hir::Expr<'_>,
|
||||
@ -2830,12 +2825,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn suggest_use_candidates(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
msg: String,
|
||||
candidates: Vec<DefId>,
|
||||
) {
|
||||
fn suggest_use_candidates(&self, err: &mut Diag<'_>, msg: String, candidates: Vec<DefId>) {
|
||||
let parent_map = self.tcx.visible_parent_map(());
|
||||
|
||||
// Separate out candidates that must be imported with a glob, because they are named `_`
|
||||
@ -2882,7 +2872,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn suggest_valid_traits(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
item_name: Ident,
|
||||
valid_out_of_scope_traits: Vec<DefId>,
|
||||
explain: bool,
|
||||
@ -2931,7 +2921,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn suggest_traits_to_import(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
span: Span,
|
||||
rcvr_ty: Ty<'tcx>,
|
||||
item_name: Ident,
|
||||
@ -3475,7 +3465,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// FIXME: currently not working for suggesting `map_or_else`, see #102408
|
||||
pub(crate) fn suggest_else_fn_with_closure(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
found: Ty<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
@ -3601,7 +3591,7 @@ pub fn all_traits(tcx: TyCtxt<'_>) -> Vec<TraitInfo> {
|
||||
|
||||
fn print_disambiguation_help<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
source: SelfSource<'tcx>,
|
||||
args: Option<&'tcx [hir::Expr<'tcx>]>,
|
||||
trait_ref: ty::TraitRef<'tcx>,
|
||||
|
@ -5,7 +5,7 @@ use super::FnCtxt;
|
||||
use crate::Expectation;
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::packed::Pu128;
|
||||
use rustc_errors::{codes::*, struct_span_code_err, Applicability, DiagnosticBuilder};
|
||||
use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag};
|
||||
use rustc_hir as hir;
|
||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
use rustc_infer::traits::ObligationCauseCode;
|
||||
@ -390,37 +390,36 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
err.downgrade_to_delayed_bug();
|
||||
}
|
||||
|
||||
let suggest_deref_binop =
|
||||
|err: &mut DiagnosticBuilder<'_, _>, lhs_deref_ty: Ty<'tcx>| {
|
||||
if self
|
||||
.lookup_op_method(
|
||||
(lhs_expr, lhs_deref_ty),
|
||||
Some((rhs_expr, rhs_ty)),
|
||||
Op::Binary(op, is_assign),
|
||||
expected,
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
let msg = format!(
|
||||
"`{}{}` can be used on `{}` if you dereference the left-hand side",
|
||||
op.node.as_str(),
|
||||
match is_assign {
|
||||
IsAssign::Yes => "=",
|
||||
IsAssign::No => "",
|
||||
},
|
||||
lhs_deref_ty,
|
||||
);
|
||||
err.span_suggestion_verbose(
|
||||
lhs_expr.span.shrink_to_lo(),
|
||||
msg,
|
||||
"*",
|
||||
rustc_errors::Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
};
|
||||
let suggest_deref_binop = |err: &mut Diag<'_, _>, lhs_deref_ty: Ty<'tcx>| {
|
||||
if self
|
||||
.lookup_op_method(
|
||||
(lhs_expr, lhs_deref_ty),
|
||||
Some((rhs_expr, rhs_ty)),
|
||||
Op::Binary(op, is_assign),
|
||||
expected,
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
let msg = format!(
|
||||
"`{}{}` can be used on `{}` if you dereference the left-hand side",
|
||||
op.node.as_str(),
|
||||
match is_assign {
|
||||
IsAssign::Yes => "=",
|
||||
IsAssign::No => "",
|
||||
},
|
||||
lhs_deref_ty,
|
||||
);
|
||||
err.span_suggestion_verbose(
|
||||
lhs_expr.span.shrink_to_lo(),
|
||||
msg,
|
||||
"*",
|
||||
rustc_errors::Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
let suggest_different_borrow =
|
||||
|err: &mut DiagnosticBuilder<'_, _>,
|
||||
|err: &mut Diag<'_, _>,
|
||||
lhs_adjusted_ty,
|
||||
lhs_new_mutbl: Option<ast::Mutability>,
|
||||
rhs_adjusted_ty,
|
||||
@ -695,7 +694,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
rhs_expr: &'tcx hir::Expr<'tcx>,
|
||||
lhs_ty: Ty<'tcx>,
|
||||
rhs_ty: Ty<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
is_assign: IsAssign,
|
||||
op: hir::BinOp,
|
||||
) -> bool {
|
||||
|
@ -3,8 +3,7 @@ use crate::{errors, FnCtxt, LoweredTy};
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::{
|
||||
codes::*, pluralize, struct_span_code_err, Applicability, DiagnosticBuilder, ErrorGuaranteed,
|
||||
MultiSpan,
|
||||
codes::*, pluralize, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, MultiSpan,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorKind, DefKind, Res};
|
||||
@ -99,7 +98,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
|
||||
expected: Ty<'tcx>,
|
||||
actual: Ty<'tcx>,
|
||||
ti: TopInfo<'tcx>,
|
||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
) -> Option<Diag<'tcx>> {
|
||||
let mut diag =
|
||||
self.demand_eqtype_with_origin(&self.pattern_cause(ti, cause_span), expected, actual)?;
|
||||
if let Some(expr) = ti.origin_expr {
|
||||
@ -529,7 +528,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
ty
|
||||
}
|
||||
|
||||
fn endpoint_has_type(&self, err: &mut DiagnosticBuilder<'_>, span: Span, ty: Ty<'_>) {
|
||||
fn endpoint_has_type(&self, err: &mut Diag<'_>, span: Span, ty: Ty<'_>) {
|
||||
if !ty.references_error() {
|
||||
err.span_label(span, format!("this is of type `{ty}`"));
|
||||
}
|
||||
@ -683,7 +682,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn suggest_adding_missing_ref_or_removing_ref(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
span: Span,
|
||||
expected: Ty<'tcx>,
|
||||
actual: Ty<'tcx>,
|
||||
@ -715,7 +714,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
|
||||
// Precondition: pat is a Ref(_) pattern
|
||||
fn borrow_pat_suggestion(&self, err: &mut DiagnosticBuilder<'_>, pat: &Pat<'_>) {
|
||||
fn borrow_pat_suggestion(&self, err: &mut Diag<'_>, pat: &Pat<'_>) {
|
||||
let tcx = self.tcx;
|
||||
if let PatKind::Ref(inner, mutbl) = pat.kind
|
||||
&& let PatKind::Binding(_, _, binding, ..) = inner.kind
|
||||
@ -933,7 +932,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn maybe_suggest_range_literal(
|
||||
&self,
|
||||
e: &mut DiagnosticBuilder<'_>,
|
||||
e: &mut Diag<'_>,
|
||||
opt_def_id: Option<hir::def_id::DefId>,
|
||||
ident: Ident,
|
||||
) -> bool {
|
||||
@ -968,7 +967,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
fn emit_bad_pat_path(
|
||||
&self,
|
||||
mut e: DiagnosticBuilder<'_>,
|
||||
mut e: Diag<'_>,
|
||||
pat: &hir::Pat<'tcx>,
|
||||
res: Res,
|
||||
pat_res: Res,
|
||||
@ -1505,7 +1504,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
variant: &VariantDef,
|
||||
pat: &'_ Pat<'_>,
|
||||
fields: &[hir::PatField<'_>],
|
||||
) -> Option<DiagnosticBuilder<'_>> {
|
||||
) -> Option<Diag<'_>> {
|
||||
// if this is a tuple struct, then all field names will be numbers
|
||||
// so if any fields in a struct pattern use shorthand syntax, they will
|
||||
// be invalid identifiers (for example, Foo { 0, 1 }).
|
||||
@ -1581,7 +1580,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
pat: &'tcx Pat<'tcx>,
|
||||
variant: &ty::VariantDef,
|
||||
args: &'tcx ty::List<ty::GenericArg<'tcx>>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let tcx = self.tcx;
|
||||
let (field_names, t, plural) = if let [field] = inexistent_fields {
|
||||
(format!("a field named `{}`", field.ident), "this", "")
|
||||
@ -1686,7 +1685,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
pat: &Pat<'_>,
|
||||
fields: &'tcx [hir::PatField<'tcx>],
|
||||
variant: &ty::VariantDef,
|
||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
) -> Option<Diag<'tcx>> {
|
||||
if let (Some(CtorKind::Fn), PatKind::Struct(qpath, pattern_fields, ..)) =
|
||||
(variant.ctor_kind(), &pat.kind)
|
||||
{
|
||||
@ -1772,7 +1771,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
&self,
|
||||
pat: &Pat<'_>,
|
||||
fields: &'tcx [hir::PatField<'tcx>],
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let mut err = self
|
||||
.dcx()
|
||||
.struct_span_err(pat.span, "pattern requires `..` due to inaccessible fields");
|
||||
@ -1863,7 +1862,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
unmentioned_fields: &[(&ty::FieldDef, Ident)],
|
||||
have_inaccessible_fields: bool,
|
||||
fields: &'tcx [hir::PatField<'tcx>],
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let inaccessible = if have_inaccessible_fields { " and inaccessible fields" } else { "" };
|
||||
let field_names = if let [(_, field)] = unmentioned_fields {
|
||||
format!("field `{field}`{inaccessible}")
|
||||
|
@ -1,8 +1,7 @@
|
||||
use hir::GenericParamKind;
|
||||
use rustc_errors::{
|
||||
codes::*, AddToDiagnostic, Applicability, DiagnosticBuilder, DiagnosticMessage,
|
||||
DiagnosticStyledString, EmissionGuarantee, IntoDiagnosticArg, MultiSpan,
|
||||
SubdiagnosticMessageOp,
|
||||
codes::*, AddToDiagnostic, Applicability, Diag, DiagStyledString, DiagnosticMessage,
|
||||
EmissionGuarantee, IntoDiagnosticArg, MultiSpan, SubdiagnosticMessageOp,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::FnRetTy;
|
||||
@ -221,14 +220,14 @@ pub enum RegionOriginNote<'a> {
|
||||
WithRequirement {
|
||||
span: Span,
|
||||
requirement: ObligationCauseAsDiagArg<'a>,
|
||||
expected_found: Option<(DiagnosticStyledString, DiagnosticStyledString)>,
|
||||
expected_found: Option<(DiagStyledString, DiagStyledString)>,
|
||||
},
|
||||
}
|
||||
|
||||
impl AddToDiagnostic for RegionOriginNote<'_> {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
_f: F,
|
||||
) {
|
||||
let mut label_or_note = |span, msg: DiagnosticMessage| {
|
||||
@ -293,7 +292,7 @@ pub enum LifetimeMismatchLabels {
|
||||
impl AddToDiagnostic for LifetimeMismatchLabels {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
_f: F,
|
||||
) {
|
||||
match self {
|
||||
@ -341,7 +340,7 @@ pub struct AddLifetimeParamsSuggestion<'a> {
|
||||
impl AddToDiagnostic for AddLifetimeParamsSuggestion<'_> {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
_f: F,
|
||||
) {
|
||||
let mut mk_suggestion = || {
|
||||
@ -443,7 +442,7 @@ pub struct IntroducesStaticBecauseUnmetLifetimeReq {
|
||||
impl AddToDiagnostic for IntroducesStaticBecauseUnmetLifetimeReq {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
mut self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
_f: F,
|
||||
) {
|
||||
self.unmet_requirements
|
||||
@ -539,7 +538,7 @@ pub enum TyOrSig<'tcx> {
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for TyOrSig<'_> {
|
||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue {
|
||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue {
|
||||
match self {
|
||||
TyOrSig::Ty(ty) => ty.into_diagnostic_arg(),
|
||||
TyOrSig::ClosureSig(sig) => sig.into_diagnostic_arg(),
|
||||
@ -762,7 +761,7 @@ pub struct ConsiderBorrowingParamHelp {
|
||||
impl AddToDiagnostic for ConsiderBorrowingParamHelp {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
f: F,
|
||||
) {
|
||||
let mut type_param_span: MultiSpan = self.spans.clone().into();
|
||||
@ -807,7 +806,7 @@ pub struct DynTraitConstraintSuggestion {
|
||||
impl AddToDiagnostic for DynTraitConstraintSuggestion {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
f: F,
|
||||
) {
|
||||
let mut multi_span: MultiSpan = vec![self.span].into();
|
||||
@ -854,7 +853,7 @@ pub struct ReqIntroducedLocations {
|
||||
impl AddToDiagnostic for ReqIntroducedLocations {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
mut self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
f: F,
|
||||
) {
|
||||
for sp in self.spans {
|
||||
@ -877,7 +876,7 @@ pub struct MoreTargeted {
|
||||
impl AddToDiagnostic for MoreTargeted {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
_f: F,
|
||||
) {
|
||||
diag.code(E0772);
|
||||
@ -1300,7 +1299,7 @@ pub struct SuggestTuplePatternMany {
|
||||
impl AddToDiagnostic for SuggestTuplePatternMany {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
f: F,
|
||||
) {
|
||||
diag.arg("path", self.path);
|
||||
|
@ -1,8 +1,7 @@
|
||||
use crate::fluent_generated as fluent;
|
||||
use crate::infer::error_reporting::nice_region_error::find_anon_type;
|
||||
use rustc_errors::{
|
||||
AddToDiagnostic, DiagnosticBuilder, EmissionGuarantee, IntoDiagnosticArg,
|
||||
SubdiagnosticMessageOp,
|
||||
AddToDiagnostic, Diag, EmissionGuarantee, IntoDiagnosticArg, SubdiagnosticMessageOp,
|
||||
};
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_span::{symbol::kw, Span};
|
||||
@ -111,7 +110,7 @@ pub enum SuffixKind {
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for PrefixKind {
|
||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue {
|
||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue {
|
||||
let kind = match self {
|
||||
Self::Empty => "empty",
|
||||
Self::RefValidFor => "ref_valid_for",
|
||||
@ -128,19 +127,19 @@ impl IntoDiagnosticArg for PrefixKind {
|
||||
Self::DataValidFor => "data_valid_for",
|
||||
}
|
||||
.into();
|
||||
rustc_errors::DiagnosticArgValue::Str(kind)
|
||||
rustc_errors::DiagArgValue::Str(kind)
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for SuffixKind {
|
||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue {
|
||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue {
|
||||
let kind = match self {
|
||||
Self::Empty => "empty",
|
||||
Self::Continues => "continues",
|
||||
Self::ReqByBinding => "req_by_binding",
|
||||
}
|
||||
.into();
|
||||
rustc_errors::DiagnosticArgValue::Str(kind)
|
||||
rustc_errors::DiagArgValue::Str(kind)
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,7 +164,7 @@ impl RegionExplanation<'_> {
|
||||
impl AddToDiagnostic for RegionExplanation<'_> {
|
||||
fn add_to_diagnostic_with<G: EmissionGuarantee, F: SubdiagnosticMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut DiagnosticBuilder<'_, G>,
|
||||
diag: &mut Diag<'_, G>,
|
||||
f: F,
|
||||
) {
|
||||
diag.arg("pref_kind", self.prefix);
|
||||
|
@ -60,8 +60,8 @@ use crate::traits::{
|
||||
|
||||
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||
use rustc_errors::{
|
||||
codes::*, pluralize, struct_span_code_err, Applicability, DiagCtxt, DiagnosticBuilder,
|
||||
DiagnosticStyledString, ErrorGuaranteed, IntoDiagnosticArg,
|
||||
codes::*, pluralize, struct_span_code_err, Applicability, Diag, DiagCtxt, DiagStyledString,
|
||||
ErrorGuaranteed, IntoDiagnosticArg,
|
||||
};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
@ -158,7 +158,7 @@ impl<'tcx> Deref for TypeErrCtxt<'_, 'tcx> {
|
||||
|
||||
pub(super) fn note_and_explain_region<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
prefix: &str,
|
||||
region: ty::Region<'tcx>,
|
||||
suffix: &str,
|
||||
@ -183,7 +183,7 @@ pub(super) fn note_and_explain_region<'tcx>(
|
||||
|
||||
fn explain_free_region<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
prefix: &str,
|
||||
region: ty::Region<'tcx>,
|
||||
suffix: &str,
|
||||
@ -265,7 +265,7 @@ fn msg_span_from_named_region<'tcx>(
|
||||
}
|
||||
|
||||
fn emit_msg_span(
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
prefix: &str,
|
||||
description: String,
|
||||
span: Option<Span>,
|
||||
@ -281,7 +281,7 @@ fn emit_msg_span(
|
||||
}
|
||||
|
||||
fn label_msg_span(
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
prefix: &str,
|
||||
description: String,
|
||||
span: Option<Span>,
|
||||
@ -303,7 +303,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
|
||||
hidden_ty: Ty<'tcx>,
|
||||
hidden_region: ty::Region<'tcx>,
|
||||
opaque_ty_key: ty::OpaqueTypeKey<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let mut err = tcx.dcx().create_err(errors::OpaqueCapturesLifetime {
|
||||
span,
|
||||
opaque_ty: Ty::new_opaque(tcx, opaque_ty_key.def_id.to_def_id(), opaque_ty_key.args),
|
||||
@ -428,6 +428,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
generic_param_scope: LocalDefId,
|
||||
errors: &[RegionResolutionError<'tcx>],
|
||||
) -> ErrorGuaranteed {
|
||||
assert!(!errors.is_empty());
|
||||
|
||||
if let Some(guaranteed) = self.infcx.tainted_by_errors() {
|
||||
return guaranteed;
|
||||
}
|
||||
@ -440,10 +442,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
|
||||
debug!("report_region_errors: {} errors after preprocessing", errors.len());
|
||||
|
||||
let mut guar = None;
|
||||
for error in errors {
|
||||
debug!("report_region_errors: error = {:?}", error);
|
||||
|
||||
if !self.try_report_nice_region_error(&error) {
|
||||
guar = Some(if let Some(guar) = self.try_report_nice_region_error(&error) {
|
||||
guar
|
||||
} else {
|
||||
match error.clone() {
|
||||
// These errors could indicate all manner of different
|
||||
// problems with many different solutions. Rather
|
||||
@ -454,21 +459,20 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
// general bit of code that displays the error information
|
||||
RegionResolutionError::ConcreteFailure(origin, sub, sup) => {
|
||||
if sub.is_placeholder() || sup.is_placeholder() {
|
||||
self.report_placeholder_failure(origin, sub, sup).emit();
|
||||
self.report_placeholder_failure(origin, sub, sup).emit()
|
||||
} else {
|
||||
self.report_concrete_failure(origin, sub, sup).emit();
|
||||
self.report_concrete_failure(origin, sub, sup).emit()
|
||||
}
|
||||
}
|
||||
|
||||
RegionResolutionError::GenericBoundFailure(origin, param_ty, sub) => {
|
||||
self.report_generic_bound_failure(
|
||||
RegionResolutionError::GenericBoundFailure(origin, param_ty, sub) => self
|
||||
.report_generic_bound_failure(
|
||||
generic_param_scope,
|
||||
origin.span(),
|
||||
Some(origin),
|
||||
param_ty,
|
||||
sub,
|
||||
);
|
||||
}
|
||||
),
|
||||
|
||||
RegionResolutionError::SubSupConflict(
|
||||
_,
|
||||
@ -480,13 +484,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
_,
|
||||
) => {
|
||||
if sub_r.is_placeholder() {
|
||||
self.report_placeholder_failure(sub_origin, sub_r, sup_r).emit();
|
||||
self.report_placeholder_failure(sub_origin, sub_r, sup_r).emit()
|
||||
} else if sup_r.is_placeholder() {
|
||||
self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit();
|
||||
self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit()
|
||||
} else {
|
||||
self.report_sub_sup_conflict(
|
||||
var_origin, sub_origin, sub_r, sup_origin, sup_r,
|
||||
);
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -506,7 +510,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
// value.
|
||||
let sub_r = self.tcx.lifetimes.re_erased;
|
||||
|
||||
self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit();
|
||||
self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit()
|
||||
}
|
||||
|
||||
RegionResolutionError::CannotNormalize(clause, origin) => {
|
||||
@ -515,15 +519,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
self.tcx
|
||||
.dcx()
|
||||
.struct_span_err(origin.span(), format!("cannot normalize `{clause}`"))
|
||||
.emit();
|
||||
.emit()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
self.tcx
|
||||
.dcx()
|
||||
.span_delayed_bug(self.tcx.def_span(generic_param_scope), "expected region errors")
|
||||
guar.unwrap()
|
||||
}
|
||||
|
||||
// This method goes through all the errors and try to group certain types
|
||||
@ -580,11 +582,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
}
|
||||
|
||||
/// Adds a note if the types come from similarly named crates
|
||||
fn check_and_note_conflicting_crates(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
terr: TypeError<'tcx>,
|
||||
) {
|
||||
fn check_and_note_conflicting_crates(&self, err: &mut Diag<'_>, terr: TypeError<'tcx>) {
|
||||
use hir::def_id::CrateNum;
|
||||
use rustc_hir::definitions::DisambiguatedDefPathData;
|
||||
use ty::print::Printer;
|
||||
@ -658,7 +656,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
let report_path_match = |err: &mut DiagnosticBuilder<'_>, did1: DefId, did2: DefId| {
|
||||
let report_path_match = |err: &mut Diag<'_>, did1: DefId, did2: DefId| {
|
||||
// Only report definitions from different crates. If both definitions
|
||||
// are from a local module we could have false positives, e.g.
|
||||
// let _ = [{struct Foo; Foo}, {struct Foo; Foo}];
|
||||
@ -708,7 +706,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
|
||||
fn note_error_origin(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
cause: &ObligationCause<'tcx>,
|
||||
exp_found: Option<ty::error::ExpectedFound<Ty<'tcx>>>,
|
||||
terr: TypeError<'tcx>,
|
||||
@ -947,8 +945,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
/// ```
|
||||
fn highlight_outer(
|
||||
&self,
|
||||
value: &mut DiagnosticStyledString,
|
||||
other_value: &mut DiagnosticStyledString,
|
||||
value: &mut DiagStyledString,
|
||||
other_value: &mut DiagStyledString,
|
||||
name: String,
|
||||
sub: ty::GenericArgsRef<'tcx>,
|
||||
pos: usize,
|
||||
@ -1021,8 +1019,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
/// ```
|
||||
fn cmp_type_arg(
|
||||
&self,
|
||||
t1_out: &mut DiagnosticStyledString,
|
||||
t2_out: &mut DiagnosticStyledString,
|
||||
t1_out: &mut DiagStyledString,
|
||||
t2_out: &mut DiagStyledString,
|
||||
path: String,
|
||||
sub: &'tcx [ty::GenericArg<'tcx>],
|
||||
other_path: String,
|
||||
@ -1050,8 +1048,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
/// Adds a `,` to the type representation only if it is appropriate.
|
||||
fn push_comma(
|
||||
&self,
|
||||
value: &mut DiagnosticStyledString,
|
||||
other_value: &mut DiagnosticStyledString,
|
||||
value: &mut DiagStyledString,
|
||||
other_value: &mut DiagStyledString,
|
||||
len: usize,
|
||||
pos: usize,
|
||||
) {
|
||||
@ -1066,7 +1064,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
&self,
|
||||
sig1: &ty::PolyFnSig<'tcx>,
|
||||
sig2: &ty::PolyFnSig<'tcx>,
|
||||
) -> (DiagnosticStyledString, DiagnosticStyledString) {
|
||||
) -> (DiagStyledString, DiagStyledString) {
|
||||
let sig1 = &(self.normalize_fn_sig)(*sig1);
|
||||
let sig2 = &(self.normalize_fn_sig)(*sig2);
|
||||
|
||||
@ -1083,10 +1081,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
let (lt2, sig2) = get_lifetimes(sig2);
|
||||
|
||||
// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
|
||||
let mut values = (
|
||||
DiagnosticStyledString::normal("".to_string()),
|
||||
DiagnosticStyledString::normal("".to_string()),
|
||||
);
|
||||
let mut values =
|
||||
(DiagStyledString::normal("".to_string()), DiagStyledString::normal("".to_string()));
|
||||
|
||||
// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
|
||||
// ^^^^^^
|
||||
@ -1175,15 +1171,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
|
||||
/// Compares two given types, eliding parts that are the same between them and highlighting
|
||||
/// relevant differences, and return two representation of those types for highlighted printing.
|
||||
pub fn cmp(
|
||||
&self,
|
||||
t1: Ty<'tcx>,
|
||||
t2: Ty<'tcx>,
|
||||
) -> (DiagnosticStyledString, DiagnosticStyledString) {
|
||||
pub fn cmp(&self, t1: Ty<'tcx>, t2: Ty<'tcx>) -> (DiagStyledString, DiagStyledString) {
|
||||
debug!("cmp(t1={}, t1.kind={:?}, t2={}, t2.kind={:?})", t1, t1.kind(), t2, t2.kind());
|
||||
|
||||
// helper functions
|
||||
let recurse = |t1, t2, values: &mut (DiagnosticStyledString, DiagnosticStyledString)| {
|
||||
let recurse = |t1, t2, values: &mut (DiagStyledString, DiagStyledString)| {
|
||||
let (x1, x2) = self.cmp(t1, t2);
|
||||
(values.0).0.extend(x1.0);
|
||||
(values.1).0.extend(x2.0);
|
||||
@ -1202,7 +1194,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
fn push_ref<'tcx>(
|
||||
region: ty::Region<'tcx>,
|
||||
mutbl: hir::Mutability,
|
||||
s: &mut DiagnosticStyledString,
|
||||
s: &mut DiagStyledString,
|
||||
) {
|
||||
s.push_highlighted(fmt_region(region));
|
||||
s.push_highlighted(mutbl.prefix_str());
|
||||
@ -1211,7 +1203,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
fn maybe_highlight<T: Eq + ToString>(
|
||||
t1: T,
|
||||
t2: T,
|
||||
(buf1, buf2): &mut (DiagnosticStyledString, DiagnosticStyledString),
|
||||
(buf1, buf2): &mut (DiagStyledString, DiagStyledString),
|
||||
tcx: TyCtxt<'_>,
|
||||
) {
|
||||
let highlight = t1 != t2;
|
||||
@ -1230,7 +1222,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
mut1: hir::Mutability,
|
||||
r2: ty::Region<'tcx>,
|
||||
mut2: hir::Mutability,
|
||||
ss: &mut (DiagnosticStyledString, DiagnosticStyledString),
|
||||
ss: &mut (DiagStyledString, DiagStyledString),
|
||||
) {
|
||||
let (r1, r2) = (fmt_region(r1), fmt_region(r2));
|
||||
if r1 != r2 {
|
||||
@ -1259,7 +1251,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
self.tcx.generics_of(did1).own_args_no_defaults(self.tcx, sub1);
|
||||
let sub_no_defaults_2 =
|
||||
self.tcx.generics_of(did2).own_args_no_defaults(self.tcx, sub2);
|
||||
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
|
||||
let mut values = (DiagStyledString::new(), DiagStyledString::new());
|
||||
let path1 = self.tcx.def_path_str(did1);
|
||||
let path2 = self.tcx.def_path_str(did2);
|
||||
if did1 == did2 {
|
||||
@ -1428,8 +1420,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
if split_idx >= min_len {
|
||||
// paths are identical, highlight everything
|
||||
(
|
||||
DiagnosticStyledString::highlighted(t1_str),
|
||||
DiagnosticStyledString::highlighted(t2_str),
|
||||
DiagStyledString::highlighted(t1_str),
|
||||
DiagStyledString::highlighted(t2_str),
|
||||
)
|
||||
} else {
|
||||
let (common, uniq1) = t1_str.split_at(split_idx);
|
||||
@ -1448,20 +1440,20 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
|
||||
// When finding `&T != &T`, compare the references, then recurse into pointee type
|
||||
(&ty::Ref(r1, ref_ty1, mutbl1), &ty::Ref(r2, ref_ty2, mutbl2)) => {
|
||||
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
|
||||
let mut values = (DiagStyledString::new(), DiagStyledString::new());
|
||||
cmp_ty_refs(r1, mutbl1, r2, mutbl2, &mut values);
|
||||
recurse(ref_ty1, ref_ty2, &mut values);
|
||||
values
|
||||
}
|
||||
// When finding T != &T, highlight the borrow
|
||||
(&ty::Ref(r1, ref_ty1, mutbl1), _) => {
|
||||
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
|
||||
let mut values = (DiagStyledString::new(), DiagStyledString::new());
|
||||
push_ref(r1, mutbl1, &mut values.0);
|
||||
recurse(ref_ty1, t2, &mut values);
|
||||
values
|
||||
}
|
||||
(_, &ty::Ref(r2, ref_ty2, mutbl2)) => {
|
||||
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
|
||||
let mut values = (DiagStyledString::new(), DiagStyledString::new());
|
||||
push_ref(r2, mutbl2, &mut values.1);
|
||||
recurse(t1, ref_ty2, &mut values);
|
||||
values
|
||||
@ -1469,8 +1461,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
|
||||
// When encountering tuples of the same size, highlight only the differing types
|
||||
(&ty::Tuple(args1), &ty::Tuple(args2)) if args1.len() == args2.len() => {
|
||||
let mut values =
|
||||
(DiagnosticStyledString::normal("("), DiagnosticStyledString::normal("("));
|
||||
let mut values = (DiagStyledString::normal("("), DiagStyledString::normal("("));
|
||||
let len = args1.len();
|
||||
for (i, (left, right)) in args1.iter().zip(args2).enumerate() {
|
||||
recurse(left, right, &mut values);
|
||||
@ -1520,7 +1511,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
(ty::FnPtr(sig1), ty::FnPtr(sig2)) => self.cmp_fn_sig(sig1, sig2),
|
||||
|
||||
_ => {
|
||||
let mut strs = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
|
||||
let mut strs = (DiagStyledString::new(), DiagStyledString::new());
|
||||
maybe_highlight(t1, t2, &mut strs, self.tcx);
|
||||
strs
|
||||
}
|
||||
@ -1542,7 +1533,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
)]
|
||||
pub fn note_type_err(
|
||||
&self,
|
||||
diag: &mut DiagnosticBuilder<'_>,
|
||||
diag: &mut Diag<'_>,
|
||||
cause: &ObligationCause<'tcx>,
|
||||
secondary_span: Option<(Span, Cow<'static, str>)>,
|
||||
mut values: Option<ValuePairs<'tcx>>,
|
||||
@ -1589,14 +1580,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
types_visitor
|
||||
}
|
||||
|
||||
fn report(&self, err: &mut DiagnosticBuilder<'_>) {
|
||||
fn report(&self, err: &mut Diag<'_>) {
|
||||
self.add_labels_for_types(err, "expected", &self.expected);
|
||||
self.add_labels_for_types(err, "found", &self.found);
|
||||
}
|
||||
|
||||
fn add_labels_for_types(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
target: &str,
|
||||
types: &FxIndexMap<TyCategory, FxIndexSet<Span>>,
|
||||
) {
|
||||
@ -1807,16 +1798,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
// If two types mismatch but have similar names, mention that specifically.
|
||||
TypeError::Sorts(values) if let Some(s) = similarity(values) => {
|
||||
let diagnose_primitive =
|
||||
|prim: Ty<'tcx>,
|
||||
shadow: Ty<'tcx>,
|
||||
defid: DefId,
|
||||
diagnostic: &mut DiagnosticBuilder<'_>| {
|
||||
|prim: Ty<'tcx>, shadow: Ty<'tcx>, defid: DefId, diag: &mut Diag<'_>| {
|
||||
let name = shadow.sort_string(self.tcx);
|
||||
diagnostic.note(format!(
|
||||
"{prim} and {name} have similar names, but are actually distinct types"
|
||||
));
|
||||
diagnostic
|
||||
.note(format!("{prim} is a primitive defined by the language"));
|
||||
diag.note(format!(
|
||||
"{prim} and {name} have similar names, but are actually distinct types"
|
||||
));
|
||||
diag.note(format!("{prim} is a primitive defined by the language"));
|
||||
let def_span = self.tcx.def_span(defid);
|
||||
let msg = if defid.is_local() {
|
||||
format!("{name} is defined in the current crate")
|
||||
@ -1824,20 +1811,20 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
let crate_name = self.tcx.crate_name(defid.krate);
|
||||
format!("{name} is defined in crate `{crate_name}`")
|
||||
};
|
||||
diagnostic.span_note(def_span, msg);
|
||||
diag.span_note(def_span, msg);
|
||||
};
|
||||
|
||||
let diagnose_adts =
|
||||
|expected_adt: ty::AdtDef<'tcx>,
|
||||
found_adt: ty::AdtDef<'tcx>,
|
||||
diagnostic: &mut DiagnosticBuilder<'_>| {
|
||||
diag: &mut Diag<'_>| {
|
||||
let found_name = values.found.sort_string(self.tcx);
|
||||
let expected_name = values.expected.sort_string(self.tcx);
|
||||
|
||||
let found_defid = found_adt.did();
|
||||
let expected_defid = expected_adt.did();
|
||||
|
||||
diagnostic.note(format!("{found_name} and {expected_name} have similar names, but are actually distinct types"));
|
||||
diag.note(format!("{found_name} and {expected_name} have similar names, but are actually distinct types"));
|
||||
for (defid, name) in
|
||||
[(found_defid, found_name), (expected_defid, expected_name)]
|
||||
{
|
||||
@ -1859,7 +1846,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
let crate_name = self.tcx.crate_name(defid.krate);
|
||||
format!("{name} is defined in crate `{crate_name}`")
|
||||
};
|
||||
diagnostic.span_note(def_span, msg);
|
||||
diag.span_note(def_span, msg);
|
||||
}
|
||||
};
|
||||
|
||||
@ -2178,7 +2165,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
&self,
|
||||
trace: TypeTrace<'tcx>,
|
||||
terr: TypeError<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
debug!("report_and_explain_type_error(trace={:?}, terr={:?})", trace, terr);
|
||||
|
||||
let span = trace.cause.span();
|
||||
@ -2223,7 +2210,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
fn values_str(
|
||||
&self,
|
||||
values: ValuePairs<'tcx>,
|
||||
) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option<PathBuf>)> {
|
||||
) -> Option<(DiagStyledString, DiagStyledString, Option<PathBuf>)> {
|
||||
match values {
|
||||
infer::Regions(exp_found) => self.expected_found_str(exp_found),
|
||||
infer::Terms(exp_found) => self.expected_found_str_term(exp_found),
|
||||
@ -2256,7 +2243,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
fn expected_found_str_term(
|
||||
&self,
|
||||
exp_found: ty::error::ExpectedFound<ty::Term<'tcx>>,
|
||||
) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option<PathBuf>)> {
|
||||
) -> Option<(DiagStyledString, DiagStyledString, Option<PathBuf>)> {
|
||||
let exp_found = self.resolve_vars_if_possible(exp_found);
|
||||
if exp_found.references_error() {
|
||||
return None;
|
||||
@ -2274,17 +2261,17 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
let mut path = None;
|
||||
if exp_s.len() > len {
|
||||
let exp_s = self.tcx.short_ty_string(expected, &mut path);
|
||||
exp = DiagnosticStyledString::highlighted(exp_s);
|
||||
exp = DiagStyledString::highlighted(exp_s);
|
||||
}
|
||||
if fnd_s.len() > len {
|
||||
let fnd_s = self.tcx.short_ty_string(found, &mut path);
|
||||
fnd = DiagnosticStyledString::highlighted(fnd_s);
|
||||
fnd = DiagStyledString::highlighted(fnd_s);
|
||||
}
|
||||
(exp, fnd, path)
|
||||
}
|
||||
_ => (
|
||||
DiagnosticStyledString::highlighted(exp_found.expected.to_string()),
|
||||
DiagnosticStyledString::highlighted(exp_found.found.to_string()),
|
||||
DiagStyledString::highlighted(exp_found.expected.to_string()),
|
||||
DiagStyledString::highlighted(exp_found.found.to_string()),
|
||||
None,
|
||||
),
|
||||
})
|
||||
@ -2294,15 +2281,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
fn expected_found_str<T: fmt::Display + TypeFoldable<TyCtxt<'tcx>>>(
|
||||
&self,
|
||||
exp_found: ty::error::ExpectedFound<T>,
|
||||
) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option<PathBuf>)> {
|
||||
) -> Option<(DiagStyledString, DiagStyledString, Option<PathBuf>)> {
|
||||
let exp_found = self.resolve_vars_if_possible(exp_found);
|
||||
if exp_found.references_error() {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some((
|
||||
DiagnosticStyledString::highlighted(exp_found.expected.to_string()),
|
||||
DiagnosticStyledString::highlighted(exp_found.found.to_string()),
|
||||
DiagStyledString::highlighted(exp_found.expected.to_string()),
|
||||
DiagStyledString::highlighted(exp_found.found.to_string()),
|
||||
None,
|
||||
))
|
||||
}
|
||||
@ -2314,9 +2301,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
origin: Option<SubregionOrigin<'tcx>>,
|
||||
bound_kind: GenericKind<'tcx>,
|
||||
sub: Region<'tcx>,
|
||||
) {
|
||||
) -> ErrorGuaranteed {
|
||||
self.construct_generic_bound_failure(generic_param_scope, span, origin, bound_kind, sub)
|
||||
.emit();
|
||||
.emit()
|
||||
}
|
||||
|
||||
pub fn construct_generic_bound_failure(
|
||||
@ -2326,7 +2313,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
origin: Option<SubregionOrigin<'tcx>>,
|
||||
bound_kind: GenericKind<'tcx>,
|
||||
sub: Region<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
if let Some(SubregionOrigin::CompareImplItemObligation {
|
||||
span,
|
||||
impl_item_def_id,
|
||||
@ -2575,7 +2562,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
sub_region: Region<'tcx>,
|
||||
sup_origin: SubregionOrigin<'tcx>,
|
||||
sup_region: Region<'tcx>,
|
||||
) {
|
||||
) -> ErrorGuaranteed {
|
||||
let mut err = self.report_inference_failure(var_origin);
|
||||
|
||||
note_and_explain_region(
|
||||
@ -2614,12 +2601,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
);
|
||||
|
||||
err.note_expected_found(&"", sup_expected, &"", sup_found);
|
||||
if sub_region.is_error() | sup_region.is_error() {
|
||||
err.delay_as_bug();
|
||||
return if sub_region.is_error() | sup_region.is_error() {
|
||||
err.delay_as_bug()
|
||||
} else {
|
||||
err.emit();
|
||||
}
|
||||
return;
|
||||
err.emit()
|
||||
};
|
||||
}
|
||||
|
||||
self.note_region_origin(&mut err, &sup_origin);
|
||||
@ -2634,11 +2620,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
);
|
||||
|
||||
self.note_region_origin(&mut err, &sub_origin);
|
||||
if sub_region.is_error() | sup_region.is_error() {
|
||||
err.delay_as_bug();
|
||||
} else {
|
||||
err.emit();
|
||||
}
|
||||
if sub_region.is_error() | sup_region.is_error() { err.delay_as_bug() } else { err.emit() }
|
||||
}
|
||||
|
||||
/// Determine whether an error associated with the given span and definition
|
||||
@ -2744,10 +2726,7 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> InferCtxt<'tcx> {
|
||||
fn report_inference_failure(
|
||||
&self,
|
||||
var_origin: RegionVariableOrigin,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
fn report_inference_failure(&self, var_origin: RegionVariableOrigin) -> Diag<'tcx> {
|
||||
let br_string = |br: ty::BoundRegionKind| {
|
||||
let mut s = match br {
|
||||
ty::BrNamed(_, name) => name.to_string(),
|
||||
@ -2913,7 +2892,7 @@ impl<'tcx> ObligationCause<'tcx> {
|
||||
pub struct ObligationCauseAsDiagArg<'tcx>(pub ObligationCause<'tcx>);
|
||||
|
||||
impl IntoDiagnosticArg for ObligationCauseAsDiagArg<'_> {
|
||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue {
|
||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue {
|
||||
use crate::traits::ObligationCauseCode::*;
|
||||
let kind = match self.0.code() {
|
||||
CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => "method_compat",
|
||||
@ -2927,7 +2906,7 @@ impl IntoDiagnosticArg for ObligationCauseAsDiagArg<'_> {
|
||||
_ => "other",
|
||||
}
|
||||
.into();
|
||||
rustc_errors::DiagnosticArgValue::Str(kind)
|
||||
rustc_errors::DiagArgValue::Str(kind)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ use crate::errors::{
|
||||
use crate::infer::error_reporting::TypeErrCtxt;
|
||||
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
use crate::infer::InferCtxt;
|
||||
use rustc_errors::{codes::*, DiagnosticBuilder, IntoDiagnosticArg};
|
||||
use rustc_errors::{codes::*, Diag, IntoDiagnosticArg};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::def::{CtorOf, DefKind, Namespace};
|
||||
@ -134,13 +134,13 @@ impl InferenceDiagnosticsParentData {
|
||||
}
|
||||
|
||||
impl IntoDiagnosticArg for UnderspecifiedArgKind {
|
||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue {
|
||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue {
|
||||
let kind = match self {
|
||||
Self::Type { .. } => "type",
|
||||
Self::Const { is_parameter: true } => "const_with_param",
|
||||
Self::Const { is_parameter: false } => "const",
|
||||
};
|
||||
rustc_errors::DiagnosticArgValue::Str(kind.into())
|
||||
rustc_errors::DiagArgValue::Str(kind.into())
|
||||
}
|
||||
}
|
||||
|
||||
@ -371,7 +371,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
span: Span,
|
||||
arg_data: InferenceDiagnosticsData,
|
||||
error_code: TypeAnnotationNeeded,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let source_kind = "other";
|
||||
let source_name = "";
|
||||
let failure_span = None;
|
||||
@ -419,7 +419,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
arg: GenericArg<'tcx>,
|
||||
error_code: TypeAnnotationNeeded,
|
||||
should_label_span: bool,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let arg = self.resolve_vars_if_possible(arg);
|
||||
let arg_data = self.extract_inference_diagnostics_data(arg, None);
|
||||
|
||||
|
@ -12,7 +12,7 @@ use crate::infer::SubregionOrigin;
|
||||
use crate::infer::TyCtxt;
|
||||
|
||||
use rustc_errors::AddToDiagnostic;
|
||||
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
|
||||
use rustc_errors::{Diag, ErrorGuaranteed};
|
||||
use rustc_hir::Ty;
|
||||
use rustc_middle::ty::Region;
|
||||
|
||||
@ -142,7 +142,7 @@ pub fn suggest_adding_lifetime_params<'tcx>(
|
||||
sub: Region<'tcx>,
|
||||
ty_sup: &'tcx Ty<'_>,
|
||||
ty_sub: &'tcx Ty<'_>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
) {
|
||||
let suggestion = AddLifetimeParamsSuggestion { tcx, sub, ty_sup, ty_sub, add_note: false };
|
||||
suggestion.add_to_diagnostic(err);
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::infer::error_reporting::TypeErrCtxt;
|
||||
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
||||
use crate::infer::lexical_region_resolve::RegionResolutionError::*;
|
||||
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
|
||||
use rustc_errors::{Diag, ErrorGuaranteed};
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_span::Span;
|
||||
|
||||
@ -21,8 +21,11 @@ pub use static_impl_trait::{suggest_new_region_bound, HirTraitObjectVisitor, Tra
|
||||
pub use util::find_param_with_region;
|
||||
|
||||
impl<'cx, 'tcx> TypeErrCtxt<'cx, 'tcx> {
|
||||
pub fn try_report_nice_region_error(&'cx self, error: &RegionResolutionError<'tcx>) -> bool {
|
||||
NiceRegionError::new(self, error.clone()).try_report().is_some()
|
||||
pub fn try_report_nice_region_error(
|
||||
&'cx self,
|
||||
error: &RegionResolutionError<'tcx>,
|
||||
) -> Option<ErrorGuaranteed> {
|
||||
NiceRegionError::new(self, error.clone()).try_report()
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,7 +53,7 @@ impl<'cx, 'tcx> NiceRegionError<'cx, 'tcx> {
|
||||
self.cx.tcx
|
||||
}
|
||||
|
||||
pub fn try_report_from_nll(&self) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
pub fn try_report_from_nll(&self) -> Option<Diag<'tcx>> {
|
||||
// Due to the improved diagnostics returned by the MIR borrow checker, only a subset of
|
||||
// the nice region errors are required when running under the MIR borrow checker.
|
||||
self.try_report_named_anon_conflict()
|
||||
|
@ -5,14 +5,14 @@ use crate::{
|
||||
errors::ExplicitLifetimeRequired,
|
||||
infer::error_reporting::nice_region_error::find_anon_type::find_anon_type,
|
||||
};
|
||||
use rustc_errors::DiagnosticBuilder;
|
||||
use rustc_errors::Diag;
|
||||
use rustc_middle::ty;
|
||||
use rustc_span::symbol::kw;
|
||||
|
||||
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||
/// When given a `ConcreteFailure` for a function with parameters containing a named region and
|
||||
/// an anonymous region, emit an descriptive diagnostic error.
|
||||
pub(super) fn try_report_named_anon_conflict(&self) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
pub(super) fn try_report_named_anon_conflict(&self) -> Option<Diag<'tcx>> {
|
||||
let (span, sub, sup) = self.regions()?;
|
||||
|
||||
debug!(
|
||||
|
@ -8,7 +8,7 @@ use crate::infer::ValuePairs;
|
||||
use crate::infer::{SubregionOrigin, TypeTrace};
|
||||
use crate::traits::{ObligationCause, ObligationCauseCode};
|
||||
use rustc_data_structures::intern::Interned;
|
||||
use rustc_errors::{DiagnosticBuilder, IntoDiagnosticArg};
|
||||
use rustc_errors::{Diag, IntoDiagnosticArg};
|
||||
use rustc_hir::def::Namespace;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::ty::error::ExpectedFound;
|
||||
@ -30,8 +30,8 @@ impl<'tcx, T> IntoDiagnosticArg for Highlighted<'tcx, T>
|
||||
where
|
||||
T: for<'a> Print<'tcx, FmtPrinter<'a, 'tcx>>,
|
||||
{
|
||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue {
|
||||
rustc_errors::DiagnosticArgValue::Str(self.to_string().into())
|
||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagArgValue {
|
||||
rustc_errors::DiagArgValue::Str(self.to_string().into())
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ where
|
||||
impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||
/// When given a `ConcreteFailure` for a function with arguments containing a named region and
|
||||
/// an anonymous region, emit a descriptive diagnostic error.
|
||||
pub(super) fn try_report_placeholder_conflict(&self) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
pub(super) fn try_report_placeholder_conflict(&self) -> Option<Diag<'tcx>> {
|
||||
match &self.error {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// NB. The ordering of cases in this match is very
|
||||
@ -193,7 +193,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||
sub_placeholder: Option<Region<'tcx>>,
|
||||
sup_placeholder: Option<Region<'tcx>>,
|
||||
value_pairs: &ValuePairs<'tcx>,
|
||||
) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
) -> Option<Diag<'tcx>> {
|
||||
let (expected_args, found_args, trait_def_id) = match value_pairs {
|
||||
ValuePairs::PolyTraitRefs(ExpectedFound { expected, found })
|
||||
if expected.def_id() == found.def_id() =>
|
||||
@ -236,7 +236,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||
trait_def_id: DefId,
|
||||
expected_args: GenericArgsRef<'tcx>,
|
||||
actual_args: GenericArgsRef<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let span = cause.span();
|
||||
|
||||
let (leading_ellipsis, satisfy_span, where_span, dup_span, def_id) =
|
||||
|
@ -5,12 +5,12 @@ use crate::{
|
||||
},
|
||||
};
|
||||
use rustc_data_structures::intern::Interned;
|
||||
use rustc_errors::DiagnosticBuilder;
|
||||
use rustc_errors::Diag;
|
||||
use rustc_middle::ty::{self, RePlaceholder, Region};
|
||||
|
||||
impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||
/// Emitted wwhen given a `ConcreteFailure` when relating two placeholders.
|
||||
pub(super) fn try_report_placeholder_relation(&self) -> Option<DiagnosticBuilder<'tcx>> {
|
||||
pub(super) fn try_report_placeholder_relation(&self) -> Option<Diag<'tcx>> {
|
||||
match &self.error {
|
||||
Some(RegionResolutionError::ConcreteFailure(
|
||||
SubregionOrigin::RelateRegionParamBound(span),
|
||||
|
@ -9,7 +9,7 @@ use crate::infer::lexical_region_resolve::RegionResolutionError;
|
||||
use crate::infer::{SubregionOrigin, TypeTrace};
|
||||
use crate::traits::{ObligationCauseCode, UnifyReceiverContext};
|
||||
use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_errors::{AddToDiagnostic, Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan};
|
||||
use rustc_errors::{AddToDiagnostic, Applicability, Diag, ErrorGuaranteed, MultiSpan};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::intravisit::{walk_ty, Visitor};
|
||||
use rustc_hir::{
|
||||
@ -261,7 +261,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||
|
||||
pub fn suggest_new_region_bound(
|
||||
tcx: TyCtxt<'_>,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
fn_returns: Vec<&rustc_hir::Ty<'_>>,
|
||||
lifetime_name: String,
|
||||
arg: Option<String>,
|
||||
@ -488,7 +488,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||
/// `'static` obligation. Suggest relaxing that implicit bound.
|
||||
fn find_impl_on_dyn_trait(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
ty: Ty<'_>,
|
||||
ctxt: &UnifyReceiverContext<'tcx>,
|
||||
) -> bool {
|
||||
@ -521,7 +521,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||
|
||||
fn suggest_constrain_dyn_trait_in_impl(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
found_dids: &FxIndexSet<DefId>,
|
||||
ident: Ident,
|
||||
self_ty: &hir::Ty<'_>,
|
||||
|
@ -5,7 +5,7 @@ use crate::errors::{
|
||||
use crate::fluent_generated as fluent;
|
||||
use crate::infer::error_reporting::{note_and_explain_region, TypeErrCtxt};
|
||||
use crate::infer::{self, SubregionOrigin};
|
||||
use rustc_errors::{AddToDiagnostic, DiagnosticBuilder};
|
||||
use rustc_errors::{AddToDiagnostic, Diag};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_middle::traits::ObligationCauseCode;
|
||||
use rustc_middle::ty::error::TypeError;
|
||||
@ -15,11 +15,7 @@ use rustc_span::symbol::kw;
|
||||
use super::ObligationCauseAsDiagArg;
|
||||
|
||||
impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
pub(super) fn note_region_origin(
|
||||
&self,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
origin: &SubregionOrigin<'tcx>,
|
||||
) {
|
||||
pub(super) fn note_region_origin(&self, err: &mut Diag<'_>, origin: &SubregionOrigin<'tcx>) {
|
||||
match *origin {
|
||||
infer::Subtype(ref trace) => RegionOriginNote::WithRequirement {
|
||||
span: trace.cause.span,
|
||||
@ -82,7 +78,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
origin: SubregionOrigin<'tcx>,
|
||||
sub: Region<'tcx>,
|
||||
sup: Region<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
let mut err = match origin {
|
||||
infer::Subtype(box trace) => {
|
||||
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
|
||||
@ -294,7 +290,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
&self,
|
||||
trait_item_def_id: DefId,
|
||||
impl_item_def_id: LocalDefId,
|
||||
err: &mut DiagnosticBuilder<'_>,
|
||||
err: &mut Diag<'_>,
|
||||
) {
|
||||
// FIXME(compiler-errors): Right now this is only being used for region
|
||||
// predicate mismatches. Ideally, we'd use it for *all* predicate mismatches,
|
||||
@ -354,7 +350,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
placeholder_origin: SubregionOrigin<'tcx>,
|
||||
sub: Region<'tcx>,
|
||||
sup: Region<'tcx>,
|
||||
) -> DiagnosticBuilder<'tcx> {
|
||||
) -> Diag<'tcx> {
|
||||
// I can't think how to do better than this right now. -nikomatsakis
|
||||
debug!(?placeholder_origin, ?sub, ?sup, "report_placeholder_failure");
|
||||
match placeholder_origin {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user