skip user-type annotations if they don't have regions
This commit is contained in:
parent
d5d5e8c5f5
commit
a66ab2bedc
@ -139,17 +139,19 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||
|
||||
ExprKind::PlaceTypeAscription { source, user_ty } => {
|
||||
let place = unpack!(block = this.as_place(block, source));
|
||||
this.cfg.push(
|
||||
block,
|
||||
Statement {
|
||||
source_info,
|
||||
kind: StatementKind::AscribeUserType(
|
||||
place.clone(),
|
||||
Variance::Invariant,
|
||||
user_ty,
|
||||
),
|
||||
},
|
||||
);
|
||||
if let Some(user_ty) = user_ty {
|
||||
this.cfg.push(
|
||||
block,
|
||||
Statement {
|
||||
source_info,
|
||||
kind: StatementKind::AscribeUserType(
|
||||
place.clone(),
|
||||
Variance::Invariant,
|
||||
user_ty,
|
||||
),
|
||||
},
|
||||
);
|
||||
}
|
||||
block.and(place)
|
||||
}
|
||||
ExprKind::ValueTypeAscription { source, user_ty } => {
|
||||
@ -157,17 +159,19 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||
let temp = unpack!(
|
||||
block = this.as_temp(block, source.temp_lifetime, source, mutability)
|
||||
);
|
||||
this.cfg.push(
|
||||
block,
|
||||
Statement {
|
||||
source_info,
|
||||
kind: StatementKind::AscribeUserType(
|
||||
Place::Local(temp.clone()),
|
||||
Variance::Invariant,
|
||||
user_ty,
|
||||
),
|
||||
},
|
||||
);
|
||||
if let Some(user_ty) = user_ty {
|
||||
this.cfg.push(
|
||||
block,
|
||||
Statement {
|
||||
source_info,
|
||||
kind: StatementKind::AscribeUserType(
|
||||
Place::Local(temp.clone()),
|
||||
Variance::Invariant,
|
||||
user_ty,
|
||||
),
|
||||
},
|
||||
);
|
||||
}
|
||||
block.and(Place::Local(temp))
|
||||
}
|
||||
|
||||
|
@ -749,7 +749,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
|
||||
|
||||
ExprKind::ValueTypeAscription {
|
||||
source: cast_expr.to_ref(),
|
||||
user_ty: user_ty,
|
||||
user_ty: Some(user_ty),
|
||||
}
|
||||
} else {
|
||||
cast
|
||||
@ -757,15 +757,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
|
||||
}
|
||||
hir::ExprKind::Type(ref source, ref ty) => {
|
||||
let user_provided_tys = cx.tables.user_provided_tys();
|
||||
let user_ty = UserTypeAnnotation::Ty(
|
||||
*user_provided_tys
|
||||
.get(ty.hir_id)
|
||||
.expect(&format!(
|
||||
"{:?} not found in user_provided_tys, source: {:?}",
|
||||
ty,
|
||||
source,
|
||||
))
|
||||
);
|
||||
let user_ty = user_provided_tys.get(ty.hir_id).map(|&c_ty| UserTypeAnnotation::Ty(c_ty));
|
||||
if source.is_place_expr() {
|
||||
ExprKind::PlaceTypeAscription {
|
||||
source: source.to_ref(),
|
||||
|
@ -276,12 +276,12 @@ pub enum ExprKind<'tcx> {
|
||||
PlaceTypeAscription {
|
||||
source: ExprRef<'tcx>,
|
||||
/// Type that the user gave to this expression
|
||||
user_ty: UserTypeAnnotation<'tcx>,
|
||||
user_ty: Option<UserTypeAnnotation<'tcx>>,
|
||||
},
|
||||
ValueTypeAscription {
|
||||
source: ExprRef<'tcx>,
|
||||
/// Type that the user gave to this expression
|
||||
user_ty: UserTypeAnnotation<'tcx>,
|
||||
user_ty: Option<UserTypeAnnotation<'tcx>>,
|
||||
},
|
||||
Closure {
|
||||
closure_id: DefId,
|
||||
|
@ -2359,8 +2359,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
|
||||
pub fn to_ty_saving_user_provided_ty(&self, ast_ty: &hir::Ty) -> Ty<'tcx> {
|
||||
let ty = self.to_ty(ast_ty);
|
||||
let c_ty = self.infcx.canonicalize_response(&ty);
|
||||
self.tables.borrow_mut().user_provided_tys_mut().insert(ast_ty.hir_id, c_ty);
|
||||
|
||||
// If the type given by the user has free regions, save it for
|
||||
// later, since NLL would like to enforce those. Other sorts
|
||||
// of things are already sufficiently enforced. =)
|
||||
if ty.has_free_regions() {
|
||||
let c_ty = self.infcx.canonicalize_response(&ty);
|
||||
self.tables.borrow_mut().user_provided_tys_mut().insert(ast_ty.hir_id, c_ty);
|
||||
}
|
||||
|
||||
ty
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@ const X: u32 = 5;
|
||||
const Y: u32 = 6;
|
||||
const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
|
||||
//~^ WARN this constant cannot be used
|
||||
//~| ERROR
|
||||
|
||||
fn main() {
|
||||
println!("{}", FOO);
|
||||
|
@ -13,7 +13,7 @@ LL | #![warn(const_err)]
|
||||
| ^^^^^^^^^
|
||||
|
||||
error[E0080]: referenced constant has errors
|
||||
--> $DIR/conditional_array_execution.rs:20:20
|
||||
--> $DIR/conditional_array_execution.rs:19:20
|
||||
|
|
||||
LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
|
||||
| ----- attempt to subtract with overflow
|
||||
@ -21,20 +21,12 @@ LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
|
||||
LL | println!("{}", FOO);
|
||||
| ^^^
|
||||
|
||||
error[E0080]: could not evaluate constant
|
||||
--> $DIR/conditional_array_execution.rs:20:20
|
||||
error[E0080]: erroneous constant used
|
||||
--> $DIR/conditional_array_execution.rs:19:20
|
||||
|
|
||||
LL | println!("{}", FOO);
|
||||
| ^^^ referenced constant has errors
|
||||
|
||||
error[E0080]: constant evaluation error
|
||||
--> $DIR/conditional_array_execution.rs:15:1
|
||||
|
|
||||
LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
|
||||
| ^^^^^^^^^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| attempt to subtract with overflow
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
|
@ -34,12 +34,6 @@ warning: attempt to divide by zero
|
||||
LL | println!("{}", 1/(false as u32));
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: this expression will panic at runtime
|
||||
--> $DIR/promoted_errors.rs:24:20
|
||||
|
|
||||
LL | println!("{}", 1/(false as u32));
|
||||
| ^^^^^^^^^^^^^^^^ attempt to divide by zero
|
||||
|
||||
warning: attempt to divide by zero
|
||||
--> $DIR/promoted_errors.rs:26:14
|
||||
|
|
||||
|
Loading…
x
Reference in New Issue
Block a user