Skip to content

Commit a143325

Browse files
committed
Auto merge of #66009 - tmandry:rollup-jt3wtfr, r=tmandry
Rollup of 14 pull requests Successful merges: - #65112 (Add lint and tests for unnecessary parens around types) - #65459 (Fix `-Zunpretty=mir-cfg` to render multiple items) - #65471 (Add long error explanation for E0578) - #65857 (rustdoc: Resolve module-level doc references more locally) - #65914 (Use structured suggestion for unnecessary bounds in type aliases) - #65945 (Optimize long-linker-command-line test) - #65946 (Make `promote_consts` emit the errors when required promotion fails) - #65960 (doc: reword iter module example and mention other methods) - #65963 (update submodules to rust-lang) - #65972 (Fix libunwind build: Define __LITTLE_ENDIAN__ for LE targets) - #65977 (Fix incorrect diagnostics for expected type in E0271 with an associated type) - #65995 (Add error code E0743 for "C-variadic has been used on a non-foreign function") - #65997 (Fix outdated rustdoc of Once::init_locking function) - #66005 (vxWorks: remove code related unix socket) Failed merges: r? @ghost
2 parents aa4e57c + 1c5156a commit a143325

File tree

54 files changed

+608
-2041
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+608
-2041
lines changed

.gitmodules

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
url = https://github.com/rust-lang/rust-installer.git
44
[submodule "src/doc/nomicon"]
55
path = src/doc/nomicon
6-
url = https://github.com/rust-lang-nursery/nomicon.git
6+
url = https://github.com/rust-lang/nomicon.git
77
[submodule "src/tools/cargo"]
88
path = src/tools/cargo
99
url = https://github.com/rust-lang/cargo.git
1010
[submodule "src/doc/reference"]
1111
path = src/doc/reference
12-
url = https://github.com/rust-lang-nursery/reference.git
12+
url = https://github.com/rust-lang/reference.git
1313
[submodule "src/doc/book"]
1414
path = src/doc/book
1515
url = https://github.com/rust-lang/book.git
@@ -36,7 +36,7 @@
3636
url = https://github.com/rust-lang/rustc-guide.git
3737
[submodule "src/doc/edition-guide"]
3838
path = src/doc/edition-guide
39-
url = https://github.com/rust-lang-nursery/edition-guide.git
39+
url = https://github.com/rust-lang/edition-guide.git
4040
[submodule "src/llvm-project"]
4141
path = src/llvm-project
4242
url = https://github.com/rust-lang/llvm-project.git

src/libcore/iter/mod.rs

+14-21
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,16 @@
118118
//!
119119
//! let mut counter = Counter::new();
120120
//!
121-
//! let x = counter.next().unwrap();
122-
//! println!("{}", x);
123-
//!
124-
//! let x = counter.next().unwrap();
125-
//! println!("{}", x);
126-
//!
127-
//! let x = counter.next().unwrap();
128-
//! println!("{}", x);
129-
//!
130-
//! let x = counter.next().unwrap();
131-
//! println!("{}", x);
132-
//!
133-
//! let x = counter.next().unwrap();
134-
//! println!("{}", x);
121+
//! assert_eq!(counter.next(), Some(1));
122+
//! assert_eq!(counter.next(), Some(2));
123+
//! assert_eq!(counter.next(), Some(3));
124+
//! assert_eq!(counter.next(), Some(4));
125+
//! assert_eq!(counter.next(), Some(5));
126+
//! assert_eq!(counter.next(), None);
135127
//! ```
136128
//!
137-
//! This will print `1` through `5`, each on their own line.
138-
//!
139-
//! Calling `next()` this way gets repetitive. Rust has a construct which can
140-
//! call `next()` on your iterator, until it reaches `None`. Let's go over that
129+
//! Calling [`next`] this way gets repetitive. Rust has a construct which can
130+
//! call [`next`] on your iterator, until it reaches `None`. Let's go over that
141131
//! next.
142132
//!
143133
//! Also note that `Iterator` provides a default implementation of methods such as `nth` and `fold`
@@ -253,20 +243,23 @@
253243
//! ```
254244
//!
255245
//! The idiomatic way to write a [`map`] for its side effects is to use a
256-
//! `for` loop instead:
246+
//! `for` loop or call the [`for_each`] method:
257247
//!
258248
//! ```
259249
//! let v = vec![1, 2, 3, 4, 5];
260250
//!
251+
//! v.iter().for_each(|x| println!("{}", x));
252+
//! // or
261253
//! for x in &v {
262254
//! println!("{}", x);
263255
//! }
264256
//! ```
265257
//!
266258
//! [`map`]: trait.Iterator.html#method.map
259+
//! [`for_each`]: trait.Iterator.html#method.for_each
267260
//!
268-
//! The two most common ways to evaluate an iterator are to use a `for` loop
269-
//! like this, or using the [`collect`] method to produce a new collection.
261+
//! Another common way to evaluate an iterator is to use the [`collect`]
262+
//! method to produce a new collection.
270263
//!
271264
//! [`collect`]: trait.Iterator.html#method.collect
272265
//!

src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
6262
&self,
6363
arg: &'tcx hir::Ty,
6464
br: &ty::BoundRegion,
65-
) -> Option<(&'tcx hir::Ty)> {
65+
) -> Option<&'tcx hir::Ty> {
6666
let mut nested_visitor = FindNestedTypeVisitor {
6767
tcx: self.tcx(),
6868
bound_region: *br,

src/librustc/traits/error_reporting.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,26 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
226226
0,
227227
&mut obligations
228228
);
229+
230+
debug!("report_projection_error obligation.cause={:?} obligation.param_env={:?}",
231+
obligation.cause, obligation.param_env);
232+
233+
debug!("report_projection_error normalized_ty={:?} data.ty={:?}",
234+
normalized_ty, data.ty);
235+
236+
let is_normalized_ty_expected = match &obligation.cause.code {
237+
ObligationCauseCode::ItemObligation(_) |
238+
ObligationCauseCode::BindingObligation(_, _) |
239+
ObligationCauseCode::ObjectCastObligation(_) => false,
240+
_ => true,
241+
};
242+
229243
if let Err(error) = self.at(&obligation.cause, obligation.param_env)
230-
.eq(normalized_ty, data.ty)
244+
.eq_exp(is_normalized_ty_expected, normalized_ty, data.ty)
231245
{
232-
values = Some(infer::ValuePairs::Types(ExpectedFound {
233-
expected: normalized_ty,
234-
found: data.ty,
235-
}));
246+
values = Some(infer::ValuePairs::Types(
247+
ExpectedFound::new(is_normalized_ty_expected, normalized_ty, data.ty)));
248+
236249
err_buf = error;
237250
err = &err_buf;
238251
}

src/librustc_data_structures/owning_ref/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1046,14 +1046,14 @@ unsafe impl<O, T: ?Sized> CloneStableAddress for OwningRef<O, T>
10461046
where O: CloneStableAddress {}
10471047

10481048
unsafe impl<O, T: ?Sized> Send for OwningRef<O, T>
1049-
where O: Send, for<'a> (&'a T): Send {}
1049+
where O: Send, for<'a> &'a T: Send {}
10501050
unsafe impl<O, T: ?Sized> Sync for OwningRef<O, T>
1051-
where O: Sync, for<'a> (&'a T): Sync {}
1051+
where O: Sync, for<'a> &'a T: Sync {}
10521052

10531053
unsafe impl<O, T: ?Sized> Send for OwningRefMut<O, T>
1054-
where O: Send, for<'a> (&'a mut T): Send {}
1054+
where O: Send, for<'a> &'a mut T: Send {}
10551055
unsafe impl<O, T: ?Sized> Sync for OwningRefMut<O, T>
1056-
where O: Sync, for<'a> (&'a mut T): Sync {}
1056+
where O: Sync, for<'a> &'a mut T: Sync {}
10571057

10581058
impl Debug for dyn Erased {
10591059
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

src/librustc_data_structures/sync.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,10 @@ impl<T> Once<T> {
492492
assert!(self.try_set(value).is_none());
493493
}
494494

495-
/// Tries to initialize the inner value by calling the closure while ensuring that no-one else
496-
/// can access the value in the mean time by holding a lock for the duration of the closure.
497-
/// If the value was already initialized the closure is not called and `false` is returned,
498-
/// otherwise if the value from the closure initializes the inner value, `true` is returned
495+
/// Initializes the inner value if it wasn't already done by calling the provided closure. It
496+
/// ensures that no-one else can access the value in the mean time by holding a lock for the
497+
/// duration of the closure.
498+
/// A reference to the inner value is returned.
499499
#[inline]
500500
pub fn init_locking<F: FnOnce() -> T>(&self, f: F) -> &T {
501501
{

src/librustc_lint/builtin.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -1125,8 +1125,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds {
11251125
.map(|pred| pred.span()).collect();
11261126
let mut err = cx.struct_span_lint(TYPE_ALIAS_BOUNDS, spans,
11271127
"where clauses are not enforced in type aliases");
1128-
err.help("the clause will not be checked when the type alias is used, \
1129-
and should be removed");
1128+
err.span_suggestion(
1129+
type_alias_generics.where_clause.span_for_predicates_or_empty_place(),
1130+
"the clause will not be checked when the type alias is used, and should be removed",
1131+
String::new(),
1132+
Applicability::MachineApplicable,
1133+
);
11301134
if !suggested_changing_assoc_types {
11311135
TypeAliasBounds::suggest_changing_assoc_types(ty, &mut err);
11321136
suggested_changing_assoc_types = true;
@@ -1136,14 +1140,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeAliasBounds {
11361140
// The parameters must not have bounds
11371141
for param in type_alias_generics.params.iter() {
11381142
let spans: Vec<_> = param.bounds.iter().map(|b| b.span()).collect();
1143+
let suggestion = spans.iter().map(|sp| {
1144+
let start = param.span.between(*sp); // Include the `:` in `T: Bound`.
1145+
(start.to(*sp), String::new())
1146+
}).collect();
11391147
if !spans.is_empty() {
11401148
let mut err = cx.struct_span_lint(
11411149
TYPE_ALIAS_BOUNDS,
11421150
spans,
11431151
"bounds on generic parameters are not enforced in type aliases",
11441152
);
1145-
err.help("the bound will not be checked when the type alias is used, \
1146-
and should be removed");
1153+
let msg = "the bound will not be checked when the type alias is used, \
1154+
and should be removed";
1155+
err.multipart_suggestion(&msg, suggestion, Applicability::MachineApplicable);
11471156
if !suggested_changing_assoc_types {
11481157
TypeAliasBounds::suggest_changing_assoc_types(ty, &mut err);
11491158
suggested_changing_assoc_types = true;

src/librustc_lint/unused.rs

+19
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,25 @@ impl EarlyLintPass for UnusedParens {
598598
fn check_arm(&mut self, cx: &EarlyContext<'_>, arm: &ast::Arm) {
599599
self.check_unused_parens_pat(cx, &arm.pat, false, false);
600600
}
601+
602+
fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) {
603+
if let &ast::TyKind::Paren(ref r) = &ty.kind {
604+
match &r.kind {
605+
&ast::TyKind::TraitObject(..) => {}
606+
&ast::TyKind::ImplTrait(_, ref bounds) if bounds.len() > 1 => {}
607+
_ => {
608+
let pattern_text = if let Ok(snippet) = cx.sess().source_map()
609+
.span_to_snippet(ty.span) {
610+
snippet
611+
} else {
612+
pprust::ty_to_string(ty)
613+
};
614+
615+
Self::remove_outer_parens(cx, ty.span, &pattern_text, "type", (false, false));
616+
}
617+
}
618+
}
619+
}
601620
}
602621

603622
declare_lint! {

src/librustc_mir/borrow_check/prefixes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(super) struct Prefixes<'cx, 'tcx> {
2929
body: &'cx Body<'tcx>,
3030
tcx: TyCtxt<'tcx>,
3131
kind: PrefixSet,
32-
next: Option<(PlaceRef<'cx, 'tcx>)>,
32+
next: Option<PlaceRef<'cx, 'tcx>>,
3333
}
3434

3535
#[derive(Copy, Clone, PartialEq, Eq, Debug)]

src/librustc_mir/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2545,7 +2545,7 @@ There are some known bugs that trigger this message.
25452545
// E0471, // constant evaluation error (in pattern)
25462546
// E0385, // {} in an aliasable location
25472547
E0521, // borrowed data escapes outside of closure
2548-
E0526, // shuffle indices are not constant
2548+
// E0526, // shuffle indices are not constant
25492549
E0594, // cannot assign to {}
25502550
// E0598, // lifetime of {} is too short to guarantee its contents can be...
25512551
E0625, // thread-local statics cannot be accessed at compile-time

src/librustc_mir/transform/promote_consts.rs

+23-6
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ pub enum Candidate {
8080
Argument { bb: BasicBlock, index: usize },
8181
}
8282

83+
impl Candidate {
84+
/// Returns `true` if we should use the "explicit" rules for promotability for this `Candidate`.
85+
fn forces_explicit_promotion(&self) -> bool {
86+
match self {
87+
Candidate::Ref(_) |
88+
Candidate::Repeat(_) => false,
89+
Candidate::Argument { .. } => true,
90+
}
91+
}
92+
}
93+
8394
fn args_required_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Vec<usize>> {
8495
let attrs = tcx.get_attrs(def_id);
8596
let attr = attrs.iter().find(|a| a.check_name(sym::rustc_args_required_const))?;
@@ -727,16 +738,22 @@ pub fn validate_candidates(
727738
};
728739

729740
candidates.iter().copied().filter(|&candidate| {
730-
validator.explicit = match candidate {
731-
Candidate::Ref(_) |
732-
Candidate::Repeat(_) => false,
733-
Candidate::Argument { .. } => true,
734-
};
741+
validator.explicit = candidate.forces_explicit_promotion();
735742

736743
// FIXME(eddyb) also emit the errors for shuffle indices
737744
// and `#[rustc_args_required_const]` arguments here.
738745

739-
validator.validate_candidate(candidate).is_ok()
746+
let is_promotable = validator.validate_candidate(candidate).is_ok();
747+
match candidate {
748+
Candidate::Argument { bb, index } if !is_promotable => {
749+
let span = body[bb].terminator().source_info.span;
750+
let msg = format!("argument {} is required to be a constant", index + 1);
751+
tcx.sess.span_err(span, &msg);
752+
}
753+
_ => ()
754+
}
755+
756+
is_promotable
740757
}).collect()
741758
}
742759

src/librustc_mir/transform/qualify_consts.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -1606,20 +1606,12 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
16061606
// This is not a problem, because the argument explicitly
16071607
// requests constness, in contrast to regular promotion
16081608
// which happens even without the user requesting it.
1609-
// We can error out with a hard error if the argument is not
1610-
// constant here.
1609+
//
1610+
// `promote_consts` is responsible for emitting the error if
1611+
// the argument is not promotable.
16111612
if !IsNotPromotable::in_operand(self, arg) {
16121613
debug!("visit_terminator_kind: candidate={:?}", candidate);
16131614
self.promotion_candidates.push(candidate);
1614-
} else {
1615-
if is_shuffle {
1616-
span_err!(self.tcx.sess, self.span, E0526,
1617-
"shuffle indices are not constant");
1618-
} else {
1619-
self.tcx.sess.span_err(self.span,
1620-
&format!("argument {} is required to be a constant",
1621-
i + 1));
1622-
}
16231615
}
16241616
}
16251617
}

0 commit comments

Comments
 (0)