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 6 pull requests #56623

Merged
merged 14 commits into from
Dec 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/doc/unstable-book/src/language-features/generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ closure-like semantics. Namely:
* Whenever a generator is dropped it will drop all captured environment
variables.

Note that unlike closures generators at this time cannot take any arguments.
Note that unlike closures, generators at this time cannot take any arguments.
That is, generators must always look like `|| { ... }`. This restriction may be
lifted at a future date, the design is ongoing!

Expand Down
2 changes: 2 additions & 0 deletions src/libcore/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl fmt::Debug for c_void {
/// Basic implementation of a `va_list`.
#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"),
not(target_arch = "x86_64")),
all(target_arch = "aarch4", target_os = "ios"),
windows))]
#[unstable(feature = "c_variadic",
reason = "the `c_variadic` feature has not been properly tested on \
Expand Down Expand Up @@ -192,6 +193,7 @@ impl<'a> VaList<'a> {
where F: for<'copy> FnOnce(VaList<'copy>) -> R {
#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"),
not(target_arch = "x86_64")),
all(target_arch = "aarch4", target_os = "ios"),
windows))]
let mut ap = va_copy(self);
#[cfg(all(any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"),
Expand Down
7 changes: 5 additions & 2 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2516,8 +2516,11 @@ pub fn eq<T: ?Sized>(a: *const T, b: *const T) -> bool {
a == b
}

/// Hash the raw pointer address behind a reference, rather than the value
/// it points to.
/// Hash a raw pointer.
///
/// This can be used to hash a `&T` reference (which coerces to `*const T` implicitly)
/// by its address rather than the value it points to
/// (which is what the `Hash for &T` implementation does).
///
/// # Examples
///
Expand Down
8 changes: 7 additions & 1 deletion src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,13 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
arg_align_attributes: bool = (false, parse_bool, [TRACKED],
"emit align metadata for reference arguments"),
dump_mir: Option<String> = (None, parse_opt_string, [UNTRACKED],
"dump MIR state at various points in transforms"),
"dump MIR state to file.
`val` is used to select which passes and functions to dump. For example:
`all` matches all passes and functions,
`foo` matches all passes for functions whose name contains 'foo',
`foo & ConstProp` only the 'ConstProp' pass for function names containing 'foo',
`foo | bar` all passes for function names containing 'foo' or 'bar'."),

dump_mir_dir: String = (String::from("mir_dump"), parse_string, [UNTRACKED],
"the directory the MIR is dumped into"),
dump_mir_graphviz: bool = (false, parse_bool, [UNTRACKED],
Expand Down
36 changes: 26 additions & 10 deletions src/librustc_codegen_llvm/va_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,30 @@ pub(super) fn emit_va_arg(
) -> &'ll Value {
// Determine the va_arg implementation to use. The LLVM va_arg instruction
// is lacking in some instances, so we should only use it as a fallback.
let target = &bx.cx.tcx.sess.target.target;
let arch = &bx.cx.tcx.sess.target.target.arch;
match (&**arch,
bx.cx.tcx.sess.target.target.options.is_like_windows) {
match (&**arch, target.options.is_like_windows) {
// Windows x86
("x86", true) => {
emit_ptr_va_arg(bx, addr, target_ty, false,
Align::from_bytes(4).unwrap(), false)
}
// Generic x86
("x86", _) => {
emit_ptr_va_arg(bx, addr, target_ty, false,
Align::from_bytes(4).unwrap(), true)
}
// Windows Aarch64
("aarch4", true) => {
emit_ptr_va_arg(bx, addr, target_ty, false,
Align::from_bytes(8).unwrap(), false)
}
// iOS Aarch64
("aarch4", _) if target.target_os == "ios" => {
emit_ptr_va_arg(bx, addr, target_ty, false,
Align::from_bytes(8).unwrap(), true)
}
// Windows x86_64
("x86_64", true) => {
let target_ty_size = bx.cx.size_of(target_ty).bytes();
let indirect = if target_ty_size > 8 || !target_ty_size.is_power_of_two() {
Expand All @@ -122,15 +139,14 @@ pub(super) fn emit_va_arg(
emit_ptr_va_arg(bx, addr, target_ty, indirect,
Align::from_bytes(8).unwrap(), false)
}
("x86", false) => {
emit_ptr_va_arg(bx, addr, target_ty, false,
Align::from_bytes(4).unwrap(), true)
}
// For all other architecture/OS combinations fall back to using
// the LLVM va_arg instruction.
// https://llvm.org/docs/LangRef.html#va-arg-instruction
_ => {
let va_list = if (bx.tcx().sess.target.target.arch == "aarch64" ||
bx.tcx().sess.target.target.arch == "x86_64" ||
bx.tcx().sess.target.target.arch == "powerpc") &&
!bx.tcx().sess.target.target.options.is_like_windows {
let va_list = if (target.arch == "aarch64" ||
target.arch == "x86_64" ||
target.arch == "powerpc") &&
!target.options.is_like_windows {
bx.load(addr.immediate(), bx.tcx().data_layout.pointer_align.abi)
} else {
addr.immediate()
Expand Down
42 changes: 23 additions & 19 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,14 +843,16 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
self.current_module = directive.parent_scope.module;

let orig_vis = directive.vis.replace(ty::Visibility::Invisible);
let prev_ambiguity_errors_len = self.ambiguity_errors.len();
let path_res = self.resolve_path(&directive.module_path, None, &directive.parent_scope,
true, directive.span, directive.crate_lint());
let no_ambiguity = self.ambiguity_errors.len() == prev_ambiguity_errors_len;
directive.vis.set(orig_vis);
let module = match path_res {
PathResult::Module(module) => {
// Consistency checks, analogous to `finalize_current_module_macro_resolutions`.
if let Some(initial_module) = directive.imported_module.get() {
if module != initial_module && self.ambiguity_errors.is_empty() {
if module != initial_module && no_ambiguity {
span_bug!(directive.span, "inconsistent resolution for an import");
}
} else {
Expand All @@ -864,30 +866,32 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
module
}
PathResult::Failed(span, msg, false) => {
assert!(!self.ambiguity_errors.is_empty() ||
directive.imported_module.get().is_none());
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
if no_ambiguity {
assert!(directive.imported_module.get().is_none());
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
}
return None;
}
PathResult::Failed(span, msg, true) => {
assert!(!self.ambiguity_errors.is_empty() ||
directive.imported_module.get().is_none());
return if let Some((suggested_path, note)) = self.make_path_suggestion(
span, directive.module_path.clone(), &directive.parent_scope
) {
Some((
span,
format!("did you mean `{}`?", Segment::names_to_string(&suggested_path)),
note,
))
} else {
Some((span, msg, None))
};
if no_ambiguity {
assert!(directive.imported_module.get().is_none());
return Some(match self.make_path_suggestion(span, directive.module_path.clone(),
&directive.parent_scope) {
Some((suggestion, note)) => (
span,
format!("did you mean `{}`?", Segment::names_to_string(&suggestion)),
note,
),
None => (span, msg, None),
});
}
return None;
}
PathResult::NonModule(path_res) if path_res.base_def() == Def::Err => {
if no_ambiguity {
assert!(directive.imported_module.get().is_none());
}
// The error was already reported earlier.
assert!(!self.ambiguity_errors.is_empty() ||
directive.imported_module.get().is_none());
return None;
}
PathResult::Indeterminate | PathResult::NonModule(..) => unreachable!(),
Expand Down
68 changes: 48 additions & 20 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5811,20 +5811,14 @@ impl<'a> Parser<'a> {
}

fn complain_if_pub_macro(&mut self, vis: &VisibilityKind, sp: Span) {
if let Err(mut err) = self.complain_if_pub_macro_diag(vis, sp) {
err.emit();
}
}

fn complain_if_pub_macro_diag(&mut self, vis: &VisibilityKind, sp: Span) -> PResult<'a, ()> {
match *vis {
VisibilityKind::Inherited => Ok(()),
VisibilityKind::Inherited => {}
_ => {
let is_macro_rules: bool = match self.token {
token::Ident(sid, _) => sid.name == Symbol::intern("macro_rules"),
_ => false,
};
if is_macro_rules {
let mut err = if is_macro_rules {
let mut err = self.diagnostic()
.struct_span_err(sp, "can't qualify macro_rules invocation with `pub`");
err.span_suggestion_with_applicability(
Expand All @@ -5833,13 +5827,14 @@ impl<'a> Parser<'a> {
"#[macro_export]".to_owned(),
Applicability::MaybeIncorrect // speculative
);
Err(err)
err
} else {
let mut err = self.diagnostic()
.struct_span_err(sp, "can't qualify macro invocation with `pub`");
err.help("try adjusting the macro to put `pub` inside the invocation");
Err(err)
}
err
};
err.emit();
}
}
}
Expand Down Expand Up @@ -6148,9 +6143,6 @@ impl<'a> Parser<'a> {

fn consume_block(&mut self, delim: token::DelimToken) {
let mut brace_depth = 0;
if !self.eat(&token::OpenDelim(delim)) {
return;
}
loop {
if self.eat(&token::OpenDelim(delim)) {
brace_depth += 1;
Expand All @@ -6161,7 +6153,7 @@ impl<'a> Parser<'a> {
brace_depth -= 1;
continue;
}
} else if self.eat(&token::Eof) || self.eat(&token::CloseDelim(token::NoDelim)) {
} else if self.token == token::Eof || self.eat(&token::CloseDelim(token::NoDelim)) {
return;
} else {
self.bump();
Expand Down Expand Up @@ -7410,17 +7402,27 @@ impl<'a> Parser<'a> {
return Err(err);
} else if self.look_ahead(1, |t| *t == token::OpenDelim(token::Paren)) {
let ident = self.parse_ident().unwrap();
self.bump(); // `(`
let kw_name = if let Ok(Some(_)) = self.parse_self_arg() {
"method"
} else {
"function"
};
self.consume_block(token::Paren);
let (kw, kw_name, ambiguous) = if self.check(&token::RArrow) ||
self.check(&token::OpenDelim(token::Brace))
{
("fn", "method", false)
let (kw, kw_name, ambiguous) = if self.check(&token::RArrow) {
self.eat_to_tokens(&[&token::OpenDelim(token::Brace)]);
self.bump(); // `{`
("fn", kw_name, false)
} else if self.check(&token::OpenDelim(token::Brace)) {
self.bump(); // `{`
("fn", kw_name, false)
} else if self.check(&token::Colon) {
let kw = "struct";
(kw, kw, false)
} else {
("fn` or `struct", "method or struct", true)
("fn` or `struct", "function or struct", true)
};
self.consume_block(token::Brace);

let msg = format!("missing `{}` for {} definition", kw, kw_name);
let mut err = self.diagnostic().struct_span_err(sp, &msg);
Expand All @@ -7447,6 +7449,32 @@ impl<'a> Parser<'a> {
}
}
return Err(err);
} else if self.look_ahead(1, |t| *t == token::Lt) {
let ident = self.parse_ident().unwrap();
self.eat_to_tokens(&[&token::Gt]);
self.bump(); // `>`
let (kw, kw_name, ambiguous) = if self.eat(&token::OpenDelim(token::Paren)) {
if let Ok(Some(_)) = self.parse_self_arg() {
("fn", "method", false)
} else {
("fn", "function", false)
}
} else if self.check(&token::OpenDelim(token::Brace)) {
("struct", "struct", false)
} else {
("fn` or `struct", "function or struct", true)
};
let msg = format!("missing `{}` for {} definition", kw, kw_name);
let mut err = self.diagnostic().struct_span_err(sp, &msg);
if !ambiguous {
err.span_suggestion_short_with_applicability(
sp,
&format!("add `{}` here to parse `{}` as a public {}", kw, ident, kw_name),
format!(" {} ", kw),
Applicability::MachineApplicable,
);
}
return Err(err);
}
}
self.parse_macro_use_or_failure(attrs, macros_allowed, attributes_allowed, lo, visibility)
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/imports/issue-56125.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
mod m1 {
use issue_56125::last_segment::*;
//~^ ERROR `issue_56125` is ambiguous
//~| ERROR unresolved import `issue_56125::last_segment`
}

mod m2 {
use issue_56125::non_last_segment::non_last_segment::*;
//~^ ERROR `issue_56125` is ambiguous
//~| ERROR failed to resolve: could not find `non_last_segment` in `issue_56125`
}

mod m3 {
Expand Down
26 changes: 7 additions & 19 deletions src/test/ui/imports/issue-56125.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
error[E0433]: failed to resolve: could not find `non_last_segment` in `issue_56125`
--> $DIR/issue-56125.rs:14:22
|
LL | use issue_56125::non_last_segment::non_last_segment::*;
| ^^^^^^^^^^^^^^^^ could not find `non_last_segment` in `issue_56125`

error[E0432]: unresolved import `issue_56125::last_segment`
--> $DIR/issue-56125.rs:8:22
|
LL | use issue_56125::last_segment::*;
| ^^^^^^^^^^^^ could not find `last_segment` in `issue_56125`

error[E0432]: unresolved import `empty::issue_56125`
--> $DIR/issue-56125.rs:21:9
--> $DIR/issue-56125.rs:19:9
|
LL | use empty::issue_56125; //~ ERROR unresolved import `empty::issue_56125`
| ^^^^^^^^^^^^^^^^^^ no `issue_56125` in `m3::empty`
Expand All @@ -32,36 +20,36 @@ LL | use issue_56125::last_segment::*;
= help: use `self::issue_56125` to refer to this module unambiguously

error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
--> $DIR/issue-56125.rs:14:9
--> $DIR/issue-56125.rs:13:9
|
LL | use issue_56125::non_last_segment::non_last_segment::*;
| ^^^^^^^^^^^ ambiguous name
|
= note: `issue_56125` could refer to an extern crate passed with `--extern`
= help: use `::issue_56125` to refer to this extern crate unambiguously
note: `issue_56125` could also refer to the module imported here
--> $DIR/issue-56125.rs:14:9
--> $DIR/issue-56125.rs:13:9
|
LL | use issue_56125::non_last_segment::non_last_segment::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: use `self::issue_56125` to refer to this module unambiguously

error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
--> $DIR/issue-56125.rs:22:9
--> $DIR/issue-56125.rs:20:9
|
LL | use issue_56125::*; //~ ERROR `issue_56125` is ambiguous
| ^^^^^^^^^^^ ambiguous name
|
= note: `issue_56125` could refer to an extern crate passed with `--extern`
= help: use `::issue_56125` to refer to this extern crate unambiguously
note: `issue_56125` could also refer to the unresolved item imported here
--> $DIR/issue-56125.rs:21:9
--> $DIR/issue-56125.rs:19:9
|
LL | use empty::issue_56125; //~ ERROR unresolved import `empty::issue_56125`
| ^^^^^^^^^^^^^^^^^^
= help: use `self::issue_56125` to refer to this unresolved item unambiguously

error: aborting due to 6 previous errors
error: aborting due to 4 previous errors

Some errors occurred: E0432, E0433, E0659.
Some errors occurred: E0432, E0659.
For more information about an error, try `rustc --explain E0432`.
2 changes: 1 addition & 1 deletion src/test/ui/pub/pub-ident-fn-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

pub foo(s: usize) { bar() }
//~^ ERROR missing `fn` for method definition
//~^ ERROR missing `fn` for function definition

fn main() {
foo(2);
Expand Down
Loading