Skip to content

Commit

Permalink
Auto merge of rust-lang#128853 - matthiaskrgr:rollup-pr222x1, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#128640 (rwlock: disable 'frob' test in Miri on macOS)
 - rust-lang#128791 (Don't implement `AsyncFn` for `FnDef`/`FnPtr` that wouldnt implement `Fn`)
 - rust-lang#128806 (Split `ColorConfig` off of `HumanReadableErrorType`)
 - rust-lang#128818 (std float tests: special-case Miri in feature detection)
 - rust-lang#128834 (rustdoc: strip unreachable modules)
 - rust-lang#128836 (rustdoc-json: add a test for impls on private & hidden types)
 - rust-lang#128837 (Clippy subtree update)
 - rust-lang#128851 (Add comment that bors did not see pushed before it merged)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Aug 9, 2024
2 parents c7b0d4e + 9243aee commit fac7753
Show file tree
Hide file tree
Showing 320 changed files with 5,830 additions and 4,097 deletions.
11 changes: 6 additions & 5 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -564,14 +564,15 @@ dependencies = [
"termize",
"tokio",
"toml 0.7.8",
"ui_test 0.24.0",
"ui_test 0.25.0",
"walkdir",
]

[[package]]
name = "clippy_config"
version = "0.1.82"
dependencies = [
"itertools",
"rustc-semver",
"serde",
"toml 0.7.8",
Expand Down Expand Up @@ -4936,9 +4937,9 @@ dependencies = [

[[package]]
name = "spanned"
version = "0.2.1"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed14ba8b4b82241bd5daba2c49185d4a0581a0058355fe96537338f002b8605d"
checksum = "86af297923fbcfd107c20a189a6e9c872160df71a7190ae4a7a6c5dce4b2feb6"
dependencies = [
"bstr",
"color-eyre",
Expand Down Expand Up @@ -5562,9 +5563,9 @@ dependencies = [

[[package]]
name = "ui_test"
version = "0.24.0"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc1c6c78d55482388711c8d417b8e547263046a607512278fed274c54633bbe4"
checksum = "f7e4f339f62edc873975c47115f9e71c5454ddaa37c1142b42fc0b2672c8dacb"
dependencies = [
"annotate-snippets 0.11.4",
"anyhow",
Expand Down
15 changes: 5 additions & 10 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,14 @@ const DEFAULT_COLUMN_WIDTH: usize = 140;
/// Describes the way the content of the `rendered` field of the json output is generated
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum HumanReadableErrorType {
Default(ColorConfig),
AnnotateSnippet(ColorConfig),
Short(ColorConfig),
Default,
AnnotateSnippet,
Short,
}

impl HumanReadableErrorType {
/// Returns a (`short`, `color`) tuple
pub fn unzip(self) -> (bool, ColorConfig) {
match self {
HumanReadableErrorType::Default(cc) => (false, cc),
HumanReadableErrorType::Short(cc) => (true, cc),
HumanReadableErrorType::AnnotateSnippet(cc) => (false, cc),
}
pub fn short(&self) -> bool {
*self == HumanReadableErrorType::Short
}
}

Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct JsonEmitter {
ignored_directories_in_source_blocks: Vec<String>,
#[setters(skip)]
json_rendered: HumanReadableErrorType,
color_config: ColorConfig,
diagnostic_width: Option<usize>,
macro_backtrace: bool,
track_diagnostics: bool,
Expand All @@ -68,6 +69,7 @@ impl JsonEmitter {
fallback_bundle: LazyFallbackBundle,
pretty: bool,
json_rendered: HumanReadableErrorType,
color_config: ColorConfig,
) -> JsonEmitter {
JsonEmitter {
dst: IntoDynSyncSend(dst),
Expand All @@ -79,6 +81,7 @@ impl JsonEmitter {
ui_testing: false,
ignored_directories_in_source_blocks: Vec::new(),
json_rendered,
color_config,
diagnostic_width: None,
macro_backtrace: false,
track_diagnostics: false,
Expand Down Expand Up @@ -173,7 +176,7 @@ impl Emitter for JsonEmitter {
}

fn should_show_explain(&self) -> bool {
!matches!(self.json_rendered, HumanReadableErrorType::Short(_))
!self.json_rendered.short()
}
}

Expand Down Expand Up @@ -353,8 +356,8 @@ impl Diagnostic {

let buf = BufWriter::default();
let mut dst: Destination = Box::new(buf.clone());
let (short, color_config) = je.json_rendered.unzip();
match color_config {
let short = je.json_rendered.short();
match je.color_config {
ColorConfig::Always | ColorConfig::Auto => dst = Box::new(termcolor::Ansi::new(dst)),
ColorConfig::Never => {}
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_errors/src/json/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
sm,
fallback_bundle,
true, // pretty
HumanReadableErrorType::Short(ColorConfig::Never),
HumanReadableErrorType::Short,
ColorConfig::Never,
);

let span = Span::with_root_ctxt(BytePos(span.0), BytePos(span.1));
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,14 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
});
sess.time("layout_testing", || layout_test::test_layout(tcx));
sess.time("abi_testing", || abi_test::test_abi(tcx));

// If `-Zvalidate-mir` is set, we also want to compute the final MIR for each item
// (either its `mir_for_ctfe` or `optimized_mir`) since that helps uncover any bugs
// in MIR optimizations that may only be reachable through codegen, or other codepaths
// that requires the optimized/ctfe MIR, such as polymorphization, coroutine bodies,
// or evaluating consts.
if tcx.sess.opts.unstable_opts.validate_mir {
sess.time("ensuring_optimized_MIR_is_computable", || {
sess.time("ensuring_final_MIR_is_computable", || {
tcx.hir().par_body_owners(|def_id| {
tcx.instance_mir(ty::InstanceKind::Item(def_id.into()));
});
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ fn test_search_paths_tracking_hash_different_order() {
let early_dcx = EarlyDiagCtxt::new(JSON);
const JSON: ErrorOutputType = ErrorOutputType::Json {
pretty: false,
json_rendered: HumanReadableErrorType::Default(ColorConfig::Never),
json_rendered: HumanReadableErrorType::Default,
color_config: ColorConfig::Never,
};

let push = |opts: &mut Options, search_path| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,28 +458,23 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
))
}

ty::FnDef(..) | ty::FnPtr(..) => {
let bound_sig = self_ty.fn_sig(cx);
let sig = bound_sig.skip_binder();
let future_trait_def_id = cx.require_lang_item(TraitSolverLangItem::Future);
// `FnDef` and `FnPtr` only implement `AsyncFn*` when their
// return type implements `Future`.
let nested = vec![
bound_sig
.rebind(ty::TraitRef::new(cx, future_trait_def_id, [sig.output()]))
.upcast(cx),
];
let future_output_def_id = cx.require_lang_item(TraitSolverLangItem::FutureOutput);
let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]);
Ok((
bound_sig.rebind(AsyncCallableRelevantTypes {
tupled_inputs_ty: Ty::new_tup(cx, sig.inputs().as_slice()),
output_coroutine_ty: sig.output(),
coroutine_return_ty: future_output_ty,
}),
nested,
))
ty::FnDef(def_id, _) => {
let sig = self_ty.fn_sig(cx);
if sig.skip_binder().is_fn_trait_compatible() && !cx.has_target_features(def_id) {
fn_item_to_async_callable(cx, sig)
} else {
Err(NoSolution)
}
}
ty::FnPtr(..) => {
let sig = self_ty.fn_sig(cx);
if sig.skip_binder().is_fn_trait_compatible() {
fn_item_to_async_callable(cx, sig)
} else {
Err(NoSolution)
}
}

ty::Closure(_, args) => {
let args = args.as_closure();
let bound_sig = args.sig();
Expand Down Expand Up @@ -563,6 +558,29 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
}
}

fn fn_item_to_async_callable<I: Interner>(
cx: I,
bound_sig: ty::Binder<I, ty::FnSig<I>>,
) -> Result<(ty::Binder<I, AsyncCallableRelevantTypes<I>>, Vec<I::Predicate>), NoSolution> {
let sig = bound_sig.skip_binder();
let future_trait_def_id = cx.require_lang_item(TraitSolverLangItem::Future);
// `FnDef` and `FnPtr` only implement `AsyncFn*` when their
// return type implements `Future`.
let nested = vec![
bound_sig.rebind(ty::TraitRef::new(cx, future_trait_def_id, [sig.output()])).upcast(cx),
];
let future_output_def_id = cx.require_lang_item(TraitSolverLangItem::FutureOutput);
let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]);
Ok((
bound_sig.rebind(AsyncCallableRelevantTypes {
tupled_inputs_ty: Ty::new_tup(cx, sig.inputs().as_slice()),
output_coroutine_ty: sig.output(),
coroutine_return_ty: future_output_ty,
}),
nested,
))
}

/// Given a coroutine-closure, project to its returned coroutine when we are *certain*
/// that the closure's kind is compatible with the goal.
fn coroutine_closure_to_certain_coroutine<I: Interner>(
Expand Down
38 changes: 23 additions & 15 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,20 +602,21 @@ impl OutputType {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ErrorOutputType {
/// Output meant for the consumption of humans.
HumanReadable(HumanReadableErrorType),
HumanReadable(HumanReadableErrorType, ColorConfig),
/// Output that's consumed by other tools such as `rustfix` or the `RLS`.
Json {
/// Render the JSON in a human readable way (with indents and newlines).
pretty: bool,
/// The JSON output includes a `rendered` field that includes the rendered
/// human output.
json_rendered: HumanReadableErrorType,
color_config: ColorConfig,
},
}

impl Default for ErrorOutputType {
fn default() -> Self {
Self::HumanReadable(HumanReadableErrorType::Default(ColorConfig::Auto))
Self::HumanReadable(HumanReadableErrorType::Default, ColorConfig::Auto)
}
}

Expand Down Expand Up @@ -1631,6 +1632,7 @@ pub fn parse_color(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Col
/// Possible json config files
pub struct JsonConfig {
pub json_rendered: HumanReadableErrorType,
pub json_color: ColorConfig,
json_artifact_notifications: bool,
pub json_unused_externs: JsonUnusedExterns,
json_future_incompat: bool,
Expand Down Expand Up @@ -1668,8 +1670,7 @@ impl JsonUnusedExterns {
/// The first value returned is how to render JSON diagnostics, and the second
/// is whether or not artifact notifications are enabled.
pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> JsonConfig {
let mut json_rendered: fn(ColorConfig) -> HumanReadableErrorType =
HumanReadableErrorType::Default;
let mut json_rendered = HumanReadableErrorType::Default;
let mut json_color = ColorConfig::Never;
let mut json_artifact_notifications = false;
let mut json_unused_externs = JsonUnusedExterns::No;
Expand All @@ -1696,7 +1697,8 @@ pub fn parse_json(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Json
}

JsonConfig {
json_rendered: json_rendered(json_color),
json_rendered,
json_color,
json_artifact_notifications,
json_unused_externs,
json_future_incompat,
Expand All @@ -1708,6 +1710,7 @@ pub fn parse_error_format(
early_dcx: &mut EarlyDiagCtxt,
matches: &getopts::Matches,
color: ColorConfig,
json_color: ColorConfig,
json_rendered: HumanReadableErrorType,
) -> ErrorOutputType {
// We need the `opts_present` check because the driver will send us Matches
Expand All @@ -1717,18 +1720,22 @@ pub fn parse_error_format(
let error_format = if matches.opts_present(&["error-format".to_owned()]) {
match matches.opt_str("error-format").as_deref() {
None | Some("human") => {
ErrorOutputType::HumanReadable(HumanReadableErrorType::Default(color))
ErrorOutputType::HumanReadable(HumanReadableErrorType::Default, color)
}
Some("human-annotate-rs") => {
ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateSnippet(color))
ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateSnippet, color)
}
Some("json") => ErrorOutputType::Json { pretty: false, json_rendered },
Some("pretty-json") => ErrorOutputType::Json { pretty: true, json_rendered },
Some("short") => ErrorOutputType::HumanReadable(HumanReadableErrorType::Short(color)),

Some("json") => {
ErrorOutputType::Json { pretty: false, json_rendered, color_config: json_color }
}
Some("pretty-json") => {
ErrorOutputType::Json { pretty: true, json_rendered, color_config: json_color }
}
Some("short") => ErrorOutputType::HumanReadable(HumanReadableErrorType::Short, color),
Some(arg) => {
early_dcx.abort_if_error_and_set_error_format(ErrorOutputType::HumanReadable(
HumanReadableErrorType::Default(color),
HumanReadableErrorType::Default,
color,
));
early_dcx.early_fatal(format!(
"argument for `--error-format` must be `human`, `json` or \
Expand All @@ -1737,7 +1744,7 @@ pub fn parse_error_format(
}
}
} else {
ErrorOutputType::HumanReadable(HumanReadableErrorType::Default(color))
ErrorOutputType::HumanReadable(HumanReadableErrorType::Default, color)
};

match error_format {
Expand Down Expand Up @@ -1791,7 +1798,7 @@ fn check_error_format_stability(
if let ErrorOutputType::Json { pretty: true, .. } = error_format {
early_dcx.early_fatal("`--error-format=pretty-json` is unstable");
}
if let ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateSnippet(_)) =
if let ErrorOutputType::HumanReadable(HumanReadableErrorType::AnnotateSnippet, _) =
error_format
{
early_dcx.early_fatal("`--error-format=human-annotate-rs` is unstable");
Expand Down Expand Up @@ -2392,12 +2399,13 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M

let JsonConfig {
json_rendered,
json_color,
json_artifact_notifications,
json_unused_externs,
json_future_incompat,
} = parse_json(early_dcx, matches);

let error_format = parse_error_format(early_dcx, matches, color, json_rendered);
let error_format = parse_error_format(early_dcx, matches, color, json_color, json_rendered);

early_dcx.abort_if_error_and_set_error_format(error_format);

Expand Down
Loading

0 comments on commit fac7753

Please sign in to comment.