Skip to content

Commit 734233d

Browse files
committed
Auto merge of #74569 - Manishearth:rollup-hkn5ex9, r=Manishearth
Rollup of 13 pull requests Successful merges: - #72714 (Fix debug assertion in typeck) - #73197 (Impl Default for ranges) - #73323 (wf: check foreign fn decls for well-formedness) - #74051 (disallow non-static lifetimes in const generics) - #74376 (test caching opt_const_param_of on disc) - #74501 (Ayu theme: Use different background color for Run button) - #74505 (Fix search input focus in ayu theme) - #74522 (Update sanitizer docs) - #74546 (Fix duplicate maybe_uninit_extra attribute) - #74552 (Stabilize TAU constant.) - #74555 (Improve "important traits" popup display on mobile) - #74557 (Fix an ICE on an invalid `binding @ ...` in a tuple struct pattern) - #74561 (update backtrace-rs) Failed merges: r? @ghost
2 parents f9a3086 + df8d169 commit 734233d

File tree

28 files changed

+305
-81
lines changed

28 files changed

+305
-81
lines changed

src/doc/unstable-book/src/compiler-flags/sanitizer.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ of bugs:
2626
* Double-free, invalid free
2727
* Memory leaks
2828

29+
The memory leak detection is enabled by default on Linux, and can be enabled
30+
with runtime flag `ASAN_OPTIONS=detect_leaks=1` on macOS.
31+
2932
AddressSanitizer is supported on the following targets:
3033

3134
* `x86_64-apple-darwin`
@@ -196,10 +199,6 @@ fn main() {
196199
197200
```shell
198201
$ export \
199-
CC=clang \
200-
CXX=clang++ \
201-
CFLAGS='-fsanitize=memory -fsanitize-memory-track-origins' \
202-
CXXFLAGS='-fsanitize=memory -fsanitize-memory-track-origins' \
203202
RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins' \
204203
RUSTDOCFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins'
205204
$ cargo clean

src/libcore/num/f32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ pub mod consts {
242242
/// The full circle constant (τ)
243243
///
244244
/// Equal to 2π.
245-
#[unstable(feature = "tau_constant", issue = "66770")]
245+
#[stable(feature = "tau_constant", since = "1.47.0")]
246246
pub const TAU: f32 = 6.28318530717958647692528676655900577_f32;
247247

248248
/// π/2

src/libcore/num/f64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ pub mod consts {
242242
/// The full circle constant (τ)
243243
///
244244
/// Equal to 2π.
245-
#[unstable(feature = "tau_constant", issue = "66770")]
245+
#[stable(feature = "tau_constant", since = "1.47.0")]
246246
pub const TAU: f64 = 6.28318530717958647692528676655900577_f64;
247247

248248
/// π/2

src/libcore/ops/range.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use crate::hash::Hash;
3939
/// [`Iterator`]: ../iter/trait.IntoIterator.html
4040
/// [slicing index]: ../slice/trait.SliceIndex.html
4141
#[doc(alias = "..")]
42-
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
42+
#[derive(Copy, Clone, Default, PartialEq, Eq, Hash)]
4343
#[stable(feature = "rust1", since = "1.0.0")]
4444
pub struct RangeFull;
4545

@@ -71,7 +71,7 @@ impl fmt::Debug for RangeFull {
7171
/// assert_eq!(arr[1..=3], [ 1,2,3 ]);
7272
/// ```
7373
#[doc(alias = "..")]
74-
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
74+
#[derive(Clone, Default, PartialEq, Eq, Hash)] // not Copy -- see #27186
7575
#[stable(feature = "rust1", since = "1.0.0")]
7676
pub struct Range<Idx> {
7777
/// The lower bound of the range (inclusive).

src/librustc_error_codes/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ E0767: include_str!("./error_codes/E0767.md"),
453453
E0768: include_str!("./error_codes/E0768.md"),
454454
E0769: include_str!("./error_codes/E0769.md"),
455455
E0770: include_str!("./error_codes/E0770.md"),
456+
E0771: include_str!("./error_codes/E0771.md"),
456457
;
457458
// E0006, // merged with E0005
458459
// E0008, // cannot bind by-move into a pattern guard
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
A non-`'static` lifetime was used in a const generic. This is currently not
2+
allowed.
3+
4+
Erroneous code example:
5+
6+
```compile_fail,E0771
7+
#![feature(const_generics)]
8+
9+
fn function_with_str<'a, const STRING: &'a str>() {} // error!
10+
```
11+
12+
To fix this issue, the lifetime in the const generic need to be changed to
13+
`'static`:
14+
15+
```
16+
#![feature(const_generics)]
17+
18+
fn function_with_str<const STRING: &'static str>() {} // ok!
19+
```
20+
21+
For more information, see [GitHub issue #74052].
22+
23+
[GitHub issue #74052]: https://github.com/rust-lang/rust/issues/74052

src/librustc_middle/query/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,13 @@ rustc_queries! {
103103
/// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
104104
/// }
105105
/// ```
106+
// It looks like caching this query on disk actually slightly
107+
// worsened performance in #74376.
108+
//
109+
// Once const generics are more prevalently used, we might want to
110+
// consider only caching calls returning `Some`.
106111
query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
107112
desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
108-
// FIXME(#74113): consider storing this query on disk.
109113
}
110114

111115
/// Records the type of every item.

src/librustc_resolve/late.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1500,11 +1500,17 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
15001500
pat_src: PatternSource,
15011501
bindings: &mut SmallVec<[(PatBoundCtx, FxHashSet<Ident>); 1]>,
15021502
) {
1503+
let is_tuple_struct_pat = matches!(pat.kind, PatKind::TupleStruct(_, _));
1504+
15031505
// Visit all direct subpatterns of this pattern.
15041506
pat.walk(&mut |pat| {
15051507
debug!("resolve_pattern pat={:?} node={:?}", pat, pat.kind);
15061508
match pat.kind {
1507-
PatKind::Ident(bmode, ident, ref sub) => {
1509+
// In tuple struct patterns ignore the invalid `ident @ ...`.
1510+
// It will be handled as an error by the AST lowering.
1511+
PatKind::Ident(bmode, ident, ref sub)
1512+
if !(is_tuple_struct_pat && sub.as_ref().filter(|p| p.is_rest()).is_some()) =>
1513+
{
15081514
// First try to resolve the identifier as some existing entity,
15091515
// then fall back to a fresh binding.
15101516
let has_sub = sub.is_some();

src/librustc_resolve/late/diagnostics.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,24 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
11411141
err.emit();
11421142
}
11431143

1144+
// FIXME(const_generics): This patches over a ICE caused by non-'static lifetimes in const
1145+
// generics. We are disallowing this until we can decide on how we want to handle non-'static
1146+
// lifetimes in const generics. See issue #74052 for discussion.
1147+
crate fn emit_non_static_lt_in_const_generic_error(&self, lifetime_ref: &hir::Lifetime) {
1148+
let mut err = struct_span_err!(
1149+
self.tcx.sess,
1150+
lifetime_ref.span,
1151+
E0771,
1152+
"use of non-static lifetime `{}` in const generic",
1153+
lifetime_ref
1154+
);
1155+
err.note(
1156+
"for more information, see issue #74052 \
1157+
<https://github.com/rust-lang/rust/issues/74052>",
1158+
);
1159+
err.emit();
1160+
}
1161+
11441162
crate fn is_trait_ref_fn_scope(&mut self, trait_ref: &'tcx hir::PolyTraitRef<'tcx>) -> bool {
11451163
if let def::Res::Def(_, did) = trait_ref.trait_ref.path.res {
11461164
if [

src/librustc_resolve/late/lifetimes.rs

+11
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ crate struct LifetimeContext<'a, 'tcx> {
173173
/// Used to disallow the use of in-band lifetimes in `fn` or `Fn` syntax.
174174
is_in_fn_syntax: bool,
175175

176+
is_in_const_generic: bool,
177+
176178
/// List of labels in the function/method currently under analysis.
177179
labels_in_fn: Vec<Ident>,
178180

@@ -333,6 +335,7 @@ fn krate(tcx: TyCtxt<'_>) -> NamedRegionMap {
333335
scope: ROOT_SCOPE,
334336
trait_ref_hack: false,
335337
is_in_fn_syntax: false,
338+
is_in_const_generic: false,
336339
labels_in_fn: vec![],
337340
xcrate_object_lifetime_defaults: Default::default(),
338341
lifetime_uses: &mut Default::default(),
@@ -828,6 +831,10 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
828831
self.insert_lifetime(lifetime_ref, Region::Static);
829832
return;
830833
}
834+
if self.is_in_const_generic && lifetime_ref.name != LifetimeName::Error {
835+
self.emit_non_static_lt_in_const_generic_error(lifetime_ref);
836+
return;
837+
}
831838
self.resolve_lifetime_ref(lifetime_ref);
832839
}
833840

@@ -860,8 +867,11 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
860867
}
861868
}
862869
GenericParamKind::Const { ref ty, .. } => {
870+
let was_in_const_generic = self.is_in_const_generic;
871+
self.is_in_const_generic = true;
863872
walk_list!(self, visit_param_bound, param.bounds);
864873
self.visit_ty(&ty);
874+
self.is_in_const_generic = was_in_const_generic;
865875
}
866876
}
867877
}
@@ -1317,6 +1327,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
13171327
scope: &wrap_scope,
13181328
trait_ref_hack: self.trait_ref_hack,
13191329
is_in_fn_syntax: self.is_in_fn_syntax,
1330+
is_in_const_generic: self.is_in_const_generic,
13201331
labels_in_fn,
13211332
xcrate_object_lifetime_defaults,
13221333
lifetime_uses,

src/librustc_typeck/check/wfcheck.rs

+28-20
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::ty::{
1515
self, AdtKind, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness,
1616
};
1717
use rustc_session::parse::feature_err;
18-
use rustc_span::symbol::{sym, Symbol};
18+
use rustc_span::symbol::{sym, Ident, Symbol};
1919
use rustc_span::Span;
2020
use rustc_trait_selection::opaque_types::may_define_opaque_type;
2121
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
@@ -142,8 +142,8 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
142142
_ => unreachable!(),
143143
}
144144
}
145-
hir::ItemKind::Fn(..) => {
146-
check_item_fn(tcx, item);
145+
hir::ItemKind::Fn(ref sig, ..) => {
146+
check_item_fn(tcx, item.hir_id, item.ident, item.span, sig.decl);
147147
}
148148
hir::ItemKind::Static(ref ty, ..) => {
149149
check_item_type(tcx, item.hir_id, ty.span, false);
@@ -153,8 +153,14 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
153153
}
154154
hir::ItemKind::ForeignMod(ref module) => {
155155
for it in module.items.iter() {
156-
if let hir::ForeignItemKind::Static(ref ty, ..) = it.kind {
157-
check_item_type(tcx, it.hir_id, ty.span, true);
156+
match it.kind {
157+
hir::ForeignItemKind::Fn(ref decl, ..) => {
158+
check_item_fn(tcx, it.hir_id, it.ident, it.span, decl)
159+
}
160+
hir::ForeignItemKind::Static(ref ty, ..) => {
161+
check_item_type(tcx, it.hir_id, ty.span, true)
162+
}
163+
hir::ForeignItemKind::Type => (),
158164
}
159165
}
160166
}
@@ -303,7 +309,7 @@ fn check_associated_item(
303309
fcx,
304310
item.ident.span,
305311
sig,
306-
hir_sig,
312+
hir_sig.decl,
307313
item.def_id,
308314
&mut implied_bounds,
309315
);
@@ -564,22 +570,24 @@ fn check_associated_type_defaults(fcx: &FnCtxt<'_, '_>, trait_def_id: DefId) {
564570
}
565571
}
566572

567-
fn check_item_fn(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
568-
for_item(tcx, item).with_fcx(|fcx, tcx| {
569-
let def_id = fcx.tcx.hir().local_def_id(item.hir_id);
573+
fn check_item_fn(
574+
tcx: TyCtxt<'_>,
575+
item_id: hir::HirId,
576+
ident: Ident,
577+
span: Span,
578+
decl: &hir::FnDecl<'_>,
579+
) {
580+
for_id(tcx, item_id, span).with_fcx(|fcx, tcx| {
581+
let def_id = fcx.tcx.hir().local_def_id(item_id);
570582
let sig = fcx.tcx.fn_sig(def_id);
571-
let sig = fcx.normalize_associated_types_in(item.span, &sig);
583+
let sig = fcx.normalize_associated_types_in(span, &sig);
572584
let mut implied_bounds = vec![];
573-
let hir_sig = match &item.kind {
574-
ItemKind::Fn(sig, ..) => sig,
575-
_ => bug!("expected `ItemKind::Fn`, found `{:?}`", item.kind),
576-
};
577585
check_fn_or_method(
578586
tcx,
579587
fcx,
580-
item.ident.span,
588+
ident.span,
581589
sig,
582-
hir_sig,
590+
decl,
583591
def_id.to_def_id(),
584592
&mut implied_bounds,
585593
);
@@ -835,28 +843,28 @@ fn check_fn_or_method<'fcx, 'tcx>(
835843
fcx: &FnCtxt<'fcx, 'tcx>,
836844
span: Span,
837845
sig: ty::PolyFnSig<'tcx>,
838-
hir_sig: &hir::FnSig<'_>,
846+
hir_decl: &hir::FnDecl<'_>,
839847
def_id: DefId,
840848
implied_bounds: &mut Vec<Ty<'tcx>>,
841849
) {
842850
let sig = fcx.normalize_associated_types_in(span, &sig);
843851
let sig = fcx.tcx.liberate_late_bound_regions(def_id, &sig);
844852

845-
for (&input_ty, span) in sig.inputs().iter().zip(hir_sig.decl.inputs.iter().map(|t| t.span)) {
853+
for (&input_ty, span) in sig.inputs().iter().zip(hir_decl.inputs.iter().map(|t| t.span)) {
846854
fcx.register_wf_obligation(input_ty.into(), span, ObligationCauseCode::MiscObligation);
847855
}
848856
implied_bounds.extend(sig.inputs());
849857

850858
fcx.register_wf_obligation(
851859
sig.output().into(),
852-
hir_sig.decl.output.span(),
860+
hir_decl.output.span(),
853861
ObligationCauseCode::ReturnType,
854862
);
855863

856864
// FIXME(#25759) return types should not be implied bounds
857865
implied_bounds.push(sig.output());
858866

859-
check_where_clauses(tcx, fcx, span, def_id, Some((sig.output(), hir_sig.decl.output.span())));
867+
check_where_clauses(tcx, fcx, span, def_id, Some((sig.output(), hir_decl.output.span())));
860868
}
861869

862870
/// Checks "defining uses" of opaque `impl Trait` types to ensure that they meet the restrictions

src/librustc_typeck/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
19271927
let re_root_empty = tcx.lifetimes.re_root_empty;
19281928
let predicate = ty::OutlivesPredicate(ty, re_root_empty);
19291929
predicates.push((
1930-
ty::PredicateKind::TypeOutlives(ty::Binder::dummy(predicate))
1930+
ty::PredicateKind::TypeOutlives(ty::Binder::bind(predicate))
19311931
.to_predicate(tcx),
19321932
span,
19331933
));

src/librustdoc/html/static/rustdoc.css

+5
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,11 @@ h4 > .important-traits {
15111511
#main > .line-numbers {
15121512
margin-top: 0;
15131513
}
1514+
1515+
.important-traits .important-traits-tooltiptext {
1516+
left: 0;
1517+
top: 100%;
1518+
}
15141519
}
15151520

15161521
@media print {

src/librustdoc/html/static/themes/ayu.css

+3-13
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,6 @@ a {
237237

238238
#crate-search+.search-input:focus {
239239
box-shadow: 0 0 0 1px #148099,0 0 0 2px transparent;
240-
color: #ffffff;
241-
background-color: #141920;
242-
box-shadow: none;
243-
transition: box-shadow 150ms ease-in-out;
244-
border-radius: 4px;
245-
margin-left: 8px;
246-
}
247-
248-
#crate-search+.search-input:focus {
249-
box-shadow: 0px 6px 20px 0px black;
250240
}
251241

252242
.search-focus:disabled {
@@ -318,12 +308,12 @@ a.test-arrow {
318308
font-size: 100%;
319309
color: #788797;
320310
border-radius: 4px;
321-
background-color: rgba(255, 255, 255, 0);
311+
background-color: rgba(57, 175, 215, 0.09);
322312
}
323313

324314
a.test-arrow:hover {
325-
background-color: rgba(242, 151, 24, 0.05);
326-
color: #ffb44c;
315+
background-color: rgba(57, 175, 215, 0.368);
316+
color: #c5c5c5;
327317
}
328318

329319
.toggle-label {

src/libstd/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,7 @@
224224
all(target_vendor = "fortanix", target_env = "sgx"),
225225
feature(slice_index_methods, coerce_unsized, sgx_platform, ptr_wrapping_offset_from)
226226
)]
227-
#![cfg_attr(
228-
all(test, target_vendor = "fortanix", target_env = "sgx"),
229-
feature(fixed_size_array, maybe_uninit_extra)
230-
)]
227+
#![cfg_attr(all(test, target_vendor = "fortanix", target_env = "sgx"), feature(fixed_size_array))]
231228
// std is implemented with unstable features, many of which are internal
232229
// compiler details that will never be stable
233230
// NB: the following list is sorted to minimize merge conflicts.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// run-pass
2+
3+
#![feature(const_generics)]
4+
//~^ WARN the feature `const_generics` is incomplete
5+
#![allow(dead_code)]
6+
7+
fn test<const N: usize>() {}
8+
9+
fn wow<'a>() -> &'a () {
10+
test::<{
11+
let _: &'a ();
12+
3
13+
}>();
14+
&()
15+
}
16+
17+
fn main() {}

0 commit comments

Comments
 (0)