Skip to content

Commit eac3558

Browse files
committed
Auto merge of #111174 - matthiaskrgr:rollup-ncnqivh, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #110859 (Explicitly reject negative and reservation drop impls) - #111020 (Validate resolution for SelfCtor too.) - #111024 (Use the full Fingerprint when stringifying Svh) - #111027 (Remove `allow(rustc::potential_query_instability)` for `builtin_macros`) - #111039 (Encode def span for foreign return-position `impl Trait` in trait) - #111070 (Don't suffix `RibKind` variants) - #111094 (Add needs-unwind annotations to tests that need stack unwinding) - #111103 (correctly recurse when expanding anon consts) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6f8c055 + b4d992f commit eac3558

File tree

43 files changed

+326
-182
lines changed

Some content is hidden

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

43 files changed

+326
-182
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3165,6 +3165,7 @@ dependencies = [
31653165
"rustc_expand",
31663166
"rustc_feature",
31673167
"rustc_fluent_macro",
3168+
"rustc_index",
31683169
"rustc_lexer",
31693170
"rustc_lint_defs",
31703171
"rustc_macros",

compiler/rustc_builtin_macros/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ rustc_data_structures = { path = "../rustc_data_structures" }
1414
rustc_errors = { path = "../rustc_errors" }
1515
rustc_expand = { path = "../rustc_expand" }
1616
rustc_feature = { path = "../rustc_feature" }
17+
rustc_index = { path = "../rustc_index" }
1718
rustc_lexer = { path = "../rustc_lexer" }
1819
rustc_lint_defs = { path = "../rustc_lint_defs" }
1920
rustc_macros = { path = "../rustc_macros" }

compiler/rustc_builtin_macros/src/asm.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use rustc_ast as ast;
22
use rustc_ast::ptr::P;
33
use rustc_ast::token::{self, Delimiter};
44
use rustc_ast::tokenstream::TokenStream;
5-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5+
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
66
use rustc_errors::PResult;
77
use rustc_expand::base::{self, *};
8+
use rustc_index::bit_set::GrowableBitSet;
89
use rustc_parse::parser::Parser;
910
use rustc_parse_format as parse;
1011
use rustc_session::lint;
@@ -20,8 +21,8 @@ use crate::errors;
2021
pub struct AsmArgs {
2122
pub templates: Vec<P<ast::Expr>>,
2223
pub operands: Vec<(ast::InlineAsmOperand, Span)>,
23-
named_args: FxHashMap<Symbol, usize>,
24-
reg_args: FxHashSet<usize>,
24+
named_args: FxIndexMap<Symbol, usize>,
25+
reg_args: GrowableBitSet<usize>,
2526
pub clobber_abis: Vec<(Symbol, Span)>,
2627
options: ast::InlineAsmOptions,
2728
pub options_spans: Vec<Span>,
@@ -56,8 +57,8 @@ pub fn parse_asm_args<'a>(
5657
let mut args = AsmArgs {
5758
templates: vec![first_template],
5859
operands: vec![],
59-
named_args: FxHashMap::default(),
60-
reg_args: FxHashSet::default(),
60+
named_args: Default::default(),
61+
reg_args: Default::default(),
6162
clobber_abis: Vec::new(),
6263
options: ast::InlineAsmOptions::empty(),
6364
options_spans: vec![],
@@ -213,7 +214,7 @@ pub fn parse_asm_args<'a>(
213214
} else {
214215
if !args.named_args.is_empty() || !args.reg_args.is_empty() {
215216
let named = args.named_args.values().map(|p| args.operands[*p].1).collect();
216-
let explicit = args.reg_args.iter().map(|p| args.operands[*p].1).collect();
217+
let explicit = args.reg_args.iter().map(|p| args.operands[p].1).collect();
217218

218219
diag.emit_err(errors::AsmPositionalAfter { span, named, explicit });
219220
}
@@ -446,8 +447,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
446447
// Register operands are implicitly used since they are not allowed to be
447448
// referenced in the template string.
448449
let mut used = vec![false; args.operands.len()];
449-
for pos in &args.reg_args {
450-
used[*pos] = true;
450+
for pos in args.reg_args.iter() {
451+
used[pos] = true;
451452
}
452453
let named_pos: FxHashMap<usize, Symbol> =
453454
args.named_args.iter().map(|(&sym, &idx)| (idx, sym)).collect();
@@ -581,7 +582,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
581582
parse::ArgumentIs(idx) | parse::ArgumentImplicitlyIs(idx) => {
582583
if idx >= args.operands.len()
583584
|| named_pos.contains_key(&idx)
584-
|| args.reg_args.contains(&idx)
585+
|| args.reg_args.contains(idx)
585586
{
586587
let msg = format!("invalid reference to argument at index {}", idx);
587588
let mut err = ecx.struct_span_err(span, &msg);
@@ -608,7 +609,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
608609
args.operands[idx].1,
609610
"named arguments cannot be referenced by position",
610611
);
611-
} else if args.reg_args.contains(&idx) {
612+
} else if args.reg_args.contains(idx) {
612613
err.span_label(
613614
args.operands[idx].1,
614615
"explicit register argument",

compiler/rustc_builtin_macros/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! This crate contains implementations of built-in macros and other code generating facilities
22
//! injecting code into the crate before it is lowered to HIR.
33
4-
#![allow(rustc::potential_query_instability)]
54
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
65
#![feature(array_windows)]
76
#![feature(box_patterns)]

compiler/rustc_data_structures/src/fingerprint.rs

+5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ impl Fingerprint {
6464
)
6565
}
6666

67+
#[inline]
68+
pub(crate) fn as_u128(self) -> u128 {
69+
u128::from(self.1) << 64 | u128::from(self.0)
70+
}
71+
6772
// Combines two hashes in an order independent way. Make sure this is what
6873
// you want.
6974
#[inline]

compiler/rustc_data_structures/src/svh.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ impl Svh {
2323
Svh { hash }
2424
}
2525

26-
pub fn as_u64(&self) -> u64 {
27-
self.hash.to_smaller_hash().as_u64()
26+
pub fn as_u128(self) -> u128 {
27+
self.hash.as_u128()
2828
}
2929

30-
pub fn to_string(&self) -> String {
31-
format!("{:016x}", self.hash.to_smaller_hash())
30+
pub fn to_hex(self) -> String {
31+
format!("{:032x}", self.hash.as_u128())
3232
}
3333
}
3434

3535
impl fmt::Display for Svh {
3636
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37-
f.pad(&self.to_string())
37+
f.pad(&self.to_hex())
3838
}
3939
}
4040

compiler/rustc_hir_analysis/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,7 @@ hir_analysis_const_specialize = cannot specialize on const impl with non-const i
280280
hir_analysis_static_specialize = cannot specialize on `'static` lifetime
281281
282282
hir_analysis_missing_tilde_const = missing `~const` qualifier for specialization
283+
284+
hir_analysis_drop_impl_negative = negative `Drop` impls are not supported
285+
286+
hir_analysis_drop_impl_reservation = reservation `Drop` impls are not supported

compiler/rustc_hir_analysis/src/check/dropck.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
// FIXME(@lcnr): Move this module out of `rustc_hir_analysis`.
22
//
33
// We don't do any drop checking during hir typeck.
4-
use crate::hir::def_id::{DefId, LocalDefId};
54
use rustc_errors::{struct_span_err, ErrorGuaranteed};
65
use rustc_middle::ty::error::TypeError;
76
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
87
use rustc_middle::ty::subst::SubstsRef;
98
use rustc_middle::ty::util::IgnoreRegions;
109
use rustc_middle::ty::{self, Predicate, Ty, TyCtxt};
1110

11+
use crate::errors;
12+
use crate::hir::def_id::{DefId, LocalDefId};
13+
1214
/// This function confirms that the `Drop` implementation identified by
1315
/// `drop_impl_did` is not any more specialized than the type it is
1416
/// attached to (Issue #8142).
@@ -27,6 +29,19 @@ use rustc_middle::ty::{self, Predicate, Ty, TyCtxt};
2729
/// cannot do `struct S<T>; impl<T:Clone> Drop for S<T> { ... }`).
2830
///
2931
pub fn check_drop_impl(tcx: TyCtxt<'_>, drop_impl_did: DefId) -> Result<(), ErrorGuaranteed> {
32+
match tcx.impl_polarity(drop_impl_did) {
33+
ty::ImplPolarity::Positive => {}
34+
ty::ImplPolarity::Negative => {
35+
return Err(tcx.sess.emit_err(errors::DropImplPolarity::Negative {
36+
span: tcx.def_span(drop_impl_did),
37+
}));
38+
}
39+
ty::ImplPolarity::Reservation => {
40+
return Err(tcx.sess.emit_err(errors::DropImplPolarity::Reservation {
41+
span: tcx.def_span(drop_impl_did),
42+
}));
43+
}
44+
}
3045
let dtor_self_type = tcx.type_of(drop_impl_did).subst_identity();
3146
let dtor_predicates = tcx.predicates_of(drop_impl_did);
3247
match dtor_self_type.kind() {

compiler/rustc_hir_analysis/src/errors.rs

+14
Original file line numberDiff line numberDiff line change
@@ -823,3 +823,17 @@ pub(crate) struct MissingTildeConst {
823823
#[primary_span]
824824
pub span: Span,
825825
}
826+
827+
#[derive(Diagnostic)]
828+
pub(crate) enum DropImplPolarity {
829+
#[diag(hir_analysis_drop_impl_negative)]
830+
Negative {
831+
#[primary_span]
832+
span: Span,
833+
},
834+
#[diag(hir_analysis_drop_impl_reservation)]
835+
Reservation {
836+
#[primary_span]
837+
span: Span,
838+
},
839+
}

compiler/rustc_incremental/src/persist/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ pub fn finalize_session_directory(sess: &Session, svh: Option<Svh>) {
346346
let mut new_sub_dir_name = String::from(&old_sub_dir_name[..=dash_indices[2]]);
347347

348348
// Append the svh
349-
base_n::push_str(svh.as_u64() as u128, INT_ENCODE_BASE, &mut new_sub_dir_name);
349+
base_n::push_str(svh.as_u128(), INT_ENCODE_BASE, &mut new_sub_dir_name);
350350

351351
// Create the full path
352352
let new_path = incr_comp_session_dir.parent().unwrap().join(new_sub_dir_name);

compiler/rustc_metadata/src/rmeta/encoder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -837,11 +837,12 @@ fn should_encode_span(def_kind: DefKind) -> bool {
837837
| DefKind::AnonConst
838838
| DefKind::InlineConst
839839
| DefKind::OpaqueTy
840+
| DefKind::ImplTraitPlaceholder
840841
| DefKind::Field
841842
| DefKind::Impl { .. }
842843
| DefKind::Closure
843844
| DefKind::Generator => true,
844-
DefKind::ForeignMod | DefKind::ImplTraitPlaceholder | DefKind::GlobalAsm => false,
845+
DefKind::ForeignMod | DefKind::GlobalAsm => false,
845846
}
846847
}
847848

compiler/rustc_middle/src/ty/abstract_const.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ impl<'tcx> TyCtxt<'tcx> {
6363
Err(e) => self.tcx.const_error_with_guaranteed(c.ty(), e),
6464
Ok(Some(bac)) => {
6565
let substs = self.tcx.erase_regions(uv.substs);
66-
bac.subst(self.tcx, substs)
66+
let bac = bac.subst(self.tcx, substs);
67+
return bac.fold_with(self);
6768
}
6869
Ok(None) => c,
6970
},

compiler/rustc_middle/src/ty/util.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -360,16 +360,16 @@ impl<'tcx> TyCtxt<'tcx> {
360360
let ty = self.type_of(adt_did).subst_identity();
361361
let mut dtor_candidate = None;
362362
self.for_each_relevant_impl(drop_trait, ty, |impl_did| {
363-
let Some(item_id) = self.associated_item_def_ids(impl_did).first() else {
364-
self.sess.delay_span_bug(self.def_span(impl_did), "Drop impl without drop function");
365-
return;
366-
};
367-
368363
if validate(self, impl_did).is_err() {
369364
// Already `ErrorGuaranteed`, no need to delay a span bug here.
370365
return;
371366
}
372367

368+
let Some(item_id) = self.associated_item_def_ids(impl_did).first() else {
369+
self.sess.delay_span_bug(self.def_span(impl_did), "Drop impl without drop function");
370+
return;
371+
};
372+
373373
if let Some((old_item_id, _)) = dtor_candidate {
374374
self.sess
375375
.struct_span_err(self.def_span(item_id), "multiple drop impls found")

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
550550

551551
let sm = self.tcx.sess.source_map();
552552
let def_id = match outer_res {
553-
Res::SelfTyParam { .. } => {
553+
Res::SelfTyParam { .. } | Res::SelfCtor(_) => {
554554
err.span_label(span, "can't use `Self` here");
555555
return err;
556556
}

0 commit comments

Comments
 (0)