Skip to content

Commit a143517

Browse files
committedFeb 16, 2021
Auto merge of #82192 - GuillaumeGomez:rollup-gi1639b, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - #82145 (Fix ES5 errors (IE11)) - #82160 (Fix typo in rustc_infer::infer::UndoLog) - #82161 (Add long explanation for E0545) - #82163 (avoid full-slicing slices) - #82175 (validation: fix invalid-fn-ptr error message) - #82184 ([Minor] Update discriminant_value docs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
·
1.88.01.52.0
2 parents 9d3deed + 9502e5c commit a143517

File tree

30 files changed

+127
-62
lines changed

30 files changed

+127
-62
lines changed
 

‎compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
135135

136136
let parent_generics = match self.items.get(&parent_hir_id).unwrap().kind {
137137
hir::ItemKind::Impl(hir::Impl { ref generics, .. })
138-
| hir::ItemKind::Trait(_, _, ref generics, ..) => &generics.params[..],
138+
| hir::ItemKind::Trait(_, _, ref generics, ..) => generics.params,
139139
_ => &[],
140140
};
141141
let lt_def_names = parent_generics.iter().filter_map(|param| match param.kind {

‎compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,7 @@ impl<'a> State<'a> {
16811681
self.ibox(INDENT_UNIT);
16821682
self.s.word("[");
16831683
self.print_inner_attributes_inline(attrs);
1684-
self.commasep_exprs(Inconsistent, &exprs[..]);
1684+
self.commasep_exprs(Inconsistent, exprs);
16851685
self.s.word("]");
16861686
self.end();
16871687
}
@@ -1722,7 +1722,7 @@ impl<'a> State<'a> {
17221722
self.print_inner_attributes_inline(attrs);
17231723
self.commasep_cmnt(
17241724
Consistent,
1725-
&fields[..],
1725+
fields,
17261726
|s, field| {
17271727
s.print_outer_attributes(&field.attrs);
17281728
s.ibox(INDENT_UNIT);
@@ -1757,7 +1757,7 @@ impl<'a> State<'a> {
17571757
fn print_expr_tup(&mut self, exprs: &[P<ast::Expr>], attrs: &[ast::Attribute]) {
17581758
self.popen();
17591759
self.print_inner_attributes_inline(attrs);
1760-
self.commasep_exprs(Inconsistent, &exprs[..]);
1760+
self.commasep_exprs(Inconsistent, exprs);
17611761
if exprs.len() == 1 {
17621762
self.s.word(",");
17631763
}

‎compiler/rustc_builtin_macros/src/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl<'a, 'b> Context<'a, 'b> {
270270
parse::ArgumentNamed(s) => Named(s),
271271
};
272272

273-
let ty = Placeholder(match &arg.format.ty[..] {
273+
let ty = Placeholder(match arg.format.ty {
274274
"" => "Display",
275275
"?" => "Debug",
276276
"e" => "LowerExp",

‎compiler/rustc_builtin_macros/src/format_foreign.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ pub mod printf {
312312
return Some((Substitution::Escape, &s[start + 2..]));
313313
}
314314

315-
Cur::new_at(&s[..], start)
315+
Cur::new_at(s, start)
316316
};
317317

318318
// This is meant to be a translation of the following regex:
@@ -673,7 +673,7 @@ pub mod shell {
673673
_ => { /* fall-through */ }
674674
}
675675

676-
Cur::new_at(&s[..], start)
676+
Cur::new_at(s, start)
677677
};
678678

679679
let at = at.at_next_cp()?;

‎compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
709709
let (tup, args) = args.split_last().unwrap();
710710
(args, Some(tup))
711711
} else {
712-
(&args[..], None)
712+
(args, None)
713713
};
714714

715715
'make_args: for (i, arg) in first_args.iter().enumerate() {

‎compiler/rustc_error_codes/src/error_codes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ E0538: include_str!("./error_codes/E0538.md"),
286286
E0539: include_str!("./error_codes/E0539.md"),
287287
E0541: include_str!("./error_codes/E0541.md"),
288288
E0542: include_str!("./error_codes/E0542.md"),
289+
E0545: include_str!("./error_codes/E0545.md"),
289290
E0546: include_str!("./error_codes/E0546.md"),
290291
E0547: include_str!("./error_codes/E0547.md"),
291292
E0550: include_str!("./error_codes/E0550.md"),
@@ -606,7 +607,6 @@ E0781: include_str!("./error_codes/E0781.md"),
606607
// E0540, // multiple rustc_deprecated attributes
607608
E0543, // missing 'reason'
608609
E0544, // multiple stability levels
609-
E0545, // incorrect 'issue'
610610
// E0548, // replaced with a generic attribute input check
611611
// rustc_deprecated attribute must be paired with either stable or unstable
612612
// attribute
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
The `issue` value is incorrect in a stability attribute.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0545
6+
#![feature(staged_api)]
7+
#![stable(since = "1.0.0", feature = "test")]
8+
9+
#[unstable(feature = "_unstable_fn", issue = "0")] // invalid
10+
fn _unstable_fn() {}
11+
12+
#[rustc_const_unstable(feature = "_unstable_const_fn", issue = "0")] // invalid
13+
fn _unstable_const_fn() {}
14+
```
15+
16+
To fix this issue, you need to provide a correct value in the `issue` field.
17+
Example:
18+
19+
```
20+
#![feature(staged_api)]
21+
#![stable(since = "1.0.0", feature = "test")]
22+
23+
#[unstable(feature = "_unstable_fn", issue = "none")] // ok!
24+
fn _unstable_fn() {}
25+
26+
#[rustc_const_unstable(feature = "_unstable_const_fn", issue = "1")] // ok!
27+
fn _unstable_const_fn() {}
28+
```
29+
30+
See the [How Rust is Made and “Nightly Rust”][how-rust-made-nightly] appendix
31+
of the Book and the [Stability attributes][stability-attributes] section of the
32+
Rustc Dev Guide for more details.
33+
34+
[how-rust-made-nightly]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
35+
[stability-attributes]: https://rustc-dev-guide.rust-lang.org/stability.html

‎compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl<'a> State<'a> {
392392
&f.decl,
393393
None,
394394
&f.generic_params,
395-
&f.param_names[..],
395+
f.param_names,
396396
);
397397
}
398398
hir::TyKind::OpaqueDef(..) => self.s.word("/*impl Trait*/"),
@@ -1200,7 +1200,7 @@ impl<'a> State<'a> {
12001200
self.s.word("{");
12011201
self.commasep_cmnt(
12021202
Consistent,
1203-
&fields[..],
1203+
fields,
12041204
|s, field| {
12051205
s.ibox(INDENT_UNIT);
12061206
if !field.is_shorthand {

‎compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
671671
if !impl_candidates.is_empty() && e.span.contains(span) {
672672
if let Some(expr) = exprs.first() {
673673
if let ExprKind::Path(hir::QPath::Resolved(_, path)) = expr.kind {
674-
if let [path_segment] = &path.segments[..] {
674+
if let [path_segment] = path.segments {
675675
let candidate_len = impl_candidates.len();
676676
let suggestions = impl_candidates.iter().map(|candidate| {
677677
format!(

‎compiler/rustc_infer/src/infer/undo_log.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct Snapshot<'tcx> {
1515
_marker: PhantomData<&'tcx ()>,
1616
}
1717

18-
/// Records the 'undo' data fora single operation that affects some form of inference variable.
18+
/// Records the "undo" data for a single operation that affects some form of inference variable.
1919
pub(crate) enum UndoLog<'tcx> {
2020
TypeVariables(type_variable::UndoLog<'tcx>),
2121
ConstUnificationTable(sv::UndoLog<ut::Delegate<ty::ConstVid<'tcx>>>),

‎compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ impl EncodeContext<'a, 'tcx> {
866866

867867
fn encode_variances_of(&mut self, def_id: DefId) {
868868
debug!("EncodeContext::encode_variances_of({:?})", def_id);
869-
record!(self.tables.variances[def_id] <- &self.tcx.variances_of(def_id)[..]);
869+
record!(self.tables.variances[def_id] <- self.tcx.variances_of(def_id));
870870
}
871871

872872
fn encode_item_type(&mut self, def_id: DefId) {

‎compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -854,22 +854,22 @@ impl<'hir> Map<'hir> {
854854
/// corresponding to the node-ID.
855855
pub fn attrs(&self, id: HirId) -> &'hir [ast::Attribute] {
856856
self.find_entry(id).map_or(&[], |entry| match entry.node {
857-
Node::Param(a) => &a.attrs[..],
857+
Node::Param(a) => a.attrs,
858858
Node::Local(l) => &l.attrs[..],
859-
Node::Item(i) => &i.attrs[..],
860-
Node::ForeignItem(fi) => &fi.attrs[..],
861-
Node::TraitItem(ref ti) => &ti.attrs[..],
862-
Node::ImplItem(ref ii) => &ii.attrs[..],
863-
Node::Variant(ref v) => &v.attrs[..],
864-
Node::Field(ref f) => &f.attrs[..],
859+
Node::Item(i) => i.attrs,
860+
Node::ForeignItem(fi) => fi.attrs,
861+
Node::TraitItem(ref ti) => ti.attrs,
862+
Node::ImplItem(ref ii) => ii.attrs,
863+
Node::Variant(ref v) => v.attrs,
864+
Node::Field(ref f) => f.attrs,
865865
Node::Expr(ref e) => &*e.attrs,
866866
Node::Stmt(ref s) => s.kind.attrs(|id| self.item(id.id)),
867867
Node::Arm(ref a) => &*a.attrs,
868-
Node::GenericParam(param) => &param.attrs[..],
868+
Node::GenericParam(param) => param.attrs,
869869
// Unit/tuple structs/variants take the attributes straight from
870870
// the struct/variant definition.
871871
Node::Ctor(..) => self.attrs(self.get_parent_item(id)),
872-
Node::Crate(item) => &item.attrs[..],
872+
Node::Crate(item) => item.attrs,
873873
Node::MacroDef(def) => def.attrs,
874874
Node::AnonConst(..)
875875
| Node::PathSegment(..)

‎compiler/rustc_middle/src/ty/query/on_disk_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl<'sess> OnDiskCache<'sess> {
427427

428428
fn sorted_cnums_including_local_crate(tcx: TyCtxt<'_>) -> Vec<CrateNum> {
429429
let mut cnums = vec![LOCAL_CRATE];
430-
cnums.extend_from_slice(&tcx.crates()[..]);
430+
cnums.extend_from_slice(tcx.crates());
431431
cnums.sort_unstable();
432432
// Just to be sure...
433433
cnums.dedup();

‎compiler/rustc_mir/src/interpret/validity.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,11 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
586586
self.path,
587587
err_unsup!(ReadPointerAsBytes) => { "part of a pointer" } expected { "a proper pointer or integer value" },
588588
);
589+
// Make sure we print a `ScalarMaybeUninit` (and not an `ImmTy`) in the error
590+
// message below.
591+
let value = value.to_scalar_or_uninit();
589592
let _fn = try_validation!(
590-
value.to_scalar().and_then(|ptr| self.ecx.memory.get_fn(ptr)),
593+
value.check_init().and_then(|ptr| self.ecx.memory.get_fn(ptr)),
591594
self.path,
592595
err_ub!(DanglingIntPointer(..)) |
593596
err_ub!(InvalidFunctionPointer(..)) |

‎compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
11051105
}
11061106

11071107
if let Some(items) = self.diagnostic_metadata.current_trait_assoc_items {
1108-
for assoc_item in &items[..] {
1108+
for assoc_item in items {
11091109
if assoc_item.ident == ident {
11101110
return Some(match &assoc_item.kind {
11111111
ast::AssocItemKind::Const(..) => AssocSuggestion::AssocConst,

‎compiler/rustc_target/src/spec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ impl Target {
14921492
} );
14931493
($key_name:ident = $json_name:expr, optional) => ( {
14941494
let name = $json_name;
1495-
if let Some(o) = obj.find(&name[..]) {
1495+
if let Some(o) = obj.find(name) {
14961496
base.$key_name = o
14971497
.as_string()
14981498
.map(|s| s.to_string() );

‎compiler/rustc_typeck/src/astconv/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
237237
}
238238
}
239239
if let ([], [bound]) = (&potential_assoc_types[..], &trait_bounds) {
240-
match &bound.trait_ref.path.segments[..] {
240+
match bound.trait_ref.path.segments {
241241
// FIXME: `trait_ref.path.span` can point to a full path with multiple
242242
// segments, even though `trait_ref.path.segments` is of length `1`. Work
243243
// around that bug here, even though it should be fixed elsewhere.

‎compiler/rustc_typeck/src/astconv/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2374,7 +2374,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
23742374
crate::collect::placeholder_type_error(
23752375
tcx,
23762376
ident_span.map(|sp| sp.shrink_to_hi()),
2377-
&generics.params[..],
2377+
generics.params,
23782378
visitor.0,
23792379
true,
23802380
hir_ty,

‎compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
897897
return (
898898
path.res,
899899
opt_qself.as_ref().map(|qself| self.to_ty(qself)),
900-
&path.segments[..],
900+
path.segments,
901901
);
902902
}
903903
QPath::TypeRelative(ref qself, ref segment) => (self.to_ty(qself), qself, segment),

‎compiler/rustc_typeck/src/check/method/suggest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
600600
});
601601
if let Some(hir::Node::Item(hir::Item { kind, .. })) = node {
602602
if let Some(g) = kind.generics() {
603-
let key = match &g.where_clause.predicates[..] {
603+
let key = match g.where_clause.predicates {
604604
[.., pred] => (pred.span().shrink_to_hi(), false),
605605
[] => (
606606
g.where_clause

‎compiler/rustc_typeck/src/collect.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,7 @@ fn reject_placeholder_type_signatures_in_item(tcx: TyCtxt<'tcx>, item: &'tcx hir
229229
let mut visitor = PlaceholderHirTyCollector::default();
230230
visitor.visit_item(item);
231231

232-
placeholder_type_error(
233-
tcx,
234-
Some(generics.span),
235-
&generics.params[..],
236-
visitor.0,
237-
suggest,
238-
None,
239-
);
232+
placeholder_type_error(tcx, Some(generics.span), generics.params, visitor.0, suggest, None);
240233
}
241234

242235
impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
@@ -417,7 +410,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
417410
| hir::ItemKind::Struct(_, generics)
418411
| hir::ItemKind::Union(_, generics) => {
419412
let lt_name = get_new_lifetime_name(self.tcx, poly_trait_ref, generics);
420-
let (lt_sp, sugg) = match &generics.params[..] {
413+
let (lt_sp, sugg) = match generics.params {
421414
[] => (generics.span, format!("<{}>", lt_name)),
422415
[bound, ..] => {
423416
(bound.span.shrink_to_lo(), format!("{}, ", lt_name))

‎library/core/src/intrinsics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,8 +1688,8 @@ extern "rust-intrinsic" {
16881688
#[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
16891689
pub fn saturating_sub<T: Copy>(a: T, b: T) -> T;
16901690

1691-
/// Returns the value of the discriminant for the variant in 'v',
1692-
/// cast to a `u64`; if `T` has no discriminant, returns `0`.
1691+
/// Returns the value of the discriminant for the variant in 'v';
1692+
/// if `T` has no discriminant, returns `0`.
16931693
///
16941694
/// The stabilized version of this intrinsic is [`core::mem::discriminant`](crate::mem::discriminant).
16951695
#[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]

‎src/bootstrap/flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
347347
};
348348

349349
// Done specifying what options are possible, so do the getopts parsing
350-
let matches = opts.parse(&args[..]).unwrap_or_else(|e| {
350+
let matches = opts.parse(args).unwrap_or_else(|e| {
351351
// Invalid argument/option format
352352
println!("\n{}\n", e);
353353
usage(1, &opts, false, &subcommand_help);

‎src/librustdoc/clean/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ where
975975
{
976976
fn clean(&self, cx: &DocContext<'_>) -> FnDecl {
977977
FnDecl {
978-
inputs: (&self.0.inputs[..], self.1).clean(cx),
978+
inputs: (self.0.inputs, self.1).clean(cx),
979979
output: self.0.output.clean(cx),
980980
c_variadic: self.0.c_variadic,
981981
attrs: Attributes::default(),
@@ -1939,7 +1939,7 @@ impl Clean<String> for Symbol {
19391939
impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> {
19401940
fn clean(&self, cx: &DocContext<'_>) -> BareFunctionDecl {
19411941
let (generic_params, decl) = enter_impl_trait(cx, || {
1942-
(self.generic_params.clean(cx), (&*self.decl, &self.param_names[..]).clean(cx))
1942+
(self.generic_params.clean(cx), (&*self.decl, self.param_names).clean(cx))
19431943
});
19441944
BareFunctionDecl { unsafety: self.unsafety, abi: self.abi, decl, generic_params }
19451945
}

‎src/librustdoc/html/static/main.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,10 +2908,14 @@ function defocusSearchBar() {
29082908
["&#9166;", "Go to active search result"],
29092909
["+", "Expand all sections"],
29102910
["-", "Collapse all sections"],
2911-
].map(x => "<dt>" +
2912-
x[0].split(" ")
2913-
.map((y, index) => (index & 1) === 0 ? "<kbd>" + y + "</kbd>" : " " + y + " ")
2914-
.join("") + "</dt><dd>" + x[1] + "</dd>").join("");
2911+
].map(function(x) {
2912+
return "<dt>" +
2913+
x[0].split(" ")
2914+
.map(function(y, index) {
2915+
return (index & 1) === 0 ? "<kbd>" + y + "</kbd>" : " " + y + " ";
2916+
})
2917+
.join("") + "</dt><dd>" + x[1] + "</dd>";
2918+
}).join("");
29152919
var div_shortcuts = document.createElement("div");
29162920
addClass(div_shortcuts, "shortcuts");
29172921
div_shortcuts.innerHTML = "<h2>Keyboard Shortcuts</h2><dl>" + shortcuts + "</dl></div>";
@@ -2929,7 +2933,9 @@ function defocusSearchBar() {
29292933
"You can look for items with an exact name by putting double quotes around \
29302934
your request: <code>\"string\"</code>",
29312935
"Look for items inside another one by searching for a path: <code>vec::Vec</code>",
2932-
].map(x => "<p>" + x + "</p>").join("");
2936+
].map(function(x) {
2937+
return "<p>" + x + "</p>";
2938+
}).join("");
29332939
var div_infos = document.createElement("div");
29342940
addClass(div_infos, "infos");
29352941
div_infos.innerHTML = "<h2>Search Tricks</h2>" + infos;

‎src/librustdoc/html/static/storage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ var updateSystemTheme = (function() {
157157
if (!window.matchMedia) {
158158
// fallback to the CSS computed value
159159
return function() {
160-
let cssTheme = getComputedStyle(document.documentElement)
160+
var cssTheme = getComputedStyle(document.documentElement)
161161
.getPropertyValue('content');
162162

163163
switchTheme(

‎src/test/ui/consts/const-eval/ub-ref.rs renamed to ‎src/test/ui/consts/const-eval/ub-ref-ptr.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
use std::mem;
55

6+
#[repr(C)]
7+
union MaybeUninit<T: Copy> {
8+
uninit: (),
9+
init: T,
10+
}
11+
612
const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
713
//~^ ERROR it is undefined behavior to use this value
814
//~| type validation failed: encountered an unaligned reference (required 2 byte alignment but found 1)
@@ -35,4 +41,9 @@ const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
3541
const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) };
3642
//~^ ERROR it is undefined behavior to use this value
3743

44+
const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init };
45+
//~^ ERROR it is undefined behavior to use this value
46+
const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init };
47+
//~^ ERROR it is undefined behavior to use this value
48+
3849
fn main() {}
Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,91 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/ub-ref.rs:6:1
2+
--> $DIR/ub-ref-ptr.rs:12:1
33
|
44
LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered an unaligned reference (required 2 byte alignment but found 1)
66
|
77
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
88

99
error[E0080]: it is undefined behavior to use this value
10-
--> $DIR/ub-ref.rs:10:1
10+
--> $DIR/ub-ref-ptr.rs:16:1
1111
|
1212
LL | const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) };
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered an unaligned box (required 2 byte alignment but found 1)
1414
|
1515
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
1616

1717
error[E0080]: it is undefined behavior to use this value
18-
--> $DIR/ub-ref.rs:14:1
18+
--> $DIR/ub-ref-ptr.rs:20:1
1919
|
2020
LL | const NULL: &u16 = unsafe { mem::transmute(0usize) };
2121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a NULL reference
2222
|
2323
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
2424

2525
error[E0080]: it is undefined behavior to use this value
26-
--> $DIR/ub-ref.rs:17:1
26+
--> $DIR/ub-ref-ptr.rs:23:1
2727
|
2828
LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) };
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a NULL box
3030
|
3131
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
3232

3333
error[E0080]: it is undefined behavior to use this value
34-
--> $DIR/ub-ref.rs:23:1
34+
--> $DIR/ub-ref-ptr.rs:29:1
3535
|
3636
LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc14, but expected initialized plain (non-pointer) bytes
3838
|
3939
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
4040

4141
error[E0080]: it is undefined behavior to use this value
42-
--> $DIR/ub-ref.rs:26:1
42+
--> $DIR/ub-ref-ptr.rs:32:1
4343
|
4444
LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
4545
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .<deref>, but expected plain (non-pointer) bytes
4646
|
4747
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
4848

4949
error[E0080]: it is undefined behavior to use this value
50-
--> $DIR/ub-ref.rs:29:1
50+
--> $DIR/ub-ref-ptr.rs:35:1
5151
|
5252
LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
5353
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .<deref>, but expected plain (non-pointer) bytes
5454
|
5555
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
5656

5757
error[E0080]: it is undefined behavior to use this value
58-
--> $DIR/ub-ref.rs:32:1
58+
--> $DIR/ub-ref-ptr.rs:38:1
5959
|
6060
LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
6161
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a dangling reference (created from integer)
6262
|
6363
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
6464

6565
error[E0080]: it is undefined behavior to use this value
66-
--> $DIR/ub-ref.rs:35:1
66+
--> $DIR/ub-ref-ptr.rs:41:1
6767
|
6868
LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) };
6969
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a dangling box (created from integer)
7070
|
7171
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
7272

73-
error: aborting due to 9 previous errors
73+
error[E0080]: it is undefined behavior to use this value
74+
--> $DIR/ub-ref-ptr.rs:44:1
75+
|
76+
LL | const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init };
77+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized raw pointer
78+
|
79+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
80+
81+
error[E0080]: it is undefined behavior to use this value
82+
--> $DIR/ub-ref-ptr.rs:46:1
83+
|
84+
LL | const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init };
85+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes, but expected a function pointer
86+
|
87+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
88+
89+
error: aborting due to 11 previous errors
7490

7591
For more information about this error, try `rustc --explain E0080`.

‎src/test/ui/feature-gates/unstable-attribute-allow-issue-0.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ LL | #[unstable(feature = "unstable_test_feature", issue = "something")]
1616

1717
error: aborting due to 2 previous errors
1818

19+
For more information about this error, try `rustc --explain E0545`.

‎src/test/ui/stability-attribute/stability-attribute-sanity-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ LL | #[unstable(feature = "a", issue = "no")]
2020

2121
error: aborting due to 3 previous errors
2222

23-
Some errors have detailed explanations: E0538, E0541.
23+
Some errors have detailed explanations: E0538, E0541, E0545.
2424
For more information about an error, try `rustc --explain E0538`.

0 commit comments

Comments
 (0)
Please sign in to comment.