Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6ed283b
rustdoc-json: Add test for `Self` type
aDotInTheVoid Aug 15, 2024
42a901a
Don't use TyKind in lint
compiler-errors Aug 24, 2024
af05882
Deny wasm_c_abi lint to nudge the last 25%
workingjubilee Aug 24, 2024
c61f85b
Don't make pattern nonterminals match statement nonterminals
compiler-errors Jan 22, 2024
a1c36c6
linker: Synchronize native library search in rustc and linker
petrochenkov Aug 14, 2024
05bd36d
linker: Better support alternative static library naming on MSVC
petrochenkov Aug 21, 2024
ac8f132
docs: Update docs for the rustc's `-L` option
petrochenkov Aug 27, 2024
ee05de8
Re-enable android tests/benches in alloc
saethlin Aug 27, 2024
83de14c
Enable some ilog2 tests as well
saethlin Aug 27, 2024
ae6f8a7
allow BufReader::peek to be called on unsized types
lolbinarycat Aug 28, 2024
e20a888
Allow running `./x.py test compiler`
Veykril Aug 29, 2024
d2c126a
Rollup merge of #120221 - compiler-errors:statements-are-not-patterns…
workingjubilee Aug 29, 2024
4756a31
Rollup merge of #129123 - aDotInTheVoid:rustdoc-json-self, r=fmease
workingjubilee Aug 29, 2024
49e6125
Rollup merge of #129366 - petrochenkov:libsearch, r=jieyouxu
workingjubilee Aug 29, 2024
eeb16a2
Rollup merge of #129527 - compiler-errors:lint-nit, r=Nadrieril
workingjubilee Aug 29, 2024
608342a
Rollup merge of #129534 - workingjubilee:ratchet-wasm-c-abi-fcw-to-de…
workingjubilee Aug 29, 2024
ad42d52
Rollup merge of #129640 - saethlin:unignore-android-in-alloc, r=tgross35
workingjubilee Aug 29, 2024
ff6e551
Rollup merge of #129675 - lolbinarycat:bufreader_peek_unsized, r=work…
workingjubilee Aug 29, 2024
1327cea
Rollup merge of #129731 - ferrocene:x-test-compiler, r=onur-ozkan
workingjubilee Aug 29, 2024
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
Don't use TyKind in lint
  • Loading branch information
compiler-errors committed Aug 24, 2024
commit 42a901acd9c9d3a0c9ca7adf2470b789f9c81a5b
25 changes: 13 additions & 12 deletions compiler/rustc_lint/src/foreign_modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,6 @@ fn structurally_same_type_impl<'tcx>(
} else {
// Do a full, depth-first comparison between the two.
use rustc_type_ir::TyKind::*;
let a_kind = a.kind();
let b_kind = b.kind();

let compare_layouts = |a, b| -> Result<bool, &'tcx LayoutError<'tcx>> {
debug!("compare_layouts({:?}, {:?})", a, b);
Expand All @@ -281,12 +279,11 @@ fn structurally_same_type_impl<'tcx>(
Ok(a_layout == b_layout)
};

#[allow(rustc::usage_of_ty_tykind)]
let is_primitive_or_pointer =
|kind: &ty::TyKind<'_>| kind.is_primitive() || matches!(kind, RawPtr(..) | Ref(..));
|ty: Ty<'tcx>| ty.is_primitive() || matches!(ty.kind(), RawPtr(..) | Ref(..));

ensure_sufficient_stack(|| {
match (a_kind, b_kind) {
match (a.kind(), b.kind()) {
(Adt(a_def, _), Adt(b_def, _)) => {
// We can immediately rule out these types as structurally same if
// their layouts differ.
Expand Down Expand Up @@ -382,17 +379,21 @@ fn structurally_same_type_impl<'tcx>(

// An Adt and a primitive or pointer type. This can be FFI-safe if non-null
// enum layout optimisation is being applied.
(Adt(..), other_kind) | (other_kind, Adt(..))
if is_primitive_or_pointer(other_kind) =>
{
let (primitive, adt) =
if is_primitive_or_pointer(a.kind()) { (a, b) } else { (b, a) };
if let Some(ty) = types::repr_nullable_ptr(tcx, param_env, adt, ckind) {
ty == primitive
(Adt(..), _) if is_primitive_or_pointer(b) => {
if let Some(ty) = types::repr_nullable_ptr(tcx, param_env, a, ckind) {
ty == b
} else {
compare_layouts(a, b).unwrap_or(false)
}
}
(_, Adt(..)) if is_primitive_or_pointer(a) => {
if let Some(ty) = types::repr_nullable_ptr(tcx, param_env, b, ckind) {
ty == a
} else {
compare_layouts(a, b).unwrap_or(false)
}
}

// Otherwise, just compare the layouts. This may fail to lint for some
// incompatible types, but at the very least, will stop reads into
// uninitialised memory.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ impl<'tcx> Ty<'tcx> {

#[inline]
pub fn is_primitive(self) -> bool {
self.kind().is_primitive()
matches!(self.kind(), Bool | Char | Int(_) | Uint(_) | Float(_))
}

#[inline]
Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_type_ir/src/ty_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,6 @@ pub enum TyKind<I: Interner> {
Error(I::ErrorGuaranteed),
}

impl<I: Interner> TyKind<I> {
#[inline]
pub fn is_primitive(&self) -> bool {
matches!(self, Bool | Char | Int(_) | Uint(_) | Float(_))
}
}

// This is manually implemented because a derive would require `I: Debug`
impl<I: Interner> fmt::Debug for TyKind<I> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down