Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #115952

Merged
merged 26 commits into from
Sep 19, 2023
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d695b95
implement -Z ignore-directory-in-diagnostics-source-blocks
pietroalbini Sep 15, 2023
c230637
avoid blessing cargo deps's source code in ui tests
pietroalbini Sep 15, 2023
4690f97
coverage: Fix an unstable-sort inconsistency in coverage spans
Zalathar Sep 18, 2023
a4cb31b
coverage: Regression test for inconsistent handling of closure spans
Zalathar Sep 18, 2023
01b67f4
coverage: Simplify sorting of coverage spans extracted from MIR
Zalathar Sep 17, 2023
354397f
Move mobile topbar title creation entirely into JS
GuillaumeGomez Sep 18, 2023
bf693d1
Migrate 'lossy ptr2int cast' diagnostic
clubby789 Sep 15, 2023
6496181
Migrate 'lossy int2ptr cast' diagnostic
clubby789 Sep 15, 2023
dcb3e70
Migrate 'is_empty' diagnostics
clubby789 Sep 15, 2023
c2841e2
Migrate 'cast to bool' diagnostic
clubby789 Sep 15, 2023
94920cc
Migrate 'int to fat pointer' cast diagnostic
clubby789 Sep 15, 2023
82471e9
Migrate 'casting unknown pointer' diagnostic
clubby789 Sep 15, 2023
80a9699
Migrate 'trivial cast' lint
clubby789 Sep 15, 2023
9c5de75
Migrate 'cast enum with drop to int' diagnostic
clubby789 Sep 15, 2023
b2bf4b6
make more pretty
BoxyUwU Sep 15, 2023
de6de23
Add myself to .mailmap
lnicola Sep 18, 2023
10a5b9a
compiletest: Don't swallow some error messages.
ehuss Sep 18, 2023
f27c06c
Update browser-ui-test version
GuillaumeGomez Sep 18, 2023
0eec5e3
Rollup merge of #115869 - ferrocene:pa-fix-tests-cargo-remap, r=compi…
matthiaskrgr Sep 18, 2023
48c6051
Rollup merge of #115873 - BoxyUwU:tykind_adt_debug, r=oli-obk
matthiaskrgr Sep 18, 2023
970ee09
Rollup merge of #115879 - clubby789:migrate-hir-typeck-cast, r=compil…
matthiaskrgr Sep 18, 2023
3cf5a6b
Rollup merge of #115930 - Zalathar:spans-bug, r=compiler-errors
matthiaskrgr Sep 18, 2023
575e091
Rollup merge of #115931 - GuillaumeGomez:remove-empty-h2, r=notriddle
matthiaskrgr Sep 18, 2023
3ddad37
Rollup merge of #115941 - lnicola:lnicola-mailmap, r=Mark-Simulacrum
matthiaskrgr Sep 18, 2023
8c5fc20
Rollup merge of #115943 - ehuss:compiletest-errors, r=compiler-errors
matthiaskrgr Sep 18, 2023
aa55d7d
Rollup merge of #115949 - GuillaumeGomez:update-browser-ui-test, r=no…
matthiaskrgr Sep 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Migrate 'int to fat pointer' cast diagnostic
clubby789 committed Sep 18, 2023
commit 94920cc6e0e7c855569c226945e988b5b41c9424
7 changes: 7 additions & 0 deletions compiler/rustc_hir_typeck/messages.ftl
Original file line number Diff line number Diff line change
@@ -64,6 +64,13 @@ hir_typeck_functional_record_update_on_non_struct =
hir_typeck_help_set_edition_cargo = set `edition = "{$edition}"` in `Cargo.toml`
hir_typeck_help_set_edition_standalone = pass `--edition {$edition}` to `rustc`

hir_typeck_int_to_fat = cannot cast `{$expr_ty}` to a pointer that {$known_wide ->
[true] is
*[false] may be
} wide
hir_typeck_int_to_fat_label = creating a `{$cast_ty}` requires both an address and {$metadata}
hir_typeck_int_to_fat_label_nightly = consider casting this expression to `*const ()`, then using `core::ptr::from_raw_parts`

hir_typeck_invalid_callee = expected function, found {$ty}

hir_typeck_lang_start_expected_sig_note = the `start` lang item should have the signature `fn(fn() -> T, isize, *const *const u8, u8) -> isize`
45 changes: 17 additions & 28 deletions compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
@@ -324,7 +324,9 @@ impl<'a, 'tcx> CastCheck<'tcx> {
CastError::CastToBool => {
let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
let help = if self.expr_ty.is_numeric() {
errors::CannotCastToBoolHelp::Numeric(self.expr_span.shrink_to_hi().with_hi(self.span.hi()))
errors::CannotCastToBoolHelp::Numeric(
self.expr_span.shrink_to_hi().with_hi(self.span.hi()),
)
} else {
errors::CannotCastToBoolHelp::Unsupported(self.span)
};
@@ -517,33 +519,20 @@ impl<'a, 'tcx> CastCheck<'tcx> {
.emit();
}
CastError::IntToFatCast(known_metadata) => {
let mut err = struct_span_err!(
fcx.tcx.sess,
self.cast_span,
E0606,
"cannot cast `{}` to a pointer that {} wide",
fcx.ty_to_string(self.expr_ty),
if known_metadata.is_some() { "is" } else { "may be" }
);

err.span_label(
self.cast_span,
format!(
"creating a `{}` requires both an address and {}",
self.cast_ty,
known_metadata.unwrap_or("type-specific metadata"),
),
);

if fcx.tcx.sess.is_nightly_build() {
err.span_label(
self.expr_span,
"consider casting this expression to `*const ()`, \
then using `core::ptr::from_raw_parts`",
);
}

err.emit();
let expr_if_nightly = fcx.tcx.sess.is_nightly_build().then_some(self.expr_span);
let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty);
let expr_ty = fcx.ty_to_string(self.expr_ty);
let metadata = known_metadata.unwrap_or("type-specific metadata");
let known_wide = known_metadata.is_some();
let span = self.cast_span;
fcx.tcx.sess.emit_err(errors::IntToWide {
span,
metadata,
expr_ty,
cast_ty,
expr_if_nightly,
known_wide,
});
}
CastError::UnknownCastPtrKind | CastError::UnknownExprPtrKind => {
let unknown_cast_to = match e {
14 changes: 14 additions & 0 deletions compiler/rustc_hir_typeck/src/errors.rs
Original file line number Diff line number Diff line change
@@ -361,6 +361,20 @@ pub struct InvalidCallee {
pub ty: String,
}

#[derive(Diagnostic)]
#[diag(hir_typeck_int_to_fat, code = "E0606")]
pub struct IntToWide<'tcx> {
#[primary_span]
#[label(hir_typeck_int_to_fat_label)]
pub span: Span,
pub metadata: &'tcx str,
pub expr_ty: String,
pub cast_ty: Ty<'tcx>,
#[label(hir_typeck_int_to_fat_label_nightly)]
pub expr_if_nightly: Option<Span>,
pub known_wide: bool,
}

#[derive(Subdiagnostic)]
pub enum OptionResultRefMismatch {
#[suggestion(