Skip to content
/ rust Public
forked from rust-lang/rust

Commit c78a294

Browse files
committed
Auto merge of rust-lang#152986 - JonathanBrouwer:rollup-YgdiVyQ, r=JonathanBrouwer
Rollup of 7 pull requests Successful merges: - rust-lang#152779 (Clarify aspects of query macros) - rust-lang#152958 (`rustc_queries` simplifications) - rust-lang#152385 (Feature gate for defaulted associated type_consts with associated_type_defaults ) - rust-lang#152708 (Build: Add `stdenv.cc.cc.lib` to Nix dependencies) - rust-lang#152921 (Add build.rustdoc option to bootstrap config) - rust-lang#152926 (Fix ICE when an associated type is wrongly marked as `final`) - rust-lang#152927 (Index expressions rendered the index: subexpression as the id, instea…)
2 parents 1500f0f + 6aa7b31 commit c78a294

File tree

25 files changed

+1772
-486
lines changed

25 files changed

+1772
-486
lines changed

bootstrap.example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@
302302
# If you set this, you likely want to set `cargo` as well.
303303
#build.rustc = "/path/to/rustc"
304304

305+
# Use this rustdoc binary as the stage0 snapshot rustdoc.
306+
# If unspecified, then the binary "rustdoc" (with platform-specific extension, e.g. ".exe")
307+
# in the same directory as "rustc" will be used.
308+
#build.rustdoc = "/path/to/rustdoc"
309+
305310
# Instead of downloading the src/stage0 version of rustfmt specified,
306311
# use this rustfmt binary instead as the stage0 snapshot rustfmt.
307312
#build.rustfmt = "/path/to/rustfmt"

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
10851085
}
10861086
};
10871087

1088-
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value, || {
1089-
hir::Defaultness::Default { has_value }
1090-
});
1088+
let defaultness = match i.kind.defaultness() {
1089+
// We do not yet support `final` on trait associated items other than functions.
1090+
// Even though we reject `final` on non-functions during AST validation, we still
1091+
// need to stop propagating it here because later compiler passes do not expect
1092+
// and cannot handle such items.
1093+
Defaultness::Final(..) if !matches!(i.kind, AssocItemKind::Fn(..)) => {
1094+
Defaultness::Implicit
1095+
}
1096+
defaultness => defaultness,
1097+
};
1098+
let (defaultness, _) = self
1099+
.lower_defaultness(defaultness, has_value, || hir::Defaultness::Default { has_value });
10911100

10921101
let item = hir::TraitItem {
10931102
owner_id: trait_item_def_id,

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
427427
false
428428
}
429429
ast::AssocItemKind::Const(box ast::ConstItem {
430-
rhs_kind: ast::ConstItemRhsKind::TypeConst { .. },
430+
rhs_kind: ast::ConstItemRhsKind::TypeConst { rhs },
431431
..
432432
}) => {
433433
// Make sure this is only allowed if the feature gate is enabled.
@@ -438,6 +438,17 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
438438
i.span,
439439
"associated `type const` are unstable"
440440
);
441+
// Make sure associated `type const` defaults in traits are only allowed
442+
// if the feature gate is enabled.
443+
// #![feature(associated_type_defaults)]
444+
if ctxt == AssocCtxt::Trait && rhs.is_some() {
445+
gate!(
446+
&self,
447+
associated_type_defaults,
448+
i.span,
449+
"associated type defaults are unstable"
450+
);
451+
}
441452
false
442453
}
443454
_ => false,

compiler/rustc_macros/src/query.rs

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,11 @@ impl<T: Parse> Parse for List<T> {
103103

104104
struct Desc {
105105
modifier: Ident,
106-
tcx_binding: Option<Ident>,
107106
expr_list: Punctuated<Expr, Token![,]>,
108107
}
109108

110109
struct CacheOnDiskIf {
111110
modifier: Ident,
112-
tcx_binding: Option<Pat>,
113111
block: Block,
114112
}
115113

@@ -192,35 +190,16 @@ fn parse_query_modifiers(input: ParseStream<'_>) -> Result<QueryModifiers> {
192190

193191
if modifier == "desc" {
194192
// Parse a description modifier like:
195-
// `desc { |tcx| "foo {}", tcx.item_path(key) }`
193+
// `desc { "foo {}", tcx.item_path(key) }`
196194
let attr_content;
197195
braced!(attr_content in input);
198-
let tcx_binding = if attr_content.peek(Token![|]) {
199-
attr_content.parse::<Token![|]>()?;
200-
let tcx = attr_content.parse()?;
201-
attr_content.parse::<Token![|]>()?;
202-
Some(tcx)
203-
} else {
204-
None
205-
};
206196
let expr_list = attr_content.parse_terminated(Expr::parse, Token![,])?;
207-
try_insert!(desc = Desc { modifier, tcx_binding, expr_list });
197+
try_insert!(desc = Desc { modifier, expr_list });
208198
} else if modifier == "cache_on_disk_if" {
209199
// Parse a cache-on-disk modifier like:
210-
//
211-
// `cache_on_disk_if { true }`
212-
// `cache_on_disk_if { key.is_local() }`
213-
// `cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }`
214-
let tcx_binding = if input.peek(token::Paren) {
215-
let args;
216-
parenthesized!(args in input);
217-
let tcx = Pat::parse_single(&args)?;
218-
Some(tcx)
219-
} else {
220-
None
221-
};
200+
// `cache_on_disk_if { tcx.is_typeck_child(key.to_def_id()) }`
222201
let block = input.parse()?;
223-
try_insert!(cache_on_disk_if = CacheOnDiskIf { modifier, tcx_binding, block });
202+
try_insert!(cache_on_disk_if = CacheOnDiskIf { modifier, block });
224203
} else if modifier == "arena_cache" {
225204
try_insert!(arena_cache = modifier);
226205
} else if modifier == "cycle_fatal" {
@@ -313,24 +292,24 @@ fn make_helpers_for_query(query: &Query, streams: &mut HelperTokenStreams) {
313292
erased_name.set_span(Span::call_site());
314293

315294
// Generate a function to check whether we should cache the query to disk, for some key.
316-
if let Some(CacheOnDiskIf { tcx_binding, block, .. }) = modifiers.cache_on_disk_if.as_ref() {
317-
let tcx = tcx_binding.as_ref().map(|t| quote! { #t }).unwrap_or_else(|| quote! { _ });
318-
// we're taking `key` by reference, but some rustc types usually prefer being passed by value
295+
if let Some(CacheOnDiskIf { block, .. }) = modifiers.cache_on_disk_if.as_ref() {
296+
// `pass_by_value`: some keys are marked with `rustc_pass_by_value`, but we take keys by
297+
// reference here.
298+
// FIXME: `pass_by_value` is badly named; `allow(rustc::pass_by_value)` actually means
299+
// "allow pass by reference of `rustc_pass_by_value` types".
319300
streams.cache_on_disk_if_fns_stream.extend(quote! {
320301
#[allow(unused_variables, rustc::pass_by_value)]
321302
#[inline]
322-
pub fn #erased_name<'tcx>(#tcx: TyCtxt<'tcx>, #key_pat: &crate::queries::#name::Key<'tcx>) -> bool
303+
pub fn #erased_name<'tcx>(tcx: TyCtxt<'tcx>, #key_pat: &#key_ty) -> bool
323304
#block
324305
});
325306
}
326307

327-
let Desc { tcx_binding, expr_list, .. } = &modifiers.desc;
328-
let tcx = tcx_binding.as_ref().map_or_else(|| quote! { _ }, |t| quote! { #t });
308+
let Desc { expr_list, .. } = &modifiers.desc;
329309

330310
let desc = quote! {
331311
#[allow(unused_variables)]
332-
pub fn #erased_name<'tcx>(tcx: TyCtxt<'tcx>, key: #key_ty) -> String {
333-
let (#tcx, #key_pat) = (tcx, key);
312+
pub fn #erased_name<'tcx>(tcx: TyCtxt<'tcx>, #key_pat: #key_ty) -> String {
334313
format!(#expr_list)
335314
}
336315
};

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,12 @@ impl StableOrd for WorkProductId {
324324
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
325325
}
326326

327+
// Note: `$K` and `$V` are unused but present so this can be called by `rustc_with_all_queries`.
327328
macro_rules! define_dep_nodes {
328329
(
329330
$(
330331
$(#[$attr:meta])*
331-
[$($modifiers:tt)*] fn $variant:ident($($K:tt)*) -> $V:ty,
332+
[$($modifiers:tt)*] fn $variant:ident($K:ty) -> $V:ty,
332333
)*
333334
) => {
334335

@@ -382,20 +383,20 @@ macro_rules! define_dep_nodes {
382383
}
383384

384385
// Create various data structures for each query, and also for a few things
385-
// that aren't queries.
386+
// that aren't queries. The key and return types aren't used, hence the use of `()`.
386387
rustc_with_all_queries!(define_dep_nodes![
387388
/// We use this for most things when incr. comp. is turned off.
388-
[] fn Null() -> (),
389+
[] fn Null(()) -> (),
389390
/// We use this to create a forever-red node.
390-
[] fn Red() -> (),
391+
[] fn Red(()) -> (),
391392
/// We use this to create a side effect node.
392-
[] fn SideEffect() -> (),
393+
[] fn SideEffect(()) -> (),
393394
/// We use this to create the anon node with zero dependencies.
394-
[] fn AnonZeroDeps() -> (),
395-
[] fn TraitSelect() -> (),
396-
[] fn CompileCodegenUnit() -> (),
397-
[] fn CompileMonoItem() -> (),
398-
[] fn Metadata() -> (),
395+
[] fn AnonZeroDeps(()) -> (),
396+
[] fn TraitSelect(()) -> (),
397+
[] fn CompileCodegenUnit(()) -> (),
398+
[] fn CompileMonoItem(()) -> (),
399+
[] fn Metadata(()) -> (),
399400
]);
400401

401402
// WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys.

0 commit comments

Comments
 (0)