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 10 pull requests #126910

Closed
wants to merge 21 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9f0c7f0
transmute size check: properly account for alignment
RalfJung May 29, 2024
d630f5d
Show notice about "never used" for enum
long-long-float Apr 28, 2024
a264bff
Mark assoc tys live only if the trait is live
mu001999 Jun 18, 2024
3f2f843
Ensure we don't accidentally succeed when we want to report an error
oli-obk Jun 13, 2024
3390159
Add `rust_analyzer` as a predefined tool
Veykril May 18, 2024
57a82e0
On short error format, append primary span label to message
estebank Jun 21, 2024
594fa01
not use offset when there is not ends with brace
bvanjoi Jun 23, 2024
8cfd4b1
Unify the precedence level for PREC_POSTFIX and PREC_PAREN
dtolnay Jun 24, 2024
273447c
Rename the 2 unambiguous precedence levels to PREC_UNAMBIGUOUS
dtolnay Jun 24, 2024
ba5ec1f
Suggest inline const blocks for array initialization
GrigorenkoPV Jun 24, 2024
8ffb5f9
compiletest: make the crash test error message abit more informative
matthiaskrgr Jun 13, 2024
1368c5e
Rollup merge of #124460 - long-long-float:show-notice-about-enum-with…
matthiaskrgr Jun 24, 2024
a7e148d
Rollup merge of #125241 - Veykril:tool-rust-analyzer, r=davidtwco
matthiaskrgr Jun 24, 2024
621ab36
Rollup merge of #125740 - RalfJung:transmute-size-check, r=oli-obk
matthiaskrgr Jun 24, 2024
b77d610
Rollup merge of #126413 - matthiaskrgr:crshmsg, r=oli-obk
matthiaskrgr Jun 24, 2024
4b78058
Rollup merge of #126618 - mu001999-contrib:dead/enhance, r=pnkfelix
matthiaskrgr Jun 24, 2024
a12f2d2
Rollup merge of #126673 - oli-obk:dont_rely_on_err_reporting, r=compi…
matthiaskrgr Jun 24, 2024
52a90f4
Rollup merge of #126804 - estebank:short-error-primary-label, r=david…
matthiaskrgr Jun 24, 2024
1ae001d
Rollup merge of #126868 - bvanjoi:fix-126764, r=davidtwco
matthiaskrgr Jun 24, 2024
98379cf
Rollup merge of #126893 - dtolnay:prec, r=compiler-errors
matthiaskrgr Jun 24, 2024
4aaa3b0
Rollup merge of #126899 - GrigorenkoPV:suggest-const-block, r=davidtwco
matthiaskrgr Jun 24, 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
41 changes: 25 additions & 16 deletions compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
@@ -155,7 +155,10 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {

fn handle_res(&mut self, res: Res) {
match res {
Res::Def(DefKind::Const | DefKind::AssocConst | DefKind::TyAlias, def_id) => {
Res::Def(
DefKind::Const | DefKind::AssocConst | DefKind::AssocTy | DefKind::TyAlias,
def_id,
) => {
self.check_def_id(def_id);
}
_ if self.in_pat => {}
@@ -441,7 +444,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
intravisit::walk_item(self, item)
}
hir::ItemKind::ForeignMod { .. } => {}
hir::ItemKind::Trait(..) => {
hir::ItemKind::Trait(_, _, _, _, trait_item_refs) => {
for impl_def_id in self.tcx.all_impls(item.owner_id.to_def_id()) {
if let Some(local_def_id) = impl_def_id.as_local()
&& let ItemKind::Impl(impl_ref) =
@@ -454,7 +457,12 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
intravisit::walk_path(self, impl_ref.of_trait.unwrap().path);
}
}

// mark assoc ty live if the trait is live
for trait_item in trait_item_refs {
if let hir::AssocItemKind::Type = trait_item.kind {
self.check_def_id(trait_item.id.owner_id.to_def_id());
}
}
intravisit::walk_item(self, item)
}
_ => intravisit::walk_item(self, item),
@@ -471,9 +479,8 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
&& let ItemKind::Impl(impl_ref) =
self.tcx.hir().expect_item(local_impl_id).kind
{
if !matches!(trait_item.kind, hir::TraitItemKind::Type(..))
&& !ty_ref_to_pub_struct(self.tcx, impl_ref.self_ty)
.ty_and_all_fields_are_public
if !ty_ref_to_pub_struct(self.tcx, impl_ref.self_ty)
.ty_and_all_fields_are_public
{
// skip impl-items of non pure pub ty,
// cause we don't know the ty is constructed or not,
@@ -812,9 +819,8 @@ fn check_item<'tcx>(
// for trait impl blocks,
// mark the method live if the self_ty is public,
// or the method is public and may construct self
if of_trait && matches!(tcx.def_kind(local_def_id), DefKind::AssocTy)
|| tcx.visibility(local_def_id).is_public()
&& (ty_and_all_fields_are_public || may_construct_self)
if tcx.visibility(local_def_id).is_public()
&& (ty_and_all_fields_are_public || may_construct_self)
{
// if the impl item is public,
// and the ty may be constructed or can be constructed in foreign crates,
@@ -851,10 +857,13 @@ fn check_trait_item(
worklist: &mut Vec<(LocalDefId, ComesFromAllowExpect)>,
id: hir::TraitItemId,
) {
use hir::TraitItemKind::{Const, Fn};
if matches!(tcx.def_kind(id.owner_id), DefKind::AssocConst | DefKind::AssocFn) {
use hir::TraitItemKind::{Const, Fn, Type};
if matches!(
tcx.def_kind(id.owner_id),
DefKind::AssocConst | DefKind::AssocTy | DefKind::AssocFn
) {
let trait_item = tcx.hir().trait_item(id);
if matches!(trait_item.kind, Const(_, Some(_)) | Fn(..))
if matches!(trait_item.kind, Const(_, Some(_)) | Type(_, Some(_)) | Fn(..))
&& let Some(comes_from_allow) =
has_allow_dead_code_or_lang_attr(tcx, trait_item.owner_id.def_id)
{
@@ -896,7 +905,7 @@ fn create_and_seed_worklist(
// checks impls, impl-items and pub structs with all public fields later
match tcx.def_kind(id) {
DefKind::Impl { .. } => false,
DefKind::AssocConst | DefKind::AssocFn => !matches!(tcx.associated_item(id).container, AssocItemContainer::ImplContainer),
DefKind::AssocConst | DefKind::AssocTy | DefKind::AssocFn => !matches!(tcx.associated_item(id).container, AssocItemContainer::ImplContainer),
DefKind::Struct => struct_all_fields_are_public(tcx, id.to_def_id()) || has_allow_dead_code_or_lang_attr(tcx, id).is_some(),
_ => true
})
@@ -1183,6 +1192,7 @@ impl<'tcx> DeadVisitor<'tcx> {
}
match self.tcx.def_kind(def_id) {
DefKind::AssocConst
| DefKind::AssocTy
| DefKind::AssocFn
| DefKind::Fn
| DefKind::Static { .. }
@@ -1224,15 +1234,14 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) {
|| (def_kind == DefKind::Trait && live_symbols.contains(&item.owner_id.def_id))
{
for &def_id in tcx.associated_item_def_ids(item.owner_id.def_id) {
// We have diagnosed unused assoc consts and fns in traits
// We have diagnosed unused assocs in traits
if matches!(def_kind, DefKind::Impl { of_trait: true })
&& matches!(tcx.def_kind(def_id), DefKind::AssocConst | DefKind::AssocFn)
&& matches!(tcx.def_kind(def_id), DefKind::AssocConst | DefKind::AssocTy | DefKind::AssocFn)
// skip unused public inherent methods,
// cause we have diagnosed unconstructed struct
|| matches!(def_kind, DefKind::Impl { of_trait: false })
&& tcx.visibility(def_id).is_public()
&& ty_ref_to_pub_struct(tcx, tcx.hir().item(item).expect_impl().self_ty).ty_is_public
|| def_kind == DefKind::Trait && tcx.def_kind(def_id) == DefKind::AssocTy
{
continue;
}
1 change: 1 addition & 0 deletions tests/ui/const-generics/cross_crate_complex.rs
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ async fn foo() {
async_in_foo(async_out_foo::<4>().await).await;
}

#[allow(dead_code)]
struct Faz<const N: usize>;

impl<const N: usize> Foo<N> for Faz<N> {}
4 changes: 4 additions & 0 deletions tests/ui/generic-associated-types/missing-bounds.fixed
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

use std::ops::Add;

#[allow(dead_code)]
struct A<B>(B);

impl<B> Add for A<B> where B: Add<Output = B> {
@@ -12,6 +13,7 @@ impl<B> Add for A<B> where B: Add<Output = B> {
}
}

#[allow(dead_code)]
struct C<B>(B);

impl<B: Add<Output = B>> Add for C<B> {
@@ -22,6 +24,7 @@ impl<B: Add<Output = B>> Add for C<B> {
}
}

#[allow(dead_code)]
struct D<B>(B);

impl<B: std::ops::Add<Output = B>> Add for D<B> {
@@ -32,6 +35,7 @@ impl<B: std::ops::Add<Output = B>> Add for D<B> {
}
}

#[allow(dead_code)]
struct E<B>(B);

impl<B: Add<Output = B>> Add for E<B> where B: Add<Output = B> {
4 changes: 4 additions & 0 deletions tests/ui/generic-associated-types/missing-bounds.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

use std::ops::Add;

#[allow(dead_code)]
struct A<B>(B);

impl<B> Add for A<B> where B: Add {
@@ -12,6 +13,7 @@ impl<B> Add for A<B> where B: Add {
}
}

#[allow(dead_code)]
struct C<B>(B);

impl<B: Add> Add for C<B> {
@@ -22,6 +24,7 @@ impl<B: Add> Add for C<B> {
}
}

#[allow(dead_code)]
struct D<B>(B);

impl<B> Add for D<B> {
@@ -32,6 +35,7 @@ impl<B> Add for D<B> {
}
}

#[allow(dead_code)]
struct E<B>(B);

impl<B: Add> Add for E<B> where <B as Add>::Output = B {
18 changes: 9 additions & 9 deletions tests/ui/generic-associated-types/missing-bounds.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: equality constraints are not yet supported in `where` clauses
--> $DIR/missing-bounds.rs:37:33
--> $DIR/missing-bounds.rs:41:33
|
LL | impl<B: Add> Add for E<B> where <B as Add>::Output = B {
| ^^^^^^^^^^^^^^^^^^^^^^ not supported
@@ -11,7 +11,7 @@ LL | impl<B: Add> Add for E<B> where B: Add<Output = B> {
| ~~~~~~~~~~~~~~~~~~

error[E0308]: mismatched types
--> $DIR/missing-bounds.rs:11:11
--> $DIR/missing-bounds.rs:12:11
|
LL | impl<B> Add for A<B> where B: Add {
| - expected this type parameter
@@ -24,14 +24,14 @@ LL | A(self.0 + rhs.0)
= note: expected type parameter `B`
found associated type `<B as Add>::Output`
help: the type constructed contains `<B as Add>::Output` due to the type of the argument passed
--> $DIR/missing-bounds.rs:11:9
--> $DIR/missing-bounds.rs:12:9
|
LL | A(self.0 + rhs.0)
| ^^--------------^
| |
| this argument influences the type of `A`
note: tuple struct defined here
--> $DIR/missing-bounds.rs:5:8
--> $DIR/missing-bounds.rs:6:8
|
LL | struct A<B>(B);
| ^
@@ -41,7 +41,7 @@ LL | impl<B> Add for A<B> where B: Add<Output = B> {
| ++++++++++++

error[E0308]: mismatched types
--> $DIR/missing-bounds.rs:21:14
--> $DIR/missing-bounds.rs:23:14
|
LL | impl<B: Add> Add for C<B> {
| - expected this type parameter
@@ -54,7 +54,7 @@ LL | Self(self.0 + rhs.0)
= note: expected type parameter `B`
found associated type `<B as Add>::Output`
note: tuple struct defined here
--> $DIR/missing-bounds.rs:15:8
--> $DIR/missing-bounds.rs:17:8
|
LL | struct C<B>(B);
| ^
@@ -64,7 +64,7 @@ LL | impl<B: Add<Output = B>> Add for C<B> {
| ++++++++++++

error[E0369]: cannot add `B` to `B`
--> $DIR/missing-bounds.rs:31:21
--> $DIR/missing-bounds.rs:34:21
|
LL | Self(self.0 + rhs.0)
| ------ ^ ----- B
@@ -77,7 +77,7 @@ LL | impl<B: std::ops::Add<Output = B>> Add for D<B> {
| +++++++++++++++++++++++++++

error[E0308]: mismatched types
--> $DIR/missing-bounds.rs:42:14
--> $DIR/missing-bounds.rs:46:14
|
LL | impl<B: Add> Add for E<B> where <B as Add>::Output = B {
| - expected this type parameter
@@ -90,7 +90,7 @@ LL | Self(self.0 + rhs.0)
= note: expected type parameter `B`
found associated type `<B as Add>::Output`
note: tuple struct defined here
--> $DIR/missing-bounds.rs:35:8
--> $DIR/missing-bounds.rs:39:8
|
LL | struct E<B>(B);
| ^
11 changes: 11 additions & 0 deletions tests/ui/lint/dead-code/unused-trait-with-assoc-ty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![deny(dead_code)]

struct T1; //~ ERROR struct `T1` is never constructed

trait Foo { type Unused; } //~ ERROR trait `Foo` is never used
impl Foo for T1 { type Unused = Self; }

pub trait Bar { type Used; }
impl Bar for T1 { type Used = Self; }

fn main() {}
20 changes: 20 additions & 0 deletions tests/ui/lint/dead-code/unused-trait-with-assoc-ty.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: struct `T1` is never constructed
--> $DIR/unused-trait-with-assoc-ty.rs:3:8
|
LL | struct T1;
| ^^
|
note: the lint level is defined here
--> $DIR/unused-trait-with-assoc-ty.rs:1:9
|
LL | #![deny(dead_code)]
| ^^^^^^^^^

error: trait `Foo` is never used
--> $DIR/unused-trait-with-assoc-ty.rs:5:7
|
LL | trait Foo { type Unused; }
| ^^^

error: aborting due to 2 previous errors

2 changes: 1 addition & 1 deletion tests/ui/pattern/issue-22546.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ impl<T: ::std::fmt::Display> Foo<T> {
}
}

trait Tr { //~ WARN trait `Tr` is never used
trait Tr {
type U;
}

10 changes: 0 additions & 10 deletions tests/ui/pattern/issue-22546.stderr

This file was deleted.