Skip to content

Commit d8215fc

Browse files
committed
Auto merge of #42049 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 5 pull requests - Successful merges: #41937, #41957, #42017, #42039, #42046 - Failed merges:
2 parents 86319e4 + c3d22eb commit d8215fc

Some content is hidden

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

41 files changed

+617
-547
lines changed

src/doc/book

Submodule book updated 62 files

src/doc/reference

src/librustc/infer/combine.rs

+19
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ use super::sub::Sub;
3939
use super::InferCtxt;
4040
use super::{MiscVariable, TypeTrace};
4141

42+
use hir::def_id::DefId;
4243
use ty::{IntType, UintType};
4344
use ty::{self, Ty, TyCtxt};
4445
use ty::error::TypeError;
4546
use ty::relate::{self, Relate, RelateResult, TypeRelation};
47+
use ty::subst::Substs;
4648
use traits::{Obligation, PredicateObligations};
4749

4850
use syntax::ast;
@@ -336,6 +338,23 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
336338
Ok(ty::Binder(self.relate(a.skip_binder(), b.skip_binder())?))
337339
}
338340

341+
fn relate_item_substs(&mut self,
342+
item_def_id: DefId,
343+
a_subst: &'tcx Substs<'tcx>,
344+
b_subst: &'tcx Substs<'tcx>)
345+
-> RelateResult<'tcx, &'tcx Substs<'tcx>>
346+
{
347+
if self.ambient_variance == ty::Variance::Invariant {
348+
// Avoid fetching the variance if we are in an invariant
349+
// context; no need, and it can induce dependency cycles
350+
// (e.g. #41849).
351+
relate::relate_substs(self, None, a_subst, b_subst)
352+
} else {
353+
let opt_variances = self.tcx().variances_of(item_def_id);
354+
relate::relate_substs(self, Some(&opt_variances), a_subst, b_subst)
355+
}
356+
}
357+
339358
fn relate_with_variance<T: Relate<'tcx>>(&mut self,
340359
variance: ty::Variance,
341360
a: &T,

src/librustc/ty/maps.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ macro_rules! define_map_struct {
592592
output: $output:tt) => {
593593
define_map_struct! {
594594
tcx: $tcx,
595-
ready: ([pub] $attrs $name),
595+
ready: ([] $attrs $name),
596596
input: ($($input)*),
597597
output: $output
598598
}

src/librustc_mir/util/pretty.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ fn write_mir_sig(tcx: TyCtxt, src: MirSource, mir: &Mir, w: &mut Write)
324324
MirSource::Promoted(_, i) => write!(w, "{:?} in", i)?
325325
}
326326

327-
write!(w, " {}", tcx.node_path_str(src.item_id()))?;
327+
item_path::with_forced_impl_filename_line(|| { // see notes on #41697 elsewhere
328+
write!(w, " {}", tcx.node_path_str(src.item_id()))
329+
})?;
328330

329331
if let MirSource::Fn(_) = src {
330332
write!(w, "(")?;

src/librustc_typeck/coherence/builtin.rs

+49-2
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,45 @@ pub fn coerce_unsized_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
249249
return err_info;
250250
}
251251

252+
// Here we are considering a case of converting
253+
// `S<P0...Pn>` to S<Q0...Qn>`. As an example, let's imagine a struct `Foo<T, U>`,
254+
// which acts like a pointer to `U`, but carries along some extra data of type `T`:
255+
//
256+
// struct Foo<T, U> {
257+
// extra: T,
258+
// ptr: *mut U,
259+
// }
260+
//
261+
// We might have an impl that allows (e.g.) `Foo<T, [i32; 3]>` to be unsized
262+
// to `Foo<T, [i32]>`. That impl would look like:
263+
//
264+
// impl<T, U: Unsize<V>, V> CoerceUnsized<Foo<T, V>> for Foo<T, U> {}
265+
//
266+
// Here `U = [i32; 3]` and `V = [i32]`. At runtime,
267+
// when this coercion occurs, we would be changing the
268+
// field `ptr` from a thin pointer of type `*mut [i32;
269+
// 3]` to a fat pointer of type `*mut [i32]` (with
270+
// extra data `3`). **The purpose of this check is to
271+
// make sure that we know how to do this conversion.**
272+
//
273+
// To check if this impl is legal, we would walk down
274+
// the fields of `Foo` and consider their types with
275+
// both substitutes. We are looking to find that
276+
// exactly one (non-phantom) field has changed its
277+
// type, which we will expect to be the pointer that
278+
// is becoming fat (we could probably generalize this
279+
// to mutiple thin pointers of the same type becoming
280+
// fat, but we don't). In this case:
281+
//
282+
// - `extra` has type `T` before and type `T` after
283+
// - `ptr` has type `*mut U` before and type `*mut V` after
284+
//
285+
// Since just one field changed, we would then check
286+
// that `*mut U: CoerceUnsized<*mut V>` is implemented
287+
// (in other words, that we know how to do this
288+
// conversion). This will work out because `U:
289+
// Unsize<V>`, and we have a builtin rule that `*mut
290+
// U` can be coerced to `*mut V` if `U: Unsize<V>`.
252291
let fields = &def_a.struct_variant().fields;
253292
let diff_fields = fields.iter()
254293
.enumerate()
@@ -260,8 +299,16 @@ pub fn coerce_unsized_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
260299
return None;
261300
}
262301

263-
// Ignore fields that aren't significantly changed
264-
if let Ok(ok) = infcx.sub_types(false, &cause, b, a) {
302+
// Ignore fields that aren't changed; it may
303+
// be that we could get away with subtyping or
304+
// something more accepting, but we use
305+
// equality because we want to be able to
306+
// perform this check without computing
307+
// variance where possible. (This is because
308+
// we may have to evaluate constraint
309+
// expressions in the course of execution.)
310+
// See e.g. #41936.
311+
if let Ok(ok) = infcx.eq_types(false, &cause, b, a) {
265312
if ok.obligations.is_empty() {
266313
return None;
267314
}

src/libsyntax/ast.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ impl Stmt {
715715
StmtKind::Mac(mac) => StmtKind::Mac(mac.map(|(mac, _style, attrs)| {
716716
(mac, MacStmtStyle::Semicolon, attrs)
717717
})),
718-
node @ _ => node,
718+
node => node,
719719
};
720720
self
721721
}
@@ -1076,16 +1076,16 @@ impl LitKind {
10761076
pub fn is_unsuffixed(&self) -> bool {
10771077
match *self {
10781078
// unsuffixed variants
1079-
LitKind::Str(..) => true,
1080-
LitKind::ByteStr(..) => true,
1081-
LitKind::Byte(..) => true,
1082-
LitKind::Char(..) => true,
1083-
LitKind::Int(_, LitIntType::Unsuffixed) => true,
1084-
LitKind::FloatUnsuffixed(..) => true,
1079+
LitKind::Str(..) |
1080+
LitKind::ByteStr(..) |
1081+
LitKind::Byte(..) |
1082+
LitKind::Char(..) |
1083+
LitKind::Int(_, LitIntType::Unsuffixed) |
1084+
LitKind::FloatUnsuffixed(..) |
10851085
LitKind::Bool(..) => true,
10861086
// suffixed variants
1087-
LitKind::Int(_, LitIntType::Signed(..)) => false,
1088-
LitKind::Int(_, LitIntType::Unsigned(..)) => false,
1087+
LitKind::Int(_, LitIntType::Signed(..)) |
1088+
LitKind::Int(_, LitIntType::Unsigned(..)) |
10891089
LitKind::Float(..) => false,
10901090
}
10911091
}

src/libsyntax/attr.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ impl NestedMetaItem {
112112
/// Returns the MetaItem if self is a NestedMetaItemKind::MetaItem.
113113
pub fn meta_item(&self) -> Option<&MetaItem> {
114114
match self.node {
115-
NestedMetaItemKind::MetaItem(ref item) => Some(&item),
115+
NestedMetaItemKind::MetaItem(ref item) => Some(item),
116116
_ => None
117117
}
118118
}
119119

120120
/// Returns the Lit if self is a NestedMetaItemKind::Literal.
121121
pub fn literal(&self) -> Option<&Lit> {
122122
match self.node {
123-
NestedMetaItemKind::Literal(ref lit) => Some(&lit),
123+
NestedMetaItemKind::Literal(ref lit) => Some(lit),
124124
_ => None
125125
}
126126
}
@@ -259,7 +259,7 @@ impl MetaItem {
259259
match self.node {
260260
MetaItemKind::NameValue(ref v) => {
261261
match v.node {
262-
LitKind::Str(ref s, _) => Some((*s).clone()),
262+
LitKind::Str(ref s, _) => Some(*s),
263263
_ => None,
264264
}
265265
},
@@ -1217,9 +1217,10 @@ impl LitKind {
12171217
Token::Literal(token::Lit::Float(symbol), Some(Symbol::intern(ty.ty_to_string())))
12181218
}
12191219
LitKind::FloatUnsuffixed(symbol) => Token::Literal(token::Lit::Float(symbol), None),
1220-
LitKind::Bool(value) => Token::Ident(Ident::with_empty_ctxt(Symbol::intern(match value {
1221-
true => "true",
1222-
false => "false",
1220+
LitKind::Bool(value) => Token::Ident(Ident::with_empty_ctxt(Symbol::intern(if value {
1221+
"true"
1222+
} else {
1223+
"false"
12231224
}))),
12241225
}
12251226
}
@@ -1261,7 +1262,7 @@ impl<T: HasAttrs> HasAttrs for Spanned<T> {
12611262

12621263
impl HasAttrs for Vec<Attribute> {
12631264
fn attrs(&self) -> &[Attribute] {
1264-
&self
1265+
self
12651266
}
12661267
fn map_attrs<F: FnOnce(Vec<Attribute>) -> Vec<Attribute>>(self, f: F) -> Self {
12671268
f(self)
@@ -1270,7 +1271,7 @@ impl HasAttrs for Vec<Attribute> {
12701271

12711272
impl HasAttrs for ThinVec<Attribute> {
12721273
fn attrs(&self) -> &[Attribute] {
1273-
&self
1274+
self
12741275
}
12751276
fn map_attrs<F: FnOnce(Vec<Attribute>) -> Vec<Attribute>>(self, f: F) -> Self {
12761277
f(self.into()).into()

src/libsyntax/codemap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl CodeMap {
485485
match self.span_to_snippet(sp) {
486486
Ok(snippet) => {
487487
let snippet = snippet.split(c).nth(0).unwrap_or("").trim_right();
488-
if snippet.len() > 0 && !snippet.contains('\n') {
488+
if !snippet.is_empty() && !snippet.contains('\n') {
489489
Span { hi: BytePos(sp.lo.0 + snippet.len() as u32), ..sp }
490490
} else {
491491
sp
@@ -502,7 +502,7 @@ impl CodeMap {
502502
pub fn get_filemap(&self, filename: &str) -> Option<Rc<FileMap>> {
503503
for fm in self.files.borrow().iter() {
504504
if filename == fm.name {
505-
(self.dep_tracking_callback.borrow())(&fm);
505+
(self.dep_tracking_callback.borrow())(fm);
506506
return Some(fm.clone());
507507
}
508508
}

src/libsyntax/config.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'a> StripUnconfigured<'a> {
123123
return false;
124124
}
125125

126-
let mis = if !is_cfg(&attr) {
126+
let mis = if !is_cfg(attr) {
127127
return true;
128128
} else if let Some(mis) = attr.meta_item_list() {
129129
mis
@@ -150,7 +150,7 @@ impl<'a> StripUnconfigured<'a> {
150150
// flag the offending attributes
151151
for attr in attrs.iter() {
152152
if !self.features.map(|features| features.stmt_expr_attributes).unwrap_or(true) {
153-
let mut err = feature_err(&self.sess,
153+
let mut err = feature_err(self.sess,
154154
"stmt_expr_attributes",
155155
attr.span,
156156
GateIssue::Language,
@@ -258,7 +258,7 @@ impl<'a> StripUnconfigured<'a> {
258258
pub fn configure_struct_expr_field(&mut self, field: ast::Field) -> Option<ast::Field> {
259259
if !self.features.map(|features| features.struct_field_attributes).unwrap_or(true) {
260260
if !field.attrs.is_empty() {
261-
let mut err = feature_err(&self.sess,
261+
let mut err = feature_err(self.sess,
262262
"struct_field_attributes",
263263
field.span,
264264
GateIssue::Language,
@@ -290,7 +290,7 @@ impl<'a> StripUnconfigured<'a> {
290290
for attr in attrs.iter() {
291291
if !self.features.map(|features| features.struct_field_attributes).unwrap_or(true) {
292292
let mut err = feature_err(
293-
&self.sess,
293+
self.sess,
294294
"struct_field_attributes",
295295
attr.span,
296296
GateIssue::Language,

src/libsyntax/diagnostics/plugin.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
120120

121121
// URLs can be unavoidably longer than the line limit, so we allow them.
122122
// Allowed format is: `[name]: https://www.rust-lang.org/`
123-
let is_url = |l: &str| l.starts_with('[') && l.contains("]:") && l.contains("http");
123+
let is_url = |l: &str| l.starts_with("[") && l.contains("]:") && l.contains("http");
124124

125125
if msg.lines().any(|line| line.len() > MAX_DESCRIPTION_WIDTH && !is_url(line)) {
126126
ecx.span_err(span, &format!(
@@ -177,7 +177,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
177177
if let Err(e) = output_metadata(ecx,
178178
&target_triple,
179179
&crate_name.name.as_str(),
180-
&diagnostics) {
180+
diagnostics) {
181181
ecx.span_bug(span, &format!(
182182
"error writing metadata for triple `{}` and crate `{}`, error: {}, \
183183
cause: {:?}",
@@ -227,7 +227,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
227227

228228
MacEager::items(SmallVector::many(vec![
229229
P(ast::Item {
230-
ident: name.clone(),
230+
ident: *name,
231231
attrs: Vec::new(),
232232
id: ast::DUMMY_NODE_ID,
233233
node: ast::ItemKind::Const(

src/libsyntax/ext/base.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,8 @@ pub struct ExpansionData {
637637
}
638638

639639
/// One of these is made during expansion and incrementally updated as we go;
640-
/// when a macro expansion occurs, the resulting nodes have the backtrace()
641-
/// -> expn_info of their expansion context stored into their span.
640+
/// when a macro expansion occurs, the resulting nodes have the `backtrace()
641+
/// -> expn_info` of their expansion context stored into their span.
642642
pub struct ExtCtxt<'a> {
643643
pub parse_sess: &'a parse::ParseSess,
644644
pub ecfg: expand::ExpansionConfig<'a>,
@@ -711,7 +711,7 @@ impl<'a> ExtCtxt<'a> {
711711
}
712712
ctxt = info.call_site.ctxt;
713713
last_macro = Some(info.call_site);
714-
return Some(());
714+
Some(())
715715
}).is_none() {
716716
break
717717
}
@@ -772,9 +772,9 @@ impl<'a> ExtCtxt<'a> {
772772
}
773773
pub fn trace_macros_diag(&self) {
774774
for (sp, notes) in self.expansions.iter() {
775-
let mut db = self.parse_sess.span_diagnostic.span_note_diag(*sp, &"trace_macro");
775+
let mut db = self.parse_sess.span_diagnostic.span_note_diag(*sp, "trace_macro");
776776
for note in notes {
777-
db.note(&note);
777+
db.note(note);
778778
}
779779
db.emit();
780780
}
@@ -797,7 +797,7 @@ impl<'a> ExtCtxt<'a> {
797797
v.push(self.ident_of(s));
798798
}
799799
v.extend(components.iter().map(|s| self.ident_of(s)));
800-
return v
800+
v
801801
}
802802
pub fn name_of(&self, st: &str) -> ast::Name {
803803
Symbol::intern(st)

0 commit comments

Comments
 (0)