Skip to content

Commit d3a4b1f

Browse files
committed
Auto merge of #133086 - GuillaumeGomez:rollup-kbkfrkj, r=GuillaumeGomez
Rollup of 5 pull requests Successful merges: - #132936 (For expr `return (_ = 42);` unused_paren lint should not be triggered) - #132956 (Add visit_coroutine_kind to ast::Visitor) - #132978 (Mention both release *and* edition breakage for never type lints) - #133074 (make UI test OS-agnostic) - #133080 (Fix span edition for 2024 RPIT coming from an external macro ) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 917a50a + fc8d2b3 commit d3a4b1f

File tree

46 files changed

+411
-188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+411
-188
lines changed

compiler/rustc_ast/src/visit.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ pub trait Visitor<'ast>: Sized {
268268
fn visit_fn_ret_ty(&mut self, ret_ty: &'ast FnRetTy) -> Self::Result {
269269
walk_fn_ret_ty(self, ret_ty)
270270
}
271-
fn visit_fn_header(&mut self, _header: &'ast FnHeader) -> Self::Result {
272-
Self::Result::output()
271+
fn visit_fn_header(&mut self, header: &'ast FnHeader) -> Self::Result {
272+
walk_fn_header(self, header)
273273
}
274274
fn visit_expr_field(&mut self, f: &'ast ExprField) -> Self::Result {
275275
walk_expr_field(self, f)
@@ -292,6 +292,9 @@ pub trait Visitor<'ast>: Sized {
292292
fn visit_capture_by(&mut self, _capture_by: &'ast CaptureBy) -> Self::Result {
293293
Self::Result::output()
294294
}
295+
fn visit_coroutine_kind(&mut self, _coroutine_kind: &'ast CoroutineKind) -> Self::Result {
296+
Self::Result::output()
297+
}
295298
}
296299

297300
pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) -> V::Result {
@@ -813,6 +816,12 @@ pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FnRetTy)
813816
V::Result::output()
814817
}
815818

819+
pub fn walk_fn_header<'a, V: Visitor<'a>>(visitor: &mut V, fn_header: &'a FnHeader) -> V::Result {
820+
let FnHeader { safety: _, coroutine_kind, constness: _, ext: _ } = fn_header;
821+
visit_opt!(visitor, visit_coroutine_kind, coroutine_kind.as_ref());
822+
V::Result::output()
823+
}
824+
816825
pub fn walk_fn_decl<'a, V: Visitor<'a>>(
817826
visitor: &mut V,
818827
FnDecl { inputs, output }: &'a FnDecl,
@@ -830,8 +839,9 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Resu
830839
try_visit!(walk_fn_decl(visitor, decl));
831840
visit_opt!(visitor, visit_block, body);
832841
}
833-
FnKind::Closure(binder, _coroutine_kind, decl, body) => {
842+
FnKind::Closure(binder, coroutine_kind, decl, body) => {
834843
try_visit!(visitor.visit_closure_binder(binder));
844+
visit_opt!(visitor, visit_coroutine_kind, coroutine_kind.as_ref());
835845
try_visit!(walk_fn_decl(visitor, decl));
836846
try_visit!(visitor.visit_expr(body));
837847
}

compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
738738
allow_internal_unstable: Option<Lrc<[Symbol]>>,
739739
) -> Span {
740740
self.tcx.with_stable_hashing_context(|hcx| {
741-
span.mark_with_reason(allow_internal_unstable, reason, self.tcx.sess.edition(), hcx)
741+
span.mark_with_reason(allow_internal_unstable, reason, span.edition(), hcx)
742742
})
743743
}
744744

compiler/rustc_lint/src/early.rs

+4-19
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
6868
}
6969

7070
impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T> {
71+
fn visit_coroutine_kind(&mut self, coroutine_kind: &'a ast::CoroutineKind) -> Self::Result {
72+
self.check_id(coroutine_kind.closure_id());
73+
}
74+
7175
fn visit_param(&mut self, param: &'a ast::Param) {
7276
self.with_lint_attrs(param.id, &param.attrs, |cx| {
7377
lint_callback!(cx, check_param, param);
@@ -111,17 +115,6 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
111115
self.with_lint_attrs(e.id, &e.attrs, |cx| {
112116
lint_callback!(cx, check_expr, e);
113117
ast_visit::walk_expr(cx, e);
114-
// Explicitly check for lints associated with 'closure_id', since
115-
// it does not have a corresponding AST node
116-
match e.kind {
117-
ast::ExprKind::Closure(box ast::Closure {
118-
coroutine_kind: Some(coroutine_kind),
119-
..
120-
}) => {
121-
cx.check_id(coroutine_kind.closure_id());
122-
}
123-
_ => {}
124-
}
125118
lint_callback!(cx, check_expr_post, e);
126119
})
127120
}
@@ -156,14 +149,6 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
156149
lint_callback!(self, check_fn, fk, span, id);
157150
self.check_id(id);
158151
ast_visit::walk_fn(self, fk);
159-
160-
// Explicitly check for lints associated with 'closure_id', since
161-
// it does not have a corresponding AST node
162-
if let ast_visit::FnKind::Fn(_, _, sig, _, _, _) = fk {
163-
if let Some(coroutine_kind) = sig.header.coroutine_kind {
164-
self.check_id(coroutine_kind.closure_id());
165-
}
166-
}
167152
}
168153

169154
fn visit_variant_data(&mut self, s: &'a ast::VariantData) {

compiler/rustc_lint/src/unused.rs

+9
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ enum UnusedDelimsCtx {
584584
MatchScrutineeExpr,
585585
ReturnValue,
586586
BlockRetValue,
587+
BreakValue,
587588
LetScrutineeExpr,
588589
ArrayLenExpr,
589590
AnonConst,
@@ -605,6 +606,7 @@ impl From<UnusedDelimsCtx> for &'static str {
605606
UnusedDelimsCtx::MatchScrutineeExpr => "`match` scrutinee expression",
606607
UnusedDelimsCtx::ReturnValue => "`return` value",
607608
UnusedDelimsCtx::BlockRetValue => "block return value",
609+
UnusedDelimsCtx::BreakValue => "`break` value",
608610
UnusedDelimsCtx::LetScrutineeExpr => "`let` scrutinee expression",
609611
UnusedDelimsCtx::ArrayLenExpr | UnusedDelimsCtx::AnonConst => "const expression",
610612
UnusedDelimsCtx::MatchArmExpr => "match arm expression",
@@ -913,6 +915,10 @@ trait UnusedDelimLint {
913915
(value, UnusedDelimsCtx::ReturnValue, false, Some(left), None, true)
914916
}
915917

918+
Break(_, Some(ref value)) => {
919+
(value, UnusedDelimsCtx::BreakValue, false, None, None, true)
920+
}
921+
916922
Index(_, ref value, _) => (value, UnusedDelimsCtx::IndexExpr, false, None, None, false),
917923

918924
Assign(_, ref value, _) | AssignOp(.., ref value) => {
@@ -1063,6 +1069,9 @@ impl UnusedDelimLint for UnusedParens {
10631069
_,
10641070
_,
10651071
) if node.is_lazy()))
1072+
&& !((ctx == UnusedDelimsCtx::ReturnValue
1073+
|| ctx == UnusedDelimsCtx::BreakValue)
1074+
&& matches!(inner.kind, ast::ExprKind::Assign(_, _, _)))
10661075
{
10671076
self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos, is_kw)
10681077
}

compiler/rustc_lint_defs/src/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4185,7 +4185,7 @@ declare_lint! {
41854185
Warn,
41864186
"never type fallback affecting unsafe function calls",
41874187
@future_incompatible = FutureIncompatibleInfo {
4188-
reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange,
4188+
reason: FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(Edition::Edition2024),
41894189
reference: "issue #123748 <https://github.com/rust-lang/rust/issues/123748>",
41904190
};
41914191
@edition Edition2024 => Deny;
@@ -4239,7 +4239,7 @@ declare_lint! {
42394239
Warn,
42404240
"never type fallback affecting unsafe function calls",
42414241
@future_incompatible = FutureIncompatibleInfo {
4242-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
4242+
reason: FutureIncompatibilityReason::EditionAndFutureReleaseError(Edition::Edition2024),
42434243
reference: "issue #123748 <https://github.com/rust-lang/rust/issues/123748>",
42444244
};
42454245
report_in_external_macro

compiler/rustc_lint_defs/src/lib.rs

+33-3
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ pub enum FutureIncompatibilityReason {
381381
/// hard errors (and the lint removed). Preferably when there is some
382382
/// confidence that the number of impacted projects is very small (few
383383
/// should have a broken dependency in their dependency tree).
384+
///
385+
/// [`EditionAndFutureReleaseError`]: FutureIncompatibilityReason::EditionAndFutureReleaseError
384386
FutureReleaseErrorReportInDeps,
385387
/// Code that changes meaning in some way in a
386388
/// future release.
@@ -419,6 +421,28 @@ pub enum FutureIncompatibilityReason {
419421
/// slightly changes the text of the diagnostic, but is otherwise the
420422
/// same.
421423
EditionSemanticsChange(Edition),
424+
/// This will be an error in the provided edition *and* in a future
425+
/// release.
426+
///
427+
/// This variant a combination of [`FutureReleaseErrorDontReportInDeps`]
428+
/// and [`EditionError`]. This is useful in rare cases when we
429+
/// want to have "preview" of a breaking change in an edition, but do a
430+
/// breaking change later on all editions anyway.
431+
///
432+
/// [`EditionError`]: FutureIncompatibilityReason::EditionError
433+
/// [`FutureReleaseErrorDontReportInDeps`]: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps
434+
EditionAndFutureReleaseError(Edition),
435+
/// This will change meaning in the provided edition *and* in a future
436+
/// release.
437+
///
438+
/// This variant a combination of [`FutureReleaseSemanticsChange`]
439+
/// and [`EditionSemanticsChange`]. This is useful in rare cases when we
440+
/// want to have "preview" of a breaking change in an edition, but do a
441+
/// breaking change later on all editions anyway.
442+
///
443+
/// [`EditionSemanticsChange`]: FutureIncompatibilityReason::EditionSemanticsChange
444+
/// [`FutureReleaseSemanticsChange`]: FutureIncompatibilityReason::FutureReleaseSemanticsChange
445+
EditionAndFutureReleaseSemanticsChange(Edition),
422446
/// A custom reason.
423447
///
424448
/// Choose this variant if the built-in text of the diagnostic of the
@@ -431,9 +455,15 @@ pub enum FutureIncompatibilityReason {
431455
impl FutureIncompatibilityReason {
432456
pub fn edition(self) -> Option<Edition> {
433457
match self {
434-
Self::EditionError(e) => Some(e),
435-
Self::EditionSemanticsChange(e) => Some(e),
436-
_ => None,
458+
Self::EditionError(e)
459+
| Self::EditionSemanticsChange(e)
460+
| Self::EditionAndFutureReleaseError(e)
461+
| Self::EditionAndFutureReleaseSemanticsChange(e) => Some(e),
462+
463+
FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps
464+
| FutureIncompatibilityReason::FutureReleaseErrorReportInDeps
465+
| FutureIncompatibilityReason::FutureReleaseSemanticsChange
466+
| FutureIncompatibilityReason::Custom(_) => None,
437467
}
438468
}
439469
}

compiler/rustc_middle/src/lint.rs

+11
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,17 @@ pub fn lint_level(
382382
FutureIncompatibilityReason::EditionSemanticsChange(edition) => {
383383
format!("this changes meaning in Rust {edition}")
384384
}
385+
FutureIncompatibilityReason::EditionAndFutureReleaseError(edition) => {
386+
format!(
387+
"this was previously accepted by the compiler but is being phased out; \
388+
it will become a hard error in Rust {edition} and in a future release in all editions!"
389+
)
390+
}
391+
FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(edition) => {
392+
format!(
393+
"this changes meaning in Rust {edition} and in a future release in all editions!"
394+
)
395+
}
385396
FutureIncompatibilityReason::Custom(reason) => reason.to_owned(),
386397
};
387398

tests/ui/delegation/unsupported.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@ mod opaque {
1010
mod to_reuse {
1111
use super::Trait;
1212

13-
pub fn opaque_ret() -> impl Trait { unimplemented!() }
14-
//~^ warn: this function depends on never type fallback being `()`
15-
//~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
13+
pub fn opaque_ret() -> impl Trait { () }
1614
}
1715

1816
trait ToReuse {
19-
fn opaque_ret() -> impl Trait { unimplemented!() }
20-
//~^ warn: this function depends on never type fallback being `()`
21-
//~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
17+
fn opaque_ret() -> impl Trait { () }
2218
}
2319

2420
// FIXME: Inherited `impl Trait`s create query cycles when used inside trait impls.
+15-46
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,43 @@
1-
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/unsupported.rs:25:5: 25:24>::{synthetic#0}`
2-
--> $DIR/unsupported.rs:26:25
1+
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/unsupported.rs:21:5: 21:24>::{synthetic#0}`
2+
--> $DIR/unsupported.rs:22:25
33
|
44
LL | reuse to_reuse::opaque_ret;
55
| ^^^^^^^^^^
66
|
77
note: ...which requires comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process...
8-
--> $DIR/unsupported.rs:26:25
8+
--> $DIR/unsupported.rs:22:25
99
|
1010
LL | reuse to_reuse::opaque_ret;
1111
| ^^^^^^^^^^
12-
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:25:5: 25:24>::{synthetic#0}`, completing the cycle
13-
note: cycle used when checking that `opaque::<impl at $DIR/unsupported.rs:25:5: 25:24>` is well-formed
14-
--> $DIR/unsupported.rs:25:5
12+
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:21:5: 21:24>::{synthetic#0}`, completing the cycle
13+
note: cycle used when checking that `opaque::<impl at $DIR/unsupported.rs:21:5: 21:24>` is well-formed
14+
--> $DIR/unsupported.rs:21:5
1515
|
1616
LL | impl ToReuse for u8 {
1717
| ^^^^^^^^^^^^^^^^^^^
1818
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
1919

20-
warning: this function depends on never type fallback being `()`
21-
--> $DIR/unsupported.rs:13:9
22-
|
23-
LL | pub fn opaque_ret() -> impl Trait { unimplemented!() }
24-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25-
|
26-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
27-
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
28-
= help: specify the types explicitly
29-
note: in edition 2024, the requirement `!: opaque::Trait` will fail
30-
--> $DIR/unsupported.rs:13:32
31-
|
32-
LL | pub fn opaque_ret() -> impl Trait { unimplemented!() }
33-
| ^^^^^^^^^^
34-
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
35-
36-
warning: this function depends on never type fallback being `()`
37-
--> $DIR/unsupported.rs:19:9
38-
|
39-
LL | fn opaque_ret() -> impl Trait { unimplemented!() }
40-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41-
|
42-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
43-
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
44-
= help: specify the types explicitly
45-
note: in edition 2024, the requirement `!: opaque::Trait` will fail
46-
--> $DIR/unsupported.rs:19:28
47-
|
48-
LL | fn opaque_ret() -> impl Trait { unimplemented!() }
49-
| ^^^^^^^^^^
50-
51-
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/unsupported.rs:28:5: 28:25>::{synthetic#0}`
52-
--> $DIR/unsupported.rs:29:24
20+
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/unsupported.rs:24:5: 24:25>::{synthetic#0}`
21+
--> $DIR/unsupported.rs:25:24
5322
|
5423
LL | reuse ToReuse::opaque_ret;
5524
| ^^^^^^^^^^
5625
|
5726
note: ...which requires comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process...
58-
--> $DIR/unsupported.rs:29:24
27+
--> $DIR/unsupported.rs:25:24
5928
|
6029
LL | reuse ToReuse::opaque_ret;
6130
| ^^^^^^^^^^
62-
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:28:5: 28:25>::{synthetic#0}`, completing the cycle
63-
note: cycle used when checking that `opaque::<impl at $DIR/unsupported.rs:28:5: 28:25>` is well-formed
64-
--> $DIR/unsupported.rs:28:5
31+
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:24:5: 24:25>::{synthetic#0}`, completing the cycle
32+
note: cycle used when checking that `opaque::<impl at $DIR/unsupported.rs:24:5: 24:25>` is well-formed
33+
--> $DIR/unsupported.rs:24:5
6534
|
6635
LL | impl ToReuse for u16 {
6736
| ^^^^^^^^^^^^^^^^^^^^
6837
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
6938

7039
error: recursive delegation is not supported yet
71-
--> $DIR/unsupported.rs:42:22
40+
--> $DIR/unsupported.rs:38:22
7241
|
7342
LL | pub reuse to_reuse2::foo;
7443
| --- callee defined here
@@ -77,14 +46,14 @@ LL | reuse to_reuse1::foo;
7746
| ^^^
7847

7948
error[E0283]: type annotations needed
80-
--> $DIR/unsupported.rs:52:18
49+
--> $DIR/unsupported.rs:48:18
8150
|
8251
LL | reuse Trait::foo;
8352
| ^^^ cannot infer type
8453
|
8554
= note: cannot satisfy `_: effects::Trait`
8655

87-
error: aborting due to 4 previous errors; 2 warnings emitted
56+
error: aborting due to 4 previous errors
8857

8958
Some errors have detailed explanations: E0283, E0391.
9059
For more information about an error, try `rustc --explain E0283`.

tests/ui/editions/never-type-fallback-breaking.e2021.fixed

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616

1717
fn m() {
1818
//[e2021]~^ this function depends on never type fallback being `()`
19-
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
19+
//[e2021]~| 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!
2020
let x: () = match true {
2121
true => Default::default(),
2222
//[e2024]~^ error: the trait bound `!: Default` is not satisfied
@@ -28,7 +28,7 @@ fn m() {
2828

2929
fn q() -> Option<()> {
3030
//[e2021]~^ this function depends on never type fallback being `()`
31-
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
31+
//[e2021]~| 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!
3232
fn deserialize<T: Default>() -> Option<T> {
3333
Some(T::default())
3434
}
@@ -45,7 +45,7 @@ fn help<'a: 'a, T: Into<()>, U>(_: U) -> Result<T, ()> {
4545
}
4646
fn meow() -> Result<(), ()> {
4747
//[e2021]~^ this function depends on never type fallback being `()`
48-
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
48+
//[e2021]~| 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!
4949
help::<(), _>(1)?;
5050
//[e2024]~^ error: the trait bound `(): From<!>` is not satisfied
5151
Ok(())

0 commit comments

Comments
 (0)