Skip to content

Commit 4b90300

Browse files
committed
Auto merge of #158027 - JonathanBrouwer:rollup-nUxhyJT, r=<try>
Rollup of 8 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 1162ebd + 0df317f commit 4b90300

29 files changed

Lines changed: 273 additions & 85 deletions

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_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)]

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3086,18 +3086,41 @@ impl<'a> Parser<'a> {
30863086
}
30873087

30883088
fn error_missing_in_for_loop(&mut self) {
3089-
let (span, sub): (_, fn(_) -> _) = if self.token.is_ident_named(sym::of) {
3089+
let (span, sub) = if self.token.is_ident_named(sym::of) {
30903090
// Possibly using JS syntax (#75311).
30913091
let span = self.token.span;
30923092
self.bump();
3093-
(span, errors::MissingInInForLoopSub::InNotOf)
3093+
(span, Some(errors::MissingInInForLoopSub::InNotOf(span)))
30943094
} else if self.eat(exp!(Eq)) {
3095-
(self.prev_token.span, errors::MissingInInForLoopSub::InNotEq)
3095+
let span = self.prev_token.span;
3096+
(span, Some(errors::MissingInInForLoopSub::InNotEq(span)))
30963097
} else {
3097-
(self.prev_token.span.between(self.token.span), errors::MissingInInForLoopSub::AddIn)
3098+
let span = self.prev_token.span.between(self.token.span);
3099+
let sub = (!self.for_loop_head_has_in())
3100+
.then_some(errors::MissingInInForLoopSub::AddIn(span));
3101+
(span, sub)
30983102
};
30993103

3100-
self.dcx().emit_err(errors::MissingInInForLoop { span, sub: sub(span) });
3104+
self.dcx().emit_err(errors::MissingInInForLoop { span, sub });
3105+
}
3106+
3107+
/// Whether the `for` loop header already contains an `in` before its body.
3108+
/// If it does, the binding is malformed (e.g. `for i i in 0..10`) rather
3109+
/// than missing `in`, so suggesting another `in` would just be invalid too.
3110+
fn for_loop_head_has_in(&self) -> bool {
3111+
let mut dist = 0;
3112+
loop {
3113+
let (is_in, is_end) = self.look_ahead(dist, |t| {
3114+
(t.is_keyword(kw::In), matches!(t.kind, token::OpenBrace | token::Eof))
3115+
});
3116+
if is_in {
3117+
return true;
3118+
}
3119+
if is_end {
3120+
return false;
3121+
}
3122+
dist += 1;
3123+
}
31013124
}
31023125

31033126
/// Parses a `while` or `while let` expression (`while` token already eaten).

0 commit comments

Comments
 (0)