Skip to content

Commit 46f5aa9

Browse files
committed
Auto merge of #69474 - Dylan-DPC:rollup-ciotplu, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - #67637 (Add primitive module to libcore) - #69387 (Deduplicate identifier printing a bit) - #69412 (Mark attributes consumed by `check_mod_attrs` as normal) - #69423 (syntax: Remove `Nt(Impl,Trait,Foreign)Item`) - #69429 (remove redundant clones and import) - #69457 (Clean up e0370 e0371) - #69468 ([master] Backport release notes of 1.41.1) Failed merges: r? @ghost
2 parents 55a777c + 8381862 commit 46f5aa9

File tree

30 files changed

+300
-119
lines changed

30 files changed

+300
-119
lines changed

RELEASES.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Version 1.41.1 (2020-02-27)
2+
===========================
3+
4+
* [Always check types of static items][69145]
5+
* [Always check lifetime bounds of `Copy` impls][69145]
6+
* [Fix miscompilation in callers of `Layout::repeat`][69225]
7+
8+
[69225]: https://github.com/rust-lang/rust/issues/69225
9+
[69145]: https://github.com/rust-lang/rust/pull/69145
10+
111
Version 1.41.0 (2020-01-30)
212
===========================
313

src/libcore/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ mod bool;
267267
mod tuple;
268268
mod unit;
269269

270+
#[stable(feature = "core_primitive", since = "1.43.0")]
271+
pub mod primitive;
272+
270273
// Pull in the `core_arch` crate directly into libcore. The contents of
271274
// `core_arch` are in a different repository: rust-lang/stdarch.
272275
//

src/libcore/primitive.rs

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//! This module reexports the primitive types to allow usage that is not
2+
//! possibly shadowed by other declared types.
3+
//!
4+
//! This is normally only useful in macro generated code.
5+
//!
6+
//! An example of this is when generating a new struct and an impl for it:
7+
//!
8+
//! ```rust,compile_fail
9+
//! pub struct bool;
10+
//!
11+
//! impl QueryId for bool {
12+
//! const SOME_PROPERTY: bool = true;
13+
//! }
14+
//!
15+
//! # trait QueryId { const SOME_PROPERTY: core::primitive::bool; }
16+
//! ```
17+
//!
18+
//! Note that the `SOME_PROPERTY` associated constant would not compile, as its
19+
//! type `bool` refers to the struct, rather than to the primitive bool type.
20+
//!
21+
//! A correct implementation could look like:
22+
//!
23+
//! ```rust
24+
//! # #[allow(non_camel_case_types)]
25+
//! pub struct bool;
26+
//!
27+
//! impl QueryId for bool {
28+
//! const SOME_PROPERTY: core::primitive::bool = true;
29+
//! }
30+
//!
31+
//! # trait QueryId { const SOME_PROPERTY: core::primitive::bool; }
32+
//! ```
33+
34+
#[stable(feature = "core_primitive", since = "1.43.0")]
35+
pub use bool;
36+
#[stable(feature = "core_primitive", since = "1.43.0")]
37+
pub use char;
38+
#[stable(feature = "core_primitive", since = "1.43.0")]
39+
pub use f32;
40+
#[stable(feature = "core_primitive", since = "1.43.0")]
41+
pub use f64;
42+
#[stable(feature = "core_primitive", since = "1.43.0")]
43+
pub use i128;
44+
#[stable(feature = "core_primitive", since = "1.43.0")]
45+
pub use i16;
46+
#[stable(feature = "core_primitive", since = "1.43.0")]
47+
pub use i32;
48+
#[stable(feature = "core_primitive", since = "1.43.0")]
49+
pub use i64;
50+
#[stable(feature = "core_primitive", since = "1.43.0")]
51+
pub use i8;
52+
#[stable(feature = "core_primitive", since = "1.43.0")]
53+
pub use isize;
54+
#[stable(feature = "core_primitive", since = "1.43.0")]
55+
pub use str;
56+
#[stable(feature = "core_primitive", since = "1.43.0")]
57+
pub use u128;
58+
#[stable(feature = "core_primitive", since = "1.43.0")]
59+
pub use u16;
60+
#[stable(feature = "core_primitive", since = "1.43.0")]
61+
pub use u32;
62+
#[stable(feature = "core_primitive", since = "1.43.0")]
63+
pub use u64;
64+
#[stable(feature = "core_primitive", since = "1.43.0")]
65+
pub use u8;
66+
#[stable(feature = "core_primitive", since = "1.43.0")]
67+
pub use usize;

src/librustc/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ impl<'tcx> GlobalCtxt<'tcx> {
15261526
ty::tls::with_related_context(tcx, |icx| {
15271527
let new_icx = ty::tls::ImplicitCtxt {
15281528
tcx,
1529-
query: icx.query.clone(),
1529+
query: icx.query,
15301530
diagnostics: icx.diagnostics,
15311531
layout_depth: icx.layout_depth,
15321532
task_deps: icx.task_deps,

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<TraitRef<'tcx>> {
14471447
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<&TraitRef<'tcx>> {
14481448
fn to_predicate(&self) -> Predicate<'tcx> {
14491449
ty::Predicate::Trait(
1450-
ty::Binder::dummy(ty::TraitPredicate { trait_ref: self.value.clone() }),
1450+
ty::Binder::dummy(ty::TraitPredicate { trait_ref: *self.value }),
14511451
self.constness,
14521452
)
14531453
}

src/librustc/ty/query/job.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl<'tcx> QueryLatch<'tcx> {
173173
return CycleError { usage, cycle };
174174
}
175175

176-
current_job = info.job.parent.clone();
176+
current_job = info.job.parent;
177177
}
178178

179179
panic!("did not find a cycle")

src/librustc_ast_pretty/pprust.rs

+4-49
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::pp::{self, Breaks};
33

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

199-
/// Print an ident from AST, `$crate` is converted into its respective crate name.
200-
pub fn ast_ident_to_string(ident: ast::Ident, is_raw: bool) -> String {
201-
ident_to_string(ident.name, is_raw, Some(ident.span))
202-
}
203-
204-
// AST pretty-printer is used as a fallback for turning AST structures into token streams for
205-
// proc macros. Additionally, proc macros may stringify their input and expect it survive the
206-
// stringification (especially true for proc macro derives written between Rust 1.15 and 1.30).
207-
// So we need to somehow pretty-print `$crate` in a way preserving at least some of its
208-
// hygiene data, most importantly name of the crate it refers to.
209-
// As a result we print `$crate` as `crate` if it refers to the local crate
210-
// and as `::other_crate_name` if it refers to some other crate.
211-
// Note, that this is only done if the ident token is printed from inside of AST pretty-pringing,
212-
// but not otherwise. Pretty-printing is the only way for proc macros to discover token contents,
213-
// so we should not perform this lossy conversion if the top level call to the pretty-printer was
214-
// done for a token stream or a single token.
215-
fn ident_to_string(name: ast::Name, is_raw: bool, convert_dollar_crate: Option<Span>) -> String {
216-
if is_raw {
217-
format!("r#{}", name)
218-
} else {
219-
if name == kw::DollarCrate {
220-
if let Some(span) = convert_dollar_crate {
221-
let converted = span.ctxt().dollar_crate_name();
222-
return if converted.is_path_segment_keyword() {
223-
converted.to_string()
224-
} else {
225-
format!("::{}", converted)
226-
};
227-
}
228-
}
229-
name.to_string()
230-
}
231-
}
232-
233199
/// Print the token kind precisely, without converting `$crate` into its respective crate name.
234200
pub fn token_kind_to_string(tok: &TokenKind) -> String {
235201
token_kind_to_string_ext(tok, None)
@@ -280,7 +246,7 @@ fn token_kind_to_string_ext(tok: &TokenKind, convert_dollar_crate: Option<Span>)
280246
token::Literal(lit) => literal_to_string(lit),
281247

282248
/* Name components */
283-
token::Ident(s, is_raw) => ident_to_string(s, is_raw, convert_dollar_crate),
249+
token::Ident(s, is_raw) => IdentPrinter::new(s, is_raw, convert_dollar_crate).to_string(),
284250
token::Lifetime(s) => s.to_string(),
285251

286252
/* Other */
@@ -315,14 +281,11 @@ pub fn nonterminal_to_string(nt: &Nonterminal) -> String {
315281
token::NtBlock(ref e) => block_to_string(e),
316282
token::NtStmt(ref e) => stmt_to_string(e),
317283
token::NtPat(ref e) => pat_to_string(e),
318-
token::NtIdent(e, is_raw) => ast_ident_to_string(e, is_raw),
284+
token::NtIdent(e, is_raw) => IdentPrinter::for_ast_ident(e, is_raw).to_string(),
319285
token::NtLifetime(e) => e.to_string(),
320286
token::NtLiteral(ref e) => expr_to_string(e),
321287
token::NtTT(ref tree) => tt_to_string(tree.clone()),
322-
// FIXME(Centril): merge these variants.
323-
token::NtImplItem(ref e) | token::NtTraitItem(ref e) => assoc_item_to_string(e),
324288
token::NtVis(ref e) => vis_to_string(e),
325-
token::NtForeignItem(ref e) => foreign_item_to_string(e),
326289
}
327290
}
328291

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

361-
fn assoc_item_to_string(i: &ast::AssocItem) -> String {
362-
to_string(|s| s.print_assoc_item(i))
363-
}
364-
365324
pub fn generic_params_to_string(generic_params: &[ast::GenericParam]) -> String {
366325
to_string(|s| s.print_generic_params(generic_params))
367326
}
@@ -404,10 +363,6 @@ pub fn param_to_string(arg: &ast::Param) -> String {
404363
to_string(|s| s.print_param(arg, false))
405364
}
406365

407-
fn foreign_item_to_string(arg: &ast::ForeignItem) -> String {
408-
to_string(|s| s.print_foreign_item(arg))
409-
}
410-
411366
fn visibility_qualified(vis: &ast::Visibility, s: &str) -> String {
412367
format!("{}{}", to_string(|s| s.print_visibility(vis)), s)
413368
}
@@ -819,7 +774,7 @@ impl<'a> PrintState<'a> for State<'a> {
819774
}
820775

821776
fn print_ident(&mut self, ident: ast::Ident) {
822-
self.s.word(ast_ident_to_string(ident, ident.is_raw_guess()));
777+
self.s.word(IdentPrinter::for_ast_ident(ident, ident.is_raw_guess()).to_string());
823778
self.ann.post(self, AnnNode::Ident(&ident))
824779
}
825780

src/librustc_codegen_ssa/mir/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
3131
_ => {
3232
let val = self.eval_mir_constant(constant)?;
3333
let ty = self.monomorphize(&constant.literal.ty);
34-
Ok(OperandRef::from_const(bx, val.clone(), ty))
34+
Ok(OperandRef::from_const(bx, val, ty))
3535
}
3636
}
3737
}

src/librustc_data_structures/obligation_forest/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl<O: ForestObligation> ObligationForest<O> {
314314
return Ok(());
315315
}
316316

317-
match self.active_cache.entry(obligation.as_cache_key().clone()) {
317+
match self.active_cache.entry(obligation.as_cache_key()) {
318318
Entry::Occupied(o) => {
319319
let node = &mut self.nodes[*o.get()];
320320
if let Some(parent_index) = parent {
@@ -385,7 +385,7 @@ impl<O: ForestObligation> ObligationForest<O> {
385385
self.error_cache
386386
.entry(node.obligation_tree_id)
387387
.or_default()
388-
.insert(node.obligation.as_cache_key().clone());
388+
.insert(node.obligation.as_cache_key());
389389
}
390390

391391
/// Performs a pass through the obligation list. This must

src/librustc_error_codes/error_codes/E0370.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
The maximum value of an enum was reached, so it cannot be automatically
2-
set in the next enum value. Erroneous code example:
2+
set in the next enum value.
3+
4+
Erroneous code example:
35

46
```compile_fail,E0370
57
#[repr(i64)]
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a
2-
definition like `trait Trait2: Trait1 { ... }`), it is not allowed to implement
3-
`Trait1` for `Trait2`. This is because `Trait2` already implements `Trait1` by
4-
definition, so it is not useful to do this.
1+
A trait was implemented on another which already automatically implemented it.
52

6-
Example:
3+
Erroneous code examples:
74

85
```compile_fail,E0371
96
trait Foo { fn foo(&self) { } }
@@ -15,3 +12,8 @@ impl Foo for Baz { } // error, `Baz` implements `Bar` which implements `Foo`
1512
impl Baz for Baz { } // error, `Baz` (trivially) implements `Baz`
1613
impl Baz for Bar { } // Note: This is OK
1714
```
15+
16+
When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a
17+
definition like `trait Trait2: Trait1 { ... }`), it is not allowed to implement
18+
`Trait1` for `Trait2`. This is because `Trait2` already implements `Trait1` by
19+
definition, so it is not useful to do this.

src/librustc_expand/expand.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -669,12 +669,17 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
669669
SyntaxExtensionKind::Attr(expander) => {
670670
self.gate_proc_macro_input(&item);
671671
self.gate_proc_macro_attr_item(span, &item);
672+
// `Annotatable` can be converted into tokens directly, but we are packing it
673+
// into a nonterminal as a piece of AST to make the produced token stream
674+
// look nicer in pretty-printed form. This may be no longer necessary.
672675
let item_tok = TokenTree::token(
673676
token::Interpolated(Lrc::new(match item {
674677
Annotatable::Item(item) => token::NtItem(item),
675-
Annotatable::TraitItem(item) => token::NtTraitItem(item),
676-
Annotatable::ImplItem(item) => token::NtImplItem(item),
677-
Annotatable::ForeignItem(item) => token::NtForeignItem(item),
678+
Annotatable::TraitItem(item)
679+
| Annotatable::ImplItem(item)
680+
| Annotatable::ForeignItem(item) => {
681+
token::NtItem(P(item.and_then(ast::AssocItem::into_item)))
682+
}
678683
Annotatable::Stmt(stmt) => token::NtStmt(stmt.into_inner()),
679684
Annotatable::Expr(expr) => token::NtExpr(expr),
680685
Annotatable::Arm(..)

src/librustc_feature/builtin_attrs.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
234234
ungated!(export_name, Whitelisted, template!(NameValueStr: "name")),
235235
ungated!(link_section, Whitelisted, template!(NameValueStr: "name")),
236236
ungated!(no_mangle, Whitelisted, template!(Word)),
237-
ungated!(used, Whitelisted, template!(Word)),
237+
ungated!(used, Normal, template!(Word)),
238238

239239
// Limits:
240240
ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N")),
@@ -250,17 +250,17 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
250250
ungated!(path, Normal, template!(NameValueStr: "file")),
251251
ungated!(no_std, CrateLevel, template!(Word)),
252252
ungated!(no_implicit_prelude, Normal, template!(Word)),
253-
ungated!(non_exhaustive, Whitelisted, template!(Word)),
253+
ungated!(non_exhaustive, Normal, template!(Word)),
254254

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

259259
// Code generation:
260-
ungated!(inline, Whitelisted, template!(Word, List: "always|never")),
260+
ungated!(inline, Normal, template!(Word, List: "always|never")),
261261
ungated!(cold, Whitelisted, template!(Word)),
262262
ungated!(no_builtins, Whitelisted, template!(Word)),
263-
ungated!(target_feature, Whitelisted, template!(List: r#"enable = "name""#)),
263+
ungated!(target_feature, Normal, template!(List: r#"enable = "name""#)),
264264
gated!(
265265
no_sanitize, Whitelisted,
266266
template!(List: "address, memory, thread"),
@@ -275,7 +275,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
275275
// ==========================================================================
276276

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

334334
gated!(ffi_returns_twice, Whitelisted, template!(Word), experimental!(ffi_returns_twice)),
335-
gated!(track_caller, Whitelisted, template!(Word), experimental!(track_caller)),
335+
gated!(track_caller, Normal, template!(Word), experimental!(track_caller)),
336336
gated!(
337337
register_attr, CrateLevel, template!(List: "attr1, attr2, ..."),
338338
experimental!(register_attr),

src/librustc_hir/print.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use rustc_ast_pretty::pp::Breaks::{Consistent, Inconsistent};
22
use rustc_ast_pretty::pp::{self, Breaks};
3-
use rustc_ast_pretty::pprust::{self, Comments, PrintState};
3+
use rustc_ast_pretty::pprust::{Comments, PrintState};
44
use rustc_span::source_map::{SourceMap, Spanned};
5-
use rustc_span::symbol::kw;
5+
use rustc_span::symbol::{kw, IdentPrinter};
66
use rustc_span::{self, BytePos, FileName};
77
use rustc_target::spec::abi::Abi;
88
use syntax::ast;
@@ -126,7 +126,7 @@ impl<'a> PrintState<'a> for State<'a> {
126126
}
127127

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

src/librustc_infer/infer/lexical_region_resolve/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
848848
for upper_bound in &upper_bounds {
849849
if let ty::RePlaceholder(p) = upper_bound.region {
850850
if node_universe.cannot_name(p.universe) {
851-
let origin = self.var_infos[node_idx].origin.clone();
851+
let origin = self.var_infos[node_idx].origin;
852852
errors.push(RegionResolutionError::UpperBoundUniverseConflict(
853853
node_idx,
854854
origin,

src/librustc_macros/src/hash_stable.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use proc_macro2::{self, Ident};
22
use quote::quote;
33
use syn::{self, parse_quote, Meta, NestedMeta};
4-
use synstructure;
54

65
struct Attributes {
76
ignore: bool,

src/librustc_mir_build/build/expr/into.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
376376
TerminatorKind::Yield {
377377
value,
378378
resume,
379-
resume_arg: destination.clone(),
379+
resume_arg: *destination,
380380
drop: cleanup,
381381
},
382382
);

0 commit comments

Comments
 (0)