Skip to content

Commit a460185

Browse files
committed
Auto merge of rust-lang#129873 - matthiaskrgr:rollup-bv849ud, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#127474 (doc: Make block of inline Deref methods foldable) - rust-lang#129678 (Deny imports of `rustc_type_ir::inherent` outside of type ir + new trait solver) - rust-lang#129738 (`rustc_mir_transform` cleanups) - rust-lang#129793 (add extra linebreaks so rustdoc can identify the first sentence) - rust-lang#129804 (Fixed some typos in the standard library documentation/comments) - rust-lang#129837 (Actually parse stdout json, instead of using hacky contains logic.) - rust-lang#129842 (Fix LLVM ABI NAME for riscv64imac-unknown-nuttx-elf) - rust-lang#129843 (Mark myself as on vacation for triagebot) - rust-lang#129858 (Replace walk with visit so we dont skip outermost expr kind in def collector) Failed merges: - rust-lang#129777 (Add `unreachable_pub`, round 4) - rust-lang#129868 (Remove kobzol vacation status) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9b82580 + 38b6a66 commit a460185

File tree

34 files changed

+305
-232
lines changed

34 files changed

+305
-232
lines changed

compiler/rustc_lint/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,9 @@ lint_tykind = usage of `ty::TyKind`
783783
lint_tykind_kind = usage of `ty::TyKind::<kind>`
784784
.suggestion = try using `ty::<kind>` directly
785785
786+
lint_type_ir_inherent_usage = do not use `rustc_type_ir::inherent` unless you're inside of the trait solver
787+
.note = the method or struct you're looking for is likely defined somewhere else downstream in the compiler
788+
786789
lint_undropped_manually_drops = calls to `std::mem::drop` with `std::mem::ManuallyDrop` instead of the inner value does nothing
787790
.label = argument has type `{$arg_ty}`
788791
.suggestion = use `std::mem::ManuallyDrop::into_inner` to get the inner value

compiler/rustc_lint/src/internal.rs

+28-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use tracing::debug;
1818
use crate::lints::{
1919
BadOptAccessDiag, DefaultHashTypesDiag, DiagOutOfImpl, LintPassByHand, NonExistentDocKeyword,
2020
NonGlobImportTypeIrInherent, QueryInstability, SpanUseEqCtxtDiag, TyQualified, TykindDiag,
21-
TykindKind, UntranslatableDiag,
21+
TykindKind, TypeIrInherentUsage, UntranslatableDiag,
2222
};
2323
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
2424

@@ -277,13 +277,39 @@ declare_tool_lint! {
277277
report_in_external_macro: true
278278
}
279279

280-
declare_lint_pass!(TypeIr => [NON_GLOB_IMPORT_OF_TYPE_IR_INHERENT]);
280+
declare_tool_lint! {
281+
/// The `usage_of_type_ir_inherent` lint detects usage `rustc_type_ir::inherent`.
282+
///
283+
/// This module should only be used within the trait solver.
284+
pub rustc::USAGE_OF_TYPE_IR_INHERENT,
285+
Allow,
286+
"usage `rustc_type_ir::inherent` outside of trait system",
287+
report_in_external_macro: true
288+
}
289+
290+
declare_lint_pass!(TypeIr => [NON_GLOB_IMPORT_OF_TYPE_IR_INHERENT, USAGE_OF_TYPE_IR_INHERENT]);
281291

282292
impl<'tcx> LateLintPass<'tcx> for TypeIr {
283293
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
284294
let rustc_hir::ItemKind::Use(path, kind) = item.kind else { return };
285295

286296
let is_mod_inherent = |def_id| cx.tcx.is_diagnostic_item(sym::type_ir_inherent, def_id);
297+
298+
// Path segments except for the final.
299+
if let Some(seg) =
300+
path.segments.iter().find(|seg| seg.res.opt_def_id().is_some_and(is_mod_inherent))
301+
{
302+
cx.emit_span_lint(USAGE_OF_TYPE_IR_INHERENT, seg.ident.span, TypeIrInherentUsage);
303+
}
304+
// Final path resolutions, like `use rustc_type_ir::inherent`
305+
else if path.res.iter().any(|res| res.opt_def_id().is_some_and(is_mod_inherent)) {
306+
cx.emit_span_lint(
307+
USAGE_OF_TYPE_IR_INHERENT,
308+
path.segments.last().unwrap().ident.span,
309+
TypeIrInherentUsage,
310+
);
311+
}
312+
287313
let (lo, hi, snippet) = match path.segments {
288314
[.., penultimate, segment]
289315
if penultimate.res.opt_def_id().is_some_and(is_mod_inherent) =>

compiler/rustc_lint/src/lints.rs

+5
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,11 @@ pub(crate) struct TyQualified {
918918
pub suggestion: Span,
919919
}
920920

921+
#[derive(LintDiagnostic)]
922+
#[diag(lint_type_ir_inherent_usage)]
923+
#[note]
924+
pub(crate) struct TypeIrInherentUsage;
925+
921926
#[derive(LintDiagnostic)]
922927
#[diag(lint_non_glob_import_type_ir_inherent)]
923928
pub(crate) struct NonGlobImportTypeIrInherent {

compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn add_move_for_packed_drop<'tcx>(
8686

8787
let source_info = terminator.source_info;
8888
let ty = place.ty(body, tcx).ty;
89-
let temp = patch.new_temp(ty, terminator.source_info.span);
89+
let temp = patch.new_temp(ty, source_info.span);
9090

9191
let storage_dead_block = patch.new_block(BasicBlockData {
9292
statements: vec![Statement { source_info, kind: StatementKind::StorageDead(temp) }],

compiler/rustc_mir_transform/src/check_packed_ref.rs

+11-18
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,17 @@ impl<'tcx> Visitor<'tcx> for PackedRefChecker<'_, 'tcx> {
3737
}
3838

3939
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: Location) {
40-
if context.is_borrow() {
41-
if util::is_disaligned(self.tcx, self.body, self.param_env, *place) {
42-
let def_id = self.body.source.instance.def_id();
43-
if let Some(impl_def_id) = self.tcx.impl_of_method(def_id)
44-
&& self.tcx.is_builtin_derived(impl_def_id)
45-
{
46-
// If we ever reach here it means that the generated derive
47-
// code is somehow doing an unaligned reference, which it
48-
// shouldn't do.
49-
span_bug!(
50-
self.source_info.span,
51-
"builtin derive created an unaligned reference"
52-
);
53-
} else {
54-
self.tcx
55-
.dcx()
56-
.emit_err(errors::UnalignedPackedRef { span: self.source_info.span });
57-
}
40+
if context.is_borrow() && util::is_disaligned(self.tcx, self.body, self.param_env, *place) {
41+
let def_id = self.body.source.instance.def_id();
42+
if let Some(impl_def_id) = self.tcx.impl_of_method(def_id)
43+
&& self.tcx.is_builtin_derived(impl_def_id)
44+
{
45+
// If we ever reach here it means that the generated derive
46+
// code is somehow doing an unaligned reference, which it
47+
// shouldn't do.
48+
span_bug!(self.source_info.span, "builtin derive created an unaligned reference");
49+
} else {
50+
self.tcx.dcx().emit_err(errors::UnalignedPackedRef { span: self.source_info.span });
5851
}
5952
}
6053
}

0 commit comments

Comments
 (0)