Skip to content

Commit 0f2a9ce

Browse files
committed
Auto merge of rust-lang#116112 - matthiaskrgr:rollup-s3cm2f7, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#116073 (Allow higher-ranked fn sigs in `ValuePairs`) - rust-lang#116082 (Tweak expected message to explain what it's actually signifying) - rust-lang#116086 (More accurate suggestion for `self.` and `Self::`) - rust-lang#116104 (Reuse calculate_debuginfo_offset for fragments.) - rust-lang#116106 (Migrate GUI colors test to original CSS color format) r? `@ghost` `@rustbot` modify labels: rollup
2 parents acfb46d + 164517c commit 0f2a9ce

25 files changed

+195
-102
lines changed

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

+10-33
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,15 @@ fn calculate_debuginfo_offset<
158158
L: DebugInfoOffsetLocation<'tcx, Bx>,
159159
>(
160160
bx: &mut Bx,
161-
local: mir::Local,
162-
var: &PerLocalVarDebugInfo<'tcx, Bx::DIVariable>,
161+
projection: &[mir::PlaceElem<'tcx>],
163162
base: L,
164163
) -> DebugInfoOffset<L> {
165164
let mut direct_offset = Size::ZERO;
166165
// FIXME(eddyb) use smallvec here.
167166
let mut indirect_offsets = vec![];
168167
let mut place = base;
169168

170-
for elem in &var.projection[..] {
169+
for elem in projection {
171170
match *elem {
172171
mir::ProjectionElem::Deref => {
173172
indirect_offsets.push(Size::ZERO);
@@ -188,23 +187,15 @@ fn calculate_debuginfo_offset<
188187
} => {
189188
let offset = indirect_offsets.last_mut().unwrap_or(&mut direct_offset);
190189
let FieldsShape::Array { stride, count: _ } = place.layout().fields else {
191-
span_bug!(
192-
var.source_info.span,
193-
"ConstantIndex on non-array type {:?}",
194-
place.layout()
195-
)
190+
bug!("ConstantIndex on non-array type {:?}", place.layout())
196191
};
197192
*offset += stride * index;
198193
place = place.project_constant_index(bx, index);
199194
}
200195
_ => {
201196
// Sanity check for `can_use_in_debuginfo`.
202197
debug_assert!(!elem.can_use_in_debuginfo());
203-
span_bug!(
204-
var.source_info.span,
205-
"unsupported var debuginfo place `{:?}`",
206-
mir::Place { local, projection: var.projection },
207-
)
198+
bug!("unsupported var debuginfo projection `{:?}`", projection)
208199
}
209200
}
210201
}
@@ -407,7 +398,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
407398
let Some(dbg_loc) = self.dbg_loc(var.source_info) else { return };
408399

409400
let DebugInfoOffset { direct_offset, indirect_offsets, result: _ } =
410-
calculate_debuginfo_offset(bx, local, &var, base.layout);
401+
calculate_debuginfo_offset(bx, &var.projection, base.layout);
411402

412403
// When targeting MSVC, create extra allocas for arguments instead of pointing multiple
413404
// dbg_var_addr() calls into the same alloca with offsets. MSVC uses CodeView records
@@ -425,7 +416,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
425416

426417
if should_create_individual_allocas {
427418
let DebugInfoOffset { direct_offset: _, indirect_offsets: _, result: place } =
428-
calculate_debuginfo_offset(bx, local, &var, base);
419+
calculate_debuginfo_offset(bx, &var.projection, base);
429420

430421
// Create a variable which will be a pointer to the actual value
431422
let ptr_ty = Ty::new_ptr(
@@ -532,23 +523,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
532523
let fragment = if let Some(ref fragment) = var.composite {
533524
let var_layout = self.cx.layout_of(var_ty);
534525

535-
let mut fragment_start = Size::ZERO;
536-
let mut fragment_layout = var_layout;
537-
538-
for elem in &fragment.projection {
539-
match *elem {
540-
mir::ProjectionElem::Field(field, _) => {
541-
let i = field.index();
542-
fragment_start += fragment_layout.fields.offset(i);
543-
fragment_layout = fragment_layout.field(self.cx, i);
544-
}
545-
_ => span_bug!(
546-
var.source_info.span,
547-
"unsupported fragment projection `{:?}`",
548-
elem,
549-
),
550-
}
551-
}
526+
let DebugInfoOffset { direct_offset, indirect_offsets, result: fragment_layout } =
527+
calculate_debuginfo_offset(bx, &fragment.projection, var_layout);
528+
debug_assert!(indirect_offsets.is_empty());
552529

553530
if fragment_layout.size == Size::ZERO {
554531
// Fragment is a ZST, so does not represent anything. Avoid generating anything
@@ -559,7 +536,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
559536
// DWARF is concerned, it's not really a fragment.
560537
None
561538
} else {
562-
Some(fragment_start..fragment_start + fragment_layout.size)
539+
Some(direct_offset..direct_offset + fragment_layout.size)
563540
}
564541
} else {
565542
None

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,10 @@ fn report_trait_method_mismatch<'tcx>(
11341134
&mut diag,
11351135
&cause,
11361136
trait_err_span.map(|sp| (sp, Cow::from("type in trait"))),
1137-
Some(infer::ValuePairs::Sigs(ExpectedFound { expected: trait_sig, found: impl_sig })),
1137+
Some(infer::ValuePairs::PolySigs(ExpectedFound {
1138+
expected: ty::Binder::dummy(trait_sig),
1139+
found: ty::Binder::dummy(impl_sig),
1140+
})),
11381141
terr,
11391142
false,
11401143
false,

compiler/rustc_hir_analysis/src/check/mod.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,7 @@ pub fn check_function_signature<'tcx>(
573573
let norm_cause = ObligationCause::misc(cause.span, local_id);
574574
let actual_sig = ocx.normalize(&norm_cause, param_env, actual_sig);
575575

576-
let expected_ty = Ty::new_fn_ptr(tcx, expected_sig);
577-
let actual_ty = Ty::new_fn_ptr(tcx, actual_sig);
578-
579-
match ocx.eq(&cause, param_env, expected_ty, actual_ty) {
576+
match ocx.eq(&cause, param_env, expected_sig, actual_sig) {
580577
Ok(()) => {
581578
let errors = ocx.select_all_or_error();
582579
if !errors.is_empty() {
@@ -595,9 +592,9 @@ pub fn check_function_signature<'tcx>(
595592
&mut diag,
596593
&cause,
597594
None,
598-
Some(infer::ValuePairs::Sigs(ExpectedFound {
599-
expected: tcx.liberate_late_bound_regions(fn_id, expected_sig),
600-
found: tcx.liberate_late_bound_regions(fn_id, actual_sig),
595+
Some(infer::ValuePairs::PolySigs(ExpectedFound {
596+
expected: expected_sig,
597+
found: actual_sig,
601598
})),
602599
err,
603600
false,

compiler/rustc_infer/src/infer/at.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,28 @@ impl<'tcx> ToTrace<'tcx> for ty::FnSig<'tcx> {
478478
a: Self,
479479
b: Self,
480480
) -> TypeTrace<'tcx> {
481-
TypeTrace { cause: cause.clone(), values: Sigs(ExpectedFound::new(a_is_expected, a, b)) }
481+
TypeTrace {
482+
cause: cause.clone(),
483+
values: PolySigs(ExpectedFound::new(
484+
a_is_expected,
485+
ty::Binder::dummy(a),
486+
ty::Binder::dummy(b),
487+
)),
488+
}
489+
}
490+
}
491+
492+
impl<'tcx> ToTrace<'tcx> for ty::PolyFnSig<'tcx> {
493+
fn to_trace(
494+
cause: &ObligationCause<'tcx>,
495+
a_is_expected: bool,
496+
a: Self,
497+
b: Self,
498+
) -> TypeTrace<'tcx> {
499+
TypeTrace {
500+
cause: cause.clone(),
501+
values: PolySigs(ExpectedFound::new(a_is_expected, a, b)),
502+
}
482503
}
483504
}
484505

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
16601660
_ => (false, Mismatch::Fixed("type")),
16611661
}
16621662
}
1663-
ValuePairs::Sigs(infer::ExpectedFound { expected, found }) => {
1663+
ValuePairs::PolySigs(infer::ExpectedFound { expected, found }) => {
16641664
OpaqueTypesVisitor::visit_expected_found(self.tcx, expected, found, span)
16651665
.report(diag);
16661666
(false, Mismatch::Fixed("signature"))
@@ -2232,15 +2232,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22322232
ret => ret,
22332233
}
22342234
}
2235-
infer::Sigs(exp_found) => {
2235+
infer::PolySigs(exp_found) => {
22362236
let exp_found = self.resolve_vars_if_possible(exp_found);
22372237
if exp_found.references_error() {
22382238
return None;
22392239
}
2240-
let (exp, fnd) = self.cmp_fn_sig(
2241-
&ty::Binder::dummy(exp_found.expected),
2242-
&ty::Binder::dummy(exp_found.found),
2243-
);
2240+
let (exp, fnd) = self.cmp_fn_sig(&exp_found.expected, &exp_found.found);
22442241
Some((exp, fnd, None, None))
22452242
}
22462243
}

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
3535
&& let (Subtype(sup_trace), Subtype(sub_trace)) = (&sup_origin, &sub_origin)
3636
&& let CompareImplItemObligation { trait_item_def_id, .. } = sub_trace.cause.code()
3737
&& sub_trace.values == sup_trace.values
38-
&& let ValuePairs::Sigs(ExpectedFound { expected, found }) = sub_trace.values
38+
&& let ValuePairs::PolySigs(ExpectedFound { expected, found }) = sub_trace.values
3939
{
4040
// FIXME(compiler-errors): Don't like that this needs `Ty`s, but
4141
// all of the region highlighting machinery only deals with those.
4242
let guar = self.emit_err(
4343
var_origin.span(),
44-
Ty::new_fn_ptr(self.cx.tcx,ty::Binder::dummy(expected)),
45-
Ty::new_fn_ptr(self.cx.tcx,ty::Binder::dummy(found)),
44+
Ty::new_fn_ptr(self.cx.tcx, expected),
45+
Ty::new_fn_ptr(self.cx.tcx, found),
4646
*trait_item_def_id,
4747
);
4848
return Some(guar);

compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,13 @@ fn foo(&self) -> Self::T { String::new() }
616616
for item in &items[..] {
617617
if let hir::AssocItemKind::Type = item.kind {
618618
let assoc_ty = tcx.type_of(item.id.owner_id).instantiate_identity();
619-
620-
if self.infcx.can_eq(param_env, assoc_ty, found) {
621-
diag.span_label(item.span, "expected this associated type");
619+
if let hir::Defaultness::Default { has_value: true } = tcx.defaultness(item.id.owner_id)
620+
&& self.infcx.can_eq(param_env, assoc_ty, found)
621+
{
622+
diag.span_label(
623+
item.span,
624+
format!("associated type is `default` and may be overridden"),
625+
);
622626
return true;
623627
}
624628
}

compiler/rustc_infer/src/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ pub enum ValuePairs<'tcx> {
383383
Aliases(ExpectedFound<ty::AliasTy<'tcx>>),
384384
TraitRefs(ExpectedFound<ty::TraitRef<'tcx>>),
385385
PolyTraitRefs(ExpectedFound<ty::PolyTraitRef<'tcx>>),
386-
Sigs(ExpectedFound<ty::FnSig<'tcx>>),
386+
PolySigs(ExpectedFound<ty::PolyFnSig<'tcx>>),
387387
ExistentialTraitRef(ExpectedFound<ty::PolyExistentialTraitRef<'tcx>>),
388388
ExistentialProjection(ExpectedFound<ty::PolyExistentialProjection<'tcx>>),
389389
}

compiler/rustc_passes/src/check_attr.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2333,7 +2333,10 @@ impl CheckAttrVisitor<'_> {
23332333
&mut diag,
23342334
&cause,
23352335
None,
2336-
Some(ValuePairs::Sigs(ExpectedFound { expected: expected_sig, found: sig })),
2336+
Some(ValuePairs::PolySigs(ExpectedFound {
2337+
expected: ty::Binder::dummy(expected_sig),
2338+
found: ty::Binder::dummy(sig),
2339+
})),
23372340
terr,
23382341
false,
23392342
false,

compiler/rustc_resolve/src/late/diagnostics.rs

+34-24
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
214214
module: None,
215215
}
216216
} else {
217+
let mut span_label = None;
217218
let item_span = path.last().unwrap().ident.span;
218219
let (mod_prefix, mod_str, module, suggestion) = if path.len() == 1 {
219220
debug!(?self.diagnostic_metadata.current_impl_items);
@@ -224,32 +225,41 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
224225
&& let FnKind::Fn(_, _, sig, ..) = fn_kind
225226
&& let Some(items) = self.diagnostic_metadata.current_impl_items
226227
&& let Some(item) = items.iter().find(|i| {
227-
if let AssocItemKind::Fn(..) | AssocItemKind::Const(..) = &i.kind
228-
&& i.ident.name == item_str.name
229-
// don't suggest if the item is in Fn signature arguments
230-
// issue #112590
228+
i.ident.name == item_str.name
229+
// Don't suggest if the item is in Fn signature arguments (#112590).
231230
&& !sig.span.contains(item_span)
232-
{
233-
debug!(?item_str.name);
234-
return true
235-
}
236-
false
237231
})
238232
{
239-
let self_sugg = match &item.kind {
240-
AssocItemKind::Fn(fn_) if fn_.sig.decl.has_self() => "self.",
241-
_ => "Self::",
242-
};
243-
244-
Some((
245-
item_span.shrink_to_lo(),
246-
match &item.kind {
247-
AssocItemKind::Fn(..) => "consider using the associated function",
248-
AssocItemKind::Const(..) => "consider using the associated constant",
249-
_ => unreachable!("item kind was filtered above"),
250-
},
251-
self_sugg.to_string()
252-
))
233+
let sp = item_span.shrink_to_lo();
234+
match &item.kind {
235+
AssocItemKind::Fn(fn_)
236+
if !sig.decl.has_self() && fn_.sig.decl.has_self() => {
237+
// Ensure that we only suggest `self.` if `self` is available,
238+
// you can't call `fn foo(&self)` from `fn bar()` (#115992).
239+
// We also want to mention that the method exists.
240+
span_label = Some((
241+
item.ident.span,
242+
"a method by that name is available on `Self` here",
243+
));
244+
None
245+
}
246+
AssocItemKind::Fn(fn_) if fn_.sig.decl.has_self() => Some((
247+
sp,
248+
"consider using the method on `Self`",
249+
"self.".to_string(),
250+
)),
251+
AssocItemKind::Fn(_) => Some((
252+
sp,
253+
"consider using the associated function on `Self`",
254+
"Self::".to_string(),
255+
)),
256+
AssocItemKind::Const(..) => Some((
257+
sp,
258+
"consider using the associated constant on `Self`",
259+
"Self::".to_string(),
260+
)),
261+
_ => None
262+
}
253263
} else {
254264
None
255265
};
@@ -314,7 +324,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
314324
msg: format!("cannot find {expected} `{item_str}` in {mod_prefix}{mod_str}"),
315325
fallback_label,
316326
span: item_span,
317-
span_label: None,
327+
span_label,
318328
could_be_expr: false,
319329
suggestion,
320330
module,

tests/rustdoc-gui/default-settings.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
go-to: "file://" + |DOC_PATH| + "/settings/index.html"
66
// Wait a bit to be sure the default theme is applied.
77
// If the theme isn't applied, the command will time out.
8-
wait-for-css: ("body", {"background-color": "rgb(15, 20, 25)"})
8+
wait-for-css: ("body", {"background-color": "#0f1419"})

tests/ui/associated-types/defaults-specialization.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ error[E0053]: method `make` has an incompatible type for trait
2929
--> $DIR/defaults-specialization.rs:35:18
3030
|
3131
LL | default type Ty = bool;
32-
| ----------------------- expected this associated type
32+
| ----------------------- associated type is `default` and may be overridden
3333
LL |
3434
LL | fn make() -> bool { true }
3535
| ^^^^
@@ -76,7 +76,7 @@ error[E0308]: mismatched types
7676
--> $DIR/defaults-specialization.rs:44:29
7777
|
7878
LL | default type Ty = bool;
79-
| ----------------------- expected this associated type
79+
| ----------------------- associated type is `default` and may be overridden
8080
LL |
8181
LL | fn make() -> Self::Ty { true }
8282
| -------- ^^^^ expected associated type, found `bool`

tests/ui/panic-handler/panic-handler-bad-signature-1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0308]: `#[panic_handler]` function has wrong type
44
LL | fn panic(info: PanicInfo) -> () {}
55
| ^^^^^^^^^ expected `&PanicInfo<'_>`, found `PanicInfo<'_>`
66
|
7-
= note: expected signature `fn(&PanicInfo<'_>) -> !`
8-
found signature `fn(PanicInfo<'_>)`
7+
= note: expected signature `for<'a, 'b> fn(&'a PanicInfo<'b>) -> !`
8+
found signature `for<'a> fn(PanicInfo<'a>)`
99

1010
error: aborting due to previous error
1111

tests/ui/panic-handler/panic-handler-bad-signature-2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0308]: `#[panic_handler]` function has wrong type
44
LL | fn panic(info: &'static PanicInfo) -> !
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
66
|
7-
= note: expected fn pointer `for<'a, 'b> fn(&'a PanicInfo<'b>) -> _`
8-
found fn pointer `for<'a> fn(&'static PanicInfo<'a>) -> _`
7+
= note: expected signature `for<'a, 'b> fn(&'a PanicInfo<'b>) -> _`
8+
found signature `for<'a> fn(&'static PanicInfo<'a>) -> _`
99

1010
error: aborting due to previous error
1111

tests/ui/panic-handler/panic-handler-bad-signature-3.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0308]: `#[panic_handler]` function has wrong type
44
LL | fn panic() -> ! {
55
| ^^^^^^^^^^^^^^^ incorrect number of function parameters
66
|
7-
= note: expected signature `fn(&PanicInfo<'_>) -> _`
7+
= note: expected signature `for<'a, 'b> fn(&'a PanicInfo<'b>) -> _`
88
found signature `fn() -> _`
99

1010
error: aborting due to previous error

tests/ui/panic-handler/panic-handler-bad-signature-5.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0308]: `#[panic_handler]` function has wrong type
44
LL | fn panic(info: &PanicInfo<'static>) -> !
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
66
|
7-
= note: expected fn pointer `for<'a, 'b> fn(&'a PanicInfo<'b>) -> _`
8-
found fn pointer `for<'a> fn(&'a PanicInfo<'static>) -> _`
7+
= note: expected signature `for<'a, 'b> fn(&'a PanicInfo<'b>) -> _`
8+
found signature `for<'a> fn(&'a PanicInfo<'static>) -> _`
99

1010
error: aborting due to previous error
1111

0 commit comments

Comments
 (0)