diff --git a/compiler/rustc_hir_typeck/src/fallback.rs b/compiler/rustc_hir_typeck/src/fallback.rs index 97f3807c2521e..7719facccc7ba 100644 --- a/compiler/rustc_hir_typeck/src/fallback.rs +++ b/compiler/rustc_hir_typeck/src/fallback.rs @@ -621,7 +621,11 @@ impl<'tcx> AnnotateUnitFallbackVisitor<'_, 'tcx> { .iter() .filter(|arg| matches!(arg.unpack(), ty::GenericArgKind::Type(_))) .count(); - for (idx, arg) in args.iter().enumerate() { + for (idx, arg) in args + .iter() + .filter(|arg| matches!(arg.unpack(), ty::GenericArgKind::Type(_))) + .enumerate() + { if let Some(ty) = arg.as_type() && let Some(vid) = self.fcx.root_vid(ty) && self.reachable_vids.contains(&vid) diff --git a/tests/ui/editions/never-type-fallback-breaking.e2021.fixed b/tests/ui/editions/never-type-fallback-breaking.e2021.fixed new file mode 100644 index 0000000000000..3fed16f0ee719 --- /dev/null +++ b/tests/ui/editions/never-type-fallback-breaking.e2021.fixed @@ -0,0 +1,52 @@ +//@ revisions: e2021 e2024 +// +//@[e2021] edition: 2021 +//@[e2024] edition: 2024 +//@[e2024] compile-flags: -Zunstable-options +// +//@[e2021] run-pass +//@[e2021] run-rustfix +//@[e2024] check-fail + +fn main() { + m(); + q(); + let _ = meow(); +} + +fn m() { + //[e2021]~^ this function depends on never type fallback being `()` + //[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + let x: () = match true { + true => Default::default(), + //[e2024]~^ error: the trait bound `!: Default` is not satisfied + false => panic!("..."), + }; + + dbg!(x); +} + +fn q() -> Option<()> { + //[e2021]~^ this function depends on never type fallback being `()` + //[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + fn deserialize() -> Option { + Some(T::default()) + } + + deserialize::<()>()?; + //[e2024]~^ error: the trait bound `!: Default` is not satisfied + + None +} + +// Make sure we turbofish the right argument +fn help<'a: 'a, T: Into<()>, U>(_: U) -> Result { + Err(()) +} +fn meow() -> Result<(), ()> { + //[e2021]~^ this function depends on never type fallback being `()` + //[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + help::<(), _>(1)?; + //[e2024]~^ error: the trait bound `(): From` is not satisfied + Ok(()) +} diff --git a/tests/ui/editions/never-type-fallback-breaking.e2021.stderr b/tests/ui/editions/never-type-fallback-breaking.e2021.stderr index 79eee2a3defd0..fdc97e54d4e44 100644 --- a/tests/ui/editions/never-type-fallback-breaking.e2021.stderr +++ b/tests/ui/editions/never-type-fallback-breaking.e2021.stderr @@ -1,5 +1,5 @@ warning: this function depends on never type fallback being `()` - --> $DIR/never-type-fallback-breaking.rs:15:1 + --> $DIR/never-type-fallback-breaking.rs:17:1 | LL | fn m() { | ^^^^^^ @@ -8,7 +8,7 @@ LL | fn m() { = note: for more information, see issue #123748 = help: specify the types explicitly note: in edition 2024, the requirement `!: Default` will fail - --> $DIR/never-type-fallback-breaking.rs:19:17 + --> $DIR/never-type-fallback-breaking.rs:21:17 | LL | true => Default::default(), | ^^^^^^^^^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | let x: () = match true { | ++++ warning: this function depends on never type fallback being `()` - --> $DIR/never-type-fallback-breaking.rs:27:1 + --> $DIR/never-type-fallback-breaking.rs:29:1 | LL | fn q() -> Option<()> { | ^^^^^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | fn q() -> Option<()> { = note: for more information, see issue #123748 = help: specify the types explicitly note: in edition 2024, the requirement `!: Default` will fail - --> $DIR/never-type-fallback-breaking.rs:34:5 + --> $DIR/never-type-fallback-breaking.rs:36:5 | LL | deserialize()?; | ^^^^^^^^^^^^^ @@ -37,5 +37,24 @@ help: use `()` annotations to avoid fallback changes LL | deserialize::<()>()?; | ++++++ -warning: 2 warnings emitted +warning: this function depends on never type fallback being `()` + --> $DIR/never-type-fallback-breaking.rs:46:1 + | +LL | fn meow() -> Result<(), ()> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = 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 + = help: specify the types explicitly +note: in edition 2024, the requirement `(): From` will fail + --> $DIR/never-type-fallback-breaking.rs:49:5 + | +LL | help(1)?; + | ^^^^^^^ +help: use `()` annotations to avoid fallback changes + | +LL | help::<(), _>(1)?; + | +++++++++ + +warning: 3 warnings emitted diff --git a/tests/ui/editions/never-type-fallback-breaking.e2024.stderr b/tests/ui/editions/never-type-fallback-breaking.e2024.stderr index 461e4ae0bdf6d..6258247f8b28e 100644 --- a/tests/ui/editions/never-type-fallback-breaking.e2024.stderr +++ b/tests/ui/editions/never-type-fallback-breaking.e2024.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `!: Default` is not satisfied - --> $DIR/never-type-fallback-breaking.rs:19:17 + --> $DIR/never-type-fallback-breaking.rs:21:17 | LL | true => Default::default(), | ^^^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `!` @@ -8,7 +8,7 @@ LL | true => Default::default(), = help: did you intend to use the type `()` here instead? error[E0277]: the trait bound `!: Default` is not satisfied - --> $DIR/never-type-fallback-breaking.rs:34:5 + --> $DIR/never-type-fallback-breaking.rs:36:5 | LL | deserialize()?; | ^^^^^^^^^^^^^ the trait `Default` is not implemented for `!` @@ -16,11 +16,34 @@ LL | deserialize()?; = note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #48950 for more information) = help: did you intend to use the type `()` here instead? note: required by a bound in `deserialize` - --> $DIR/never-type-fallback-breaking.rs:30:23 + --> $DIR/never-type-fallback-breaking.rs:32:23 | LL | fn deserialize() -> Option { | ^^^^^^^ required by this bound in `deserialize` -error: aborting due to 2 previous errors +error[E0277]: the trait bound `(): From` is not satisfied + --> $DIR/never-type-fallback-breaking.rs:49:5 + | +LL | help(1)?; + | ^^^^^^^ the trait `From` is not implemented for `()` + | + = help: the following other types implement trait `From`: + `(T, T)` implements `From<[T; 2]>` + `(T, T, T)` implements `From<[T; 3]>` + `(T, T, T, T)` implements `From<[T; 4]>` + `(T, T, T, T, T)` implements `From<[T; 5]>` + `(T, T, T, T, T, T)` implements `From<[T; 6]>` + `(T, T, T, T, T, T, T)` implements `From<[T; 7]>` + `(T, T, T, T, T, T, T, T)` implements `From<[T; 8]>` + `(T, T, T, T, T, T, T, T, T)` implements `From<[T; 9]>` + and 4 others + = note: required for `!` to implement `Into<()>` +note: required by a bound in `help` + --> $DIR/never-type-fallback-breaking.rs:43:20 + | +LL | fn help<'a: 'a, T: Into<()>, U>(_: U) -> Result { + | ^^^^^^^^ required by this bound in `help` + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/editions/never-type-fallback-breaking.rs b/tests/ui/editions/never-type-fallback-breaking.rs index 7b4a1b1de0487..71d36f3a2d92b 100644 --- a/tests/ui/editions/never-type-fallback-breaking.rs +++ b/tests/ui/editions/never-type-fallback-breaking.rs @@ -5,11 +5,13 @@ //@[e2024] compile-flags: -Zunstable-options // //@[e2021] run-pass +//@[e2021] run-rustfix //@[e2024] check-fail fn main() { m(); q(); + let _ = meow(); } fn m() { @@ -36,3 +38,15 @@ fn q() -> Option<()> { None } + +// Make sure we turbofish the right argument +fn help<'a: 'a, T: Into<()>, U>(_: U) -> Result { + Err(()) +} +fn meow() -> Result<(), ()> { + //[e2021]~^ this function depends on never type fallback being `()` + //[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + help(1)?; + //[e2024]~^ error: the trait bound `(): From` is not satisfied + Ok(()) +}