Skip to content

Commit 2dc3024

Browse files
committed
Auto merge of #150068 - JonathanBrouwer:rollup-45j7puz, r=JonathanBrouwer
Rollup of 11 pull requests Successful merges: - #147939 (Make `const BorrowMut` require `const Borrow` and make `const Fn` require `const FnMut`) - #149734 (Mirror GCC 9.5.0) - #149767 (Tidying up tests/ui/issues 33 tests [4/N]) - #149804 (chore: fix some minor issues in the comments) - #149967 (custom `VaList` layout for Hexagon) - #150025 (dont create unnecessary `DefId`s under mgca) - #150032 (Use annotate-snippet as default emitter on stable) - #150033 (Add try_as_dyn and try_as_dyn_mut) - #150042 (rustc-dev-guide subtree update) - #150063 (Remove deny of manual-let-else) - #150064 (std: io: error: Add comment for UEFI unpacked repr use) Failed merges: - #150044 (Avoid unhelpful suggestion when crate name is invalid) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 31010ca + ff84058 commit 2dc3024

File tree

212 files changed

+2882
-677
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+2882
-677
lines changed

compiler/rustc_ast/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
77
// tidy-alphabetical-start
88
#![cfg_attr(bootstrap, feature(array_windows))]
9-
#![deny(clippy::manual_let_else)]
109
#![doc(test(attr(deny(warnings), allow(internal_features))))]
1110
#![feature(associated_type_defaults)]
1211
#![feature(box_patterns)]

compiler/rustc_borrowck/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
// tidy-alphabetical-start
44
#![allow(internal_features)]
5-
#![deny(clippy::manual_let_else)]
65
#![feature(assert_matches)]
76
#![feature(box_patterns)]
87
#![feature(file_buffered)]

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ mod simd;
66

77
use std::assert_matches::assert_matches;
88

9-
use rustc_abi::{FieldIdx, HasDataLayout, Size, VariantIdx};
9+
use rustc_abi::{FIRST_VARIANT, FieldIdx, HasDataLayout, Size, VariantIdx};
1010
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
11+
use rustc_hir::def_id::CRATE_DEF_ID;
12+
use rustc_infer::infer::TyCtxtInferExt;
1113
use rustc_middle::mir::interpret::{CTFE_ALLOC_SALT, read_target_uint, write_target_uint};
1214
use rustc_middle::mir::{self, BinOp, ConstValue, NonDivergingIntrinsic};
1315
use rustc_middle::ty::layout::TyAndLayout;
14-
use rustc_middle::ty::{FloatTy, Ty, TyCtxt};
16+
use rustc_middle::ty::{FloatTy, PolyExistentialPredicate, Ty, TyCtxt, TypeFoldable};
1517
use rustc_middle::{bug, span_bug, ty};
1618
use rustc_span::{Symbol, sym};
19+
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
1720
use tracing::trace;
1821

1922
use super::memory::MemoryKind;
@@ -219,6 +222,49 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
219222

220223
self.write_scalar(Scalar::from_target_usize(offset, self), dest)?;
221224
}
225+
sym::vtable_for => {
226+
let tp_ty = instance.args.type_at(0);
227+
let result_ty = instance.args.type_at(1);
228+
229+
ensure_monomorphic_enough(tcx, tp_ty)?;
230+
ensure_monomorphic_enough(tcx, result_ty)?;
231+
let ty::Dynamic(preds, _) = result_ty.kind() else {
232+
span_bug!(
233+
self.find_closest_untracked_caller_location(),
234+
"Invalid type provided to vtable_for::<T, U>. U must be dyn Trait, got {result_ty}."
235+
);
236+
};
237+
238+
let (infcx, param_env) =
239+
self.tcx.infer_ctxt().build_with_typing_env(self.typing_env);
240+
241+
let ocx = ObligationCtxt::new(&infcx);
242+
ocx.register_obligations(preds.iter().map(|pred: PolyExistentialPredicate<'_>| {
243+
let pred = pred.with_self_ty(tcx, tp_ty);
244+
// Lifetimes can only be 'static because of the bound on T
245+
let pred = pred.fold_with(&mut ty::BottomUpFolder {
246+
tcx,
247+
ty_op: |ty| ty,
248+
lt_op: |lt| {
249+
if lt == tcx.lifetimes.re_erased { tcx.lifetimes.re_static } else { lt }
250+
},
251+
ct_op: |ct| ct,
252+
});
253+
Obligation::new(tcx, ObligationCause::dummy(), param_env, pred)
254+
}));
255+
let type_impls_trait = ocx.evaluate_obligations_error_on_ambiguity().is_empty();
256+
// Since `assumed_wf_tys=[]` the choice of LocalDefId is irrelevant, so using the "default"
257+
let regions_are_valid = ocx.resolve_regions(CRATE_DEF_ID, param_env, []).is_empty();
258+
259+
if regions_are_valid && type_impls_trait {
260+
let vtable_ptr = self.get_vtable_ptr(tp_ty, preds)?;
261+
// Writing a non-null pointer into an `Option<NonNull>` will automatically make it `Some`.
262+
self.write_pointer(vtable_ptr, dest)?;
263+
} else {
264+
// Write `None`
265+
self.write_discriminant(FIRST_VARIANT, dest)?;
266+
}
267+
}
222268
sym::variant_count => {
223269
let tp_ty = instance.args.type_at(0);
224270
let ty = match tp_ty.kind() {

compiler/rustc_const_eval/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// tidy-alphabetical-start
22
#![allow(rustc::diagnostic_outside_of_impl)]
3-
#![deny(clippy::manual_let_else)]
43
#![feature(array_try_map)]
54
#![feature(assert_matches)]
65
#![feature(box_patterns)]

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -303,17 +303,6 @@ impl AnnotateSnippetEmitter {
303303
}
304304
}
305305

306-
let suggestions_expected = suggestions
307-
.iter()
308-
.filter(|s| {
309-
matches!(
310-
s.style,
311-
SuggestionStyle::HideCodeInline
312-
| SuggestionStyle::ShowCode
313-
| SuggestionStyle::ShowAlways
314-
)
315-
})
316-
.count();
317306
for suggestion in suggestions {
318307
match suggestion.style {
319308
SuggestionStyle::CompletelyHidden => {
@@ -526,12 +515,6 @@ impl AnnotateSnippetEmitter {
526515
}
527516
}
528517

529-
// FIXME: This hack should be removed once annotate_snippets is the
530-
// default emitter.
531-
if suggestions_expected > 0 && report.is_empty() {
532-
group = group.element(Padding);
533-
}
534-
535518
if !group.is_empty() {
536519
report.push(group);
537520
}

compiler/rustc_errors/src/emitter.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,14 @@ const DEFAULT_COLUMN_WIDTH: usize = 140;
4646

4747
/// Describes the way the content of the `rendered` field of the json output is generated
4848
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
49-
pub enum HumanReadableErrorType {
50-
Default { short: bool },
51-
AnnotateSnippet { short: bool, unicode: bool },
49+
pub struct HumanReadableErrorType {
50+
pub short: bool,
51+
pub unicode: bool,
5252
}
5353

5454
impl HumanReadableErrorType {
5555
pub fn short(&self) -> bool {
56-
match self {
57-
HumanReadableErrorType::Default { short }
58-
| HumanReadableErrorType::AnnotateSnippet { short, .. } => *short,
59-
}
56+
self.short
6057
}
6158
}
6259

@@ -607,7 +604,7 @@ pub enum OutputTheme {
607604
Unicode,
608605
}
609606

610-
/// Handles the writing of `HumanReadableErrorType::Default` and `HumanReadableErrorType::Short`
607+
/// Handles the writing of `HumanReadableErrorType`
611608
#[derive(Setters)]
612609
pub struct HumanEmitter {
613610
#[setters(skip)]

compiler/rustc_errors/src/json.rs

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use serde::Serialize;
2828
use crate::annotate_snippet_emitter_writer::AnnotateSnippetEmitter;
2929
use crate::diagnostic::IsLint;
3030
use crate::emitter::{
31-
ColorConfig, Destination, Emitter, HumanEmitter, HumanReadableErrorType, OutputTheme,
32-
TimingEvent, should_show_source_code,
31+
ColorConfig, Destination, Emitter, HumanReadableErrorType, OutputTheme, TimingEvent,
32+
should_show_source_code,
3333
};
3434
use crate::registry::Registry;
3535
use crate::timings::{TimingRecord, TimingSection};
@@ -378,38 +378,17 @@ impl Diagnostic {
378378
choice => choice,
379379
},
380380
);
381-
match je.json_rendered {
382-
HumanReadableErrorType::AnnotateSnippet { short, unicode } => {
383-
AnnotateSnippetEmitter::new(dst, je.translator.clone())
384-
.short_message(short)
385-
.sm(je.sm.clone())
386-
.diagnostic_width(je.diagnostic_width)
387-
.macro_backtrace(je.macro_backtrace)
388-
.track_diagnostics(je.track_diagnostics)
389-
.terminal_url(je.terminal_url)
390-
.ui_testing(je.ui_testing)
391-
.ignored_directories_in_source_blocks(
392-
je.ignored_directories_in_source_blocks.clone(),
393-
)
394-
.theme(if unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
395-
.emit_diagnostic(diag, registry)
396-
}
397-
HumanReadableErrorType::Default { short } => {
398-
HumanEmitter::new(dst, je.translator.clone())
399-
.short_message(short)
400-
.sm(je.sm.clone())
401-
.diagnostic_width(je.diagnostic_width)
402-
.macro_backtrace(je.macro_backtrace)
403-
.track_diagnostics(je.track_diagnostics)
404-
.terminal_url(je.terminal_url)
405-
.ui_testing(je.ui_testing)
406-
.ignored_directories_in_source_blocks(
407-
je.ignored_directories_in_source_blocks.clone(),
408-
)
409-
.theme(OutputTheme::Ascii)
410-
.emit_diagnostic(diag, registry)
411-
}
412-
}
381+
AnnotateSnippetEmitter::new(dst, je.translator.clone())
382+
.short_message(je.json_rendered.short)
383+
.sm(je.sm.clone())
384+
.diagnostic_width(je.diagnostic_width)
385+
.macro_backtrace(je.macro_backtrace)
386+
.track_diagnostics(je.track_diagnostics)
387+
.terminal_url(je.terminal_url)
388+
.ui_testing(je.ui_testing)
389+
.ignored_directories_in_source_blocks(je.ignored_directories_in_source_blocks.clone())
390+
.theme(if je.json_rendered.unicode { OutputTheme::Unicode } else { OutputTheme::Ascii })
391+
.emit_diagnostic(diag, registry);
413392

414393
let buf = Arc::try_unwrap(buf.0).unwrap().into_inner().unwrap();
415394
let buf = String::from_utf8(buf).unwrap();

compiler/rustc_errors/src/json/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn test_positions(code: &str, span: (u32, u32), expected_output: SpanTestData) {
5454
Some(sm),
5555
translator,
5656
true, // pretty
57-
HumanReadableErrorType::Default { short: true },
57+
HumanReadableErrorType { short: true, unicode: false },
5858
ColorConfig::Never,
5959
);
6060

compiler/rustc_hir/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
55
// tidy-alphabetical-start
66
#![cfg_attr(bootstrap, feature(debug_closure_helpers))]
7-
#![deny(clippy::manual_let_else)]
87
#![feature(associated_type_defaults)]
98
#![feature(closure_track_caller)]
109
#![feature(const_default)]

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
215215
| sym::type_name
216216
| sym::ub_checks
217217
| sym::variant_count
218+
| sym::vtable_for
218219
| sym::wrapping_add
219220
| sym::wrapping_mul
220221
| sym::wrapping_sub
@@ -643,6 +644,20 @@ pub(crate) fn check_intrinsic_type(
643644
(0, 0, vec![Ty::new_imm_ptr(tcx, tcx.types.unit)], tcx.types.usize)
644645
}
645646

647+
sym::vtable_for => {
648+
let dyn_metadata = tcx.require_lang_item(LangItem::DynMetadata, span);
649+
let dyn_metadata_adt_ref = tcx.adt_def(dyn_metadata);
650+
let dyn_metadata_args = tcx.mk_args(&[param(1).into()]);
651+
let dyn_ty = Ty::new_adt(tcx, dyn_metadata_adt_ref, dyn_metadata_args);
652+
653+
let option_did = tcx.require_lang_item(LangItem::Option, span);
654+
let option_adt_ref = tcx.adt_def(option_did);
655+
let option_args = tcx.mk_args(&[dyn_ty.into()]);
656+
let ret_ty = Ty::new_adt(tcx, option_adt_ref, option_args);
657+
658+
(2, 0, vec![], ret_ty)
659+
}
660+
646661
// This type check is not particularly useful, but the `where` bounds
647662
// on the definition in `core` do the heavy lifting for checking it.
648663
sym::aggregate_raw_ptr => (3, 0, vec![param(1), param(2)], param(0)),

0 commit comments

Comments
 (0)