Skip to content

Commit 9d9c2c9

Browse files
committed
Auto merge of #84342 - Dylan-DPC:rollup-5b40142, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - #84123 (Introduce CompileMonoItem DepNode) - #84126 (Enable sanitizers for x86_64-unknown-linux-musl) - #84168 (Lower async fn in traits.) - #84256 (doc: use U+2212 for minus sign in floating-point -0.0 remarks) - #84291 (fix aliasing violations in thread_local_const_init) - #84313 (fix suggestion for unsized function parameters) - #84330 (Remove unused footer section) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1a6c98e + a23fd16 commit 9d9c2c9

37 files changed

+146
-57
lines changed

compiler/rustc_ast_lowering/src/item.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
836836
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Required(names)))
837837
}
838838
AssocItemKind::Fn(box FnKind(_, ref sig, ref generics, Some(ref body))) => {
839-
let body_id = self.lower_fn_body_block(i.span, &sig.decl, Some(body));
840-
let (generics, sig) =
841-
self.lower_method_sig(generics, sig, trait_item_def_id, false, None, i.id);
839+
let asyncness = sig.header.asyncness;
840+
let body_id =
841+
self.lower_maybe_async_body(i.span, &sig.decl, asyncness, Some(&body));
842+
let (generics, sig) = self.lower_method_sig(
843+
generics,
844+
sig,
845+
trait_item_def_id,
846+
false,
847+
asyncness.opt_return_id(),
848+
i.id,
849+
);
842850
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(body_id)))
843851
}
844852
AssocItemKind::TyAlias(box TyAliasKind(_, ref generics, ref bounds, ref default)) => {

compiler/rustc_middle/src/dep_graph/dep_node.rs

+28-8
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
//! `DepNode` definition happens in the `define_dep_nodes!()` macro. This macro
3333
//! defines the `DepKind` enum. Each `DepKind` has its own parameters that are
3434
//! needed at runtime in order to construct a valid `DepNode` fingerprint.
35-
//! However, only `CompileCodegenUnit` is constructed explicitly (with
36-
//! `make_compile_codegen_unit`).
35+
//! However, only `CompileCodegenUnit` and `CompileMonoItem` are constructed
36+
//! explicitly (with `make_compile_codegen_unit` cq `make_compile_mono_item`).
3737
//!
3838
//! Because the macro sees what parameters a given `DepKind` requires, it can
3939
//! "infer" some properties for each kind of `DepNode`:
@@ -46,15 +46,17 @@
4646
//! `DefId` it was computed from. In other cases, too much information gets
4747
//! lost during fingerprint computation.
4848
//!
49-
//! `make_compile_codegen_unit`, together with `DepNode::new()`, ensures that only
50-
//! valid `DepNode` instances can be constructed. For example, the API does not
51-
//! allow for constructing parameterless `DepNode`s with anything other
52-
//! than a zeroed out fingerprint. More generally speaking, it relieves the
53-
//! user of the `DepNode` API of having to know how to compute the expected
54-
//! fingerprint for a given set of node parameters.
49+
//! `make_compile_codegen_unit` and `make_compile_mono_items`, together with
50+
//! `DepNode::new()`, ensures that only valid `DepNode` instances can be
51+
//! constructed. For example, the API does not allow for constructing
52+
//! parameterless `DepNode`s with anything other than a zeroed out fingerprint.
53+
//! More generally speaking, it relieves the user of the `DepNode` API of
54+
//! having to know how to compute the expected fingerprint for a given set of
55+
//! node parameters.
5556
//!
5657
//! [dependency graph]: https://rustc-dev-guide.rust-lang.org/query.html
5758
59+
use crate::mir::mono::MonoItem;
5860
use crate::ty::TyCtxt;
5961

6062
use rustc_data_structures::fingerprint::Fingerprint;
@@ -175,6 +177,14 @@ pub mod dep_kind {
175177
can_reconstruct_query_key: || false,
176178
};
177179

180+
pub const CompileMonoItem: DepKindStruct = DepKindStruct {
181+
has_params: true,
182+
is_anon: false,
183+
is_eval_always: false,
184+
185+
can_reconstruct_query_key: || false,
186+
};
187+
178188
macro_rules! define_query_dep_kinds {
179189
($(
180190
[$($attrs:tt)*]
@@ -251,6 +261,10 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
251261

252262
// WARNING: if `Symbol` is changed, make sure you update `make_compile_codegen_unit` below.
253263
[] CompileCodegenUnit(Symbol),
264+
265+
// WARNING: if `MonoItem` is changed, make sure you update `make_compile_mono_item` below.
266+
// Only used by rustc_codegen_cranelift
267+
[] CompileMonoItem(MonoItem),
254268
]);
255269

256270
// WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys.
@@ -259,6 +273,12 @@ crate fn make_compile_codegen_unit(tcx: TyCtxt<'_>, name: Symbol) -> DepNode {
259273
DepNode::construct(tcx, DepKind::CompileCodegenUnit, &name)
260274
}
261275

276+
// WARNING: `construct` is generic and does not know that `CompileMonoItem` takes `MonoItem`s as keys.
277+
// Be very careful changing this type signature!
278+
crate fn make_compile_mono_item(tcx: TyCtxt<'tcx>, mono_item: &MonoItem<'tcx>) -> DepNode {
279+
DepNode::construct(tcx, DepKind::CompileMonoItem, mono_item)
280+
}
281+
262282
pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
263283

264284
// We keep a lot of `DepNode`s in memory during compilation. It's not

compiler/rustc_middle/src/dep_graph/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ pub use rustc_query_system::dep_graph::{
1212
SerializedDepNodeIndex, WorkProduct, WorkProductId,
1313
};
1414

15-
crate use dep_node::make_compile_codegen_unit;
1615
pub use dep_node::{label_strs, DepKind, DepNode, DepNodeExt};
16+
crate use dep_node::{make_compile_codegen_unit, make_compile_mono_item};
1717

1818
pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>;
1919
pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps<DepKind>;

compiler/rustc_middle/src/mir/mono.rs

+5
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ impl<'tcx> MonoItem<'tcx> {
181181
}
182182
.map(|hir_id| tcx.hir().span(hir_id))
183183
}
184+
185+
// Only used by rustc_codegen_cranelift
186+
pub fn codegen_dep_node(&self, tcx: TyCtxt<'tcx>) -> DepNode {
187+
crate::dep_graph::make_compile_mono_item(tcx, self)
188+
}
184189
}
185190

186191
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for MonoItem<'tcx> {

compiler/rustc_query_impl/src/plumbing.rs

+5
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@ macro_rules! define_queries {
438438
try_load_from_on_disk_cache: |_, _| {},
439439
};
440440

441+
pub const CompileMonoItem: QueryStruct = QueryStruct {
442+
force_from_dep_node: |_, _| false,
443+
try_load_from_on_disk_cache: |_, _| {},
444+
};
445+
441446
$(pub const $name: QueryStruct = {
442447
const is_anon: bool = is_anon!([$($modifiers)*]);
443448

compiler/rustc_target/src/spec/x86_64_unknown_linux_musl.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::spec::{LinkerFlavor, StackProbeType, Target};
1+
use crate::spec::{LinkerFlavor, SanitizerSet, StackProbeType, Target};
22

33
pub fn target() -> Target {
44
let mut base = super::linux_musl_base::opts();
@@ -7,6 +7,8 @@ pub fn target() -> Target {
77
base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string());
88
base.stack_probes = StackProbeType::InlineOrCall { min_llvm_version_for_inline: (11, 0, 1) };
99
base.static_position_independent_executables = true;
10+
base.supported_sanitizers =
11+
SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::MEMORY | SanitizerSet::THREAD;
1012

1113
Target {
1214
llvm_target: "x86_64-unknown-linux-musl".to_string(),

compiler/rustc_typeck/src/check/gather_locals.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKi
66
use rustc_middle::ty::Ty;
77
use rustc_span::{sym, Span};
88
use rustc_trait_selection::traits;
9-
use std::mem;
109

1110
pub(super) struct GatherLocalsVisitor<'a, 'tcx> {
1211
fcx: &'a FnCtxt<'a, 'tcx>,
1312
parent_id: hir::HirId,
1413
// parameters are special cases of patterns, but we want to handle them as
1514
// *distinct* cases. so track when we are hitting a pattern *within* an fn
1615
// parameter.
17-
outermost_fn_param_pat: bool,
16+
outermost_fn_param_pat: Option<Span>,
1817
}
1918

2019
impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> {
2120
pub(super) fn new(fcx: &'a FnCtxt<'a, 'tcx>, parent_id: hir::HirId) -> Self {
22-
Self { fcx, parent_id, outermost_fn_param_pat: false }
21+
Self { fcx, parent_id, outermost_fn_param_pat: None }
2322
}
2423

2524
fn assign(&mut self, span: Span, nid: hir::HirId, ty_opt: Option<LocalTy<'tcx>>) -> Ty<'tcx> {
@@ -92,7 +91,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
9291
}
9392

9493
fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
95-
let old_outermost_fn_param_pat = mem::replace(&mut self.outermost_fn_param_pat, true);
94+
let old_outermost_fn_param_pat = self.outermost_fn_param_pat.replace(param.ty_span);
9695
intravisit::walk_param(self, param);
9796
self.outermost_fn_param_pat = old_outermost_fn_param_pat;
9897
}
@@ -102,12 +101,12 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
102101
if let PatKind::Binding(_, _, ident, _) = p.kind {
103102
let var_ty = self.assign(p.span, p.hir_id, None);
104103

105-
if self.outermost_fn_param_pat {
104+
if let Some(ty_span) = self.outermost_fn_param_pat {
106105
if !self.fcx.tcx.features().unsized_fn_params {
107106
self.fcx.require_type_is_sized(
108107
var_ty,
109108
p.span,
110-
traits::SizedArgumentType(Some(p.span)),
109+
traits::SizedArgumentType(Some(ty_span)),
111110
);
112111
}
113112
} else {
@@ -123,7 +122,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
123122
var_ty
124123
);
125124
}
126-
let old_outermost_fn_param_pat = mem::replace(&mut self.outermost_fn_param_pat, false);
125+
let old_outermost_fn_param_pat = self.outermost_fn_param_pat.take();
127126
intravisit::walk_pat(self, p);
128127
self.outermost_fn_param_pat = old_outermost_fn_param_pat;
129128
}

library/std/src/primitive_docs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -807,10 +807,10 @@ mod prim_tuple {}
807807
///
808808
/// Additionally, `f32` can represent some special values:
809809
///
810-
/// - -0.0: IEEE 754 floating point numbers have a bit that indicates their sign, so -0.0 is a
811-
/// possible value. For comparison `-0.0 == +0.0` is true but floating point operations can
812-
/// carry the sign bit through arithmetic operations. This means `-1.0 * 0.0` produces -0.0 and
813-
/// a negative number rounded to a value smaller than a float can represent also produces -0.0.
810+
/// - 0.0: IEEE 754 floating point numbers have a bit that indicates their sign, so 0.0 is a
811+
/// possible value. For comparison 0.0 = +0.0, but floating point operations can carry
812+
/// the sign bit through arithmetic operations. This means −0.0 × +0.0 produces 0.0 and
813+
/// a negative number rounded to a value smaller than a float can represent also produces 0.0.
814814
/// - [∞](#associatedconstant.INFINITY) and
815815
/// [−∞](#associatedconstant.NEG_INFINITY): these result from calculations
816816
/// like `1.0 / 0.0`.

library/std/src/thread/local.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ macro_rules! __thread_local_inner {
217217
// so now.
218218
0 => {
219219
$crate::thread::__FastLocalKeyInner::<$t>::register_dtor(
220-
&VAL as *const _ as *mut u8,
220+
$crate::ptr::addr_of_mut!(VAL) as *mut u8,
221221
destroy,
222222
);
223223
STATE = 1;

src/bootstrap/native.rs

+3
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,9 @@ fn supported_sanitizers(
814814
"x86_64-unknown-linux-gnu" => {
815815
common_libs("linux", "x86_64", &["asan", "lsan", "msan", "tsan"])
816816
}
817+
"x86_64-unknown-linux-musl" => {
818+
common_libs("linux", "x86_64", &["asan", "lsan", "msan", "tsan"])
819+
}
817820
_ => Vec::new(),
818821
}
819822
}

src/librustdoc/html/layout.rs

-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ crate fn render<T: Print, S: Print>(
110110
</nav>\
111111
<section id=\"main\" class=\"content\">{content}</section>\
112112
<section id=\"search\" class=\"content hidden\"></section>\
113-
<section class=\"footer\"></section>\
114113
{after_content}\
115114
<div id=\"rustdoc-vars\" data-root-path=\"{root_path}\" data-current-crate=\"{krate}\" \
116115
data-search-index-js=\"{root_path}search-index{suffix}.js\" \

src/test/ui/async-await/async-trait-fn.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
trait T {
33
async fn foo() {} //~ ERROR functions in traits cannot be declared `async`
44
async fn bar(&self) {} //~ ERROR functions in traits cannot be declared `async`
5+
async fn baz() { //~ ERROR functions in traits cannot be declared `async`
6+
// Nested item must not ICE.
7+
fn a() {}
8+
}
59
}
610

711
fn main() {}

src/test/ui/async-await/async-trait-fn.stderr

+17-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ LL | async fn bar(&self) {}
2020
= note: `async` trait functions are not currently supported
2121
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
2222

23-
error: aborting due to 2 previous errors
23+
error[E0706]: functions in traits cannot be declared `async`
24+
--> $DIR/async-trait-fn.rs:5:5
25+
|
26+
LL | async fn baz() {
27+
| ^----
28+
| |
29+
| _____`async` because of this
30+
| |
31+
LL | | // Nested item must not ICE.
32+
LL | | fn a() {}
33+
LL | | }
34+
| |_____^
35+
|
36+
= note: `async` trait functions are not currently supported
37+
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
38+
39+
error: aborting due to 3 previous errors
2440

2541
For more information about this error, try `rustc --explain E0706`.

src/test/ui/error-codes/E0277.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ LL | fn f(p: Path) { }
99
= help: unsized fn params are gated as an unstable feature
1010
help: function arguments must have a statically known size, borrowed types always have a known size
1111
|
12-
LL | fn f(&p: Path) { }
13-
| ^
12+
LL | fn f(p: &Path) { }
13+
| ^
1414

1515
error[E0277]: the trait bound `i32: Foo` is not satisfied
1616
--> $DIR/E0277.rs:15:15

src/test/ui/feature-gates/feature-gate-unsized_fn_params.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ LL | fn foo(x: dyn Foo) {
88
= help: unsized fn params are gated as an unstable feature
99
help: function arguments must have a statically known size, borrowed types always have a known size
1010
|
11-
LL | fn foo(&x: dyn Foo) {
12-
| ^
11+
LL | fn foo(x: &dyn Foo) {
12+
| ^
1313

1414
error[E0277]: the size for values of type `(dyn Foo + 'static)` cannot be known at compilation time
1515
--> $DIR/feature-gate-unsized_fn_params.rs:24:5

src/test/ui/feature-gates/feature-gate-unsized_locals.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ LL | fn f(f: dyn FnOnce()) {}
88
= help: unsized fn params are gated as an unstable feature
99
help: function arguments must have a statically known size, borrowed types always have a known size
1010
|
11-
LL | fn f(&f: dyn FnOnce()) {}
12-
| ^
11+
LL | fn f(f: &dyn FnOnce()) {}
12+
| ^
1313

1414
error: aborting due to previous error
1515

src/test/ui/issues/issue-5883.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ struct Struct {
44
r: dyn A + 'static
55
}
66

7-
fn new_struct(r: dyn A + 'static)
8-
-> Struct { //~^ ERROR the size for values of type
9-
//~^ ERROR the size for values of type
7+
fn new_struct(
8+
r: dyn A + 'static //~ ERROR the size for values of type
9+
) -> Struct { //~ ERROR the size for values of type
1010
Struct { r: r }
1111
}
1212

src/test/ui/issues/issue-5883.stderr

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time
2-
--> $DIR/issue-5883.rs:7:15
2+
--> $DIR/issue-5883.rs:8:5
33
|
4-
LL | fn new_struct(r: dyn A + 'static)
5-
| ^ doesn't have a size known at compile-time
4+
LL | r: dyn A + 'static
5+
| ^ doesn't have a size known at compile-time
66
|
77
= help: the trait `Sized` is not implemented for `(dyn A + 'static)`
88
= help: unsized fn params are gated as an unstable feature
99
help: function arguments must have a statically known size, borrowed types always have a known size
1010
|
11-
LL | fn new_struct(&r: dyn A + 'static)
12-
| ^
11+
LL | r: &dyn A + 'static
12+
| ^
1313

1414
error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time
15-
--> $DIR/issue-5883.rs:8:8
15+
--> $DIR/issue-5883.rs:9:6
1616
|
17-
LL | -> Struct {
18-
| ^^^^^^ doesn't have a size known at compile-time
19-
LL |
17+
LL | ) -> Struct {
18+
| ^^^^^^ doesn't have a size known at compile-time
2019
LL | Struct { r: r }
2120
| --------------- this returned value is of type `Struct`
2221
|

src/test/ui/resolve/issue-5035-2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ LL | fn foo(_x: K) {}
88
= help: unsized fn params are gated as an unstable feature
99
help: function arguments must have a statically known size, borrowed types always have a known size
1010
|
11-
LL | fn foo(&_x: K) {}
12-
| ^
11+
LL | fn foo(_x: &K) {}
12+
| ^
1313

1414
error: aborting due to previous error
1515

src/test/ui/suggestions/path-by-value.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ LL | fn f(p: Path) { }
99
= help: unsized fn params are gated as an unstable feature
1010
help: function arguments must have a statically known size, borrowed types always have a known size
1111
|
12-
LL | fn f(&p: Path) { }
13-
| ^
12+
LL | fn f(p: &Path) { }
13+
| ^
1414

1515
error: aborting due to previous error
1616

src/test/ui/traits/bound/not-on-bare-trait.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ LL | fn foo(_x: Foo + Send) {
1616
= help: unsized fn params are gated as an unstable feature
1717
help: function arguments must have a statically known size, borrowed types always have a known size
1818
|
19-
LL | fn foo(&_x: Foo + Send) {
20-
| ^
19+
LL | fn foo(_x: &Foo + Send) {
20+
| ^
2121

2222
error: aborting due to previous error; 1 warning emitted
2323

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// run-rustfix
2+
#![crate_type="lib"]
3+
#![allow(unused)]
4+
5+
fn f<T: ?Sized>(t: &T) {}
6+
//~^ ERROR the size for values of type `T` cannot be known at compilation time

0 commit comments

Comments
 (0)