Skip to content

Commit 48ece81

Browse files
committed
Auto merge of #155885 - JonathanBrouwer:rollup-BNIchAQ, r=JonathanBrouwer
Rollup of 9 pull requests Successful merges: - #155760 (Remove `AttributeLintKind`) - #154510 (Partially stabilize LoongArch target features) - #155137 (Allow trailing `self` in more contexts) - #155433 (Rip out rustc_layout_scalar_valid_range_* attribute support) - #155702 (Change `ItemKind::Trait` to a field variant.) - #154896 (Fix ICE: Scalar layout for non-primitive non-enum type unsafe binder) - #155675 (Disallow non_exhaustive structs and enums with non_exhaustive variants from implementing `ConstParamTy`) - #155874 (Avoid misleading closure return type note) - #155876 (CI: rfl: move job forward to Linux v7.1-rc1)
2 parents 345a975 + 22c3c2a commit 48ece81

191 files changed

Lines changed: 2460 additions & 4325 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.

compiler/rustc_abi/src/layout.rs

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::BTreeSet;
22
use std::fmt::{self, Write};
3-
use std::ops::{Bound, Deref};
3+
use std::ops::Deref;
44
use std::{cmp, iter};
55

66
use rustc_hashes::Hash64;
@@ -348,7 +348,6 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
348348
variants: &IndexSlice<VariantIdx, IndexVec<FieldIdx, F>>,
349349
is_enum: bool,
350350
is_special_no_niche: bool,
351-
scalar_valid_range: (Bound<u128>, Bound<u128>),
352351
discr_range_of_repr: impl Fn(i128, i128) -> (Integer, bool),
353352
discriminants: impl Iterator<Item = (VariantIdx, i128)>,
354353
always_sized: bool,
@@ -380,7 +379,6 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
380379
variants,
381380
is_enum,
382381
is_special_no_niche,
383-
scalar_valid_range,
384382
always_sized,
385383
present_first,
386384
)
@@ -530,7 +528,6 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
530528
variants: &IndexSlice<VariantIdx, IndexVec<FieldIdx, F>>,
531529
is_enum: bool,
532530
is_special_no_niche: bool,
533-
scalar_valid_range: (Bound<u128>, Bound<u128>),
534531
always_sized: bool,
535532
present_first: VariantIdx,
536533
) -> LayoutCalculatorResult<FieldIdx, VariantIdx, F> {
@@ -570,52 +567,6 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
570567
return Ok(st);
571568
}
572569

573-
let (start, end) = scalar_valid_range;
574-
match st.backend_repr {
575-
BackendRepr::Scalar(ref mut scalar) | BackendRepr::ScalarPair(ref mut scalar, _) => {
576-
// Enlarging validity ranges would result in missed
577-
// optimizations, *not* wrongly assuming the inner
578-
// value is valid. e.g. unions already enlarge validity ranges,
579-
// because the values may be uninitialized.
580-
//
581-
// Because of that we only check that the start and end
582-
// of the range is representable with this scalar type.
583-
584-
let max_value = scalar.size(dl).unsigned_int_max();
585-
if let Bound::Included(start) = start {
586-
// FIXME(eddyb) this might be incorrect - it doesn't
587-
// account for wrap-around (end < start) ranges.
588-
assert!(start <= max_value, "{start} > {max_value}");
589-
scalar.valid_range_mut().start = start;
590-
}
591-
if let Bound::Included(end) = end {
592-
// FIXME(eddyb) this might be incorrect - it doesn't
593-
// account for wrap-around (end < start) ranges.
594-
assert!(end <= max_value, "{end} > {max_value}");
595-
scalar.valid_range_mut().end = end;
596-
}
597-
598-
// Update `largest_niche` if we have introduced a larger niche.
599-
let niche = Niche::from_scalar(dl, Size::ZERO, *scalar);
600-
if let Some(niche) = niche {
601-
match st.largest_niche {
602-
Some(largest_niche) => {
603-
// Replace the existing niche even if they're equal,
604-
// because this one is at a lower offset.
605-
if largest_niche.available(dl) <= niche.available(dl) {
606-
st.largest_niche = Some(niche);
607-
}
608-
}
609-
None => st.largest_niche = Some(niche),
610-
}
611-
}
612-
}
613-
_ => assert!(
614-
start == Bound::Unbounded && end == Bound::Unbounded,
615-
"nonscalar layout for layout_scalar_valid_range type: {st:#?}",
616-
),
617-
}
618-
619570
Ok(st)
620571
}
621572

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,16 +569,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
569569
(safety, items, bounds)
570570
},
571571
);
572-
hir::ItemKind::Trait(
572+
hir::ItemKind::Trait {
573573
impl_restriction,
574574
constness,
575-
*is_auto,
575+
is_auto: *is_auto,
576576
safety,
577577
ident,
578578
generics,
579579
bounds,
580580
items,
581-
)
581+
}
582582
}
583583
ItemKind::TraitAlias(box TraitAlias { constness, ident, generics, bounds }) => {
584584
let constness = self.lower_constness(*constness);

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use std::sync::Arc;
4141
use rustc_ast::node_id::NodeMap;
4242
use rustc_ast::visit::Visitor;
4343
use rustc_ast::{self as ast, *};
44-
use rustc_attr_parsing::{AttributeParser, EmitAttribute, Late, OmitDoc};
44+
use rustc_attr_parsing::{AttributeParser, Late, OmitDoc};
4545
use rustc_data_structures::fingerprint::Fingerprint;
4646
use rustc_data_structures::fx::FxIndexSet;
4747
use rustc_data_structures::sorted_map::SortedMap;
@@ -52,7 +52,7 @@ use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle};
5252
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
5353
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId};
5454
use rustc_hir::definitions::PerParentDisambiguatorState;
55-
use rustc_hir::lints::{AttributeLint, DelayedLint, DynAttribute};
55+
use rustc_hir::lints::DelayedLint;
5656
use rustc_hir::{
5757
self as hir, AngleBrackets, ConstArg, GenericArg, HirId, ItemLocalMap, LifetimeSource,
5858
LifetimeSyntax, ParamName, Target, TraitCandidate, find_attr,
@@ -1096,23 +1096,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
10961096
target,
10971097
OmitDoc::Lower,
10981098
|s| l.lower(s),
1099-
|lint_id, span, kind| match kind {
1100-
EmitAttribute::Static(attr_kind) => {
1101-
self.delayed_lints.push(DelayedLint::AttributeParsing(AttributeLint {
1102-
lint_id,
1103-
id: target_hir_id,
1104-
span,
1105-
kind: attr_kind,
1106-
}));
1107-
}
1108-
EmitAttribute::Dynamic(callback) => {
1109-
self.delayed_lints.push(DelayedLint::Dynamic(DynAttribute {
1110-
lint_id,
1111-
id: target_hir_id,
1112-
span,
1113-
callback,
1114-
}));
1115-
}
1099+
|lint_id, span, kind| {
1100+
self.delayed_lints.push(DelayedLint {
1101+
lint_id,
1102+
id: target_hir_id,
1103+
span,
1104+
callback: Box::new(move |dcx, level, sess: &dyn std::any::Any| {
1105+
let sess = sess
1106+
.downcast_ref::<rustc_session::Session>()
1107+
.expect("expected `Session`");
1108+
(kind.0)(dcx, level, sess)
1109+
}),
1110+
});
11161111
},
11171112
)
11181113
}

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ use std::convert::identity;
33
use rustc_ast::token::Delimiter;
44
use rustc_ast::tokenstream::DelimSpan;
55
use rustc_ast::{AttrItem, Attribute, LitKind, ast, token};
6-
use rustc_errors::{Applicability, PResult, msg};
6+
use rustc_errors::{Applicability, Diagnostic, PResult, msg};
77
use rustc_feature::{
88
AttrSuggestionStyle, AttributeTemplate, Features, GatedCfg, find_gated_cfg, template,
99
};
1010
use rustc_hir::attrs::CfgEntry;
11-
use rustc_hir::lints::AttributeLintKind;
1211
use rustc_hir::{AttrPath, RustcVersion, Target};
1312
use rustc_parse::parser::{ForceCollect, Parser, Recovery};
1413
use rustc_parse::{exp, parse_in};
@@ -20,6 +19,7 @@ use rustc_span::{ErrorGuaranteed, Span, Symbol, sym};
2019
use thin_vec::ThinVec;
2120

2221
use crate::attributes::AttributeSafety;
22+
use crate::attributes::diagnostic::check_cfg;
2323
use crate::context::{AcceptContext, ShouldEmit, Stage};
2424
use crate::parser::{
2525
AllowExprMetavar, ArgParser, MetaItemListParser, MetaItemOrLitParser, NameValueParser,
@@ -224,14 +224,19 @@ pub(crate) fn parse_name_value<S: Stage>(
224224

225225
match cx.sess.psess.check_config.expecteds.get(&name) {
226226
Some(ExpectedValues::Some(values)) if !values.contains(&value.map(|(v, _)| v)) => cx
227-
.emit_lint(
227+
.emit_dyn_lint_with_sess(
228228
UNEXPECTED_CFGS,
229-
AttributeLintKind::UnexpectedCfgValue((name, name_span), value),
229+
move |dcx, level, sess| {
230+
check_cfg::unexpected_cfg_value(sess, (name, name_span), value)
231+
.into_diag(dcx, level)
232+
},
230233
span,
231234
),
232-
None if cx.sess.psess.check_config.exhaustive_names => cx.emit_lint(
235+
None if cx.sess.psess.check_config.exhaustive_names => cx.emit_dyn_lint_with_sess(
233236
UNEXPECTED_CFGS,
234-
AttributeLintKind::UnexpectedCfgName((name, name_span), value),
237+
move |dcx, level, sess| {
238+
check_cfg::unexpected_cfg_name(sess, (name, name_span), value).into_diag(dcx, level)
239+
},
235240
span,
236241
),
237242
_ => { /* not unexpected */ }

0 commit comments

Comments
 (0)