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 8 pull requests #126760

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
cb9f55c
Adds expr_2024 migration lit
vincenzopalazzo May 25, 2024
9b22110
Add powerpc-unknown-openbsd maintaince status
ChrisDenton Jun 14, 2024
c4ddc86
Print the tested value in int_log tests
tgross35 Jun 18, 2024
b6d20d1
Add the target-features
sayantn Jun 18, 2024
1e1b3fc
Fix stderr cases
sayantn Jun 18, 2024
6366acc
tests: adds cargo fix tests
vincenzopalazzo May 25, 2024
50d1efa
Add a test demonstrating the problem
compiler-errors Jun 19, 2024
3e8898a
Allow naming expr_2021 in all editions
compiler-errors Jun 19, 2024
a656bb6
Specify target for inaccessible-temp-dir rmake test
Hoverbear Jun 19, 2024
108b3f2
Properly gate `safe` keyword in pre-expansion
compiler-errors Jun 20, 2024
bc12972
Slightly refactor the dumping of HIR analysis data
fmease Jun 19, 2024
9092473
Add `#[rustc_dump_{predicates,item_bounds}]`
fmease Jun 19, 2024
cdf9a41
Rollup merge of #125627 - vincenzopalazzo:macros/cargo-fix-expr2024, …
matthiaskrgr Jun 20, 2024
a8d641f
Rollup merge of #126481 - ChrisDenton:powerpc-unkown-openbsd, r=ehuss
matthiaskrgr Jun 20, 2024
5376a54
Rollup merge of #126613 - tgross35:log-test-update, r=cuviper
matthiaskrgr Jun 20, 2024
651ed0f
Rollup merge of #126617 - sayantn:veorq, r=workingjubilee
matthiaskrgr Jun 20, 2024
2700fc8
Rollup merge of #126686 - fmease:dump-preds-n-item-bounds, r=compiler…
matthiaskrgr Jun 20, 2024
250a3e5
Rollup merge of #126700 - compiler-errors:fragment, r=fmease
matthiaskrgr Jun 20, 2024
6e624ff
Rollup merge of #126707 - ferrocene:hoverbear/fix-inaccessible-temp-d…
matthiaskrgr Jun 20, 2024
3319aae
Rollup merge of #126757 - compiler-errors:safe, r=spastorino
matthiaskrgr Jun 20, 2024
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
19 changes: 14 additions & 5 deletions compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,11 @@ pub enum NonterminalKind {
PatWithOr,
Expr,
/// Matches an expression using the rules from edition 2021 and earlier.
Expr2021,
Expr2021 {
/// Keep track of whether the user used `:expr` or `:expr_2021` and we inferred it from the
/// edition of the span. This is used for diagnostics AND feature gating.
inferred: bool,
},
Ty,
Ident,
Lifetime,
Expand Down Expand Up @@ -929,8 +933,13 @@ impl NonterminalKind {
Edition::Edition2021 | Edition::Edition2024 => NonterminalKind::PatWithOr,
},
sym::pat_param => NonterminalKind::PatParam { inferred: false },
sym::expr => NonterminalKind::Expr,
sym::expr_2021 if edition().at_least_rust_2021() => NonterminalKind::Expr2021,
sym::expr => match edition() {
Edition::Edition2015 | Edition::Edition2018 | Edition::Edition2021 => {
NonterminalKind::Expr2021 { inferred: true }
}
Edition::Edition2024 => NonterminalKind::Expr,
},
sym::expr_2021 => NonterminalKind::Expr2021 { inferred: false },
sym::ty => NonterminalKind::Ty,
sym::ident => NonterminalKind::Ident,
sym::lifetime => NonterminalKind::Lifetime,
Expand All @@ -949,8 +958,8 @@ impl NonterminalKind {
NonterminalKind::Stmt => sym::stmt,
NonterminalKind::PatParam { inferred: false } => sym::pat_param,
NonterminalKind::PatParam { inferred: true } | NonterminalKind::PatWithOr => sym::pat,
NonterminalKind::Expr => sym::expr,
NonterminalKind::Expr2021 => sym::expr_2021,
NonterminalKind::Expr | NonterminalKind::Expr2021 { inferred: true } => sym::expr,
NonterminalKind::Expr2021 { inferred: false } => sym::expr_2021,
NonterminalKind::Ty => sym::ty,
NonterminalKind::Ident => sym::ident,
NonterminalKind::Lifetime => sym::lifetime,
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,10 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
gate_all!(precise_capturing, "precise captures on `impl Trait` are experimental");
gate_all!(global_registration, "global registration is experimental");
gate_all!(unsafe_attributes, "`#[unsafe()]` markers for attributes are experimental");
gate_all!(
unsafe_extern_blocks,
"`unsafe extern {}` blocks and `safe` keyword are experimental"
);

if !visitor.features.never_patterns {
if let Some(spans) = spans.get(&sym::never_patterns) {
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,9 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow {
// maintain
IsInFollow::Yes
}
NonterminalKind::Stmt | NonterminalKind::Expr | NonterminalKind::Expr2021 => {
NonterminalKind::Stmt
| NonterminalKind::Expr
| NonterminalKind::Expr2021 { inferred: _ } => {
const TOKENS: &[&str] = &["`=>`", "`,`", "`;`"];
match tok {
TokenTree::Token(token) => match token.kind {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_expand/src/mbe/quoted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ pub(super) fn parse(
);
token::NonterminalKind::Ident
});
if kind == token::NonterminalKind::Expr2021
if kind
== (token::NonterminalKind::Expr2021 { inferred: false })
&& !features.expr_fragment_specifier_2024
{
rustc_session::parse::feature_err(
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,14 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
ErrorFollowing, EncodeCrossCrate::No,
"the `#[custom_mir]` attribute is just used for the Rust test suite",
),
rustc_attr!(
TEST, rustc_dump_item_bounds, Normal, template!(Word),
WarnFollowing, EncodeCrossCrate::No
),
rustc_attr!(
TEST, rustc_dump_predicates, Normal, template!(Word),
WarnFollowing, EncodeCrossCrate::No
),
rustc_attr!(
TEST, rustc_object_lifetime_default, Normal, template!(Word),
WarnFollowing, EncodeCrossCrate::No
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ hir_analysis_ty_param_some = type parameter `{$param}` must be used as the type
.note = implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
.only_note = only traits defined in the current crate can be implemented for a type parameter

hir_analysis_type_of = {$type_of}
hir_analysis_type_of = {$ty}

hir_analysis_typeof_reserved_keyword_used =
`typeof` is a reserved keyword but unimplemented
Expand Down Expand Up @@ -566,7 +566,7 @@ hir_analysis_value_of_associated_struct_already_specified =
hir_analysis_variadic_function_compatible_convention = C-variadic function must have a compatible calling convention, like {$conventions}
.label = C-variadic function must have a compatible calling convention

hir_analysis_variances_of = {$variances_of}
hir_analysis_variances_of = {$variances}

hir_analysis_where_clause_on_main = `main` function is not allowed to have a `where` clause
.label = `main` cannot have a `where` clause
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 @@ -45,8 +45,8 @@ use std::ops::Bound;
use crate::check::intrinsic::intrinsic_operation_unsafety;
use crate::errors;
use crate::hir_ty_lowering::{HirTyLowerer, RegionInferReason};
pub use type_of::test_opaque_hidden_types;

pub(crate) mod dump;
mod generics_of;
mod item_bounds;
mod predicates_of;
Expand Down
43 changes: 43 additions & 0 deletions compiler/rustc_hir_analysis/src/collect/dump.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use rustc_hir::def::DefKind;
use rustc_hir::def_id::CRATE_DEF_ID;
use rustc_middle::ty::TyCtxt;
use rustc_span::sym;

pub(crate) fn opaque_hidden_types(tcx: TyCtxt<'_>) {
if !tcx.has_attr(CRATE_DEF_ID, sym::rustc_hidden_type_of_opaques) {
return;
}

for id in tcx.hir().items() {
let DefKind::OpaqueTy = tcx.def_kind(id.owner_id) else { continue };

let ty = tcx.type_of(id.owner_id).instantiate_identity();

tcx.dcx().emit_err(crate::errors::TypeOf { span: tcx.def_span(id.owner_id), ty });
}
}

pub(crate) fn predicates_and_item_bounds(tcx: TyCtxt<'_>) {
for id in tcx.hir_crate_items(()).owners() {
if tcx.has_attr(id, sym::rustc_dump_predicates) {
let preds = tcx.predicates_of(id).instantiate_identity(tcx).predicates;
let span = tcx.def_span(id);

let mut diag = tcx.dcx().struct_span_err(span, sym::rustc_dump_predicates.as_str());
for pred in preds {
diag.note(format!("{pred:?}"));
}
diag.emit();
}
if tcx.has_attr(id, sym::rustc_dump_item_bounds) {
let bounds = tcx.item_bounds(id).instantiate_identity();
let span = tcx.def_span(id);

let mut diag = tcx.dcx().struct_span_err(span, sym::rustc_dump_item_bounds.as_str());
for bound in bounds {
diag.note(format!("{bound:?}"));
}
diag.emit();
}
}
}
1 change: 0 additions & 1 deletion compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::errors::TypeofReservedKeywordUsed;

use super::bad_placeholder;
use super::ItemCtxt;
pub use opaque::test_opaque_hidden_types;

mod opaque;

Expand Down
20 changes: 3 additions & 17 deletions compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
use rustc_errors::StashKey;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{self as hir, def, Expr, ImplItem, Item, Node, TraitItem};
use rustc_middle::bug;
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP};
use rustc_span::DUMMY_SP;

use crate::errors::{TaitForwardCompat, TaitForwardCompat2, TypeOf, UnconstrainedOpaqueType};

pub fn test_opaque_hidden_types(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
let mut res = Ok(());
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_hidden_type_of_opaques) {
for id in tcx.hir().items() {
if matches!(tcx.def_kind(id.owner_id), DefKind::OpaqueTy) {
let type_of = tcx.type_of(id.owner_id).instantiate_identity();

res = Err(tcx.dcx().emit_err(TypeOf { span: tcx.def_span(id.owner_id), type_of }));
}
}
}
res
}
use crate::errors::{TaitForwardCompat, TaitForwardCompat2, UnconstrainedOpaqueType};

/// Checks "defining uses" of opaque `impl Trait` in associated types.
/// These can only be defined by associated items of the same trait.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,15 +682,15 @@ pub(crate) enum CannotCaptureLateBound {
pub(crate) struct VariancesOf {
#[primary_span]
pub span: Span,
pub variances_of: String,
pub variances: String,
}

#[derive(Diagnostic)]
#[diag(hir_analysis_type_of)]
pub(crate) struct TypeOf<'tcx> {
#[primary_span]
pub span: Span,
pub type_of: Ty<'tcx>,
pub ty: Ty<'tcx>,
}

#[derive(Diagnostic)]
Expand Down
13 changes: 4 additions & 9 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ pub fn provide(providers: &mut Providers) {
pub fn check_crate(tcx: TyCtxt<'_>) {
let _prof_timer = tcx.sess.timer("type_check_crate");

if tcx.features().rustc_attrs {
let _ = tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx));
}

tcx.sess.time("coherence_checking", || {
tcx.hir().par_for_each_module(|module| {
let _ = tcx.ensure().check_mod_type_wf(module);
Expand All @@ -169,11 +165,10 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
});

if tcx.features().rustc_attrs {
let _ = tcx.sess.time("variance_testing", || variance::test::test_variance(tcx));
}

if tcx.features().rustc_attrs {
let _ = collect::test_opaque_hidden_types(tcx);
tcx.sess.time("outlives_dumping", || outlives::dump::inferred_outlives(tcx));
tcx.sess.time("variance_dumping", || variance::dump::variances(tcx));
collect::dump::opaque_hidden_types(tcx);
collect::dump::predicates_and_item_bounds(tcx);
}

// Make sure we evaluate all static and (non-associated) const items, even if unused.
Expand Down
29 changes: 29 additions & 0 deletions compiler/rustc_hir_analysis/src/outlives/dump.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use rustc_middle::bug;
use rustc_middle::ty::{self, TyCtxt};
use rustc_span::sym;

pub(crate) fn inferred_outlives(tcx: TyCtxt<'_>) {
for id in tcx.hir().items() {
if !tcx.has_attr(id.owner_id, sym::rustc_outlives) {
continue;
}

let preds = tcx.inferred_outlives_of(id.owner_id);
let mut preds: Vec<_> = preds
.iter()
.map(|(pred, _)| match pred.kind().skip_binder() {
ty::ClauseKind::RegionOutlives(p) => p.to_string(),
ty::ClauseKind::TypeOutlives(p) => p.to_string(),
err => bug!("unexpected clause {:?}", err),
})
.collect();
preds.sort();

let span = tcx.def_span(id.owner_id);
let mut err = tcx.dcx().struct_span_err(span, sym::rustc_outlives.as_str());
for pred in preds {
err.note(pred);
}
err.emit();
}
}
3 changes: 1 addition & 2 deletions compiler/rustc_hir_analysis/src/outlives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use rustc_middle::ty::GenericArgKind;
use rustc_middle::ty::{self, CratePredicatesMap, TyCtxt, Upcast};
use rustc_span::Span;

pub(crate) mod dump;
mod explicit;
mod implicit_infer;
/// Code to write unit test for outlives.
pub mod test;
mod utils;

pub fn provide(providers: &mut Providers) {
Expand Down
31 changes: 0 additions & 31 deletions compiler/rustc_hir_analysis/src/outlives/test.rs

This file was deleted.

32 changes: 32 additions & 0 deletions compiler/rustc_hir_analysis/src/variance/dump.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use rustc_hir::def::DefKind;
use rustc_hir::def_id::CRATE_DEF_ID;
use rustc_middle::ty::TyCtxt;
use rustc_span::symbol::sym;

pub(crate) fn variances(tcx: TyCtxt<'_>) {
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_variance_of_opaques) {
for id in tcx.hir().items() {
let DefKind::OpaqueTy = tcx.def_kind(id.owner_id) else { continue };

let variances = tcx.variances_of(id.owner_id);

tcx.dcx().emit_err(crate::errors::VariancesOf {
span: tcx.def_span(id.owner_id),
variances: format!("{variances:?}"),
});
}
}

for id in tcx.hir().items() {
if !tcx.has_attr(id.owner_id, sym::rustc_variance) {
continue;
}

let variances = tcx.variances_of(id.owner_id);

tcx.dcx().emit_err(crate::errors::VariancesOf {
span: tcx.def_span(id.owner_id),
variances: format!("{variances:?}"),
});
}
}
3 changes: 1 addition & 2 deletions compiler/rustc_hir_analysis/src/variance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ mod constraints;
/// Code to solve constraints and write out the results.
mod solve;

/// Code to write unit tests of variance.
pub mod test;
pub(crate) mod dump;

/// Code for transforming variances.
mod xform;
Expand Down
37 changes: 0 additions & 37 deletions compiler/rustc_hir_analysis/src/variance/test.rs

This file was deleted.

Loading
Loading