Skip to content

Commit 52cea08

Browse files
committed
Auto merge of rust-lang#121491 - matthiaskrgr:rollup-wkzqawy, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#121434 (Fix rust-lang#121208 fallout) - rust-lang#121471 (When encountering `<&T as Clone>::clone(x)` because `T: Clone`, suggest `#[derive(Clone)]`) - rust-lang#121476 (remove `llvm.assertions=true` in compiler profile) - rust-lang#121479 (fix generalizer unsoundness) - rust-lang#121480 (Fix more rust-lang#121208 fallout) - rust-lang#121482 (Allow for a missing `adt_def` in `NamePrivacyVisitor`.) - rust-lang#121484 (coverage: Use variable name `this` in `CoverageGraph::from_mir`) - rust-lang#121487 (Explicitly call `emit_stashed_diagnostics`.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ea2cc43 + 6ee43bc commit 52cea08

File tree

34 files changed

+377
-133
lines changed

34 files changed

+377
-133
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16361636
if let Some(old_def_id) = self.orig_opt_local_def_id(param) {
16371637
old_def_id
16381638
} else {
1639-
self.dcx().span_bug(lifetime.ident.span, "no def-id for fresh lifetime");
1639+
self.dcx()
1640+
.span_delayed_bug(lifetime.ident.span, "no def-id for fresh lifetime");
1641+
continue;
16401642
}
16411643
}
16421644

compiler/rustc_borrowck/src/type_check/relate_tys.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
123123
// `handle_opaque_type` cannot handle subtyping, so to support subtyping
124124
// we instead eagerly generalize here. This is a bit of a mess but will go
125125
// away once we're using the new solver.
126-
let mut enable_subtyping = |ty, ty_is_expected| {
126+
//
127+
// Given `opaque rel B`, we create a new infer var `ty_vid` constrain it
128+
// by using `ty_vid rel B` and then finally and end by equating `ty_vid` to
129+
// the opaque.
130+
let mut enable_subtyping = |ty, opaque_is_expected| {
127131
let ty_vid = infcx.next_ty_var_id_in_universe(
128132
TypeVariableOrigin {
129133
kind: TypeVariableOriginKind::MiscVariable,
@@ -132,15 +136,15 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
132136
ty::UniverseIndex::ROOT,
133137
);
134138

135-
let variance = if ty_is_expected {
139+
let variance = if opaque_is_expected {
136140
self.ambient_variance
137141
} else {
138142
self.ambient_variance.xform(ty::Contravariant)
139143
};
140144

141145
self.type_checker.infcx.instantiate_ty_var(
142146
self,
143-
ty_is_expected,
147+
opaque_is_expected,
144148
ty_vid,
145149
variance,
146150
ty,
@@ -149,8 +153,8 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
149153
};
150154

151155
let (a, b) = match (a.kind(), b.kind()) {
152-
(&ty::Alias(ty::Opaque, ..), _) => (a, enable_subtyping(b, false)?),
153-
(_, &ty::Alias(ty::Opaque, ..)) => (enable_subtyping(a, true)?, b),
156+
(&ty::Alias(ty::Opaque, ..), _) => (a, enable_subtyping(b, true)?),
157+
(_, &ty::Alias(ty::Opaque, ..)) => (enable_subtyping(a, false)?, b),
154158
_ => unreachable!(
155159
"expected at least one opaque type in `relate_opaques`, got {a} and {b}."
156160
),

compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,17 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
154154
trait_m_sig.inputs_and_output,
155155
));
156156
if !ocx.select_all_or_error().is_empty() {
157-
// This code path is not reached in any tests, but may be reachable. If
158-
// this is triggered, it should be converted to `delayed_bug` and the
159-
// triggering case turned into a test.
160-
tcx.dcx().bug("encountered errors when checking RPITIT refinement (selection)");
157+
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (selection)");
158+
return;
161159
}
162160
let outlives_env = OutlivesEnvironment::with_bounds(
163161
param_env,
164162
infcx.implied_bounds_tys(param_env, impl_m.def_id.expect_local(), &implied_wf_types),
165163
);
166164
let errors = infcx.resolve_regions(&outlives_env);
167165
if !errors.is_empty() {
168-
// This code path is not reached in any tests, but may be reachable. If
169-
// this is triggered, it should be converted to `delayed_bug` and the
170-
// triggering case turned into a test.
171-
tcx.dcx().bug("encountered errors when checking RPITIT refinement (regions)");
166+
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (regions)");
167+
return;
172168
}
173169
// Resolve any lifetime variables that may have been introduced during normalization.
174170
let Ok((trait_bounds, impl_bounds)) = infcx.fully_resolve((trait_bounds, impl_bounds)) else {

compiler/rustc_hir_analysis/src/collect/generics_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
315315

316316
if is_host_effect {
317317
if let Some(idx) = host_effect_index {
318-
tcx.dcx().span_bug(
318+
tcx.dcx().span_delayed_bug(
319319
param.span,
320320
format!("parent also has host effect param? index: {idx}, def: {def_id:?}"),
321321
);

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7777
// coercions from ! to `expected`.
7878
if ty.is_never() {
7979
if let Some(_) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
80-
self.dcx()
81-
.span_bug(expr.span, "expression with never type wound up being adjusted");
80+
let reported = self.dcx().span_delayed_bug(
81+
expr.span,
82+
"expression with never type wound up being adjusted",
83+
);
84+
return Ty::new_error(self.tcx(), reported);
8285
}
8386

8487
let adj_ty = self.next_ty_var(TypeVariableOrigin {

compiler/rustc_hir_typeck/src/mem_categorization.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,8 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
582582
match ty.kind() {
583583
ty::Tuple(args) => Ok(args.len()),
584584
_ => {
585-
self.tcx().dcx().span_bug(span, "tuple pattern not applied to a tuple");
585+
self.tcx().dcx().span_delayed_bug(span, "tuple pattern not applied to a tuple");
586+
Err(())
586587
}
587588
}
588589
}

compiler/rustc_infer/src/infer/relate/generalize.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ impl<'tcx> InferCtxt<'tcx> {
2626
/// This is *not* expected to be used anywhere except for an implementation of
2727
/// `TypeRelation`. Do not use this, and instead please use `At::eq`, for all
2828
/// other usecases (i.e. setting the value of a type var).
29-
#[instrument(level = "debug", skip(self, relation, target_is_expected))]
29+
#[instrument(level = "debug", skip(self, relation))]
3030
pub fn instantiate_ty_var<R: ObligationEmittingRelation<'tcx>>(
3131
&self,
3232
relation: &mut R,
3333
target_is_expected: bool,
3434
target_vid: ty::TyVid,
35-
ambient_variance: ty::Variance,
35+
instantiation_variance: ty::Variance,
3636
source_ty: Ty<'tcx>,
3737
) -> RelateResult<'tcx, ()> {
3838
debug_assert!(self.inner.borrow_mut().type_variables().probe(target_vid).is_unknown());
@@ -46,7 +46,7 @@ impl<'tcx> InferCtxt<'tcx> {
4646
//
4747
// We then relate `generalized_ty <: source_ty`,adding constraints like `'x: '?2` and `?1 <: ?3`.
4848
let Generalization { value_may_be_infer: generalized_ty, has_unconstrained_ty_var } =
49-
self.generalize(relation.span(), target_vid, ambient_variance, source_ty)?;
49+
self.generalize(relation.span(), target_vid, instantiation_variance, source_ty)?;
5050

5151
// Constrain `b_vid` to the generalized type `generalized_ty`.
5252
if let &ty::Infer(ty::TyVar(generalized_vid)) = generalized_ty.kind() {
@@ -73,7 +73,7 @@ impl<'tcx> InferCtxt<'tcx> {
7373
// the alias can be normalized to something which does not
7474
// mention `?0`.
7575
if self.next_trait_solver() {
76-
let (lhs, rhs, direction) = match ambient_variance {
76+
let (lhs, rhs, direction) = match instantiation_variance {
7777
ty::Variance::Invariant => {
7878
(generalized_ty.into(), source_ty.into(), AliasRelationDirection::Equate)
7979
}
@@ -106,22 +106,28 @@ impl<'tcx> InferCtxt<'tcx> {
106106
}
107107
}
108108
} else {
109-
// HACK: make sure that we `a_is_expected` continues to be
110-
// correct when relating the generalized type with the source.
109+
// NOTE: The `instantiation_variance` is not the same variance as
110+
// used by the relation. When instantiating `b`, `target_is_expected`
111+
// is flipped and the `instantion_variance` is also flipped. To
112+
// constrain the `generalized_ty` while using the original relation,
113+
// we therefore only have to flip the arguments.
114+
//
115+
// ```ignore (not code)
116+
// ?a rel B
117+
// instantiate_ty_var(?a, B) # expected and variance not flipped
118+
// B' rel B
119+
// ```
120+
// or
121+
// ```ignore (not code)
122+
// A rel ?b
123+
// instantiate_ty_var(?b, A) # expected and variance flipped
124+
// A rel A'
125+
// ```
111126
if target_is_expected == relation.a_is_expected() {
112-
relation.relate_with_variance(
113-
ambient_variance,
114-
ty::VarianceDiagInfo::default(),
115-
generalized_ty,
116-
source_ty,
117-
)?;
127+
relation.relate(generalized_ty, source_ty)?;
118128
} else {
119-
relation.relate_with_variance(
120-
ambient_variance.xform(ty::Contravariant),
121-
ty::VarianceDiagInfo::default(),
122-
source_ty,
123-
generalized_ty,
124-
)?;
129+
debug!("flip relation");
130+
relation.relate(source_ty, generalized_ty)?;
125131
}
126132
}
127133

compiler/rustc_lint/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ lint_non_upper_case_global = {$sort} `{$name}` should have an upper case name
429429
lint_noop_method_call = call to `.{$method}()` on a reference in this situation does nothing
430430
.suggestion = remove this redundant call
431431
.note = the type `{$orig_ty}` does not implement `{$trait_}`, so calling `{$method}` on `&{$orig_ty}` copies the reference, which does not do anything and can be removed
432+
.derive_suggestion = if you meant to clone `{$orig_ty}`, implement `Clone` for it
432433
433434
lint_only_cast_u8_to_char = only `u8` can be cast into `char`
434435
.suggestion = use a `char` literal instead

compiler/rustc_lint/src/lints.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,12 @@ pub struct NoopMethodCallDiag<'a> {
13141314
pub trait_: Symbol,
13151315
#[suggestion(code = "", applicability = "machine-applicable")]
13161316
pub label: Span,
1317+
#[suggestion(
1318+
lint_derive_suggestion,
1319+
code = "#[derive(Clone)]\n",
1320+
applicability = "maybe-incorrect"
1321+
)]
1322+
pub suggest_derive: Option<Span>,
13171323
}
13181324

13191325
#[derive(LintDiagnostic)]

compiler/rustc_lint/src/noop_method_call.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,20 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
121121
let orig_ty = expr_ty.peel_refs();
122122

123123
if receiver_ty == expr_ty {
124+
let suggest_derive = match orig_ty.kind() {
125+
ty::Adt(def, _) => Some(cx.tcx.def_span(def.did()).shrink_to_lo()),
126+
_ => None,
127+
};
124128
cx.emit_span_lint(
125129
NOOP_METHOD_CALL,
126130
span,
127-
NoopMethodCallDiag { method: call.ident.name, orig_ty, trait_, label: span },
131+
NoopMethodCallDiag {
132+
method: call.ident.name,
133+
orig_ty,
134+
trait_,
135+
label: span,
136+
suggest_derive,
137+
},
128138
);
129139
} else {
130140
match name {

0 commit comments

Comments
 (0)