Skip to content

Commit 5f58737

Browse files
authored
Merge branch 'main' into generic_anon_consts
2 parents 2e3b70d + a962594 commit 5f58737

417 files changed

Lines changed: 7180 additions & 2172 deletions

File tree

Some content is hidden

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

Cargo.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4010,9 +4010,7 @@ dependencies = [
40104010
name = "rustc_feature"
40114011
version = "0.0.0"
40124012
dependencies = [
4013-
"rustc_ast",
40144013
"rustc_data_structures",
4015-
"rustc_hir",
40164014
"rustc_span",
40174015
"serde",
40184016
"serde_json",

compiler/rustc_ast_lowering/src/diagnostics.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ pub(crate) struct AwaitOnlyInAsyncFnAndBlocks {
122122
pub item_span: Option<Span>,
123123
}
124124

125+
#[derive(Diagnostic)]
126+
#[diag("a function cannot be both `comptime` and `const`")]
127+
pub(crate) struct ConstComptimeFn {
128+
#[primary_span]
129+
#[suggestion("remove the `const`", applicability = "machine-applicable", code = "")]
130+
#[note("`const` implies the function can be called at runtime, too")]
131+
pub span: Span,
132+
#[label("`comptime` because of this")]
133+
pub attr_span: Span,
134+
}
135+
125136
#[derive(Diagnostic)]
126137
#[diag("too many parameters for a coroutine (expected 0 or 1 parameters)", code = E0628)]
127138
pub(crate) struct CoroutineTooManyParameters {

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use super::{
2727
AstOwner, FnDeclKind, GenericArgsMode, ImplTraitContext, ImplTraitPosition, LoweringContext,
2828
ParamMode, RelaxedBoundForbiddenReason, RelaxedBoundPolicy, ResolverAstLoweringExt,
2929
};
30+
use crate::diagnostics::ConstComptimeFn;
3031

3132
/// Wraps either IndexVec (during `hir_crate`), which acts like a primary
3233
/// storage for most of the MaybeOwners, or FxIndexMap during delayed AST -> HIR
@@ -1773,12 +1774,23 @@ impl<'hir> LoweringContext<'_, 'hir> {
17731774
safety.into()
17741775
};
17751776

1776-
hir::FnHeader {
1777-
safety,
1778-
asyncness,
1779-
constness: self.lower_constness(h.constness),
1780-
abi: self.lower_extern(h.ext),
1777+
let mut constness = self.lower_constness(h.constness);
1778+
if let Some(&attr_span) = find_attr!(attrs, RustcComptime(span) => span) {
1779+
match std::mem::replace(&mut constness, rustc_hir::Constness::Const { always: true }) {
1780+
rustc_hir::Constness::Const { always: true } => {
1781+
unreachable!("lower_constness cannot produce comptime")
1782+
}
1783+
// A function can't be `const` and `comptime` at the same time
1784+
rustc_hir::Constness::Const { always: false } => {
1785+
let Const::Yes(span) = h.constness else { unreachable!() };
1786+
self.dcx().emit_err(ConstComptimeFn { span, attr_span });
1787+
}
1788+
// Good
1789+
rustc_hir::Constness::NotConst => {}
1790+
}
17811791
}
1792+
1793+
hir::FnHeader { safety, asyncness, constness, abi: self.lower_extern(h.ext) }
17821794
}
17831795

17841796
pub(super) fn lower_abi(&mut self, abi_str: StrLit) -> ExternAbi {
@@ -1840,7 +1852,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18401852

18411853
pub(super) fn lower_constness(&mut self, c: Const) -> hir::Constness {
18421854
match c {
1843-
Const::Yes(_) => hir::Constness::Const,
1855+
Const::Yes(_) => hir::Constness::Const { always: false },
18441856
Const::No => hir::Constness::NotConst,
18451857
}
18461858
}

compiler/rustc_attr_parsing/src/attributes/autodiff.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::str::FromStr;
22

33
use rustc_ast::LitKind;
44
use rustc_ast::expand::autodiff_attrs::{DiffActivity, DiffMode};
5-
use rustc_feature::{AttributeStability, AttributeTemplate, template};
5+
use rustc_feature::AttributeStability;
66
use rustc_hir::attrs::{AttributeKind, RustcAutodiff};
77
use rustc_hir::{MethodKind, Target};
88
use rustc_span::{Symbol, sym};
@@ -13,7 +13,7 @@ use crate::attributes::prelude::Allow;
1313
use crate::context::AcceptContext;
1414
use crate::parser::{ArgParser, MetaItemOrLitParser};
1515
use crate::target_checking::AllowedTargets;
16-
use crate::unstable;
16+
use crate::{AttributeTemplate, template, unstable};
1717

1818
pub(crate) struct RustcAutodiffParser;
1919

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use rustc_ast::token::Delimiter;
44
use rustc_ast::tokenstream::DelimSpan;
55
use rustc_ast::{AttrItem, Attribute, LitKind, ast, token};
66
use rustc_errors::{Applicability, Diagnostic, PResult, msg};
7-
use rustc_feature::{
8-
AttrSuggestionStyle, AttributeTemplate, Features, GatedCfg, find_gated_cfg, template,
9-
};
7+
use rustc_feature::{Features, GatedCfg, find_gated_cfg};
108
use rustc_hir::attrs::CfgEntry;
119
use rustc_hir::{AttrPath, RustcVersion, Target};
1210
use rustc_parse::parser::{ForceCollect, Parser, Recovery};
@@ -28,7 +26,10 @@ use crate::session_diagnostics::{
2826
AttributeParseError, AttributeParseErrorReason, CfgAttrBadDelim, MetaBadDelimSugg,
2927
ParsedDescription,
3028
};
31-
use crate::{AttributeParser, check_cfg, parse_version, session_diagnostics};
29+
use crate::{
30+
AttrSuggestionStyle, AttributeParser, AttributeTemplate, check_cfg, parse_version,
31+
session_diagnostics, template,
32+
};
3233

3334
pub const CFG_TEMPLATE: AttributeTemplate = template!(
3435
List: &["predicate"],

compiler/rustc_attr_parsing/src/attributes/cfg_select.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_ast::tokenstream::TokenStream;
33
use rustc_ast::{AttrStyle, NodeId, token};
44
use rustc_data_structures::fx::FxHashMap;
55
use rustc_errors::{Diagnostic, MultiSpan};
6-
use rustc_feature::{AttributeTemplate, Features};
6+
use rustc_feature::Features;
77
use rustc_hir::attrs::CfgEntry;
88
use rustc_hir::{AttrPath, Target};
99
use rustc_parse::exp;
@@ -14,7 +14,9 @@ use rustc_span::{ErrorGuaranteed, Span, Symbol, sym};
1414

1515
use crate::attributes::AttributeSafety;
1616
use crate::parser::{AllowExprMetavar, MetaItemOrLitParser};
17-
use crate::{AttributeParser, ParsedDescription, ShouldEmit, errors, parse_cfg_entry};
17+
use crate::{
18+
AttributeParser, AttributeTemplate, ParsedDescription, ShouldEmit, diagnostics, parse_cfg_entry,
19+
};
1820

1921
#[derive(Clone)]
2022
pub enum CfgSelectPredicate {
@@ -189,10 +191,10 @@ fn lint_unreachable(
189191
lint_node_id,
190192
move |dcx, level| match wildcard_span {
191193
Some(wildcard_span) => {
192-
errors::UnreachableCfgSelectPredicateWildcard { span, wildcard_span }
194+
diagnostics::UnreachableCfgSelectPredicateWildcard { span, wildcard_span }
193195
.into_diag(dcx, level)
194196
}
195-
None => errors::UnreachableCfgSelectPredicate { span }.into_diag(dcx, level),
197+
None => diagnostics::UnreachableCfgSelectPredicate { span }.into_diag(dcx, level),
196198
},
197199
);
198200
};

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_span::Symbol;
55
use rustc_span::edit_distance::find_best_match_for_name;
66

77
use super::prelude::*;
8-
use crate::errors::{UnknownCrateTypes, UnknownCrateTypesSuggestion};
8+
use crate::diagnostics::{UnknownCrateTypes, UnknownCrateTypesSuggestion};
99

1010
pub(crate) struct CrateNameParser;
1111

compiler/rustc_attr_parsing/src/attributes/diagnostic/do_not_recommend.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_feature::{AttributeStability, AttributeTemplate, template};
1+
use rustc_feature::AttributeStability;
22
use rustc_hir::Target;
33
use rustc_hir::attrs::AttributeKind;
44
use rustc_session::lint::builtin::{
@@ -8,9 +8,10 @@ use rustc_span::{Symbol, sym};
88

99
use crate::attributes::{OnDuplicate, SingleAttributeParser};
1010
use crate::context::AcceptContext;
11-
use crate::errors::IncorrectDoNotRecommendLocation;
11+
use crate::diagnostics::IncorrectDoNotRecommendLocation;
1212
use crate::parser::ArgParser;
1313
use crate::target_checking::{ALL_TARGETS, AllowedTargets};
14+
use crate::{AttributeTemplate, template};
1415

1516
pub(crate) struct DoNotRecommendParser;
1617
impl SingleAttributeParser for DoNotRecommendParser {
@@ -26,7 +27,7 @@ impl SingleAttributeParser for DoNotRecommendParser {
2627
if !matches!(args, ArgParser::NoArgs) {
2728
cx.emit_lint(
2829
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
29-
crate::errors::DoNotRecommendDoesNotExpectArgs,
30+
crate::diagnostics::DoNotRecommendDoesNotExpectArgs,
3031
attr_span,
3132
);
3233
}

compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
use std::ops::Range;
22

3-
use rustc_errors::E0232;
4-
use rustc_hir::AttrPath;
53
use rustc_hir::attrs::diagnostic::{
64
Directive, Filter, FilterFormatString, Flag, FormatArg, FormatString, LitOrArg, Name,
75
NameValue, Piece, Predicate,
86
};
9-
use rustc_macros::Diagnostic;
107
use rustc_parse_format::{
118
Argument, FormatSpec, ParseError, ParseMode, Parser, Piece as RpfPiece, Position,
129
};
@@ -17,9 +14,10 @@ use rustc_span::{Ident, InnerSpan, Span, Symbol, kw, sym};
1714
use thin_vec::{ThinVec, thin_vec};
1815

1916
use crate::context::AcceptContext;
20-
use crate::errors::{
21-
FormatWarning, IgnoredDiagnosticOption, MalFormedDiagnosticAttributeLint,
22-
MissingOptionsForDiagnosticAttribute, NonMetaItemDiagnosticAttribute, WrappedParserError,
17+
use crate::diagnostics::{
18+
DupesNotAllowed, FormatWarning, IgnoredDiagnosticOption, InvalidOnClause,
19+
MalFormedDiagnosticAttributeLint, MissingOptionsForDiagnosticAttribute,
20+
NonMetaItemDiagnosticAttribute, WrappedParserError,
2321
};
2422
use crate::parser::{ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser};
2523

@@ -611,54 +609,3 @@ fn parse_filter_format(input: Symbol) -> FilterFormatString {
611609
.collect();
612610
FilterFormatString { pieces }
613611
}
614-
615-
#[derive(Diagnostic)]
616-
pub(crate) enum InvalidOnClause {
617-
#[diag("empty `on`-clause in `#[rustc_on_unimplemented]`", code = E0232)]
618-
Empty {
619-
#[primary_span]
620-
#[label("empty `on`-clause here")]
621-
span: Span,
622-
},
623-
#[diag("expected a single predicate in `not(..)`", code = E0232)]
624-
ExpectedOnePredInNot {
625-
#[primary_span]
626-
#[label("unexpected quantity of predicates here")]
627-
span: Span,
628-
},
629-
#[diag("literals inside `on`-clauses are not supported", code = E0232)]
630-
UnsupportedLiteral {
631-
#[primary_span]
632-
#[label("unexpected literal here")]
633-
span: Span,
634-
},
635-
#[diag("expected an identifier inside this `on`-clause", code = E0232)]
636-
ExpectedIdentifier {
637-
#[primary_span]
638-
#[label("expected an identifier here, not `{$path}`")]
639-
span: Span,
640-
path: AttrPath,
641-
},
642-
#[diag("this predicate is invalid", code = E0232)]
643-
InvalidPredicate {
644-
#[primary_span]
645-
#[label("expected one of `any`, `all` or `not` here, not `{$invalid_pred}`")]
646-
span: Span,
647-
invalid_pred: Symbol,
648-
},
649-
#[diag("invalid flag in `on`-clause", code = E0232)]
650-
InvalidFlag {
651-
#[primary_span]
652-
#[label(
653-
"expected one of the `crate_local`, `direct` or `from_desugaring` flags, not `{$invalid_flag}`"
654-
)]
655-
span: Span,
656-
invalid_flag: Symbol,
657-
},
658-
}
659-
660-
#[derive(Diagnostic)]
661-
#[diag(
662-
"using multiple `rustc_on_unimplemented` (or mixing it with `diagnostic::on_unimplemented`) is not supported"
663-
)]
664-
pub(crate) struct DupesNotAllowed;

compiler/rustc_attr_parsing/src/attributes/diagnostic/on_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_session::lint::builtin::MISPLACED_DIAGNOSTIC_ATTRIBUTES;
44

55
use crate::attributes::diagnostic::*;
66
use crate::attributes::prelude::*;
7-
use crate::errors::DiagnosticOnConstOnlyForTraitImpls;
7+
use crate::diagnostics::DiagnosticOnConstOnlyForTraitImpls;
88
#[derive(Default)]
99
pub(crate) struct OnConstParser {
1010
span: Option<Span>,

0 commit comments

Comments
 (0)