Skip to content

Commit 7e966bc

Browse files
committed
Auto merge of #108640 - matthiaskrgr:rollup-rii4t5t, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #108516 (Restrict `#[rustc_box]` to `Box::new` calls) - #108575 (Erase **all** regions when probing for associated types on ambiguity in astconv) - #108585 (Run compiler test suite in parallel on Fuchsia) - #108606 (Add test case for mismatched open/close delims) - #108609 (Highlight whole expression for E0599) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 18caf88 + 832987b commit 7e966bc

File tree

22 files changed

+252
-64
lines changed

22 files changed

+252
-64
lines changed

compiler/rustc_ast_lowering/locales/en-US.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ ast_lowering_misplaced_impl_trait =
2222
ast_lowering_misplaced_assoc_ty_binding =
2323
associated type bounds are only allowed in where clauses and function signatures, not in {$position}
2424
25-
ast_lowering_rustc_box_attribute_error =
26-
#[rustc_box] requires precisely one argument and no other attributes are allowed
27-
2825
ast_lowering_underscore_expr_lhs_assign =
2926
in expressions, `_` can only be used on the left-hand side of an assignment
3027
.label = `_` not allowed here

compiler/rustc_ast_lowering/src/errors.rs

-7
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,6 @@ pub struct MisplacedAssocTyBinding<'a> {
8787
pub position: DiagnosticArgFromDisplay<'a>,
8888
}
8989

90-
#[derive(Diagnostic, Clone, Copy)]
91-
#[diag(ast_lowering_rustc_box_attribute_error)]
92-
pub struct RustcBoxAttributeError {
93-
#[primary_span]
94-
pub span: Span,
95-
}
96-
9790
#[derive(Diagnostic, Clone, Copy)]
9891
#[diag(ast_lowering_underscore_expr_lhs_assign)]
9992
pub struct UnderscoreExprLhsAssign {

compiler/rustc_ast_lowering/src/expr.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::errors::{
22
AsyncGeneratorsNotSupported, AsyncNonMoveClosureNotSupported, AwaitOnlyInAsyncFnAndBlocks,
33
BaseExpressionDoubleDot, ClosureCannotBeStatic, FunctionalRecordUpdateDestructuringAssignemnt,
44
GeneratorTooManyParameters, InclusiveRangeWithNoEnd, NotSupportedForLifetimeBinderAsyncClosure,
5-
RustcBoxAttributeError, UnderscoreExprLhsAssign,
5+
UnderscoreExprLhsAssign,
66
};
77
use super::ResolverAstLoweringExt;
88
use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
@@ -83,15 +83,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
8383
}
8484
ExprKind::Tup(elts) => hir::ExprKind::Tup(self.lower_exprs(elts)),
8585
ExprKind::Call(f, args) => {
86-
if e.attrs.get(0).map_or(false, |a| a.has_name(sym::rustc_box)) {
87-
if let [inner] = &args[..] && e.attrs.len() == 1 {
88-
let kind = hir::ExprKind::Box(self.lower_expr(&inner));
89-
return hir::Expr { hir_id, kind, span: self.lower_span(e.span) };
90-
} else {
91-
let guar = self.tcx.sess.emit_err(RustcBoxAttributeError { span: e.span });
92-
hir::ExprKind::Err(guar)
93-
}
94-
} else if let Some(legacy_args) = self.resolver.legacy_const_generic_args(f) {
86+
if let Some(legacy_args) = self.resolver.legacy_const_generic_args(f) {
9587
self.lower_legacy_const_generics((**f).clone(), args.clone(), &legacy_args)
9688
} else {
9789
let f = self.lower_expr(f);

compiler/rustc_hir_analysis/src/astconv/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2399,8 +2399,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
23992399
infcx
24002400
.can_eq(
24012401
ty::ParamEnv::empty(),
2402-
tcx.erase_regions(impl_.self_ty()),
2403-
tcx.erase_regions(qself_ty),
2402+
impl_.self_ty(),
2403+
// Must fold past escaping bound vars too,
2404+
// since we have those at this point in astconv.
2405+
tcx.fold_regions(qself_ty, |_, _| tcx.lifetimes.re_erased),
24042406
)
24052407
})
24062408
&& tcx.impl_polarity(impl_def_id) != ty::ImplPolarity::Negative

compiler/rustc_hir_typeck/src/method/suggest.rs

+3
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
333333
rcvr_ty.prefix_string(self.tcx),
334334
ty_str_reported,
335335
);
336+
if tcx.sess.source_map().is_multiline(sugg_span) {
337+
err.span_label(sugg_span.with_hi(span.lo()), "");
338+
}
336339
let ty_str = if short_ty_str.len() < ty_str.len() && ty_str.len() > 10 {
337340
short_ty_str
338341
} else {

compiler/rustc_mir_build/locales/en-US.ftl

+6
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,9 @@ mir_build_suggest_let_else = you might want to use `let else` to handle the {$co
374374
} matched
375375
376376
mir_build_suggest_attempted_int_lit = alternatively, you could prepend the pattern with an underscore to define a new named variable; identifiers cannot begin with digits
377+
378+
379+
mir_build_rustc_box_attribute_error = `#[rustc_box]` attribute used incorrectly
380+
.attributes = no other attributes may be applied
381+
.not_box = `#[rustc_box]` may only be applied to a `Box::new()` call
382+
.missing_box = `#[rustc_box]` requires the `owned_box` lang item

compiler/rustc_mir_build/src/errors.rs

+19
Original file line numberDiff line numberDiff line change
@@ -888,3 +888,22 @@ pub enum MiscPatternSuggestion {
888888
start_span: Span,
889889
},
890890
}
891+
892+
#[derive(Diagnostic)]
893+
#[diag(mir_build_rustc_box_attribute_error)]
894+
pub struct RustcBoxAttributeError {
895+
#[primary_span]
896+
pub span: Span,
897+
#[subdiagnostic]
898+
pub reason: RustcBoxAttrReason,
899+
}
900+
901+
#[derive(Subdiagnostic)]
902+
pub enum RustcBoxAttrReason {
903+
#[note(mir_build_attributes)]
904+
Attributes,
905+
#[note(mir_build_not_box)]
906+
NotBoxNew,
907+
#[note(mir_build_missing_box)]
908+
MissingBox,
909+
}

compiler/rustc_mir_build/src/thir/cx/expr.rs

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::errors;
12
use crate::thir::cx::region::Scope;
23
use crate::thir::cx::Cx;
34
use crate::thir::util::UserAnnotatedTyHelpers;
@@ -18,7 +19,7 @@ use rustc_middle::ty::subst::InternalSubsts;
1819
use rustc_middle::ty::{
1920
self, AdtKind, InlineConstSubsts, InlineConstSubstsParts, ScalarInt, Ty, UpvarSubsts, UserType,
2021
};
21-
use rustc_span::Span;
22+
use rustc_span::{sym, Span};
2223
use rustc_target::abi::VariantIdx;
2324

2425
impl<'tcx> Cx<'tcx> {
@@ -262,6 +263,7 @@ impl<'tcx> Cx<'tcx> {
262263
}
263264
}
264265

266+
#[instrument(level = "debug", skip(self), ret)]
265267
fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx> {
266268
let tcx = self.tcx;
267269
let expr_ty = self.typeck_results().expr_ty(expr);
@@ -322,6 +324,34 @@ impl<'tcx> Cx<'tcx> {
322324
fn_span: expr.span,
323325
}
324326
} else {
327+
let attrs = tcx.hir().attrs(expr.hir_id);
328+
if attrs.iter().any(|a| a.name_or_empty() == sym::rustc_box) {
329+
if attrs.len() != 1 {
330+
tcx.sess.emit_err(errors::RustcBoxAttributeError {
331+
span: attrs[0].span,
332+
reason: errors::RustcBoxAttrReason::Attributes,
333+
});
334+
} else if let Some(box_item) = tcx.lang_items().owned_box() {
335+
if let hir::ExprKind::Path(hir::QPath::TypeRelative(ty, fn_path)) = fun.kind
336+
&& let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = ty.kind
337+
&& path.res.opt_def_id().map_or(false, |did| did == box_item)
338+
&& fn_path.ident.name == sym::new
339+
&& let [value] = args
340+
{
341+
return Expr { temp_lifetime, ty: expr_ty, span: expr.span, kind: ExprKind::Box { value: self.mirror_expr(value) } }
342+
} else {
343+
tcx.sess.emit_err(errors::RustcBoxAttributeError {
344+
span: expr.span,
345+
reason: errors::RustcBoxAttrReason::NotBoxNew
346+
});
347+
}
348+
} else {
349+
tcx.sess.emit_err(errors::RustcBoxAttributeError {
350+
span: attrs[0].span,
351+
reason: errors::RustcBoxAttrReason::MissingBox,
352+
});
353+
}
354+
}
325355
let adt_data =
326356
if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = fun.kind {
327357
// Tuple-like ADTs are represented as ExprKind::Call. We convert them here.

src/ci/docker/scripts/fuchsia-test-runner.py

+26-13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import argparse
1111
from dataclasses import dataclass
12+
import fcntl
1213
import glob
1314
import hashlib
1415
import json
@@ -146,6 +147,9 @@ def host_arch_triple(self):
146147
def zxdb_script_path(self):
147148
return os.path.join(self.tmp_dir(), "zxdb_script")
148149

150+
def pm_lockfile_path(self):
151+
return os.path.join(self.tmp_dir(), "pm.lock")
152+
149153
def log_info(self, msg):
150154
print(msg)
151155

@@ -460,6 +464,9 @@ def start(self):
460464
stderr=self.subprocess_output(),
461465
)
462466

467+
# Create lockfiles
468+
open(self.pm_lockfile_path(), 'a').close()
469+
463470
# Write to file
464471
self.write_to_file()
465472

@@ -676,19 +683,25 @@ def log(msg):
676683
log("Publishing package to repo...")
677684

678685
# Publish package to repo
679-
subprocess.check_call(
680-
[
681-
self.tool_path("pm"),
682-
"publish",
683-
"-a",
684-
"-repo",
685-
self.repo_dir(),
686-
"-f",
687-
far_path,
688-
],
689-
stdout=log_file,
690-
stderr=log_file,
691-
)
686+
with open(self.pm_lockfile_path(), 'w') as pm_lockfile:
687+
fcntl.lockf(pm_lockfile.fileno(), fcntl.LOCK_EX)
688+
subprocess.check_call(
689+
[
690+
self.tool_path("pm"),
691+
"publish",
692+
"-a",
693+
"-repo",
694+
self.repo_dir(),
695+
"-f",
696+
far_path,
697+
],
698+
stdout=log_file,
699+
stderr=log_file,
700+
)
701+
# This lock should be released automatically when the pm
702+
# lockfile is closed, but we'll be polite and unlock it now
703+
# since the spec leaves some wiggle room.
704+
fcntl.lockf(pm_lockfile.fileno(), fcntl.LOCK_UN)
692705

693706
log("Running ffx test...")
694707

src/doc/rustc/src/platform-support/fuchsia.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ run the full `tests/ui` test suite:
716716
--stage=2 \
717717
test tests/ui \
718718
--target x86_64-unknown-fuchsia \
719-
--run=always --jobs 1 \
719+
--run=always \
720720
--test-args --target-rustcflags \
721721
--test-args -Lnative=${SDK_PATH}/arch/{x64|arm64}/sysroot/lib \
722722
--test-args --target-rustcflags \
@@ -728,9 +728,6 @@ run the full `tests/ui` test suite:
728728
)
729729
```
730730

731-
*Note: The test suite cannot be run in parallel at the moment, so `x.py`
732-
must be run with `--jobs 1` to ensure only one test runs at a time.*
733-
734731
By default, `x.py` compiles test binaries with `panic=unwind`. If you built your
735732
Rust toolchain with `-Cpanic=abort`, you need to tell `x.py` to compile test
736733
binaries with `panic=abort` as well:
@@ -907,7 +904,7 @@ through our `x.py` invocation. The full invocation is:
907904
--stage=2 \
908905
test tests/${TEST} \
909906
--target x86_64-unknown-fuchsia \
910-
--run=always --jobs 1 \
907+
--run=always \
911908
--test-args --target-rustcflags \
912909
--test-args -Lnative=${SDK_PATH}/arch/{x64|arm64}/sysroot/lib \
913910
--test-args --target-rustcflags \

src/tools/clippy/clippy_utils/src/higher.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,12 @@ impl<'a> VecArgs<'a> {
287287
Some(VecArgs::Repeat(&args[0], &args[1]))
288288
} else if match_def_path(cx, fun_def_id, &paths::SLICE_INTO_VEC) && args.len() == 1 {
289289
// `vec![a, b, c]` case
290-
if_chain! {
291-
if let hir::ExprKind::Box(boxed) = args[0].kind;
292-
if let hir::ExprKind::Array(args) = boxed.kind;
293-
then {
294-
return Some(VecArgs::Vec(args));
295-
}
290+
if let hir::ExprKind::Call(_, [arg]) = &args[0].kind
291+
&& let hir::ExprKind::Array(args) = arg.kind {
292+
Some(VecArgs::Vec(args))
293+
} else {
294+
None
296295
}
297-
298-
None
299296
} else if match_def_path(cx, fun_def_id, &paths::VEC_NEW) && args.is_empty() {
300297
Some(VecArgs::Vec(&[]))
301298
} else {

src/tools/compiletest/src/runtest.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1432,12 +1432,13 @@ impl<'test> TestCx<'test> {
14321432
expect_help: bool,
14331433
expect_note: bool,
14341434
) -> bool {
1435-
match actual_error.kind {
1436-
Some(ErrorKind::Help) => expect_help,
1437-
Some(ErrorKind::Note) => expect_note,
1438-
Some(ErrorKind::Error) | Some(ErrorKind::Warning) => true,
1439-
Some(ErrorKind::Suggestion) | None => false,
1440-
}
1435+
!actual_error.msg.is_empty()
1436+
&& match actual_error.kind {
1437+
Some(ErrorKind::Help) => expect_help,
1438+
Some(ErrorKind::Note) => expect_note,
1439+
Some(ErrorKind::Error) | Some(ErrorKind::Warning) => true,
1440+
Some(ErrorKind::Suggestion) | None => false,
1441+
}
14411442
}
14421443

14431444
fn should_emit_metadata(&self, pm: Option<PassMode>) -> Emit {

tests/ui/attributes/rustc-box.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(rustc_attrs, stmt_expr_attributes)]
2+
3+
fn foo(_: u32, _: u32) {}
4+
fn bar(_: u32) {}
5+
6+
fn main() {
7+
#[rustc_box]
8+
Box::new(1); // OK
9+
#[rustc_box]
10+
Box::pin(1); //~ ERROR `#[rustc_box]` attribute used incorrectly
11+
#[rustc_box]
12+
foo(1, 1); //~ ERROR `#[rustc_box]` attribute used incorrectly
13+
#[rustc_box]
14+
bar(1); //~ ERROR `#[rustc_box]` attribute used incorrectly
15+
#[rustc_box] //~ ERROR `#[rustc_box]` attribute used incorrectly
16+
#[rustfmt::skip]
17+
Box::new(1);
18+
}

tests/ui/attributes/rustc-box.stderr

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
error: `#[rustc_box]` attribute used incorrectly
2+
--> $DIR/rustc-box.rs:10:5
3+
|
4+
LL | Box::pin(1);
5+
| ^^^^^^^^^^^
6+
|
7+
= note: `#[rustc_box]` may only be applied to a `Box::new()` call
8+
9+
error: `#[rustc_box]` attribute used incorrectly
10+
--> $DIR/rustc-box.rs:12:5
11+
|
12+
LL | foo(1, 1);
13+
| ^^^^^^^^^
14+
|
15+
= note: `#[rustc_box]` may only be applied to a `Box::new()` call
16+
17+
error: `#[rustc_box]` attribute used incorrectly
18+
--> $DIR/rustc-box.rs:14:5
19+
|
20+
LL | bar(1);
21+
| ^^^^^^
22+
|
23+
= note: `#[rustc_box]` may only be applied to a `Box::new()` call
24+
25+
error: `#[rustc_box]` attribute used incorrectly
26+
--> $DIR/rustc-box.rs:15:5
27+
|
28+
LL | #[rustc_box]
29+
| ^^^^^^^^^^^^
30+
|
31+
= note: no other attributes may be applied
32+
33+
error: aborting due to 4 previous errors
34+

tests/ui/methods/method-call-err-msg.stderr

+10-7
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,17 @@ LL | .two(0, /* isize */);
4848
error[E0599]: `Foo` is not an iterator
4949
--> $DIR/method-call-err-msg.rs:19:7
5050
|
51-
LL | pub struct Foo;
52-
| --------------
53-
| |
54-
| method `take` not found for this struct
55-
| doesn't satisfy `Foo: Iterator`
51+
LL | pub struct Foo;
52+
| --------------
53+
| |
54+
| method `take` not found for this struct
55+
| doesn't satisfy `Foo: Iterator`
5656
...
57-
LL | .take()
58-
| ^^^^ `Foo` is not an iterator
57+
LL | / y.zero()
58+
LL | | .take()
59+
| | -^^^^ `Foo` is not an iterator
60+
| |______|
61+
|
5962
|
6063
= note: the following trait bounds were not satisfied:
6164
`Foo: Iterator`
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[derive(A)]
2+
struct S {
3+
d: [u32; {
4+
#![cfg] {
5+
#![w,) //~ ERROR mismatched closing delimiter
6+
//~ ERROR this file contains an unclosed delimiter

0 commit comments

Comments
 (0)