Skip to content

Commit 2f22e63

Browse files
committed
Auto merge of #90037 - matthiaskrgr:rollup-cdfhxtn, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #89766 (RustWrapper: adapt for an LLVM API change) - #89867 (Fix macro_rules! duplication when reexported in the same module) - #89941 (removing TLS support in x86_64-unknown-none-hermitkernel) - #89956 (Suggest a case insensitive match name regardless of levenshtein distance) - #89988 (Do not promote values with const drop that need to be dropped) - #89997 (Add test for issue #84957 - `str.as_bytes()` in a `const` expression) - #90002 (:arrow_up: rust-analyzer) - #90034 (Tiny tweak to Iterator::unzip() doc comment example.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents cd8b56f + 5bcaf04 commit 2f22e63

File tree

21 files changed

+225
-57
lines changed

21 files changed

+225
-57
lines changed

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+37-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::mem;
2222
use std::ops::Deref;
2323

2424
use super::ops::{self, NonConstOp, Status};
25-
use super::qualifs::{self, CustomEq, HasMutInterior, NeedsNonConstDrop};
25+
use super::qualifs::{self, CustomEq, HasMutInterior, NeedsDrop, NeedsNonConstDrop};
2626
use super::resolver::FlowSensitiveAnalysis;
2727
use super::{is_lang_panic_fn, is_lang_special_const_fn, ConstCx, Qualif};
2828
use crate::const_eval::is_unstable_const_fn;
@@ -39,7 +39,8 @@ type QualifResults<'mir, 'tcx, Q> =
3939
#[derive(Default)]
4040
pub struct Qualifs<'mir, 'tcx> {
4141
has_mut_interior: Option<QualifResults<'mir, 'tcx, HasMutInterior>>,
42-
needs_drop: Option<QualifResults<'mir, 'tcx, NeedsNonConstDrop>>,
42+
needs_drop: Option<QualifResults<'mir, 'tcx, NeedsDrop>>,
43+
needs_non_const_drop: Option<QualifResults<'mir, 'tcx, NeedsNonConstDrop>>,
4344
indirectly_mutable: Option<IndirectlyMutableResults<'mir, 'tcx>>,
4445
}
4546

@@ -80,14 +81,14 @@ impl Qualifs<'mir, 'tcx> {
8081
location: Location,
8182
) -> bool {
8283
let ty = ccx.body.local_decls[local].ty;
83-
if !NeedsNonConstDrop::in_any_value_of_ty(ccx, ty) {
84+
if !NeedsDrop::in_any_value_of_ty(ccx, ty) {
8485
return false;
8586
}
8687

8788
let needs_drop = self.needs_drop.get_or_insert_with(|| {
8889
let ConstCx { tcx, body, .. } = *ccx;
8990

90-
FlowSensitiveAnalysis::new(NeedsNonConstDrop, ccx)
91+
FlowSensitiveAnalysis::new(NeedsDrop, ccx)
9192
.into_engine(tcx, &body)
9293
.iterate_to_fixpoint()
9394
.into_results_cursor(&body)
@@ -97,6 +98,33 @@ impl Qualifs<'mir, 'tcx> {
9798
needs_drop.get().contains(local) || self.indirectly_mutable(ccx, local, location)
9899
}
99100

101+
/// Returns `true` if `local` is `NeedsNonConstDrop` at the given `Location`.
102+
///
103+
/// Only updates the cursor if absolutely necessary
104+
pub fn needs_non_const_drop(
105+
&mut self,
106+
ccx: &'mir ConstCx<'mir, 'tcx>,
107+
local: Local,
108+
location: Location,
109+
) -> bool {
110+
let ty = ccx.body.local_decls[local].ty;
111+
if !NeedsNonConstDrop::in_any_value_of_ty(ccx, ty) {
112+
return false;
113+
}
114+
115+
let needs_non_const_drop = self.needs_non_const_drop.get_or_insert_with(|| {
116+
let ConstCx { tcx, body, .. } = *ccx;
117+
118+
FlowSensitiveAnalysis::new(NeedsNonConstDrop, ccx)
119+
.into_engine(tcx, &body)
120+
.iterate_to_fixpoint()
121+
.into_results_cursor(&body)
122+
});
123+
124+
needs_non_const_drop.seek_before_primary_effect(location);
125+
needs_non_const_drop.get().contains(local) || self.indirectly_mutable(ccx, local, location)
126+
}
127+
100128
/// Returns `true` if `local` is `HasMutInterior` at the given `Location`.
101129
///
102130
/// Only updates the cursor if absolutely necessary.
@@ -173,6 +201,7 @@ impl Qualifs<'mir, 'tcx> {
173201

174202
ConstQualifs {
175203
needs_drop: self.needs_drop(ccx, RETURN_PLACE, return_loc),
204+
needs_non_const_drop: self.needs_non_const_drop(ccx, RETURN_PLACE, return_loc),
176205
has_mut_interior: self.has_mut_interior(ccx, RETURN_PLACE, return_loc),
177206
custom_eq,
178207
error_occured,
@@ -999,7 +1028,7 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> {
9991028
}
10001029

10011030
// Forbid all `Drop` terminators unless the place being dropped is a local with no
1002-
// projections that cannot be `NeedsDrop`.
1031+
// projections that cannot be `NeedsNonConstDrop`.
10031032
TerminatorKind::Drop { place: dropped_place, .. }
10041033
| TerminatorKind::DropAndReplace { place: dropped_place, .. } => {
10051034
// If we are checking live drops after drop-elaboration, don't emit duplicate
@@ -1019,15 +1048,15 @@ impl Visitor<'tcx> for Checker<'mir, 'tcx> {
10191048
return;
10201049
}
10211050

1022-
let needs_drop = if let Some(local) = dropped_place.as_local() {
1051+
let needs_non_const_drop = if let Some(local) = dropped_place.as_local() {
10231052
// Use the span where the local was declared as the span of the drop error.
10241053
err_span = self.body.local_decls[local].source_info.span;
1025-
self.qualifs.needs_drop(self.ccx, local, location)
1054+
self.qualifs.needs_non_const_drop(self.ccx, local, location)
10261055
} else {
10271056
true
10281057
};
10291058

1030-
if needs_drop {
1059+
if needs_non_const_drop {
10311060
self.check_op_spanned(
10321061
ops::LiveDrop { dropped_at: Some(terminator.source_info.span) },
10331062
err_span,

compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl Visitor<'tcx> for CheckLiveDrops<'mir, 'tcx> {
9797
// `src/test/ui/consts/control-flow/drop-pass.rs`; e.g., when an `Option<Vec<T>>` is
9898
// initialized with `None` and never changed, it still emits drop glue.
9999
// Hence we additionally check the qualifs here to allow more code to pass.
100-
if self.qualifs.needs_drop(self.ccx, dropped_place.local, location) {
100+
if self.qualifs.needs_non_const_drop(self.ccx, dropped_place.local, location) {
101101
// Use the span where the dropped local was declared for the error.
102102
let span = self.body.local_decls[dropped_place.local].source_info.span;
103103
self.check_live_drop(span);

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+28-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ pub fn in_any_value_of_ty(
2121
) -> ConstQualifs {
2222
ConstQualifs {
2323
has_mut_interior: HasMutInterior::in_any_value_of_ty(cx, ty),
24-
needs_drop: NeedsNonConstDrop::in_any_value_of_ty(cx, ty),
24+
needs_drop: NeedsDrop::in_any_value_of_ty(cx, ty),
25+
needs_non_const_drop: NeedsNonConstDrop::in_any_value_of_ty(cx, ty),
2526
custom_eq: CustomEq::in_any_value_of_ty(cx, ty),
2627
error_occured,
2728
}
@@ -98,17 +99,39 @@ impl Qualif for HasMutInterior {
9899
}
99100

100101
/// Constant containing an ADT that implements `Drop`.
101-
/// This must be ruled out (a) because we cannot run `Drop` during compile-time
102-
/// as that might not be a `const fn`, and (b) because implicit promotion would
103-
/// remove side-effects that occur as part of dropping that value.
102+
/// This must be ruled out because implicit promotion would remove side-effects
103+
/// that occur as part of dropping that value. N.B., the implicit promotion has
104+
/// to reject const Drop implementations because even if side-effects are ruled
105+
/// out through other means, the execution of the drop could diverge.
106+
pub struct NeedsDrop;
107+
108+
impl Qualif for NeedsDrop {
109+
const ANALYSIS_NAME: &'static str = "flow_needs_drop";
110+
const IS_CLEARED_ON_MOVE: bool = true;
111+
112+
fn in_qualifs(qualifs: &ConstQualifs) -> bool {
113+
qualifs.needs_drop
114+
}
115+
116+
fn in_any_value_of_ty(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
117+
ty.needs_drop(cx.tcx, cx.param_env)
118+
}
119+
120+
fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &'tcx AdtDef, _: SubstsRef<'tcx>) -> bool {
121+
adt.has_dtor(cx.tcx)
122+
}
123+
}
124+
125+
/// Constant containing an ADT that implements non-const `Drop`.
126+
/// This must be ruled out because we cannot run `Drop` during compile-time.
104127
pub struct NeedsNonConstDrop;
105128

106129
impl Qualif for NeedsNonConstDrop {
107130
const ANALYSIS_NAME: &'static str = "flow_needs_nonconst_drop";
108131
const IS_CLEARED_ON_MOVE: bool = true;
109132

110133
fn in_qualifs(qualifs: &ConstQualifs) -> bool {
111-
qualifs.needs_drop
134+
qualifs.needs_non_const_drop
112135
}
113136

114137
fn in_any_value_of_ty(cx: &ConstCx<'_, 'tcx>, mut ty: Ty<'tcx>) -> bool {

compiler/rustc_const_eval/src/transform/promote_consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl<'tcx> Validator<'_, 'tcx> {
230230

231231
// We cannot promote things that need dropping, since the promoted value
232232
// would not get dropped.
233-
if self.qualif_local::<qualifs::NeedsNonConstDrop>(place.local) {
233+
if self.qualif_local::<qualifs::NeedsDrop>(place.local) {
234234
return Err(Unpromotable);
235235
}
236236

compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "llvm/Support/Host.h"
1919
#include "llvm/Support/Memory.h"
2020
#include "llvm/Support/SourceMgr.h"
21-
#include "llvm/Support/TargetRegistry.h"
2221
#include "llvm/Support/TargetSelect.h"
2322
#include "llvm/Support/Timer.h"
2423
#include "llvm/Support/raw_ostream.h"

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
#include "llvm/Support/CBindingWrapping.h"
2222
#include "llvm/Support/FileSystem.h"
2323
#include "llvm/Support/Host.h"
24+
#if LLVM_VERSION_LT(14, 0)
25+
#include "llvm/Support/TargetRegistry.h"
26+
#else
27+
#include "llvm/MC/TargetRegistry.h"
28+
#endif
2429
#include "llvm/Target/TargetMachine.h"
2530
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
2631
#include "llvm/Transforms/IPO/AlwaysInliner.h"

compiler/rustc_middle/src/mir/query.rs

+1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ pub struct BorrowCheckResult<'tcx> {
225225
pub struct ConstQualifs {
226226
pub has_mut_interior: bool,
227227
pub needs_drop: bool,
228+
pub needs_non_const_drop: bool,
228229
pub custom_eq: bool,
229230
pub error_occured: Option<ErrorReported>,
230231
}

compiler/rustc_span/src/lev_distance.rs

+15-21
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,28 @@ pub fn find_best_match_for_name(
5858
let lookup = &lookup.as_str();
5959
let max_dist = dist.unwrap_or_else(|| cmp::max(lookup.len(), 3) / 3);
6060

61-
let (case_insensitive_match, levenshtein_match) = name_vec
61+
// Priority of matches:
62+
// 1. Exact case insensitive match
63+
// 2. Levenshtein distance match
64+
// 3. Sorted word match
65+
if let Some(case_insensitive_match) =
66+
name_vec.iter().find(|candidate| candidate.as_str().to_uppercase() == lookup.to_uppercase())
67+
{
68+
return Some(*case_insensitive_match);
69+
}
70+
let levenshtein_match = name_vec
6271
.iter()
6372
.filter_map(|&name| {
6473
let dist = lev_distance(lookup, &name.as_str());
6574
if dist <= max_dist { Some((name, dist)) } else { None }
6675
})
6776
// Here we are collecting the next structure:
68-
// (case_insensitive_match, (levenshtein_match, levenshtein_distance))
69-
.fold((None, None), |result, (candidate, dist)| {
70-
(
71-
if candidate.as_str().to_uppercase() == lookup.to_uppercase() {
72-
Some(candidate)
73-
} else {
74-
result.0
75-
},
76-
match result.1 {
77-
None => Some((candidate, dist)),
78-
Some((c, d)) => Some(if dist < d { (candidate, dist) } else { (c, d) }),
79-
},
80-
)
77+
// (levenshtein_match, levenshtein_distance)
78+
.fold(None, |result, (candidate, dist)| match result {
79+
None => Some((candidate, dist)),
80+
Some((c, d)) => Some(if dist < d { (candidate, dist) } else { (c, d) }),
8181
});
82-
// Priority of matches:
83-
// 1. Exact case insensitive match
84-
// 2. Levenshtein distance match
85-
// 3. Sorted word match
86-
if let Some(candidate) = case_insensitive_match {
87-
Some(candidate)
88-
} else if levenshtein_match.is_some() {
82+
if levenshtein_match.is_some() {
8983
levenshtein_match.map(|(candidate, _)| candidate)
9084
} else {
9185
find_match_by_sorted_words(name_vec, lookup)

compiler/rustc_span/src/lev_distance/tests.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,12 @@ fn test_find_best_match_for_name() {
3131

3232
assert_eq!(find_best_match_for_name(&input, Symbol::intern("1111111111"), None), None);
3333

34-
let input = vec![Symbol::intern("aAAA")];
34+
let input = vec![Symbol::intern("AAAA")];
3535
assert_eq!(
36-
find_best_match_for_name(&input, Symbol::intern("AAAA"), None),
37-
Some(Symbol::intern("aAAA"))
36+
find_best_match_for_name(&input, Symbol::intern("aaaa"), None),
37+
Some(Symbol::intern("AAAA"))
3838
);
3939

40-
let input = vec![Symbol::intern("AAAA")];
41-
// Returns None because `lev_distance > max_dist / 3`
42-
assert_eq!(find_best_match_for_name(&input, Symbol::intern("aaaa"), None), None);
43-
4440
let input = vec![Symbol::intern("AAAA")];
4541
assert_eq!(
4642
find_best_match_for_name(&input, Symbol::intern("aaaa"), Some(4)),

compiler/rustc_target/src/spec/hermit_kernel_base.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor, PanicStrategy, TargetOptions, TlsModel};
1+
use crate::spec::{LinkArgs, LinkerFlavor, LldFlavor, PanicStrategy, TargetOptions};
22

33
pub fn opts() -> TargetOptions {
44
let mut pre_link_args = LinkArgs::new();
@@ -13,12 +13,10 @@ pub fn opts() -> TargetOptions {
1313
disable_redzone: true,
1414
linker: Some("rust-lld".to_owned()),
1515
executables: true,
16-
has_elf_tls: true,
1716
pre_link_args,
1817
panic_strategy: PanicStrategy::Abort,
1918
position_independent_executables: true,
2019
static_position_independent_executables: true,
21-
tls_model: TlsModel::InitialExec,
2220
..Default::default()
2321
}
2422
}

library/core/src/iter/traits/iterator.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2837,12 +2837,12 @@ pub trait Iterator {
28372837
/// Basic usage:
28382838
///
28392839
/// ```
2840-
/// let a = [(1, 2), (3, 4)];
2840+
/// let a = [(1, 2), (3, 4), (5, 6)];
28412841
///
28422842
/// let (left, right): (Vec<_>, Vec<_>) = a.iter().cloned().unzip();
28432843
///
2844-
/// assert_eq!(left, [1, 3]);
2845-
/// assert_eq!(right, [2, 4]);
2844+
/// assert_eq!(left, [1, 3, 5]);
2845+
/// assert_eq!(right, [2, 4, 6]);
28462846
///
28472847
/// // you can also unzip multiple nested tuples at once
28482848
/// let a = [(1, (2, 3)), (4, (5, 6))];

library/std/src/sys/hermit/net.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl TcpStream {
182182
Ok(self.clone())
183183
}
184184

185-
pub fn set_linger(&self, linger: Option<Duration>) -> io::Result<()> {
185+
pub fn set_linger(&self, _linger: Option<Duration>) -> io::Result<()> {
186186
unsupported()
187187
}
188188

src/librustdoc/visit_ast.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,21 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
8787
// the rexport defines the path that a user will actually see. Accordingly,
8888
// we add the rexport as an item here, and then skip over the original
8989
// definition in `visit_item()` below.
90+
//
91+
// We also skip `#[macro_export] macro_rules!` that have already been inserted,
92+
// it can happen if within the same module a `#[macro_export] macro_rules!`
93+
// is declared but also a reexport of itself producing two exports of the same
94+
// macro in the same module.
95+
let mut inserted = FxHashSet::default();
9096
for export in self.cx.tcx.module_exports(CRATE_DEF_ID).unwrap_or(&[]) {
9197
if let Res::Def(DefKind::Macro(_), def_id) = export.res {
9298
if let Some(local_def_id) = def_id.as_local() {
9399
if self.cx.tcx.has_attr(def_id, sym::macro_export) {
94-
let hir_id = self.cx.tcx.hir().local_def_id_to_hir_id(local_def_id);
95-
let item = self.cx.tcx.hir().expect_item(hir_id);
96-
top_level_module.items.push((item, None));
100+
if inserted.insert(def_id) {
101+
let hir_id = self.cx.tcx.hir().local_def_id_to_hir_id(local_def_id);
102+
let item = self.cx.tcx.hir().expect_item(hir_id);
103+
top_level_module.items.push((item, None));
104+
}
97105
}
98106
}
99107
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// edition:2018
2+
3+
#![no_core]
4+
#![feature(no_core)]
5+
6+
// @count macro.json "$.index[*][?(@.name=='macro')].inner.items[*]" 2
7+
8+
// @set repro_id = macro.json "$.index[*][?(@.name=='repro')].id"
9+
// @has - "$.index[*][?(@.name=='macro')].inner.items[*]" $repro_id
10+
#[macro_export]
11+
macro_rules! repro {
12+
() => {};
13+
}
14+
15+
// @set repro2_id = macro.json "$.index[*][?(@.inner.name=='repro2')].id"
16+
// @has - "$.index[*][?(@.name=='macro')].inner.items[*]" $repro2_id
17+
pub use crate::repro as repro2;

src/test/rustdoc/issue-89852.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// edition:2018
2+
3+
#![no_core]
4+
#![feature(no_core)]
5+
6+
// @matches 'issue_89852/sidebar-items.js' '"repro"'
7+
// @!matches 'issue_89852/sidebar-items.js' '"repro".*"repro"'
8+
9+
#[macro_export]
10+
macro_rules! repro {
11+
() => {};
12+
}
13+
14+
pub use crate::repro as repro2;

0 commit comments

Comments
 (0)