Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 13 pull requests #74569

Merged
merged 30 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
187aea7
Impl Default for ranges
c410-f3r Jun 10, 2020
c375692
Remove some Default impls
c410-f3r Jul 10, 2020
a11024f
Fix debug assertion in typeck
JohnTitor May 28, 2020
e8d16fd
add note to `opt_const_param_of`
lcnr Jul 18, 2020
174abeb
Add an border around the Run button
tesuji Jul 19, 2020
dec7076
Fix search input focus in ayu theme
Cldfire Jul 19, 2020
0eff3d5
Ayu: use different background color to make Run button easy-to-spot
tesuji Jul 19, 2020
251878e
Remove CC & CFLAGS from MemorySanitizer example
tmiasko Jul 18, 2020
58b8620
Document AddressSanitizer memory leak detection defaults
tmiasko Jul 18, 2020
69d5dd6
disallow non-static lifetimes in const generics
yodaldevoid Jul 5, 2020
c60a035
Add test for an explicit non-'static lifetime in a const argument
yodaldevoid Jul 19, 2020
ceac273
wf: check foreign fn decls for well-formedness
davidtwco Jun 13, 2020
c8cdcc8
Fix duplicate maybe_uninit_extra attribute
Jul 20, 2020
5d4147a
Stabilize TAU constant.
m-ou-se Jul 10, 2020
995d63a
Improve "important traits" popup display on mobile
GuillaumeGomez Jul 20, 2020
4cbd265
update backtrace-rs
RalfJung Jul 20, 2020
f5e5eb6
Fix an ICE on an invalid `binding @ ...` in a tuple struct pattern
jakubadamw Jul 20, 2020
105cd49
Rollup merge of #72714 - JohnTitor:debug-assert, r=nikomatsakis
Manishearth Jul 20, 2020
241374a
Rollup merge of #73197 - c410-f3r:ranges, r=dtolnay
Manishearth Jul 20, 2020
0897bc2
Rollup merge of #73323 - davidtwco:issue-73252-wfcheck-foreign-fn-dec…
Manishearth Jul 20, 2020
991da05
Rollup merge of #74051 - yodaldevoid:issue_60814, r=nikomatsakis
Manishearth Jul 20, 2020
6a4276d
Rollup merge of #74376 - lcnr:type-dependent-path-cleanup, r=eddyb
Manishearth Jul 20, 2020
e0fae89
Rollup merge of #74501 - lzutao:css_run_border, r=GuillaumeGomez
Manishearth Jul 20, 2020
6467f6f
Rollup merge of #74505 - Cldfire:fix-search-focus, r=GuillaumeGomez
Manishearth Jul 20, 2020
15f8b80
Rollup merge of #74522 - tmiasko:sanitizer-docs, r=nikomatsakis
Manishearth Jul 20, 2020
b7357c4
Rollup merge of #74546 - jethrogb:jb/duplicate-attribute-maybe_uninit…
Manishearth Jul 20, 2020
810d322
Rollup merge of #74552 - fusion-engineering-forks:stabilize-tau, r=dt…
Manishearth Jul 20, 2020
963b837
Rollup merge of #74555 - GuillaumeGomez:important-traits-popup, r=Man…
Manishearth Jul 20, 2020
6bbf82d
Rollup merge of #74557 - jakubadamw:issue-74539, r=nagisa
Manishearth Jul 20, 2020
df8d169
Rollup merge of #74561 - RalfJung:backtrace, r=alexcrichton
Manishearth Jul 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backtrace
7 changes: 3 additions & 4 deletions src/doc/unstable-book/src/compiler-flags/sanitizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ of bugs:
* Double-free, invalid free
* Memory leaks

The memory leak detection is enabled by default on Linux, and can be enabled
with runtime flag `ASAN_OPTIONS=detect_leaks=1` on macOS.

AddressSanitizer is supported on the following targets:

* `x86_64-apple-darwin`
Expand Down Expand Up @@ -196,10 +199,6 @@ fn main() {

```shell
$ export \
CC=clang \
CXX=clang++ \
CFLAGS='-fsanitize=memory -fsanitize-memory-track-origins' \
CXXFLAGS='-fsanitize=memory -fsanitize-memory-track-origins' \
RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins' \
RUSTDOCFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins'
$ cargo clean
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ pub mod consts {
/// The full circle constant (τ)
///
/// Equal to 2π.
#[unstable(feature = "tau_constant", issue = "66770")]
#[stable(feature = "tau_constant", since = "1.47.0")]
pub const TAU: f32 = 6.28318530717958647692528676655900577_f32;

/// π/2
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ pub mod consts {
/// The full circle constant (τ)
///
/// Equal to 2π.
#[unstable(feature = "tau_constant", issue = "66770")]
#[stable(feature = "tau_constant", since = "1.47.0")]
pub const TAU: f64 = 6.28318530717958647692528676655900577_f64;

/// π/2
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/ops/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use crate::hash::Hash;
/// [`Iterator`]: ../iter/trait.IntoIterator.html
/// [slicing index]: ../slice/trait.SliceIndex.html
#[doc(alias = "..")]
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, Default, PartialEq, Eq, Hash)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct RangeFull;

Expand Down Expand Up @@ -71,7 +71,7 @@ impl fmt::Debug for RangeFull {
/// assert_eq!(arr[1..=3], [ 1,2,3 ]);
/// ```
#[doc(alias = "..")]
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
#[derive(Clone, Default, PartialEq, Eq, Hash)] // not Copy -- see #27186
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Range<Idx> {
/// The lower bound of the range (inclusive).
Expand Down
1 change: 1 addition & 0 deletions src/librustc_error_codes/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ E0767: include_str!("./error_codes/E0767.md"),
E0768: include_str!("./error_codes/E0768.md"),
E0769: include_str!("./error_codes/E0769.md"),
E0770: include_str!("./error_codes/E0770.md"),
E0771: include_str!("./error_codes/E0771.md"),
;
// E0006, // merged with E0005
// E0008, // cannot bind by-move into a pattern guard
Expand Down
23 changes: 23 additions & 0 deletions src/librustc_error_codes/error_codes/E0771.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
A non-`'static` lifetime was used in a const generic. This is currently not
allowed.

Erroneous code example:

```compile_fail,E0771
#![feature(const_generics)]

fn function_with_str<'a, const STRING: &'a str>() {} // error!
```

To fix this issue, the lifetime in the const generic need to be changed to
`'static`:

```
#![feature(const_generics)]

fn function_with_str<const STRING: &'static str>() {} // ok!
```

For more information, see [GitHub issue #74052].

[GitHub issue #74052]: https://github.com/rust-lang/rust/issues/74052
6 changes: 5 additions & 1 deletion src/librustc_middle/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ rustc_queries! {
/// // ^ While calling `opt_const_param_of` for other bodies returns `None`.
/// }
/// ```
// It looks like caching this query on disk actually slightly
// worsened performance in #74376.
//
// Once const generics are more prevalently used, we might want to
// consider only caching calls returning `Some`.
query opt_const_param_of(key: LocalDefId) -> Option<DefId> {
desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) }
// FIXME(#74113): consider storing this query on disk.
}

/// Records the type of every item.
Expand Down
8 changes: 7 additions & 1 deletion src/librustc_resolve/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1500,11 +1500,17 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
pat_src: PatternSource,
bindings: &mut SmallVec<[(PatBoundCtx, FxHashSet<Ident>); 1]>,
) {
let is_tuple_struct_pat = matches!(pat.kind, PatKind::TupleStruct(_, _));

// Visit all direct subpatterns of this pattern.
pat.walk(&mut |pat| {
debug!("resolve_pattern pat={:?} node={:?}", pat, pat.kind);
match pat.kind {
PatKind::Ident(bmode, ident, ref sub) => {
// In tuple struct patterns ignore the invalid `ident @ ...`.
// It will be handled as an error by the AST lowering.
PatKind::Ident(bmode, ident, ref sub)
if !(is_tuple_struct_pat && sub.as_ref().filter(|p| p.is_rest()).is_some()) =>
{
// First try to resolve the identifier as some existing entity,
// then fall back to a fresh binding.
let has_sub = sub.is_some();
Expand Down
18 changes: 18 additions & 0 deletions src/librustc_resolve/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,24 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
err.emit();
}

// FIXME(const_generics): This patches over a ICE caused by non-'static lifetimes in const
// generics. We are disallowing this until we can decide on how we want to handle non-'static
// lifetimes in const generics. See issue #74052 for discussion.
crate fn emit_non_static_lt_in_const_generic_error(&self, lifetime_ref: &hir::Lifetime) {
let mut err = struct_span_err!(
self.tcx.sess,
lifetime_ref.span,
E0771,
"use of non-static lifetime `{}` in const generic",
lifetime_ref
);
err.note(
"for more information, see issue #74052 \
<https://github.com/rust-lang/rust/issues/74052>",
);
err.emit();
}

crate fn is_trait_ref_fn_scope(&mut self, trait_ref: &'tcx hir::PolyTraitRef<'tcx>) -> bool {
if let def::Res::Def(_, did) = trait_ref.trait_ref.path.res {
if [
Expand Down
11 changes: 11 additions & 0 deletions src/librustc_resolve/late/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ crate struct LifetimeContext<'a, 'tcx> {
/// Used to disallow the use of in-band lifetimes in `fn` or `Fn` syntax.
is_in_fn_syntax: bool,

is_in_const_generic: bool,

/// List of labels in the function/method currently under analysis.
labels_in_fn: Vec<Ident>,

Expand Down Expand Up @@ -333,6 +335,7 @@ fn krate(tcx: TyCtxt<'_>) -> NamedRegionMap {
scope: ROOT_SCOPE,
trait_ref_hack: false,
is_in_fn_syntax: false,
is_in_const_generic: false,
labels_in_fn: vec![],
xcrate_object_lifetime_defaults: Default::default(),
lifetime_uses: &mut Default::default(),
Expand Down Expand Up @@ -828,6 +831,10 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
self.insert_lifetime(lifetime_ref, Region::Static);
return;
}
if self.is_in_const_generic && lifetime_ref.name != LifetimeName::Error {
self.emit_non_static_lt_in_const_generic_error(lifetime_ref);
return;
}
self.resolve_lifetime_ref(lifetime_ref);
}

Expand Down Expand Up @@ -860,8 +867,11 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
}
}
GenericParamKind::Const { ref ty, .. } => {
let was_in_const_generic = self.is_in_const_generic;
self.is_in_const_generic = true;
walk_list!(self, visit_param_bound, param.bounds);
self.visit_ty(&ty);
self.is_in_const_generic = was_in_const_generic;
}
}
}
Expand Down Expand Up @@ -1317,6 +1327,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
scope: &wrap_scope,
trait_ref_hack: self.trait_ref_hack,
is_in_fn_syntax: self.is_in_fn_syntax,
is_in_const_generic: self.is_in_const_generic,
labels_in_fn,
xcrate_object_lifetime_defaults,
lifetime_uses,
Expand Down
48 changes: 28 additions & 20 deletions src/librustc_typeck/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_middle::ty::{
self, AdtKind, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness,
};
use rustc_session::parse::feature_err;
use rustc_span::symbol::{sym, Symbol};
use rustc_span::symbol::{sym, Ident, Symbol};
use rustc_span::Span;
use rustc_trait_selection::opaque_types::may_define_opaque_type;
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
Expand Down Expand Up @@ -142,8 +142,8 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
_ => unreachable!(),
}
}
hir::ItemKind::Fn(..) => {
check_item_fn(tcx, item);
hir::ItemKind::Fn(ref sig, ..) => {
check_item_fn(tcx, item.hir_id, item.ident, item.span, sig.decl);
}
hir::ItemKind::Static(ref ty, ..) => {
check_item_type(tcx, item.hir_id, ty.span, false);
Expand All @@ -153,8 +153,14 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
}
hir::ItemKind::ForeignMod(ref module) => {
for it in module.items.iter() {
if let hir::ForeignItemKind::Static(ref ty, ..) = it.kind {
check_item_type(tcx, it.hir_id, ty.span, true);
match it.kind {
hir::ForeignItemKind::Fn(ref decl, ..) => {
check_item_fn(tcx, it.hir_id, it.ident, it.span, decl)
}
hir::ForeignItemKind::Static(ref ty, ..) => {
check_item_type(tcx, it.hir_id, ty.span, true)
}
hir::ForeignItemKind::Type => (),
}
}
}
Expand Down Expand Up @@ -303,7 +309,7 @@ fn check_associated_item(
fcx,
item.ident.span,
sig,
hir_sig,
hir_sig.decl,
item.def_id,
&mut implied_bounds,
);
Expand Down Expand Up @@ -564,22 +570,24 @@ fn check_associated_type_defaults(fcx: &FnCtxt<'_, '_>, trait_def_id: DefId) {
}
}

fn check_item_fn(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
for_item(tcx, item).with_fcx(|fcx, tcx| {
let def_id = fcx.tcx.hir().local_def_id(item.hir_id);
fn check_item_fn(
tcx: TyCtxt<'_>,
item_id: hir::HirId,
ident: Ident,
span: Span,
decl: &hir::FnDecl<'_>,
) {
for_id(tcx, item_id, span).with_fcx(|fcx, tcx| {
let def_id = fcx.tcx.hir().local_def_id(item_id);
let sig = fcx.tcx.fn_sig(def_id);
let sig = fcx.normalize_associated_types_in(item.span, &sig);
let sig = fcx.normalize_associated_types_in(span, &sig);
let mut implied_bounds = vec![];
let hir_sig = match &item.kind {
ItemKind::Fn(sig, ..) => sig,
_ => bug!("expected `ItemKind::Fn`, found `{:?}`", item.kind),
};
check_fn_or_method(
tcx,
fcx,
item.ident.span,
ident.span,
sig,
hir_sig,
decl,
def_id.to_def_id(),
&mut implied_bounds,
);
Expand Down Expand Up @@ -835,28 +843,28 @@ fn check_fn_or_method<'fcx, 'tcx>(
fcx: &FnCtxt<'fcx, 'tcx>,
span: Span,
sig: ty::PolyFnSig<'tcx>,
hir_sig: &hir::FnSig<'_>,
hir_decl: &hir::FnDecl<'_>,
def_id: DefId,
implied_bounds: &mut Vec<Ty<'tcx>>,
) {
let sig = fcx.normalize_associated_types_in(span, &sig);
let sig = fcx.tcx.liberate_late_bound_regions(def_id, &sig);

for (&input_ty, span) in sig.inputs().iter().zip(hir_sig.decl.inputs.iter().map(|t| t.span)) {
for (&input_ty, span) in sig.inputs().iter().zip(hir_decl.inputs.iter().map(|t| t.span)) {
fcx.register_wf_obligation(input_ty.into(), span, ObligationCauseCode::MiscObligation);
}
implied_bounds.extend(sig.inputs());

fcx.register_wf_obligation(
sig.output().into(),
hir_sig.decl.output.span(),
hir_decl.output.span(),
ObligationCauseCode::ReturnType,
);

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

check_where_clauses(tcx, fcx, span, def_id, Some((sig.output(), hir_sig.decl.output.span())));
check_where_clauses(tcx, fcx, span, def_id, Some((sig.output(), hir_decl.output.span())));
}

/// Checks "defining uses" of opaque `impl Trait` types to ensure that they meet the restrictions
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1927,7 +1927,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
let re_root_empty = tcx.lifetimes.re_root_empty;
let predicate = ty::OutlivesPredicate(ty, re_root_empty);
predicates.push((
ty::PredicateKind::TypeOutlives(ty::Binder::dummy(predicate))
ty::PredicateKind::TypeOutlives(ty::Binder::bind(predicate))
.to_predicate(tcx),
span,
));
Expand Down
5 changes: 5 additions & 0 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,11 @@ h4 > .important-traits {
#main > .line-numbers {
margin-top: 0;
}

.important-traits .important-traits-tooltiptext {
left: 0;
top: 100%;
}
}

@media print {
Expand Down
16 changes: 3 additions & 13 deletions src/librustdoc/html/static/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,6 @@ a {

#crate-search+.search-input:focus {
box-shadow: 0 0 0 1px #148099,0 0 0 2px transparent;
color: #ffffff;
background-color: #141920;
box-shadow: none;
transition: box-shadow 150ms ease-in-out;
border-radius: 4px;
margin-left: 8px;
}

#crate-search+.search-input:focus {
box-shadow: 0px 6px 20px 0px black;
}

.search-focus:disabled {
Expand Down Expand Up @@ -318,12 +308,12 @@ a.test-arrow {
font-size: 100%;
color: #788797;
border-radius: 4px;
background-color: rgba(255, 255, 255, 0);
background-color: rgba(57, 175, 215, 0.09);
}

a.test-arrow:hover {
background-color: rgba(242, 151, 24, 0.05);
color: #ffb44c;
background-color: rgba(57, 175, 215, 0.368);
color: #c5c5c5;
}

.toggle-label {
Expand Down
5 changes: 1 addition & 4 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,7 @@
all(target_vendor = "fortanix", target_env = "sgx"),
feature(slice_index_methods, coerce_unsized, sgx_platform, ptr_wrapping_offset_from)
)]
#![cfg_attr(
all(test, target_vendor = "fortanix", target_env = "sgx"),
feature(fixed_size_array, maybe_uninit_extra)
)]
#![cfg_attr(all(test, target_vendor = "fortanix", target_env = "sgx"), feature(fixed_size_array))]
// std is implemented with unstable features, many of which are internal
// compiler details that will never be stable
// NB: the following list is sorted to minimize merge conflicts.
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/const-generics/const-argument-non-static-lifetime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// run-pass

#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete
#![allow(dead_code)]

fn test<const N: usize>() {}

fn wow<'a>() -> &'a () {
test::<{
let _: &'a ();
3
}>();
&()
}

fn main() {}
Loading