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 5 pull requests #69393

Merged
merged 12 commits into from
Feb 23, 2020
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/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<'a> StableHashingContext<'a> {
#[inline]
pub fn source_map(&mut self) -> &mut CachingSourceMapView<'a> {
match self.caching_source_map {
Some(ref mut cm) => cm,
Some(ref mut sm) => sm,
ref mut none => {
*none = Some(CachingSourceMapView::new(self.raw_source_map));
none.as_mut().unwrap()
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ pub fn report_unstable(
};

let msp: MultiSpan = span.into();
let cm = &sess.parse_sess.source_map();
let sm = &sess.parse_sess.source_map();
let span_key = msp.primary_span().and_then(|sp: Span| {
if !sp.is_dummy() {
let file = cm.lookup_char_pos(sp.lo()).file;
let file = sm.lookup_char_pos(sp.lo()).file;
if file.name.is_macros() { None } else { Some(span) }
} else {
None
Expand Down
18 changes: 9 additions & 9 deletions src/librustc_ast_lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,28 +297,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
ItemKind::Mod(ref m) => hir::ItemKind::Mod(self.lower_mod(m)),
ItemKind::ForeignMod(ref nm) => hir::ItemKind::ForeignMod(self.lower_foreign_mod(nm)),
ItemKind::GlobalAsm(ref ga) => hir::ItemKind::GlobalAsm(self.lower_global_asm(ga)),
ItemKind::TyAlias(ref ty, ref generics) => match ty.kind.opaque_top_hack() {
ItemKind::TyAlias(ref generics, _, Some(ref ty)) => match ty.kind.opaque_top_hack() {
None => {
let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
hir::ItemKind::TyAlias(ty, generics)
}
Some(bounds) => {
let ctx = || ImplTraitContext::OpaqueTy(None, hir::OpaqueTyOrigin::Misc);
let ty = hir::OpaqueTy {
generics: self.lower_generics(
generics,
ImplTraitContext::OpaqueTy(None, hir::OpaqueTyOrigin::Misc),
),
bounds: self.lower_param_bounds(
bounds,
ImplTraitContext::OpaqueTy(None, hir::OpaqueTyOrigin::Misc),
),
generics: self.lower_generics(generics, ctx()),
bounds: self.lower_param_bounds(bounds, ctx()),
impl_trait_fn: None,
origin: hir::OpaqueTyOrigin::TypeAlias,
};
hir::ItemKind::OpaqueTy(ty)
}
},
ItemKind::TyAlias(ref generics, _, None) => {
let ty = self.arena.alloc(self.ty(span, hir::TyKind::Err));
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
hir::ItemKind::TyAlias(ty, generics)
}
ItemKind::Enum(ref enum_definition, ref generics) => hir::ItemKind::Enum(
hir::EnumDef {
variants: self.arena.alloc_from_iter(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_lowering/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ItemKind::Struct(_, ref generics)
| ItemKind::Union(_, ref generics)
| ItemKind::Enum(_, ref generics)
| ItemKind::TyAlias(_, ref generics)
| ItemKind::TyAlias(ref generics, ..)
| ItemKind::Trait(_, _, ref generics, ..) => {
let def_id = self.lctx.resolver.definitions().local_def_id(item.id);
let count = generics
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_ast_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
let msg = "free static item without body";
self.error_item_without_body(item.span, "static", msg, " = <expr>;");
}
ItemKind::TyAlias(_, ref bounds, ref body) => {
if body.is_none() {
let msg = "free type alias without body";
self.error_item_without_body(item.span, "type", msg, " = <type>;");
}
self.check_type_no_bounds(bounds, "this context");
}
_ => {}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_passes/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
gate_feature_post!(&self, decl_macro, i.span, msg);
}

ast::ItemKind::TyAlias(ref ty, ..) => self.check_impl_trait(&ty),
ast::ItemKind::TyAlias(_, _, Some(ref ty)) => self.check_impl_trait(&ty),

_ => {}
}
Expand Down
90 changes: 47 additions & 43 deletions src/librustc_ast_pretty/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::pp::Breaks::{Consistent, Inconsistent};
use crate::pp::{self, Breaks};

use rustc_span::edition::Edition;
use rustc_span::source_map::{dummy_spanned, SourceMap, Spanned};
use rustc_span::source_map::{SourceMap, Spanned};
use rustc_span::symbol::{kw, sym};
use rustc_span::{BytePos, FileName, Span};
use syntax::ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
Expand Down Expand Up @@ -47,15 +47,15 @@ pub struct NoAnn;
impl PpAnn for NoAnn {}

pub struct Comments<'a> {
cm: &'a SourceMap,
sm: &'a SourceMap,
comments: Vec<comments::Comment>,
current: usize,
}

impl<'a> Comments<'a> {
pub fn new(cm: &'a SourceMap, filename: FileName, input: String) -> Comments<'a> {
let comments = comments::gather_comments(cm, filename, input);
Comments { cm, comments, current: 0 }
pub fn new(sm: &'a SourceMap, filename: FileName, input: String) -> Comments<'a> {
let comments = comments::gather_comments(sm, filename, input);
Comments { sm, comments, current: 0 }
}

pub fn next(&self) -> Option<comments::Comment> {
Expand All @@ -71,8 +71,8 @@ impl<'a> Comments<'a> {
if cmnt.style != comments::Trailing {
return None;
}
let span_line = self.cm.lookup_char_pos(span.hi());
let comment_line = self.cm.lookup_char_pos(cmnt.pos);
let span_line = self.sm.lookup_char_pos(span.hi());
let comment_line = self.sm.lookup_char_pos(cmnt.pos);
let next = next_pos.unwrap_or_else(|| cmnt.pos + BytePos(1));
if span.hi() < cmnt.pos && cmnt.pos < next && span_line.line == comment_line.line {
return Some(cmnt);
Expand All @@ -95,7 +95,7 @@ crate const INDENT_UNIT: usize = 4;
/// Requires you to pass an input filename and reader so that
/// it can scan the input text for comments to copy forward.
pub fn print_crate<'a>(
cm: &'a SourceMap,
sm: &'a SourceMap,
krate: &ast::Crate,
filename: FileName,
input: String,
Expand All @@ -106,7 +106,7 @@ pub fn print_crate<'a>(
) -> String {
let mut s = State {
s: pp::mk_printer(),
comments: Some(Comments::new(cm, filename, input)),
comments: Some(Comments::new(sm, filename, input)),
ann,
is_expanded,
};
Expand Down Expand Up @@ -522,8 +522,8 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.hardbreak();
}
}
if let Some(cm) = self.comments() {
cm.current += 1;
if let Some(cmnts) = self.comments() {
cmnts.current += 1;
}
}

Expand Down Expand Up @@ -1026,27 +1026,26 @@ impl<'a> State<'a> {
span: Span,
ident: ast::Ident,
attrs: &[Attribute],
defaultness: ast::Defaultness,
def: ast::Defaultness,
kind: &ast::AssocItemKind,
vis: &ast::Visibility,
) {
self.ann.pre(self, AnnNode::SubItem(id));
self.hardbreak_if_not_bol();
self.maybe_print_comment(span.lo());
self.print_outer_attributes(attrs);
self.print_defaultness(defaultness);
match kind {
ast::ForeignItemKind::Fn(sig, gen, body) => {
self.print_fn_full(sig, ident, gen, vis, body.as_deref(), attrs);
self.print_fn_full(sig, ident, gen, vis, def, body.as_deref(), attrs);
}
ast::ForeignItemKind::Const(ty, body) => {
self.print_item_const(ident, None, ty, body.as_deref(), vis);
self.print_item_const(ident, None, ty, body.as_deref(), vis, def);
}
ast::ForeignItemKind::Static(ty, mutbl, body) => {
self.print_item_const(ident, Some(*mutbl), ty, body.as_deref(), vis);
self.print_item_const(ident, Some(*mutbl), ty, body.as_deref(), vis, def);
}
ast::ForeignItemKind::TyAlias(generics, bounds, ty) => {
self.print_associated_type(ident, generics, bounds, ty.as_deref());
self.print_associated_type(ident, generics, bounds, ty.as_deref(), vis, def);
}
ast::ForeignItemKind::Macro(m) => {
self.print_mac(m);
Expand All @@ -1065,13 +1064,17 @@ impl<'a> State<'a> {
ty: &ast::Ty,
body: Option<&ast::Expr>,
vis: &ast::Visibility,
defaultness: ast::Defaultness,
) {
self.head("");
self.print_visibility(vis);
self.print_defaultness(defaultness);
let leading = match mutbl {
None => "const",
Some(ast::Mutability::Not) => "static",
Some(ast::Mutability::Mut) => "static mut",
};
self.head(visibility_qualified(vis, leading));
self.word_space(leading);
self.print_ident(ident);
self.word_space(":");
self.print_type(ty);
Expand All @@ -1091,7 +1094,12 @@ impl<'a> State<'a> {
generics: &ast::Generics,
bounds: &ast::GenericBounds,
ty: Option<&ast::Ty>,
vis: &ast::Visibility,
defaultness: ast::Defaultness,
) {
self.head("");
self.print_visibility(vis);
self.print_defaultness(defaultness);
self.word_space("type");
self.print_ident(ident);
self.print_generic_params(&generics.params);
Expand All @@ -1102,7 +1110,9 @@ impl<'a> State<'a> {
self.word_space("=");
self.print_type(ty);
}
self.s.word(";")
self.s.word(";");
self.end(); // end inner head-block
self.end(); // end outer head-block
}

/// Pretty-prints an item.
Expand Down Expand Up @@ -1133,13 +1143,17 @@ impl<'a> State<'a> {
self.end(); // end outer head-block
}
ast::ItemKind::Static(ref ty, mutbl, ref body) => {
self.print_item_const(item.ident, Some(mutbl), ty, body.as_deref(), &item.vis);
let def = ast::Defaultness::Final;
self.print_item_const(item.ident, Some(mutbl), ty, body.as_deref(), &item.vis, def);
}
ast::ItemKind::Const(ref ty, ref body) => {
self.print_item_const(item.ident, None, ty, body.as_deref(), &item.vis);
let def = ast::Defaultness::Final;
self.print_item_const(item.ident, None, ty, body.as_deref(), &item.vis, def);
}
ast::ItemKind::Fn(ref sig, ref gen, ref body) => {
self.print_fn_full(sig, item.ident, gen, &item.vis, body.as_deref(), &item.attrs);
let def = ast::Defaultness::Final;
let body = body.as_deref();
self.print_fn_full(sig, item.ident, gen, &item.vis, def, body, &item.attrs);
}
ast::ItemKind::Mod(ref _mod) => {
self.head(visibility_qualified(&item.vis, "mod"));
Expand Down Expand Up @@ -1171,18 +1185,10 @@ impl<'a> State<'a> {
self.s.word(ga.asm.to_string());
self.end();
}
ast::ItemKind::TyAlias(ref ty, ref generics) => {
self.head(visibility_qualified(&item.vis, "type"));
self.print_ident(item.ident);
self.print_generic_params(&generics.params);
self.end(); // end the inner ibox

self.print_where_clause(&generics.where_clause);
self.s.space();
self.word_space("=");
self.print_type(ty);
self.s.word(";");
self.end(); // end the outer ibox
ast::ItemKind::TyAlias(ref generics, ref bounds, ref ty) => {
let def = ast::Defaultness::Final;
let ty = ty.as_deref();
self.print_associated_type(item.ident, generics, bounds, ty, &item.vis, def);
}
ast::ItemKind::Enum(ref enum_definition, ref params) => {
self.print_enum_def(enum_definition, params, item.ident, item.span, &item.vis);
Expand Down Expand Up @@ -2370,13 +2376,16 @@ impl<'a> State<'a> {
name: ast::Ident,
generics: &ast::Generics,
vis: &ast::Visibility,
defaultness: ast::Defaultness,
body: Option<&ast::Block>,
attrs: &[ast::Attribute],
) {
if body.is_some() {
self.head("");
}
self.print_fn(&sig.decl, sig.header, Some(name), generics, vis);
self.print_visibility(vis);
self.print_defaultness(defaultness);
self.print_fn(&sig.decl, sig.header, Some(name), generics);
if let Some(body) = body {
self.nbsp();
self.print_block_with_attrs(body, attrs);
Expand All @@ -2391,10 +2400,8 @@ impl<'a> State<'a> {
header: ast::FnHeader,
name: Option<ast::Ident>,
generics: &ast::Generics,
vis: &ast::Visibility,
) {
self.print_fn_header_info(header, vis);

self.print_fn_header_info(header);
if let Some(name) = name {
self.nbsp();
self.print_ident(name);
Expand Down Expand Up @@ -2672,8 +2679,7 @@ impl<'a> State<'a> {
span: rustc_span::DUMMY_SP,
};
let header = ast::FnHeader { unsafety, ext, ..ast::FnHeader::default() };
let vis = dummy_spanned(ast::VisibilityKind::Inherited);
self.print_fn(decl, header, name, &generics, &vis);
self.print_fn(decl, header, name, &generics);
self.end();
}

Expand All @@ -2700,9 +2706,7 @@ impl<'a> State<'a> {
}
}

crate fn print_fn_header_info(&mut self, header: ast::FnHeader, vis: &ast::Visibility) {
self.s.word(visibility_qualified(vis, ""));

crate fn print_fn_header_info(&mut self, header: ast::FnHeader) {
self.print_constness(header.constness);
self.print_asyncness(header.asyncness);
self.print_unsafety(header.unsafety);
Expand Down
10 changes: 2 additions & 8 deletions src/librustc_ast_pretty/pprust/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;

use rustc_span;
use rustc_span::source_map::{dummy_spanned, respan};
use rustc_span::source_map::respan;
use syntax::ast;
use syntax::with_default_globals;

Expand All @@ -13,13 +13,7 @@ fn fun_to_string(
) -> String {
to_string(|s| {
s.head("");
s.print_fn(
decl,
header,
Some(name),
generics,
&dummy_spanned(ast::VisibilityKind::Inherited),
);
s.print_fn(decl, header, Some(name), generics);
s.end(); // Close the head box.
s.end(); // Close the outer box.
})
Expand Down
24 changes: 15 additions & 9 deletions src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,20 +1002,26 @@ fn get_crt_libs_path(sess: &Session) -> Option<PathBuf> {
x if x == "x86" => "i686",
x => x,
};
let mingw_bits = &sess.target.target.target_pointer_width;
let mingw_dir = format!("{}-w64-mingw32", mingw_arch);
// Here we have path/bin/gcc but we need path/
let mut path = linker_path;
path.pop();
path.pop();
// Based on Clang MinGW driver
let probe_path = path.join(&mingw_dir).join("lib");
if probe_path.exists() {
return Some(probe_path);
};
let probe_path = path.join(&mingw_dir).join("sys-root/mingw/lib");
if probe_path.exists() {
return Some(probe_path);
};
// Loosely based on Clang MinGW driver
let probe_paths = vec![
path.join(&mingw_dir).join("lib"), // Typical path
path.join(&mingw_dir).join("sys-root/mingw/lib"), // Rare path
path.join(format!(
"lib/mingw/tools/install/mingw{}/{}/lib",
&mingw_bits, &mingw_dir
)), // Chocolatey is creative
];
for probe_path in probe_paths {
if probe_path.join("crt2.o").exists() {
return Some(probe_path);
};
}
};
};
None
Expand Down
Loading