Skip to content

Commit 0c029c8

Browse files
committed
Auto merge of rust-lang#118641 - fee1-dead-contrib:rollup-2qlatcy, r=fee1-dead
Rollup of 8 pull requests Successful merges: - rust-lang#117922 (Tweak unclosed generics errors) - rust-lang#117981 (Remove deprecated `--check-cfg` syntax) - rust-lang#118471 (Fix typos in README.md) - rust-lang#118488 (Change prefetch to avoid deadlock) - rust-lang#118605 (Remove `#[rustc_host]`, use internal desugaring) - rust-lang#118608 (Use default params until effects in desugaring) - rust-lang#118614 (Update books) - rust-lang#118637 (rustc_symbol_mangling,rustc_interface,rustc_driver_impl: Enforce `rustc::potential_query_instability` lint) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f536185 + 0a896b4 commit 0c029c8

File tree

78 files changed

+364
-567
lines changed

Some content is hidden

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

78 files changed

+364
-567
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ If you wish to _contribute_ to the compiler, you should read
1212
[CONTRIBUTING.md](CONTRIBUTING.md) instead.
1313

1414
<details>
15-
<summary>Table of content</summary>
15+
<summary>Table of Contents</summary>
1616

1717
- [Quick Start](#quick-start)
1818
- [Installing from Source](#installing-from-source)

compiler/rustc_ast_lowering/src/item.rs

+16-39
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
561561
.params
562562
.iter()
563563
.find(|param| {
564-
parent_hir
565-
.attrs
566-
.get(param.hir_id.local_id)
567-
.iter()
568-
.any(|attr| attr.has_name(sym::rustc_host))
564+
matches!(
565+
param.kind,
566+
hir::GenericParamKind::Const { is_host_effect: true, .. }
567+
)
569568
})
570569
.map(|param| param.def_id);
571570
}
@@ -1352,27 +1351,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
13521351
let host_param_parts = if let Const::Yes(span) = constness
13531352
&& self.tcx.features().effects
13541353
{
1355-
if let Some(param) =
1356-
generics.params.iter().find(|x| x.attrs.iter().any(|x| x.has_name(sym::rustc_host)))
1357-
{
1358-
// user has manually specified a `rustc_host` param, in this case, we set
1359-
// the param id so that lowering logic can use that. But we don't create
1360-
// another host param, so this gives `None`.
1361-
self.host_param_id = Some(self.local_def_id(param.id));
1362-
None
1363-
} else {
1364-
let param_node_id = self.next_node_id();
1365-
let hir_id = self.next_id();
1366-
let def_id = self.create_def(
1367-
self.local_def_id(parent_node_id),
1368-
param_node_id,
1369-
sym::host,
1370-
DefKind::ConstParam,
1371-
span,
1372-
);
1373-
self.host_param_id = Some(def_id);
1374-
Some((span, hir_id, def_id))
1375-
}
1354+
let param_node_id = self.next_node_id();
1355+
let hir_id = self.next_id();
1356+
let def_id = self.create_def(
1357+
self.local_def_id(parent_node_id),
1358+
param_node_id,
1359+
sym::host,
1360+
DefKind::ConstParam,
1361+
span,
1362+
);
1363+
self.host_param_id = Some(def_id);
1364+
Some((span, hir_id, def_id))
13761365
} else {
13771366
None
13781367
};
@@ -1436,19 +1425,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
14361425
self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
14371426
self.children.push((anon_const, hir::MaybeOwner::NonOwner(const_id)));
14381427

1439-
let attr_id = self.tcx.sess.parse_sess.attr_id_generator.mk_attr_id();
1440-
1441-
let attrs = self.arena.alloc_from_iter([Attribute {
1442-
kind: AttrKind::Normal(P(NormalAttr::from_ident(Ident::new(
1443-
sym::rustc_host,
1444-
span,
1445-
)))),
1446-
span,
1447-
id: attr_id,
1448-
style: AttrStyle::Outer,
1449-
}]);
1450-
self.attrs.insert(hir_id.local_id, attrs);
1451-
14521428
let const_body = self.lower_body(|this| {
14531429
(
14541430
&[],
@@ -1490,6 +1466,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14901466
hir_id: const_id,
14911467
body: const_body,
14921468
}),
1469+
is_host_effect: true,
14931470
},
14941471
colon_span: None,
14951472
pure_wrt_drop: false,

compiler/rustc_ast_lowering/src/lib.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21082108
let default = default.as_ref().map(|def| self.lower_anon_const(def));
21092109
(
21102110
hir::ParamName::Plain(self.lower_ident(param.ident)),
2111-
hir::GenericParamKind::Const { ty, default },
2111+
hir::GenericParamKind::Const { ty, default, is_host_effect: false },
21122112
)
21132113
}
21142114
}
@@ -2536,22 +2536,14 @@ impl<'hir> GenericArgsCtor<'hir> {
25362536
})
25372537
});
25382538

2539-
let attr_id = lcx.tcx.sess.parse_sess.attr_id_generator.mk_attr_id();
2540-
let attr = lcx.arena.alloc(Attribute {
2541-
kind: AttrKind::Normal(P(NormalAttr::from_ident(Ident::new(sym::rustc_host, span)))),
2542-
span,
2543-
id: attr_id,
2544-
style: AttrStyle::Outer,
2545-
});
2546-
lcx.attrs.insert(hir_id.local_id, std::slice::from_ref(attr));
2547-
25482539
let def_id = lcx.create_def(
25492540
lcx.current_hir_id_owner.def_id,
25502541
id,
25512542
kw::Empty,
25522543
DefKind::AnonConst,
25532544
span,
25542545
);
2546+
25552547
lcx.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
25562548
self.args.push(hir::GenericArg::Const(hir::ConstArg {
25572549
value: hir::AnonConst { def_id, hir_id, body },

compiler/rustc_driver_impl/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#![feature(let_chains)]
1414
#![feature(panic_update_hook)]
1515
#![recursion_limit = "256"]
16-
#![allow(rustc::potential_query_instability)]
1716
#![deny(rustc::untranslatable_diagnostic)]
1817
#![deny(rustc::diagnostic_outside_of_impl)]
1918

compiler/rustc_feature/src/builtin_attrs.rs

-6
Original file line numberDiff line numberDiff line change
@@ -719,12 +719,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
719719
and it is only intended to be used in `alloc`."
720720
),
721721

722-
rustc_attr!(
723-
rustc_host, AttributeType::Normal, template!(Word), ErrorFollowing,
724-
"#[rustc_host] annotates const generic parameters as the `host` effect param, \
725-
and it is only intended for internal use and as a desugaring."
726-
),
727-
728722
BuiltinAttribute {
729723
name: sym::rustc_diagnostic_item,
730724
// FIXME: This can be `true` once we always use `tcx.is_diagnostic_item`.

compiler/rustc_hir/src/hir.rs

+1
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ pub enum GenericParamKind<'hir> {
487487
ty: &'hir Ty<'hir>,
488488
/// Optional default value for the const generic param
489489
default: Option<AnonConst>,
490+
is_host_effect: bool,
490491
},
491492
}
492493

compiler/rustc_hir/src/intravisit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Generi
874874
match param.kind {
875875
GenericParamKind::Lifetime { .. } => {}
876876
GenericParamKind::Type { ref default, .. } => walk_list!(visitor, visit_ty, default),
877-
GenericParamKind::Const { ref ty, ref default } => {
877+
GenericParamKind::Const { ref ty, ref default, is_host_effect: _ } => {
878878
visitor.visit_ty(ty);
879879
if let Some(ref default) = default {
880880
visitor.visit_const_param_default(param.hir_id, default);

compiler/rustc_hir_analysis/src/astconv/generics.rs

+25
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,31 @@ pub fn create_args_for_parent_generic_args<'tcx, 'a>(
243243
match (args_iter.peek(), params.peek()) {
244244
(Some(&arg), Some(&param)) => {
245245
match (arg, &param.kind, arg_count.explicit_late_bound) {
246+
(
247+
GenericArg::Const(hir::ConstArg {
248+
is_desugared_from_effects: true,
249+
..
250+
}),
251+
GenericParamDefKind::Const { is_host_effect: false, .. }
252+
| GenericParamDefKind::Type { .. }
253+
| GenericParamDefKind::Lifetime,
254+
_,
255+
) => {
256+
// SPECIAL CASE FOR DESUGARED EFFECT PARAMS
257+
// This comes from the following example:
258+
//
259+
// ```
260+
// #[const_trait]
261+
// pub trait PartialEq<Rhs: ?Sized = Self> {}
262+
// impl const PartialEq for () {}
263+
// ```
264+
//
265+
// Since this is a const impl, we need to insert `<false>` at the end of
266+
// `PartialEq`'s generics, but this errors since `Rhs` isn't specified.
267+
// To work around this, we infer all arguments until we reach the host param.
268+
args.push(ctx.inferred_kind(Some(&args), param, infer_args));
269+
params.next();
270+
}
246271
(GenericArg::Lifetime(_), GenericParamDefKind::Lifetime, _)
247272
| (
248273
GenericArg::Type(_) | GenericArg::Infer(_),

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
859859
hir::GenericParamKind::Lifetime { .. } | hir::GenericParamKind::Type { .. } => Ok(()),
860860

861861
// Const parameters are well formed if their type is structural match.
862-
hir::GenericParamKind::Const { ty: hir_ty, default: _ } => {
862+
hir::GenericParamKind::Const { ty: hir_ty, default: _, is_host_effect: _ } => {
863863
let ty = tcx.type_of(param.def_id).instantiate_identity();
864864

865865
if tcx.features().adt_const_params {

compiler/rustc_hir_analysis/src/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ fn impl_trait_ref(
13831383
let last_segment = path_segments.len() - 1;
13841384
let mut args = *path_segments[last_segment].args();
13851385
let last_arg = args.args.len() - 1;
1386-
assert!(matches!(args.args[last_arg], hir::GenericArg::Const(anon_const) if tcx.has_attr(anon_const.value.def_id, sym::rustc_host)));
1386+
assert!(matches!(args.args[last_arg], hir::GenericArg::Const(anon_const) if anon_const.is_desugared_from_effects));
13871387
args.args = &args.args[..args.args.len() - 1];
13881388
path_segments[last_segment].args = Some(&args);
13891389
let path = hir::Path {

compiler/rustc_hir_analysis/src/collect/generics_of.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::def_id::LocalDefId;
99
use rustc_middle::ty::{self, TyCtxt};
1010
use rustc_session::lint;
1111
use rustc_span::symbol::{kw, Symbol};
12-
use rustc_span::{sym, Span};
12+
use rustc_span::Span;
1313

1414
pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
1515
use rustc_hir::*;
@@ -298,13 +298,11 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
298298
kind,
299299
})
300300
}
301-
GenericParamKind::Const { default, .. } => {
302-
let is_host_param = tcx.has_attr(param.def_id, sym::rustc_host);
303-
301+
GenericParamKind::Const { ty: _, default, is_host_effect } => {
304302
if !matches!(allow_defaults, Defaults::Allowed)
305303
&& default.is_some()
306-
// `rustc_host` effect params are allowed to have defaults.
307-
&& !is_host_param
304+
// `host` effect params are allowed to have defaults.
305+
&& !is_host_effect
308306
{
309307
tcx.sess.span_err(
310308
param.span,
@@ -315,7 +313,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
315313

316314
let index = next_index();
317315

318-
if is_host_param {
316+
if is_host_effect {
319317
if let Some(idx) = host_effect_index {
320318
bug!("parent also has host effect param? index: {idx}, def: {def_id:?}");
321319
}
@@ -330,7 +328,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
330328
pure_wrt_drop: param.pure_wrt_drop,
331329
kind: ty::GenericParamDefKind::Const {
332330
has_default: default.is_some(),
333-
is_host_effect: is_host_param,
331+
is_host_effect,
334332
},
335333
})
336334
}
@@ -489,7 +487,7 @@ struct AnonConstInParamTyDetector {
489487

490488
impl<'v> Visitor<'v> for AnonConstInParamTyDetector {
491489
fn visit_generic_param(&mut self, p: &'v hir::GenericParam<'v>) {
492-
if let GenericParamKind::Const { ty, default: _ } = p.kind {
490+
if let GenericParamKind::Const { ty, default: _, is_host_effect: _ } = p.kind {
493491
let prev = self.in_param_ty;
494492
self.in_param_ty = true;
495493
self.visit_ty(ty);

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
992992
self.visit_ty(ty);
993993
}
994994
}
995-
GenericParamKind::Const { ty, default } => {
995+
GenericParamKind::Const { ty, default, is_host_effect: _ } => {
996996
self.visit_ty(ty);
997997
if let Some(default) = default {
998998
self.visit_body(self.tcx.hir().body(default.body));

compiler/rustc_hir_pretty/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,7 @@ impl<'a> State<'a> {
21262126
self.print_type(default);
21272127
}
21282128
}
2129-
GenericParamKind::Const { ty, ref default } => {
2129+
GenericParamKind::Const { ty, ref default, is_host_effect: _ } => {
21302130
self.word_space(":");
21312131
self.print_type(ty);
21322132
if let Some(default) = default {

0 commit comments

Comments
 (0)