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 7 pull requests #69474

Merged
merged 18 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
178de46
Add primitive module to libcore/std
Mark-Simulacrum Dec 26, 2019
d78b22f
Mark attributes consumed by `check_mod_attrs` as normal
tmiasko Feb 23, 2020
e355a33
Deduplicate identifier printing a bit
petrochenkov Feb 22, 2020
9c3ee1b
Bump core::primitive to 1.43
dtolnay Feb 24, 2020
5ae4500
remove redundant clones in librustc_mir_build and librustc_data_struc…
matthiaskrgr Feb 24, 2020
d4a005b
librustc{, codegen_ssa,infer,mir_build}: don't clone types that are copy
matthiaskrgr Feb 24, 2020
1892ff7
librustc_macros: remove redundant single component path import
matthiaskrgr Feb 24, 2020
d134385
syntax: Remove `Nt(Impl,Trait,Foreign)Item`
petrochenkov Feb 24, 2020
f56042f
Clean up E0370 explanation
GuillaumeGomez Feb 25, 2020
d6f83c5
Clean up E0371 explanation
GuillaumeGomez Feb 25, 2020
9d84f1f
backport release notes of 1.41.1
pietroalbini Feb 25, 2020
0860f5a
Rollup merge of #67637 - Mark-Simulacrum:primitive-mod, r=dtolnay
Dylan-DPC Feb 26, 2020
41bf200
Rollup merge of #69387 - petrochenkov:idprint, r=Mark-Simulacrum
Dylan-DPC Feb 26, 2020
d050b00
Rollup merge of #69412 - tmiasko:checked-unused, r=petrochenkov
Dylan-DPC Feb 26, 2020
7603c2c
Rollup merge of #69423 - petrochenkov:nont, r=Centril
Dylan-DPC Feb 26, 2020
ab3fb8b
Rollup merge of #69429 - matthiaskrgr:clippy_, r=estebank
Dylan-DPC Feb 26, 2020
35ae48c
Rollup merge of #69457 - GuillaumeGomez:clean-up-e0370-e0371, r=Dylan…
Dylan-DPC Feb 26, 2020
8381862
Rollup merge of #69468 - pietroalbini:master-1.41.1-notes, r=Mark-Sim…
Dylan-DPC Feb 26, 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
10 changes: 10 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
Version 1.41.1 (2020-02-27)
===========================

* [Always check types of static items][69145]
* [Always check lifetime bounds of `Copy` impls][69145]
* [Fix miscompilation in callers of `Layout::repeat`][69225]

[69225]: https://github.com/rust-lang/rust/issues/69225
[69145]: https://github.com/rust-lang/rust/pull/69145

Version 1.41.0 (2020-01-30)
===========================

Expand Down
3 changes: 3 additions & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ mod bool;
mod tuple;
mod unit;

#[stable(feature = "core_primitive", since = "1.43.0")]
pub mod primitive;

// Pull in the `core_arch` crate directly into libcore. The contents of
// `core_arch` are in a different repository: rust-lang/stdarch.
//
Expand Down
67 changes: 67 additions & 0 deletions src/libcore/primitive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//! This module reexports the primitive types to allow usage that is not
//! possibly shadowed by other declared types.
//!
//! This is normally only useful in macro generated code.
//!
//! An example of this is when generating a new struct and an impl for it:
//!
//! ```rust,compile_fail
//! pub struct bool;
//!
//! impl QueryId for bool {
//! const SOME_PROPERTY: bool = true;
//! }
//!
//! # trait QueryId { const SOME_PROPERTY: core::primitive::bool; }
//! ```
//!
//! Note that the `SOME_PROPERTY` associated constant would not compile, as its
//! type `bool` refers to the struct, rather than to the primitive bool type.
//!
//! A correct implementation could look like:
//!
//! ```rust
//! # #[allow(non_camel_case_types)]
//! pub struct bool;
//!
//! impl QueryId for bool {
//! const SOME_PROPERTY: core::primitive::bool = true;
//! }
//!
//! # trait QueryId { const SOME_PROPERTY: core::primitive::bool; }
//! ```

#[stable(feature = "core_primitive", since = "1.43.0")]
pub use bool;
#[stable(feature = "core_primitive", since = "1.43.0")]
pub use char;
#[stable(feature = "core_primitive", since = "1.43.0")]
pub use f32;
#[stable(feature = "core_primitive", since = "1.43.0")]
pub use f64;
#[stable(feature = "core_primitive", since = "1.43.0")]
pub use i128;
#[stable(feature = "core_primitive", since = "1.43.0")]
pub use i16;
#[stable(feature = "core_primitive", since = "1.43.0")]
pub use i32;
#[stable(feature = "core_primitive", since = "1.43.0")]
pub use i64;
#[stable(feature = "core_primitive", since = "1.43.0")]
pub use i8;
#[stable(feature = "core_primitive", since = "1.43.0")]
pub use isize;
#[stable(feature = "core_primitive", since = "1.43.0")]
pub use str;
#[stable(feature = "core_primitive", since = "1.43.0")]
pub use u128;
#[stable(feature = "core_primitive", since = "1.43.0")]
pub use u16;
#[stable(feature = "core_primitive", since = "1.43.0")]
pub use u32;
#[stable(feature = "core_primitive", since = "1.43.0")]
pub use u64;
#[stable(feature = "core_primitive", since = "1.43.0")]
pub use u8;
#[stable(feature = "core_primitive", since = "1.43.0")]
pub use usize;
2 changes: 1 addition & 1 deletion src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ impl<'tcx> GlobalCtxt<'tcx> {
ty::tls::with_related_context(tcx, |icx| {
let new_icx = ty::tls::ImplicitCtxt {
tcx,
query: icx.query.clone(),
query: icx.query,
diagnostics: icx.diagnostics,
layout_depth: icx.layout_depth,
task_deps: icx.task_deps,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<TraitRef<'tcx>> {
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&TraitRef<'tcx>> {
fn to_predicate(&self) -> Predicate<'tcx> {
ty::Predicate::Trait(
ty::Binder::dummy(ty::TraitPredicate { trait_ref: self.value.clone() }),
ty::Binder::dummy(ty::TraitPredicate { trait_ref: *self.value }),
self.constness,
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/query/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl<'tcx> QueryLatch<'tcx> {
return CycleError { usage, cycle };
}

current_job = info.job.parent.clone();
current_job = info.job.parent;
}

panic!("did not find a cycle")
Expand Down
53 changes: 4 additions & 49 deletions src/librustc_ast_pretty/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::pp::{self, Breaks};

use rustc_span::edition::Edition;
use rustc_span::source_map::{SourceMap, Spanned};
use rustc_span::symbol::{kw, sym};
use rustc_span::symbol::{kw, sym, IdentPrinter};
use rustc_span::{BytePos, FileName, Span};
use syntax::ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
use syntax::ast::{Attribute, GenericArg, MacArgs};
Expand Down Expand Up @@ -196,40 +196,6 @@ pub fn literal_to_string(lit: token::Lit) -> String {
out
}

/// Print an ident from AST, `$crate` is converted into its respective crate name.
pub fn ast_ident_to_string(ident: ast::Ident, is_raw: bool) -> String {
ident_to_string(ident.name, is_raw, Some(ident.span))
}

// AST pretty-printer is used as a fallback for turning AST structures into token streams for
// proc macros. Additionally, proc macros may stringify their input and expect it survive the
// stringification (especially true for proc macro derives written between Rust 1.15 and 1.30).
// So we need to somehow pretty-print `$crate` in a way preserving at least some of its
// hygiene data, most importantly name of the crate it refers to.
// As a result we print `$crate` as `crate` if it refers to the local crate
// and as `::other_crate_name` if it refers to some other crate.
// Note, that this is only done if the ident token is printed from inside of AST pretty-pringing,
// but not otherwise. Pretty-printing is the only way for proc macros to discover token contents,
// so we should not perform this lossy conversion if the top level call to the pretty-printer was
// done for a token stream or a single token.
fn ident_to_string(name: ast::Name, is_raw: bool, convert_dollar_crate: Option<Span>) -> String {
if is_raw {
format!("r#{}", name)
} else {
if name == kw::DollarCrate {
if let Some(span) = convert_dollar_crate {
let converted = span.ctxt().dollar_crate_name();
return if converted.is_path_segment_keyword() {
converted.to_string()
} else {
format!("::{}", converted)
};
}
}
name.to_string()
}
}

/// Print the token kind precisely, without converting `$crate` into its respective crate name.
pub fn token_kind_to_string(tok: &TokenKind) -> String {
token_kind_to_string_ext(tok, None)
Expand Down Expand Up @@ -280,7 +246,7 @@ fn token_kind_to_string_ext(tok: &TokenKind, convert_dollar_crate: Option<Span>)
token::Literal(lit) => literal_to_string(lit),

/* Name components */
token::Ident(s, is_raw) => ident_to_string(s, is_raw, convert_dollar_crate),
token::Ident(s, is_raw) => IdentPrinter::new(s, is_raw, convert_dollar_crate).to_string(),
token::Lifetime(s) => s.to_string(),

/* Other */
Expand Down Expand Up @@ -315,14 +281,11 @@ pub fn nonterminal_to_string(nt: &Nonterminal) -> String {
token::NtBlock(ref e) => block_to_string(e),
token::NtStmt(ref e) => stmt_to_string(e),
token::NtPat(ref e) => pat_to_string(e),
token::NtIdent(e, is_raw) => ast_ident_to_string(e, is_raw),
token::NtIdent(e, is_raw) => IdentPrinter::for_ast_ident(e, is_raw).to_string(),
token::NtLifetime(e) => e.to_string(),
token::NtLiteral(ref e) => expr_to_string(e),
token::NtTT(ref tree) => tt_to_string(tree.clone()),
// FIXME(Centril): merge these variants.
token::NtImplItem(ref e) | token::NtTraitItem(ref e) => assoc_item_to_string(e),
token::NtVis(ref e) => vis_to_string(e),
token::NtForeignItem(ref e) => foreign_item_to_string(e),
}
}

Expand Down Expand Up @@ -358,10 +321,6 @@ pub fn item_to_string(i: &ast::Item) -> String {
to_string(|s| s.print_item(i))
}

fn assoc_item_to_string(i: &ast::AssocItem) -> String {
to_string(|s| s.print_assoc_item(i))
}

pub fn generic_params_to_string(generic_params: &[ast::GenericParam]) -> String {
to_string(|s| s.print_generic_params(generic_params))
}
Expand Down Expand Up @@ -404,10 +363,6 @@ pub fn param_to_string(arg: &ast::Param) -> String {
to_string(|s| s.print_param(arg, false))
}

fn foreign_item_to_string(arg: &ast::ForeignItem) -> String {
to_string(|s| s.print_foreign_item(arg))
}

fn visibility_qualified(vis: &ast::Visibility, s: &str) -> String {
format!("{}{}", to_string(|s| s.print_visibility(vis)), s)
}
Expand Down Expand Up @@ -819,7 +774,7 @@ impl<'a> PrintState<'a> for State<'a> {
}

fn print_ident(&mut self, ident: ast::Ident) {
self.s.word(ast_ident_to_string(ident, ident.is_raw_guess()));
self.s.word(IdentPrinter::for_ast_ident(ident, ident.is_raw_guess()).to_string());
self.ann.post(self, AnnNode::Ident(&ident))
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
_ => {
let val = self.eval_mir_constant(constant)?;
let ty = self.monomorphize(&constant.literal.ty);
Ok(OperandRef::from_const(bx, val.clone(), ty))
Ok(OperandRef::from_const(bx, val, ty))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_data_structures/obligation_forest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ impl<O: ForestObligation> ObligationForest<O> {
return Ok(());
}

match self.active_cache.entry(obligation.as_cache_key().clone()) {
match self.active_cache.entry(obligation.as_cache_key()) {
Entry::Occupied(o) => {
let node = &mut self.nodes[*o.get()];
if let Some(parent_index) = parent {
Expand Down Expand Up @@ -385,7 +385,7 @@ impl<O: ForestObligation> ObligationForest<O> {
self.error_cache
.entry(node.obligation_tree_id)
.or_default()
.insert(node.obligation.as_cache_key().clone());
.insert(node.obligation.as_cache_key());
}

/// Performs a pass through the obligation list. This must
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_error_codes/error_codes/E0370.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
The maximum value of an enum was reached, so it cannot be automatically
set in the next enum value. Erroneous code example:
set in the next enum value.

Erroneous code example:

```compile_fail,E0370
#[repr(i64)]
Expand Down
12 changes: 7 additions & 5 deletions src/librustc_error_codes/error_codes/E0371.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a
definition like `trait Trait2: Trait1 { ... }`), it is not allowed to implement
`Trait1` for `Trait2`. This is because `Trait2` already implements `Trait1` by
definition, so it is not useful to do this.
A trait was implemented on another which already automatically implemented it.

Example:
Erroneous code examples:

```compile_fail,E0371
trait Foo { fn foo(&self) { } }
Expand All @@ -15,3 +12,8 @@ impl Foo for Baz { } // error, `Baz` implements `Bar` which implements `Foo`
impl Baz for Baz { } // error, `Baz` (trivially) implements `Baz`
impl Baz for Bar { } // Note: This is OK
```

When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a
definition like `trait Trait2: Trait1 { ... }`), it is not allowed to implement
`Trait1` for `Trait2`. This is because `Trait2` already implements `Trait1` by
definition, so it is not useful to do this.
11 changes: 8 additions & 3 deletions src/librustc_expand/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,12 +669,17 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
SyntaxExtensionKind::Attr(expander) => {
self.gate_proc_macro_input(&item);
self.gate_proc_macro_attr_item(span, &item);
// `Annotatable` can be converted into tokens directly, but we are packing it
// into a nonterminal as a piece of AST to make the produced token stream
// look nicer in pretty-printed form. This may be no longer necessary.
let item_tok = TokenTree::token(
token::Interpolated(Lrc::new(match item {
Annotatable::Item(item) => token::NtItem(item),
Annotatable::TraitItem(item) => token::NtTraitItem(item),
Annotatable::ImplItem(item) => token::NtImplItem(item),
Annotatable::ForeignItem(item) => token::NtForeignItem(item),
Annotatable::TraitItem(item)
| Annotatable::ImplItem(item)
| Annotatable::ForeignItem(item) => {
token::NtItem(P(item.and_then(ast::AssocItem::into_item)))
}
Annotatable::Stmt(stmt) => token::NtStmt(stmt.into_inner()),
Annotatable::Expr(expr) => token::NtExpr(expr),
Annotatable::Arm(..)
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_feature/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
ungated!(export_name, Whitelisted, template!(NameValueStr: "name")),
ungated!(link_section, Whitelisted, template!(NameValueStr: "name")),
ungated!(no_mangle, Whitelisted, template!(Word)),
ungated!(used, Whitelisted, template!(Word)),
ungated!(used, Normal, template!(Word)),

// Limits:
ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N")),
Expand All @@ -250,17 +250,17 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
ungated!(path, Normal, template!(NameValueStr: "file")),
ungated!(no_std, CrateLevel, template!(Word)),
ungated!(no_implicit_prelude, Normal, template!(Word)),
ungated!(non_exhaustive, Whitelisted, template!(Word)),
ungated!(non_exhaustive, Normal, template!(Word)),

// Runtime
ungated!(windows_subsystem, Whitelisted, template!(NameValueStr: "windows|console")),
ungated!(panic_handler, Normal, template!(Word)), // RFC 2070

// Code generation:
ungated!(inline, Whitelisted, template!(Word, List: "always|never")),
ungated!(inline, Normal, template!(Word, List: "always|never")),
ungated!(cold, Whitelisted, template!(Word)),
ungated!(no_builtins, Whitelisted, template!(Word)),
ungated!(target_feature, Whitelisted, template!(List: r#"enable = "name""#)),
ungated!(target_feature, Normal, template!(List: r#"enable = "name""#)),
gated!(
no_sanitize, Whitelisted,
template!(List: "address, memory, thread"),
Expand All @@ -275,7 +275,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
// ==========================================================================

// Linking:
gated!(naked, Whitelisted, template!(Word), naked_functions, experimental!(naked)),
gated!(naked, Normal, template!(Word), naked_functions, experimental!(naked)),
gated!(
link_args, Normal, template!(NameValueStr: "args"),
"the `link_args` attribute is experimental and not portable across platforms, \
Expand Down Expand Up @@ -332,7 +332,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
),

gated!(ffi_returns_twice, Whitelisted, template!(Word), experimental!(ffi_returns_twice)),
gated!(track_caller, Whitelisted, template!(Word), experimental!(track_caller)),
gated!(track_caller, Normal, template!(Word), experimental!(track_caller)),
gated!(
register_attr, CrateLevel, template!(List: "attr1, attr2, ..."),
experimental!(register_attr),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_hir/print.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use rustc_ast_pretty::pp::Breaks::{Consistent, Inconsistent};
use rustc_ast_pretty::pp::{self, Breaks};
use rustc_ast_pretty::pprust::{self, Comments, PrintState};
use rustc_ast_pretty::pprust::{Comments, PrintState};
use rustc_span::source_map::{SourceMap, Spanned};
use rustc_span::symbol::kw;
use rustc_span::symbol::{kw, IdentPrinter};
use rustc_span::{self, BytePos, FileName};
use rustc_target::spec::abi::Abi;
use syntax::ast;
Expand Down Expand Up @@ -126,7 +126,7 @@ impl<'a> PrintState<'a> for State<'a> {
}

fn print_ident(&mut self, ident: ast::Ident) {
self.s.word(pprust::ast_ident_to_string(ident, ident.is_raw_guess()));
self.s.word(IdentPrinter::for_ast_ident(ident, ident.is_raw_guess()).to_string());
self.ann.post(self, AnnNode::Name(&ident.name))
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/infer/lexical_region_resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
for upper_bound in &upper_bounds {
if let ty::RePlaceholder(p) = upper_bound.region {
if node_universe.cannot_name(p.universe) {
let origin = self.var_infos[node_idx].origin.clone();
let origin = self.var_infos[node_idx].origin;
errors.push(RegionResolutionError::UpperBoundUniverseConflict(
node_idx,
origin,
Expand Down
1 change: 0 additions & 1 deletion src/librustc_macros/src/hash_stable.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use proc_macro2::{self, Ident};
use quote::quote;
use syn::{self, parse_quote, Meta, NestedMeta};
use synstructure;

struct Attributes {
ignore: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir_build/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
TerminatorKind::Yield {
value,
resume,
resume_arg: destination.clone(),
resume_arg: *destination,
drop: cleanup,
},
);
Expand Down
Loading