about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-12-01 03:01:00 +0000
committerMichael Goulet <michael@errs.io>2024-12-01 03:01:05 +0000
commit805649b6482f65dfcbdc7dfc96d4b14f5bf1ad99 (patch)
tree2a35bc96766830709cd0c73bd9af7cbdc5f742de
parent7442931d49b199ad0a1cc0f8ca54e327b5139b66 (diff)
downloadrust-805649b6482f65dfcbdc7dfc96d4b14f5bf1ad99.tar.gz
rust-805649b6482f65dfcbdc7dfc96d4b14f5bf1ad99.zip
Check let source before suggesting annotation
-rw-r--r--compiler/rustc_hir_typeck/src/fallback.rs3
-rw-r--r--tests/ui/never_type/lint-breaking-2024-assign-underscore.fixed17
-rw-r--r--tests/ui/never_type/lint-breaking-2024-assign-underscore.rs17
-rw-r--r--tests/ui/never_type/lint-breaking-2024-assign-underscore.stderr26
4 files changed, 62 insertions, 1 deletions
diff --git a/compiler/rustc_hir_typeck/src/fallback.rs b/compiler/rustc_hir_typeck/src/fallback.rs
index 7719facccc7..ddd146fe785 100644
--- a/compiler/rustc_hir_typeck/src/fallback.rs
+++ b/compiler/rustc_hir_typeck/src/fallback.rs
@@ -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)
diff --git a/tests/ui/never_type/lint-breaking-2024-assign-underscore.fixed b/tests/ui/never_type/lint-breaking-2024-assign-underscore.fixed
new file mode 100644
index 00000000000..f9f2b59a8c2
--- /dev/null
+++ b/tests/ui/never_type/lint-breaking-2024-assign-underscore.fixed
@@ -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() {}
diff --git a/tests/ui/never_type/lint-breaking-2024-assign-underscore.rs b/tests/ui/never_type/lint-breaking-2024-assign-underscore.rs
new file mode 100644
index 00000000000..8a2f3d311ab
--- /dev/null
+++ b/tests/ui/never_type/lint-breaking-2024-assign-underscore.rs
@@ -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() {}
diff --git a/tests/ui/never_type/lint-breaking-2024-assign-underscore.stderr b/tests/ui/never_type/lint-breaking-2024-assign-underscore.stderr
new file mode 100644
index 00000000000..dc4ffa0d6f4
--- /dev/null
+++ b/tests/ui/never_type/lint-breaking-2024-assign-underscore.stderr
@@ -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
+