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 11 pull requests #120408

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
853504d
Remove feature not required by `Ipv6Addr::to_cononical` doctest
eopb Jan 5, 2024
1eaeaaf
Add FileCheck for array_index.rs, boolean_identities.rs and cast.rs
sfzhu93 Jan 8, 2024
e05c779
Add FileCheck for checked.rs and default_boxed_slice.rs.
sfzhu93 Jan 8, 2024
33e5d85
Add FileCheck for enum.rs
sfzhu93 Jan 8, 2024
24aefa0
Add FileCheck for if.rs, inherit_overflow.rs, issue_81605.rs
sfzhu93 Jan 9, 2024
9452d7e
Add FileCheck to 3 tests: large_array_index, mult_by_zero, and offset_of
sfzhu93 Jan 9, 2024
e9152e2
Add FileCheck to 3 tests: ref_without_sb, repeat, repr_transparent
sfzhu93 Jan 9, 2024
3ab1d5d
Add FileCheck to 3 tests: self_assign_add, self_assign, and sibling_ptr
sfzhu93 Jan 9, 2024
d765e3a
Add FileCheck to slice_len.rs
sfzhu93 Jan 9, 2024
732f6a1
Add FileCheck to struct.rs
sfzhu93 Jan 9, 2024
1adda9a
Add FileCheck to terminator.rs and tuple.rs
sfzhu93 Jan 9, 2024
7135168
Add FileCheck for enum.rs
sfzhu93 Jan 8, 2024
d63f10b
resolve code reviews
sfzhu93 Jan 12, 2024
1c886d7
resolve code reviews
sfzhu93 Jan 12, 2024
cd77d59
update enum.rs for code review
sfzhu93 Jan 13, 2024
5747ece
add FIXME for default_boxed_slice.rs
sfzhu93 Jan 15, 2024
edba949
update misuse of check-label
sfzhu93 Jan 20, 2024
7ad307d
finish a pattern in `enum.rs`
sfzhu93 Jan 20, 2024
65b1083
update enum.rs
sfzhu93 Jan 23, 2024
f9259d1
Boost intersperse(_with) performance
nyurik May 9, 2023
b8d245e
Postpone .next() call until iteration
nyurik May 9, 2023
f1dbc7b
fmt
nyurik May 9, 2023
8cbff0b
Update library/core/src/iter/adapters/intersperse.rs
nyurik Jan 26, 2024
77f31ef
use checked_add for upper bound
nyurik Jan 26, 2024
6e53e66
MCP #705: Provide the option `-Csymbol-mangling-version=hashed -Z uns…
h1467792822 Dec 5, 2023
730299b
Regenerate `uninhabited_enum_branching.rs`
DianQK Jan 26, 2024
df9681b
Replace the default branch with an unreachable branch If it is the la…
DianQK Jan 23, 2024
a3341df
Get all variants to eliminate the default branching if we cannot get …
DianQK Jan 24, 2024
bdf7404
Update codegen test for LLVM 18
nikic Jan 26, 2024
90254cd
ScopeTree: remove destruction_scopes as unused
klensy Jan 26, 2024
304361a
Improve handling of numbers in IntoDiagnosticArg
Urgau Jan 26, 2024
93ff4a4
Fix typo
Urgau Jan 26, 2024
169c728
Remove myself from review rotation
thomcc Jan 26, 2024
a5d9def
Properly recover from trailing attr in body
estebank Nov 22, 2023
3022c76
Avoid ICE in trait without `dyn` lint
estebank Jan 23, 2024
37f8c01
Rollup merge of #111379 - nyurik:intersperse-speed-up, r=cuviper
Nadrieril Jan 27, 2024
00f5e09
Rollup merge of #118182 - estebank:issue-118164, r=davidtwco
Nadrieril Jan 27, 2024
b4bda9b
Rollup merge of #118636 - h1467792822:dev, r=michaelwoerister
Nadrieril Jan 27, 2024
b93aba2
Rollup merge of #119641 - eopb:std-unused-ip-feature, r=ChrisDenton
Nadrieril Jan 27, 2024
696cec3
Rollup merge of #119759 - sfzhu93:master, r=cjgillot
Nadrieril Jan 27, 2024
35c1914
Rollup merge of #120268 - DianQK:otherwise_is_last_variant_switchs, r…
Nadrieril Jan 27, 2024
a58ce1e
Rollup merge of #120275 - estebank:issue-120241, r=fmease
Nadrieril Jan 27, 2024
340c99b
Rollup merge of #120376 - nikic:update-codegen-test, r=cuviper
Nadrieril Jan 27, 2024
98b86de
Rollup merge of #120386 - klensy:destruction_scopes, r=compiler-errors
Nadrieril Jan 27, 2024
9018ae8
Rollup merge of #120398 - Urgau:into_diag_arg-numbers, r=compiler-errors
Nadrieril Jan 27, 2024
4459817
Rollup merge of #120399 - thomcc:thomcc-no-rotation, r=Nilstrieb
Nadrieril Jan 27, 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
Avoid ICE in trait without dyn lint
Do not attempt to provide an accurate suggestion for `impl Trait`
in bare trait types when linting. Instead, only do the object
safety check when an E0782 is already going to be emitted in the
2021 edition.

Fix #120241.
  • Loading branch information
estebank committed Jan 27, 2024
commit 3022c769ab9d19c7bf68f7ebd753cac3495cc0a1
10 changes: 4 additions & 6 deletions compiler/rustc_hir_analysis/src/astconv/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
],
Applicability::MachineApplicable,
);
} else if diag.is_error() && is_downgradable {
} else if is_downgradable {
// We'll emit the object safety error already, with a structured suggestion.
diag.downgrade_to_delayed_bug();
}
Expand All @@ -158,7 +158,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
if !is_object_safe {
diag.note(format!("`{trait_name}` it is not object safe, so it can't be `dyn`"));
if diag.is_error() && is_downgradable {
if is_downgradable {
// We'll emit the object safety error already, with a structured suggestion.
diag.downgrade_to_delayed_bug();
}
Expand Down Expand Up @@ -241,13 +241,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} else {
let msg = "trait objects without an explicit `dyn` are deprecated";
tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, msg, |lint| {
if self_ty.span.can_be_used_for_suggestions()
&& !self.maybe_lint_impl_trait(self_ty, lint)
{
if self_ty.span.can_be_used_for_suggestions() {
lint.multipart_suggestion_verbose(
"use `dyn`",
sugg,
Applicability::MachineApplicable,
Applicability::MaybeIncorrect,
);
}
self.maybe_lint_blanket_trait_impl(self_ty, lint);
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/object-safety/avoid-ice-on-warning-2.new.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0038]: the trait `Copy` cannot be made into an object
--> $DIR/avoid-ice-on-warning-2.rs:4:13
|
LL | fn id<F>(f: Copy) -> usize {
| ^^^^ `Copy` cannot be made into an object
|
= note: the trait cannot be made into an object because it requires `Self: Sized`
= note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0038`.
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/avoid-ice-on-warning-2.rs:1:13
--> $DIR/avoid-ice-on-warning-2.rs:4:13
|
LL | fn id<F>(f: Copy) -> usize {
| ^^^^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `Copy` it is not object safe, so it can't be `dyn`
= note: `#[warn(bare_trait_objects)]` on by default
help: use a new generic type parameter, constrained by `Copy`
help: use `dyn`
|
LL | fn id<F, T: Copy>(f: T) -> usize {
| +++++++++ ~
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
|
LL | fn id<F>(f: impl Copy) -> usize {
| ++++
LL | fn id<F>(f: dyn Copy) -> usize {
| +++

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/avoid-ice-on-warning-2.rs:1:13
--> $DIR/avoid-ice-on-warning-2.rs:4:13
|
LL | fn id<F>(f: Copy) -> usize {
| ^^^^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `Copy` it is not object safe, so it can't be `dyn`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use a new generic type parameter, constrained by `Copy`
|
LL | fn id<F, T: Copy>(f: T) -> usize {
| +++++++++ ~
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
help: use `dyn`
|
LL | fn id<F>(f: impl Copy) -> usize {
| ++++
LL | fn id<F>(f: dyn Copy) -> usize {
| +++

error[E0038]: the trait `Copy` cannot be made into an object
--> $DIR/avoid-ice-on-warning-2.rs:1:13
--> $DIR/avoid-ice-on-warning-2.rs:4:13
|
LL | fn id<F>(f: Copy) -> usize {
| ^^^^ `Copy` cannot be made into an object
Expand Down
13 changes: 8 additions & 5 deletions tests/ui/object-safety/avoid-ice-on-warning-2.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// revisions: old new
//[old] edition:2015
//[new] edition:2021
fn id<F>(f: Copy) -> usize {
//~^ WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
//~| WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
//~| ERROR the trait `Copy` cannot be made into an object
//~^ ERROR the trait `Copy` cannot be made into an object
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
//[old]~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
//[old]~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
f()
}
fn main() {}
47 changes: 47 additions & 0 deletions tests/ui/object-safety/avoid-ice-on-warning-3.new.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
error[E0038]: the trait `A` cannot be made into an object
--> $DIR/avoid-ice-on-warning-3.rs:4:19
|
LL | trait B { fn f(a: A) -> A; }
| ^ `A` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/avoid-ice-on-warning-3.rs:12:14
|
LL | trait A { fn g(b: B) -> B; }
| - ^ ...because associated function `g` has no `self` parameter
| |
| this trait cannot be made into an object...
help: consider turning `g` into a method by giving it a `&self` argument
|
LL | trait A { fn g(&self, b: B) -> B; }
| ++++++
help: alternatively, consider constraining `g` so it does not apply to trait objects
|
LL | trait A { fn g(b: B) -> B where Self: Sized; }
| +++++++++++++++++

error[E0038]: the trait `B` cannot be made into an object
--> $DIR/avoid-ice-on-warning-3.rs:12:19
|
LL | trait A { fn g(b: B) -> B; }
| ^ `B` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/avoid-ice-on-warning-3.rs:4:14
|
LL | trait B { fn f(a: A) -> A; }
| - ^ ...because associated function `f` has no `self` parameter
| |
| this trait cannot be made into an object...
help: consider turning `f` into a method by giving it a `&self` argument
|
LL | trait B { fn f(&self, a: A) -> A; }
| ++++++
help: alternatively, consider constraining `f` so it does not apply to trait objects
|
LL | trait B { fn f(a: A) -> A where Self: Sized; }
| +++++++++++++++++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0038`.
Original file line number Diff line number Diff line change
@@ -1,93 +1,78 @@
warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/avoid-ice-on-warning-3.rs:9:19
--> $DIR/avoid-ice-on-warning-3.rs:4:19
|
LL | trait A { fn g(b: B) -> B; }
LL | trait B { fn f(a: A) -> A; }
| ^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `B` it is not object safe, so it can't be `dyn`
= note: `#[warn(bare_trait_objects)]` on by default
help: use a new generic type parameter, constrained by `B`
|
LL | trait A { fn g<T: B>(b: T) -> B; }
| ++++++ ~
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
help: use `dyn`
|
LL | trait A { fn g(b: impl B) -> B; }
| ++++
LL | trait B { fn f(a: dyn A) -> A; }
| +++

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/avoid-ice-on-warning-3.rs:9:25
--> $DIR/avoid-ice-on-warning-3.rs:4:25
|
LL | trait A { fn g(b: B) -> B; }
LL | trait B { fn f(a: A) -> A; }
| ^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: `B` is not object safe, use `impl B` to return an opaque type, as long as you return a single underlying type
help: use `dyn`
|
LL | trait A { fn g(b: B) -> impl B; }
| ++++
LL | trait B { fn f(a: A) -> dyn A; }
| +++

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/avoid-ice-on-warning-3.rs:1:19
--> $DIR/avoid-ice-on-warning-3.rs:12:19
|
LL | trait B { fn f(a: A) -> A; }
LL | trait A { fn g(b: B) -> B; }
| ^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `A` it is not object safe, so it can't be `dyn`
help: use a new generic type parameter, constrained by `A`
|
LL | trait B { fn f<T: A>(a: T) -> A; }
| ++++++ ~
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
help: use `dyn`
|
LL | trait B { fn f(a: impl A) -> A; }
| ++++
LL | trait A { fn g(b: dyn B) -> B; }
| +++

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/avoid-ice-on-warning-3.rs:1:25
--> $DIR/avoid-ice-on-warning-3.rs:12:25
|
LL | trait B { fn f(a: A) -> A; }
LL | trait A { fn g(b: B) -> B; }
| ^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
help: `A` is not object safe, use `impl A` to return an opaque type, as long as you return a single underlying type
help: use `dyn`
|
LL | trait B { fn f(a: A) -> impl A; }
| ++++
LL | trait A { fn g(b: B) -> dyn B; }
| +++

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/avoid-ice-on-warning-3.rs:1:19
--> $DIR/avoid-ice-on-warning-3.rs:4:19
|
LL | trait B { fn f(a: A) -> A; }
| ^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `A` it is not object safe, so it can't be `dyn`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use a new generic type parameter, constrained by `A`
|
LL | trait B { fn f<T: A>(a: T) -> A; }
| ++++++ ~
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
help: use `dyn`
|
LL | trait B { fn f(a: impl A) -> A; }
| ++++
LL | trait B { fn f(a: dyn A) -> A; }
| +++

error[E0038]: the trait `A` cannot be made into an object
--> $DIR/avoid-ice-on-warning-3.rs:1:19
--> $DIR/avoid-ice-on-warning-3.rs:4:19
|
LL | trait B { fn f(a: A) -> A; }
| ^ `A` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/avoid-ice-on-warning-3.rs:9:14
--> $DIR/avoid-ice-on-warning-3.rs:12:14
|
LL | trait A { fn g(b: B) -> B; }
| - ^ ...because associated function `g` has no `self` parameter
Expand All @@ -103,32 +88,27 @@ LL | trait A { fn g(b: B) -> B where Self: Sized; }
| +++++++++++++++++

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/avoid-ice-on-warning-3.rs:9:19
--> $DIR/avoid-ice-on-warning-3.rs:12:19
|
LL | trait A { fn g(b: B) -> B; }
| ^
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `B` it is not object safe, so it can't be `dyn`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: use a new generic type parameter, constrained by `B`
|
LL | trait A { fn g<T: B>(b: T) -> B; }
| ++++++ ~
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
help: use `dyn`
|
LL | trait A { fn g(b: impl B) -> B; }
| ++++
LL | trait A { fn g(b: dyn B) -> B; }
| +++

error[E0038]: the trait `B` cannot be made into an object
--> $DIR/avoid-ice-on-warning-3.rs:9:19
--> $DIR/avoid-ice-on-warning-3.rs:12:19
|
LL | trait A { fn g(b: B) -> B; }
| ^ `B` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/avoid-ice-on-warning-3.rs:1:14
--> $DIR/avoid-ice-on-warning-3.rs:4:14
|
LL | trait B { fn f(a: A) -> A; }
| - ^ ...because associated function `f` has no `self` parameter
Expand Down
31 changes: 17 additions & 14 deletions tests/ui/object-safety/avoid-ice-on-warning-3.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
// revisions: old new
//[old] edition:2015
//[new] edition:2021
trait B { fn f(a: A) -> A; }
//~^ WARN trait objects without an explicit `dyn` are deprecated
//~| WARN trait objects without an explicit `dyn` are deprecated
//~| WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
//~| WARN this is accepted in the current edition
//~| WARN this is accepted in the current edition
//~| ERROR the trait `A` cannot be made into an object
//~^ ERROR the trait `A` cannot be made into an object
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
//[old]~| WARN this is accepted in the current edition
//[old]~| WARN this is accepted in the current edition
//[old]~| WARN this is accepted in the current edition
trait A { fn g(b: B) -> B; }
//~^ WARN trait objects without an explicit `dyn` are deprecated
//~| WARN trait objects without an explicit `dyn` are deprecated
//~| WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
//~| WARN this is accepted in the current edition
//~| WARN this is accepted in the current edition
//~| ERROR the trait `B` cannot be made into an object
//~^ ERROR the trait `B` cannot be made into an object
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
//[old]~| WARN this is accepted in the current edition
//[old]~| WARN this is accepted in the current edition
//[old]~| WARN this is accepted in the current edition
fn main() {}
15 changes: 15 additions & 0 deletions tests/ui/object-safety/avoid-ice-on-warning.new.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: return types are denoted using `->`
--> $DIR/avoid-ice-on-warning.rs:4:23
|
LL | fn call_this<F>(f: F) : Fn(&str) + call_that {}
| ^ help: use `->` instead

error[E0405]: cannot find trait `call_that` in this scope
--> $DIR/avoid-ice-on-warning.rs:4:36
|
LL | fn call_this<F>(f: F) : Fn(&str) + call_that {}
| ^^^^^^^^^ not found in this scope

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0405`.
Loading
Loading