Skip to content

Commit 4f50ae6

Browse files
committed
Auto merge of #158047 - JonathanBrouwer:rollup-IaduMyK, r=<try>
Rollup of 12 pull requests try-job: dist-various-1 try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple try-job: x86_64-mingw-1 try-job: i686-msvc-2
2 parents 693b3e4 + d9dc07c commit 4f50ae6

69 files changed

Lines changed: 720 additions & 115 deletions

File tree

Some content is hidden

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

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::diagnostics::{
2222
use crate::parser::{ArgParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser};
2323
use crate::session_diagnostics::{
2424
DocAliasBadChar, DocAliasEmpty, DocAliasMalformed, DocAliasStartEnd, DocAttrNotCrateLevel,
25-
DocAttributeNotAttribute, DocKeywordNotKeyword,
25+
DocAttributeNotAttribute, DocKeywordNotKeyword, UnusedDuplicate,
2626
};
2727

2828
fn check_keyword(cx: &mut AcceptContext<'_, '_>, keyword: Symbol, span: Span) -> bool {
@@ -159,11 +159,7 @@ impl DocParser {
159159
let unused_span = path.span();
160160
cx.emit_lint(
161161
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
162-
rustc_errors::lints::UnusedDuplicate {
163-
this: unused_span,
164-
other: used_span,
165-
warning: true,
166-
},
162+
UnusedDuplicate { this: unused_span, other: used_span, warning: true },
167163
unused_span,
168164
);
169165
return;

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use crate::parser::{
7171
};
7272
use crate::session_diagnostics::{
7373
AttributeParseError, AttributeParseErrorReason, AttributeParseErrorSuggestions,
74-
ParsedDescription,
74+
ParsedDescription, UnusedDuplicate,
7575
};
7676
use crate::target_checking::AllowedTargets;
7777
use crate::{AttrSuggestionStyle, AttributeParser, AttributeTemplate, EmitAttribute};
@@ -436,11 +436,7 @@ impl<'f, 'sess: 'f> SharedContext<'f, 'sess> {
436436
pub(crate) fn warn_unused_duplicate(&mut self, used_span: Span, unused_span: Span) {
437437
self.emit_lint(
438438
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
439-
rustc_errors::lints::UnusedDuplicate {
440-
this: unused_span,
441-
other: used_span,
442-
warning: false,
443-
},
439+
UnusedDuplicate { this: unused_span, other: used_span, warning: false },
444440
unused_span,
445441
)
446442
}
@@ -452,11 +448,7 @@ impl<'f, 'sess: 'f> SharedContext<'f, 'sess> {
452448
) {
453449
self.emit_lint(
454450
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
455-
rustc_errors::lints::UnusedDuplicate {
456-
this: unused_span,
457-
other: used_span,
458-
warning: true,
459-
},
451+
UnusedDuplicate { this: unused_span, other: used_span, warning: true },
460452
unused_span,
461453
)
462454
}

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,3 +1045,16 @@ pub(crate) struct AdditionalCommaSuggestion {
10451045
#[primary_span]
10461046
pub span: Span,
10471047
}
1048+
1049+
#[derive(Diagnostic)]
1050+
#[diag("unused attribute")]
1051+
pub(crate) struct UnusedDuplicate {
1052+
#[suggestion("remove this attribute", code = "", applicability = "machine-applicable")]
1053+
pub this: Span,
1054+
#[note("attribute also specified here")]
1055+
pub other: Span,
1056+
#[warning(
1057+
"this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
1058+
)]
1059+
pub warning: bool,
1060+
}

compiler/rustc_errors/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ mod diagnostic_impls;
7979
pub mod emitter;
8080
pub mod formatting;
8181
pub mod json;
82-
pub mod lints;
8382
mod lock;
8483
pub mod markdown;
8584
pub mod timings;

compiler/rustc_errors/src/lints.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,6 +2594,43 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
25942594
let variant_def = adt_def.variant_with_id(variant_did);
25952595
let variant_idx = adt_def.variant_index_with_id(variant_did).as_u32();
25962596

2597+
for init in inits {
2598+
if !variant_def.fields.iter().any(|field_def| field_def.name == init.field.name) {
2599+
let mut err = if adt_def.is_enum() {
2600+
struct_span_code_err!(
2601+
tcx.dcx(),
2602+
init.field.span,
2603+
E0559,
2604+
"variant `{}::{}` has no field named `{}`",
2605+
ty,
2606+
variant_def.name,
2607+
init.field
2608+
)
2609+
} else {
2610+
struct_span_code_err!(
2611+
tcx.dcx(),
2612+
init.field.span,
2613+
E0560,
2614+
"struct `{}` has no field named `{}`",
2615+
variant_def.name,
2616+
init.field
2617+
)
2618+
};
2619+
if adt_def.is_enum() {
2620+
err.span_label(
2621+
init.field.span,
2622+
format!("`{}::{}` does not have this field", ty, variant_def.name),
2623+
);
2624+
} else {
2625+
err.span_label(
2626+
init.field.span,
2627+
format!("`{}` does not have this field", variant_def.name),
2628+
);
2629+
}
2630+
return ty::Const::new_error(tcx, err.emit());
2631+
}
2632+
}
2633+
25972634
let fields = variant_def
25982635
.fields
25992636
.iter()

compiler/rustc_lint/src/builtin.rs

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -606,37 +606,61 @@ impl_lint_pass!(MissingDebugImplementations => [MISSING_DEBUG_IMPLEMENTATIONS]);
606606

607607
impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
608608
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
609-
if !cx.effective_visibilities.is_reachable(item.owner_id.def_id) {
609+
let def_id = item.owner_id.def_id;
610+
if !cx.effective_visibilities.is_reachable(def_id) {
610611
return;
611612
}
612613

613-
match item.kind {
614-
hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) | hir::ItemKind::Enum(..) => {}
614+
let is_generic = match item.kind {
615+
hir::ItemKind::Struct(_, generics, _)
616+
| hir::ItemKind::Union(_, generics, _)
617+
| hir::ItemKind::Enum(_, generics, _) => !generics.params.is_empty(),
615618
_ => return,
616-
}
619+
};
620+
621+
let tcx = cx.tcx;
617622

618623
// Avoid listing trait impls if the trait is allowed.
619-
if cx.tcx.lint_level_spec_at_node(MISSING_DEBUG_IMPLEMENTATIONS, item.hir_id()).is_allow() {
624+
if tcx.lint_level_spec_at_node(MISSING_DEBUG_IMPLEMENTATIONS, item.hir_id()).is_allow() {
620625
return;
621626
}
622627

623-
let Some(debug) = cx.tcx.get_diagnostic_item(sym::Debug) else { return };
628+
let Some(debug) = tcx.get_diagnostic_item(sym::Debug) else { return };
624629

625-
let has_impl = cx
626-
.tcx
627-
.non_blanket_impls_for_ty(
628-
debug,
629-
cx.tcx.type_of(item.owner_id).instantiate_identity().skip_norm_wip(),
630-
)
630+
let ty = tcx.type_of(item.owner_id);
631+
if tcx
632+
.non_blanket_impls_for_ty(debug, ty.instantiate_identity().skip_norm_wip())
631633
.next()
632-
.is_some();
633-
if !has_impl {
634-
cx.emit_span_lint(
635-
MISSING_DEBUG_IMPLEMENTATIONS,
636-
item.span,
637-
BuiltinMissingDebugImpl { tcx: cx.tcx, def_id: debug },
638-
);
634+
.is_some()
635+
{
636+
return;
639637
}
638+
639+
let infcx = tcx.infer_ctxt().build(cx.typing_mode());
640+
if is_generic {
641+
let args = infcx.fresh_args_for_item(item.span, def_id.to_def_id());
642+
if infcx
643+
.type_implements_trait_shallow(
644+
debug,
645+
ty.instantiate(tcx, args).skip_norm_wip(),
646+
cx.param_env,
647+
)
648+
.is_some()
649+
{
650+
return;
651+
}
652+
} else if infcx
653+
.type_implements_trait(debug, [ty.instantiate_identity().skip_norm_wip()], cx.param_env)
654+
.must_apply_modulo_regions()
655+
{
656+
return;
657+
}
658+
659+
cx.emit_span_lint(
660+
MISSING_DEBUG_IMPLEMENTATIONS,
661+
item.span,
662+
BuiltinMissingDebugImpl { tcx: cx.tcx, def_id: debug },
663+
);
640664
}
641665
}
642666

compiler/rustc_metadata/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// tidy-alphabetical-start
22
#![allow(internal_features)]
33
#![cfg_attr(bootstrap, feature(result_option_map_or_default))]
4+
#![cfg_attr(bootstrap, feature(strip_circumfix))]
45
#![feature(error_iter)]
56
#![feature(file_buffered)]
67
#![feature(gen_blocks)]
78
#![feature(macro_metavar_expr)]
89
#![feature(min_specialization)]
910
#![feature(never_type)]
1011
#![feature(proc_macro_internals)]
11-
#![feature(strip_circumfix)]
1212
#![feature(trusted_len)]
1313
// tidy-alphabetical-end
1414

compiler/rustc_middle/src/ty/instance.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,9 @@ impl<'tcx> InstanceKind<'tcx> {
310310

311311
pub fn requires_caller_location(&self, tcx: TyCtxt<'_>) -> bool {
312312
match *self {
313-
InstanceKind::Item(def_id) | InstanceKind::Virtual(def_id, _) => {
313+
InstanceKind::Item(def_id)
314+
| InstanceKind::Virtual(def_id, _)
315+
| InstanceKind::VTableShim(def_id) => {
314316
tcx.body_codegen_attrs(def_id).flags.contains(CodegenFnAttrFlags::TRACK_CALLER)
315317
}
316318
InstanceKind::ClosureOnceShim { call_once: _, closure: _, track_caller } => {

compiler/rustc_parse/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ pub(crate) struct MissingInInForLoop {
689689
#[primary_span]
690690
pub span: Span,
691691
#[subdiagnostic]
692-
pub sub: MissingInInForLoopSub,
692+
pub sub: Option<MissingInInForLoopSub>,
693693
}
694694

695695
#[derive(Subdiagnostic)]

0 commit comments

Comments
 (0)