Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1716932

Browse files
committed
Auto merge of rust-lang#109130 - matthiaskrgr:rollup-dm3jza6, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#108722 (Support for Fuchsia RISC-V target) - rust-lang#108880 (Remove tests/ui/impl-trait/in-trait/new-lowering-strategy in favor of using revisions on existing tests) - rust-lang#108909 (Fix object safety checks for new RPITITs) - rust-lang#108915 (Remove some direct calls to local_def_id_to_hir_id on diagnostics) - rust-lang#108923 (Make fns from other crates with RPITIT work for -Zlower-impl-trait-in-trait-to-assoc-ty) - rust-lang#109101 (Fall back to old metadata computation when type references errors) - rust-lang#109105 (Don't ICE for late-bound consts across `AnonConstBoundary`) - rust-lang#109110 (Don't codegen impossible to satisfy impls) - rust-lang#109116 (Emit diagnostic when calling methods on the unit type in method chains) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2e7034e + b17ee10 commit 1716932

File tree

84 files changed

+612
-106
lines changed

Some content is hidden

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

84 files changed

+612
-106
lines changed

compiler/rustc_hir/src/definitions.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,12 @@ impl DefPathData {
404404
match *self {
405405
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
406406

407+
// We use this name when collecting `ModChild`s.
408+
// FIXME this could probably be removed with some refactoring to the name resolver.
409+
ImplTraitAssocTy => Some(kw::Empty),
410+
407411
Impl | ForeignMod | CrateRoot | Use | GlobalAsm | ClosureExpr | Ctor | AnonConst
408-
| ImplTrait | ImplTraitAssocTy => None,
412+
| ImplTrait => None,
409413
}
410414
}
411415

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
14401440
tcx.associated_items(pred.def_id())
14411441
.in_definition_order()
14421442
.filter(|item| item.kind == ty::AssocKind::Type)
1443+
.filter(|item| tcx.opt_rpitit_info(item.def_id).is_none())
14431444
.map(|item| item.def_id),
14441445
);
14451446
}

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,25 +1427,25 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
14271427
if let ResolvedArg::LateBound(..) = def && crossed_anon_const {
14281428
let use_span = self.tcx.hir().span(hir_id);
14291429
let def_span = self.tcx.def_span(param_def_id);
1430-
match self.tcx.def_kind(param_def_id) {
1430+
let guar = match self.tcx.def_kind(param_def_id) {
14311431
DefKind::ConstParam => {
14321432
self.tcx.sess.emit_err(errors::CannotCaptureLateBoundInAnonConst::Const {
14331433
use_span,
14341434
def_span,
1435-
});
1435+
})
14361436
}
14371437
DefKind::TyParam => {
14381438
self.tcx.sess.emit_err(errors::CannotCaptureLateBoundInAnonConst::Type {
14391439
use_span,
14401440
def_span,
1441-
});
1441+
})
14421442
}
14431443
_ => unreachable!(),
1444-
}
1445-
return;
1444+
};
1445+
self.map.defs.insert(hir_id, ResolvedArg::Error(guar));
1446+
} else {
1447+
self.map.defs.insert(hir_id, def);
14461448
}
1447-
1448-
self.map.defs.insert(hir_id, def);
14491449
return;
14501450
}
14511451

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8383
self.annotate_expected_due_to_let_ty(err, expr, error);
8484
self.emit_type_mismatch_suggestions(err, expr, expr_ty, expected, expected_ty_expr, error);
8585
self.note_type_is_not_clone(err, expected, expr_ty, expr);
86-
self.note_internal_mutation_in_method(err, expr, expected, expr_ty);
86+
self.note_internal_mutation_in_method(err, expr, Some(expected), expr_ty);
8787
self.check_for_range_as_method_call(err, expr, expr_ty, expected);
8888
self.check_for_binding_assigned_block_without_tail_expression(err, expr, expr_ty, expected);
8989
self.check_wrong_return_type_due_to_generic_arg(err, expr, expr_ty);

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -950,44 +950,75 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
950950
&self,
951951
err: &mut Diagnostic,
952952
expr: &hir::Expr<'_>,
953-
expected: Ty<'tcx>,
953+
expected: Option<Ty<'tcx>>,
954954
found: Ty<'tcx>,
955955
) {
956956
if found != self.tcx.types.unit {
957957
return;
958958
}
959-
if let ExprKind::MethodCall(path_segment, rcvr, ..) = expr.kind {
960-
if self
961-
.typeck_results
959+
960+
let ExprKind::MethodCall(path_segment, rcvr, ..) = expr.kind else {
961+
return;
962+
};
963+
964+
let rcvr_has_the_expected_type = self
965+
.typeck_results
966+
.borrow()
967+
.expr_ty_adjusted_opt(rcvr)
968+
.and_then(|ty| expected.map(|expected_ty| expected_ty.peel_refs() == ty.peel_refs()))
969+
.unwrap_or(false);
970+
971+
let prev_call_mutates_and_returns_unit = || {
972+
self.typeck_results
962973
.borrow()
963-
.expr_ty_adjusted_opt(rcvr)
964-
.map_or(true, |ty| expected.peel_refs() != ty.peel_refs())
965-
{
966-
return;
967-
}
968-
let mut sp = MultiSpan::from_span(path_segment.ident.span);
969-
sp.push_span_label(
970-
path_segment.ident.span,
971-
format!(
972-
"this call modifies {} in-place",
973-
match rcvr.kind {
974-
ExprKind::Path(QPath::Resolved(
975-
None,
976-
hir::Path { segments: [segment], .. },
977-
)) => format!("`{}`", segment.ident),
978-
_ => "its receiver".to_string(),
979-
}
980-
),
981-
);
974+
.type_dependent_def_id(expr.hir_id)
975+
.map(|def_id| self.tcx.fn_sig(def_id).skip_binder().skip_binder())
976+
.and_then(|sig| sig.inputs_and_output.split_last())
977+
.map(|(output, inputs)| {
978+
output.is_unit()
979+
&& inputs
980+
.get(0)
981+
.and_then(|self_ty| self_ty.ref_mutability())
982+
.map_or(false, rustc_ast::Mutability::is_mut)
983+
})
984+
.unwrap_or(false)
985+
};
986+
987+
if !(rcvr_has_the_expected_type || prev_call_mutates_and_returns_unit()) {
988+
return;
989+
}
990+
991+
let mut sp = MultiSpan::from_span(path_segment.ident.span);
992+
sp.push_span_label(
993+
path_segment.ident.span,
994+
format!(
995+
"this call modifies {} in-place",
996+
match rcvr.kind {
997+
ExprKind::Path(QPath::Resolved(
998+
None,
999+
hir::Path { segments: [segment], .. },
1000+
)) => format!("`{}`", segment.ident),
1001+
_ => "its receiver".to_string(),
1002+
}
1003+
),
1004+
);
1005+
1006+
let modifies_rcvr_note =
1007+
format!("method `{}` modifies its receiver in-place", path_segment.ident);
1008+
if rcvr_has_the_expected_type {
9821009
sp.push_span_label(
9831010
rcvr.span,
9841011
"you probably want to use this value after calling the method...",
9851012
);
1013+
err.span_note(sp, &modifies_rcvr_note);
1014+
err.note(&format!("...instead of the `()` output of method `{}`", path_segment.ident));
1015+
} else if let ExprKind::MethodCall(..) = rcvr.kind {
9861016
err.span_note(
9871017
sp,
988-
&format!("method `{}` modifies its receiver in-place", path_segment.ident),
1018+
modifies_rcvr_note.clone() + ", it is not meant to be used in method chains.",
9891019
);
990-
err.note(&format!("...instead of the `()` output of method `{}`", path_segment.ident));
1020+
} else {
1021+
err.span_note(sp, &modifies_rcvr_note);
9911022
}
9921023
}
9931024

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
416416
);
417417
probe.is_ok()
418418
});
419+
420+
self.note_internal_mutation_in_method(
421+
&mut err,
422+
rcvr_expr,
423+
expected.to_option(&self),
424+
rcvr_ty,
425+
);
419426
}
420427

421428
let mut custom_span_label = false;

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,13 +1356,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13561356
debug!("EncodeContext::encode_info_for_impl_item({:?})", def_id);
13571357
let tcx = self.tcx;
13581358

1359-
let ast_item = self.tcx.hir().expect_impl_item(def_id.expect_local());
1360-
self.tables.impl_defaultness.set_some(def_id.index, ast_item.defaultness);
1359+
let defaultness = self.tcx.impl_defaultness(def_id.expect_local());
1360+
self.tables.impl_defaultness.set_some(def_id.index, defaultness);
13611361
let impl_item = self.tcx.associated_item(def_id);
13621362
self.tables.assoc_container.set_some(def_id.index, impl_item.container);
13631363

13641364
match impl_item.kind {
13651365
ty::AssocKind::Fn => {
1366+
let ast_item = self.tcx.hir().expect_impl_item(def_id.expect_local());
13661367
let hir::ImplItemKind::Fn(ref sig, body) = ast_item.kind else { bug!() };
13671368
self.tables.asyncness.set_some(def_id.index, sig.header.asyncness);
13681369
record_array!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body));

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl<'hir> Map<'hir> {
316316
/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
317317
#[inline]
318318
pub fn find_by_def_id(self, id: LocalDefId) -> Option<Node<'hir>> {
319-
self.find(self.local_def_id_to_hir_id(id))
319+
self.find(self.tcx.opt_local_def_id_to_hir_id(id)?)
320320
}
321321

322322
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
@@ -333,7 +333,7 @@ impl<'hir> Map<'hir> {
333333
}
334334

335335
pub fn get_if_local(self, id: DefId) -> Option<Node<'hir>> {
336-
id.as_local().and_then(|id| self.find(self.local_def_id_to_hir_id(id)))
336+
id.as_local().and_then(|id| self.find(self.tcx.opt_local_def_id_to_hir_id(id)?))
337337
}
338338

339339
pub fn get_generics(self, id: LocalDefId) -> Option<&'hir Generics<'hir>> {

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,11 @@ where
730730
*/
731731
};
732732

733-
let metadata = if let Some(metadata_def_id) = tcx.lang_items().metadata_type() {
733+
let metadata = if let Some(metadata_def_id) = tcx.lang_items().metadata_type()
734+
// Projection eagerly bails out when the pointee references errors,
735+
// fall back to structurally deducing metadata.
736+
&& !pointee.references_error()
737+
{
734738
let metadata = tcx.normalize_erasing_regions(
735739
cx.param_env(),
736740
tcx.mk_projection(metadata_def_id, [pointee]),

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,21 @@ fn create_mono_items_for_default_impls<'tcx>(
13261326
return;
13271327
}
13281328

1329+
// Unlike 'lazy' monomorphization that begins by collecting items transitively
1330+
// called by `main` or other global items, when eagerly monomorphizing impl
1331+
// items, we never actually check that the predicates of this impl are satisfied
1332+
// in a empty reveal-all param env (i.e. with no assumptions).
1333+
//
1334+
// Even though this impl has no substitutions, because we don't consider higher-
1335+
// ranked predicates such as `for<'a> &'a mut [u8]: Copy` to be trivially false,
1336+
// we must now check that the impl has no impossible-to-satisfy predicates.
1337+
if tcx.subst_and_check_impossible_predicates((
1338+
item.owner_id.to_def_id(),
1339+
&InternalSubsts::identity_for_item(tcx, item.owner_id.to_def_id()),
1340+
)) {
1341+
return;
1342+
}
1343+
13291344
let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) else {
13301345
return;
13311346
};

0 commit comments

Comments
 (0)