Point out exactly what obligation will fail

This commit is contained in:
Michael Goulet 2024-06-12 21:42:46 -04:00
parent f1586001ac
commit fdd90db528
12 changed files with 80 additions and 6 deletions

View File

@ -45,6 +45,7 @@ hir_typeck_convert_using_method = try using `{$sugg}` to convert `{$found}` to `
hir_typeck_ctor_is_private = tuple struct constructor `{$def}` is private hir_typeck_ctor_is_private = tuple struct constructor `{$def}` is private
hir_typeck_dependency_on_unit_never_type_fallback = this function depends on never type fallback being `()` hir_typeck_dependency_on_unit_never_type_fallback = this function depends on never type fallback being `()`
.note = in edition 2024, the requirement `{$obligation}` will fail
.help = specify the types explicitly .help = specify the types explicitly
hir_typeck_deref_is_empty = this expression `Deref`s to `{$deref_ty}` which implements `is_empty` hir_typeck_deref_is_empty = this expression `Deref`s to `{$deref_ty}` which implements `is_empty`

View File

@ -7,7 +7,7 @@
SubdiagMessageOp, Subdiagnostic, SubdiagMessageOp, Subdiagnostic,
}; };
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::Ty; use rustc_middle::ty::{self, Ty};
use rustc_span::{ use rustc_span::{
edition::{Edition, LATEST_STABLE_EDITION}, edition::{Edition, LATEST_STABLE_EDITION},
symbol::Ident, symbol::Ident,
@ -186,7 +186,11 @@ pub enum NeverTypeFallbackFlowingIntoUnsafe {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[help] #[help]
#[diag(hir_typeck_dependency_on_unit_never_type_fallback)] #[diag(hir_typeck_dependency_on_unit_never_type_fallback)]
pub struct DependencyOnUnitNeverTypeFallback {} pub struct DependencyOnUnitNeverTypeFallback<'tcx> {
#[note]
pub obligation_span: Span,
pub obligation: ty::Predicate<'tcx>,
}
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[multipart_suggestion( #[multipart_suggestion(

View File

@ -488,7 +488,7 @@ fn lint_obligations_broken_by_never_type_fallback_change(
let remaining_errors_if_fallback_to = |fallback| { let remaining_errors_if_fallback_to = |fallback| {
self.probe(|_| { self.probe(|_| {
let obligations = self.fulfillment_cx.borrow().pending_obligations(); let obligations = self.fulfillment_cx.borrow().pending_obligations();
let ocx = ObligationCtxt::new(&self.infcx); let ocx = ObligationCtxt::new_with_diagnostics(&self.infcx);
ocx.register_obligations(obligations.iter().cloned()); ocx.register_obligations(obligations.iter().cloned());
for &diverging_vid in diverging_vids { for &diverging_vid in diverging_vids {
@ -506,14 +506,18 @@ fn lint_obligations_broken_by_never_type_fallback_change(
// then this code will be broken by the never type fallback change.qba // then this code will be broken by the never type fallback change.qba
let unit_errors = remaining_errors_if_fallback_to(self.tcx.types.unit); let unit_errors = remaining_errors_if_fallback_to(self.tcx.types.unit);
if unit_errors.is_empty() if unit_errors.is_empty()
&& let never_errors = remaining_errors_if_fallback_to(self.tcx.types.never) && let mut never_errors = remaining_errors_if_fallback_to(self.tcx.types.never)
&& !never_errors.is_empty() && let [ref mut never_error, ..] = never_errors.as_mut_slice()
{ {
self.adjust_fulfillment_error_for_expr_obligation(never_error);
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
lint::builtin::DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK, lint::builtin::DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
self.tcx.local_def_id_to_hir_id(self.body_id), self.tcx.local_def_id_to_hir_id(self.body_id),
self.tcx.def_span(self.body_id), self.tcx.def_span(self.body_id),
errors::DependencyOnUnitNeverTypeFallback {}, errors::DependencyOnUnitNeverTypeFallback {
obligation_span: never_error.obligation.cause.span,
obligation: never_error.obligation.predicate,
},
) )
} }
} }

View File

@ -124,6 +124,11 @@ LL | fn opaque_ret() -> impl Trait { unimplemented!() }
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly = help: specify the types explicitly
note: in edition 2024, the requirement `!: opaque::Trait` will fail
--> $DIR/not-supported.rs:80:28
|
LL | fn opaque_ret() -> impl Trait { unimplemented!() }
| ^^^^^^^^^^
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/not-supported.rs:86:5: 86:24>::{synthetic#0}` error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/not-supported.rs:86:5: 86:24>::{synthetic#0}`
@ -154,6 +159,11 @@ LL | pub fn opaque_ret() -> impl Trait { unimplemented!() }
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly = help: specify the types explicitly
note: in edition 2024, the requirement `!: opaque::Trait` will fail
--> $DIR/not-supported.rs:72:32
|
LL | pub fn opaque_ret() -> impl Trait { unimplemented!() }
| ^^^^^^^^^^
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/not-supported.rs:89:5: 89:25>::{synthetic#0}` error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/not-supported.rs:89:5: 89:25>::{synthetic#0}`
--> $DIR/not-supported.rs:90:24 --> $DIR/not-supported.rs:90:24

View File

@ -7,6 +7,11 @@ LL | fn m() {
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly = help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
--> $DIR/never-type-fallback-breaking.rs:19:17
|
LL | true => Default::default(),
| ^^^^^^^^^^^^^^^^^^
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
warning: this function depends on never type fallback being `()` warning: this function depends on never type fallback being `()`
@ -18,6 +23,11 @@ LL | fn q() -> Option<()> {
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly = help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
--> $DIR/never-type-fallback-breaking.rs:34:5
|
LL | deserialize()?;
| ^^^^^^^^^^^^^
warning: 2 warnings emitted warning: 2 warnings emitted

View File

@ -7,6 +7,11 @@ LL | fn smeg() {
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly = help: specify the types explicitly
note: in edition 2024, the requirement `!: ImplementedForUnitButNotNever` will fail
--> $DIR/defaulted-never-note.rs:32:9
|
LL | foo(_x);
| ^^
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
warning: 1 warning emitted warning: 1 warning emitted

View File

@ -7,6 +7,11 @@ LL | fn def() {
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly = help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
--> $DIR/dependency-on-fallback-to-unit.rs:12:19
|
LL | false => <_>::default(),
| ^
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
warning: this function depends on never type fallback being `()` warning: this function depends on never type fallback being `()`
@ -18,6 +23,11 @@ LL | fn question_mark() -> Result<(), ()> {
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly = help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
--> $DIR/dependency-on-fallback-to-unit.rs:22:5
|
LL | deserialize()?;
| ^^^^^^^^^^^^^
warning: 2 warnings emitted warning: 2 warnings emitted

View File

@ -7,6 +7,11 @@ LL | fn assignment() {
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly = help: specify the types explicitly
note: in edition 2024, the requirement `!: UnitDefault` will fail
--> $DIR/diverging-fallback-control-flow.rs:36:13
|
LL | x = UnitDefault::default();
| ^^^^^^^^^^^^^^^^^^^^^^
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
warning: this function depends on never type fallback being `()` warning: this function depends on never type fallback being `()`
@ -18,6 +23,11 @@ LL | fn assignment_rev() {
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly = help: specify the types explicitly
note: in edition 2024, the requirement `!: UnitDefault` will fail
--> $DIR/diverging-fallback-control-flow.rs:50:13
|
LL | x = UnitDefault::default();
| ^^^^^^^^^^^^^^^^^^^^^^
warning: 2 warnings emitted warning: 2 warnings emitted

View File

@ -7,6 +7,11 @@ LL | fn main() {
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly = help: specify the types explicitly
note: in edition 2024, the requirement `!: Test` will fail
--> $DIR/diverging-fallback-no-leak.rs:20:23
|
LL | unconstrained_arg(return);
| ^^^^^^
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
warning: 1 warning emitted warning: 1 warning emitted

View File

@ -7,6 +7,11 @@ LL | fn main() {
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly = help: specify the types explicitly
note: in edition 2024, the requirement `!: UnitReturn` will fail
--> $DIR/diverging-fallback-unconstrained-return.rs:39:23
|
LL | let _ = if true { unconstrained_return() } else { panic!() };
| ^^^^^^^^^^^^^^^^^^^^^^
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
warning: 1 warning emitted warning: 1 warning emitted

View File

@ -7,6 +7,11 @@ LL | fn main() {
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly = help: specify the types explicitly
note: in edition 2024, the requirement `!: Bar` will fail
--> $DIR/fallback-closure-ret.rs:24:5
|
LL | foo(|| panic!());
| ^^^^^^^^^^^^^^^^
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
warning: 1 warning emitted warning: 1 warning emitted

View File

@ -7,6 +7,11 @@ LL | fn should_ret_unit() -> impl T {
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748> = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly = help: specify the types explicitly
note: in edition 2024, the requirement `!: T` will fail
--> $DIR/impl_trait_fallback.rs:8:25
|
LL | fn should_ret_unit() -> impl T {
| ^^^^^^
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
warning: 1 warning emitted warning: 1 warning emitted