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

Check let source before suggesting annotation #133691

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion compiler/rustc_hir_typeck/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,8 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {

fn visit_local(&mut self, local: &'tcx hir::LetStmt<'tcx>) -> Self::Result {
// For a local, try suggest annotating the type if it's missing.
if let None = local.ty
if let hir::LocalSource::Normal = local.source
&& let None = local.ty
&& let Some(ty) = self.fcx.typeck_results.borrow().node_type_opt(local.hir_id)
&& let Some(vid) = self.fcx.root_vid(ty)
&& self.reachable_vids.contains(&vid)
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/never_type/lint-breaking-2024-assign-underscore.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ run-rustfix

#![allow(unused)]
#![deny(dependency_on_unit_never_type_fallback)]

fn foo<T: Default>() -> Result<T, ()> {
Err(())
}

fn test() -> Result<(), ()> {
//~^ ERROR this function depends on never type fallback being `()`
//~| WARN this was previously accepted by the compiler but is being phased out
_ = foo::<()>()?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo the better suggestion would be to () = foo()?;, at least it's less noisy than ::<()> 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is impossible to suggest given how this desugars into two let statements

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or at least i don't want to look into it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

welp :(

Ok(())
}

fn main() {}
17 changes: 17 additions & 0 deletions tests/ui/never_type/lint-breaking-2024-assign-underscore.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ run-rustfix

#![allow(unused)]
#![deny(dependency_on_unit_never_type_fallback)]

fn foo<T: Default>() -> Result<T, ()> {
Err(())
}

fn test() -> Result<(), ()> {
//~^ ERROR this function depends on never type fallback being `()`
//~| WARN this was previously accepted by the compiler but is being phased out
_ = foo()?;
Ok(())
}

fn main() {}
26 changes: 26 additions & 0 deletions tests/ui/never_type/lint-breaking-2024-assign-underscore.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: this function depends on never type fallback being `()`
--> $DIR/lint-breaking-2024-assign-underscore.rs:10:1
|
LL | fn test() -> Result<(), ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
= 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/lint-breaking-2024-assign-underscore.rs:13:9
|
LL | _ = foo()?;
| ^^^^^
note: the lint level is defined here
--> $DIR/lint-breaking-2024-assign-underscore.rs:4:9
|
LL | #![deny(dependency_on_unit_never_type_fallback)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: use `()` annotations to avoid fallback changes
|
LL | _ = foo::<()>()?;
| ++++++

error: aborting due to 1 previous error

Loading