Skip to content

Commit d163a28

Browse files
committed
Auto merge of rust-lang#141011 - matthiaskrgr:rollup-4uwllo2, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#140827 (Do not ICE when reassigning in GatherLocalsVisitor on the bad path) - rust-lang#140904 (Add an issue template for future-incompatible lints) - rust-lang#140953 (Fix a compiletest blessing message) - rust-lang#140973 (Update rustix to 1.0.7 for bootstrap) - rust-lang#140976 (Add `Ipv4Addr` and `Ipv6Addr` diagnostic items) - rust-lang#140988 (MaybeUninit::write: fix doc) - rust-lang#140989 (Suggest replace f with f: Box<f> when expr field is short hand) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2a5da7a + e39ab25 commit d163a28

File tree

14 files changed

+194
-46
lines changed

14 files changed

+194
-46
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
name: Future Incompatibility Tracking Issue
3+
about: A tracking issue for a future-incompatible lint
4+
title: Tracking Issue for future-incompatibility lint XXX
5+
labels: C-tracking-issue C-future-incompatibility T-compiler A-lints
6+
---
7+
<!--
8+
Thank you for creating a future-incompatible tracking issue! 📜 These issues
9+
are for lints that implement a future-incompatible warning.
10+
11+
Remember to add team labels to the tracking issue.
12+
For something that affects the language, this would be `T-lang`, and for libs
13+
it would be `T-libs-api`.
14+
Also check for any `A-` labels to add.
15+
-->
16+
17+
This is the **tracking issue** for the `YOUR_LINT_NAME_HERE` future-compatibility warning and other related errors. The goal of this page is describe why this change was made and how you can fix code that is affected by it. It also provides a place to ask questions or register a complaint if you feel the change should not be made. For more information on the policy around future-compatibility warnings, see our [breaking change policy guidelines][guidelines].
18+
19+
[guidelines]: https://rustc-dev-guide.rust-lang.org/bug-fix-procedure.html
20+
21+
### What is the warning for?
22+
23+
*Describe the conditions that trigger the warning.*
24+
25+
### Why was this change made?
26+
27+
*Explain why this change was made. If there is additional context, like an MCP, link it here.*
28+
29+
### Example
30+
31+
```rust
32+
// Include an example here.
33+
```
34+
35+
### Recommendations
36+
37+
*Give some recommendations on how a user can avoid the lint.*
38+
39+
### When will this warning become a hard error?
40+
41+
*If known, describe the future plans. For example, how long you anticipate this being a warning, or if there are other factors that will influence the anticipated closure.*
42+
43+
### Steps
44+
45+
- [ ] Implement the lint
46+
- [ ] Raise lint level to deny
47+
- [ ] Make lint report in dependencies
48+
- [ ] Switch to a hard error
49+
50+
### Implementation history
51+
52+
<!--
53+
Include a list of all the PRs that were involved in implementing the lint.
54+
-->

compiler/rustc_hir_typeck/src/errors.rs

+12
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,18 @@ pub(crate) enum SuggestBoxing {
680680
hir_typeck_suggest_boxing_when_appropriate,
681681
applicability = "machine-applicable"
682682
)]
683+
ExprFieldShorthand {
684+
#[suggestion_part(code = "{ident}: Box::new(")]
685+
start: Span,
686+
#[suggestion_part(code = ")")]
687+
end: Span,
688+
ident: Ident,
689+
},
690+
#[note(hir_typeck_suggest_boxing_note)]
691+
#[multipart_suggestion(
692+
hir_typeck_suggest_boxing_when_appropriate,
693+
applicability = "machine-applicable"
694+
)]
683695
Other {
684696
#[suggestion_part(code = "Box::new(")]
685697
start: Span,

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+9
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
585585
{
586586
errors::SuggestBoxing::AsyncBody
587587
}
588+
_ if let Node::ExprField(expr_field) = self.tcx.parent_hir_node(hir_id)
589+
&& expr_field.is_shorthand =>
590+
{
591+
errors::SuggestBoxing::ExprFieldShorthand {
592+
start: span.shrink_to_lo(),
593+
end: span.shrink_to_hi(),
594+
ident: expr_field.ident,
595+
}
596+
}
588597
_ => errors::SuggestBoxing::Other {
589598
start: span.shrink_to_lo(),
590599
end: span.shrink_to_hi(),

compiler/rustc_hir_typeck/src/gather_locals.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,26 @@ impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> {
105105
}
106106

107107
fn assign(&mut self, span: Span, nid: HirId, ty_opt: Option<Ty<'tcx>>) -> Ty<'tcx> {
108+
// We evaluate expressions twice occasionally in diagnostics for better
109+
// type information or because it needs type information out-of-order.
110+
// In order to not ICE and not lead to knock-on ambiguity errors, if we
111+
// try to re-assign a type to a local, then just take out the previous
112+
// type and delay a bug.
113+
if let Some(&local) = self.fcx.locals.borrow_mut().get(&nid) {
114+
self.fcx.dcx().span_delayed_bug(span, "evaluated expression more than once");
115+
return local;
116+
}
117+
108118
match ty_opt {
109119
None => {
110120
// Infer the variable's type.
111121
let var_ty = self.fcx.next_ty_var(span);
112-
assert_eq!(self.fcx.locals.borrow_mut().insert(nid, var_ty), None);
122+
self.fcx.locals.borrow_mut().insert(nid, var_ty);
113123
var_ty
114124
}
115125
Some(typ) => {
116126
// Take type that the user specified.
117-
assert_eq!(self.fcx.locals.borrow_mut().insert(nid, typ), None);
127+
self.fcx.locals.borrow_mut().insert(nid, typ);
118128
typ
119129
}
120130
}

compiler/rustc_span/src/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ symbols! {
280280
IoSeek,
281281
IoWrite,
282282
IpAddr,
283+
Ipv4Addr,
284+
Ipv6Addr,
283285
IrTyKind,
284286
Is,
285287
Item,

library/core/src/mem/maybe_uninit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl<T> MaybeUninit<T> {
391391
/// For your convenience, this also returns a mutable reference to the
392392
/// (now safely initialized) contents of `self`.
393393
///
394-
/// As the content is stored inside a `MaybeUninit`, the destructor is not
394+
/// As the content is stored inside a `ManuallyDrop`, the destructor is not
395395
/// run for the inner data if the MaybeUninit leaves scope without a call to
396396
/// [`assume_init`], [`assume_init_drop`], or similar. Code that receives
397397
/// the mutable reference returned by this function needs to keep this in

library/core/src/net/ip_addr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub enum IpAddr {
6868
/// assert!("0000000.0.0.0".parse::<Ipv4Addr>().is_err()); // first octet is a zero in octal
6969
/// assert!("0xcb.0x0.0x71.0x00".parse::<Ipv4Addr>().is_err()); // all octets are in hex
7070
/// ```
71+
#[rustc_diagnostic_item = "Ipv4Addr"]
7172
#[derive(Copy, Clone, PartialEq, Eq)]
7273
#[stable(feature = "rust1", since = "1.0.0")]
7374
pub struct Ipv4Addr {
@@ -160,6 +161,7 @@ impl Hash for Ipv4Addr {
160161
/// assert_eq!("::1".parse(), Ok(localhost));
161162
/// assert_eq!(localhost.is_loopback(), true);
162163
/// ```
164+
#[rustc_diagnostic_item = "Ipv6Addr"]
163165
#[derive(Copy, Clone, PartialEq, Eq)]
164166
#[stable(feature = "rust1", since = "1.0.0")]
165167
pub struct Ipv6Addr {

src/bootstrap/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
579579

580580
[[package]]
581581
name = "rustix"
582-
version = "1.0.2"
582+
version = "1.0.7"
583583
source = "registry+https://github.com/rust-lang/crates.io-index"
584-
checksum = "f7178faa4b75a30e269c71e61c353ce2748cf3d76f0c44c393f4e60abf49b825"
584+
checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266"
585585
dependencies = [
586586
"bitflags",
587587
"errno",

src/doc/rustc-dev-guide/src/bug-fix-procedure.md

+3-33
Original file line numberDiff line numberDiff line change
@@ -80,41 +80,11 @@ approachable and practical; it may make sense to direct users to an RFC or some
8080
other issue for the full details. The issue also serves as a place where users
8181
can comment with questions or other concerns.
8282

83-
A template for these breaking-change tracking issues can be found below. An
84-
example of how such an issue should look can be [found
83+
A template for these breaking-change tracking issues can be found
84+
[here][template]. An example of how such an issue should look can be [found
8585
here][breaking-change-issue].
8686

87-
The issue should be tagged with (at least) `B-unstable` and `T-compiler`.
88-
89-
### Tracking issue template
90-
91-
This is a template to use for tracking issues:
92-
93-
```
94-
This is the **summary issue** for the `YOUR_LINT_NAME_HERE`
95-
future-compatibility warning and other related errors. The goal of
96-
this page is describe why this change was made and how you can fix
97-
code that is affected by it. It also provides a place to ask questions
98-
or register a complaint if you feel the change should not be made. For
99-
more information on the policy around future-compatibility warnings,
100-
see our [breaking change policy guidelines][guidelines].
101-
102-
[guidelines]: LINK_TO_THIS_RFC
103-
104-
#### What is the warning for?
105-
106-
*Describe the conditions that trigger the warning and how they can be
107-
fixed. Also explain why the change was made.**
108-
109-
#### When will this warning become a hard error?
110-
111-
At the beginning of each 6-week release cycle, the Rust compiler team
112-
will review the set of outstanding future compatibility warnings and
113-
nominate some of them for **Final Comment Period**. Toward the end of
114-
the cycle, we will review any comments and make a final determination
115-
whether to convert the warning into a hard error or remove it
116-
entirely.
117-
```
87+
[template]: https://github.com/rust-lang/rust/issues/new?template=tracking_issue_future.md
11888

11989
### Issuing future compatibility warnings
12090

src/tools/compiletest/src/runtest.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -2609,18 +2609,19 @@ impl<'test> TestCx<'test> {
26092609
(expected, actual)
26102610
};
26112611

2612-
// Write the actual output to a file in build/
2613-
let test_name = self.config.compare_mode.as_ref().map_or("", |m| m.to_str());
2612+
// Write the actual output to a file in build directory.
26142613
let actual_path = self
26152614
.output_base_name()
26162615
.with_extra_extension(self.revision.unwrap_or(""))
2617-
.with_extra_extension(test_name)
2616+
.with_extra_extension(
2617+
self.config.compare_mode.as_ref().map(|cm| cm.to_str()).unwrap_or(""),
2618+
)
26182619
.with_extra_extension(stream);
26192620

26202621
if let Err(err) = fs::write(&actual_path, &actual) {
2621-
self.fatal(&format!("failed to write {stream} to `{actual_path:?}`: {err}",));
2622+
self.fatal(&format!("failed to write {stream} to `{actual_path}`: {err}",));
26222623
}
2623-
println!("Saved the actual {stream} to {actual_path:?}");
2624+
println!("Saved the actual {stream} to `{actual_path}`");
26242625

26252626
if !self.config.bless {
26262627
if expected.is_empty() {
@@ -2646,13 +2647,16 @@ impl<'test> TestCx<'test> {
26462647

26472648
if !actual.is_empty() {
26482649
if let Err(err) = fs::write(&expected_path, &actual) {
2649-
self.fatal(&format!("failed to write {stream} to `{expected_path:?}`: {err}"));
2650+
self.fatal(&format!("failed to write {stream} to `{expected_path}`: {err}"));
26502651
}
2651-
println!("Blessing the {stream} of {test_name} in {expected_path:?}");
2652+
println!(
2653+
"Blessing the {stream} of `{test_name}` as `{expected_path}`",
2654+
test_name = self.testpaths.file
2655+
);
26522656
}
26532657
}
26542658

2655-
println!("\nThe actual {0} differed from the expected {0}.", stream);
2659+
println!("\nThe actual {stream} differed from the expected {stream}");
26562660

26572661
if self.config.bless { CompareOutcome::Blessed } else { CompareOutcome::Differed }
26582662
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct X {
2+
a: Box<u32>,
3+
}
4+
5+
struct Y {
6+
y: Box<u32>,
7+
}
8+
9+
fn main() {
10+
let a = 8;
11+
let v2 = X { a }; //~ ERROR mismatched types [E0308]
12+
let v3 = Y { y: a }; //~ ERROR mismatched types [E0308]
13+
let v4 = Y { a }; //~ ERROR struct `Y` has no field named `a` [E0560]
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/suggest-box-for-expr-field-issue-139631.rs:11:18
3+
|
4+
LL | let v2 = X { a };
5+
| ^ expected `Box<u32>`, found integer
6+
|
7+
= note: expected struct `Box<u32>`
8+
found type `{integer}`
9+
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
10+
help: store this in the heap by calling `Box::new`
11+
|
12+
LL | let v2 = X { a: Box::new(a) };
13+
| ++++++++++++ +
14+
15+
error[E0308]: mismatched types
16+
--> $DIR/suggest-box-for-expr-field-issue-139631.rs:12:21
17+
|
18+
LL | let v3 = Y { y: a };
19+
| ^ expected `Box<u32>`, found integer
20+
|
21+
= note: expected struct `Box<u32>`
22+
found type `{integer}`
23+
= note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
24+
help: store this in the heap by calling `Box::new`
25+
|
26+
LL | let v3 = Y { y: Box::new(a) };
27+
| +++++++++ +
28+
29+
error[E0560]: struct `Y` has no field named `a`
30+
--> $DIR/suggest-box-for-expr-field-issue-139631.rs:13:18
31+
|
32+
LL | let v4 = Y { a };
33+
| ^ unknown field
34+
|
35+
help: a field with a similar name exists
36+
|
37+
LL - let v4 = Y { a };
38+
LL + let v4 = Y { y };
39+
|
40+
41+
error: aborting due to 3 previous errors
42+
43+
Some errors have detailed explanations: E0308, E0560.
44+
For more information about an error, try `rustc --explain E0308`.
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/140785>.
2+
3+
fn main() {
4+
() += { let x; };
5+
//~^ ERROR binary assignment operation `+=` cannot be applied to type `()`
6+
//~| ERROR invalid left-hand side of assignment
7+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0368]: binary assignment operation `+=` cannot be applied to type `()`
2+
--> $DIR/gather-locals-twice.rs:4:5
3+
|
4+
LL | () += { let x; };
5+
| --^^^^^^^^^^^^^^
6+
| |
7+
| cannot use `+=` on type `()`
8+
9+
error[E0067]: invalid left-hand side of assignment
10+
--> $DIR/gather-locals-twice.rs:4:8
11+
|
12+
LL | () += { let x; };
13+
| -- ^^
14+
| |
15+
| cannot assign to this expression
16+
17+
error: aborting due to 2 previous errors
18+
19+
Some errors have detailed explanations: E0067, E0368.
20+
For more information about an error, try `rustc --explain E0067`.

0 commit comments

Comments
 (0)