Skip to content

Commit 7e90b28

Browse files
authored
Unrolled build for rust-lang#126367
Rollup merge of rust-lang#126367 - compiler-errors:point-out-failing-never-obligation, r=WaffleLapkin Point out failing never obligation for `DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK` Based on top of rust-lang#125289, so just need to look at the last commit. r? `@WaffleLapkin`
2 parents 1d1356d + fdd90db commit 7e90b28

12 files changed

+80
-6
lines changed

compiler/rustc_hir_typeck/messages.ftl

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

compiler/rustc_hir_typeck/src/errors.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_errors::{
77
SubdiagMessageOp, Subdiagnostic,
88
};
99
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
10-
use rustc_middle::ty::Ty;
10+
use rustc_middle::ty::{self, Ty};
1111
use rustc_span::{
1212
edition::{Edition, LATEST_STABLE_EDITION},
1313
symbol::Ident,
@@ -186,7 +186,11 @@ pub enum NeverTypeFallbackFlowingIntoUnsafe {
186186
#[derive(LintDiagnostic)]
187187
#[help]
188188
#[diag(hir_typeck_dependency_on_unit_never_type_fallback)]
189-
pub struct DependencyOnUnitNeverTypeFallback {}
189+
pub struct DependencyOnUnitNeverTypeFallback<'tcx> {
190+
#[note]
191+
pub obligation_span: Span,
192+
pub obligation: ty::Predicate<'tcx>,
193+
}
190194

191195
#[derive(Subdiagnostic)]
192196
#[multipart_suggestion(

compiler/rustc_hir_typeck/src/fallback.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
488488
let remaining_errors_if_fallback_to = |fallback| {
489489
self.probe(|_| {
490490
let obligations = self.fulfillment_cx.borrow().pending_obligations();
491-
let ocx = ObligationCtxt::new(&self.infcx);
491+
let ocx = ObligationCtxt::new_with_diagnostics(&self.infcx);
492492
ocx.register_obligations(obligations.iter().cloned());
493493

494494
for &diverging_vid in diverging_vids {
@@ -506,14 +506,18 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
506506
// then this code will be broken by the never type fallback change.qba
507507
let unit_errors = remaining_errors_if_fallback_to(self.tcx.types.unit);
508508
if unit_errors.is_empty()
509-
&& let never_errors = remaining_errors_if_fallback_to(self.tcx.types.never)
510-
&& !never_errors.is_empty()
509+
&& let mut never_errors = remaining_errors_if_fallback_to(self.tcx.types.never)
510+
&& let [ref mut never_error, ..] = never_errors.as_mut_slice()
511511
{
512+
self.adjust_fulfillment_error_for_expr_obligation(never_error);
512513
self.tcx.emit_node_span_lint(
513514
lint::builtin::DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
514515
self.tcx.local_def_id_to_hir_id(self.body_id),
515516
self.tcx.def_span(self.body_id),
516-
errors::DependencyOnUnitNeverTypeFallback {},
517+
errors::DependencyOnUnitNeverTypeFallback {
518+
obligation_span: never_error.obligation.cause.span,
519+
obligation: never_error.obligation.predicate,
520+
},
517521
)
518522
}
519523
}

tests/ui/delegation/not-supported.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ LL | fn opaque_ret() -> impl Trait { unimplemented!() }
124124
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
125125
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
126126
= help: specify the types explicitly
127+
note: in edition 2024, the requirement `!: opaque::Trait` will fail
128+
--> $DIR/not-supported.rs:80:28
129+
|
130+
LL | fn opaque_ret() -> impl Trait { unimplemented!() }
131+
| ^^^^^^^^^^
127132
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
128133

129134
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!() }
154159
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
155160
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
156161
= help: specify the types explicitly
162+
note: in edition 2024, the requirement `!: opaque::Trait` will fail
163+
--> $DIR/not-supported.rs:72:32
164+
|
165+
LL | pub fn opaque_ret() -> impl Trait { unimplemented!() }
166+
| ^^^^^^^^^^
157167

158168
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/not-supported.rs:89:5: 89:25>::{synthetic#0}`
159169
--> $DIR/not-supported.rs:90:24

tests/ui/editions/never-type-fallback-breaking.e2021.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ LL | fn m() {
77
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
88
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
99
= help: specify the types explicitly
10+
note: in edition 2024, the requirement `!: Default` will fail
11+
--> $DIR/never-type-fallback-breaking.rs:19:17
12+
|
13+
LL | true => Default::default(),
14+
| ^^^^^^^^^^^^^^^^^^
1015
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
1116

1217
warning: this function depends on never type fallback being `()`
@@ -18,6 +23,11 @@ LL | fn q() -> Option<()> {
1823
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1924
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
2025
= help: specify the types explicitly
26+
note: in edition 2024, the requirement `!: Default` will fail
27+
--> $DIR/never-type-fallback-breaking.rs:34:5
28+
|
29+
LL | deserialize()?;
30+
| ^^^^^^^^^^^^^
2131

2232
warning: 2 warnings emitted
2333

tests/ui/never_type/defaulted-never-note.nofallback.stderr

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

1217
warning: 1 warning emitted

tests/ui/never_type/dependency-on-fallback-to-unit.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ LL | fn def() {
77
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
88
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
99
= help: specify the types explicitly
10+
note: in edition 2024, the requirement `!: Default` will fail
11+
--> $DIR/dependency-on-fallback-to-unit.rs:12:19
12+
|
13+
LL | false => <_>::default(),
14+
| ^
1015
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
1116

1217
warning: this function depends on never type fallback being `()`
@@ -18,6 +23,11 @@ LL | fn question_mark() -> Result<(), ()> {
1823
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1924
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
2025
= help: specify the types explicitly
26+
note: in edition 2024, the requirement `!: Default` will fail
27+
--> $DIR/dependency-on-fallback-to-unit.rs:22:5
28+
|
29+
LL | deserialize()?;
30+
| ^^^^^^^^^^^^^
2131

2232
warning: 2 warnings emitted
2333

tests/ui/never_type/diverging-fallback-control-flow.nofallback.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ LL | fn assignment() {
77
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
88
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
99
= help: specify the types explicitly
10+
note: in edition 2024, the requirement `!: UnitDefault` will fail
11+
--> $DIR/diverging-fallback-control-flow.rs:36:13
12+
|
13+
LL | x = UnitDefault::default();
14+
| ^^^^^^^^^^^^^^^^^^^^^^
1015
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
1116

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

2232
warning: 2 warnings emitted
2333

tests/ui/never_type/diverging-fallback-no-leak.nofallback.stderr

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

1217
warning: 1 warning emitted

tests/ui/never_type/diverging-fallback-unconstrained-return.nofallback.stderr

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

1217
warning: 1 warning emitted

tests/ui/never_type/fallback-closure-ret.nofallback.stderr

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

1217
warning: 1 warning emitted

tests/ui/never_type/impl_trait_fallback.stderr

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

1217
warning: 1 warning emitted

0 commit comments

Comments
 (0)