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 #51930

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
30d825c
Fix doc links
MajorBreakfast Jun 27, 2018
64f8e3b
Update liblibc
est31 Jun 28, 2018
fb58db4
Require type is sized in wfcheck.check_item_type for externed DSTs, c…
krk Jun 28, 2018
cd8ca26
Point at lifetimes instead of def span for E0195
estebank Jun 27, 2018
5436a5c
Point to lifetime in fn definition on lifetime error note
estebank Jun 27, 2018
3005162
Extend support to `get_generics` for all `NodeItem`s
estebank Jun 27, 2018
03bcebb
Also point to free named region on lifetime errors
estebank Jun 28, 2018
9a9b747
review comments: unify duplicated code
estebank Jun 28, 2018
8449c5a
Fix rebase
estebank Jun 28, 2018
23d59d0
Suggest correct comparison against negative literal
estebank Jun 28, 2018
d6cf182
Fix inconsequential typo in GlobalAlloc doc example
Ixrec Jun 29, 2018
52b7eb9
Do not allow LLVM to increase a TLS's alignment on macOS.
kennytm Jun 27, 2018
0250302
Implement PartialEq between &str and OsString
GabrielMajeri May 29, 2018
fdcee4d
Fix stability attributes
GabrielMajeri May 30, 2018
fbd3c92
Add run-pass test
GabrielMajeri Jun 5, 2018
28c4813
use literal span for concrete type suggestion
euclio Jun 29, 2018
faaf250
improve the error message when `#[panic_implementation]` is missing
japaric Jun 29, 2018
ee52862
update another cfail test
japaric Jun 29, 2018
1328bde
resolve: Cleanup `resolve_crate_root`
petrochenkov Jun 24, 2018
09856c8
expansion: Give names to some fields of `SyntaxExtension`
petrochenkov Jun 24, 2018
99ecdb3
hygiene: Implement transparent marks
petrochenkov Jun 24, 2018
297109e
proc-macro: Use transparent marks for call-site hygiene
petrochenkov Jun 24, 2018
9f92fce
Fortify dummy span checking
petrochenkov Jun 24, 2018
b69d511
Restore the old behavior of `$crate` in nested `macro_rules`
petrochenkov Jun 29, 2018
84f1bc8
Address comments
petrochenkov Jun 29, 2018
12247fd
Rollup merge of #51178 - GabrielMajeri:os-str-compare, r=SimonSapin
Mark-Simulacrum Jun 30, 2018
d562bff
Rollup merge of #51762 - petrochenkov:oh-hi-mark, r=oli-obk
Mark-Simulacrum Jun 30, 2018
8c30769
Rollup merge of #51828 - kennytm:no-simd-swap-for-mac, r=alexcrichton
Mark-Simulacrum Jun 30, 2018
4b6d98d
Rollup merge of #51853 - MajorBreakfast:fix-doc-links, r=cramertj
Mark-Simulacrum Jun 30, 2018
b3f8989
Rollup merge of #51862 - estebank:lifetime-spans, r=nikomatsakis
Mark-Simulacrum Jun 30, 2018
bea664b
Rollup merge of #51864 - est31:libc_update, r=alexcrichton
Mark-Simulacrum Jun 30, 2018
de85644
Rollup merge of #51867 - krk:issue-36122, r=petrochenkov
Mark-Simulacrum Jun 30, 2018
2223cc8
Rollup merge of #51883 - estebank:placement-suggestion, r=varkor
Mark-Simulacrum Jun 30, 2018
cf957c8
Rollup merge of #51890 - Ixrec:patch-3, r=alexcrichton
Mark-Simulacrum Jun 30, 2018
b50a6ba
Rollup merge of #51920 - euclio:concrete-type-suggestion, r=estebank
Mark-Simulacrum Jun 30, 2018
b7bd4aa
Rollup merge of #51921 - japaric:panic-impl-error, r=nagisa
Mark-Simulacrum Jun 30, 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
14 changes: 9 additions & 5 deletions src/libcore/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ pub trait Future {
///
/// This function returns:
///
/// - `Poll::Pending` if the future is not ready yet
/// - `Poll::Ready(val)` with the result `val` of this future if it finished
/// successfully.
/// - [`Poll::Pending`] if the future is not ready yet
/// - [`Poll::Ready(val)`] with the result `val` of this future if it
/// finished successfully.
///
/// Once a future has finished, clients should not `poll` it again.
///
/// When a future is not ready yet, `poll` returns
/// [`Poll::Pending`](::task::Poll). The future will *also* register the
/// `Poll::Pending`. The future will *also* register the
/// interest of the current task in the value being produced. For example,
/// if the future represents the availability of data on a socket, then the
/// task is recorded so that when data arrives, it is woken up (via
/// [`cx.waker()`](::task::Context::waker)). Once a task has been woken up,
/// [`cx.waker()`]). Once a task has been woken up,
/// it should attempt to `poll` the future again, which may or may not
/// produce a final value.
///
Expand Down Expand Up @@ -90,6 +90,10 @@ pub trait Future {
/// then any future calls to `poll` may panic, block forever, or otherwise
/// cause bad behavior. The `Future` trait itself provides no guarantees
/// about the behavior of `poll` after a future has completed.
///
/// [`Poll::Pending`]: ../task/enum.Poll.html#variant.Pending
/// [`Poll::Ready(val)`]: ../task/enum.Poll.html#variant.Ready
/// [`cx.waker()`]: ../task/struct.Context.html#method.waker
fn poll(self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output>;
}

Expand Down
2 changes: 1 addition & 1 deletion src/liblibc
Submodule liblibc updated 48 files
+5 −2 .travis.yml
+54 −74 Cargo.lock
+1 −1 Cargo.toml
+21 −21 README.md
+1 −1 ci/linux-sparc64.sh
+3 −1 ci/style.rs
+17 −2 libc-test/build.rs
+63 −5 src/dox.rs
+2 −0 src/fuchsia/mod.rs
+25 −27 src/lib.rs
+34 −0 src/redox/mod.rs
+12 −0 src/redox/net.rs
+33 −2 src/unix/bsd/apple/mod.rs
+2 −0 src/unix/bsd/freebsdlike/freebsd/mod.rs
+24 −4 src/unix/bsd/freebsdlike/mod.rs
+27 −4 src/unix/bsd/netbsdlike/mod.rs
+9 −0 src/unix/bsd/netbsdlike/netbsd/mod.rs
+2 −0 src/unix/bsd/netbsdlike/openbsdlike/bitrig/mod.rs
+3 −0 src/unix/bsd/netbsdlike/openbsdlike/mod.rs
+4 −0 src/unix/bsd/netbsdlike/openbsdlike/openbsd/mod.rs
+27 −4 src/unix/haiku/mod.rs
+15 −0 src/unix/mod.rs
+0 −16 src/unix/notbsd/android/b32/mod.rs
+0 −25 src/unix/notbsd/android/b64/mod.rs
+111 −23 src/unix/notbsd/android/mod.rs
+15 −27 src/unix/notbsd/emscripten.rs
+71 −3 src/unix/notbsd/linux/mips/mips32.rs
+70 −0 src/unix/notbsd/linux/mips/mips64.rs
+21 −20 src/unix/notbsd/linux/mips/mod.rs
+148 −50 src/unix/notbsd/linux/mod.rs
+74 −0 src/unix/notbsd/linux/musl/b32/mod.rs
+0 −62 src/unix/notbsd/linux/musl/b64/mod.rs
+143 −12 src/unix/notbsd/linux/musl/b64/powerpc64.rs
+136 −0 src/unix/notbsd/linux/musl/b64/x86_64.rs
+20 −74 src/unix/notbsd/linux/musl/mod.rs
+71 −0 src/unix/notbsd/linux/other/b32/mod.rs
+43 −0 src/unix/notbsd/linux/other/b64/aarch64.rs
+72 −0 src/unix/notbsd/linux/other/b64/not_x32.rs
+70 −0 src/unix/notbsd/linux/other/b64/powerpc64.rs
+77 −0 src/unix/notbsd/linux/other/b64/sparc64.rs
+42 −0 src/unix/notbsd/linux/other/b64/x32.rs
+4 −0 src/unix/notbsd/linux/other/b64/x86_64.rs
+42 −20 src/unix/notbsd/linux/other/mod.rs
+41 −0 src/unix/notbsd/linux/s390x.rs
+200 −2 src/unix/notbsd/mod.rs
+2 −2 src/unix/solaris/mod.rs
+367 −2 src/unix/uclibc/mips/mips32.rs
+5 −2 src/unix/uclibc/mod.rs
2 changes: 1 addition & 1 deletion src/libproc_macro/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Diagnostic {
/// Emit the diagnostic.
#[unstable(feature = "proc_macro", issue = "38356")]
pub fn emit(self) {
::__internal::with_sess(move |(sess, _)| {
::__internal::with_sess(move |sess, _| {
let handler = &sess.span_diagnostic;
let level = __internal::level_to_internal_level(self.level);
let mut diag = rustc::DiagnosticBuilder::new(handler, level, &*self.message);
Expand Down
95 changes: 58 additions & 37 deletions src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ use syntax::parse::{self, token};
use syntax::symbol::{keywords, Symbol};
use syntax::tokenstream;
use syntax::parse::lexer::{self, comments};
use syntax_pos::{FileMap, Pos, SyntaxContext, FileName};
use syntax_pos::hygiene::Mark;
use syntax_pos::{FileMap, Pos, FileName};

/// The main type provided by this crate, representing an abstract stream of
/// tokens, or, more specifically, a sequence of token trees.
Expand Down Expand Up @@ -109,6 +108,7 @@ impl TokenStream {
/// Attempts to break the string into tokens and parse those tokens into a token stream.
/// May fail for a number of reasons, for example, if the string contains unbalanced delimiters
/// or characters not existing in the language.
/// All tokens in the parsed stream get `Span::call_site()` spans.
///
/// NOTE: Some errors may cause panics instead of returning `LexError`. We reserve the right to
/// change these errors into `LexError`s later.
Expand All @@ -117,17 +117,10 @@ impl FromStr for TokenStream {
type Err = LexError;

fn from_str(src: &str) -> Result<TokenStream, LexError> {
__internal::with_sess(|(sess, mark)| {
let src = src.to_string();
let name = FileName::ProcMacroSourceCode;
let expn_info = mark.expn_info().unwrap();
let call_site = expn_info.call_site;
// notify the expansion info that it is unhygienic
let mark = Mark::fresh(mark);
mark.set_expn_info(expn_info);
let span = call_site.with_ctxt(SyntaxContext::empty().apply_mark(mark));
let stream = parse::parse_stream_from_source_str(name, src, sess, Some(span));
Ok(__internal::token_stream_wrap(stream))
__internal::with_sess(|sess, data| {
Ok(__internal::token_stream_wrap(parse::parse_stream_from_source_str(
FileName::ProcMacroSourceCode, src.to_string(), sess, Some(data.call_site.0)
)))
})
}
}
Expand Down Expand Up @@ -184,8 +177,6 @@ impl iter::FromIterator<TokenStream> for TokenStream {
#[unstable(feature = "proc_macro", issue = "38356")]
pub mod token_stream {
use syntax::tokenstream;
use syntax_pos::DUMMY_SP;

use {TokenTree, TokenStream, Delimiter};

/// An iterator over `TokenStream`'s `TokenTree`s.
Expand Down Expand Up @@ -214,7 +205,7 @@ pub mod token_stream {
// need to flattened during iteration over stream's token trees.
// Eventually this needs to be removed in favor of keeping original token trees
// and not doing the roundtrip through AST.
if tree.span().0 == DUMMY_SP {
if tree.span().0.is_dummy() {
if let TokenTree::Group(ref group) = tree {
if group.delimiter() == Delimiter::None {
self.cursor.insert(group.stream.clone().0);
Expand Down Expand Up @@ -284,10 +275,7 @@ impl Span {
/// A span that resolves at the macro definition site.
#[unstable(feature = "proc_macro", issue = "38356")]
pub fn def_site() -> Span {
::__internal::with_sess(|(_, mark)| {
let call_site = mark.expn_info().unwrap().call_site;
Span(call_site.with_ctxt(SyntaxContext::empty().apply_mark(mark)))
})
::__internal::with_sess(|_, data| data.def_site)
}

/// The span of the invocation of the current procedural macro.
Expand All @@ -296,7 +284,7 @@ impl Span {
/// at the macro call site will be able to refer to them as well.
#[unstable(feature = "proc_macro", issue = "38356")]
pub fn call_site() -> Span {
::__internal::with_sess(|(_, mark)| Span(mark.expn_info().unwrap().call_site))
::__internal::with_sess(|_, data| data.call_site)
}

/// The original source file into which this span points.
Expand Down Expand Up @@ -1243,7 +1231,7 @@ impl TokenTree {
}

Interpolated(_) => {
__internal::with_sess(|(sess, _)| {
__internal::with_sess(|sess, _| {
let tts = token.interpolated_to_tokenstream(sess, span);
tt!(Group::new(Delimiter::None, TokenStream(tts)))
})
Expand Down Expand Up @@ -1354,20 +1342,21 @@ pub mod __internal {
pub use quote::{LiteralKind, SpannedSymbol, Quoter, unquote};

use std::cell::Cell;
use std::ptr;

use syntax::ast;
use syntax::ext::base::ExtCtxt;
use syntax::ext::hygiene::Mark;
use syntax::ptr::P;
use syntax::parse::{self, ParseSess};
use syntax::parse::token::{self, Token};
use syntax::tokenstream;
use syntax_pos::{BytePos, Loc, DUMMY_SP};
use syntax_pos::hygiene::{Mark, SyntaxContext, Transparency};

use super::{TokenStream, LexError};
use super::{TokenStream, LexError, Span};

pub fn lookup_char_pos(pos: BytePos) -> Loc {
with_sess(|(sess, _)| sess.codemap().lookup_char_pos(pos))
with_sess(|sess, _| sess.codemap().lookup_char_pos(pos))
}

pub fn new_token_stream(item: P<ast::Item>) -> TokenStream {
Expand All @@ -1380,7 +1369,7 @@ pub mod __internal {
}

pub fn token_stream_parse_items(stream: TokenStream) -> Result<Vec<P<ast::Item>>, LexError> {
with_sess(move |(sess, _)| {
with_sess(move |sess, _| {
let mut parser = parse::stream_to_parser(sess, stream.0);
let mut items = Vec::new();

Expand Down Expand Up @@ -1411,16 +1400,30 @@ pub mod __internal {
expand: fn(TokenStream) -> TokenStream);
}

#[derive(Clone, Copy)]
pub struct ProcMacroData {
pub def_site: Span,
pub call_site: Span,
}

#[derive(Clone, Copy)]
struct ProcMacroSess {
parse_sess: *const ParseSess,
data: ProcMacroData,
}

// Emulate scoped_thread_local!() here essentially
thread_local! {
static CURRENT_SESS: Cell<(*const ParseSess, Mark)> =
Cell::new((0 as *const _, Mark::root()));
static CURRENT_SESS: Cell<ProcMacroSess> = Cell::new(ProcMacroSess {
parse_sess: ptr::null(),
data: ProcMacroData { def_site: Span(DUMMY_SP), call_site: Span(DUMMY_SP) },
});
}

pub fn set_sess<F, R>(cx: &ExtCtxt, f: F) -> R
where F: FnOnce() -> R
{
struct Reset { prev: (*const ParseSess, Mark) }
struct Reset { prev: ProcMacroSess }

impl Drop for Reset {
fn drop(&mut self) {
Expand All @@ -1430,24 +1433,42 @@ pub mod __internal {

CURRENT_SESS.with(|p| {
let _reset = Reset { prev: p.get() };
p.set((cx.parse_sess, cx.current_expansion.mark));

// No way to determine def location for a proc macro right now, so use call location.
let location = cx.current_expansion.mark.expn_info().unwrap().call_site;
// Opaque mark was already created by expansion, now create its transparent twin.
// We can't use the call-site span literally here, even if it appears to provide
// correct name resolution, because it has all the `ExpnInfo` wrong, so the edition
// checks, lint macro checks, macro backtraces will all break.
let opaque_mark = cx.current_expansion.mark;
let transparent_mark = Mark::fresh_cloned(opaque_mark);
transparent_mark.set_transparency(Transparency::Transparent);

let to_span = |mark| Span(location.with_ctxt(SyntaxContext::empty().apply_mark(mark)));
p.set(ProcMacroSess {
parse_sess: cx.parse_sess,
data: ProcMacroData {
def_site: to_span(opaque_mark),
call_site: to_span(transparent_mark),
},
});
f()
})
}

pub fn in_sess() -> bool
{
let p = CURRENT_SESS.with(|p| p.get());
!p.0.is_null()
!CURRENT_SESS.with(|sess| sess.get()).parse_sess.is_null()
}

pub fn with_sess<F, R>(f: F) -> R
where F: FnOnce((&ParseSess, Mark)) -> R
where F: FnOnce(&ParseSess, &ProcMacroData) -> R
{
let p = CURRENT_SESS.with(|p| p.get());
assert!(!p.0.is_null(), "proc_macro::__internal::with_sess() called \
before set_parse_sess()!");
f(unsafe { (&*p.0, p.1) })
let sess = CURRENT_SESS.with(|sess| sess.get());
if sess.parse_sess.is_null() {
panic!("procedural macro API is used outside of a procedural macro");
}
f(unsafe { &*sess.parse_sess }, &sess.data)
}
}

Expand Down
11 changes: 3 additions & 8 deletions src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,12 +486,7 @@ impl Definitions {
#[inline]
pub fn opt_span(&self, def_id: DefId) -> Option<Span> {
if def_id.krate == LOCAL_CRATE {
let span = self.def_index_to_span.get(&def_id.index).cloned().unwrap_or(DUMMY_SP);
if span != DUMMY_SP {
Some(span)
} else {
None
}
self.def_index_to_span.get(&def_id.index).cloned()
} else {
None
}
Expand Down Expand Up @@ -588,8 +583,8 @@ impl Definitions {
self.opaque_expansions_that_defined.insert(index, expansion);
}

// The span is added if it isn't DUMMY_SP
if span != DUMMY_SP {
// The span is added if it isn't dummy
if !span.is_dummy() {
self.def_index_to_span.insert(index, span);
}

Expand Down
29 changes: 28 additions & 1 deletion src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use rustc_target::spec::abi::Abi;
use syntax::ast::{self, Name, NodeId, CRATE_NODE_ID};
use syntax::codemap::Spanned;
use syntax::ext::base::MacroKind;
use syntax_pos::Span;
use syntax_pos::{Span, DUMMY_SP};

use hir::*;
use hir::print::Nested;
Expand Down Expand Up @@ -664,6 +664,33 @@ impl<'hir> Map<'hir> {
self.as_local_node_id(id).map(|id| self.get(id)) // read recorded by `get`
}

pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics> {
self.get_if_local(id).and_then(|node| {
match node {
NodeImplItem(ref impl_item) => Some(&impl_item.generics),
NodeTraitItem(ref trait_item) => Some(&trait_item.generics),
NodeItem(ref item) => {
match item.node {
ItemFn(_, _, ref generics, _) |
ItemTy(_, ref generics) |
ItemEnum(_, ref generics) |
ItemStruct(_, ref generics) |
ItemUnion(_, ref generics) |
ItemTrait(_, _, ref generics, ..) |
ItemTraitAlias(ref generics, _) |
ItemImpl(_, _, _, ref generics, ..) => Some(generics),
_ => None,
}
}
_ => None,
}
})
}

pub fn get_generics_span(&self, id: DefId) -> Option<Span> {
self.get_generics(id).map(|generics| generics.span).filter(|sp| *sp != DUMMY_SP)
}

/// Retrieve the Node corresponding to `id`, returning None if
/// cannot be found.
pub fn find(&self, id: NodeId) -> Option<Node<'hir>> {
Expand Down
11 changes: 10 additions & 1 deletion src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
use util::nodemap::{NodeMap, FxHashSet};
use mir::mono::Linkage;

use syntax_pos::{Span, DUMMY_SP};
use syntax_pos::{Span, DUMMY_SP, symbol::InternedString};
use syntax::codemap::{self, Spanned};
use rustc_target::spec::abi::Abi;
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, DUMMY_NODE_ID, AsmDialect};
Expand Down Expand Up @@ -547,6 +547,15 @@ impl Generics {

own_counts
}

pub fn get_named(&self, name: &InternedString) -> Option<&GenericParam> {
for param in &self.params {
if *name == param.name.ident().as_interned_str() {
return Some(param);
}
}
None
}
}

/// Synthetic Type Parameters are converted to an other form during lowering, this allows
Expand Down
28 changes: 23 additions & 5 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self,
region: ty::Region<'tcx>,
) -> (String, Option<Span>) {
let cm = self.sess.codemap();

let scope = region.free_region_binding_scope(self);
let node = self.hir.as_local_node_id(scope).unwrap_or(DUMMY_NODE_ID);
let unknown;
Expand Down Expand Up @@ -219,10 +221,26 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}
};
let (prefix, span) = match *region {
ty::ReEarlyBound(ref br) => (
format!("the lifetime {} as defined on", br.name),
self.sess.codemap().def_span(self.hir.span(node)),
),
ty::ReEarlyBound(ref br) => {
let mut sp = cm.def_span(self.hir.span(node));
if let Some(param) = self.hir.get_generics(scope).and_then(|generics| {
generics.get_named(&br.name)
}) {
sp = param.span;
}
(format!("the lifetime {} as defined on", br.name), sp)
}
ty::ReFree(ty::FreeRegion {
bound_region: ty::BoundRegion::BrNamed(_, ref name), ..
}) => {
let mut sp = cm.def_span(self.hir.span(node));
if let Some(param) = self.hir.get_generics(scope).and_then(|generics| {
generics.get_named(&name)
}) {
sp = param.span;
}
(format!("the lifetime {} as defined on", name), sp)
}
ty::ReFree(ref fr) => match fr.bound_region {
ty::BrAnon(idx) => (
format!("the anonymous lifetime #{} defined on", idx + 1),
Expand All @@ -234,7 +252,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
),
_ => (
format!("the lifetime {} as defined on", fr.bound_region),
self.sess.codemap().def_span(self.hir.span(node)),
cm.def_span(self.hir.span(node)),
),
},
_ => bug!(),
Expand Down
Loading