Skip to content

Commit adc719d

Browse files
committed
Auto merge of #112324 - matthiaskrgr:rollup-qscmi3c, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #112081 (Avoid ICE on `#![doc(test(...)]` with literal parameter) - #112196 (Resolve vars in result from `scrape_region_constraints`) - #112303 (Normalize in infcx instead of globally for `Option::as_deref` suggestion) - #112316 (Ensure space is inserted after keyword in `unused_delims`) - #112318 (Merge method, type and const object safety checks) - #112322 (Don't mention `IMPLIED_BOUNDS_ENTAILMENT` if signatures reference error) Failed merges: - #112251 (rustdoc: convert `if let Some()` that always matches to variable) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e6d4725 + dcdd867 commit adc719d

27 files changed

+364
-136
lines changed

Diff for: compiler/rustc_hir_analysis/src/astconv/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16011601
tcx.associated_items(pred.def_id())
16021602
.in_definition_order()
16031603
.filter(|item| item.kind == ty::AssocKind::Type)
1604-
.filter(|item| tcx.opt_rpitit_info(item.def_id).is_none())
1604+
.filter(|item| item.opt_rpitit_info.is_none())
16051605
.map(|item| item.def_id),
16061606
);
16071607
}
@@ -1643,6 +1643,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16431643
}
16441644
}
16451645

1646+
// `dyn Trait<Assoc = Foo>` desugars to (not Rust syntax) `dyn Trait where <Self as Trait>::Assoc = Foo`.
1647+
// So every `Projection` clause is an `Assoc = Foo` bound. `associated_types` contains all associated
1648+
// types's `DefId`, so the following loop removes all the `DefIds` of the associated types that have a
1649+
// corresponding `Projection` clause
16461650
for (projection_bound, _) in &projection_bounds {
16471651
for def_ids in associated_types.values_mut() {
16481652
def_ids.remove(&projection_bound.projection_def_id());

Diff for: compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ fn compare_method_predicate_entailment<'tcx>(
302302
return Err(emitted);
303303
}
304304

305-
if check_implied_wf == CheckImpliedWfMode::Check {
305+
if check_implied_wf == CheckImpliedWfMode::Check && !(impl_sig, trait_sig).references_error() {
306306
// We need to check that the impl's args are well-formed given
307307
// the hybrid param-env (impl + trait method where-clauses).
308308
ocx.register_obligation(traits::Obligation::new(
@@ -1216,7 +1216,7 @@ fn compare_number_of_generics<'tcx>(
12161216
// has mismatched type or const generic arguments, then the method that it's
12171217
// inheriting the generics from will also have mismatched arguments, and
12181218
// we'll report an error for that instead. Delay a bug for safety, though.
1219-
if tcx.opt_rpitit_info(trait_.def_id).is_some() {
1219+
if trait_.opt_rpitit_info.is_some() {
12201220
return Err(tcx.sess.delay_span_bug(
12211221
rustc_span::DUMMY_SP,
12221222
"errors comparing numbers of generics of trait/impl functions were not emitted",
@@ -2006,7 +2006,7 @@ pub(super) fn check_type_bounds<'tcx>(
20062006
// A synthetic impl Trait for RPITIT desugaring has no HIR, which we currently use to get the
20072007
// span for an impl's associated type. Instead, for these, use the def_span for the synthesized
20082008
// associated type.
2009-
let impl_ty_span = if tcx.opt_rpitit_info(impl_ty.def_id).is_some() {
2009+
let impl_ty_span = if impl_ty.opt_rpitit_info.is_some() {
20102010
tcx.def_span(impl_ty_def_id)
20112011
} else {
20122012
match tcx.hir().get_by_def_id(impl_ty_def_id) {

Diff for: compiler/rustc_hir_analysis/src/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ fn missing_items_err(
188188
full_impl_span: Span,
189189
) {
190190
let missing_items =
191-
missing_items.iter().filter(|trait_item| tcx.opt_rpitit_info(trait_item.def_id).is_none());
191+
missing_items.iter().filter(|trait_item| trait_item.opt_rpitit_info.is_none());
192192

193193
let missing_items_msg = missing_items
194194
.clone()

Diff for: compiler/rustc_lint/src/unused.rs

+42-17
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ trait UnusedDelimLint {
556556
followed_by_block: bool,
557557
left_pos: Option<BytePos>,
558558
right_pos: Option<BytePos>,
559+
is_kw: bool,
559560
);
560561

561562
fn is_expr_delims_necessary(
@@ -624,6 +625,7 @@ trait UnusedDelimLint {
624625
ctx: UnusedDelimsCtx,
625626
left_pos: Option<BytePos>,
626627
right_pos: Option<BytePos>,
628+
is_kw: bool,
627629
) {
628630
// If `value` has `ExprKind::Err`, unused delim lint can be broken.
629631
// For example, the following code caused ICE.
@@ -667,7 +669,7 @@ trait UnusedDelimLint {
667669
left_pos.is_some_and(|s| s >= value.span.lo()),
668670
right_pos.is_some_and(|s| s <= value.span.hi()),
669671
);
670-
self.emit_unused_delims(cx, value.span, spans, ctx.into(), keep_space);
672+
self.emit_unused_delims(cx, value.span, spans, ctx.into(), keep_space, is_kw);
671673
}
672674

673675
fn emit_unused_delims(
@@ -677,6 +679,7 @@ trait UnusedDelimLint {
677679
spans: Option<(Span, Span)>,
678680
msg: &str,
679681
keep_space: (bool, bool),
682+
is_kw: bool,
680683
) {
681684
let primary_span = if let Some((lo, hi)) = spans {
682685
if hi.is_empty() {
@@ -690,7 +693,7 @@ trait UnusedDelimLint {
690693
let suggestion = spans.map(|(lo, hi)| {
691694
let sm = cx.sess().source_map();
692695
let lo_replace =
693-
if keep_space.0 &&
696+
if (keep_space.0 || is_kw) &&
694697
let Ok(snip) = sm.span_to_prev_source(lo) && !snip.ends_with(' ') {
695698
" "
696699
} else {
@@ -720,15 +723,15 @@ trait UnusedDelimLint {
720723

721724
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
722725
use rustc_ast::ExprKind::*;
723-
let (value, ctx, followed_by_block, left_pos, right_pos) = match e.kind {
726+
let (value, ctx, followed_by_block, left_pos, right_pos, is_kw) = match e.kind {
724727
// Do not lint `unused_braces` in `if let` expressions.
725728
If(ref cond, ref block, _)
726729
if !matches!(cond.kind, Let(_, _, _))
727730
|| Self::LINT_EXPR_IN_PATTERN_MATCHING_CTX =>
728731
{
729732
let left = e.span.lo() + rustc_span::BytePos(2);
730733
let right = block.span.lo();
731-
(cond, UnusedDelimsCtx::IfCond, true, Some(left), Some(right))
734+
(cond, UnusedDelimsCtx::IfCond, true, Some(left), Some(right), true)
732735
}
733736

734737
// Do not lint `unused_braces` in `while let` expressions.
@@ -738,27 +741,27 @@ trait UnusedDelimLint {
738741
{
739742
let left = e.span.lo() + rustc_span::BytePos(5);
740743
let right = block.span.lo();
741-
(cond, UnusedDelimsCtx::WhileCond, true, Some(left), Some(right))
744+
(cond, UnusedDelimsCtx::WhileCond, true, Some(left), Some(right), true)
742745
}
743746

744747
ForLoop(_, ref cond, ref block, ..) => {
745-
(cond, UnusedDelimsCtx::ForIterExpr, true, None, Some(block.span.lo()))
748+
(cond, UnusedDelimsCtx::ForIterExpr, true, None, Some(block.span.lo()), true)
746749
}
747750

748751
Match(ref head, _) if Self::LINT_EXPR_IN_PATTERN_MATCHING_CTX => {
749752
let left = e.span.lo() + rustc_span::BytePos(5);
750-
(head, UnusedDelimsCtx::MatchScrutineeExpr, true, Some(left), None)
753+
(head, UnusedDelimsCtx::MatchScrutineeExpr, true, Some(left), None, true)
751754
}
752755

753756
Ret(Some(ref value)) => {
754757
let left = e.span.lo() + rustc_span::BytePos(3);
755-
(value, UnusedDelimsCtx::ReturnValue, false, Some(left), None)
758+
(value, UnusedDelimsCtx::ReturnValue, false, Some(left), None, true)
756759
}
757760

758-
Index(_, ref value) => (value, UnusedDelimsCtx::IndexExpr, false, None, None),
761+
Index(_, ref value) => (value, UnusedDelimsCtx::IndexExpr, false, None, None, false),
759762

760763
Assign(_, ref value, _) | AssignOp(.., ref value) => {
761-
(value, UnusedDelimsCtx::AssignedValue, false, None, None)
764+
(value, UnusedDelimsCtx::AssignedValue, false, None, None, false)
762765
}
763766
// either function/method call, or something this lint doesn't care about
764767
ref call_or_other => {
@@ -778,12 +781,20 @@ trait UnusedDelimLint {
778781
return;
779782
}
780783
for arg in args_to_check {
781-
self.check_unused_delims_expr(cx, arg, ctx, false, None, None);
784+
self.check_unused_delims_expr(cx, arg, ctx, false, None, None, false);
782785
}
783786
return;
784787
}
785788
};
786-
self.check_unused_delims_expr(cx, &value, ctx, followed_by_block, left_pos, right_pos);
789+
self.check_unused_delims_expr(
790+
cx,
791+
&value,
792+
ctx,
793+
followed_by_block,
794+
left_pos,
795+
right_pos,
796+
is_kw,
797+
);
787798
}
788799

789800
fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) {
@@ -794,7 +805,7 @@ trait UnusedDelimLint {
794805
None => UnusedDelimsCtx::AssignedValue,
795806
Some(_) => UnusedDelimsCtx::AssignedValueLetElse,
796807
};
797-
self.check_unused_delims_expr(cx, init, ctx, false, None, None);
808+
self.check_unused_delims_expr(cx, init, ctx, false, None, None, false);
798809
}
799810
}
800811
StmtKind::Expr(ref expr) => {
@@ -805,6 +816,7 @@ trait UnusedDelimLint {
805816
false,
806817
None,
807818
None,
819+
false,
808820
);
809821
}
810822
_ => {}
@@ -824,6 +836,7 @@ trait UnusedDelimLint {
824836
false,
825837
None,
826838
None,
839+
false,
827840
);
828841
}
829842
}
@@ -879,6 +892,7 @@ impl UnusedDelimLint for UnusedParens {
879892
followed_by_block: bool,
880893
left_pos: Option<BytePos>,
881894
right_pos: Option<BytePos>,
895+
is_kw: bool,
882896
) {
883897
match value.kind {
884898
ast::ExprKind::Paren(ref inner) => {
@@ -893,7 +907,7 @@ impl UnusedDelimLint for UnusedParens {
893907
_,
894908
) if node.lazy()))
895909
{
896-
self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos)
910+
self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos, is_kw)
897911
}
898912
}
899913
ast::ExprKind::Let(_, ref expr, _) => {
@@ -904,6 +918,7 @@ impl UnusedDelimLint for UnusedParens {
904918
followed_by_block,
905919
None,
906920
None,
921+
false,
907922
);
908923
}
909924
_ => {}
@@ -942,7 +957,7 @@ impl UnusedParens {
942957
.span
943958
.find_ancestor_inside(value.span)
944959
.map(|inner| (value.span.with_hi(inner.lo()), value.span.with_lo(inner.hi())));
945-
self.emit_unused_delims(cx, value.span, spans, "pattern", keep_space);
960+
self.emit_unused_delims(cx, value.span, spans, "pattern", keep_space, false);
946961
}
947962
}
948963
}
@@ -967,6 +982,7 @@ impl EarlyLintPass for UnusedParens {
967982
true,
968983
None,
969984
None,
985+
true,
970986
);
971987
for stmt in &block.stmts {
972988
<Self as UnusedDelimLint>::check_stmt(self, cx, stmt);
@@ -985,6 +1001,7 @@ impl EarlyLintPass for UnusedParens {
9851001
false,
9861002
None,
9871003
None,
1004+
true,
9881005
);
9891006
}
9901007
}
@@ -1043,6 +1060,7 @@ impl EarlyLintPass for UnusedParens {
10431060
false,
10441061
None,
10451062
None,
1063+
false,
10461064
);
10471065
}
10481066
ast::TyKind::Paren(r) => {
@@ -1057,7 +1075,7 @@ impl EarlyLintPass for UnusedParens {
10571075
.find_ancestor_inside(ty.span)
10581076
.map(|r| (ty.span.with_hi(r.lo()), ty.span.with_lo(r.hi())));
10591077

1060-
self.emit_unused_delims(cx, ty.span, spans, "type", (false, false));
1078+
self.emit_unused_delims(cx, ty.span, spans, "type", (false, false), false);
10611079
}
10621080
}
10631081
self.with_self_ty_parens = false;
@@ -1130,6 +1148,7 @@ impl UnusedDelimLint for UnusedBraces {
11301148
followed_by_block: bool,
11311149
left_pos: Option<BytePos>,
11321150
right_pos: Option<BytePos>,
1151+
is_kw: bool,
11331152
) {
11341153
match value.kind {
11351154
ast::ExprKind::Block(ref inner, None)
@@ -1170,7 +1189,7 @@ impl UnusedDelimLint for UnusedBraces {
11701189
&& !value.span.from_expansion()
11711190
&& !inner.span.from_expansion()
11721191
{
1173-
self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos)
1192+
self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos, is_kw)
11741193
}
11751194
}
11761195
}
@@ -1183,6 +1202,7 @@ impl UnusedDelimLint for UnusedBraces {
11831202
followed_by_block,
11841203
None,
11851204
None,
1205+
false,
11861206
);
11871207
}
11881208
_ => {}
@@ -1207,6 +1227,7 @@ impl EarlyLintPass for UnusedBraces {
12071227
false,
12081228
None,
12091229
None,
1230+
false,
12101231
);
12111232
}
12121233
}
@@ -1220,6 +1241,7 @@ impl EarlyLintPass for UnusedBraces {
12201241
false,
12211242
None,
12221243
None,
1244+
false,
12231245
);
12241246
}
12251247
}
@@ -1233,6 +1255,7 @@ impl EarlyLintPass for UnusedBraces {
12331255
false,
12341256
None,
12351257
None,
1258+
false,
12361259
);
12371260
}
12381261
}
@@ -1247,6 +1270,7 @@ impl EarlyLintPass for UnusedBraces {
12471270
false,
12481271
None,
12491272
None,
1273+
false,
12501274
);
12511275
}
12521276

@@ -1258,6 +1282,7 @@ impl EarlyLintPass for UnusedBraces {
12581282
false,
12591283
None,
12601284
None,
1285+
false,
12611286
);
12621287
}
12631288

Diff for: compiler/rustc_passes/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ passes_doc_keyword_not_mod =
211211
passes_doc_keyword_only_impl =
212212
`#[doc(keyword = "...")]` should be used on impl blocks
213213
214+
passes_doc_test_literal = `#![doc(test(...)]` does not take a literal
215+
214216
passes_doc_test_takes_list =
215217
`#[doc(test(...)]` takes a list of attributes
216218

Diff for: compiler/rustc_passes/src/check_attr.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -944,21 +944,28 @@ impl CheckAttrVisitor<'_> {
944944
let mut is_valid = true;
945945
if let Some(metas) = meta.meta_item_list() {
946946
for i_meta in metas {
947-
match i_meta.name_or_empty() {
948-
sym::attr | sym::no_crate_inject => {}
949-
_ => {
947+
match (i_meta.name_or_empty(), i_meta.meta_item()) {
948+
(sym::attr | sym::no_crate_inject, _) => {}
949+
(_, Some(m)) => {
950950
self.tcx.emit_spanned_lint(
951951
INVALID_DOC_ATTRIBUTES,
952952
hir_id,
953953
i_meta.span(),
954954
errors::DocTestUnknown {
955-
path: rustc_ast_pretty::pprust::path_to_string(
956-
&i_meta.meta_item().unwrap().path,
957-
),
955+
path: rustc_ast_pretty::pprust::path_to_string(&m.path),
958956
},
959957
);
960958
is_valid = false;
961959
}
960+
(_, None) => {
961+
self.tcx.emit_spanned_lint(
962+
INVALID_DOC_ATTRIBUTES,
963+
hir_id,
964+
i_meta.span(),
965+
errors::DocTestLiteral,
966+
);
967+
is_valid = false;
968+
}
962969
}
963970
}
964971
} else {

Diff for: compiler/rustc_passes/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ pub struct DocTestUnknown {
281281
pub path: String,
282282
}
283283

284+
#[derive(LintDiagnostic)]
285+
#[diag(passes_doc_test_literal)]
286+
pub struct DocTestLiteral;
287+
284288
#[derive(LintDiagnostic)]
285289
#[diag(passes_doc_test_takes_list)]
286290
pub struct DocTestTakesList;

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3592,8 +3592,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
35923592
// Extract `<U as Deref>::Target` assoc type and check that it is `T`
35933593
&& let Some(deref_target_did) = tcx.lang_items().deref_target()
35943594
&& let projection = tcx.mk_projection(deref_target_did, tcx.mk_substs(&[ty::GenericArg::from(found_ty)]))
3595-
&& let Ok(deref_target) = tcx.try_normalize_erasing_regions(param_env, projection)
3596-
&& deref_target == target_ty
3595+
&& let InferOk { value: deref_target, obligations } = infcx.at(&ObligationCause::dummy(), param_env).normalize(projection)
3596+
&& obligations.iter().all(|obligation| infcx.predicate_must_hold_modulo_regions(obligation))
3597+
&& infcx.can_eq(param_env, deref_target, target_ty)
35973598
{
35983599
let help = if let hir::Mutability::Mut = needs_mut
35993600
&& let Some(deref_mut_did) = tcx.lang_items().deref_mut_trait()

0 commit comments

Comments
 (0)