Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #118651

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2faaea9
Provide context when `?` can't be called because of `Result<_, E>`
estebank Oct 6, 2023
276b74d
Point at fewer methods in the chain, only those that change the E type
estebank Oct 7, 2023
e688742
Detect incorrect `;` in `Option::ok_or_else` and `Result::map_err`
estebank Oct 7, 2023
cc49398
Reduce verbosity of error
estebank Oct 7, 2023
d92c2b5
add comments
estebank Oct 7, 2023
cce82d8
let-chain fmt
estebank Nov 16, 2023
d1583eb
lib features ending in '_internals?' are internal
RalfJung Nov 21, 2023
74834a9
also make 'core_intrinsics' internal
RalfJung Nov 22, 2023
d627e2a
Fix parser ICE when recovering `dyn`/`impl` after `for<...>`
sjwang05 Dec 4, 2023
65212a0
Remove `#[rustc_host]`, use internal desugaring
fee1-dead Dec 4, 2023
a0ba895
bootstrap(builder.rs): Don't explicitly warn against `semicolon_in_ex…
Xanewok Dec 5, 2023
334577f
Add deeply_normalize_for_diagnostics, use it in coherence
compiler-errors Nov 27, 2023
3448284
Continue folding if deep normalizer fails
compiler-errors Nov 28, 2023
b97ff8e
Add print_trait_sugared
compiler-errors Nov 24, 2023
f6c30b3
Add more
compiler-errors Nov 24, 2023
94fd369
Rollup merge of #116496 - estebank:question-method-chain-context, r=c…
matthiaskrgr Dec 5, 2023
13d386e
Rollup merge of #118123 - RalfJung:internal-lib-features, r=compiler-…
matthiaskrgr Dec 5, 2023
18b7570
Rollup merge of #118268 - compiler-errors:pretty-print, r=estebank
matthiaskrgr Dec 5, 2023
1503a53
Rollup merge of #118346 - compiler-errors:deeply-normalize-for-diagno…
matthiaskrgr Dec 5, 2023
ee37f4a
Rollup merge of #118585 - sjwang05:issue-118564, r=compiler-errors
matthiaskrgr Dec 5, 2023
848dc33
Rollup merge of #118605 - fee1-dead-contrib:rm-rustc_host, r=compiler…
matthiaskrgr Dec 5, 2023
ed076f8
Rollup merge of #118642 - Xanewok:patch-1, r=clubby789
matthiaskrgr Dec 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 16 additions & 39 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,11 +561,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
.params
.iter()
.find(|param| {
parent_hir
.attrs
.get(param.hir_id.local_id)
.iter()
.any(|attr| attr.has_name(sym::rustc_host))
matches!(
param.kind,
hir::GenericParamKind::Const { is_host_effect: true, .. }
)
})
.map(|param| param.def_id);
}
Expand Down Expand Up @@ -1352,27 +1351,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
let host_param_parts = if let Const::Yes(span) = constness
&& self.tcx.features().effects
{
if let Some(param) =
generics.params.iter().find(|x| x.attrs.iter().any(|x| x.has_name(sym::rustc_host)))
{
// user has manually specified a `rustc_host` param, in this case, we set
// the param id so that lowering logic can use that. But we don't create
// another host param, so this gives `None`.
self.host_param_id = Some(self.local_def_id(param.id));
None
} else {
let param_node_id = self.next_node_id();
let hir_id = self.next_id();
let def_id = self.create_def(
self.local_def_id(parent_node_id),
param_node_id,
sym::host,
DefKind::ConstParam,
span,
);
self.host_param_id = Some(def_id);
Some((span, hir_id, def_id))
}
let param_node_id = self.next_node_id();
let hir_id = self.next_id();
let def_id = self.create_def(
self.local_def_id(parent_node_id),
param_node_id,
sym::host,
DefKind::ConstParam,
span,
);
self.host_param_id = Some(def_id);
Some((span, hir_id, def_id))
} else {
None
};
Expand Down Expand Up @@ -1436,19 +1425,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
self.children.push((anon_const, hir::MaybeOwner::NonOwner(const_id)));

let attr_id = self.tcx.sess.parse_sess.attr_id_generator.mk_attr_id();

let attrs = self.arena.alloc_from_iter([Attribute {
kind: AttrKind::Normal(P(NormalAttr::from_ident(Ident::new(
sym::rustc_host,
span,
)))),
span,
id: attr_id,
style: AttrStyle::Outer,
}]);
self.attrs.insert(hir_id.local_id, attrs);

let const_body = self.lower_body(|this| {
(
&[],
Expand Down Expand Up @@ -1490,6 +1466,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir_id: const_id,
body: const_body,
}),
is_host_effect: true,
},
colon_span: None,
pure_wrt_drop: false,
Expand Down
12 changes: 2 additions & 10 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2108,7 +2108,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let default = default.as_ref().map(|def| self.lower_anon_const(def));
(
hir::ParamName::Plain(self.lower_ident(param.ident)),
hir::GenericParamKind::Const { ty, default },
hir::GenericParamKind::Const { ty, default, is_host_effect: false },
)
}
}
Expand Down Expand Up @@ -2536,22 +2536,14 @@ impl<'hir> GenericArgsCtor<'hir> {
})
});

let attr_id = lcx.tcx.sess.parse_sess.attr_id_generator.mk_attr_id();
let attr = lcx.arena.alloc(Attribute {
kind: AttrKind::Normal(P(NormalAttr::from_ident(Ident::new(sym::rustc_host, span)))),
span,
id: attr_id,
style: AttrStyle::Outer,
});
lcx.attrs.insert(hir_id.local_id, std::slice::from_ref(attr));

let def_id = lcx.create_def(
lcx.current_hir_id_owner.def_id,
id,
kw::Empty,
DefKind::AnonConst,
span,
);

lcx.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
self.args.push(hir::GenericArg::Const(hir::ConstArg {
value: hir::AnonConst { def_id, hir_id, body },
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,12 +719,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
and it is only intended to be used in `alloc`."
),

rustc_attr!(
rustc_host, AttributeType::Normal, template!(Word), ErrorFollowing,
"#[rustc_host] annotates const generic parameters as the `host` effect param, \
and it is only intended for internal use and as a desugaring."
),

BuiltinAttribute {
name: sym::rustc_diagnostic_item,
// FIXME: This can be `true` once we always use `tcx.is_diagnostic_item`.
Expand Down
20 changes: 14 additions & 6 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ macro_rules! declare_features {
#[derive(Clone, Default, Debug)]
pub struct Features {
/// `#![feature]` attrs for language features, for error reporting.
/// "declared" here means that the feature is actually enabled in the current crate.
pub declared_lang_features: Vec<(Symbol, Span, Option<Symbol>)>,
/// `#![feature]` attrs for non-language (library) features.
/// "declared" here means that the feature is actually enabled in the current crate.
pub declared_lib_features: Vec<(Symbol, Span)>,
/// `declared_lang_features` + `declared_lib_features`.
pub declared_features: FxHashSet<Symbol>,
Expand Down Expand Up @@ -133,9 +135,18 @@ macro_rules! declare_features {
$(
sym::$feature => status_to_enum!($status) == FeatureStatus::Internal,
)*
// Accepted/removed features aren't in this file but are never internal
// (a removed feature might have been internal, but that's now irrelevant).
_ if self.declared_features.contains(&feature) => false,
_ if self.declared_features.contains(&feature) => {
// This could be accepted/removed, or a libs feature.
// Accepted/removed features aren't in this file but are never internal
// (a removed feature might have been internal, but that's now irrelevant).
// Libs features are internal if they end in `_internal` or `_internals`.
// As a special exception we also consider `core_intrinsics` internal;
// renaming that age-old feature is just not worth the hassle.
// We just always test the name; it's not a big deal if we accidentally hit
// an accepted/removed lang feature that way.
let name = feature.as_str();
name == "core_intrinsics" || name.ends_with("_internal") || name.ends_with("_internals")
}
_ => panic!("`{}` was not listed in `declare_features`", feature),
}
}
Expand Down Expand Up @@ -215,9 +226,6 @@ declare_features! (
(internal, test_2018_feature, "1.31.0", None, Some(Edition::Edition2018)),
/// Added for testing unstable lints; perma-unstable.
(internal, test_unstable_lint, "1.60.0", None, None),
/// Allows non-`unsafe` —and thus, unsound— access to `Pin` constructions.
/// Marked `internal` since perma-unstable and unsound.
(internal, unsafe_pin_internals, "1.60.0", None, None),
/// Use for stable + negative coherence and strict coherence depending on trait's
/// rustc_strict_coherence value.
(unstable, with_negative_coherence, "1.60.0", None, None),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ pub enum GenericParamKind<'hir> {
ty: &'hir Ty<'hir>,
/// Optional default value for the const generic param
default: Option<AnonConst>,
is_host_effect: bool,
},
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Generi
match param.kind {
GenericParamKind::Lifetime { .. } => {}
GenericParamKind::Type { ref default, .. } => walk_list!(visitor, visit_ty, default),
GenericParamKind::Const { ref ty, ref default } => {
GenericParamKind::Const { ref ty, ref default, is_host_effect: _ } => {
visitor.visit_ty(ty);
if let Some(ref default) = default {
visitor.visit_const_param_default(param.hir_id, default);
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,10 +1182,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if let Some(bound_span) = bound_span {
err.span_label(
bound_span,
format!(
"ambiguous `{assoc_name}` from `{}`",
bound.print_only_trait_path(),
),
format!("ambiguous `{assoc_name}` from `{}`", bound.print_trait_sugared(),),
);
if let Some(constraint) = &is_equality {
where_bounds.push(format!(
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_analysis/src/astconv/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
trait here instead: `trait NewTrait: {} {{}}`",
regular_traits
.iter()
// FIXME: This should `print_sugared`, but also needs to integrate projection bounds...
.map(|t| t.trait_ref().print_only_trait_path().to_string())
.collect::<Vec<_>>()
.join(" + "),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
hir::GenericParamKind::Lifetime { .. } | hir::GenericParamKind::Type { .. } => Ok(()),

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

if tcx.features().adt_const_params {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir_analysis/src/coherence/unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
tcx.def_span(def_id),
E0199,
"implementing the trait `{}` is not unsafe",
trait_ref.print_only_trait_path()
trait_ref.print_trait_sugared()
)
.span_suggestion_verbose(
item.span.with_hi(item.span.lo() + rustc_span::BytePos(7)),
Expand All @@ -40,13 +40,13 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
tcx.def_span(def_id),
E0200,
"the trait `{}` requires an `unsafe impl` declaration",
trait_ref.print_only_trait_path()
trait_ref.print_trait_sugared()
)
.note(format!(
"the trait `{}` enforces invariants that the compiler can't check. \
Review the trait documentation and make sure this implementation \
upholds those invariants before adding the `unsafe` keyword",
trait_ref.print_only_trait_path()
trait_ref.print_trait_sugared()
))
.span_suggestion_verbose(
item.span.shrink_to_lo(),
Expand All @@ -69,7 +69,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
"the trait `{}` enforces invariants that the compiler can't check. \
Review the trait documentation and make sure this implementation \
upholds those invariants before adding the `unsafe` keyword",
trait_ref.print_only_trait_path()
trait_ref.print_trait_sugared()
))
.span_suggestion_verbose(
item.span.shrink_to_lo(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ fn impl_trait_ref(
let last_segment = path_segments.len() - 1;
let mut args = *path_segments[last_segment].args();
let last_arg = args.args.len() - 1;
assert!(matches!(args.args[last_arg], hir::GenericArg::Const(anon_const) if tcx.has_attr(anon_const.value.def_id, sym::rustc_host)));
assert!(matches!(args.args[last_arg], hir::GenericArg::Const(anon_const) if anon_const.is_desugared_from_effects));
args.args = &args.args[..args.args.len() - 1];
path_segments[last_segment].args = Some(&args);
let path = hir::Path {
Expand Down
16 changes: 7 additions & 9 deletions compiler/rustc_hir_analysis/src/collect/generics_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_hir::def_id::LocalDefId;
use rustc_middle::ty::{self, TyCtxt};
use rustc_session::lint;
use rustc_span::symbol::{kw, Symbol};
use rustc_span::{sym, Span};
use rustc_span::Span;

pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
use rustc_hir::*;
Expand Down Expand Up @@ -298,13 +298,11 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
kind,
})
}
GenericParamKind::Const { default, .. } => {
let is_host_param = tcx.has_attr(param.def_id, sym::rustc_host);

GenericParamKind::Const { ty: _, default, is_host_effect } => {
if !matches!(allow_defaults, Defaults::Allowed)
&& default.is_some()
// `rustc_host` effect params are allowed to have defaults.
&& !is_host_param
// `host` effect params are allowed to have defaults.
&& !is_host_effect
{
tcx.sess.span_err(
param.span,
Expand All @@ -315,7 +313,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {

let index = next_index();

if is_host_param {
if is_host_effect {
if let Some(idx) = host_effect_index {
bug!("parent also has host effect param? index: {idx}, def: {def_id:?}");
}
Expand All @@ -330,7 +328,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
pure_wrt_drop: param.pure_wrt_drop,
kind: ty::GenericParamDefKind::Const {
has_default: default.is_some(),
is_host_effect: is_host_param,
is_host_effect,
},
})
}
Expand Down Expand Up @@ -489,7 +487,7 @@ struct AnonConstInParamTyDetector {

impl<'v> Visitor<'v> for AnonConstInParamTyDetector {
fn visit_generic_param(&mut self, p: &'v hir::GenericParam<'v>) {
if let GenericParamKind::Const { ty, default: _ } = p.kind {
if let GenericParamKind::Const { ty, default: _, is_host_effect: _ } = p.kind {
let prev = self.in_param_ty;
self.in_param_ty = true;
self.visit_ty(ty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
self.visit_ty(ty);
}
}
GenericParamKind::Const { ty, default } => {
GenericParamKind::Const { ty, default, is_host_effect: _ } => {
self.visit_ty(ty);
if let Some(default) = default {
self.visit_body(self.tcx.hir().body(default.body));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,7 @@ impl<'a> State<'a> {
self.print_type(default);
}
}
GenericParamKind::Const { ty, ref default } => {
GenericParamKind::Const { ty, ref default, is_host_effect: _ } => {
self.word_space(":");
self.print_type(ty);
if let Some(default) = default {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2288,7 +2288,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty::Adt(def, _) if def.did().is_local() => {
spans.push_span_label(
self.tcx.def_span(def.did()),
format!("must implement `{}`", pred.trait_ref.print_only_trait_path()),
format!("must implement `{}`", pred.trait_ref.print_trait_sugared()),
);
}
_ => {}
Expand All @@ -2299,7 +2299,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let msg = if preds.len() == 1 {
format!(
"an implementation of `{}` might be missing for `{}`",
preds[0].trait_ref.print_only_trait_path(),
preds[0].trait_ref.print_trait_sugared(),
preds[0].self_ty()
)
} else {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2219,8 +2219,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
infer::ExistentialProjection(exp_found) => self.expected_found_str(exp_found),
infer::PolyTraitRefs(exp_found) => {
let pretty_exp_found = ty::error::ExpectedFound {
expected: exp_found.expected.print_only_trait_path(),
found: exp_found.found.print_only_trait_path(),
expected: exp_found.expected.print_trait_sugared(),
found: exp_found.found.print_trait_sugared(),
};
match self.expected_found_str(pretty_exp_found) {
Some((expected, found, _, _)) if expected == found => {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_lint/src/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,9 @@ impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
}

fn check_generic_param(&mut self, cx: &LateContext<'_>, param: &hir::GenericParam<'_>) {
if let GenericParamKind::Const { .. } = param.kind {
// `rustc_host` params are explicitly allowed to be lowercase.
if cx.tcx.has_attr(param.def_id, sym::rustc_host) {
if let GenericParamKind::Const { is_host_effect, .. } = param.kind {
// `host` params are explicitly allowed to be lowercase.
if is_host_effect {
return;
}
NonUpperCaseGlobals::check_upper_case(cx, "const parameter", &param.name.ident());
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2186,7 +2186,7 @@ impl<'tcx> TyCtxt<'tcx> {
hir::Node::Item(hir::Item {
kind: hir::ItemKind::Impl(hir::Impl { generics, .. }),
..
}) if generics.params.iter().any(|p| self.has_attr(p.def_id, sym::rustc_host))
}) if generics.params.iter().any(|p| matches!(p.kind, hir::GenericParamKind::Const { is_host_effect: true, .. }))
)
}

Expand Down
Loading
Loading