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 11 pull requests #54068

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d7a74be
Fix incorrect outer function type parameter message
estebank Sep 4, 2018
5238b52
Reword un-closed delimiter label
estebank Aug 27, 2018
008aa5a
Provide more context for unenclosed delimiters
estebank Sep 4, 2018
b2d2d83
Fix existing test
estebank Sep 5, 2018
3192d3d
Change wording of unclosed delimiter label
estebank Sep 5, 2018
941b2e3
slight rewording of labels
estebank Sep 5, 2018
bebecf8
reword label as per review
estebank Sep 5, 2018
308d197
Log when buffering a diagnostic.
davidtwco Sep 6, 2018
b45648b
De-duplicate moved variable errors.
davidtwco Sep 6, 2018
b9e7574
rustc_codegen_llvm: don't assume offsets are always aligned.
eddyb Sep 6, 2018
4088a38
Allow named lifetimes in async functions.
jkozlowski Sep 6, 2018
4b7f2eb
Fixup whitespace
jkozlowski Sep 6, 2018
0c89243
Fix compiling some rustc crates to wasm
alexcrichton Sep 7, 2018
d14a9c5
Don't promote const fn calls with arguments
oli-obk Aug 31, 2018
6a7175f
Check that min_const_fn doesn't promote functions with arguments
oli-obk Sep 4, 2018
9876ff6
Some `Sync` tests
oli-obk Sep 4, 2018
0a7a208
Ban promoting user defined const fns
oli-obk Sep 4, 2018
3abde0e
Don't autopromote const fns without arguments
oli-obk Sep 5, 2018
6eced55
Indent fix
oli-obk Sep 5, 2018
0765eb1
Add a test for `rustc_promotable`
oli-obk Sep 5, 2018
408f307
Do not promote calls to `NonZero*::new_unchecked`
oli-obk Sep 5, 2018
9da9ca5
Assert that no unsafe function is treated as promotable
oli-obk Sep 6, 2018
e0e7cf3
rustc_resolve: only prepend CrateRoot to a non-keyword segment.
eddyb Sep 6, 2018
449516f
rustc_resolve: inject `uniform_paths` canary always on Rust 2018.
eddyb Sep 6, 2018
e942e0e
Stabilize the 2018 edition
Mark-Simulacrum Sep 6, 2018
a0330f5
Remove crate_visibility_modifier from 2018 edition
Mark-Simulacrum Sep 6, 2018
0ec351d
`&CStr`, not `CStr`, is the counterpart of `&str`
nagisa Sep 8, 2018
3e56dec
submodules: update clippy, rls with crate visibility patches
matthiaskrgr Sep 8, 2018
4d187ae
Rollup merge of #53851 - oli-obk:local_promotion, r=eddyb
Mark-Simulacrum Sep 8, 2018
1e5e014
Rollup merge of #53949 - estebank:unclosed-delim, r=nikomatsakis
Mark-Simulacrum Sep 8, 2018
7c9b41a
Rollup merge of #53960 - estebank:issue-51303, r=nagisa
Mark-Simulacrum Sep 8, 2018
9a442e7
Rollup merge of #53988 - eddyb:issue-53770, r=petrochenkov
Mark-Simulacrum Sep 8, 2018
b15a146
Rollup merge of #53995 - davidtwco:issue-53807, r=nikomatsakis
Mark-Simulacrum Sep 8, 2018
a88d6fb
Rollup merge of #53998 - eddyb:issue-53728, r=oli-obk
Mark-Simulacrum Sep 8, 2018
0eb8ea9
Rollup merge of #54000 - jkozlowski:fix-53174, r=cramertj
Mark-Simulacrum Sep 8, 2018
10418e8
Rollup merge of #54011 - eddyb:anchored-in-the-future, r=petrochenkov
Mark-Simulacrum Sep 8, 2018
56ceb16
Rollup merge of #54024 - alexcrichton:compile-to-wasm, r=petrochenkov
Mark-Simulacrum Sep 8, 2018
870144f
Rollup merge of #54057 - matthiaskrgr:stabilize-edition-plus-clippy, …
Mark-Simulacrum Sep 8, 2018
b93b944
Rollup merge of #54064 - nagisa:tiny-typo, r=sfackler
Mark-Simulacrum Sep 8, 2018
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
1 change: 1 addition & 0 deletions src/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2173,6 +2173,7 @@ name = "rustc_errors"
version = "0.0.0"
dependencies = [
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_cratesio_shim 0.0.0",
"rustc_data_structures 0.0.0",
"serialize 0.0.0",
Expand Down
14 changes: 14 additions & 0 deletions src/doc/rustdoc/src/command-line-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,17 @@ $ rustdoc src/lib.rs --sysroot /path/to/sysroot

Similar to `rustc --sysroot`, this lets you change the sysroot `rustdoc` uses
when compiling your code.

### `--edition`: control the edition of docs and doctests

Using this flag looks like this:

```bash
$ rustdoc src/lib.rs --edition 2018
$ rustdoc --test src/lib.rs --edition 2018
```

This flag allows rustdoc to treat your rust code as the given edition. It will compile doctests with
the given edition as well. As with `rustc`, the default edition that `rustdoc` will use is `2015`
(the first edition).

13 changes: 0 additions & 13 deletions src/doc/rustdoc/src/unstable-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,19 +346,6 @@ details.

[issue-display-warnings]: https://github.com/rust-lang/rust/issues/41574

### `--edition`: control the edition of docs and doctests

Using this flag looks like this:

```bash
$ rustdoc src/lib.rs -Z unstable-options --edition 2018
$ rustdoc --test src/lib.rs -Z unstable-options --edition 2018
```

This flag allows rustdoc to treat your rust code as the given edition. It will compile doctests with
the given edition as well. As with `rustc`, the default edition that `rustdoc` will use is `2015`
(the first edition).

### `--extern-html-root-url`: control how rustdoc links to non-local crates

Using this flag looks like this:
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ pub fn forget<T>(t: T) {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg(not(stage0))]
#[rustc_promotable]
pub const fn size_of<T>() -> usize {
intrinsics::size_of::<T>()
}
Expand Down Expand Up @@ -396,6 +397,7 @@ pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg(not(stage0))]
#[rustc_promotable]
pub const fn align_of<T>() -> usize {
intrinsics::min_align_of::<T>()
}
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ $EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
#[cfg_attr(not(stage0), rustc_promotable)]
pub const fn min_value() -> Self {
!0 ^ ((!0 as $UnsignedT) >> 1) as Self
}
Expand All @@ -224,6 +225,7 @@ $EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
#[cfg_attr(not(stage0), rustc_promotable)]
pub const fn max_value() -> Self {
!Self::min_value()
}
Expand Down
1 change: 1 addition & 0 deletions src/libcore/ops/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ impl<Idx> RangeInclusive<Idx> {
/// ```
#[stable(feature = "inclusive_range_methods", since = "1.27.0")]
#[inline]
#[cfg_attr(not(stage0), rustc_promotable)]
pub const fn new(start: Idx, end: Idx) -> Self {
Self { start, end, is_empty: None }
}
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(stage0), rustc_promotable)]
pub const fn null<T>() -> *const T { 0 as *const T }

/// Creates a null mutable raw pointer.
Expand All @@ -88,6 +89,7 @@ pub const fn null<T>() -> *const T { 0 as *const T }
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(stage0), rustc_promotable)]
pub const fn null_mut<T>() -> *mut T { 0 as *mut T }

/// Swaps the values at two mutable locations of the same type, without
Expand Down
4 changes: 4 additions & 0 deletions src/libcore/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl Duration {
/// ```
#[stable(feature = "duration", since = "1.3.0")]
#[inline]
#[cfg_attr(not(stage0), rustc_promotable)]
pub const fn from_secs(secs: u64) -> Duration {
Duration { secs, nanos: 0 }
}
Expand All @@ -126,6 +127,7 @@ impl Duration {
/// ```
#[stable(feature = "duration", since = "1.3.0")]
#[inline]
#[cfg_attr(not(stage0), rustc_promotable)]
pub const fn from_millis(millis: u64) -> Duration {
Duration {
secs: millis / MILLIS_PER_SEC,
Expand All @@ -147,6 +149,7 @@ impl Duration {
/// ```
#[stable(feature = "duration_from_micros", since = "1.27.0")]
#[inline]
#[cfg_attr(not(stage0), rustc_promotable)]
pub const fn from_micros(micros: u64) -> Duration {
Duration {
secs: micros / MICROS_PER_SEC,
Expand All @@ -168,6 +171,7 @@ impl Duration {
/// ```
#[stable(feature = "duration_extras", since = "1.27.0")]
#[inline]
#[cfg_attr(not(stage0), rustc_promotable)]
pub const fn from_nanos(nanos: u64) -> Duration {
Duration {
secs: nanos / (NANOS_PER_SEC as u64),
Expand Down
1 change: 1 addition & 0 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ define_dep_nodes!( <'tcx>
[] ItemVarianceConstraints(DefId),
[] ItemVariances(DefId),
[] IsConstFn(DefId),
[] IsPromotableConstFn(DefId),
[] IsForeignItem(DefId),
[] TypeParamPredicates { item_id: DefId, param_id: DefId },
[] SizedConstraint(DefId),
Expand Down
57 changes: 37 additions & 20 deletions src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,38 @@ impl<'a> DefCollector<'a> {
fn visit_async_fn(
&mut self,
id: NodeId,
async_node_id: NodeId,
return_impl_trait_id: NodeId,
name: Name,
span: Span,
visit_fn: impl FnOnce(&mut DefCollector<'a>)
header: &FnHeader,
generics: &'a Generics,
decl: &'a FnDecl,
body: &'a Block,
) {
let (closure_id, return_impl_trait_id) = match header.asyncness {
IsAsync::Async {
closure_id,
return_impl_trait_id,
} => (closure_id, return_impl_trait_id),
_ => unreachable!(),
};

// For async functions, we need to create their inner defs inside of a
// closure to match their desugared representation.
let fn_def_data = DefPathData::ValueNs(name.as_interned_str());
let fn_def = self.create_def(id, fn_def_data, ITEM_LIKE_SPACE, span);
return self.with_parent(fn_def, |this| {
this.create_def(return_impl_trait_id, DefPathData::ImplTrait, REGULAR_SPACE, span);
let closure_def = this.create_def(async_node_id,

visit::walk_generics(this, generics);
visit::walk_fn_decl(this, decl);

let closure_def = this.create_def(closure_id,
DefPathData::ClosureExpr,
REGULAR_SPACE,
span);
this.with_parent(closure_def, visit_fn)
this.with_parent(closure_def, |this| {
visit::walk_block(this, body);
})
})
}

Expand Down Expand Up @@ -122,17 +137,20 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
ItemKind::Mod(..) if i.ident == keywords::Invalid.ident() => {
return visit::walk_item(self, i);
}
ItemKind::Fn(_, FnHeader { asyncness: IsAsync::Async {
closure_id,
return_impl_trait_id,
}, .. }, ..) => {
ItemKind::Fn(
ref decl,
ref header @ FnHeader { asyncness: IsAsync::Async { .. }, .. },
ref generics,
ref body,
) => {
return self.visit_async_fn(
i.id,
closure_id,
return_impl_trait_id,
i.ident.name,
i.span,
|this| visit::walk_item(this, i)
header,
generics,
decl,
body,
)
}
ItemKind::Mod(..) => DefPathData::Module(i.ident.as_interned_str()),
Expand Down Expand Up @@ -233,18 +251,17 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
fn visit_impl_item(&mut self, ii: &'a ImplItem) {
let def_data = match ii.node {
ImplItemKind::Method(MethodSig {
header: FnHeader { asyncness: IsAsync::Async {
closure_id,
return_impl_trait_id,
}, .. }, ..
}, ..) => {
header: ref header @ FnHeader { asyncness: IsAsync::Async { .. }, .. },
ref decl,
}, ref body) => {
return self.visit_async_fn(
ii.id,
closure_id,
return_impl_trait_id,
ii.ident.name,
ii.span,
|this| visit::walk_impl_item(this, ii)
header,
&ii.generics,
decl,
body,
)
}
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
Expand Down
1 change: 1 addition & 0 deletions src/librustc/ich/impls_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ impl_stable_hash_for!(struct ::syntax::attr::Stability {
level,
feature,
rustc_depr,
promotable,
const_stability
});

Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ impl<'a, 'tcx> Index<'tcx> {
feature: Symbol::intern("rustc_private"),
rustc_depr: None,
const_stability: None,
promotable: false,
});
annotator.parent_stab = Some(stability);
}
Expand Down
110 changes: 110 additions & 0 deletions src/librustc/ty/constness.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
use ty::query::Providers;
use hir::def_id::DefId;
use hir;
use ty::TyCtxt;
use syntax_pos::symbol::Symbol;
use hir::map::blocks::FnLikeNode;
use syntax::attr;
use rustc_target::spec::abi;

impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
/// Whether the `def_id` counts as const fn in your current crate, considering all active
/// feature gates
pub fn is_const_fn(self, def_id: DefId) -> bool {
self.is_const_fn_raw(def_id) && match self.lookup_stability(def_id) {
Some(stab) => match stab.const_stability {
// has a `rustc_const_unstable` attribute, check whether the user enabled the
// corresponding feature gate
Some(feature_name) => self.features()
.declared_lib_features
.iter()
.any(|&(sym, _)| sym == feature_name),
// the function has no stability attribute, it is stable as const fn or the user
// nees to use feature gates to use the function at all
None => true,
},
// functions without stability are either stable user written const fn or the user is
// using feature gates and we thus don't care what they do
None => true,
}
}

/// Whether the `def_id` is an unstable const fn and what feature gate is necessary to enable it
pub fn is_unstable_const_fn(self, def_id: DefId) -> Option<Symbol> {
if self.is_const_fn_raw(def_id) {
self.lookup_stability(def_id)?.const_stability
} else {
None
}
}

/// Returns true if this function must conform to `min_const_fn`
pub fn is_min_const_fn(self, def_id: DefId) -> bool {
if self.features().staged_api {
// some intrinsics are waved through if called inside the
// standard library. Users never need to call them directly
if let abi::Abi::RustIntrinsic = self.fn_sig(def_id).abi() {
assert!(!self.is_const_fn(def_id));
match &self.item_name(def_id).as_str()[..] {
| "size_of"
| "min_align_of"
=> return true,
_ => {},
}
}
// in order for a libstd function to be considered min_const_fn
// it needs to be stable and have no `rustc_const_unstable` attribute
match self.lookup_stability(def_id) {
// stable functions with unstable const fn aren't `min_const_fn`
Some(&attr::Stability { const_stability: Some(_), .. }) => false,
// unstable functions don't need to conform
Some(&attr::Stability { ref level, .. }) if level.is_unstable() => false,
// everything else needs to conform, because it would be callable from
// other `min_const_fn` functions
_ => true,
}
} else {
// users enabling the `const_fn` can do what they want
!self.sess.features_untracked().const_fn
}
}
}


pub fn provide<'tcx>(providers: &mut Providers<'tcx>) {
/// only checks whether the function has a `const` modifier
fn is_const_fn_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
let node_id = tcx.hir.as_local_node_id(def_id)
.expect("Non-local call to local provider is_const_fn");

if let Some(fn_like) = FnLikeNode::from_node(tcx.hir.get(node_id)) {
fn_like.constness() == hir::Constness::Const
} else {
false
}
}

fn is_promotable_const_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
tcx.is_const_fn(def_id) && match tcx.lookup_stability(def_id) {
Some(stab) => {
if cfg!(debug_assertions) && stab.promotable {
let sig = tcx.fn_sig(def_id);
assert_eq!(
sig.unsafety(),
hir::Unsafety::Normal,
"don't mark const unsafe fns as promotable",
// https://github.com/rust-lang/rust/pull/53851#issuecomment-418760682
);
}
stab.promotable
},
None => false,
}
}

*providers = Providers {
is_const_fn_raw,
is_promotable_const_fn,
..*providers
};
}
Loading