Rollup merge of #132933 - compiler-errors:never-lint-arg-bug, r=WaffleLapkin
Make sure that we suggest turbofishing the right type arg for never suggestion I had a bug where rust would suggest the wrong arg to turbofish `()` if there were any early-bound lifetimes... r? WaffleLapkin
This commit is contained in:
commit
506f52c7f3
5 changed files with 122 additions and 10 deletions
|
|
@ -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)
|
||||
|
|
|
|||
52
tests/ui/editions/never-type-fallback-breaking.e2021.fixed
Normal file
52
tests/ui/editions/never-type-fallback-breaking.e2021.fixed
Normal file
|
|
@ -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<T: Default>() -> Option<T> {
|
||||
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<T, ()> {
|
||||
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(())
|
||||
}
|
||||
|
|
@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <https://github.com/rust-lang/rust/issues/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<T: Default>() -> Option<T> {
|
||||
| ^^^^^^^ 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, 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<T, ()> {
|
||||
| ^^^^^^^^ required by this bound in `help`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
|
|||
|
|
@ -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<T, ()> {
|
||||
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(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue