Skip to content

Commit 78dad1e

Browse files
authored
Rollup merge of #133691 - compiler-errors:let-source, r=lqd
Check let source before suggesting annotation Make sure we don't annotate nonsense type annotations on locals that come from desugarings. fixes #133688
2 parents 2f00feb + 805649b commit 78dad1e

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

compiler/rustc_hir_typeck/src/fallback.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,8 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
705705

706706
fn visit_local(&mut self, local: &'tcx hir::LetStmt<'tcx>) -> Self::Result {
707707
// For a local, try suggest annotating the type if it's missing.
708-
if let None = local.ty
708+
if let hir::LocalSource::Normal = local.source
709+
&& let None = local.ty
709710
&& let Some(ty) = self.fcx.typeck_results.borrow().node_type_opt(local.hir_id)
710711
&& let Some(vid) = self.fcx.root_vid(ty)
711712
&& self.reachable_vids.contains(&vid)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ run-rustfix
2+
3+
#![allow(unused)]
4+
#![deny(dependency_on_unit_never_type_fallback)]
5+
6+
fn foo<T: Default>() -> Result<T, ()> {
7+
Err(())
8+
}
9+
10+
fn test() -> Result<(), ()> {
11+
//~^ ERROR this function depends on never type fallback being `()`
12+
//~| WARN this was previously accepted by the compiler but is being phased out
13+
_ = foo::<()>()?;
14+
Ok(())
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ run-rustfix
2+
3+
#![allow(unused)]
4+
#![deny(dependency_on_unit_never_type_fallback)]
5+
6+
fn foo<T: Default>() -> Result<T, ()> {
7+
Err(())
8+
}
9+
10+
fn test() -> Result<(), ()> {
11+
//~^ ERROR this function depends on never type fallback being `()`
12+
//~| WARN this was previously accepted by the compiler but is being phased out
13+
_ = foo()?;
14+
Ok(())
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: this function depends on never type fallback being `()`
2+
--> $DIR/lint-breaking-2024-assign-underscore.rs:10:1
3+
|
4+
LL | fn test() -> Result<(), ()> {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= 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!
8+
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
9+
= help: specify the types explicitly
10+
note: in edition 2024, the requirement `!: Default` will fail
11+
--> $DIR/lint-breaking-2024-assign-underscore.rs:13:9
12+
|
13+
LL | _ = foo()?;
14+
| ^^^^^
15+
note: the lint level is defined here
16+
--> $DIR/lint-breaking-2024-assign-underscore.rs:4:9
17+
|
18+
LL | #![deny(dependency_on_unit_never_type_fallback)]
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
help: use `()` annotations to avoid fallback changes
21+
|
22+
LL | _ = foo::<()>()?;
23+
| ++++++
24+
25+
error: aborting due to 1 previous error
26+

0 commit comments

Comments
 (0)